1.污区图
2.过程监督-终端 代码提交
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
package com.njcn.process.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.process.pojo.param.TerminalParam;
|
||||
import com.njcn.process.pojo.po.PmsTerminalDetection;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.process.pojo.vo.TerminalVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 终端检测监督
|
||||
* </p>
|
||||
*
|
||||
* @author wr
|
||||
* @since 2023-02-27
|
||||
*/
|
||||
public interface PmsTerminalDetectionService extends IService<PmsTerminalDetection> {
|
||||
|
||||
/***
|
||||
* 终端检测监督列表
|
||||
* @author wr
|
||||
* @date 2023-02-27 13:58
|
||||
* @param param
|
||||
* @return Page<?>
|
||||
*/
|
||||
Page<TerminalVO> terminalPage(TerminalParam.TerminalPageParam param);
|
||||
|
||||
/***
|
||||
* 导出模板
|
||||
* @author wr
|
||||
* @date 2023-02-27 16:14
|
||||
* @param response
|
||||
*/
|
||||
void exportTemplate(HttpServletResponse response);
|
||||
|
||||
/***
|
||||
* 终端检测监督单条新增
|
||||
* @author wr
|
||||
* @date 2023-02-27 14:02
|
||||
* @param param
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean insertTerminal(TerminalParam param);
|
||||
/***
|
||||
* 终端检测监督批量新增
|
||||
* @author wr
|
||||
* @date 2023-02-27 14:02
|
||||
* @param file
|
||||
* @param response
|
||||
* @return Boolean
|
||||
*/
|
||||
void batchTerminal(MultipartFile file, HttpServletResponse response);
|
||||
|
||||
/***
|
||||
* 终端检测监督修改
|
||||
* @author wr
|
||||
* @date 2023-02-27 14:02
|
||||
* @param param
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean updateTerminal(TerminalParam.TerminalUpdateParam param);
|
||||
|
||||
/***
|
||||
* 终端检测监督删除
|
||||
* @author wr
|
||||
* @date 2023-02-27 14:02
|
||||
* @param ids
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean dekTerminal(List<String> ids);
|
||||
|
||||
/***
|
||||
* 批量导入检测报告
|
||||
* @author wr
|
||||
* @date 2023-02-28 9:55
|
||||
* @param files
|
||||
* @param response
|
||||
*/
|
||||
void importReport(MultipartFile[] files, HttpServletResponse response);
|
||||
|
||||
/***
|
||||
* 终端入网检测台账统计
|
||||
* @author wr
|
||||
* @date 2023-02-28 11:03
|
||||
* @param param
|
||||
* @return List<TerminalStatistics>
|
||||
*/
|
||||
List<TerminalVO.TerminalStatistics> getStatistics(TerminalParam param);
|
||||
|
||||
/***
|
||||
* 周期检测统计
|
||||
* @author wr
|
||||
* @date 2023-02-28 13:48
|
||||
* @param param
|
||||
* @return List<TerminalStatistics>
|
||||
*/
|
||||
List<TerminalVO.TerminalStatistics> getCycleStatistics(TerminalParam.TerminalCycleParam param);
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
package com.njcn.process.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.pms.enums.PmsDeviceResponseEnum;
|
||||
import com.njcn.poi.excel.ExcelUtil;
|
||||
import com.njcn.poi.util.PoiUtil;
|
||||
import com.njcn.process.pojo.dto.excel.TerminalExcel;
|
||||
import com.njcn.process.pojo.param.TerminalParam;
|
||||
import com.njcn.process.pojo.po.PmsTerminalDetection;
|
||||
import com.njcn.process.mapper.PmsTerminalDetectionMapper;
|
||||
import com.njcn.process.pojo.vo.TerminalVO;
|
||||
import com.njcn.process.service.PmsTerminalDetectionService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.process.utils.ExcelStyleUtil;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.dto.DeptDTO;
|
||||
import com.njcn.user.pojo.vo.PvTerminalTreeVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 终端检测监督
|
||||
* </p>
|
||||
*
|
||||
* @author wr
|
||||
* @since 2023-02-27
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PmsTerminalDetectionServiceImpl extends ServiceImpl<PmsTerminalDetectionMapper, PmsTerminalDetection> implements PmsTerminalDetectionService {
|
||||
|
||||
private final DeptFeignClient deptFeignClient;
|
||||
|
||||
@Override
|
||||
public Page<TerminalVO> terminalPage(TerminalParam.TerminalPageParam param) {
|
||||
Page<PmsTerminalDetection> pageList = this.page(new Page<>(param.getPageNum(), param.getPageSize())
|
||||
, new LambdaQueryWrapper<PmsTerminalDetection>()
|
||||
.eq(PmsTerminalDetection::getStatus, DataStateEnum.ENABLE.getCode())
|
||||
// .in(RMpWpPowerDetailQ::getMeasurementPointId, monitorIds)
|
||||
.le(param.getType() != 0, PmsTerminalDetection::getNextInspectionTime, LocalDate.now())
|
||||
// .le(StrUtil.isNotBlank(param.getEndTime()), PmsTerminalDetection::getDataDate, param.getEndTime())
|
||||
);
|
||||
List<TerminalVO> rMpWpPowerDetailVOS2 = BeanUtil.copyToList(pageList.getRecords(), TerminalVO.class);
|
||||
|
||||
Page<TerminalVO> page = BeanUtil.copyProperties(pageList, Page.class);
|
||||
page.setRecords(rMpWpPowerDetailVOS2);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportTemplate(HttpServletResponse response) {
|
||||
ExportParams exportParams = new ExportParams("批量导入模板(请严格按照模板标准填入数据)", "终端入网检测录入信息");
|
||||
exportParams.setStyle(ExcelStyleUtil.class);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, TerminalExcel.class, new ArrayList<TerminalExcel>());
|
||||
PoiUtil.exportFileByWorkbook(workbook, "终端入网检测录入模板.xlsx", response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertTerminal(TerminalParam param) {
|
||||
PmsTerminalDetection detection = BeanUtil.copyProperties(param, PmsTerminalDetection.class);
|
||||
|
||||
return this.save(detection);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchTerminal(MultipartFile file, HttpServletResponse response) {
|
||||
ImportParams params = new ImportParams();
|
||||
params.setHeadRows(1);
|
||||
params.setTitleRows(1);
|
||||
params.setNeedVerify(true);
|
||||
//第一个sheet为台账信息
|
||||
params.setStartSheetIndex(0);
|
||||
params.setSheetNum(1);
|
||||
try {
|
||||
ExcelImportResult<TerminalExcel> terminalList = ExcelImportUtil.importExcelMore(file.getInputStream(), TerminalExcel.class, params);
|
||||
//如果存在非法数据,将不合格的数据导出
|
||||
if (terminalList.isVerifyFail()) {
|
||||
PoiUtil.exportFileByWorkbook(terminalList.getFailWorkbook(), "非法终端入网检测录入信息.xlsx", response);
|
||||
} else {
|
||||
saveTerminalBase(terminalList.getList());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateTerminal(TerminalParam.TerminalUpdateParam param) {
|
||||
long count = this.count(new LambdaQueryWrapper<PmsTerminalDetection>()
|
||||
.ne(PmsTerminalDetection::getId, param.getId())
|
||||
.and(wrapper ->
|
||||
wrapper.eq(PmsTerminalDetection::getName, param.getName())
|
||||
)
|
||||
|
||||
);
|
||||
if (count > 0) {
|
||||
throw new BusinessException(PmsDeviceResponseEnum.MODEL_NAME_REPEAT);
|
||||
}
|
||||
PmsTerminalDetection detection = BeanUtil.copyProperties(param, PmsTerminalDetection.class);
|
||||
return this.updateById(detection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean dekTerminal(List<String> ids) {
|
||||
return this.removeByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importReport(MultipartFile[] files, HttpServletResponse response) {
|
||||
PmsTerminalDetection detection;
|
||||
List<PmsTerminalDetection> data = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
detection = new PmsTerminalDetection();
|
||||
//上传的文件名称
|
||||
String originalFilename = files[i].getOriginalFilename();
|
||||
String[] split = originalFilename.split("-");
|
||||
if (split.length > 0) {
|
||||
if (split[1].substring(0, split[1].indexOf(".")).equals("检测报告")) {
|
||||
//todo 文件名称
|
||||
detection.setInspectionReport(originalFilename);
|
||||
detection.setId(split[0]);
|
||||
data.add(detection);
|
||||
}
|
||||
if (split[1].substring(0, split[1].indexOf(".")).equals("原始数据报告")) {
|
||||
//todo 文件名称
|
||||
detection.setOriginalReport(originalFilename);
|
||||
detection.setId(split[0]);
|
||||
data.add(detection);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(data)) {
|
||||
Map<String, PmsTerminalDetection> terminalMap = data.stream().collect(Collectors.toMap(PmsTerminalDetection::getId, Function.identity(), (key1, key2) -> {
|
||||
//检测报告告为空
|
||||
if (key1.getInspectionReport() == null) {
|
||||
key1.setInspectionReport(key2.getInspectionReport());
|
||||
}
|
||||
//原始数据报告为空
|
||||
if (key1.getOriginalReport() == null) {
|
||||
key1.setOriginalReport(key2.getOriginalReport());
|
||||
}
|
||||
return key1;
|
||||
}));
|
||||
List<PmsTerminalDetection> updateTerminal = new ArrayList<>(terminalMap.values());
|
||||
this.updateBatchById(updateTerminal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TerminalVO.TerminalStatistics> getStatistics(TerminalParam param) {
|
||||
List<DeptDTO> deptDTOS = deptFeignClient.getDepSonDetailByDeptId(param.getId()).getData();
|
||||
List<String> ids = deptDTOS.stream().map(DeptDTO::getCode).collect(Collectors.toList());
|
||||
List<TerminalVO.TerminalStatistics> list = this.baseMapper.selectStatistics(param, ids);
|
||||
return getStatisticsList(deptDTOS, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TerminalVO.TerminalStatistics> getCycleStatistics(TerminalParam.TerminalCycleParam param) {
|
||||
List<DeptDTO> deptDTOS = deptFeignClient.getDepSonDetailByDeptId(param.getId()).getData();
|
||||
List<String> ids = deptDTOS.stream().map(DeptDTO::getCode).collect(Collectors.toList());
|
||||
List<TerminalVO.TerminalStatistics> list = this.baseMapper.selectCycleStatistics(param, ids);
|
||||
return getStatisticsList(deptDTOS, list);
|
||||
}
|
||||
|
||||
/***
|
||||
* 统计数据,单位名称赋值
|
||||
* @author wr
|
||||
* @date 2023-02-28 14:04
|
||||
* @param deptDTOS
|
||||
* @param list
|
||||
* @return List<TerminalStatistics>
|
||||
*/
|
||||
private List<TerminalVO.TerminalStatistics> getStatisticsList(List<DeptDTO> deptDTOS, List<TerminalVO.TerminalStatistics> list) {
|
||||
Map<String, String> deptMap = deptDTOS.stream().collect(Collectors.toMap(DeptDTO::getCode, DeptDTO::getName));
|
||||
for (TerminalVO.TerminalStatistics t : list) {
|
||||
if (deptMap.containsKey(t.getOrgNo())) {
|
||||
t.setOrgName(deptMap.get(t.getOrgNo()));
|
||||
}
|
||||
}
|
||||
Map<String, TerminalVO.TerminalStatistics> listMap = list.stream().collect(
|
||||
Collectors.toMap(TerminalVO.TerminalStatistics::getOrgNo, Function.identity()));
|
||||
|
||||
List<DeptDTO> notDeptDTOS = deptDTOS.stream().filter(r -> !listMap.containsKey(r.getCode()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(notDeptDTOS)) {
|
||||
TerminalVO.TerminalStatistics notTerminal;
|
||||
for (DeptDTO notDeptDTO : notDeptDTOS) {
|
||||
notTerminal = new TerminalVO.TerminalStatistics();
|
||||
notTerminal.setOrgNo(notDeptDTO.getCode());
|
||||
notTerminal.setOrgName(notDeptDTO.getName());
|
||||
notTerminal.setCount(0);
|
||||
list.add(notTerminal);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/***
|
||||
* 批量导入t终端入网检测信息
|
||||
* @author wr
|
||||
* @date 2023-02-28 14:05
|
||||
* @param terminalList
|
||||
*/
|
||||
private void saveTerminalBase(List<TerminalExcel> terminalList) {
|
||||
List<PvTerminalTreeVO> data = deptFeignClient.allDeptList().getData();
|
||||
List<PmsTerminalDetection> list = this.list(new LambdaQueryWrapper<PmsTerminalDetection>()
|
||||
.eq(PmsTerminalDetection::getStatus, DataStateEnum.ENABLE.getCode()));
|
||||
Map<String, PmsTerminalDetection> terminalMap = list.stream().collect(Collectors.toMap(p -> p.getId(), Function.identity()));
|
||||
List<TerminalExcel.TerminalExcelMsg> terminalExcelMsg = new ArrayList<>();
|
||||
//错误数据初始化
|
||||
TerminalExcel.TerminalExcelMsg msg = null;
|
||||
List<PmsTerminalDetection> pmsTerminalDetections = new ArrayList<>();
|
||||
//正常数据
|
||||
PmsTerminalDetection detection;
|
||||
for (TerminalExcel terminalExcel : terminalList) {
|
||||
//根据终端编号和终端名称判断数据是否又重复终端
|
||||
if (terminalMap.containsKey(terminalExcel.getId())) {
|
||||
addMsg(terminalExcelMsg, terminalExcel, msg, "当前终端编号重复");
|
||||
continue;
|
||||
}
|
||||
String orgName = terminalExcel.getOrgName();
|
||||
//判断
|
||||
List<PvTerminalTreeVO> deptList = data.stream().filter(d ->
|
||||
d.getName().indexOf(orgName) > -1
|
||||
).collect(Collectors.toList());
|
||||
if (CollectionUtil.isEmpty(deptList)) {
|
||||
addMsg(terminalExcelMsg, terminalExcel, msg, "当前部门机构不存在");
|
||||
continue;
|
||||
}
|
||||
if (deptList.size() > 1) {
|
||||
addMsg(terminalExcelMsg, terminalExcel, msg, "当前部门机构模糊匹配出现多个部门,请详细编写部门机构");
|
||||
continue;
|
||||
}
|
||||
detection = BeanUtil.copyProperties(terminalExcel, PmsTerminalDetection.class);
|
||||
detection.setOrgNo(deptList.get(0).getCode());
|
||||
detection.setOrgName(deptList.get(0).getName());
|
||||
detection.setTestResults(0);
|
||||
detection.setStatus(1);
|
||||
pmsTerminalDetections.add(detection);
|
||||
}
|
||||
|
||||
this.saveBatch(pmsTerminalDetections);
|
||||
|
||||
//错误信息不为空,则以excel的形式输出到前台
|
||||
if (CollectionUtil.isNotEmpty(terminalExcelMsg)) {
|
||||
ExcelUtil.exportExcel("失败列表.xlsx", TerminalExcel.TerminalExcelMsg.class, terminalExcelMsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* 错误信息,赋值
|
||||
* @author wr
|
||||
* @date 2023-02-28 14:05
|
||||
* @param terminalExcelMsg
|
||||
* @param terminalExcel
|
||||
* @param msg
|
||||
* @param content
|
||||
*/
|
||||
private void addMsg(List<TerminalExcel.TerminalExcelMsg> terminalExcelMsg, TerminalExcel terminalExcel, TerminalExcel.TerminalExcelMsg msg, String content) {
|
||||
msg = BeanUtil.copyProperties(terminalExcel, TerminalExcel.TerminalExcelMsg.class);
|
||||
msg.setMsg(content);
|
||||
terminalExcelMsg.add(msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user