添加了根据不同行业查询设备信息的接口

This commit is contained in:
XinYi Song 2022-02-24 17:21:28 +08:00
parent 97dd89a938
commit cde7338d33
4 changed files with 128 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import com.xkrs.dao.AlarmDao;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.model.entity.Equipment;
import com.xkrs.util.DateTimeUtil;
import com.xkrs.util.Query;
import com.xkrs.util.RequestUtil;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
@ -32,6 +33,9 @@ public class EquipmentController {
@Resource
private AlarmDao alarmDao;
@Resource
private Query query;
Locale locale = LocaleContextHolder.getLocale();
/*@GetMapping("/getEquipment")
@ -210,4 +214,24 @@ public class EquipmentController {
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, alarmTypeByCode, locale);
}
/**
* 根据不同的行业查询设备信息
* @param agriculture
* @param habitat
* @param waterConservancy
* @param forestry
* @return
*/
@GetMapping("/selectEquipment")
public String selectEquipment(@RequestParam("agriculture") String agriculture,
@RequestParam("habitat") String habitat,
@RequestParam("waterConservancy") String waterConservancy,
@RequestParam("forestry") String forestry){
List<Equipment> equipment = query.selectEquipment(agriculture, habitat, waterConservancy, forestry);
if(equipment == null || equipment.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有您所需要的信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, equipment, locale);
}
}

View File

@ -2,6 +2,7 @@ package com.xkrs.dao;
import com.xkrs.model.entity.Equipment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -12,7 +13,7 @@ import java.util.Map;
* @Author: XinYi Song
* @Date: 2022/2/8 9:26
*/
public interface EquipmentDao extends JpaRepository<Equipment,Long> {
public interface EquipmentDao extends JpaRepository<Equipment,Long>, JpaSpecificationExecutor<Equipment> {
/**
* 根据设备编码修改实时视频路径

View File

@ -69,10 +69,34 @@ public class Equipment {
*/
private String street;
/**
* 农业 0未用 1在用
*/
@Column(length = 32, columnDefinition = "varchar(32)")
private String agriculture;
/**
* 人居 0未用 1在用
*/
@Column(length = 32, columnDefinition = "varchar(32)")
private String habitat;
/**
* 水利 0未用 1在用
*/
@Column(length = 32, columnDefinition = "varchar(32)")
private String waterConservancy;
/**
* 林业 0未用 1在用
*/
@Column(length = 32, columnDefinition = "varchar(32)")
private String forestry;
public Equipment() {
}
public Equipment(Integer id, String equipmentCode, String equipmentName, String equipmentType, String equipmentStatus, String equipmentLongitude, String equipmentLatitude, String installationTime, String liveVideo, String street) {
public Equipment(Integer id, String equipmentCode, String equipmentName, String equipmentType, String equipmentStatus, String equipmentLongitude, String equipmentLatitude, String installationTime, String liveVideo, String street, String agriculture, String habitat, String waterConservancy, String forestry) {
this.id = id;
this.equipmentCode = equipmentCode;
this.equipmentName = equipmentName;
@ -83,6 +107,10 @@ public class Equipment {
this.installationTime = installationTime;
this.liveVideo = liveVideo;
this.street = street;
this.agriculture = agriculture;
this.habitat = habitat;
this.waterConservancy = waterConservancy;
this.forestry = forestry;
}
public Integer getId() {
@ -165,6 +193,38 @@ public class Equipment {
this.street = street;
}
public String getAgriculture() {
return agriculture;
}
public void setAgriculture(String agriculture) {
this.agriculture = agriculture;
}
public String getHabitat() {
return habitat;
}
public void setHabitat(String habitat) {
this.habitat = habitat;
}
public String getWaterConservancy() {
return waterConservancy;
}
public void setWaterConservancy(String waterConservancy) {
this.waterConservancy = waterConservancy;
}
public String getForestry() {
return forestry;
}
public void setForestry(String forestry) {
this.forestry = forestry;
}
@Override
public String toString() {
return "Equipment{" +
@ -178,6 +238,10 @@ public class Equipment {
", installationTime='" + installationTime + '\'' +
", liveVideo='" + liveVideo + '\'' +
", street='" + street + '\'' +
", agriculture='" + agriculture + '\'' +
", habitat='" + habitat + '\'' +
", waterConservancy='" + waterConservancy + '\'' +
", forestry='" + forestry + '\'' +
'}';
}
}

View File

@ -1,7 +1,9 @@
package com.xkrs.util;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.dao.FireDao;
import com.xkrs.dao.WeatherDao;
import com.xkrs.model.entity.Equipment;
import com.xkrs.model.entity.Fire;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
@ -24,6 +26,9 @@ public class Query {
@Resource
private FireDao fireDao;
@Resource
private EquipmentDao equipmentDao;
/**
* 根据设备编号和时间段动态查询报警信息
* @param startTime
@ -50,4 +55,36 @@ public class Query {
};
return fireDao.findAll(specification);
}
/**
* 根据不同行业查询设备信息
* @param agriculture
* @param habitat
* @param waterConservancy
* @param forestry
* @return
*/
public List<Equipment> selectEquipment(String agriculture, String habitat, String waterConservancy, String forestry) {
Specification<Equipment> specification = new Specification<Equipment>() {
@Override
public Predicate toPredicate(Root<Equipment> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> list = new ArrayList<>();
if (agriculture != null && !"".equals(agriculture)) {
list.add(criteriaBuilder.equal(root.get("agriculture").as(String.class), agriculture));
}
if (habitat != null && !"".equals(habitat)) {
list.add(criteriaBuilder.equal(root.get("habitat").as(String.class), habitat));
}
if (waterConservancy != null && !"".equals(waterConservancy)) {
list.add(criteriaBuilder.equal(root.get("waterConservancy").as(String.class), waterConservancy));
}
if (forestry != null && !"".equals(forestry)) {
list.add(criteriaBuilder.equal(root.get("forestry").as(String.class), forestry));
}
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return equipmentDao.findAll(specification);
}
}