fxkh-txl-service/src/main/java/com/whdc/controller/WarnMsgFBController.java

136 lines
5.0 KiB
Java
Raw Normal View History

package com.whdc.controller;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
2025-07-14 11:23:11 +08:00
import com.whdc.model.entity.WarningResponder;
import com.whdc.model.entity.QXWarning;
import com.whdc.model.entity.WarnMsgFB;
import com.whdc.model.vo.ExcelOldDataVo;
2025-07-14 11:23:11 +08:00
import com.whdc.service.IWarningResponderService;
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;
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.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Api(tags = "预警叫应 - Controller")
@RestController
@RequestMapping("/warnmsgfb")
public class WarnMsgFBController {
@Autowired
private IWarnMsgFBService service;
@Autowired
private IQXWarningService qxService;
@Autowired
2025-07-14 11:23:11 +08:00
private IWarningResponderService oldService;
//增
@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));
}
@ApiOperation(value = "解析文件数据")
@PostMapping(value = "getExcelData")
public ResultJson<ExcelOldDataVo> getExcelData(MultipartFile file) {
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()));
2025-07-14 11:23:11 +08:00
List<WarningResponder> olds = oldService.list();
Map<String, List<WarningResponder>> txlByName = olds.stream().collect(Collectors.groupingBy(WarningResponder::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();
2025-07-14 11:23:11 +08:00
List<WarningResponder> 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()));
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();
}
}