2024-06-06 10:23:50 +08:00
|
|
|
package com.whdc.controller;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
2024-06-26 13:15:29 +08:00
|
|
|
import com.whdc.model.entity.AddressBookOld;
|
|
|
|
|
import com.whdc.model.entity.QXWarning;
|
2024-06-06 10:23:50 +08:00
|
|
|
import com.whdc.model.entity.WarnMsgFB;
|
2024-06-25 17:58:24 +08:00
|
|
|
import com.whdc.model.vo.ExcelOldDataVo;
|
2024-06-26 13:15:29 +08:00
|
|
|
import com.whdc.service.IAddressBookOldService;
|
|
|
|
|
import com.whdc.service.IQXWarningService;
|
2024-06-06 10:23:50 +08:00
|
|
|
import com.whdc.service.IWarnMsgFBService;
|
2024-06-25 17:58:24 +08:00
|
|
|
import com.whdc.utils.ExcelCommon;
|
2024-06-06 10:23:50 +08:00
|
|
|
import com.whdc.utils.ResultJson;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2024-06-26 13:15:29 +08:00
|
|
|
import org.apache.commons.compress.utils.Lists;
|
2024-06-06 10:23:50 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2024-06-25 17:58:24 +08:00
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
2024-06-06 10:23:50 +08:00
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Api(tags = "预警叫应 - Controller")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/warnmsgfb")
|
|
|
|
|
public class WarnMsgFBController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IWarnMsgFBService service;
|
2024-06-26 13:15:29 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IQXWarningService qxService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IAddressBookOldService oldService;
|
2024-06-06 10:23:50 +08:00
|
|
|
//增
|
|
|
|
|
@ApiOperation(value = "新增")
|
|
|
|
|
@PostMapping(value = "/add")
|
|
|
|
|
public ResultJson<String> insert(@RequestBody @Validated WarnMsgFB dto) {
|
|
|
|
|
|
|
|
|
|
//根据warnid和phone判断是否重复
|
|
|
|
|
if (CollectionUtils.isNotEmpty(
|
|
|
|
|
service.lambdaQuery()
|
|
|
|
|
.eq(WarnMsgFB::getWarnid,dto.getWarnid())
|
|
|
|
|
.eq(WarnMsgFB::getCalledPhone,String.valueOf(dto.getCalledPhone())).list()
|
|
|
|
|
)
|
|
|
|
|
){
|
|
|
|
|
return ResultJson.error("该名称或编码重复");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean save = service.save(dto);
|
|
|
|
|
return ResultJson.ok(save);
|
|
|
|
|
}
|
|
|
|
|
//删
|
|
|
|
|
//改
|
|
|
|
|
//查
|
|
|
|
|
@ApiOperation(value = "查询所有")
|
|
|
|
|
@PostMapping(value = "/find")
|
|
|
|
|
public ResultJson<WarnMsgFB> find(@RequestBody WarnMsgFB dto) {
|
|
|
|
|
|
|
|
|
|
return ResultJson.ok(service.find(dto));
|
|
|
|
|
|
|
|
|
|
}
|
2024-06-25 17:58:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "解析文件数据")
|
|
|
|
|
@PostMapping(value = "getExcelData")
|
|
|
|
|
public ResultJson<ExcelOldDataVo> getExcelData(MultipartFile file) {
|
|
|
|
|
|
2024-06-26 13:15:29 +08:00
|
|
|
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()));
|
|
|
|
|
|
|
|
|
|
List<AddressBookOld> olds = oldService.list();
|
|
|
|
|
Map<String, List<AddressBookOld>> txlByName = olds.stream().collect(Collectors.groupingBy(AddressBookOld::getName, 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-25 17:58:24 +08:00
|
|
|
|
|
|
|
|
|
2024-06-26 13:15:29 +08:00
|
|
|
List<Integer> warns = warnMsgs.stream().map(WarnMsgFB::getWarnid).collect(Collectors.toList());
|
2024-06-25 17:58:24 +08:00
|
|
|
|
|
|
|
|
List<WarnMsgFB> list = service.lambdaQuery().in(WarnMsgFB::getWarnid, warns).list();
|
|
|
|
|
|
|
|
|
|
Map<Integer, List<WarnMsgFB>> map = list.stream().collect(Collectors.groupingBy(WarnMsgFB::getWarnid, Collectors.toList()));
|
|
|
|
|
|
2024-06-26 13:15:29 +08:00
|
|
|
List<WarnMsgFB> warnDb = Lists.newArrayList();
|
|
|
|
|
for (WarnMsgFB warn : warnMsgs) {
|
|
|
|
|
Integer warnid = warn.getWarnid();
|
|
|
|
|
if (!map.containsKey(warnid)){
|
|
|
|
|
warnDb.add(warn);
|
2024-06-25 17:58:24 +08:00
|
|
|
}
|
2024-06-26 13:15:29 +08:00
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(warnDb)){
|
|
|
|
|
service.saveBatch(warnDb);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-25 17:58:24 +08:00
|
|
|
|
2024-06-26 13:15:29 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2024-06-25 17:58:24 +08:00
|
|
|
return ResultJson.ok();
|
|
|
|
|
}
|
2024-06-06 10:23:50 +08:00
|
|
|
}
|