Ver Fonte

CommonService.java修改

lengfaqiang há 2 anos atrás
pai
commit
5248094e76

+ 34 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/HttpDemoController.java

@@ -1,13 +1,23 @@
 package com.sckw.slope.detection.controller;
 
+import com.alibaba.fastjson2.JSONObject;
+import com.sckw.core.model.constant.NumberConstant;
+import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.core.web.response.PhpResult;
+import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.service.api.DetectionApiService;
 import jakarta.servlet.http.HttpServletResponse;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
 /**
  * @author lfdc
  * @description httpDemo
@@ -22,7 +32,7 @@ public class HttpDemoController {
 
     @RequestMapping(value = "/toSaasGetDemo", method = RequestMethod.GET)
     public void httpToSaasGetDemo(HttpServletResponse response) {
-        String s= response.getHeader("a");
+        String s = response.getHeader("a");
         HttpResult saasGetDemo = detectionApiService.toSaasGetDemo();
         System.out.println(saasGetDemo);
     }
@@ -34,5 +44,28 @@ public class HttpDemoController {
         System.out.println(saasPostDemo);
     }
 
+    @RequestMapping(value = "/toSaasGetDict", method = RequestMethod.GET)
+    public void httpToSaasGetDict() {
+        HashMap<String, Object> mapBody = new HashMap<>(NumberConstant.SIXTEEN);
+        mapBody.put("code", DictEnum.THRESHOLD_TYPE.getCodeType());
+        HashMap<String, String> mapPara = new HashMap<>(NumberConstant.SIXTEEN);
+        mapPara.put("code", DictEnum.THRESHOLD_TYPE.getCodeType());
+        mapPara.put("type", "1");
+        PhpResult httpResult = detectionApiService.toSaasGetDict("http://10.10.10.185:9501",
+                "/common/getDict", mapBody
+                , mapPara);
+        List<SystemDict> systemDictList = new ArrayList<>();
+        if (httpResult.isStatus()) {
+            ArrayList list = JSONObject.parseObject(JSONObject.toJSONString(httpResult.getData()), ArrayList.class);
+            if (!CollectionUtils.isEmpty(list)) {
+                list.forEach(s -> {
+                    SystemDict systemDict = JSONObject.parseObject(s.toString(), SystemDict.class);
+                    systemDictList.add(systemDict);
+                });
+            }
+        }
+        System.out.println(systemDictList);
+    }
+
 
 }

+ 37 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -4,18 +4,25 @@ import com.alibaba.fastjson2.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.BusinessException;
+import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.page.PageRes;
+import com.sckw.core.web.response.PhpResult;
 import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
 import com.sckw.slope.detection.model.dto.HeaderData;
+import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
+import com.sckw.slope.detection.service.api.DetectionApiService;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.util.Base64;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author lfdc
@@ -26,6 +33,12 @@ import java.util.List;
 @Service
 public class CommonService {
 
+    @Value("${OkHttpClit.url}")
+    String url;
+
+    @Autowired
+    DetectionApiService detectionApiService;
+
     @Autowired
     KwsDictMapper dictMapper;
 
@@ -40,6 +53,15 @@ public class CommonService {
         }
         String message = new String(Base64.getDecoder().decode(uInfo));
         HeaderData headerData = JSONObject.parseObject(message, HeaderData.class);
+        if (headerData.getMountainId().isBlank()) {
+            throw new BusinessException("矿山id不能为空");
+        }
+        if (headerData.getCompanyId().isBlank()) {
+            throw new BusinessException("企业id不能为空");
+        }
+        if (headerData.getCompanyName().isBlank()) {
+            throw new BusinessException("企业名称不能为空");
+        }
         return headerData;
     }
 
@@ -49,4 +71,19 @@ public class CommonService {
         PageInfo<QueryDictTypePageReqVo> info = new PageInfo<>();
         return PageRes.build(info, list);
     }
+
+    public Map<String,SystemDict> getDictList(Map<String, Object> mapBody, Map<String, String> mapPara) {
+        PhpResult result = detectionApiService.toSaasGetDict(url,
+                "/common/getDict", mapBody
+                , mapPara);
+        Map<String, SystemDict> map = new HashMap(NumberConstant.SIXTEEN);
+        if (result.isStatus()) {
+            HashMap hashMap = JSONObject.parseObject(JSONObject.toJSONString(result.getData()), HashMap.class);
+            for (Object value : hashMap.values()) {
+                SystemDict systemDict = JSONObject.parseObject(value.toString(), SystemDict.class);
+                map.put(systemDict.getValue(), systemDict);
+            }
+        }
+        return map;
+    }
 }