丁治程 1 semana atrás
pai
commit
f1f65fed72

+ 9 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/dashboardInterface/controller/CurrentInterlockStatusController.java

@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -102,14 +104,19 @@ public class CurrentInterlockStatusController {
         ArrayList<String[]> strings2 = new ArrayList<>();
 
 
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate currentDate = LocalDate.now();
+        String currentDay = currentDate.format(formatter);
+        Date dateTime = format.parse(currentDay);
+
         String str1 = "2024-06-13";
         Date data1 = format.parse(str1);
 
-        String[] v1 = new String[]{String.valueOf(total)};
+        String[] v1 = new String[]{String.valueOf(total),String.valueOf(dateTime.getTime())};
         strings1.add(v1);
         result1.setDatapoints(strings1);
 
-        String[] v2 = new String[]{String.valueOf(wty)};
+        String[] v2 = new String[]{String.valueOf(wty),String.valueOf(dateTime.getTime())};
         strings2.add(v2);
         result2.setDatapoints(strings2);
 

+ 10 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/dashboardInterface/controller/CurrentInterlockYbController.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.dashboardInterface.controller;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.base.service.IInterlockBaseService;
 import org.jeecg.modules.dashboardInterface.entity.InterlockAndYbStatus;
 import org.jeecg.modules.dashboardInterface.service.IDashboardINterfaceService;
@@ -11,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -98,14 +101,19 @@ public class CurrentInterlockYbController {
         ArrayList<String[]> strings2 = new ArrayList<>();
 
 
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate currentDate = LocalDate.now();
+        String currentDay = currentDate.format(formatter);
+        Date dateTime = format.parse(currentDay);
+
         String str1 = "2024-06-13";
         Date data1 = format.parse(str1);
 
-        String[] v1 = new String[]{normalNumber};
+        String[] v1 = new String[]{normalNumber,String.valueOf(dateTime.getTime())};
         strings1.add(v1);
         result1.setDatapoints(strings1);
 
-        String[] v2 = new String[]{anNormalNumber};
+        String[] v2 = new String[]{anNormalNumber,String.valueOf(dateTime.getTime())};
         strings2.add(v2);
         result2.setDatapoints(strings2);
 

+ 8 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/iotedgeCollectData/controller/IoredgeInterfaceTestController.java

@@ -175,4 +175,12 @@ public class IoredgeInterfaceTestController extends JeecgController<IotedgeColle
         return restClientService.ifUserInSSO(userName);
     }
 
+    @AutoLog(value = "SSO-新增用户-------")
+    @ApiOperation(value="SSO-新增用户-------", notes="SSO-新增用户-------")
+    @PostMapping(value = "/test")
+    public JSONObject test(@RequestParam(name = "userName",required = false) String userName, @RequestParam(name = "password",required = false) String password){
+        return restClientService.addSSOUserTest(userName,password);
+    }
+
+
 }

+ 52 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/iotedgeCollectData/service/RestClientService.java

@@ -372,8 +372,14 @@ public class RestClientService {
         String ssoToken = getSSOToken();
         String url = configService.getConfigValue(ConfigInfo.SSO_CREATECLIENT);
         JSONObject jsonObject = new JSONObject();
-        jsonObject.put("appName",System.getenv("appName"));
+        //if (ObjectUtil.isNotNull(System.getenv("appName"))){
+        //    jsonObject.put("appName",System.getenv("appName"));
+        //}else {
+        //    jsonObject.put("appName","InterlockServer");
+        //}
+        jsonObject.put("appName","InterlockServer");
         jsonObject.put("appId",System.getenv("appId"));
+        jsonObject.put("serviceName","InterlockServer");
         jsonObject.put("cluster",System.getenv("cluster"));
         jsonObject.put("workspace",System.getenv("workspace"));
         jsonObject.put("namespace",System.getenv("namespace"));
@@ -462,6 +468,51 @@ public class RestClientService {
 
     }
 
+
+    public JSONObject addSSOUserTest(String userName,String password){
+        ArrayList<String> scopList = new ArrayList<>();
+        scopList.add("Admin");
+
+        String clientToken = configService.getConfigValue(ConfigInfo.POST_CLIENT_TOKEN);
+        String clientId = configService.getConfigValue(ConfigInfo.CLIENT_ID);
+        String clientSecret = configService.getConfigValue(ConfigInfo.CLIENT_SECRET);
+
+        if (ObjectUtil.isNull(clientToken) || "".equals(clientToken) || ObjectUtil.isNull(clientId) || "".equals(clientId) || ObjectUtil.isNull(clientSecret) || "".equals(clientSecret)){
+            getClientToken2();
+            clientToken = configService.getConfigValue(ConfigInfo.POST_CLIENT_TOKEN);
+            clientId = configService.getConfigValue(ConfigInfo.CLIENT_ID);
+            clientSecret = configService.getConfigValue(ConfigInfo.CLIENT_SECRET);
+        }
+
+
+        String url = configService.getConfigValue(ConfigInfo.SSO_ADDUSER)+"/"+userName+"/scopes";
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("clientId",clientId);
+        jsonObject.put("clientSecret",clientSecret);
+        jsonObject.put("action","append");
+        jsonObject.put("scopes",scopList);
+        if (ObjectUtil.isNotNull(password) || !"".equals(password)) {
+            jsonObject.put("password",password);
+        }
+        HttpHeaders headers = new HttpHeaders();
+        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
+        headers.setContentType(type);
+        headers.add("Authorization", "Bearer " + clientToken);
+        HttpEntity<String> httpEntity = new HttpEntity<String>(jsonObject.toString(), headers);
+
+        HttpClient httpClient = HttpClients.custom().build();
+        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
+
+        //RestTemplate restTemplate1 = new RestTemplate(factory);
+        //restTemplate1.setErrorHandler(new MyResponseErrorHandler());
+        ResponseEntity<JSONObject> response = restTemplate.exchange(url,HttpMethod.PATCH,httpEntity, JSONObject.class);
+        return response.getBody();
+
+    }
+
+
+
     /**
     *   author: dzc
     *   version: 1.0

+ 4 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/util/MyResponseErrorHandler.java

@@ -27,9 +27,13 @@ public class MyResponseErrorHandler implements ResponseErrorHandler {
 
     @Override
     public void handleError(ClientHttpResponse response) throws IOException {
+        System.out.println("SSOinfo:"+response.getBody());
         String responseBody = "";
         try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getBody()))) {
+            System.out.println("SSOinfo:"+reader);
+            System.out.println("SSOinfo:"+reader.lines());
             responseBody = reader.lines().collect(Collectors.joining("\n"));
+            System.out.println("SSOinfo:"+responseBody);
         }
         throw new RuntimeException(responseBody);
     }