diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index 8a746918..3ab0011e 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -11,6 +11,7 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; import com.zc.business.constant.DeviceTypeConstants; import com.zc.business.domain.DcDevice; import com.zc.business.interfaces.OperationLog; @@ -30,6 +31,7 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; import java.util.*; @@ -182,6 +184,20 @@ public class DcDeviceController extends BaseController { } + /** + * 导出 + * @param response 响应 + * @param iotDevice 导入数据结果 + */ + @PreAuthorize("@ss.hasPermi('iot:device:export')") + @Log(title = "导出设备", businessType = BusinessType.EXPORT) + @PostMapping("export") + public void exportDevice(HttpServletResponse response, DcDevice iotDevice) { + List list = dcDeviceService.listDevice(iotDevice); + ExcelUtil util = new ExcelUtil<>(DcDevice.class); + util.exportExcel(response, list, "设备数据"); + } + //***********************************物联设备接口************************************** diff --git a/zc-business/src/main/java/com/zc/business/controller/DcEventImportantFileController.java b/zc-business/src/main/java/com/zc/business/controller/DcEventImportantFileController.java index 2ea37c94..29d8cf4a 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcEventImportantFileController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcEventImportantFileController.java @@ -9,16 +9,10 @@ import javax.servlet.http.HttpServletResponse; import com.zc.business.utils.PoiUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -86,7 +80,7 @@ public class DcEventImportantFileController extends BaseController { InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/importantTemplate.docx"); - XWPFDocument document = null; + XWPFDocument document = null; try { @@ -171,4 +165,12 @@ public class DcEventImportantFileController extends BaseController public AjaxResult getImportantFileStatus(@PathVariable("eventId") String eventId){ return dcEventImportantFileService.getImportantFileStatus(eventId); } + + @ApiOperation("生成重要事件文件内容") + @PostMapping("/generate") + public AjaxResult generate(@ApiParam(value="事件id", name="eventId", required=true) @RequestParam("eventId") String eventId, + @ApiParam(value="类型 1:初报,2续报,3终报", name="type", required=true) @RequestParam("type") String type){ + return dcEventImportantFileService.generate(eventId,type); + } + } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcDevice.java b/zc-business/src/main/java/com/zc/business/domain/DcDevice.java index ed37f702..0bd60eb7 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcDevice.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcDevice.java @@ -3,6 +3,7 @@ package com.zc.business.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; +import com.ruoyi.common.annotation.Excel; import com.zc.business.utils.StakeMarkUtils; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -28,55 +29,80 @@ public class DcDevice { public static final String ONLINE = "1"; @ApiModelProperty("ID") + @Excel(name = "设备ID") @TableId(value = "id", type = IdType.AUTO) private Long id; @ApiModelProperty("物联设备ID") + @Excel(name = "物联设备ID") private String iotDeviceId; @ApiModelProperty("组ID") + @Excel(name = "组ID") private Long groupId; @ApiModelProperty("产品ID") + @Excel(name = "产品ID") private Long productId; @ApiModelProperty("桩号") + @Excel(name = "桩号") private String stakeMark; @ApiModelProperty("方向1-上行(菏泽方向),2-中,3-下行(济南方向)") + @Excel(name = "方向") private String direction; @ApiModelProperty("设备名称") + @Excel(name = "设备名称") private String deviceName; @ApiModelProperty("设备编号") + @Excel(name = "设备编号") private String deviceCode; @ApiModelProperty("设备类型") + @Excel(name = "设备类型") private String deviceType; @ApiModelProperty("所属网段") + @Excel(name = "所属网段") private String networkSegment; @ApiModelProperty("设备图片") + @Excel(name = "设备图片") private String deviceImg; @ApiModelProperty("安装日期") + @Excel(name = "安装日期") private Date installationDate; @ApiModelProperty("生产日期") + @Excel(name = "生产日期") private Date productionDate; @ApiModelProperty("使用年限") + @Excel(name = "使用年限") private String durableYears; @ApiModelProperty("安装位置") + @Excel(name = "安装位置") private String installationSite; @ApiModelProperty("设备状态") + @Excel(name = "设备状态") private String deviceState; @ApiModelProperty("使用状态") + @Excel(name = "使用状态") private Integer useState; @ApiModelProperty("其他配置") + @Excel(name = "其他配置") private String otherConfig; @ApiModelProperty("备注") + @Excel(name = "备注") private String remark; @ApiModelProperty("设施归属类型(0:默认1: 道路沿线2:桥梁3: 隧道4:收费广场5: 收费站6: 服务区等") + @Excel(name = "设施归属类型") private String facilitiesType; @ApiModelProperty("设备ip") + @Excel(name = "设备ip") private String deviceIp; @ApiModelProperty("范围桩号") + @Excel(name = "范围桩号") private String stakeMarkRange; @ApiModelProperty("创建时间") + @Excel(name = "创建时间") private Date createTime; @ApiModelProperty("修改时间") + @Excel(name = "修改时间") private Date updateTime; @ApiModelProperty("子类型") + @Excel(name = "子类型") private String childType; @TableField(exist = false) private String longitude; diff --git a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java index 805ab2c3..77310221 100644 --- a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java +++ b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java @@ -16,6 +16,7 @@ import com.zc.business.enums.WarningSourceEnum; import com.zc.business.enums.WarningStateEnum; import com.zc.business.enums.WarningSubclassEnum; import com.zc.business.service.*; +import com.zc.common.core.websocket.WebSocketService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +39,8 @@ public class DeviceMessageHandler { private final int EVENT_STATE = 1; private final int EVENTEND_STATE = 4; private final int VISIBILITY_LEVEL = 8; + private final String DEVICE_STATE = "deviceState"; + private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Resource @@ -77,6 +80,7 @@ public class DeviceMessageHandler { // 批量更新设备状态 dcDeviceService.batchUpdate(dcDevices); + WebSocketService.broadcast(DEVICE_STATE, dcDevices); //推送设备状态更新 // 批量更新中间库设备状态 middleDatabaseService.updateMiddleDatabaseDeviceByList(dcDevices); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcEventImportantFileService.java b/zc-business/src/main/java/com/zc/business/service/IDcEventImportantFileService.java index 223b11de..bc862eb3 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcEventImportantFileService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcEventImportantFileService.java @@ -68,4 +68,15 @@ public interface IDcEventImportantFileService * @return 结果 */ AjaxResult getImportantFileStatus(String eventId); + + /** + * @Description 生成重要事件文件内容 + * + * @author liuwenge + * @date 2024/5/8 15:50 + * @param eventId 事件id + * @param type 类型 1:初报,2续报,3终报 + * @return com.ruoyi.common.core.domain.AjaxResult + */ + AjaxResult generate(String eventId,String type); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEventImportantFileServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEventImportantFileServiceImpl.java index 12513d6c..251de5de 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEventImportantFileServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEventImportantFileServiceImpl.java @@ -1,17 +1,20 @@ package com.zc.business.service.impl; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; +import java.util.HashSet; import java.util.List; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; -import com.zc.business.domain.DcEventProcess; +import com.zc.business.domain.*; +import com.zc.business.mapper.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.zc.business.mapper.DcEventImportantFileMapper; -import com.zc.business.domain.DcEventImportantFile; import com.zc.business.service.IDcEventImportantFileService; /** @@ -27,6 +30,16 @@ public class DcEventImportantFileServiceImpl implements IDcEventImportantFileSer private DcEventImportantFileMapper dcEventImportantFileMapper; @Autowired private DcEventProcessServiceImpl dcEventProcessService; + @Autowired + private DcEventServiceImpl dcEventService; + @Autowired + private DcEventMapper dcEventMapper; + @Autowired + private DcEventAccidentMapper dcEventAccidentMapper; + @Autowired + private DcEventTrafficCongestionMapper dcEventTrafficCongestionMapper; + @Autowired + private DcEventImportantMapper dcEventImportantMapper; /** * 查询重要事件文件内容 @@ -153,4 +166,226 @@ public class DcEventImportantFileServiceImpl implements IDcEventImportantFileSer return AjaxResult.success(num); } + /** + * @Description 生成重要事件文件内容 + * + * @author liuwenge + * @date 2024/5/8 15:51 + * @param eventId 事件id + * @param type 类型 1:初报,2续报,3终报 + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @Override + public AjaxResult generate(String eventId,String type){ + + if (StringUtils.isEmpty(eventId) || StringUtils.isEmpty(type)){ + return AjaxResult.error("参数错误!"); + } + DcEvent dcEvent = dcEventMapper.selectDcEventById(eventId); + if (dcEvent == null){ + return AjaxResult.error("事件查询失败,请检查事件id是否正确!"); + } + String eventType = dcEvent.getEventType().toString(); + if ("1".equals(eventType) && "4".equals(eventType)){ + return AjaxResult.error("事件类型错误!"); + } + + DcEventImportantFile dcEventImportantFile = new DcEventImportantFile(); + dcEventImportantFile.setFromDept("齐鲁高速股份有限公司"); + SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分"); + String createTime = df.format(new Date()); + dcEventImportantFile.setCreateTime(createTime); + + String title = "关于G35济菏高速" + dcEvent.getStakeMark() + dcEvent.getStringEventType(); + if ("1".equals(type)){ + title += "的初报"; + } else if ("2".equals(type)){ + title += "的续报"; + } else if ("3".equals(type)){ + title += "的终报"; + } + dcEventImportantFile.setTitle(title); + + dcEventImportantFile.setToDept("智慧管理中心:"); + + String content = "\t" + df.format(dcEvent.getOccurrenceTime()) + ",G35济菏高速" + dcEvent.getStakeMark(); + if ("1".equals(dcEvent.getDirection()) || "菏泽方向".equals(dcEvent.getDirection())) { + content += "菏泽方向"; + } else if ("3".equals(dcEvent.getDirection()) || "济南方向".equals(dcEvent.getDirection())) { + content += "济南方向"; + } + content += "发生"; + if ("1-1".equals(dcEvent.getEventSubclass()) || "追尾".equals(dcEvent.getEventSubclass())) { + content += "追尾"; + } else if ("1-2".equals(dcEvent.getEventSubclass()) || "侧翻".equals(dcEvent.getEventSubclass())) { + content += "侧翻"; + } else if ("1-3".equals(dcEvent.getEventSubclass()) || "撞护栏".equals(dcEvent.getEventSubclass())) { + content += "撞护栏"; + } else if ("1-4".equals(dcEvent.getEventSubclass()) || "自燃".equals(dcEvent.getEventSubclass())) { + content += "自燃"; + } else if ("1-5".equals(dcEvent.getEventSubclass()) || "其他事故".equals(dcEvent.getEventSubclass())){ + content += "其他"; + } else if ("4-1".equals(dcEvent.getEventSubclass()) || "道路拥堵".equals(dcEvent.getEventSubclass())){ + content += "道路拥堵"; + } else if ("4-2".equals(dcEvent.getEventSubclass()) || "立交拥堵".equals(dcEvent.getEventSubclass())){ + content += "立交拥堵"; + } else if ("4-3".equals(dcEvent.getEventSubclass()) || "收费站拥堵".equals(dcEvent.getEventSubclass())){ + content += "收费站拥堵"; + } else if ("4-4".equals(dcEvent.getEventSubclass()) || "服务区拥堵".equals(dcEvent.getEventSubclass())){ + content += "服务区拥堵"; + } + content += "事故。"; + + if ("1".equals(type) || "2".equals(type)) { + + //占用车道 + if (StringUtils.isNotEmpty(dcEvent.getLang())) { + String[] langArr = dcEvent.getLang().split(","); + content += "事故占用"; + for (String lang : langArr) { + if ("0".equals(lang)) { + content += "应急车道、"; + } else if ("1".equals(lang)) { + content += "行1车道、"; + } else if ("2".equals(lang)) { + content += "行2车道、"; + } else if ("3".equals(lang)) { + content += "行3车道、"; + } else if ("4".equals(lang)) { + content += "行4车道、"; + } + } + content = content.substring(0, content.length() - 1); + content += ","; + + String[] langAll = {"1", "2", "3", "4", "0"}; + HashSet diff = new HashSet<>(Arrays.asList(langAll)); + diff.removeAll(Arrays.asList(langArr)); + for (String s : diff) { + if ("0".equals(s)) { + content += "应急车道、"; + } else if ("1".equals(s)) { + content += "行1车道、"; + } else if ("2".equals(s)) { + content += "行2车道、"; + } else if ("3".equals(s)) { + content += "行3车道、"; + } else if ("4".equals(s)) { + content += "行4车道、"; + } + } + content = content.substring(0, content.length() - 1); + content += "正常通行,"; + + + } else { + content += "行1车道、行2车道、行3车道、行4车道、应急车道正常通行,"; + } + + //压车情况 + if ("1".equals(eventType)) { + DcEventAccident dcEventAccident = dcEventAccidentMapper.selectDcEventAccidentById(eventId); + if (dcEventAccident != null && dcEventAccident.getTrafficJam() != null && dcEventAccident.getTrafficJam() > 0f) { + content += "压车" + dcEventAccident.getTrafficJam() + "公里。\n\t"; + } else { + content += "无压车。\n\t"; + } + } else if ("4".equals(eventType)){ + DcEventTrafficCongestion dcEventTrafficCongestion = dcEventTrafficCongestionMapper.selectDcEventTrafficCongestionById(eventId); + if (dcEventTrafficCongestion != null && dcEventTrafficCongestion.getCongestionMileage() != null && dcEventTrafficCongestion.getCongestionMileage() > 0f) { + content += "压车" + dcEventTrafficCongestion.getCongestionMileage() + "公里。\n\t"; + } else { + content += "无压车。\n\t"; + } + } + + //到达现场情况 + DcEventImportant dcEventImportant = dcEventImportantMapper.selectDcEventImportantByEventId(eventId); + if (dcEventImportant == null){ + dcEventImportant = new DcEventImportant(); + dcEventImportant.setEventId(eventId); + dcEventImportant.setTrafficPoliceStatus(0); + dcEventImportant.setMedicalStatus(0); + dcEventImportant.setFireStatus(0); + dcEventImportant.setBoardStatus(0); + dcEventImportantMapper.insertDcEventImportant(dcEventImportant); + } + if (StringUtils.isNotEmpty(dcEventImportant.getPlateNumber())) { + content += "现场事故车辆及车牌号信息:" + dcEventImportant.getPlateNumber() + "。"; + } + + String arrived = ""; + String notArrived = "路管、"; + if (dcEventImportant.getTrafficPoliceStatus() == 1) { + arrived += "交警、"; + } else { + notArrived += "交警、"; + } + if (dcEventImportant.getMedicalStatus() == 1) { + arrived += "医疗、"; + } else { + notArrived += "医疗、"; + } + if (dcEventImportant.getFireStatus() == 1) { + arrived += "消防、"; + } else { + notArrived += "消防、"; + } + if (arrived.length() > 0) { + arrived = arrived.substring(0, arrived.length() - 1); + content += arrived + "等单位已到达现场。"; + } + + + if (StringUtils.isNotEmpty(dcEventImportant.getCurrentProgress())) { + content += "事故目前处置进度为" + dcEventImportant.getCurrentProgress() + "。"; + } + if (StringUtils.isNotEmpty(dcEventImportant.getTakeSteps())) { + content += "已采取的措施:" + dcEventImportant.getTakeSteps() + "。"; + } + if (StringUtils.isNotEmpty(dcEventImportant.getDiversionPoint())) { + content += "在" + dcEventImportant.getDiversionPoint() + "进行分流。"; + } + + if (dcEventImportant.getBoardStatus() == 1) { + content += "事故点后方情报板已经做好信息提示。"; + } + content += "\n"; + + notArrived = notArrived.substring(0, notArrived.length() - 1); + content += "\t" + notArrived + "等单位正在赶往现场。"; + + if ("1".equals(type)) { + content += "具体情况稍后报告。"; + } else if ("2".equals(type)) { + if (dcEvent.getEstimatedEndTime() != null) { + SimpleDateFormat dateFormat = new SimpleDateFormat("HH时mm分"); + content += "预计结束时间为" + dateFormat.format(dcEvent.getEstimatedEndTime()) + "。"; + } + } + + dcEventImportantFile.setContent(content); + + + } else if ("3".equals(type)){ + content += "\n\t"; + SimpleDateFormat dateFormat = new SimpleDateFormat("HH时mm分"); + content += dateFormat.format(new Date()) + ",事故处理完毕,道路恢复畅通。"; + dcEventImportantFile.setContent(content); + + } else { + return AjaxResult.error("文件类型错误!"); + } + + + SysUser user = SecurityUtils.getLoginUser().getUser(); + dcEventImportantFile.setCreateName(user.getNickName()); + dcEventImportantFile.setPhoneNumber(user.getPhonenumber()); + dcEventImportantFile.setType(type); + dcEventImportantFile.setStatus("0"); + dcEventImportantFile.setEventId(eventId); + + return AjaxResult.success(dcEventImportantFile); + } + } diff --git a/zc-business/src/main/java/com/zc/business/utils/PoiUtil.java b/zc-business/src/main/java/com/zc/business/utils/PoiUtil.java index 5727021c..a85915f2 100644 --- a/zc-business/src/main/java/com/zc/business/utils/PoiUtil.java +++ b/zc-business/src/main/java/com/zc/business/utils/PoiUtil.java @@ -516,7 +516,17 @@ public class PoiUtil { //判断key在Map中是否存在 if (textMap.containsKey(runsText)) { if (value != null) { - run.setText(value.toString(), 0); + String valueStr = value.toString().replaceAll("\\\\t"," "); + String[] valueArr = valueStr.split("\\\\n"); + if (valueArr.length > 1) { + for (int index = 0; index < valueArr.length; index++) { + run.setText(valueArr[index], index); + run.addCarriageReturn(); + } + } else { + run.setText(valueStr,0); + } + } else { run.setText("", 0); }