同步防汛抗旱通讯录旧平台数据库,防汛通讯录历史预警查询修改

master
徐杰盟 2024-06-26 13:15:29 +08:00
parent 74f9b8bfe0
commit 8fe0ea7a7a
5 changed files with 120 additions and 14 deletions

View File

@ -91,6 +91,9 @@ public class AddressBookOldController {
List<AddressBookOld> list = service.lambdaQuery()
.list();
for (AddressBookOld o : list) {
o.decryptPhone();
}
ExcelCommon.exportExcel(list,
null, "防汛抗旱通讯录", AddressBookOld.class, "湖北省防汛抗旱通信录模版" + LocalDateTime.now() + ".xlsx",
response);

View File

@ -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<ExcelOldDataVo> getExcelData(MultipartFile file) {
List<WarnMsgFB> appends = ExcelCommon.importExcel(file, 0, 1, WarnMsgFB.class);
List<WarnMsgFB> warnMsgs = ExcelCommon.importExcel(file,0, 1, WarnMsgFB.class);
List<QXWarning> qxWarns = ExcelCommon.importExcel(file,1, 0, 1, QXWarning.class);
Map<String, List<QXWarning>> qxByID = qxWarns.stream().collect(Collectors.groupingBy(QXWarning::getEffectId, Collectors.toList()));
service.saveBatch(appends);
List<AddressBookOld> olds = oldService.list();
Map<String, List<AddressBookOld>> txlByName = olds.stream().collect(Collectors.groupingBy(AddressBookOld::getName, Collectors.toList()));
List<Integer> warns = appends.stream().map(WarnMsgFB::getWarnid).collect(Collectors.toList());
warnMsgs.forEach(o -> {
List<QXWarning> 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<AddressBookOld> txl = txlByName.get(name);
if (CollectionUtils.isNotEmpty(txl)){
o.setCalledPhone(txl.get(0).getPhone());
}else{
o.setCalledPhone(null);
}
}
});
List<Integer> warns = warnMsgs.stream().map(WarnMsgFB::getWarnid).collect(Collectors.toList());
List<WarnMsgFB> list = service.lambdaQuery().in(WarnMsgFB::getWarnid, warns).list();
Map<Integer, List<WarnMsgFB>> 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<WarnMsgFB> 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<Integer> qxwarns = qxWarns.stream().map(QXWarning::getWarnid).collect(Collectors.toList());
List<QXWarning> qxlist = qxService.lambdaQuery().in(QXWarning::getWarnid, qxwarns).list();
Map<Integer, List<QXWarning>> qxmap = qxlist.stream().collect(Collectors.groupingBy(QXWarning::getWarnid, Collectors.toList()));
List<QXWarning> 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();
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -77,6 +77,18 @@ public class ExcelCommon {
list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
return list;
}
public static <T> List<T> importExcel(String filePath, Integer startSheetIndex, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
if (StringUtils.isBlank(filePath)) {
return null;
}
ImportParams params = new ImportParams();
params.setTitleRows(titleRows);
params.setHeadRows(headerRows);
params.setStartSheetIndex(startSheetIndex);
List<T> list = null;
list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
return list;
}
public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
if (file == null) {
@ -93,4 +105,20 @@ public class ExcelCommon {
}
return list;
}
public static <T> List<T> importExcel(MultipartFile file, Integer startSheetIndex, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
if (file == null) {
return null;
}
ImportParams params = new ImportParams();
params.setTitleRows(titleRows);
params.setHeadRows(headerRows);
params.setStartSheetIndex(startSheetIndex);
List<T> list = null;
try {
list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}