fire_point/src/main/java/com/xkrs/controller/FirePointController.java
liuchengqian e8c02d1403 添加接口:/queryHuangDao
获取黄岛区2023年以来全部地物类型火点
2023-01-31 17:02:30 +08:00

327 lines
15 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.service.FirePointService;
import com.xkrs.service.StreetService;
import com.xkrs.service.impl.FirePointServiceImpl;
import com.xkrs.utils.FirePointQueryHelper;
import org.apache.hc.core5.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
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 {
public static Logger log = LoggerFactory.getLogger(FirePointServiceImpl.class);
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);
}
@GetMapping("/queryHuangDao")
public String queryHuangDao() {
List<FirePointEntity> firePointList = firePointQueryHelper.queryFirePoint("370211", "2023-01-01 00:00:10", null, null, null);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointList, locale);
}
/**
* 添加火点数据
*
* @param firePointQo
* @return
*/
@PostMapping("/insertFirePoint")
public String insertFirePoint(@RequestBody FirePointQo firePointQo) {
log.info("insertFirePoint 接收到火点信息:" + firePointQo.toString());
boolean success = firePointService.insertFirePoint(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);
}
@RequestMapping(value = "/download/firepoint", method = RequestMethod.GET)
public String downloadFirePoint(HttpServletResponse response, HttpServletRequest request, @RequestParam(value = "ids") String ids) {
return firePointService.downloadFirePoint(request, response, ids);
}
/**
* 动态多条件查询火点列表
*
* @param code 区划编码,可以是省市区县街道任意编码,如果传需要至少两位。不传代表查询全国火点
* @param startTime 过滤火点开始卫星时间,不传代表不指定开始时间。后台会有限制。
* @param endTime 过滤火点结束卫星时间,不传代表不指定结束时间。
* @param satelliteType 过滤传感器类型,不传代表查询全部类型的传感器
* @param landType 过滤地物类型,不传代表查询全部地物类型
*/
@GetMapping("/queryFirePoint")
public String queryFirePoint(@RequestParam(value = "code", required = false) String code, @RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime, @RequestParam(value = "satelliteType", required = false) String satelliteType, @RequestParam(value = "landType", required = false) String landType) {
List<FirePointEntity> firePointList = firePointService.queryFirePoint(code, startTime, endTime, satelliteType, landType);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointList, locale);
}
/**
* 测试
*
* @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);
}
/**
* 查询今天的火点信息
*
* @return
*/
@GetMapping("/selectTodayFirePoint")
public String selectTodayFirePoint(@RequestParam("countyCode") String countyCode) {
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);
}
/**
* 查询近一周的火点信息
*/
@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);
}
}