修改 动态多条件查询火点信息

This commit is contained in:
liuchengqian 2022-05-07 16:00:58 +08:00
parent 9321bdf9bf
commit d3ab960893
3 changed files with 254 additions and 317 deletions

View File

@ -43,6 +43,7 @@ public class FirePointController {
/**
* 添加火点数据
*
* @param firePointQo
* @return
*/
@ -60,6 +61,7 @@ public class FirePointController {
/**
* 测试
*
* @param token
* @return
*/
@ -79,6 +81,7 @@ public class FirePointController {
/**
* 查询今天的火点信息
*
* @param token
* @return
*/
@ -96,6 +99,7 @@ public class FirePointController {
/**
* 动态多条件查询火点信息
*
* @param map
* @param token
* @return
@ -119,21 +123,29 @@ public class FirePointController {
String tokenUserName = TokenUtil.getTokenUserName(token);
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
// 查询省
if(sysUserEntity.getCountyCode().substring(2).equals("0000")){
if (9 == sysUserEntity.getCountyCode().length()) {
// 查询县
List<FirePointEntity> firePointEntities = firePointService.selectFirePointByCounty(sysUserEntity.getCountyCode(), satelliteType, landType, startTime, endTime);
if (firePointEntities == null || firePointEntities.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointEntities, locale);
} else if (sysUserEntity.getCountyCode().substring(2).equals("0000")) {
// 查询省
List<FirePointEntity> firePointEntities = firePointService.selectFirePoint(sysUserEntity.getCountyCode(), cityCode, satelliteType, landType, startTime, endTime);
if (firePointEntities == null || firePointEntities.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointEntities, locale);
// 查询市
} else if (sysUserEntity.getCountyCode().substring(4).equals("00") && !sysUserEntity.getCountyCode().substring(2).equals("0000")) {
// 查询市
List<FirePointEntity> firePointEntities = firePointService.selectFirePointByCity(sysUserEntity.getCountyCode(), cityCode, satelliteType, landType, startTime, endTime);
if (firePointEntities == null || firePointEntities.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointEntities, locale);
// 查询县
} else {
// 查询县
List<FirePointEntity> firePointEntities = firePointService.selectFirePointByCounty(sysUserEntity.getCountyCode(), satelliteType, landType, startTime, endTime);
if (firePointEntities == null || firePointEntities.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale);
@ -144,6 +156,7 @@ public class FirePointController {
/**
* 根据火点编码修改火点状态
*
* @param map
* @param token
* @return
@ -157,6 +170,7 @@ public class FirePointController {
/**
* 提交核查任务
*
* @param files
* @param appTaskBodyVo
* @return
@ -179,6 +193,7 @@ public class FirePointController {
/**
* 查询核查的任务信息
*
* @param fireCode
* @return
*/
@ -189,6 +204,7 @@ public class FirePointController {
/**
* 查询近一周的火点信息
*
* @return
*/
@GetMapping("/selectFirePointBetweenSeven")
@ -204,6 +220,7 @@ public class FirePointController {
/**
* 查询近一个月的火点信息
*
* @return
*/
@GetMapping("/selectFirePointByMonth")
@ -223,6 +240,7 @@ public class FirePointController {
/**
* 查询火点数量
*
* @return
*/
@GetMapping("/selectFirePointNum")
@ -246,6 +264,7 @@ public class FirePointController {
/**
* 查询该省所有的市
*
* @return
*/
@GetMapping("/selectCityName")
@ -263,6 +282,7 @@ public class FirePointController {
/**
* 根据火点编码查询火点信息
*
* @param fireCode
* @return
*/
@ -276,6 +296,7 @@ public class FirePointController {
/**
* 测试添加火点信息
*
* @param firePointQo
* @return
*/
@ -293,6 +314,7 @@ public class FirePointController {
/**
* 导入全国省市区
*
* @param file
* @return
* @throws Exception
@ -307,6 +329,7 @@ public class FirePointController {
/**
* 查询今天的火点信息(测试)
*
* @param token
* @return
*/
@ -324,6 +347,7 @@ public class FirePointController {
/**
* 删除水体类型的火点信息
*
* @return
*/
@Transactional(rollbackOn = Exception.class)
@ -346,6 +370,7 @@ public class FirePointController {
/**
* 根据火点编码添加火点前后的图片
*
* @param map
* @return
*/

View File

@ -210,19 +210,16 @@ public class FirePointServiceImpl implements FirePointService {
@Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override
public List<FirePointEntity> selectFirePointByCity(String cityCodeOne, String cityCode, String satelliteType, String landType, String startTime, String endTime) {
//List<CityEntity> byCityCode = cityDao.findByCityCode(cityCodeOne.substring(0,3));
List<CountyEntity> byCityCode = countyDao.findByCityCode(cityCodeOne);
String cityName = byCityCode.get(0).getCityName();
CityEntity byCityCode1 = cityDao.findByCityName(cityName);
String proName = byCityCode1.getProName();
if (!"".equals(startTime) && !"".equals(endTime)) {
LocalDate localDate = DateTimeUtil.stringToDate(endTime);
// 结束时间
LocalDate localDate1 = localDate.plusDays(1);
String dateToString = DateTimeUtil.dateToString(localDate1);
return query.selectFirePointByCity(proName, cityName, cityCode, satelliteType, landType, startTime, dateToString);
return query.selectFirePointByCity(cityName, cityCode, satelliteType, landType, startTime, dateToString);
}
return query.selectFirePointByCity(proName, cityName, cityCode, satelliteType, landType, startTime, endTime);
return query.selectFirePointByCity(cityName, cityCode, satelliteType, landType, startTime, endTime);
}
/**
@ -238,18 +235,14 @@ public class FirePointServiceImpl implements FirePointService {
@Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override
public List<FirePointEntity> selectFirePointByCounty(String cityCode, String satelliteType, String landType, String startTime, String endTime) {
List<CountyEntity> byCountyCode = countyDao.findByCountyCode(cityCode);
CityEntity byCityCode = cityDao.findByCityName(byCountyCode.get(0).getCityName());
String proName = byCityCode.getProName();
if (!"".equals(startTime) && !"".equals(endTime)) {
LocalDate localDate = DateTimeUtil.stringToDate(endTime);
// 结束时间
LocalDate localDate1 = localDate.plusDays(1);
String dateToString = DateTimeUtil.dateToString(localDate1);
return query.selectFirePointByCounty(proName, cityCode, satelliteType, landType, startTime, dateToString);
return query.selectFirePointByCounty(cityCode, satelliteType, landType, startTime, dateToString);
}
return query.selectFirePointByCounty(proName, cityCode, satelliteType, landType, startTime, endTime);
return query.selectFirePointByCounty(cityCode, satelliteType, landType, startTime, endTime);
}
/**
@ -381,7 +374,6 @@ public class FirePointServiceImpl implements FirePointService {
public List<FirePointEntity> selectFirePointBetweenSeven() {
LocalDateTime localDateTime = LocalDateTime.now();
String endTime = DateTimeUtil.dateTimeToString(localDateTime);
// 当前时间减7
LocalDateTime localDateTime1 = localDateTime.minusDays(7);
String startTime = DateTimeUtil.dateTimeToString(localDateTime1);
@ -401,21 +393,18 @@ public class FirePointServiceImpl implements FirePointService {
// 当前时间减31
LocalDateTime localDateTime1 = localDateTime.minusDays(31);
String startTime = DateTimeUtil.dateTimeToString(localDateTime1);
if ("0000".equals(countyCode.substring(2))) {
if (9 == countyCode.length()) {
return query.selectFirePointByMonthCounty(countyCode, startTime, endTime);
} else if ("0000".equals(countyCode.substring(2))) {
List<CityEntity> byProCode = cityDao.findByProCode(countyCode);
String proName = byProCode.get(0).getProName();
return query.selectFirePointByMonth(proName, startTime, endTime);
return query.selectFirePointByMonthPro(proName, startTime, endTime);
} else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) {
List<CountyEntity> byCityCode = countyDao.findByCityCode(countyCode);
String cityName = byCityCode.get(0).getCityName();
CityEntity byCityName = cityDao.findByCityName(cityName);
String proName = byCityName.getProName();
return query.selectFirePointByMonthCity(proName, cityName, startTime, endTime);
return query.selectFirePointByMonthCity(cityName, startTime, endTime);
} else {
List<CountyEntity> byCountyCode = countyDao.findByCountyCode(countyCode);
CityEntity byCityName = cityDao.findByCityName(byCountyCode.get(0).getCityName());
String proName = byCityName.getProName();
return query.selectFirePointByMonthCounty(proName, countyCode, startTime, endTime);
return query.selectFirePointByMonthCounty(countyCode, startTime, endTime);
}
}

View File

@ -6,10 +6,7 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@ -26,13 +23,9 @@ public class Query {
/**
* 动态多条件查询项目信息()
* @param
* @return
*/
public List<FirePointEntity> selectFirePointByPro(String address, String cityCode, String satelliteType, String landType, String startTime, String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
Specification<FirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
if (address != null && !"".equals(address)) {
list.add(criteriaBuilder.like(root.get("firePointAddress").as(String.class), "%" + address + "%"));
@ -44,16 +37,8 @@ public class Query {
list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
}
if (landType != null && !"".equals(landType)) {
// if(address.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType));
}
// else {
// if(address.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
// }
if (startTime != null && !"".equals(startTime)) {
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime));
}
@ -70,20 +55,15 @@ public class Query {
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimes));
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}
/**
* 动态多条件查询项目信息()
* @param
* @return
*/
public List<FirePointEntity> selectFirePointByCity(String proName, String address, String cityCode,String satelliteType,String landType,String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
public List<FirePointEntity> selectFirePointByCity(String address, String cityCode, String satelliteType, String landType, String startTime, String endTime) {
Specification<FirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
if (address != null && !"".equals(address)) {
list.add(criteriaBuilder.like(root.get("firePointAddress").as(String.class), "%" + address + "%"));
@ -95,16 +75,8 @@ public class Query {
list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
}
if (landType != null && !"".equals(landType)) {
// if(proName.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType));
}
// else {
// if(proName.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
// }
if (startTime != null && !"".equals(startTime)) {
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime));
}
@ -121,20 +93,15 @@ public class Query {
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimes));
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}
/**
* 动态多条件查询项目信息()
* @param
* @return
*/
public List<FirePointEntity> selectFirePointByCounty(String proName, String cityCode,String satelliteType,String landType,String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
public List<FirePointEntity> selectFirePointByCounty(String cityCode, String satelliteType, String landType, String startTime, String endTime) {
Specification<FirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
if (cityCode != null && !"".equals(cityCode)) {
list.add(criteriaBuilder.equal(root.get("countyCode").as(String.class), cityCode));
@ -143,16 +110,8 @@ public class Query {
list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
}
if (landType != null && !"".equals(landType)) {
// if(proName.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType));
}
// else {
// if(proName.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
// }
if (startTime != null && !"".equals(startTime)) {
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime));
}
@ -169,21 +128,15 @@ public class Query {
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimes));
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}
/**
* 查询近一周的火点
* @param startTime
* @param endTime
* @return
*/
public List<FirePointEntity> selectFirePointBetweenThree(String startTime, String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
Specification<FirePointEntity> 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));
@ -193,21 +146,15 @@ public class Query {
}
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}
/**
* 查询近一个月的火点
* @param startTime
* @param endTime
* @return
* 查询近一个月的火点信息
*/
public List<FirePointEntity> selectFirePointByMonth(String address,String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
public List<FirePointEntity> selectFirePointByMonthPro(String address, String startTime, String endTime) {
Specification<FirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
if (address != null && !"".equals(address)) {
list.add(criteriaBuilder.like(root.get("firePointAddress").as(String.class), "%" + address + "%"));
@ -218,27 +165,17 @@ public class Query {
if (endTime != null && !"".equals(endTime)) {
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime));
}
// if(address.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}
/**
* 查询近一个月的火点信息
* @param address
* @param startTime
* @param endTime
* @return
*/
public List<FirePointEntity> selectFirePointByMonthCity(String proName, String address,String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
public List<FirePointEntity> selectFirePointByMonthCity(String address, String startTime, String endTime) {
Specification<FirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
if (address != null && !"".equals(address)) {
list.add(criteriaBuilder.like(root.get("firePointAddress").as(String.class), "%" + address + "%"));
@ -249,27 +186,17 @@ public class Query {
if (endTime != null && !"".equals(endTime)) {
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime));
}
// if(proName.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}
/**
* 查询近一个月的火点信息
* @param countyCode
* @param startTime
* @param endTime
* @return
*/
public List<FirePointEntity> selectFirePointByMonthCounty(String proName, String countyCode,String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
public List<FirePointEntity> selectFirePointByMonthCounty(String countyCode, String startTime, String endTime) {
Specification<FirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
if (countyCode != null && !"".equals(countyCode)) {
list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), countyCode));
@ -280,12 +207,8 @@ public class Query {
if (endTime != null && !"".equals(endTime)) {
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime));
}
// if(proName.equals("山东省")){
// list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
// }
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}