|
@@ -5,15 +5,20 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
-import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
import com.ruoyi.project.base.domain.TBaseDevice;
|
|
|
-import com.ruoyi.project.base.domain.TBasePlant;
|
|
|
-import com.ruoyi.project.base.domain.TBaseRegion;
|
|
|
+import com.ruoyi.project.base.mapper.TBaseDeviceMapper;
|
|
|
+import com.ruoyi.project.base.mapper.TBasePointMapper;
|
|
|
import com.ruoyi.project.base.service.ITBaseDeviceService;
|
|
|
import com.ruoyi.project.base.service.ITBasePlantService;
|
|
|
import com.ruoyi.project.base.service.ITBaseRegionService;
|
|
@@ -59,6 +64,10 @@ public class TBasePointController extends BaseController {
|
|
|
@Autowired
|
|
|
private ISysDictTypeService isysDictTypeService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TBasePointMapper tBasePointMapper;
|
|
|
+ @Resource
|
|
|
+ private TBaseDeviceMapper tBaseDeviceMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询密封点列表
|
|
@@ -145,183 +154,169 @@ public class TBasePointController extends BaseController {
|
|
|
//获取操作人员ID
|
|
|
Long userId = getUserId();
|
|
|
//报错行数统计
|
|
|
- List<Integer> failRow = new ArrayList<>();
|
|
|
+ CopyOnWriteArrayList<Integer> failRow = new CopyOnWriteArrayList<>();
|
|
|
Workbook workbook = ExcelUtils.getWorkBook(file);
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
List<TBasePoint> list = new ArrayList<>();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
int rowNum = sheet.getPhysicalNumberOfRows();
|
|
|
- int failNumber = 0;
|
|
|
+ //线程池
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(30);
|
|
|
+ final CountDownLatch latch = new CountDownLatch(rowNum -1); //相同线程数量的计数
|
|
|
+ AtomicInteger failNumber = new AtomicInteger();
|
|
|
+ AtomicInteger successNumber = new AtomicInteger();
|
|
|
for (int i = 1; i < rowNum; i++) {
|
|
|
- try {
|
|
|
- logger.info("读取行数:" + i);
|
|
|
- Row row = sheet.getRow(i);
|
|
|
- int cellNum = row.getLastCellNum();
|
|
|
- TBasePoint entity = new TBasePoint();
|
|
|
- Long plantId = 0L;
|
|
|
- Long regionId = 0L;
|
|
|
- String devCode = "";
|
|
|
- String devName = "";
|
|
|
- for (int j = 0; j < cellNum; j++) {
|
|
|
- Cell cell = row.getCell(j);
|
|
|
- if (cell == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
- logger.info("cellValue:" + cellValue);
|
|
|
- if (j == 0) {
|
|
|
- //装置名称
|
|
|
- TBasePlant tBasePlant = tBasePlantService.selectTBasePlantByName(cellValue);
|
|
|
- if (tBasePlant == null) {
|
|
|
- return AjaxResult.success("未找到对应装置!请检查装置无误后重新提交!", 0);
|
|
|
- }
|
|
|
- plantId = tBasePlant.getPlantId();
|
|
|
- entity.setPlantId(plantId);
|
|
|
- } else if (j == 1 || j == 2) {
|
|
|
- if (StringUtils.isEmpty(cellValue))
|
|
|
- return AjaxResult.success("未找到对应装置!请检查装置名称无误后重新提交!", 0);
|
|
|
- } else if (j == 3) {
|
|
|
- // 区域名称
|
|
|
- TBaseRegion tBaseRegion = tBaseRegionService.selectTBaseRegionByName(cellValue, plantId);
|
|
|
- if (tBaseRegion == null) {
|
|
|
- return AjaxResult.success("未找到对应区域!请检查装置与区域无误后重新提交!", 0);
|
|
|
+ int finalI = i;
|
|
|
+ executorService.execute(() -> {
|
|
|
+ try {
|
|
|
+ logger.info("读取行数:" + finalI);
|
|
|
+ Row row = sheet.getRow(finalI);
|
|
|
+ int cellNum = row.getLastCellNum();
|
|
|
+ TBasePoint entity = new TBasePoint();
|
|
|
+ for (int j = 0; j < cellNum; j++) {
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ if (cell == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- regionId = tBaseRegion.getId();
|
|
|
- entity.setRegionId(regionId);
|
|
|
- } else if (j == 4) {
|
|
|
- if (StringUtils.isEmpty(cellValue))
|
|
|
- return AjaxResult.success("未找到对应区域!请检查装置与区域无误后重新提交!", 0);
|
|
|
- } else if (j == 5) {
|
|
|
- // 平台
|
|
|
- entity.setLayer(cellValue);
|
|
|
- } else if (j == 6) {
|
|
|
- //PID
|
|
|
- entity.setPidNo(cellValue);
|
|
|
- } else if (j == 7) {
|
|
|
- // 设备名称
|
|
|
- devName = cellValue;
|
|
|
- } else if (j == 8) {
|
|
|
- // 设备编号
|
|
|
- devCode = cellValue;
|
|
|
- TBaseDevice tBaseDevice = new TBaseDevice();
|
|
|
- tBaseDevice.setPlantId(plantId);
|
|
|
- tBaseDevice.setRegionId(regionId);
|
|
|
- tBaseDevice.setDevCode(devCode);
|
|
|
- tBaseDevice.setDevDescribe(devName);
|
|
|
- TBaseDevice device = tBaseDeviceService.selectDeviceByPlantRegionAndDevice(tBaseDevice);
|
|
|
- if (device == null) {
|
|
|
- return AjaxResult.success("未找到对应设备!请检查装置、区域、设备无误后重新提交!", 0);
|
|
|
- }
|
|
|
- entity.setDevId(device.getDevId());// 设备id
|
|
|
- } else if (j == 9) {
|
|
|
- // 群组位置
|
|
|
- entity.setGroupPosition(cellValue);
|
|
|
- } else if (j == 10) {
|
|
|
- // 密封点位置
|
|
|
- entity.setPointPosition(cellValue);
|
|
|
- } else if (j == 11) {
|
|
|
- // 群组编码
|
|
|
- entity.setGroupCode(cellValue);
|
|
|
- } else if (j == 12) {
|
|
|
- // 密封点扩展号编码
|
|
|
- entity.setExtendCode(cellValue);
|
|
|
- } else if (j == 13) {
|
|
|
- for (SysDictData dictData : isysDictTypeService.selectDictDataByType("point_type")) {
|
|
|
- if (dictData.getDictLabel().equals(cellValue)) {
|
|
|
- // 密封点类型
|
|
|
- entity.setPointType(dictData.getDictValue());
|
|
|
- break;
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ logger.info("cellValue:" + cellValue);
|
|
|
+ if (j == 0) {
|
|
|
+ //装置名称
|
|
|
+ entity.setPlantName(cellValue);
|
|
|
+ } else if (j == 1 ) {
|
|
|
+ entity.setPlantCode(cellValue);
|
|
|
+ } else if (j == 3) {
|
|
|
+ // 区域名称
|
|
|
+ entity.setRegionName(cellValue);
|
|
|
+ } else if (j == 4) {
|
|
|
+ entity.setRegionCode(cellValue);
|
|
|
+ } else if (j == 5) {
|
|
|
+ // 平台
|
|
|
+ entity.setLayer(cellValue);
|
|
|
+ } else if (j == 6) {
|
|
|
+ //PID
|
|
|
+ entity.setPidNo(cellValue);
|
|
|
+ } else if (j == 7) {
|
|
|
+ // 设备名称
|
|
|
+ entity.setDevName(cellValue);
|
|
|
+ } else if (j == 8) {
|
|
|
+ // 设备编号
|
|
|
+ entity.setDevCode(cellValue);// 设备id
|
|
|
+ } else if (j == 9) {
|
|
|
+ // 群组位置
|
|
|
+ entity.setGroupPosition(cellValue);
|
|
|
+ } else if (j == 10) {
|
|
|
+ // 密封点位置
|
|
|
+ entity.setPointPosition(cellValue);
|
|
|
+ } else if (j == 11) {
|
|
|
+ // 群组编码
|
|
|
+ entity.setGroupCode(cellValue);
|
|
|
+ } else if (j == 12) {
|
|
|
+ // 密封点扩展号编码
|
|
|
+ entity.setExtendCode(cellValue);
|
|
|
+ } else if (j == 13) {
|
|
|
+ // 密封点类型
|
|
|
+ entity.setPointType(cellValue);
|
|
|
+ } else if (j == 14) {
|
|
|
+ // 密封点子类型
|
|
|
+ entity.setSubPointType(cellValue);
|
|
|
+ } else if (j == 15) {
|
|
|
+ // 公称直径
|
|
|
+ entity.setDia(cellValue);
|
|
|
+ } else if (j == 16) {
|
|
|
+ // 是否不可达点
|
|
|
+ entity.setUnarrive(cellValue);
|
|
|
+ } else if (j == 17) {
|
|
|
+ // 不可达原因
|
|
|
+ entity.setUnarriveReason(cellValue);
|
|
|
+ } else if (j == 18) {
|
|
|
+ // 是否保温
|
|
|
+ entity.setKeepWarm(cellValue);
|
|
|
+ } else if (j == 19) {
|
|
|
+ // 介质
|
|
|
+ entity.setMedium(cellValue);
|
|
|
+ } else if (j == 20) {
|
|
|
+ for (SysDictData dictData : isysDictTypeService.selectDictDataByType("medium_type")) {
|
|
|
+ if (dictData.getDictLabel().equals(cellValue)) {
|
|
|
+ // 介质状态
|
|
|
+ entity.setMediumType(dictData.getDictValue());
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ } else if (j == 21) {
|
|
|
+ // toc分数
|
|
|
+ entity.setTocMark(cellValue);
|
|
|
+ } else if (j == 22) {
|
|
|
+ // 甲烷质量分数
|
|
|
+ entity.setMethaneMark(cellValue);
|
|
|
+ } else if (j == 23) {
|
|
|
+ // vocs分数
|
|
|
+ entity.setVocsMark(cellValue);
|
|
|
+ } else if (j == 24) {
|
|
|
+ // 工艺温度
|
|
|
+ entity.setTemperature(cellValue);
|
|
|
+ } else if (j == 25) {
|
|
|
+ // 工艺压力
|
|
|
+ entity.setPressure(cellValue);
|
|
|
+ } else if (j == 26) {
|
|
|
+ // pic图号
|
|
|
+ entity.setPicNo(cellValue);
|
|
|
+ } else if (j == 27) {
|
|
|
+ // 运行时间
|
|
|
+ entity.setRunTime(sdf.parse(cellValue));
|
|
|
+ } else if (j == 28) {
|
|
|
+ // 备注
|
|
|
+ entity.setRemarks(cellValue);
|
|
|
}
|
|
|
- } else if (j == 14) {
|
|
|
- // 密封点子类型
|
|
|
- entity.setSubPointType(cellValue);
|
|
|
- } else if (j == 15) {
|
|
|
- // 公称直径
|
|
|
- entity.setDia(cellValue);
|
|
|
- } else if (j == 16) {
|
|
|
- // 是否不可达点
|
|
|
- entity.setUnarrive(cellValue.equals("是")?"1":"0");
|
|
|
- } else if (j == 17) {
|
|
|
- // 不可达原因
|
|
|
- entity.setUnarriveReason(cellValue);
|
|
|
- } else if (j == 18) {
|
|
|
- // 是否保温
|
|
|
- entity.setKeepWarm(cellValue.equals("是")?"1":"0");
|
|
|
- } else if (j == 19) {
|
|
|
- // 介质
|
|
|
- entity.setMedium(cellValue);
|
|
|
- } else if (j == 20) {
|
|
|
- for (SysDictData dictData : isysDictTypeService.selectDictDataByType("medium_type")) {
|
|
|
- if (dictData.getDictLabel().equals(cellValue)) {
|
|
|
- // 介质状态
|
|
|
- entity.setMediumType(dictData.getDictValue());
|
|
|
- break;
|
|
|
- }
|
|
|
+ }
|
|
|
+ entity.setCreaterCode(userId);
|
|
|
+ entity.setApproveStatus(0L);
|
|
|
+ TBaseDevice device = tBaseDeviceMapper.selectTBaseDeviceByCode(entity);
|
|
|
+ if (device == null) {
|
|
|
+ logger.info("没有设备数据");
|
|
|
+ failRow.add(finalI + 1);
|
|
|
+ throw new InterruptedException(); //中止线程
|
|
|
+ }else {
|
|
|
+ entity.setDevId(device.getDevId());
|
|
|
+ entity.setPlantId(device.getPlantId());
|
|
|
+ entity.setRegionId(device.getRegionId());
|
|
|
+ logger.info("entity:" + entity);
|
|
|
+ //进行数据更新
|
|
|
+ TBasePoint tBasePoint = tBasePointService.selectTBasePointByGroupCodeAndExtendCode(entity);
|
|
|
+ if (tBasePoint == null) {
|
|
|
+ entity.setUpdatedate(new Date());
|
|
|
+ entity.setUpdaterCode(getUserId());
|
|
|
+ tBasePointService.insertTBasePoint(entity);
|
|
|
+ successNumber.getAndIncrement();
|
|
|
+ }else {
|
|
|
+ logger.info("重复数据");
|
|
|
+ failNumber.getAndIncrement();
|
|
|
+ failRow.add(finalI + 1);
|
|
|
+ throw new InterruptedException();//中止线程
|
|
|
}
|
|
|
- } else if (j == 21) {
|
|
|
- // toc分数
|
|
|
- entity.setTocMark(cellValue);
|
|
|
- } else if (j == 22) {
|
|
|
- // 甲烷质量分数
|
|
|
- entity.setMethaneMark(cellValue);
|
|
|
- } else if (j == 23) {
|
|
|
- // vocs分数
|
|
|
- entity.setVocsMark(cellValue);
|
|
|
- } else if (j == 24) {
|
|
|
- // 工艺温度
|
|
|
- entity.setTemperature(cellValue);
|
|
|
- } else if (j == 25) {
|
|
|
- // 工艺压力
|
|
|
- entity.setPressure(cellValue);
|
|
|
- } else if (j == 26) {
|
|
|
- // pic图号
|
|
|
- entity.setPicNo(cellValue);
|
|
|
- } else if (j == 27) {
|
|
|
- // 运行时间
|
|
|
- entity.setRunTime(sdf.parse(cellValue));
|
|
|
- } else if (j == 28) {
|
|
|
- // 备注
|
|
|
- entity.setRemarks(cellValue);
|
|
|
}
|
|
|
+ }catch (InterruptedException e) {
|
|
|
+ logger.info("中止线程"+ Thread.currentThread().getName());
|
|
|
+ }catch (Exception e) {
|
|
|
+ failNumber.getAndIncrement();
|
|
|
+ failRow.add(finalI + 1);
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ latch.countDown(); //线程计数
|
|
|
}
|
|
|
- entity.setCreaterCode(userId);
|
|
|
- entity.setApproveStatus(0L);
|
|
|
- logger.info("entity:" + entity);
|
|
|
- list.add(entity);
|
|
|
- } catch (Exception e) {
|
|
|
- failNumber++;
|
|
|
- logger.info("e:" + JSON.toJSONString(e));
|
|
|
- failRow.add(i + 1);
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
- int successNumber = 0;
|
|
|
- int failNum = 0;
|
|
|
- for (TBasePoint t : list
|
|
|
- ) {
|
|
|
- failNum++;
|
|
|
- try {
|
|
|
- //进行数据更新
|
|
|
- TBasePoint tBasePoint = tBasePointService.selectTBasePointByGroupCodeAndExtendCode(t);
|
|
|
- if (tBasePoint == null) {
|
|
|
- t.setUpdatedate(new Date());
|
|
|
- t.setUpdaterCode(getUserId());
|
|
|
- tBasePointService.insertTBasePoint(t);
|
|
|
- successNumber++;
|
|
|
- }else {
|
|
|
- failNumber++;
|
|
|
- failRow.add(failNum + 1);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failNumber++;
|
|
|
- logger.info("e:" + e);
|
|
|
- failRow.add(failNum + 1);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ latch.await(); //线程计数完毕后继续执行
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+ executorService.shutdown();
|
|
|
+
|
|
|
logger.info("list:" + JSON.toJSONString(list));
|
|
|
logger.info("successNumber:" + successNumber);
|
|
|
logger.info("failNumber:" + failNumber);
|
|
|
logger.info("failRow:" + failRow);
|
|
|
- return AjaxResult.success(String.valueOf(successNumber), failRow);
|
|
|
+ return AjaxResult.success(String.valueOf(successNumber.get()), failRow);
|
|
|
}
|
|
|
}
|