wangliang 1 gadu atpakaļ
vecāks
revīzija
092aca0786

+ 20 - 23
sop-business/src/main/java/com/qmth/sop/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -17,7 +17,6 @@ import com.qmth.sop.business.util.excel.BasicExcelListener;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
 import com.qmth.sop.common.util.DateDisposeUtils;
-import com.qmth.sop.common.util.ServletUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -108,7 +107,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             EasyExcel.read(inputStream, UserArchivesImportDto.class, new BasicExcelListener<UserArchivesImportDto>() {
 
                 @Override
-                public void handle(LinkedMultiValueMap<String, UserArchivesImportDto> dataList, StringJoiner errorDataSj) {
+                public void handle(LinkedMultiValueMap<String, UserArchivesImportDto> dataList, StringJoiner errorDataSj, Exception exception) {
                     userArchivesImportDtoLinkedMultiValueMap.addAll(dataList);
                     errorData.add(errorDataSj.toString());
                 }
@@ -232,7 +231,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             EasyExcel.read(inputStream, CustomImportDto.class, new BasicExcelListener<CustomImportDto>() {
 
                 @Override
-                public void handle(LinkedMultiValueMap<String, CustomImportDto> dataList, StringJoiner errorDataSj) {
+                public void handle(LinkedMultiValueMap<String, CustomImportDto> dataList, StringJoiner errorDataSj, Exception exception) {
                     customImportDtoLinkedMultiValueMap.addAll(dataList);
                     errorData.add(errorDataSj.toString());
                 }
@@ -265,7 +264,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     sysCustom.setLevelId(sysLevel.getId());
                     sysCustom.setSync(false);
                     sysCustom.setEnable(true);
-                    sysCustom.setCreateId(((SysUser)map.get("account")).getId());
+                    sysCustom.setCreateId(((SysUser) map.get("account")).getId());
                     sysCustom.setCreateTime(System.currentTimeMillis());
                     sysCustomService.saveOrUpdate(sysCustom);
 
@@ -311,10 +310,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 dto.setStatus(e.getStatus() ? "已阅" : "未阅");
                 dto.setSupplier(e.getSupplier());
                 //时间戳转化为日期字符串
-                if(Objects.nonNull(e.getReceiveTime()))
-                dto.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(e.getReceiveTime()));
-                if(Objects.nonNull(e.getType()))
-                dto.setType(e.getType().getTitle());
+                if (Objects.nonNull(e.getReceiveTime()))
+                    dto.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(e.getReceiveTime()));
+                if (Objects.nonNull(e.getType()))
+                    dto.setType(e.getType().getTitle());
                 return dto;
             }).collect(Collectors.toList());
 
@@ -337,7 +336,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         try {
             fileTemp = SystemConstant.getFileTempVar(SystemConstant.XLSX_PREFIX);
 
-            List<TBDingSubmitQueryResult> tbDingCountQueryResults = tbDingService.query((SysUser)map.get("account"),(Long) map.get("serviceId"), (String) map.get("status"), (Long) map.get("createId"), (String) map.get("userName"), (Long) map.get("supplierId"), (String) map.get("String"), (String) map.get("sopNo"), (Long) map.get("days"));
+            List<TBDingSubmitQueryResult> tbDingCountQueryResults = tbDingService.query((SysUser) map.get("account"), (Long) map.get("serviceId"), (String) map.get("status"), (Long) map.get("createId"), (String) map.get("userName"), (Long) map.get("supplierId"), (String) map.get("String"), (String) map.get("sopNo"), (Long) map.get("days"));
 //            tbDingCountQueryResults.forEach(e -> {
 //                e.setStatus(FlowStatusEnum.convertToEnum(e.getStatus()).getTitle());
 //            });
@@ -388,7 +387,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             EasyExcel.read(inputStream, DeviceImportDto.class, new BasicExcelListener<DeviceImportDto>() {
 
                 @Override
-                public void handle(LinkedMultiValueMap<String, DeviceImportDto> dataList, StringJoiner errorDataSj) {
+                public void handle(LinkedMultiValueMap<String, DeviceImportDto> dataList, StringJoiner errorDataSj, Exception exception) {
                     customImportDtoLinkedMultiValueMap.addAll(dataList);
                     errorData.add(errorDataSj.toString());
                 }
@@ -406,24 +405,24 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 List<SysDeviceModel> modelList = sysDeviceModelService.list();
                 Objects.requireNonNull(customImportDtoLinkedMultiValueMap.get(BasicExcelListener.SUCCESS)).forEach(e -> {
                     SysDevice device = new SysDevice();
-                    if(brandList.stream().noneMatch(r->r.getBrand().equals(e.getBrand()))){
-                        SysDeviceBrand brand=new SysDeviceBrand();
+                    if (brandList.stream().noneMatch(r -> r.getBrand().equals(e.getBrand()))) {
+                        SysDeviceBrand brand = new SysDeviceBrand();
                         brand.setBrand(e.getBrand());
-                        brand.insertInfo(((SysUser)map.get("account")).getId());
+                        brand.insertInfo(((SysUser) map.get("account")).getId());
                         sysDeviceBrandService.saveOrUpdate(brand);
                         brandList.add(brand);
-                        SysDeviceModel model=new SysDeviceModel();
+                        SysDeviceModel model = new SysDeviceModel();
                         model.setBrandId(brand.getId());
                         model.setModel(e.getModel());
-                        model.insertInfo(((SysUser)map.get("account")).getId());
+                        model.insertInfo(((SysUser) map.get("account")).getId());
                         sysDeviceModelService.saveOrUpdate(model);
                         modelList.add(model);
-                    }else{
-                        if(modelList.stream().noneMatch(r->r.getModel().equals(e.getModel()))){
-                            SysDeviceModel model=new SysDeviceModel();
-                            model.setBrandId(brandList.stream().filter(r->r.getBrand().equals(e.getBrand())).findFirst().get().getId());
+                    } else {
+                        if (modelList.stream().noneMatch(r -> r.getModel().equals(e.getModel()))) {
+                            SysDeviceModel model = new SysDeviceModel();
+                            model.setBrandId(brandList.stream().filter(r -> r.getBrand().equals(e.getBrand())).findFirst().get().getId());
                             model.setModel(e.getModel());
-                            model.insertInfo(((SysUser)map.get("account")).getId());
+                            model.insertInfo(((SysUser) map.get("account")).getId());
                             sysDeviceModelService.saveOrUpdate(model);
                             modelList.add(model);
                         }
@@ -433,8 +432,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     device.setModel(e.getModel());
 
 
-
-
                     device.setDeviceCode(e.getDeviceCode());
                     InOutTypeEnum bound = InOutTypeEnum.IN.getTitle().equals(e.getBound()) ? InOutTypeEnum.IN : InOutTypeEnum.OUT;
                     device.setBound(bound);
@@ -456,7 +453,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     DeviceStatusEnum status = DeviceStatusEnum.NORMAL.getTitle().equals(e.getStatus()) ? DeviceStatusEnum.NORMAL : DeviceStatusEnum.BREAK_DOWN;
                     device.setStatus(status);
                     device.setSync(false);
-                    device.insertInfo(((SysUser)map.get("account")).getId());
+                    device.insertInfo(((SysUser) map.get("account")).getId());
                     sysDevices.add(device);
                 });
                 sysDeviceService.saveSysDevice(sysDevices);

+ 7 - 3
sop-business/src/main/java/com/qmth/sop/business/util/excel/BasicExcelListener.java

@@ -35,6 +35,7 @@ public abstract class BasicExcelListener<T> extends AnalysisEventListener<T> {
     public static final String ERROR = "error";
     private LinkedMultiValueMap<String, T> list;
     private StringJoiner errorDataSj = new StringJoiner("\n");
+    private Exception exception = null;
 
     public BasicExcelListener() {
         this.list = new LinkedMultiValueMap<>(BATCH_COUNT);
@@ -45,7 +46,7 @@ public abstract class BasicExcelListener<T> extends AnalysisEventListener<T> {
         this.list = new LinkedMultiValueMap<>(BATCH_COUNT);
     }
 
-    public abstract void handle(LinkedMultiValueMap<String, T> dataList, StringJoiner errorData);
+    public abstract void handle(LinkedMultiValueMap<String, T> dataList, StringJoiner errorData, Exception exception);
 
 //    public abstract void errorData(List<String> errorDataList);
 
@@ -60,7 +61,7 @@ public abstract class BasicExcelListener<T> extends AnalysisEventListener<T> {
             list.add(SUCCESS, o);
         }
         if (list.size() >= BATCH_COUNT) {
-            handle(list, errorDataSj);
+            handle(list, errorDataSj, this.exception);
             list.clear();
         }
     }
@@ -78,12 +79,15 @@ public abstract class BasicExcelListener<T> extends AnalysisEventListener<T> {
     @Override
     public void doAfterAllAnalysed(AnalysisContext analysisContext) {
         log.info("所有数据解析完成!");
-        handle(list, errorDataSj);
+        handle(list, errorDataSj, this.exception);
     }
 
     @Override
     public void onException(Exception exception, AnalysisContext context) {
         log.info("onException is come in!");
+//        XlsxReadSheetHolder xlsxReadSheetHolder = (XlsxReadSheetHolder) context.currentReadHolder();
+//        errorDataSj.add("第" + (xlsxReadSheetHolder.getSheetNo() + 1) + "个sheet第" + (xlsxReadSheetHolder.getRowIndex() - 1) + "行" + exception.getMessage().toString());
+        this.exception = exception;
     }
 
     @Override