diff --git a/src/main/java/com/whdc/controller/AddressBookOldController.java b/src/main/java/com/whdc/controller/AddressBookOldController.java index 8cb1aa6..55124d0 100644 --- a/src/main/java/com/whdc/controller/AddressBookOldController.java +++ b/src/main/java/com/whdc/controller/AddressBookOldController.java @@ -91,6 +91,9 @@ public class AddressBookOldController { List list = service.lambdaQuery() .list(); + for (AddressBookOld o : list) { + o.decryptPhone(); + } ExcelCommon.exportExcel(list, null, "防汛抗旱通讯录", AddressBookOld.class, "湖北省防汛抗旱通信录模版" + LocalDateTime.now() + ".xlsx", response); diff --git a/src/main/java/com/whdc/controller/WarnMsgFBController.java b/src/main/java/com/whdc/controller/WarnMsgFBController.java index 4b2a367..c37aa40 100644 --- a/src/main/java/com/whdc/controller/WarnMsgFBController.java +++ b/src/main/java/com/whdc/controller/WarnMsgFBController.java @@ -1,14 +1,19 @@ package com.whdc.controller; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.whdc.model.entity.AddressBookOld; +import com.whdc.model.entity.QXWarning; import com.whdc.model.entity.WarnMsgFB; import com.whdc.model.vo.ExcelOldDataVo; +import com.whdc.service.IAddressBookOldService; +import com.whdc.service.IQXWarningService; import com.whdc.service.IWarnMsgFBService; import com.whdc.utils.ExcelCommon; import com.whdc.utils.ResultJson; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; @@ -28,6 +33,11 @@ import java.util.stream.Collectors; public class WarnMsgFBController { @Autowired private IWarnMsgFBService service; + @Autowired + private IQXWarningService qxService; + + @Autowired + private IAddressBookOldService oldService; //增 @ApiOperation(value = "新增") @PostMapping(value = "/add") @@ -62,24 +72,64 @@ public class WarnMsgFBController { @PostMapping(value = "getExcelData") public ResultJson getExcelData(MultipartFile file) { - List appends = ExcelCommon.importExcel(file, 0, 1, WarnMsgFB.class); + List warnMsgs = ExcelCommon.importExcel(file,0, 1, WarnMsgFB.class); + List qxWarns = ExcelCommon.importExcel(file,1, 0, 1, QXWarning.class); + Map> qxByID = qxWarns.stream().collect(Collectors.groupingBy(QXWarning::getEffectId, Collectors.toList())); - service.saveBatch(appends); + List olds = oldService.list(); + Map> txlByName = olds.stream().collect(Collectors.groupingBy(AddressBookOld::getName, Collectors.toList())); - List warns = appends.stream().map(WarnMsgFB::getWarnid).collect(Collectors.toList()); + warnMsgs.forEach(o -> { + List qxWarnings = qxByID.get(o.getEffectId()); + if (CollectionUtils.isNotEmpty(qxWarnings)){ + QXWarning qxWarning = qxWarnings.get(0); + o.setHandleTime(qxWarning.getHandleTime()) + .setPublishTime(qxWarning.getPublishTime()) + .setWarnid(qxWarning.getWarnid()); + String name = o.getCalledPerson(); + List txl = txlByName.get(name); + if (CollectionUtils.isNotEmpty(txl)){ + o.setCalledPhone(txl.get(0).getPhone()); + }else{ + o.setCalledPhone(null); + } + } + }); + + + + List warns = warnMsgs.stream().map(WarnMsgFB::getWarnid).collect(Collectors.toList()); List list = service.lambdaQuery().in(WarnMsgFB::getWarnid, warns).list(); Map> map = list.stream().collect(Collectors.groupingBy(WarnMsgFB::getWarnid, Collectors.toList())); - map.forEach((k,v) ->{ - if (CollectionUtils.isNotEmpty(v) && v.size() > 1){ - for (int i = 1; i < v.size(); i++) { - service.removeById(v.get(i)); - } + List warnDb = Lists.newArrayList(); + for (WarnMsgFB warn : warnMsgs) { + Integer warnid = warn.getWarnid(); + if (!map.containsKey(warnid)){ + warnDb.add(warn); } - }); + } + if (CollectionUtils.isNotEmpty(warnDb)){ + service.saveBatch(warnDb); + } + + List qxwarns = qxWarns.stream().map(QXWarning::getWarnid).collect(Collectors.toList()); + List qxlist = qxService.lambdaQuery().in(QXWarning::getWarnid, qxwarns).list(); + Map> qxmap = qxlist.stream().collect(Collectors.groupingBy(QXWarning::getWarnid, Collectors.toList())); + + List qxDb = Lists.newArrayList(); + for (QXWarning qxWarn : qxWarns) { + Integer warnid = qxWarn.getWarnid(); + if (!qxmap.containsKey(warnid)){ + qxDb.add(qxWarn); + } + } + if (CollectionUtils.isNotEmpty(qxDb)){ + qxService.saveBatch(qxDb); + } return ResultJson.ok(); } } diff --git a/src/main/java/com/whdc/model/entity/QXWarning.java b/src/main/java/com/whdc/model/entity/QXWarning.java index bb571bb..0fe8415 100644 --- a/src/main/java/com/whdc/model/entity/QXWarning.java +++ b/src/main/java/com/whdc/model/entity/QXWarning.java @@ -1,5 +1,6 @@ package com.whdc.model.entity; +import cn.afterturn.easypoi.excel.annotation.Excel; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -24,51 +25,71 @@ public class QXWarning { @ApiModelProperty(value = "id") private Integer id; + @Excel(name = "createTime") @TableField("CREATE_TIME") @ApiModelProperty(value = "预警信息生成时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date createTime; + @Excel(name = "publishTime") @TableField("PUBLISH_TIME") @ApiModelProperty(value = "预警信息发布时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date publishTime; + @Excel(name = "startTime") @TableField("START_TIME") @ApiModelProperty(value = "预警信息开始时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date startTime; + @Excel(name = "endTime") @TableField("END_TIME") @ApiModelProperty(value = "预警信息结束时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date endTime; + @Excel(name = "warnSignalType") @ApiParam(value = "预警类型") @ApiModelProperty(value = "预警类型", dataType = "java.lang.String") private String warnSignalType; + @Excel(name = "warnSignalLevel") @ApiParam(value = "预警级别") @ApiModelProperty(value = "预警级别", dataType = "java.lang.String") private String warnSignalLevel; + @Excel(name = "publishUnit") @ApiParam(value = "发布单位") @ApiModelProperty(value = "发布单位", dataType = "java.lang.String") private String publishUnit; + @Excel(name = "content") @ApiParam(value = "预警内容") @ApiModelProperty(value = "预警内容", dataType = "java.lang.String") private String content; + @Excel(name = "Qx_Id") @TableField("WARNID") @ApiModelProperty(value = "预警信息ID") private Integer warnid; + @Excel(name = "effectArea_Big") @TableField("CTNM") @ApiModelProperty(value = "预警市名称", dataType = "java.lang.String") private String ctnm; + @Excel(name = "effectArea_Small") @TableField("CNNM") @ApiModelProperty(value = "预警县名称", dataType = "java.lang.String") private String cnnm; + + @Excel(name = "handleTime") + @TableField(exist = false) + @ApiModelProperty(value = "预警信息处理时间", dataType = "java.lang.String") + private Date handleTime; + + @TableField(exist = false) + @Excel(name = "Effect_Id") + private String effectId; } diff --git a/src/main/java/com/whdc/model/entity/WarnMsgFB.java b/src/main/java/com/whdc/model/entity/WarnMsgFB.java index 568a83b..6d36d3c 100644 --- a/src/main/java/com/whdc/model/entity/WarnMsgFB.java +++ b/src/main/java/com/whdc/model/entity/WarnMsgFB.java @@ -45,26 +45,30 @@ public class WarnMsgFB { @TableField("CALL_TIME") @ApiModelProperty(value = "预警信息呼叫时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - @Excel(name = "callTime") + @Excel(name = "Call_Time") private Date callTime; @TableField("CALLED_PERSON") @ApiModelProperty(value="被呼叫人姓名") - @Excel(name = "calledPerson") + @Excel(name = "Call_Name") private String calledPerson; @TableField("CALLED_POSITION") @ApiModelProperty(value="被呼叫人职务") - @Excel(name = "calledPosition") + @Excel(name = "Call_Deparment") private String calledPosition; @TableField("CALLED_PHONE") @ApiModelProperty(value="被呼叫人手机号") - @Excel(name = "calledPhone") + @Excel(name = "Call_Telephone") private String calledPhone; @TableField("CALL_PERSON") @ApiModelProperty(value="呼叫人姓名") - @Excel(name = "callPerson") + @Excel(name = "Call_User") private String callPerson; + + @TableField(exist = false) + @Excel(name = "Effect_Id") + private String effectId; } diff --git a/src/main/java/com/whdc/utils/ExcelCommon.java b/src/main/java/com/whdc/utils/ExcelCommon.java index 00a5ded..df167b1 100644 --- a/src/main/java/com/whdc/utils/ExcelCommon.java +++ b/src/main/java/com/whdc/utils/ExcelCommon.java @@ -77,6 +77,18 @@ public class ExcelCommon { list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params); return list; } + public static List importExcel(String filePath, Integer startSheetIndex, Integer titleRows, Integer headerRows, Class pojoClass) { + if (StringUtils.isBlank(filePath)) { + return null; + } + ImportParams params = new ImportParams(); + params.setTitleRows(titleRows); + params.setHeadRows(headerRows); + params.setStartSheetIndex(startSheetIndex); + List list = null; + list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params); + return list; + } public static List importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class pojoClass) { if (file == null) { @@ -93,4 +105,20 @@ public class ExcelCommon { } return list; } + public static List importExcel(MultipartFile file, Integer startSheetIndex, Integer titleRows, Integer headerRows, Class pojoClass) { + if (file == null) { + return null; + } + ImportParams params = new ImportParams(); + params.setTitleRows(titleRows); + params.setHeadRows(headerRows); + params.setStartSheetIndex(startSheetIndex); + List list = null; + try { + list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params); + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } }