diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsLedgerFeignClient.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsLedgerFeignClient.java index a41d350..38a3f4d 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsLedgerFeignClient.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsLedgerFeignClient.java @@ -33,6 +33,5 @@ public interface CsLedgerFeignClient { HttpResult> queryLine(@RequestBody @Validated LineParamDTO lineParamdto); @PostMapping("/queryDevDetail") - HttpResult queryDevDetail(@RequestParam("devId") String devId); } diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAddParm.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAddParm.java index 95679dd..519d714 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAddParm.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAddParm.java @@ -64,36 +64,36 @@ public class CsEquipmentDeliveryAddParm{ @NotBlank(message="装置程序版本不能为空!") private String programVersion; - /** - * 调试人员 - */ - @ApiModelProperty(value="调试人员") - @NotBlank(message="调试人员不能为空!") - private String debugPerson; - - /** - * 出厂日期 - */ - @ApiModelProperty(value="出厂日期") - @NotNull(message="出厂日期不能为空!") - @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") - private Date producteTime; - - /** - * 检修日期 - */ - @ApiModelProperty(value="检修日期") - @NotNull(message="检修日期不能为空!") - @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") - private Date checkTime; - - /** - * 调试日期 - */ - @ApiModelProperty(value="调试日期") - @NotNull(message="调试日期不能为空!") - @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") - private Date debugTime; +// /** +// * 调试人员 +// */ +// @ApiModelProperty(value="调试人员") +// @NotBlank(message="调试人员不能为空!") +// private String debugPerson; +// +// /** +// * 出厂日期 +// */ +// @ApiModelProperty(value="出厂日期") +// @NotNull(message="出厂日期不能为空!") +// @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") +// private Date producteTime; +// +// /** +// * 检修日期 +// */ +// @ApiModelProperty(value="检修日期") +// @NotNull(message="检修日期不能为空!") +// @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") +// private Date checkTime; +// +// /** +// * 调试日期 +// */ +// @ApiModelProperty(value="调试日期") +// @NotNull(message="调试日期不能为空!") +// @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") +// private Date debugTime; /** * 合同号 @@ -101,11 +101,11 @@ public class CsEquipmentDeliveryAddParm{ @ApiModelProperty(value="合同号") private String cntractNo; - /** - * 营销经理 - */ - @ApiModelProperty(value="营销经理") - private String salesManager; +// /** +// * 营销经理 +// */ +// @ApiModelProperty(value="营销经理") +// private String salesManager; /** * 装置接入方式 diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAuditParm.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAuditParm.java index 34a66d9..de03bbb 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAuditParm.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/CsEquipmentDeliveryAuditParm.java @@ -66,32 +66,32 @@ public class CsEquipmentDeliveryAuditParm { @ApiModelProperty(value="装置程序版本") private String programVersion; - /** - * 调试人员 - */ - @ApiModelProperty(value="调试人员") - private String debugPerson; - - /** - * 出厂日期 - */ - @ApiModelProperty(value="出厂日期") - @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") - private Date producteTime; - - /** - * 检修日期 - */ - @ApiModelProperty(value="检修日期") - @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") - private Date checkTime; - - /** - * 调试日期 - */ - @ApiModelProperty(value="调试日期") - @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") - private Date debugTime; +// /** +// * 调试人员 +// */ +// @ApiModelProperty(value="调试人员") +// private String debugPerson; +// +// /** +// * 出厂日期 +// */ +// @ApiModelProperty(value="出厂日期") +// @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") +// private Date producteTime; +// +// /** +// * 检修日期 +// */ +// @ApiModelProperty(value="检修日期") +// @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") +// private Date checkTime; +// +// /** +// * 调试日期 +// */ +// @ApiModelProperty(value="调试日期") +// @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") +// private Date debugTime; /** * 合同号 @@ -99,11 +99,11 @@ public class CsEquipmentDeliveryAuditParm { @ApiModelProperty(value="合同号") private String cntractNo; - /** - * 营销经理 - */ - @ApiModelProperty(value="营销经理") - private String salesManager; +// /** +// * 营销经理 +// */ +// @ApiModelProperty(value="营销经理") +// private String salesManager; /** * 状态 diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/DeviceExcelTemplete.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/DeviceExcelTemplete.java new file mode 100644 index 0000000..fe56fbb --- /dev/null +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/param/DeviceExcelTemplete.java @@ -0,0 +1,74 @@ +package com.njcn.csdevice.pojo.param; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * Description: + * 接口文档访问地址:http://serverIP:port/swagger-ui.html + * Date: 2022/11/21 9:35【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +@Data +public class DeviceExcelTemplete implements Serializable { + + + + + /** + * 装置名称 + */ + @Excel(name = "装置名称", width = 15) + private String name; + + /** + * 网关识别码 + */ + @Excel(name = "网关识别码", width = 15) + private String ndid; + + /** + * 装置类型(直连设备、网关设备、装置) + */ + @Excel(name = "装置类型(直连设备,网关设备)", width = 30) + private String devType; + + /** + * 装置型号(pqs588、pqs680...) + */ + @Excel(name = "装置型号", width = 15) + private String devModel; + + /** + * 装置接入方式(mqtt、cloud) + */ + @Excel(name = "装置接入方式(mqtt、cloud)", width = 25) + private String devAccessMethod; + + /** + * 合同号 + */ + @Excel(name = "合同号", width = 15) + private String cntractNo; + + @EqualsAndHashCode(callSuper = true) + + public static class IllegalityDeviceExcelTemplete extends DeviceExcelTemplete implements Serializable { + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + @Excel(name = "错误信息描述", width = 30) + private String msg; + } + +} diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsEquipmentDeliveryPO.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsEquipmentDeliveryPO.java index df37099..3fda285 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsEquipmentDeliveryPO.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsEquipmentDeliveryPO.java @@ -107,7 +107,7 @@ public class CsEquipmentDeliveryPO extends BaseEntity { private String qrPath; /** - * 二维码文件路径 + * 设备当前流程(1:设备登记,2:功能调试,3:出厂调试),4:设备投运) */ @TableField(value = "process") private String process; diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/utils/ExcelStyleUtil.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/utils/ExcelStyleUtil.java new file mode 100644 index 0000000..8dd05e5 --- /dev/null +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/utils/ExcelStyleUtil.java @@ -0,0 +1,158 @@ +package com.njcn.csdevice.utils; + +import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; +import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; +import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.*; + +/** + * pqs + * + * @author cdf + * @date 2022/7/4 + */ +public class ExcelStyleUtil implements IExcelExportStyler { + // 数据行类型 + private static final String DATA_STYLES = "dataStyles"; + // 标题类型 + private static final String TITLE_STYLES = "titleStyles"; + //头样式 + private static final String HEADER_STYLES = "headerStyles"; + + //数据行样式 + private CellStyle styles; + // 标题样式 + private CellStyle titleStyle; + + // 标题样式 + private CellStyle headerStyle; + + public ExcelStyleUtil(Workbook workbook) { + this.init(workbook); + } + + private void init(Workbook workbook) { + this.styles = initStyles(workbook); + this.titleStyle = initTitleStyle(workbook); + this.headerStyle = initTitleStyle(workbook); + } + + + @Override + public CellStyle getHeaderStyle(short headerColor) { + return headerStyle; + } + + /** + * 标题样式 + */ + @Override + public CellStyle getTitleStyle(short i) { + return titleStyle; + } + + @Override + public CellStyle getStyles(boolean parity, ExcelExportEntity entity) { + return styles; + } + + /** + * 获取样式方法 + * + * @param dataRow 数据行 + * @param obj 对象 + * @param data 数据 + */ + @Override + public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) { + return getStyles(true, entity); + } + + @Override + public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) { + return null; + } + + + /** + * 初始化--标题行样式 + * @param workbook + * @return + */ + private CellStyle initTitleStyle(Workbook workbook) { + return buildCellStyle(workbook,TITLE_STYLES); + } + + /** + * 头样式 + * @author cdf + * @date 2022/7/4 + */ + private CellStyle initHeaderStyle(Workbook workbook) { + return buildCellStyle(workbook,HEADER_STYLES); + } + + /** + * 初始化--数据行样式 + * @param workbook + * @return + */ + private CellStyle initStyles(Workbook workbook) { + return buildCellStyle(workbook,DATA_STYLES); + } + + /** + * 设置单元格样式 + * @param workbook + * @param type 类型 用来区分是数据行样式还是标题样式 + * @return + */ + private CellStyle buildCellStyle(Workbook workbook,String type) { + CellStyle style = workbook.createCellStyle(); + // 字体样式 + Font font = workbook.createFont(); + if(TITLE_STYLES.equals(type)){ + font.setFontHeightInPoints((short)12); + font.setBold(true); + // 设置水平对齐的样式为居中对齐; + style.setAlignment(HorizontalAlignment.CENTER); + } + if(HEADER_STYLES.equals(type)){ + font.setFontHeightInPoints((short)12); + font.setBold(true); + // 设置水平对齐的样式为居中对齐; + style.setAlignment(HorizontalAlignment.LEFT); + } + if(DATA_STYLES.equals(type)){ + font.setFontHeightInPoints((short)10); + // 设置水平对齐的样式为居中对齐; + style.setAlignment(HorizontalAlignment.CENTER); + } + font.setFontName("Courier New"); + style.setFont(font); + // 设置底边框 + style.setBorderBottom(BorderStyle.THIN); + // 设置左边框 + style.setBorderLeft(BorderStyle.THIN); + // 设置右边框; + style.setBorderRight(BorderStyle.THIN); + // 设置顶边框; + style.setBorderTop(BorderStyle.THIN); + // 设置底边颜色 + style.setBottomBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex()); + // 设置左边框颜色; + style.setLeftBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex()); + // 设置右边框颜色; + style.setRightBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex()); + // 设置顶边框颜色; + style.setTopBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex()); + // 设置自动换行; + style.setWrapText(false); + + + // 设置垂直对齐的样式为居中对齐; + style.setVerticalAlignment(VerticalAlignment.CENTER); + return style; + } +} diff --git a/cs-device/cs-device-boot/pom.xml b/cs-device/cs-device-boot/pom.xml index ca39ed8..981a02e 100644 --- a/cs-device/cs-device-boot/pom.xml +++ b/cs-device/cs-device-boot/pom.xml @@ -102,6 +102,34 @@ core 3.3.3 + + common-poi + com.njcn + 1.0.0 + + + + + + org.apache.poi + poi + 4.1.1 + + + org.apache.poi + poi-scratchpad + 4.1.1 + + + org.apache.poi + poi-ooxml + 4.1.1 + + + org.apache.poi + poi-ooxml-schemas + 4.1.1 + com.google.zxing diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/EquipmentDeliveryController.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/EquipmentDeliveryController.java index ca1b7ff..2f049b5 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/EquipmentDeliveryController.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/EquipmentDeliveryController.java @@ -1,5 +1,7 @@ package com.njcn.csdevice.controller.equipment; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.njcn.common.pojo.annotation.OperateInfo; @@ -9,30 +11,34 @@ import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; import com.njcn.csdevice.enums.DeviceOperate; import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO; -import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAddParm; -import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAuditParm; -import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryQueryParm; -import com.njcn.csdevice.pojo.param.ProjectEquipmentQueryParm; +import com.njcn.csdevice.pojo.param.*; import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO; import com.njcn.csdevice.pojo.vo.DeviceManagerVO; import com.njcn.csdevice.pojo.vo.ProjectEquipmentVO; import com.njcn.csdevice.service.CsEquipmentDeliveryService; import com.njcn.csdevice.service.IMqttUserService; +import com.njcn.csdevice.utils.ExcelStyleUtil; +import com.njcn.poi.excel.ExcelUtil; +import com.njcn.poi.util.PoiUtil; + import com.njcn.web.advice.DeviceLog; import com.njcn.web.controller.BaseController; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.*; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; + +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Description: @@ -190,4 +196,29 @@ public class EquipmentDeliveryController extends BaseController { } + @ResponseBody + @ApiOperation("导出设备模板") + @GetMapping(value = "getExcelTemplate") + public HttpResult getExcelTemplate(HttpServletResponse response) { + String methodDescribe = getMethodDescribe("getExcelTemplate"); + + ExportParams exportParams = new ExportParams("批量导入模板(请严格按照模板标准填入数据)", "终端入网检测录入信息"); + exportParams.setStyle(ExcelStyleUtil.class); + Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DeviceExcelTemplete.class, new ArrayList()); + ExcelUtil.selectList(workbook, 2, 2, Stream.of("直连设备","网关设备").collect(Collectors.toList()).toArray(new String[]{})); + ExcelUtil.selectList(workbook, 4, 4, Stream.of("mqtt","cloud").collect(Collectors.toList()).toArray(new String[]{})); + String fileName = "设备模板.xlsx"; + ExportParams exportExcel = new ExportParams("设备模板", "设备模板"); + PoiUtil.exportFileByWorkbook(workbook, fileName, response); + return null; + } + + @ResponseBody + @ApiOperation("excel批量导入设备信息") + @PostMapping(value = "importEquipment") + public HttpResult importEquipment(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file, HttpServletResponse response) { + String methodDescribe = getMethodDescribe("importEquipment"); + csEquipmentDeliveryService.importEquipment(file, response); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java index af3f9dc..1cdec59 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java @@ -11,6 +11,9 @@ import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO; import com.njcn.csdevice.pojo.vo.DeviceManagerVO; import com.njcn.csdevice.pojo.vo.ProjectEquipmentVO; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; /** * @@ -89,4 +92,6 @@ public interface CsEquipmentDeliveryService extends IService terminalBaseList = ExcelImportUtil.importExcelMore (file.getInputStream ( ), DeviceExcelTemplete.class, params); + //如果存在非法数据,将不合格的数据导出 + List trueCollect = new ArrayList<> ( ); + List falseCollect = new ArrayList<> ( ); + + for (int i = 0; i < terminalBaseList.getList ( ).size ( ); i++) { + DeviceExcelTemplete deviceExcelTemplete = terminalBaseList.getList ( ).get (i); + CsEquipmentDeliveryPO po = this.queryEquipmentPOByndid (deviceExcelTemplete.getNdid ( )); + if(!Objects.isNull (po)){ + DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete(); + BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException); + idlegalityDeviceException.setMsg("NDID重复"); + falseCollect.add(idlegalityDeviceException); + } + if(Objects.equals(deviceExcelTemplete.getDevType(),DicDataEnum.GATEWAY_DEV.getName())){ + DictTreeVO data = dictTreeFeignClient.queryByCode(DicDataEnum.GATEWAY_DEV.getCode()).getData(); + deviceExcelTemplete.setDevType(data.getId()); + List data1 = dictTreeFeignClient.query(data.getId()).getData(); + Map collect = data1.stream().collect(Collectors.toMap(DictTreeVO::getCode, dictTreeVO -> dictTreeVO)); + if(collect.containsKey(deviceExcelTemplete.getDevModel())){ + deviceExcelTemplete.setDevModel(collect.get(deviceExcelTemplete.getDevModel()).getId()); + trueCollect.add(deviceExcelTemplete); + }else { + DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete(); + BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException); + idlegalityDeviceException.setMsg("装置型号不正确"); + falseCollect.add(idlegalityDeviceException); + } + } else if (Objects.equals(deviceExcelTemplete.getDevType(),DicDataEnum.CONNECT_DEV.getName())) { + DictTreeVO data = dictTreeFeignClient.queryByCode(DicDataEnum.CONNECT_DEV.getCode()).getData(); + deviceExcelTemplete.setDevType(data.getId()); + List data1 = dictTreeFeignClient.query(data.getId()).getData(); + Map collect = data1.stream().collect(Collectors.toMap(DictTreeVO::getCode, dictTreeVO -> dictTreeVO)); + if(collect.containsKey(deviceExcelTemplete.getDevModel())){ + deviceExcelTemplete.setDevModel(collect.get(deviceExcelTemplete.getDevModel()).getId()); + trueCollect.add(deviceExcelTemplete); + }else { + DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete(); + BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException); + idlegalityDeviceException.setMsg("装置型号不正确"); + falseCollect.add(idlegalityDeviceException); + } + }else { + DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete(); + BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException); + idlegalityDeviceException.setMsg("装置类型不正确"); + falseCollect.add(idlegalityDeviceException); + } + + + } + if (!CollectionUtils.isEmpty (trueCollect)) { + List collect = trueCollect.stream ( ).map (temp -> { + CsEquipmentDeliveryPO csEquipmentDeliveryPO = new CsEquipmentDeliveryPO ( ); + BeanUtils.copyProperties (temp, csEquipmentDeliveryPO); + String qr = this.createQr(temp.getNdid()); + csEquipmentDeliveryPO.setQrPath(qr); + String path = this.createPath(temp.getNdid()); + csEquipmentDeliveryPO.setMac(path); + csEquipmentDeliveryPO.setRunStatus(1); + csEquipmentDeliveryPO.setStatus("1"); + csEquipmentDeliveryPO.setProcess(1); + return csEquipmentDeliveryPO; + }).collect (Collectors.toList ( )); + this.saveOrUpdateBatch (collect, 500); + } + if (!CollectionUtils.isEmpty (falseCollect)) { + ExportParams exportExcel = new ExportParams ("批量导入模板(请严格按照模板标准填入数据)", "非法设备信息"); + Workbook workbook = ExcelExportUtil.exportExcel (exportExcel, DeviceExcelTemplete.IllegalityDeviceExcelTemplete.class, falseCollect); + PoiUtil.exportFileByWorkbook (workbook, "非法设备信息.xlsx", response); + + } + + } catch (Exception e) { + e.printStackTrace ( ); + } + } + + /** + * 根据ndid生成二维码 + * @param ndid + * @return + */ + private String createQr(String ndid){ + String filePath =""; + //生成二维码文件 + try { + QrParam qrParam = new QrParam(); + qrParam.setData(ndid); + BufferedImage bufferedImage = QRCodeUtil.getBufferedImage(JSONObject.toJSONString(qrParam)); + InputStream inputStream = bufferedImageToInputStream(bufferedImage); + String fileName = ndid + ".png"; + filePath = fileStorageUtil.uploadStream(inputStream,OssPath.APP_DEVICE_QR,fileName); + } catch (Exception e) { + e.printStackTrace(); + } + return filePath; + + } + public InputStream bufferedImageToInputStream(BufferedImage image) { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { @@ -322,4 +438,25 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl 0) { + //添加冒号分隔符 + output.append(StrPool.COLON); + } + if (i + 1 < nDid.length()) { + // 检查是否有足够的字符来分割成两组 + // 每两个字符添加到新字符串 + output.append(nDid.substring(i, i + 2)); + } else { + // 如果只剩一个字符,可以根据需要添加处理逻辑 + output.append(nDid.charAt(i)); + } + } + return output.toString(); + } } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java index 4daf738..141ec91 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java @@ -218,7 +218,7 @@ public class CsLedgerServiceImpl extends ServiceImpl i public DevDetailDTO queryDevDetail(String devId) { DevDetailDTO device = new DevDetailDTO(); CsLedger dev = this.findDataById(devId); - device.setEquipmentName(dev.getId()); + device.setEquipmentName(dev.getName()); device.setEquipmentId(devId); CsLedger project = this.findDataById(dev.getPid()); device.setProjectId(project.getId()); diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/param/CsEventUserQueryParam.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/param/CsEventUserQueryParam.java index ac1d097..3c92e54 100644 --- a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/param/CsEventUserQueryParam.java +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/param/CsEventUserQueryParam.java @@ -30,7 +30,7 @@ public class CsEventUserQueryParam { /** * 事件id */ - private String eventId; + private List eventIds; /** * 事件类型 */ diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/EventDetailVO.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/EventDetailVO.java index 07eacaf..dd5ceaa 100644 --- a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/EventDetailVO.java +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/EventDetailVO.java @@ -3,11 +3,14 @@ package com.njcn.csharmonic.pojo.vo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; import com.njcn.influx.pojo.dto.EventDataSetDTO; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; +import java.util.Date; import java.util.List; /** @@ -53,7 +56,9 @@ public class EventDetailVO { /** * 事件时间 */ - private LocalDateTime startTime; + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + private Date startTime; /** * 事件类型 diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventUserController.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventUserController.java index 655bb8f..9c4cabc 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventUserController.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventUserController.java @@ -41,4 +41,16 @@ public class EventUserController extends BaseController { Integer count = csEventUserPOService.queryEventCount(csEventUserQueryParam); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, count, methodDescribe); } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/updateStatus") + @ApiOperation("已读事件") + @ApiImplicitParam(name = "csEventUserQueryParam", value = "暂降事件查询参数", required = true) + public HttpResult updateStatus(@RequestBody CsEventUserQueryParam csEventUserQueryParam) { + String methodDescribe = getMethodDescribe("updateStatus"); + csEventUserPOService.updateStatus(csEventUserQueryParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); + } + + } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java index 0868dc1..218307e 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java @@ -13,6 +13,7 @@ import com.njcn.csharmonic.service.ILineTargetService; import com.njcn.csharmonic.service.StableDataService; import com.njcn.csharmonic.service.TemperatureService; import com.njcn.influx.pojo.dto.StatisticalDataDTO; +import com.njcn.redis.utils.RedisUtil; import com.njcn.system.api.CsStatisticalSetFeignClient; import com.njcn.system.pojo.po.EleEpdPqd; import lombok.AllArgsConstructor; @@ -47,6 +48,8 @@ public class MqttMessageHandler { private final CsStatisticalSetFeignClient csStatisticalSetFeignClient; private final StableDataService stableDataService; + private final RedisUtil redisUtil; + private final TemperatureService temperatureService; private final DecimalFormat df = new DecimalFormat("#0.000"); /** @@ -74,122 +77,129 @@ public class MqttMessageHandler { */ @MqttSubscribe(value = "/zl/askDevData/{devId}",qos = 1) public void responseTopoData(String topic, @NamedValue("devId") String devId, MqttMessage message, @Payload String payload) { - List result = new ArrayList<>(); - List tempList = new ArrayList<>(); - ExecutorService executorService = new ThreadPoolExecutor(40, 400, - 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(100, true), - Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy()); - List>> resultList = new ArrayList< Future>>(); + String topoDataJson =redisUtil.getStringByKey (devId); + if(StringUtils.isEmpty(topoDataJson)){ + List result = new ArrayList<>(); + List tempList = new ArrayList<>(); + ExecutorService executorService = new ThreadPoolExecutor(10, 100, + 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(100, true), + Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy()); + List>> resultList = new ArrayList< Future>>(); - //1.查询拓扑图配置的指标:拓扑图扑图配置:7677f94c749dedaff30f911949cbd724 - List data = csStatisticalSetFeignClient.queryStatisticalSelect("7677f94c749dedaff30f911949cbd724").getData(); - data.forEach(temp->{ - if(Objects.nonNull(temp.getHarmStart())&&Objects.nonNull(temp.getHarmEnd())){ - for (int i = temp.getHarmStart(); i < temp.getHarmEnd()+1; i++) { - CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam(); - commonStatisticalQueryParam.setDevId(devId); - commonStatisticalQueryParam.setStatisticalId(temp.getId()); - commonStatisticalQueryParam.setValueType("avg"); - commonStatisticalQueryParam.setFrequency(i+""); - Future> listFuture= executorService.submit(new TaskWithResult(commonStatisticalQueryParam)); - resultList.add(listFuture); - } + //1.查询拓扑图配置的指标:拓扑图扑图配置:7677f94c749dedaff30f911949cbd724 + List data = csStatisticalSetFeignClient.queryStatisticalSelect("7677f94c749dedaff30f911949cbd724").getData(); + data.forEach(temp->{ + if(Objects.nonNull(temp.getHarmStart())&&Objects.nonNull(temp.getHarmEnd())){ + for (int i = temp.getHarmStart(); i < temp.getHarmEnd()+1; i++) { + CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam(); + commonStatisticalQueryParam.setDevId(devId); + commonStatisticalQueryParam.setStatisticalId(temp.getId()); + commonStatisticalQueryParam.setValueType("avg"); + commonStatisticalQueryParam.setFrequency(i+""); + Future> listFuture= executorService.submit(new TaskWithResult(commonStatisticalQueryParam)); + resultList.add(listFuture); + } - }else { - CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam(); - commonStatisticalQueryParam.setDevId(devId); - commonStatisticalQueryParam.setStatisticalId(temp.getId()); - commonStatisticalQueryParam.setValueType("avg"); - Future> listFuture= executorService.submit(new TaskWithResult(commonStatisticalQueryParam)); - resultList.add(listFuture); - } + }else { + CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam(); + commonStatisticalQueryParam.setDevId(devId); + commonStatisticalQueryParam.setStatisticalId(temp.getId()); + commonStatisticalQueryParam.setValueType("avg"); + Future> listFuture= executorService.submit(new TaskWithResult(commonStatisticalQueryParam)); + resultList.add(listFuture); + } - }); - executorService.shutdown(); + }); + executorService.shutdown(); - resultList.forEach(temp->{ - try { - tempList.addAll(temp.get()); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } - }); - //过滤M相 - List m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); - m.stream().forEach(temp->{ - Stream.of("A","B","C").forEach(phase->{ - ThdDataVO thdDataVO = new ThdDataVO(); - BeanUtils.copyProperties(temp,thdDataVO); - thdDataVO.setPhase(phase); - result.add(thdDataVO); - }); - }); - //过滤谐波电流,谐波电压畸变率求平均值 - List thdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Pq_ThdU(%)")).collect(Collectors.toList()); - Map> collect = thdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); - collect.forEach((k,v)->{ - if(!CollectionUtil.isEmpty(v)){ - double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); - ThdDataVO thdDataVO = new ThdDataVO(); - BeanUtils.copyProperties(v.get(0),thdDataVO); - thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); - thdDataVO.setPhase("avg"); - result.add(thdDataVO); + resultList.forEach(temp->{ + try { + tempList.addAll(temp.get()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + }); + //过滤M相 + List m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); + m.stream().forEach(temp->{ + Stream.of("A","B","C").forEach(phase->{ + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(temp,thdDataVO); + thdDataVO.setPhase(phase); + result.add(thdDataVO); + }); + }); + //过滤谐波电流,谐波电压畸变率求平均值 + List thdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Pq_ThdU(%)")).collect(Collectors.toList()); + Map> collect = thdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); + collect.forEach((k,v)->{ + if(!CollectionUtil.isEmpty(v)){ + double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(v.get(0),thdDataVO); + thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); + thdDataVO.setPhase("avg"); + result.add(thdDataVO); - } - }); + } + }); - List thdV = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Pq_ThdI(%)")).collect(Collectors.toList()); - Map> collect1 = thdV.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); - collect1.forEach((k,v)->{ - if(!CollectionUtil.isEmpty(v)){ - double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); - ThdDataVO thdDataVO = new ThdDataVO(); - BeanUtils.copyProperties(v.get(0),thdDataVO); - thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); - thdDataVO.setPhase("avg"); - result.add(thdDataVO); + List thdV = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Pq_ThdI(%)")).collect(Collectors.toList()); + Map> collect1 = thdV.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); + collect1.forEach((k,v)->{ + if(!CollectionUtil.isEmpty(v)){ + double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(v.get(0),thdDataVO); + thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); + thdDataVO.setPhase("avg"); + result.add(thdDataVO); - } - }); - List apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList()); - Map> collect3 = apfThdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); - collect3.forEach((k,v)->{ - if(!CollectionUtil.isEmpty(v)){ - double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); - ThdDataVO thdDataVO = new ThdDataVO(); - BeanUtils.copyProperties(v.get(0),thdDataVO); - thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); - thdDataVO.setPhase("avg"); - result.add(thdDataVO); + } + }); + List apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList()); + Map> collect3 = apfThdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); + collect3.forEach((k,v)->{ + if(!CollectionUtil.isEmpty(v)){ + double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(v.get(0),thdDataVO); + thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); + thdDataVO.setPhase("avg"); + result.add(thdDataVO); - } - }); - List apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList()); - Map> collect4 = apfThdISys.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); - collect4.forEach((k,v)->{ - if(!CollectionUtil.isEmpty(v)){ - double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); - ThdDataVO thdDataVO = new ThdDataVO(); - BeanUtils.copyProperties(v.get(0),thdDataVO); - thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); - thdDataVO.setPhase("avg"); - result.add(thdDataVO); + } + }); + List apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList()); + Map> collect4 = apfThdISys.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); + collect4.forEach((k,v)->{ + if(!CollectionUtil.isEmpty(v)){ + double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(v.get(0),thdDataVO); + thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); + thdDataVO.setPhase("avg"); + result.add(thdDataVO); - } - }); + } + }); - List notM = tempList.stream().filter(temp -> !Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); + List notM = tempList.stream().filter(temp -> !Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); - result.addAll(notM); + result.addAll(notM); - Gson gson = new Gson(); - publisher.send("/zl/devData/"+devId,gson.toJson(result),1,false); + Gson gson = new Gson(); + topoDataJson = gson.toJson(result); + redisUtil.saveByKeyWithExpire(devId, (Object) topoDataJson,Long.valueOf(10*60)); + } + + + publisher.send("/zl/devData/"+devId,topoDataJson,1,false); } public String getCldidName( String cldid) { diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventUserPOService.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventUserPOService.java index 4eb2d33..ef2c6f9 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventUserPOService.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventUserPOService.java @@ -21,4 +21,6 @@ public interface CsEventUserPOService extends IService{ Integer queryEventCount(CsEventUserQueryParam csEventUserQueryParam); List queryUserEventList(CsEventUserQueryParam csEventUserQueryParam); - } + + void updateStatus(CsEventUserQueryParam csEventUserQueryParam); +} diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventUserPOServiceImpl.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventUserPOServiceImpl.java index cd8caa6..7980468 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventUserPOServiceImpl.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventUserPOServiceImpl.java @@ -49,4 +49,15 @@ public class CsEventUserPOServiceImpl extends ServiceImpl list = this.getBaseMapper().queryUserEventList(csEventUserQueryParam); return list; } + + @Override + public void updateStatus(CsEventUserQueryParam csEventUserQueryParam) { + if(CollectionUtil.isEmpty(csEventUserQueryParam.getEventIds())){ + return; + } + csEventUserQueryParam.setUserId(RequestUtil.getUserIndex()); + this.lambdaUpdate().in(CsEventUserPO::getEventId,csEventUserQueryParam.getEventIds()). + eq(CsEventUserPO::getUserId,csEventUserQueryParam.getUserId()). + set(CsEventUserPO::getStatus,1).update(); + } }