Selaa lähdekoodia

修改dashboard数据源的数据格式

丁治程 1 kuukausi sitten
vanhempi
commit
df7d1d01b9

+ 2 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/base/mapper/InterlockBaseMapper.java

@@ -69,4 +69,6 @@ public interface InterlockBaseMapper extends BaseMapper<InterlockBase> {
 	InterlockUser getUserInfoByName(@Param("wiseUser") String wiseUser);
 
     List<InterlockBase> getListByPId(@Param("interlockId") String interlockId);
+
+	List<InterlockBase> getDeviceByUser(@Param("wiSEUser") String wiSEUser);
 }

+ 11 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/base/mapper/xml/InterlockBaseMapper.xml

@@ -65,4 +65,15 @@
 		select * from interlock_base where pid = #{interlockId}
 	</select>
 
+	<select id="getDeviceByUser" resultType="org.jeecg.modules.base.entity.InterlockBase">
+		SELECT DISTINCT(interlock_name)
+		FROM interlock_base b
+		left join interlock_system_limit s
+		on b.id = s.interlock_apparatus_id
+		left join interlock_user u
+		on s.interlock_user_id = u.id
+		where u.username = #{wiSEUser}
+		and s.limit_type in ('0','1')
+	</select>
+
 </mapper>

+ 2 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/base/service/IInterlockBaseService.java

@@ -115,4 +115,6 @@ public interface IInterlockBaseService extends IService<InterlockBase> {
 	void addInterlockBase1(InterlockBase interlockBase);
 
 	List<InterlockBase> getListByPId(String interlockId);
+
+	List<InterlockBase> getDeviceByUser(String wiSEUser);
 }

+ 5 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/base/service/impl/InterlockBaseServiceImpl.java

@@ -424,4 +424,9 @@ public class InterlockBaseServiceImpl extends ServiceImpl<InterlockBaseMapper, I
     public List<InterlockBase> getListByPId(String interlockId) {
         return baseMapper.getListByPId(interlockId);
     }
+
+    @Override
+    public List<InterlockBase> getDeviceByUser(String wiSEUser) {
+        return baseMapper.getDeviceByUser(wiSEUser);
+    }
 }

+ 106 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/dashboardInterface/controller/HistoryLoopHealthLevelController.java

@@ -11,6 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 /**
@@ -51,6 +54,9 @@ public class HistoryLoopHealthLevelController {
     public String query(@RequestBody JSONObject request) throws Exception {
         log.info("调用query接口:{}", JSON.toJSONString(request));
 
+        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+        DateTimeFormatter dateFormatterDay = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
         SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM");
 
@@ -87,8 +93,108 @@ public class HistoryLoopHealthLevelController {
             beginDate = formatMonth.format(beginDated);
             endDate = formatMonth.format(endDated);
             loopHealthLevelMap = dashboardService.getLoopHealthLevelsMonth(deviceName, sysName, beginDate,endDate);
+            if (loopHealthLevelMap.size() == 0){
+                YearMonth startMonth = YearMonth.parse(beginDate, dateFormatter);
+                YearMonth endMonth = YearMonth.parse(endDate, dateFormatter);
+                YearMonth currentYearMonth = startMonth.plusMonths(1);
+
+                ArrayList<LoopHealthLevel> aList = new ArrayList<>();
+                ArrayList<LoopHealthLevel> bList = new ArrayList<>();
+                ArrayList<LoopHealthLevel> cList = new ArrayList<>();
+                ArrayList<LoopHealthLevel> dList = new ArrayList<>();
+                while (!currentYearMonth.isAfter(endMonth)){
+                    LoopHealthLevel loopHealthLevelA = new LoopHealthLevel();
+                    loopHealthLevelA.setLevel("A");
+                    loopHealthLevelA.setNumber("0");
+                    loopHealthLevelA.setTime(currentYearMonth.format(dateFormatter));
+                    aList.add(loopHealthLevelA);
+
+                    LoopHealthLevel loopHealthLevelB = new LoopHealthLevel();
+                    loopHealthLevelB.setLevel("B");
+                    loopHealthLevelB.setNumber("0");
+                    loopHealthLevelB.setTime(currentYearMonth.format(dateFormatter));
+                    bList.add(loopHealthLevelB);
+
+                    LoopHealthLevel loopHealthLevelC = new LoopHealthLevel();
+                    loopHealthLevelC.setLevel("C");
+                    loopHealthLevelC.setNumber("0");
+                    loopHealthLevelC.setTime(currentYearMonth.format(dateFormatter));
+                    cList.add(loopHealthLevelC);
+
+                    LoopHealthLevel loopHealthLevelD = new LoopHealthLevel();
+                    loopHealthLevelD.setLevel("D");
+                    loopHealthLevelD.setNumber("0");
+                    loopHealthLevelD.setTime(currentYearMonth.format(dateFormatter));
+                    dList.add(loopHealthLevelD);
+
+                    currentYearMonth = currentYearMonth.plusMonths(1);
+                }
+
+                loopHealthLevelMap.put("A",aList);
+                loopHealthLevelMap.put("B",bList);
+                loopHealthLevelMap.put("C",cList);
+                loopHealthLevelMap.put("D",dList);
+            }
         }else {
             loopHealthLevelMap = dashboardService.getLoopHealthLevels(deviceName, sysName, beginDate,endDate);
+            if (loopHealthLevelMap.size() == 0){
+
+                ArrayList<LoopHealthLevel> aList = new ArrayList<>();
+                ArrayList<LoopHealthLevel> bList = new ArrayList<>();
+                ArrayList<LoopHealthLevel> cList = new ArrayList<>();
+                ArrayList<LoopHealthLevel> dList = new ArrayList<>();
+
+                // 解析为 LocalDate 对象
+                LocalDate start = LocalDate.parse(beginDate, dateFormatterDay);
+                LocalDate end = LocalDate.parse(endDate, dateFormatterDay);
+
+                // 获取输入日期的月份和年份
+                int year = end.getYear();
+                int month = end.getMonthValue();
+
+                // 创建该月份的开始和结束日期
+                LocalDate monthStart = LocalDate.of(year, month, 1);
+                LocalDate monthEnd = monthStart.withDayOfMonth(monthStart.lengthOfMonth());
+
+                // 如果 endDate 之后的月份,则将结束日期限制在该月的最后一天
+                if (end.isAfter(monthEnd)) {
+                    end = monthEnd;
+                }
+                LocalDate currentDate = start;
+                while (!currentDate.isAfter(end)) {
+                    if (!currentDate.isBefore(monthStart) && !currentDate.isAfter(monthEnd)) {
+                        LoopHealthLevel loopHealthLevelA = new LoopHealthLevel();
+                        loopHealthLevelA.setLevel("A");
+                        loopHealthLevelA.setNumber("0");
+                        loopHealthLevelA.setTime(currentDate.format(dateFormatterDay));
+                        aList.add(loopHealthLevelA);
+
+                        LoopHealthLevel loopHealthLevelB = new LoopHealthLevel();
+                        loopHealthLevelB.setLevel("B");
+                        loopHealthLevelB.setNumber("0");
+                        loopHealthLevelB.setTime(currentDate.format(dateFormatterDay));
+                        bList.add(loopHealthLevelB);
+
+                        LoopHealthLevel loopHealthLevelC = new LoopHealthLevel();
+                        loopHealthLevelC.setLevel("C");
+                        loopHealthLevelC.setNumber("0");
+                        loopHealthLevelC.setTime(currentDate.format(dateFormatterDay));
+                        cList.add(loopHealthLevelC);
+
+                        LoopHealthLevel loopHealthLevelD = new LoopHealthLevel();
+                        loopHealthLevelD.setLevel("D");
+                        loopHealthLevelD.setNumber("0");
+                        loopHealthLevelD.setTime(currentDate.format(dateFormatterDay));
+                        dList.add(loopHealthLevelD);
+                    }
+                    currentDate = currentDate.plusDays(1);
+                }
+
+                loopHealthLevelMap.put("A",aList);
+                loopHealthLevelMap.put("B",bList);
+                loopHealthLevelMap.put("C",cList);
+                loopHealthLevelMap.put("D",dList);
+            }
         }
 
         for (String key : loopHealthLevelMap.keySet()) {

+ 47 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/dashboardInterface/controller/HistroyTylController.java

@@ -12,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -53,6 +56,10 @@ public class HistroyTylController {
     @PostMapping(value = "/query")
     public String query(@RequestBody JSONObject request) throws Exception {
         log.info("调用query接口:{}", JSON.toJSONString(request));
+
+        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+        DateTimeFormatter dateFormatterDay = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
         SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM");
 
@@ -93,9 +100,48 @@ public class HistroyTylController {
             beginDate = formatMonth.format(beginDated);
             endDate = formatMonth.format(endDated);
             tylList = dashboardService.getTylBySysNameTimeMonth(deviceName,sysName,beginDate,endDate);
-
+            if (tylList.size() == 0){
+                YearMonth startMonth = YearMonth.parse(beginDate, dateFormatter);
+                YearMonth endMonth = YearMonth.parse(endDate, dateFormatter);
+                YearMonth currentYearMonth = startMonth.plusMonths(1);
+                while (!currentYearMonth.isAfter(endMonth)){
+                    InterlockTyl interlockTyl = new InterlockTyl();
+                    interlockTyl.setTyl("0");
+                    interlockTyl.setTime(currentYearMonth.format(dateFormatter));
+                    tylList.add(interlockTyl);
+                    currentYearMonth = currentYearMonth.plusMonths(1);
+                }
+            }
         }else {
             tylList = dashboardService.getTylBySysNameTime(deviceName,sysName,beginDate,endDate);
+            if (tylList.size() == 0){
+                // 解析为 LocalDate 对象
+                LocalDate start = LocalDate.parse(beginDate, dateFormatterDay);
+                LocalDate end = LocalDate.parse(endDate, dateFormatterDay);
+
+                // 获取输入日期的月份和年份
+                int year = end.getYear();
+                int month = end.getMonthValue();
+
+                // 创建该月份的开始和结束日期
+                LocalDate monthStart = LocalDate.of(year, month, 1);
+                LocalDate monthEnd = monthStart.withDayOfMonth(monthStart.lengthOfMonth());
+
+                // 如果 endDate 之后的月份,则将结束日期限制在该月的最后一天
+                if (end.isAfter(monthEnd)) {
+                    end = monthEnd;
+                }
+                LocalDate currentDate = start;
+                while (!currentDate.isAfter(end)) {
+                    if (!currentDate.isBefore(monthStart) && !currentDate.isAfter(monthEnd)) {
+                        InterlockTyl interlockTyl = new InterlockTyl();
+                        interlockTyl.setTyl("0");
+                        interlockTyl.setTime(currentDate.format(dateFormatterDay));
+                        tylList.add(interlockTyl);
+                    }
+                    currentDate = currentDate.plusDays(1);
+                }
+            }
         }
 
 

+ 25 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/dashboardInterface/controller/InterlockDeviceController.java

@@ -3,8 +3,11 @@ package org.jeecg.modules.dashboardInterface.controller;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.modules.base.mapper.InterlockBaseMapper;
 import org.jeecg.modules.dashboardInterface.service.IDashboardINterfaceService;
+import org.jeecg.modules.interlockUser.entity.InterlockUser;
 import org.jeecg.modules.iotedgeCollectData.entity.ResultD;
+import org.jeecg.modules.iotedgeCollectData.service.RestClientService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -32,6 +35,14 @@ public class InterlockDeviceController {
     @SuppressWarnings("all")
     private IDashboardINterfaceService dashboardService;
 
+    @Autowired
+    @SuppressWarnings("all")
+    private RestClientService restClientService;
+
+    @Autowired
+    @SuppressWarnings("all")
+    private InterlockBaseMapper baseMapper;
+
     @GetMapping(value = "/")
     public JSONObject testConnect() {
         log.info("检查服务成功");
@@ -43,7 +54,20 @@ public class InterlockDeviceController {
     @PostMapping(value = "/search")
     public String search(@RequestBody JSONObject request) {
         log.info("调用search接口:{}", JSON.toJSONString(request));
-
+        //List<String> list = new ArrayList<>();
+        //List<String> ssoLoginInfo = restClientService.getSSOLoginInfo();
+        //String wiSEUser = ssoLoginInfo.stream()
+        //        .filter(s -> s.startsWith("WISEUser="))
+        //        .map(s -> s.substring("WISEUser=".length()).split(";")[0].trim())
+        //        .findFirst()
+        //        .orElse("WiSEUser not found");
+        //
+        //InterlockUser interlockUser = baseMapper.getUserInfoByName(wiSEUser);
+        //if(interlockUser.getRole().equals("0")){//如果当前用户是系统管理员
+        //    list = dashboardService.getAllDevice();
+        //}else{
+        //    list = dashboardService.getDeviceByUser(wiSEUser);
+        //}
         List<String> list = dashboardService.getAllDevice();
 
         return JSON.toJSONString(list);

+ 2 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/dashboardInterface/service/IDashboardINterfaceService.java

@@ -119,4 +119,6 @@ public interface IDashboardINterfaceService {
     *   date: 2024/7/11
     */
     Map<String, List<LoopHealthLevel>> getLoopHealthLevelsMonth(String deviceName, String sysName, String beginDate, String endDate);
+
+    List<String> getDeviceByUser(String wiSEUser);
 }

+ 10 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/dashboardInterface/service/impl/IDashboardINterfaceServiceImpl.java

@@ -211,6 +211,16 @@ public class IDashboardINterfaceServiceImpl implements IDashboardINterfaceServic
         return countMonthService.getLoopHealthLevelsMonth(base.getId(),sysName,beginDate,endDate);
     }
 
+    @Override
+    public List<String> getDeviceByUser(String wiSEUser) {
+        ArrayList<String> deviceList = new ArrayList<>();
+        List<InterlockBase> list = baseService.getDeviceByUser(wiSEUser);
+        for (InterlockBase item : list) {
+            deviceList.add(item.getInterlockName());
+        }
+        return deviceList;
+    }
+
     /**
     *   author: dzc
     *   version: 1.0

+ 18 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/service/impl/InterlockCountDayServiceImpl.java

@@ -18,6 +18,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -91,7 +93,14 @@ public class InterlockCountDayServiceImpl extends ServiceImpl<InterlockCountDayM
                 LoopHealthLevel loopHealthLevel = new LoopHealthLevel();
                 loopHealthLevel.setLevel(d);
                 loopHealthLevel.setNumber("0");
-                loopHealthLevel.setTime(loopHealthLevelList.get(0).getTime());
+                if (loopHealthLevelList.size() == 0) {
+                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                    LocalDate currentDate = LocalDate.now();
+                    String currentDay = currentDate.format(formatter);
+                    loopHealthLevel.setTime(currentDay);
+                }else {
+                    loopHealthLevel.setTime(loopHealthLevelList.get(0).getTime());
+                }
                 loopHealthLevelList.add(loopHealthLevel);
             }
         }
@@ -137,7 +146,14 @@ public class InterlockCountDayServiceImpl extends ServiceImpl<InterlockCountDayM
             tyl = yty.divide(total,4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
         }
         interlockTyl.setTyl(String.valueOf(tyl));
-        interlockTyl.setTime(list.get(0).getTime());
+        if(list.size() > 0){
+            interlockTyl.setTime(list.get(0).getTime());
+        }else {
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate currentDate = LocalDate.now();
+            String currentDay = currentDate.format(formatter);
+            interlockTyl.setTime(currentDay);
+        }
         tylList.add(interlockTyl);
         return tylList;
     }

+ 18 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/iotedgeCollectData/service/RestClientService.java

@@ -107,6 +107,24 @@ public class RestClientService {
     }
 
 
+    public List<String> getSSOLoginInfo() {
+        String url = "http://"+iotIp+":"+iotPort+"/v1/sso/auth";
+        //String url = configService.getConfigValue(ConfigInfo.GETTOKEN);
+        //String username = configService.getConfigValue(ConfigInfo.USERNAME);
+        //String password = configService.getConfigValue(ConfigInfo.PASSWORD);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("username",ssoUsername);
+        jsonObject.put("password",ssoPassword);
+        HttpHeaders headers = new HttpHeaders();
+        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
+        headers.setContentType(type);
+        HttpEntity<String> httpEntity = new HttpEntity<String>(jsonObject.toString(), headers);
+        ResponseEntity<JSONObject> response = restTemplate.postForEntity(url, httpEntity, JSONObject.class);
+        HttpHeaders headers1 = response.getHeaders();
+        List<String> list = headers1.get(HttpHeaders.SET_COOKIE);
+        return list;
+    }
+
     /**
     *   author: dzc
     *   version: 1.0