From 3be9cfcb6b59366b936821966d20a998a6895f9f Mon Sep 17 00:00:00 2001 From: 黎星凯 <13949086503@163.com> Date: 星期二, 30 四月 2024 14:38:13 +0800 Subject: [PATCH] bug41、42修改 --- consum-base/src/main/java/com/consum/base/controller/FinSysTenantController.java | 142 ++++++++++++++++++++++++++++------------------- 1 files changed, 85 insertions(+), 57 deletions(-) diff --git a/consum-base/src/main/java/com/consum/base/controller/FinSysTenantController.java b/consum-base/src/main/java/com/consum/base/controller/FinSysTenantController.java index 9cfab13..3335a92 100644 --- a/consum-base/src/main/java/com/consum/base/controller/FinSysTenantController.java +++ b/consum-base/src/main/java/com/consum/base/controller/FinSysTenantController.java @@ -28,15 +28,17 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.EasyExcelFactory; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.exception.ExcelDataConvertException; +import com.alibaba.excel.read.metadata.holder.ReadSheetHolder; import com.consum.base.BaseController; import com.consum.base.core.utils.CommonUtil; import com.consum.base.core.utils.FinSysTenantUtils; import com.consum.base.pojo.FinSysTenantParam; import com.consum.base.pojo.FinSysTenantSearchParam; +import com.consum.base.pojo.excel.ImportTenantTemplate; import com.consum.base.service.FinSysTenantService; import com.consum.base.service.FinSysTenantUserService; import com.consum.model.po.FinSysTenant; @@ -404,6 +406,8 @@ fileName = "鏈烘瀯瀵煎叆妯℃澘.xls"; } else if ("goods".equals(type)) { fileName = "鐗╁搧淇℃伅.xls"; + } else if ("procure".equals(type)) { + fileName = "閲囪喘瀵煎叆.xls"; } Resource resource = new ClassPathResource("import/" + fileName); // 鑾峰彇鏂囦欢杈撳叆娴� @@ -422,7 +426,7 @@ @PostMapping("import") public ResponseValue upload(@RequestParam Long pid, MultipartFile file) throws IOException { String originalFilename = file.getOriginalFilename(); - if (!"xls".equals(originalFilename.substring(originalFilename.lastIndexOf(".") + 1))) { + if (!originalFilename.endsWith("xls")) { return ResponseValue.error("鏂囦欢鏍煎紡鏈夎!"); } FinSysTenantUser sysInfo = this.getSysInfo(); @@ -435,55 +439,62 @@ return ResponseValue.error("涓嶈兘鍒涘缓鍘匡紙鍖猴級绾т互涓嬫満鏋�"); } - EasyExcel.read(file.getInputStream(), FinSysTenantParam.class, new AnalysisEventListener<FinSysTenantParam>() { - LinkedList<FinSysTenantParam> finSysTenantParams = new LinkedList<>(); + EasyExcelFactory + .read(file.getInputStream(), ImportTenantTemplate.class, new AnalysisEventListener<ImportTenantTemplate>() { + LinkedList<FinSysTenantParam> finSysTenantParams = new LinkedList<>(); - @Override - public void invoke(FinSysTenantParam finSysTenantParam, AnalysisContext analysisContext) { - if (StringUtils.isEmpty(finSysTenantParam.getCode()) || finSysTenantParam.getCode().length() > 20) { - IllegalStateException exception = new IllegalStateException( - "绗�" + analysisContext.readSheetHolder().getRowIndex() + "琛�,鏈烘瀯缂栧彿涓嶈兘涓虹┖鎴栭暱搴﹀ぇ浜�20"); - throw exception; - } - if (null != finSysTenantService.queryOneByCode(finSysTenantParam.getCode())) { - throw new IllegalStateException( - "绗�" + analysisContext.readSheetHolder().getRowIndex() + "琛�,鏈烘瀯缂栧彿宸插瓨鍦�"); - } - if (StringUtils.isEmpty(finSysTenantParam.getName()) || finSysTenantParam.getName().length() > 100) { - IllegalStateException exception = new IllegalStateException( - "绗�" + analysisContext.readSheetHolder().getRowIndex() + "琛�,鏈烘瀯鍚嶇О涓嶈兘涓虹┖鎴栭暱搴﹀ぇ浜�100"); - throw exception; - } - finSysTenantParam.setParentId(pid); - finSysTenantParam.setStatus(1); - finSysTenantParam.setSummary("绯荤粺瀵煎叆"); - finSysTenantParams.add(finSysTenantParam); - } - - @Override - public void doAfterAllAnalysed(AnalysisContext analysisContext) { - finSysTenantService.insertFinSysTenantBatch(finSysTenantParams, sysInfo, lv); - } - - @Override - public void onException(Exception exception, AnalysisContext context) { - // 濡傛灉鏄煇涓�涓崟鍏冩牸鐨勮浆鎹㈠紓甯� 鑳借幏鍙栧埌鍏蜂綋琛屽彿 - if (exception instanceof ExcelDataConvertException) { - ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception; - logger.error("绗瑊}琛岋紝绗瑊}鍒楄В鏋愬紓甯革紝鏁版嵁涓�:{}", excelDataConvertException.getRowIndex(), - excelDataConvertException.getColumnIndex() + 1, - excelDataConvertException.getCellData().getStringValue()); - throw new IllegalStateException("绗�" + (excelDataConvertException.getRowIndex() + 1) + "琛岋紝绗�" - + (excelDataConvertException.getColumnIndex() + 1) + "鍒楄В鏋愬紓甯�,寮傚父鏁版嵁涓�:[ " - + excelDataConvertException.getCellData().getStringValue() + " ]"); - } - if (exception instanceof IllegalStateException) { - throw (IllegalStateException)exception; + @Override + public void invoke(ImportTenantTemplate finSysTenantParam, AnalysisContext analysisContext) { + String code = finSysTenantParam.getCode(); + String tenantName = finSysTenantParam.getTenantName(); + ReadSheetHolder readSheetHolder = analysisContext.readSheetHolder(); + Integer rowIndex = readSheetHolder.getRowIndex() + 1; + if (StringUtils.isEmpty(code) || code.length() > 20) { + IllegalStateException exception = + new IllegalStateException("绗�" + rowIndex + "琛�,鏈烘瀯缂栧彿涓嶈兘涓虹┖鎴栭暱搴﹀ぇ浜�20"); + throw exception; + } + if (null != finSysTenantService.queryOneByCode(code)) { + throw new IllegalStateException("绗�" + rowIndex + "琛�,鏈烘瀯缂栧彿宸插瓨鍦�"); + } + if (StringUtils.isEmpty(tenantName) || tenantName.length() > 100) { + IllegalStateException exception = + new IllegalStateException("绗�" + rowIndex + "琛�,鏈烘瀯鍚嶇О涓嶈兘涓虹┖鎴栭暱搴﹀ぇ浜�100"); + throw exception; + } + FinSysTenantParam tenantParam = new FinSysTenantParam(); + tenantParam.setParentId(pid); + tenantParam.setStatus(1); + tenantParam.setSummary("绯荤粺瀵煎叆"); + tenantParam.setCode(code); + tenantParam.setName(tenantName); + finSysTenantParams.add(tenantParam); } - } + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + finSysTenantService.insertFinSysTenantBatch(finSysTenantParams, sysInfo, lv); + } - }).doReadAll(); + @Override + public void onException(Exception exception, AnalysisContext context) { + // 濡傛灉鏄煇涓�涓崟鍏冩牸鐨勮浆鎹㈠紓甯� 鑳借幏鍙栧埌鍏蜂綋琛屽彿 + if (exception instanceof ExcelDataConvertException) { + ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception; + Integer rowIndex = excelDataConvertException.getRowIndex() + 1; + Integer columnIndex = excelDataConvertException.getColumnIndex(); + String stringValue = excelDataConvertException.getCellData().getStringValue(); + logger.error("绗瑊}琛岋紝绗瑊}鍒楄В鏋愬紓甯革紝鏁版嵁涓�:{}", rowIndex, columnIndex, stringValue); + throw new IllegalStateException( + "绗�" + rowIndex + "琛岋紝绗�" + columnIndex + "鍒楄В鏋愬紓甯�,寮傚父鏁版嵁涓�:[ " + stringValue + " ]"); + } + if (exception instanceof IllegalStateException) { + throw (IllegalStateException)exception; + } + + } + + }).doReadAll(); return ResponseValue.success("瀵煎叆鎴愬姛!", 1); } @@ -509,10 +520,31 @@ if (sysInfo == null) { return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); } - // FinSysTenant finSysTenant1 = this.finSysTenantService.selectByTenantId(sysInfo.getTenantCode()); - // if (finSysTenant1.getLv() != 1) { - // return ResponseValue.error("鏆傛棤淇敼鏉冮檺"); - // } + + int num = this.finSysTenantService.updateFinSysTenant(param, this.getSysInfo()); + return num > 0 ? ResponseValue.success(1) : ResponseValue.error("缂栬緫澶辫触锛�"); + } + + /** + * 淇敼鍚敤绂佺敤鐘舵�� + * + * @return + */ + @PostMapping("/editState") + public ResponseValue editState() { + FinSysTenant param = CommonUtil.getObjFromReqBody(FinSysTenant.class); + FinSysTenant selFinSysTenant = finSysTenantService.selectById(param.getId()); + selFinSysTenant.setStatus(param.getStatus()); + //FinSysTenant finSysTenant = new FinSysTenant(); + param = selFinSysTenant; + Long id = param.getId(); + if (id == null || id.longValue() <= 0) { + return ResponseValue.error("缂栬緫鐨勬満鏋勪笉瀛樺湪"); + } + FinSysTenantUser sysInfo = getSysInfo(); + if (sysInfo == null) { + return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); + } int num = this.finSysTenantService.updateFinSysTenant(param, this.getSysInfo()); return num > 0 ? ResponseValue.success(1) : ResponseValue.error("缂栬緫澶辫触锛�"); } @@ -609,17 +641,13 @@ return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); } String tenantId = sysInfo.getTenantId(); - FinSysTenant finSysTenant = new FinSysTenant(); - finSysTenant.setTempId(Long.valueOf(tenantId)); - FinSysTenant userTenant = this.finSysTenantService.get(finSysTenant); + FinSysTenant userTenant = finSysTenantService.selectById(Long.valueOf(tenantId)); Long parentId = userTenant.getParentId(); // 绗竴绾� if (parentId == 0) { return ResponseValue.success(userTenant); } else { - FinSysTenant param = new FinSysTenant(); - param.setTempId(Long.valueOf(parentId)); - FinSysTenant result = this.finSysTenantService.get(param); + FinSysTenant result = finSysTenantService.selectById(parentId); return ResponseValue.success(result); } } -- Gitblit v1.9.1