Jelajahi Sumber

数据大屏代码修改

zhengjie 1 tahun lalu
induk
melakukan
deafc2c19b

+ 83 - 82
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDataDisplayController.java

@@ -19,14 +19,13 @@ import java.util.stream.Collectors;
 
 /**
  * 数据大屏Controller
- * 
+ *
  * @author zhengjie
  * @date 2023-09-08
  */
 @RestController
 @RequestMapping("/system/display")
-public class TDataDisplayController extends BaseController
-{
+public class TDataDisplayController extends BaseController {
     @Autowired
     private ITShouhuanAlarmListService tShouhuanAlarmListService;
 
@@ -49,32 +48,30 @@ public class TDataDisplayController extends BaseController
      * 查询SOS预警处理列表
      */
     @GetMapping("/list")
-    public TableDataInfo list(DataAlarmListDto dataAlarmListDto)
-    {
+    public TableDataInfo list(DataAlarmListDto dataAlarmListDto) {
         startPage();
         List<DataAlarmListDto> list = tShouhuanAlarmListService.selectTShouhuanAlarmList(dataAlarmListDto);
-        List<AlarmListDto> alarmListDtoList = new ArrayList<>();
-        for (DataAlarmListDto dto : list){
-            AlarmListDto alarmListDto = new AlarmListDto();
-            alarmListDto.setName(dto.getName());
-            alarmListDto.setTelno(dto.getTel_one());
-            alarmListDto.setLocation(getCounterLocation(dto.getGps_long() + "," + dto.getGps_lat()));
-            alarmListDto.setAlarmMessage(tDeviceListService.checkMessage(dto.getAlarm_type()));
-            alarmListDto.setCreatetime(dto.getCreatetime());
-            alarmListDtoList.add(alarmListDto);
-        }
-        return getDataTable1(alarmListDtoList,tShouhuanAlarmListService.selectTShouhuanAlarmListCount());
+        List<AlarmListDto> alarmListDtos = list.stream().map(
+                mapper -> {
+                    AlarmListDto alarmListDto = new AlarmListDto();
+                    alarmListDto.setName(mapper.getName());
+                    alarmListDto.setTelno(mapper.getTel_one());
+                    alarmListDto.setLocation(getCounterLocation(mapper.getGps_long() + "," + mapper.getGps_lat()));
+                    alarmListDto.setAlarmMessage(tDeviceListService.checkMessage(mapper.getAlarm_type()));
+                    alarmListDto.setCreatetime(mapper.getCreatetime());
+                    return alarmListDto;
+                }
+        ).collect(Collectors.toList());
+        return getDataTable1(alarmListDtos, tShouhuanAlarmListService.selectTShouhuanAlarmListCount());
     }
 
     @GetMapping("/count")
-    public AjaxResult count()
-    {
+    public AjaxResult count() {
         return success(userProfileService.selectuserAgeCount());
     }
 
     @GetMapping("/alarm")
-    public AjaxResult alarm()
-    {
+    public AjaxResult alarm() {
         AlarmStatusDto dto = new AlarmStatusDto();
         dto.setAlarmSOSSolve(tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve());
         dto.setUn_alarmSOSSolve(tShouhuanAlarmListService.selectTShouhuanAlarmSOS() - tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve());
@@ -92,22 +89,20 @@ public class TDataDisplayController extends BaseController
     }
 
     @GetMapping("/percent")
-    public AjaxResult percent()
-    {
+    public AjaxResult percent() {
         AlarmPercentDto dto = new AlarmPercentDto();
-        dto.setAlarmSOS(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve(),tShouhuanAlarmListService.selectTShouhuanAlarmSOS()));
-        dto.setAlarmRail(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve(),tShouhuanAlarmListService.selectTShouhuanAlarmRail()));
-        dto.setAlarmFall(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmFallSolve(),tShouhuanAlarmListService.selectTShouhuanAlarmFall()));
+        dto.setAlarmSOS(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve(), tShouhuanAlarmListService.selectTShouhuanAlarmSOS()));
+        dto.setAlarmRail(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve(), tShouhuanAlarmListService.selectTShouhuanAlarmRail()));
+        dto.setAlarmFall(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmFallSolve(), tShouhuanAlarmListService.selectTShouhuanAlarmFall()));
         int statusSum = tShouhuanAlarmListService.selectTShouhuanAlarmStatus() + tShouhuanAlarmListService.selectTShouhuanAlarmStatusSolve();
-        dto.setAlarmStauts(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmStatus(),statusSum));
+        dto.setAlarmStauts(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmStatus(), statusSum));
         int alarmAll = tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmFallSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmOtherSolve();
-        dto.setAlarmAll(checkPercent(alarmAll,tShouhuanAlarmListService.selectTShouhuanAlarmListCount()));
+        dto.setAlarmAll(checkPercent(alarmAll, tShouhuanAlarmListService.selectTShouhuanAlarmListCount()));
         return success(dto);
     }
 
     @GetMapping("/deviceView")
-    public AjaxResult deviceView()
-    {
+    public AjaxResult deviceView() {
         DeviceViewDto dto = new DeviceViewDto();
         dto.setDeviceCount(tShouhuanAlarmListService.selectTShouhuanAlarmStatus() + tShouhuanAlarmListService.selectTShouhuanAlarmStatusSolve());
         dto.setDeviceOnline(tShouhuanAlarmListService.selectTShouhuanAlarmStatus());
@@ -117,64 +112,64 @@ public class TDataDisplayController extends BaseController
     }
 
     @GetMapping("/deviceType")
-    public AjaxResult deviceType()
-    {
+    public AjaxResult deviceType() {
         Integer total = tDeviceListService.selectDeviceListCount();
         List<DeviceTypeDto> deviceListDto = tDeviceListService.selectDeviceListDto();
-        for (DeviceTypeDto listDto : deviceListDto){
+        for (DeviceTypeDto listDto : deviceListDto) {
             listDto.setDeviceStr(checkDeviceType(listDto.getDevice_model()));
-            listDto.setDevicePercent(checkPercent(listDto.getCount(),total));
+            listDto.setDevicePercent(checkPercent(listDto.getCount(), total));
         }
         AjaxResult ajax = new AjaxResult();
-        ajax.put("list",deviceListDto);
+        ajax.put("list", deviceListDto);
         ajax.put("total", total);
-        return AjaxResult.success("操作成功",ajax);
+        return AjaxResult.success("操作成功", ajax);
     }
 
     @GetMapping("/userAgeAll")
-    public AjaxResult userAgeAll()
-    {
+    public AjaxResult userAgeAll() {
         Integer total = userProfileService.selectuserAgeCount();
         List<UserAgeDto> dtoList = userProfileService.selectuserAgeDto();
         dtoList.removeIf(user -> StringUtils.isNull(user.getAge()));
         AjaxResult ajax = new AjaxResult();
-        ajax.put("list",dtoList);
+        ajax.put("list", dtoList);
         ajax.put("total", total);
-        return AjaxResult.success("操作成功",ajax);
+        return AjaxResult.success("操作成功", ajax);
     }
 
     @GetMapping("/mapGpsView")
-    public AjaxResult mapGpsView()
-    {
+    public AjaxResult mapGpsView() {
         List<MapGpsDto> dtoList = itShouhuanInfoService.selectMapGpsView();
         AjaxResult ajax = new AjaxResult();
         ajax.put("lnglat", dtoList);
         AjaxResult ajax1 = new AjaxResult();
-        ajax1.put("pointList",ajax);
-        return AjaxResult.success("操作成功",ajax1);
+        ajax1.put("pointList", ajax);
+        return AjaxResult.success("操作成功", ajax1);
     }
 
     @GetMapping("/mapGpsViewV2")
     public AjaxResult mapGpsViewV2() {   //TODO 暂时写在Controller中
         List<MapGpsDto> dtoList = itShouhuanInfoService.selectMapGpsView();
-        List<AjaxResult> collect = dtoList.stream()
-                .map(mapGpsDto -> {
-                    AjaxResult ajax = new AjaxResult();
-                    List<Float> list = new ArrayList<>();
-                    list.add(mapGpsDto.getGps_long());
-                    list.add(mapGpsDto.getGps_lat());
-                    ajax.put("lnglat", list);
-                    return ajax;
-                }).filter(
-                        person -> {
-                            List<Float> lngList = (List<Float>) person.get("lnglat");
-                            if (lngList != null && !lngList.isEmpty() && lngList.size() >= 2) {
-                                Float lng = lngList.get(0);
-                                Float lat = lngList.get(1);
-                                return lng > 0 && lat > 0;
-                            }
-                            return false;
-                        }).collect(Collectors.toList());
+        List<AjaxResult> collect = new ArrayList<>();
+        if (dtoList != null && !dtoList.isEmpty()) {
+            collect = dtoList.stream()
+                    .map(mapGpsDto -> {
+                        AjaxResult ajax = new AjaxResult();
+                        List<Float> list = new ArrayList<>();
+                        list.add(mapGpsDto.getGps_long());
+                        list.add(mapGpsDto.getGps_lat());
+                        ajax.put("lnglat", list);
+                        return ajax;
+                    }).filter(
+                            person -> {
+                                List<Float> lngList = (List<Float>) person.get("lnglat");
+                                if (lngList != null && !lngList.isEmpty() && lngList.size() >= 2) {
+                                    Float lng = lngList.get(0);
+                                    Float lat = lngList.get(1);
+                                    return lng > 0 && lat > 0;
+                                }
+                                return false;
+                            }).collect(Collectors.toList());
+        }
         return AjaxResult.success("操作成功", collect);
     }
 
@@ -182,8 +177,7 @@ public class TDataDisplayController extends BaseController
      * 用户新增
      */
     @GetMapping("/addUser")
-    public AjaxResult addUser()
-    {
+    public AjaxResult addUser() {
         List<AddUserDto> dtoList = userProfileService.selectAddUser();
         return success(dtoList);
     }
@@ -192,21 +186,20 @@ public class TDataDisplayController extends BaseController
      * 设备新增
      */
     @GetMapping("/addDevice")
-    public AjaxResult addDevice()
-    {
+    public AjaxResult addDevice() {
         List<AddDeviceDto> dtoList = tDeviceListService.selectAddDevice();
         LocalDate currentDate = LocalDate.now();
         LocalDate lastMonthDate = currentDate.minusMonths(1);
-        int year= currentDate.getYear();
-        if (dtoList.size() == 2){
-            int lastMonth = lastMonthDate.getMonthValue()-1;
+        int year = currentDate.getYear();
+        if (dtoList.size() == 2) {
+            int lastMonth = lastMonthDate.getMonthValue() - 1;
             AddDeviceDto dto = new AddDeviceDto();
             dto.setMonth(year + "-0" + lastMonth);
             dto.setCount(0);
             dtoList.add(dto);
-        }else if (dtoList.size() == 1){
+        } else if (dtoList.size() == 1) {
             int lastMonth = lastMonthDate.getMonthValue();
-            int lastlastMonth = lastMonthDate.getMonthValue()-1;
+            int lastlastMonth = lastMonthDate.getMonthValue() - 1;
             AddDeviceDto dto = new AddDeviceDto();
             dto.setMonth(year + "-0" + lastMonth);
             dto.setCount(0);
@@ -221,10 +214,9 @@ public class TDataDisplayController extends BaseController
     }
 
     @GetMapping("/alarmStatusList")
-    public AjaxResult alarmStatusList()
-    {
+    public AjaxResult alarmStatusList() {
         List<AlarmStatusListDto> dtoList = tShouhuanAlarmListService.selectAlarmStatusListDto();
-        for (AlarmStatusListDto dto : dtoList){
+        for (AlarmStatusListDto dto : dtoList) {
             dto.setAlarm_msg(tDeviceListService.checkMessage(dto.getAlarm_type()));
         }
         return success(dtoList);
@@ -234,8 +226,7 @@ public class TDataDisplayController extends BaseController
      * 设备总览
      */
     @GetMapping("/deviceOver")
-    public AjaxResult deviceOver()
-    {
+    public AjaxResult deviceOver() {
         DeviceOverDto dto = new DeviceOverDto();
         dto.setBindDevice(tDeviceListService.selectDeviceListCount());
         dto.setBindUser(tDeviceListService.selectTDeviceListBandUser());
@@ -247,11 +238,10 @@ public class TDataDisplayController extends BaseController
      * 查询SOS预警处理列表
      */
     @GetMapping("/alarmList")
-    public AjaxResult alarmList(DataAlarmListDto dataAlarmListDto)
-    {
+    public AjaxResult alarmList(DataAlarmListDto dataAlarmListDto) {
         List<DataAlarmListDto> list = tShouhuanAlarmListService.selectTShouhuanAlarmList(dataAlarmListDto);
         List<MessageAlarmListDto> messageAlarmListDtoList = new ArrayList<>();
-        for (DataAlarmListDto dto : list){
+        for (DataAlarmListDto dto : list) {
             MessageAlarmListDto alarmListDto = new MessageAlarmListDto();
             alarmListDto.setName(dto.getName());
             alarmListDto.setAlarm_msg(tDeviceListService.checkMessage(dto.getAlarm_type()));
@@ -267,13 +257,13 @@ public class TDataDisplayController extends BaseController
     }
 
 
-
     /**
      * 逆地理编码
+     *
      * @param location
      * @return
      */
-    public String getCounterLocation(String location){
+    public String getCounterLocation(String location) {
 
         Map<String, String> params = new HashMap<>();
         params.put("location", location);
@@ -287,13 +277,14 @@ public class TDataDisplayController extends BaseController
     /**
      * 计算百分比
      */
-    public String checkPercent(int num1, int num2){
+    public String checkPercent(int num1, int num2) {
         NumberFormat numberFormat = NumberFormat.getInstance();
         numberFormat.setMaximumFractionDigits(2);
-        String result = numberFormat.format((float)num1/(float)num2*100);
+        String result = numberFormat.format((float) num1 / (float) num2 * 100);
         return result;
     }
 
+<<<<<<< HEAD
     public String checkDeviceType(Integer device_model){
         SysDictData date = new SysDictData();
         date.setDictType("sys_device_type");
@@ -302,6 +293,16 @@ public class TDataDisplayController extends BaseController
             if (device_model == Integer.parseInt(sysDictData.getDictValue())){
                 return sysDictData.getDictLabel();
             }
+=======
+    public String checkDeviceType(Integer device_model) {
+        switch (device_model) {
+            case 0:
+                return "S8";
+            case 1:
+                return "X5";
+            default:
+                return "无效";
+>>>>>>> c9056a51da1e5d78b74d6e682c7c9dfe7371603f
         }
         return "null";
     }