387 lines
17 KiB
Java
387 lines
17 KiB
Java
package com.xkrs.controller;
|
||
|
||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||
import com.xkrs.common.tool.TokenUtil;
|
||
import com.xkrs.dao.FirePointDao;
|
||
import com.xkrs.dao.ShanDongFirePointDao;
|
||
import com.xkrs.dao.SysUserDao;
|
||
import com.xkrs.model.entity.FirePointEntity;
|
||
import com.xkrs.model.entity.ShanDongFirePointEntity;
|
||
import com.xkrs.model.entity.SysUserEntity;
|
||
import com.xkrs.model.qo.AuditFireTypeQo;
|
||
import com.xkrs.model.qo.FirePointQo;
|
||
import com.xkrs.model.qo.ShanDongFirePointVerifyStateQo;
|
||
import com.xkrs.model.vo.AppTaskBodyVo;
|
||
import com.xkrs.service.FirePointService;
|
||
import com.xkrs.service.StreetService;
|
||
import com.xkrs.utils.FirePointQueryHelper;
|
||
import org.apache.hc.core5.util.TextUtils;
|
||
import org.springframework.context.i18n.LocaleContextHolder;
|
||
import org.springframework.data.domain.Sort;
|
||
import org.springframework.data.jpa.domain.Specification;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.persistence.criteria.Predicate;
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import javax.transaction.Transactional;
|
||
import java.io.IOException;
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.Locale;
|
||
import java.util.Map;
|
||
|
||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||
|
||
@RestController
|
||
public class FirePointController {
|
||
|
||
private final Locale locale = LocaleContextHolder.getLocale();
|
||
|
||
@Resource
|
||
private FirePointService firePointService;
|
||
|
||
@Resource
|
||
private SysUserDao sysUserDao;
|
||
|
||
@Resource
|
||
private FirePointDao firePointDao;
|
||
|
||
@Resource
|
||
private ShanDongFirePointDao shanDongFirePointDao;
|
||
|
||
@Resource
|
||
private StreetService streetService;
|
||
|
||
@Resource
|
||
private FirePointQueryHelper firePointQueryHelper;
|
||
|
||
@GetMapping("/queryzzhd")
|
||
public String queryzzhd() {
|
||
List<FirePointEntity> firePointEntities1 = firePointQueryHelper.queryZZHD("371482", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||
List<FirePointEntity> firePointEntities2 = firePointQueryHelper.queryZZHD("371403", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||
List<FirePointEntity> firePointEntities3 = firePointQueryHelper.queryZZHD("371426", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||
List<FirePointEntity> firePointEntities4 = firePointQueryHelper.queryZZHD("371424", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||
List<FirePointEntity> firePointEntities5 = firePointQueryHelper.queryZZHD("371526", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||
List<FirePointEntity> firePointEntities6 = firePointQueryHelper.queryZZHD("371425", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||
List<FirePointEntity> firePointEntities7 = firePointQueryHelper.queryZZHD("371503", "2022-01-01 00:00:10", "2022-06-26 00:00:10");
|
||
|
||
List<FirePointEntity> firePointList = new ArrayList<>();
|
||
firePointList.addAll(firePointEntities1);
|
||
firePointList.addAll(firePointEntities2);
|
||
firePointList.addAll(firePointEntities3);
|
||
firePointList.addAll(firePointEntities4);
|
||
firePointList.addAll(firePointEntities5);
|
||
firePointList.addAll(firePointEntities6);
|
||
firePointList.addAll(firePointEntities7);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointList, locale);
|
||
}
|
||
|
||
/**
|
||
* 添加火点数据
|
||
*
|
||
* @param firePointQo
|
||
* @return
|
||
*/
|
||
@PostMapping("/insertFirePoint")
|
||
public String insertFirePoint(@RequestBody FirePointQo firePointQo) {
|
||
boolean success = firePointService.insertFirePoint(firePointQo);
|
||
if (success) {
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
|
||
} else {
|
||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "添加失败", locale);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 添加火点数据
|
||
*
|
||
* @param firePointQo
|
||
* @return
|
||
*/
|
||
@PostMapping("/insertfirepointchanneltwo")
|
||
public String insertFirePointChannelTwo(@RequestBody FirePointQo firePointQo) {
|
||
boolean success = firePointService.insertFirePointChannelTwo(firePointQo);
|
||
if (success) {
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
|
||
} else {
|
||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "添加失败", locale);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询山东临时火点表
|
||
*
|
||
* @return
|
||
*/
|
||
@GetMapping("/queryshandongfirepointlist")
|
||
public String queryShanDongFirePointList() {
|
||
List<ShanDongFirePointEntity> shanDongFirePointList = shanDongFirePointDao.findAll(Sort.by(Sort.Direction.DESC, "satelliteTime"));
|
||
if (shanDongFirePointList.isEmpty()) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale);
|
||
}
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, shanDongFirePointList, locale);
|
||
}
|
||
|
||
/**
|
||
* 将山东临时火点表中的火点根据火点编号更新审核状态
|
||
* 操作1:如果verifyState==1,将火点编号对应的火点从山东火点表转存到火点表
|
||
* 操作2:将山东火点表中的这个火点的审核状态更新
|
||
*/
|
||
@PostMapping("/updateverifystatebyfirecode")
|
||
public String updateVerifyStateByFireCode(@RequestBody ShanDongFirePointVerifyStateQo shanDongFirePointVerifyStateQo) {
|
||
String fireCode = shanDongFirePointVerifyStateQo.getFireCode();
|
||
String verifyState = shanDongFirePointVerifyStateQo.getVerifyState();
|
||
return firePointService.updateVerifyStateByFireCode(fireCode, verifyState);
|
||
}
|
||
|
||
/**
|
||
* 在全国火点表中根据火点编码修改审核火点状态
|
||
*/
|
||
@Transactional(rollbackOn = Exception.class)
|
||
@PostMapping("/updateauditfiretype")
|
||
public String updateAuditFireType(@RequestBody AuditFireTypeQo auditFireTypeQo) {
|
||
String fireCode = auditFireTypeQo.getFireCode();
|
||
String auditFireType = auditFireTypeQo.getAuditFireType();
|
||
FirePointEntity firePointByFireCode = firePointDao.findByFireCode(fireCode);
|
||
if (firePointByFireCode == null) {
|
||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败,没有指定的火点编号", locale);
|
||
}
|
||
firePointDao.updateAuditFireTypeByFireCode(fireCode, auditFireType);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
|
||
}
|
||
|
||
@GetMapping("/queryshandongfirepointbytime")
|
||
public String queryShanDongFirePointByTime(@RequestParam(required = false, value = "startTime") String startTime, @RequestParam(required = false, value = "endTime") String endTime) {
|
||
Specification<ShanDongFirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
|
||
List<Predicate> list = new ArrayList<>();
|
||
if (startTime != null && !"".equals(startTime)) {
|
||
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime));
|
||
}
|
||
if (endTime != null && !"".equals(endTime)) {
|
||
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime));
|
||
}
|
||
Predicate[] predicates = new Predicate[list.size()];
|
||
return criteriaBuilder.and(list.toArray(predicates));
|
||
};
|
||
List<ShanDongFirePointEntity> shanDongFirePointList = shanDongFirePointDao.findAll(specification, Sort.by(Sort.Direction.DESC, "satelliteTime"));
|
||
if (shanDongFirePointList.isEmpty()) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale);
|
||
}
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, shanDongFirePointList, locale);
|
||
}
|
||
|
||
@RequestMapping(value = "/download/vipuserfirepoint", method = RequestMethod.GET)
|
||
public String downloadVipUserFirePoint(HttpServletResponse response, HttpServletRequest request) {
|
||
return firePointService.downloadVipUserFilePoint(request, response);
|
||
}
|
||
|
||
/**
|
||
* 更新火点的街道编号数据
|
||
*
|
||
* @return
|
||
*/
|
||
@GetMapping("/updateFirePointStreetCode")
|
||
public String updateFirePointStreetCode() {
|
||
return firePointService.updateFirePointStreetCode();
|
||
}
|
||
|
||
/**
|
||
* 测试
|
||
*
|
||
* @param token
|
||
* @return
|
||
*/
|
||
@GetMapping("/selectUserName")
|
||
public String selectUserName(@RequestHeader(value = "Authorization") String token) {
|
||
// 验证token
|
||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||
if (sysUserEntity == null) {
|
||
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
||
}
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, sysUserEntity.getUserName(), locale);
|
||
}
|
||
|
||
/**
|
||
* 查询今天的火点信息
|
||
*
|
||
* @param token
|
||
* @return
|
||
*/
|
||
@GetMapping("/selectTodayFirePoint")
|
||
public String selectTodayFirePoint(@RequestParam("countyCode") String countyCode, @RequestHeader(value = "Authorization") String token) {
|
||
List<FirePointEntity> firePointList = firePointService.selectTodayFirePoint(countyCode);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointList, locale);
|
||
}
|
||
|
||
/**
|
||
* 动态多条件查询火点信息
|
||
*/
|
||
@PostMapping("/selectFirePoint")
|
||
public String selectFirePoint(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
|
||
// 区县编码
|
||
String cityCode = (String) map.get("cityCode");
|
||
// 开始时间
|
||
String startTime = (String) map.get("startTime");
|
||
// 结束时间
|
||
String endTime = (String) map.get("endTime");
|
||
// 卫星类型
|
||
String satelliteType = (String) map.get("satelliteType");
|
||
// 植被类型
|
||
String landType = (String) map.get("landType");
|
||
// 验证token
|
||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||
// 用于查询的区划编码,可能是省市区县街道任意级别
|
||
String queryCode = TextUtils.isEmpty(cityCode) ? sysUserEntity.getCountyCode() : cityCode;
|
||
List<FirePointEntity> firePointList = firePointQueryHelper.queryFirePoint(queryCode, startTime, endTime, satelliteType, landType);
|
||
if (firePointList == null || firePointList.size() == 0) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale);
|
||
}
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointList, locale);
|
||
}
|
||
|
||
/**
|
||
* 根据火点编码修改火点状态
|
||
*
|
||
* @param map
|
||
* @param token
|
||
* @return
|
||
*/
|
||
@PostMapping("/updateTypeByFireCode")
|
||
public String updateTypeByFireCode(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
|
||
String fireCode = (String) map.get("fireCode");
|
||
String fireType = (String) map.get("fireType");
|
||
return firePointService.updateTypeByFireCode(fireCode, fireType, token);
|
||
}
|
||
|
||
/**
|
||
* 提交核查任务
|
||
*/
|
||
@PostMapping("/insertAppTask")
|
||
public String insertAppTask(@RequestParam("files") MultipartFile[] files, AppTaskBodyVo appTaskBodyVo) throws IOException {
|
||
if ("".equals(appTaskBodyVo.getFireCode()) || appTaskBodyVo.getFireCode() == null) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "火点编码不能为空", locale);
|
||
}
|
||
if ("".equals(appTaskBodyVo.getTaskInformation()) || appTaskBodyVo.getTaskInformation() == null) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "任务描述不能为空", locale);
|
||
}
|
||
if (files == null || files.length == 0) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "图片不能为空", locale);
|
||
}
|
||
return firePointService.insertAppTask(files, appTaskBodyVo);
|
||
}
|
||
|
||
/**
|
||
* 查询核查的任务信息
|
||
*/
|
||
@GetMapping("/selectAppTask")
|
||
public String selectAppTask(@RequestParam("fireCode") String fireCode) throws Exception {
|
||
return firePointService.selectAppTask(fireCode);
|
||
}
|
||
|
||
/**
|
||
* 查询近一周的火点信息
|
||
*/
|
||
@GetMapping("/selectFirePointBetweenSeven")
|
||
public String selectFirePointBetweenSeven() {
|
||
List<FirePointEntity> firePointEntities = firePointService.selectFirePointBetweenSeven();
|
||
if (firePointEntities == null || firePointEntities.size() == 0) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有火点数据", locale);
|
||
}
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointEntities, locale);
|
||
}
|
||
|
||
/**
|
||
* 查询近一个月的火点信息
|
||
*/
|
||
@GetMapping("/selectFirePointByMonth")
|
||
public String selectFirePointByMonth(@RequestHeader(value = "Authorization") String token) {
|
||
// 验证token
|
||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||
List<FirePointEntity> firePointEntities = firePointService.selectFirePointByMonth(sysUserEntity.getCountyCode());
|
||
if (firePointEntities == null || firePointEntities.size() == 0) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有火点数据", locale);
|
||
}
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointEntities, locale);
|
||
}
|
||
|
||
/**
|
||
* 查询火点数量
|
||
*/
|
||
@GetMapping("/selectFirePointNum")
|
||
public String selectFirePointNum(@RequestParam("keepType") String keepType) {
|
||
// keepType为1时,查询近一天的火点数量
|
||
if ("1".equals(keepType)) {
|
||
return firePointService.selectFirePointNumDay();
|
||
// keepType为2时,查询近一周的火点数量
|
||
} else if ("2".equals(keepType)) {
|
||
return firePointService.selectFirePointNumWeek();
|
||
} else {
|
||
return firePointService.selectFirePointNumMonth();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询该省所有的市
|
||
*
|
||
* @return
|
||
*/
|
||
@GetMapping("/selectCityName")
|
||
public String selectCityName(@RequestParam("code") String countyCode) {
|
||
if (9 == countyCode.length()) {
|
||
List<Map<String, String>> maps = new ArrayList<>();
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
|
||
} else if ("0000".equals(countyCode.substring(2))) {
|
||
List<Map<String, String>> maps = streetService.selectCityList(countyCode);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
|
||
} else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) {
|
||
List<Map<String, String>> maps = streetService.selectCountyList(countyCode);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
|
||
} else {
|
||
List<Map<String, String>> maps = streetService.selectStreetList(countyCode);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 根据火点编码查询火点信息
|
||
*
|
||
* @param fireCode
|
||
* @return
|
||
*/
|
||
@GetMapping("/selectFirePointByCode")
|
||
public String selectFirePoint(@RequestParam("fireCode") String fireCode) {
|
||
FirePointEntity byFireCode = firePointDao.findByFireCode(fireCode);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byFireCode, locale);
|
||
}
|
||
|
||
/**
|
||
* 根据火点编码添加火点前后的图片
|
||
*
|
||
* @param map
|
||
* @return
|
||
*/
|
||
@Transactional(rollbackOn = Exception.class)
|
||
@PostMapping("/updateBeforeFireAndAfterFireImage")
|
||
public String updateBeforeFireAndAfterFireImage(@RequestBody Map map) {
|
||
String fireCode = (String) map.get("fireCode");
|
||
String beforeFireImage = (String) map.get("beforeFireImage");
|
||
String afterFireImage = (String) map.get("afterFireImage");
|
||
if (fireCode == null || "".equals(fireCode)) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "火点编码不能为空!", locale);
|
||
}
|
||
FirePointEntity byFireCode = firePointDao.findByFireCode(fireCode);
|
||
if (byFireCode == null) {
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "火点编码错误!", locale);
|
||
}
|
||
firePointDao.updateBeforeFireAndAfterFireImage(fireCode, beforeFireImage, afterFireImage);
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加图片成功!", locale);
|
||
}
|
||
|
||
}
|