添加了查询一个月中每一天的火情数量

This commit is contained in:
XinYi Song 2022-02-16 10:06:09 +08:00
parent d8268ef1c8
commit 52ec30f940
3 changed files with 61 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package com.xkrs.controller; package com.xkrs.controller;
import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.model.entity.Fire; import com.xkrs.model.entity.Fire;
import com.xkrs.service.FireService; import com.xkrs.service.FireService;
import com.xkrs.util.Query; import com.xkrs.util.Query;
@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -26,6 +28,11 @@ public class FireController {
@Resource @Resource
private FireService fireService; private FireService fireService;
@Resource
private EquipmentDao equipmentDao;
Locale locale = LocaleContextHolder.getLocale();
/** /**
* 根据设备编号获取火情信息 * 根据设备编号获取火情信息
* @param code * @param code
@ -56,4 +63,19 @@ public class FireController {
public String findThreeHundredData(){ public String findThreeHundredData(){
return fireService.findThreeHundredData(); return fireService.findThreeHundredData();
} }
/**
* 查询一个月中每一天各个街道的火情数量
* @param beginTime
* @param endTime
* @return
*/
@GetMapping("/selectEveryDayCount")
public String selectEveryDayCount(@RequestParam("beginTime") String beginTime,@RequestParam("endTime") String endTime){
List<Map<String, Object>> maps = equipmentDao.selectEveryDayCount(beginTime, endTime);
if(maps == null || maps.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该月暂时唯有火情信息!",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale);
}
} }

View File

@ -43,6 +43,28 @@ public interface EquipmentDao extends JpaRepository<Equipment,Long> {
*/ */
@Query(value = "select equipment_code equipmentcode,equipment_name equipmentname,equipment_type equipmenttype," + @Query(value = "select equipment_code equipmentcode,equipment_name equipmentname,equipment_type equipmenttype," +
"equipment_status equipmentstatus,equipment_longitude equipmentlongitude," + "equipment_status equipmentstatus,equipment_longitude equipmentlongitude," +
"equipment_latitude equipmentlatitude,installation_time installationtime from equipment",nativeQuery = true) "equipment_latitude equipmentlatitude,installation_time installationtime,street from equipment",nativeQuery = true)
List<Map<String,String>> findEquipment(); List<Map<String,String>> findEquipment();
/**
* 根据时间段查询各个街道火情数量
* @param beginTime
* @param endTime
* @return
*/
@Query(value = "select e.street street,count(f.id) AS firenumber from equipment e,fire f where f.alarm_date " +
"BETWEEN ?1 AND ?2 AND e.equipment_code = f.device_code " +
"GROUP BY e.street",nativeQuery = true)
List<Map<String,Object>> selectCountFire(String beginTime, String endTime);
/**
* 查询一个月中每一天各个街道的火情数量
* @param beginTime
* @param endTime
* @return
*/
@Query(value = "select LEFT(f.alarm_date,10) AS data,e.street as street,count(f.id) AS firenumber " +
"from equipment e,fire f where f.alarm_date BETWEEN ?1 AND ?2 " +
"AND e.equipment_code = f.device_code GROUP BY LEFT(f.alarm_date,10),e.street",nativeQuery = true)
List<Map<String,Object>> selectEveryDayCount(String beginTime, String endTime);
} }

View File

@ -64,10 +64,15 @@ public class Equipment {
*/ */
private String liveVideo; private String liveVideo;
/**
* 街道信息
*/
private String street;
public Equipment() { public Equipment() {
} }
public Equipment(Integer id, String equipmentCode, String equipmentName, String equipmentType, String equipmentStatus, String equipmentLongitude, String equipmentLatitude, String installationTime, String liveVideo) { public Equipment(Integer id, String equipmentCode, String equipmentName, String equipmentType, String equipmentStatus, String equipmentLongitude, String equipmentLatitude, String installationTime, String liveVideo, String street) {
this.id = id; this.id = id;
this.equipmentCode = equipmentCode; this.equipmentCode = equipmentCode;
this.equipmentName = equipmentName; this.equipmentName = equipmentName;
@ -77,6 +82,7 @@ public class Equipment {
this.equipmentLatitude = equipmentLatitude; this.equipmentLatitude = equipmentLatitude;
this.installationTime = installationTime; this.installationTime = installationTime;
this.liveVideo = liveVideo; this.liveVideo = liveVideo;
this.street = street;
} }
public Integer getId() { public Integer getId() {
@ -151,6 +157,14 @@ public class Equipment {
this.liveVideo = liveVideo; this.liveVideo = liveVideo;
} }
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
@Override @Override
public String toString() { public String toString() {
return "Equipment{" + return "Equipment{" +
@ -163,6 +177,7 @@ public class Equipment {
", equipmentLatitude='" + equipmentLatitude + '\'' + ", equipmentLatitude='" + equipmentLatitude + '\'' +
", installationTime='" + installationTime + '\'' + ", installationTime='" + installationTime + '\'' +
", liveVideo='" + liveVideo + '\'' + ", liveVideo='" + liveVideo + '\'' +
", street='" + street + '\'' +
'}'; '}';
} }
} }