2024-06-06 10:23:50 +08:00
|
|
|
package com.whdc.controller;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
|
import com.whdc.model.entity.WarnMsgFB;
|
2024-06-25 17:58:24 +08:00
|
|
|
import com.whdc.model.vo.ExcelOldDataVo;
|
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;
|
|
|
|
|
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;
|
|
|
|
|
//增
|
|
|
|
|
@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) {
|
|
|
|
|
|
|
|
|
|
List<WarnMsgFB> appends = ExcelCommon.importExcel(file, 0, 1, WarnMsgFB.class);
|
|
|
|
|
|
|
|
|
|
service.saveBatch(appends);
|
|
|
|
|
|
|
|
|
|
List<Integer> warns = appends.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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return ResultJson.ok();
|
|
|
|
|
}
|
2024-06-06 10:23:50 +08:00
|
|
|
}
|