Browse Source

Merge branch 'dev' of http://219.151.181.73:3000/zhuwei/bladex into dev

LHB 3 tháng trước cách đây
mục cha
commit
c8fd4fc442

+ 30 - 0
blade-common/src/main/java/org/springblade/common/utils/YiKeYunApiUtils.java

@@ -43,6 +43,7 @@ public class YiKeYunApiUtils {
             map.put("high", jsonData.get("tem_day").toString());
             map.put("low", jsonData.get("tem_night").toString());
             map.put("windLevel", jsonData.get("win_speed").toString());
+            map.put("nums", jsonData.getInteger("nums").toString());
         } catch (IOException e) {
             e.printStackTrace();
             return null;
@@ -98,6 +99,9 @@ public class YiKeYunApiUtils {
             }
             log.info("获取当天天气 ======= sb.toString():" + sb);
             JSONObject jsonData = JSONObject.parseObject(sb.toString());
+            map.put("nums", new HashMap<String, String>(){{
+                put("nums", jsonData.getInteger("nums").toString());
+            }});
             JSONArray list = jsonData.getJSONArray("list");
 
             list.forEach(item -> {
@@ -122,5 +126,31 @@ public class YiKeYunApiUtils {
         return map;
     }
 
+    /**
+     * 易客 国内LBS逆地理编码服务 (区县级) 每日免费500次
+     * 根据经纬度坐标解析地址详情
+     */
+    public static Map<String, String> getPosition(String LatitudeAndLongitude) throws IOException {
+        String getUrl = String.format("http://apia.yikeapi.com/geocode?appid=%s&appsecret=%s&output=json&location=", API_YIKEYUN_APPID, API_YIKEYUN_APPSECRET, LatitudeAndLongitude);
+        URL url = new URL(getUrl);
+        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8));
+        String res;
+        StringBuilder sb = new StringBuilder("");
+        while ((res = in.readLine()) != null) {
+            sb.append(res.trim());
+        }
+        log.info("获取经纬度坐标地址 ======= sb.toString():" + sb);
+        Map<String, String> map = new HashMap<>();
+        JSONObject jsonData = JSONObject.parseObject(sb.toString());
+        map.put("nums", jsonData.get("nums").toString());
+        JSONObject regeocode = (JSONObject) jsonData.get("regeocode");
+        JSONObject addressComponent = (JSONObject) regeocode.get("addressComponent");
+        map.put("province", addressComponent.get("province").toString());
+        map.put("city", addressComponent.get("city").toString());
+        map.put("district", addressComponent.get("district").toString());
+        map.put("adcode", addressComponent.get("adcode").toString());
+        return map;
+    }
+
 
 }

+ 3 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/utils/ItextPdfUtils.java

@@ -49,6 +49,9 @@ public class ItextPdfUtils {
         twoTable.setWidthPercentage(widthPercentage);
         //设置每页占满
         twoTable.setSplitLate(false);
+        if (text == null) {
+            text = "";
+        }
         String[] split = text.split("\n");
         for (String s : split) {
             PdfPCell cell = pdfTableStyle2(s, size10font);

+ 199 - 91
blade-service/blade-business/src/main/java/org/springblade/business/controller/InformationWriteQueryController.java

@@ -147,6 +147,8 @@ public class InformationWriteQueryController extends BladeController {
 
     private final ExcelTabClient excelTabClient;
 
+    private final IRecycleBinService recycleBinService;
+
     @Autowired
     StringRedisTemplate RedisTemplate;
 
@@ -1454,7 +1456,7 @@ public R<Object> batchTask(@RequestBody StartTaskVO startTaskVO) {
                             jdbcTemplate.execute(sql);
                         }
                         var = true;
-                        getPdfs(queryMap.get(id));
+//                        getPdfs(queryMap.get(id));
                     } else {
                         return R.fail("创建主流程失败");
                     }
@@ -3087,8 +3089,8 @@ private void currentNodeAllParent(StringBuilder nodeName, WbsTreeContract curren
 private void currentNodeAllChild(List<WbsTreeContract> resultChildNodes, List<WbsTreeContract> childNodes, String contractId) {
     if (childNodes.size() > 0) {
         //如果存在子级,那么递归获取子级的子级
-        List<Long> ids = childNodes.stream().map(WbsTreeContract::getId).collect(Collectors.toList());
-        List<WbsTreeContract> childNodeList = jdbcTemplate.query("select p_key_id,id,parent_id,type from m_wbs_tree_contract where is_deleted = 0 and contract_id = " + contractId + " and parent_id in(" + StringUtils.join(ids, ",") + ")", new BeanPropertyRowMapper<>(WbsTreeContract.class));
+        List<Long> ids = childNodes.stream().map(WbsTreeContract::getId).distinct().collect(Collectors.toList());
+        List<WbsTreeContract> childNodeList = jdbcTemplate.query("select p_key_id,id,parent_id,type,contract_id,project_id,full_name,node_name from m_wbs_tree_contract where is_deleted = 0 and contract_id = " + contractId + " and parent_id in(" + StringUtils.join(ids, ",") + ")", new BeanPropertyRowMapper<>(WbsTreeContract.class));
         if (childNodeList.size() > 0) {
             resultChildNodes.addAll(childNodeList);
             this.currentNodeAllChild(resultChildNodes, childNodeList, contractId);
@@ -3123,105 +3125,211 @@ public R removeContractTreeNodeJudge(@RequestParam String ids) {
     return R.data(true);
 }
 
-/**
- * 删除节点
- *
- * @param ids 节点的primaryKeyId(只有一个值)
- * @return 删除结果
- */
-@PostMapping("/removeContractTreeNode")
-@ApiOperationSupport(order = 11)
-@ApiOperation(value = "删除节点")
-@ApiImplicitParam(name = "ids", value = "节点的primaryKeyId")
-public R<Boolean> removeContractTreeNode(@RequestParam String ids) {
-    //根据传入的节点,将其所有子节点删除
-    WbsTreeContract removeNode = this.wbsTreeContractClient.getContractWbsTreeByPrimaryKeyId(Long.parseLong(ids));
+    /**
+     * 删除节点
+     * @param ids 节点的primaryKeyId
+     * @return 删除结果
+     */
+    @PostMapping("/removeContractTreeNode")
+    @ApiOperationSupport(order = 11)
+    @ApiOperation(value = "批量删除节点")
+    @ApiImplicitParam(name = "ids", value = "节点的primaryKeyId, 逗号拼接")
+    public R<Boolean> removeContractTreeNode(@RequestParam String ids) {
+        if (!ids.isEmpty()) {
+            List<WbsTreeContract> removeWbsTreeContracts = this.jdbcTemplate.query("select p_key_id,id,parent_id,type,contract_id,project_id,full_name,node_name from m_wbs_tree_contract where is_deleted = 0 and p_key_id in (" + ids + ")", new BeanPropertyRowMapper<>(WbsTreeContract.class));
+            if (removeWbsTreeContracts.isEmpty()) {
+                return R.fail("删除失败:节点不存在");
+            }
 
-        /*//判断是否存在原始节点
-        if (ObjectUtil.isEmpty(removeNode.getOldId())) {
-            return R.data(300, false, "节点【" + removeNode.getFullName() + "】为原始节点,不允许删除");
-        }*/
+            String contractId = removeWbsTreeContracts.get(0).getContractId();
+            String projectId = removeWbsTreeContracts.get(0).getProjectId();
+            removeWbsTreeContracts.forEach(node -> {
+                if (contractId == null || !contractId.equals(node.getContractId())) {
+                    throw new ServiceException("删除失败:节点不属于同一合同段");
+                }
+            });
 
-    //查询当前操作的节点的父级关系
-    StringBuilder parentNodeName = new StringBuilder();
-    this.currentNodeAllParent(parentNodeName, removeNode);
+            List<WbsTreeContract> removeNodeList = new ArrayList<>();
+            Map<Long , WbsTreeContract> unremoveNodeMap = new HashMap<>();
+            // 查询所有子节点
+            this.currentNodeAllChild(removeNodeList, removeWbsTreeContracts, contractId);
+            removeNodeList.addAll(removeWbsTreeContracts);
+            // 根据pKeyId去重
+            removeNodeList = distinct(removeNodeList);
+            //获取pKeyId
+            List<Long> removeList = removeNodeList.stream().map(WbsTreeContract::getPKeyId).distinct().collect(Collectors.toList());
+            if (!removeList.isEmpty()) {
+                String wbsIds = removeList.stream().map(Object::toString).collect(Collectors.joining(","));
+                /** 判断是否子节点有上报或审批过的资料,因为父id和祖级节点错误,直接使用上面的值去查询上报情况*/
+                List<String> unRemoveIds = jdbcTemplate.queryForList("SELECT wbs_id from u_information_query WHERE wbs_id in (" + wbsIds + ") and is_deleted = 0 and status in (1,2) GROUP BY wbs_id HAVING count(1) > 0", String.class);
+                if (!unRemoveIds.isEmpty()) {
+                    // 剔除此节点
+                    Map<String, String> map = unRemoveIds.stream().collect(Collectors.toMap(id -> id, Function.identity()));
+                    removeNodeList.removeIf(node -> {
+                        //删除掉表格 TODO(不清楚为什么要剔除表格,按理说删除节点后,节点下的表也应该一起删除的,猜测或许是为了方便恢复节点的时候表数据还存在)2023年9月19日
+                        boolean removeIf = node.getType() != null && new Integer("2").equals(node.getType());
+                        boolean equals = map.containsKey(node.getPKeyId().toString());
+                        if (equals) {
+                            unremoveNodeMap.put(node.getPKeyId(), node);
+                        }
+                        return removeIf || equals;
+                    });
+                    Map<Long, WbsTreeContract> contractMap = removeNodeList.stream().collect(Collectors.toMap(WbsTreeContract::getId, Function.identity()));
+                    Map<Long, WbsTreeContract> tempMap = new HashMap<>();
+                    unremoveNodeMap.forEach((key, value) -> collectNodeAndAncestors(value, contractMap, tempMap));
+                    unremoveNodeMap.putAll(tempMap);
+                }
+            }
+            if(removeNodeList.isEmpty()) {
+                return R.fail("删除失败,该节点下有已填报的资料");
+            }
 
-    //判断是否子节点有上报或审批过的资料
-//        List<InformationQuery> list = informationQueryService.selectChildrenNodeInfo(removeNode);
-//        if (list != null && list.size() >= 1) {
-//            return R.data(300, false, "存在已经上报或审批的节点,不允许删除");
-//        }
+            StringBuilder position = new StringBuilder();
+            List<String> idArray = removeNodeList.stream().filter(wbsTreeContract -> !unremoveNodeMap.containsKey(wbsTreeContract.getPKeyId())).map(wbsTreeContract -> {
+                position.append(",").append(StringUtils.isNotEmpty(wbsTreeContract.getFullName()) ? wbsTreeContract.getFullName() : wbsTreeContract.getNodeName());
+                return wbsTreeContract.getPKeyId() + "";
+            }).distinct().collect(Collectors.toList());
 
-    //查询所有子节点 TODO(不能用ancestors字段获取,ancestors字段有问题,目前用递归获取)2023年9月19日
-    //List<WbsTreeContract> removeNodeList = jdbcTemplate.query("select p_key_id,type from m_wbs_tree_contract where is_deleted = 0 and contract_id = " + removeNode.getContractId() + " and ancestors like '%" + removeNode.getId() + "%'", new BeanPropertyRowMapper<>(WbsTreeContract.class));
-    List<WbsTreeContract> removeNodeList = new ArrayList<>();
-    this.currentNodeAllChild(removeNodeList, Collections.singletonList(removeNode), removeNode.getContractId());
+            JSONObject json = new JSONObject();
+            json.put("operationObjIds", idArray);
+            String positionStr = position.substring(1);
+            json.put("operationObjName", positionStr);
+            json.put("projectId", projectId);
+            json.put("contractId", contractId);
+            this.operationLogClient.saveUserOperationLog(4, "资料管理", "工序资料", json);
+
+            //保存进回收站
+            this.recycleBinService.save(new RecycleBin(String.join(",", idArray), "工程划分批量删除", 2, positionStr, projectId, contractId));
+            //改为物理删除 (8.28改为逻辑删除,方便恢复)
+            this.wbsTreeContractClient.removeContractTreeNode(idArray);
+            //更新redis
+            this.informationQueryService.delAsyncWbsTree(removeWbsTreeContracts.get(0).getContractId());
+        }
+        return R.data(true);
+    }
 
-    //获取pKeyId
-    List<Long> removeList = removeNodeList.stream().map(WbsTreeContract::getPKeyId).distinct().collect(Collectors.toList());
-    if (removeList.size() > 0) {
-        /** 判断是否子节点有上报或审批过的资料,因为父id和祖级节点错误,直接使用上面的值去查询上报情况*/
-        List<InformationQuery> list = informationQueryService.selectChildrenNodeInfo(removeList);
-        if (list != null && list.size() >= 1) {
-            return R.data(300, false, "存在已经上报或审批的节点,不允许删除");
+    // 递归收集节点及其所有父节点
+    private  void collectNodeAndAncestors(WbsTreeContract node, Map<Long, WbsTreeContract> contractMap, Map<Long , WbsTreeContract> unremoveNodeMap) {
+        if (node == null || node.getParentId() == null || contractMap == null || contractMap.isEmpty()) return;
+        WbsTreeContract item = contractMap.get(node.getParentId());
+        if (item != null && item.getId() != null && item.getId().equals(node.getParentId())) {
+            unremoveNodeMap.put(item.getPKeyId(), item);
+            collectNodeAndAncestors(item, contractMap, unremoveNodeMap);
         }
-        //拼接
-        ids = ids + "," + String.join(",", JSONArray.parseArray(JSONObject.toJSONString(removeList), String.class));
-        //删除掉表格 TODO(不清楚为什么要剔除表格,按理说删除节点后,节点下的表也应该一起删除的,猜测或许是为了方便恢复节点的时候表数据还存在)2023年9月19日
-        removeNodeList.removeIf(tree -> tree.getType() != null && new Integer("2").equals(tree.getType()));
     }
-    //获取被删除节点名称
-    //String nodeName = StringUtils.isNotEmpty(removeNode.getFullName()) ? removeNode.getFullName() : removeNode.getNodeName() + "," + removeNodeList.stream().map(wbs -> StringUtils.isNotEmpty(wbs.getFullName()) ? wbs.getFullName() : wbs.getNodeName()).collect(Collectors.joining());
-
-    //获取当前节点下所有填报节点
-        /*List<QueryProcessDataVO> queryProcess = new ArrayList<>();
-        if (!Arrays.asList("1,2,3,4".split(",")).contains(removeNode.getMajorDataType().toString())) {
-            queryProcess = this.informationQueryService.queryProcessDataByParentIdAndContractId2(removeNode.getId().toString(), 1, removeNode.getContractId());
-            if (queryProcess == null || queryProcess.size() == 0) {
-                //填报节点
-                queryProcess = this.informationQueryService.queryProcessDataByPrimaryKeyIdAndClassify(removeNode.getPKeyId().toString(), 1);
-            }
+    private List<WbsTreeContract> distinct(List<WbsTreeContract> list) {
+        if (list == null || list.isEmpty()) {
+            return list;
         }
-
-        if (queryProcess != null && queryProcess.size() > 0) {
-            //检查这些填报节点是否存在已经审批或已经上报的节点,如果存在则不允许删除
-            List<QueryProcessDataVO> approvalList = queryProcess.stream().filter(vo -> new Integer("2").equals(vo.getStatus()) && vo.getInformationQueryId() != null).collect(Collectors.toList());
-            List<QueryProcessDataVO> runTaskList = queryProcess.stream().filter(vo -> new Integer("1").equals(vo.getStatus()) && vo.getInformationQueryId() != null).collect(Collectors.toList());
-            if (approvalList.size() > 0 || runTaskList.size() > 0) {
-                //说明存在已经审批或已经上报的节点,不允许删除
-                return R.data(300, false, "存在已经上报或审批的节点,不允许删除");
+        Map<Long, WbsTreeContract> tempMap = new HashMap<>();
+        return list.stream().filter(node -> {
+            if (tempMap.containsKey(node.getPKeyId())) {
+                return false;
             }
-        }*/
-
-    //保存操作记录
-    List<String> idArray = JSONArray.parseArray(JSONObject.toJSONString(ids.split(",")), String.class);
-    //获取当前节点的所有父节点
-    List<WbsTreeContract> result = new ArrayList<>();
-    result.add(removeNode);
-    this.queryParentNode(removeNode, result);
-    StringBuilder pathName = new StringBuilder();
-    for (int i = 1, l = result.size(); i <= l; i++) {
-        WbsTreeContract node = result.get(result.size() - i);
-        pathName.append("-").append(StringUtils.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
+            tempMap.put(node.getPKeyId(), node);
+            return true;
+        }).collect(Collectors.toList());
     }
-    JSONObject json = new JSONObject();
-    json.put("operationObjIds", idArray);
-    json.put("operationObjName", pathName.substring(1));
-    json.put("projectId", removeNode.getProjectId());
-    json.put("contractId", removeNode.getContractId());
-    this.operationLogClient.saveUserOperationLog(4, "资料管理", "工序资料", json);
-
-    //保存进回收站
-    this.recycleBinClient.saveDelBusinessData(idArray, StringUtils.isNotEmpty(removeNode.getFullName()) ? removeNode.getFullName() : removeNode.getNodeName(), 2, parentNodeName.toString(), removeNode.getProjectId(), removeNode.getContractId());
-
-    //改为物理删除 (8.28改为逻辑删除,方便恢复)
-    this.wbsTreeContractClient.removeContractTreeNode(idArray);
 
-    //更新redis
-    this.informationQueryService.delAsyncWbsTree(removeNode.getContractId());
-
-    return R.data(true);
-}
+///**
+// * 删除节点
+// *
+// * @param ids 节点的primaryKeyId(只有一个值)
+// * @return 删除结果
+// */
+//@PostMapping("/removeContractTreeNode")
+//@ApiOperationSupport(order = 11)
+//@ApiOperation(value = "删除节点")
+//@ApiImplicitParam(name = "ids", value = "节点的primaryKeyId")
+//public R<Boolean> removeContractTreeNode(@RequestParam String ids) {
+//    //根据传入的节点,将其所有子节点删除
+//    WbsTreeContract removeNode = this.wbsTreeContractClient.getContractWbsTreeByPrimaryKeyId(Long.parseLong(ids));
+//
+//        /*//判断是否存在原始节点
+//        if (ObjectUtil.isEmpty(removeNode.getOldId())) {
+//            return R.data(300, false, "节点【" + removeNode.getFullName() + "】为原始节点,不允许删除");
+//        }*/
+//
+//    //查询当前操作的节点的父级关系
+//    StringBuilder parentNodeName = new StringBuilder();
+//    this.currentNodeAllParent(parentNodeName, removeNode);
+//
+//    //判断是否子节点有上报或审批过的资料
+////        List<InformationQuery> list = informationQueryService.selectChildrenNodeInfo(removeNode);
+////        if (list != null && list.size() >= 1) {
+////            return R.data(300, false, "存在已经上报或审批的节点,不允许删除");
+////        }
+//
+//    //查询所有子节点 TODO(不能用ancestors字段获取,ancestors字段有问题,目前用递归获取)2023年9月19日
+//    //List<WbsTreeContract> removeNodeList = jdbcTemplate.query("select p_key_id,type from m_wbs_tree_contract where is_deleted = 0 and contract_id = " + removeNode.getContractId() + " and ancestors like '%" + removeNode.getId() + "%'", new BeanPropertyRowMapper<>(WbsTreeContract.class));
+//    List<WbsTreeContract> removeNodeList = new ArrayList<>();
+//    this.currentNodeAllChild(removeNodeList, Collections.singletonList(removeNode), removeNode.getContractId());
+//
+//    //获取pKeyId
+//    List<Long> removeList = removeNodeList.stream().map(WbsTreeContract::getPKeyId).distinct().collect(Collectors.toList());
+//    if (removeList.size() > 0) {
+//        /** 判断是否子节点有上报或审批过的资料,因为父id和祖级节点错误,直接使用上面的值去查询上报情况*/
+//        List<InformationQuery> list = informationQueryService.selectChildrenNodeInfo(removeList);
+//        if (list != null && list.size() >= 1) {
+//            return R.data(300, false, "存在已经上报或审批的节点,不允许删除");
+//        }
+//        //拼接
+//        ids = ids + "," + String.join(",", JSONArray.parseArray(JSONObject.toJSONString(removeList), String.class));
+//        //删除掉表格 TODO(不清楚为什么要剔除表格,按理说删除节点后,节点下的表也应该一起删除的,猜测或许是为了方便恢复节点的时候表数据还存在)2023年9月19日
+//        removeNodeList.removeIf(tree -> tree.getType() != null && new Integer("2").equals(tree.getType()));
+//    }
+//    //获取被删除节点名称
+//    //String nodeName = StringUtils.isNotEmpty(removeNode.getFullName()) ? removeNode.getFullName() : removeNode.getNodeName() + "," + removeNodeList.stream().map(wbs -> StringUtils.isNotEmpty(wbs.getFullName()) ? wbs.getFullName() : wbs.getNodeName()).collect(Collectors.joining());
+//
+//    //获取当前节点下所有填报节点
+//        /*List<QueryProcessDataVO> queryProcess = new ArrayList<>();
+//        if (!Arrays.asList("1,2,3,4".split(",")).contains(removeNode.getMajorDataType().toString())) {
+//            queryProcess = this.informationQueryService.queryProcessDataByParentIdAndContractId2(removeNode.getId().toString(), 1, removeNode.getContractId());
+//            if (queryProcess == null || queryProcess.size() == 0) {
+//                //填报节点
+//                queryProcess = this.informationQueryService.queryProcessDataByPrimaryKeyIdAndClassify(removeNode.getPKeyId().toString(), 1);
+//            }
+//        }
+//
+//        if (queryProcess != null && queryProcess.size() > 0) {
+//            //检查这些填报节点是否存在已经审批或已经上报的节点,如果存在则不允许删除
+//            List<QueryProcessDataVO> approvalList = queryProcess.stream().filter(vo -> new Integer("2").equals(vo.getStatus()) && vo.getInformationQueryId() != null).collect(Collectors.toList());
+//            List<QueryProcessDataVO> runTaskList = queryProcess.stream().filter(vo -> new Integer("1").equals(vo.getStatus()) && vo.getInformationQueryId() != null).collect(Collectors.toList());
+//            if (approvalList.size() > 0 || runTaskList.size() > 0) {
+//                //说明存在已经审批或已经上报的节点,不允许删除
+//                return R.data(300, false, "存在已经上报或审批的节点,不允许删除");
+//            }
+//        }*/
+//
+//    //保存操作记录
+//    List<String> idArray = JSONArray.parseArray(JSONObject.toJSONString(ids.split(",")), String.class);
+//    //获取当前节点的所有父节点
+//    List<WbsTreeContract> result = new ArrayList<>();
+//    result.add(removeNode);
+//    this.queryParentNode(removeNode, result);
+//    StringBuilder pathName = new StringBuilder();
+//    for (int i = 1, l = result.size(); i <= l; i++) {
+//        WbsTreeContract node = result.get(result.size() - i);
+//        pathName.append("-").append(StringUtils.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
+//    }
+//    JSONObject json = new JSONObject();
+//    json.put("operationObjIds", idArray);
+//    json.put("operationObjName", pathName.substring(1));
+//    json.put("projectId", removeNode.getProjectId());
+//    json.put("contractId", removeNode.getContractId());
+//    this.operationLogClient.saveUserOperationLog(4, "资料管理", "工序资料", json);
+//
+//    //保存进回收站
+//    this.recycleBinClient.saveDelBusinessData(idArray, StringUtils.isNotEmpty(removeNode.getFullName()) ? removeNode.getFullName() : removeNode.getNodeName(), 2, parentNodeName.toString(), removeNode.getProjectId(), removeNode.getContractId());
+//
+//    //改为物理删除 (8.28改为逻辑删除,方便恢复)
+//    this.wbsTreeContractClient.removeContractTreeNode(idArray);
+//
+//    //更新redis
+//    this.informationQueryService.delAsyncWbsTree(removeNode.getContractId());
+//
+//    return R.data(true);
+//}
 
 /**
  * 新增子节点

+ 25 - 2
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/WeatherInfoServiceImpl.java

@@ -26,6 +26,8 @@ import org.springblade.manager.feign.ProjectClient;
 import org.springblade.manager.feign.ProjectContractAreaClient;
 import org.springblade.manager.vo.ContractInfoVO;
 import org.springframework.dao.DataAccessException;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.ResultSetExtractor;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -54,6 +56,8 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
 
     private final JdbcTemplate jdbcTemplate;
 
+    private final StringRedisTemplate stringRedisTemplate;
+
     /**
      * 根据所选年份获取当年所有天气台账
      */
@@ -138,11 +142,19 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
                 Map<String, String> weatherMap = cachedWeatherMap.get(area.getCity_code());
                 if (weatherMap == null) {
                     //获取天气信息(百度天气)
-                    weatherMap = YiKeYunApiUtils.getTodayWeatherByAdcode(area.getCity_code() + "000000");
+                    String nums = stringRedisTemplate.opsForValue().get("blade-business::contractArea:yiKeYun:todayWeatherNums");
+                    if (nums != null && Integer.parseInt(nums) <= 19000) {
+                        weatherMap = YiKeYunApiUtils.getTodayWeatherByAdcode(area.getCity_code() + "000000");
+                    }
                     if (weatherMap == null) {
                         weatherMap = BaiduApiUtil.getTodayWeather(area.getCity_code());
                     }
-                    cachedWeatherMap.put(area.getCity_code(), weatherMap);
+                    if (weatherMap != null) {
+                        cachedWeatherMap.put(area.getCity_code(), weatherMap);
+                        if (weatherMap.get("nums") != null) {
+                            stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:todayWeatherNums", weatherMap.get("nums"));
+                        }
+                    }
                 }
                 if (weatherMap != null) {
                     //计算平均气温
@@ -406,6 +418,11 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
     }
 
     public Map<String, Map<String, String>> getHistoryWeather(ProjectContractArea area, String month) {
+        String nums = stringRedisTemplate.opsForValue().get("blade-business::contractArea:yiKeYun:historyWeatherNums");
+        if (nums == null || Integer.parseInt(nums) > 19000) {
+            log.info("获取历史天气失败:易客云获取历史天气的api次数已用完。");
+            return null;
+        }
         String county = area.getCounty();
         if (county.length() > 2) {
             county = county.substring(0, county.length() - 1);
@@ -425,6 +442,12 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
         }
         if (cityId != null) {
             Map<String, Map<String, String>> historyWeather = YiKeYunApiUtils.getHistoryWeather(cityId, Integer.parseInt(month.substring(0, 4)), Integer.parseInt(month.substring(4, 6)));
+            if (historyWeather != null) {
+                Map<String, String> map = historyWeather.get("nums");
+                if (map != null && map.get("nums") != null) {
+                    stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:historyWeatherNums", map.get("nums"));
+                }
+            }
             return historyWeather;
         } else {
             log.info("获取历史天气失败:" + area.getCity()+"-"+area.getCounty());

+ 19 - 18
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ContractInfoServiceImpl.java

@@ -1059,19 +1059,23 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
                 });
             }
             String projectPlace = contractInfo.getProjectPlace();
+            Map<String, String> position = new HashMap<>();
             try {
                 Map<String, Object> addressInfo = BaiduApiUtil.geocoding(projectPlace);
-                Map<String, String> position = BaiduApiUtil.getPosition(addressInfo.get("lat").toString()
+                position = BaiduApiUtil.getPosition(addressInfo.get("lat").toString()
                         + "," + addressInfo.get("lng").toString());
-                ProjectContractArea projectContractArea = new ProjectContractArea();
-                projectContractArea.setProvince(position.get("province"));
-                projectContractArea.setCity(position.get("city"));
-                projectContractArea.setCounty(position.get("district"));
-                projectContractArea.setCity_code(position.get("adcode"));
-                projectContractArea.setProjectId(contractInfo.getPId());
-                projectContractArea.setIsDeleted(0);
-                projectContractArea.setContractId(String.valueOf(contractInfo.getId()));
-                projectContractArea.setProjectId(contractInfo.getPId());
+            } catch (Exception e) {
+                throw new ServiceException("施工台账初始化失败: 百度地理编码API配额超限,今日限制访问");
+            }
+            ProjectContractArea projectContractArea = new ProjectContractArea();
+            projectContractArea.setProvince(position.get("province"));
+            projectContractArea.setCity(position.get("city"));
+            projectContractArea.setCounty(position.get("district"));
+            projectContractArea.setCity_code(position.get("adcode"));
+            projectContractArea.setProjectId(contractInfo.getPId());
+            projectContractArea.setIsDeleted(0);
+            projectContractArea.setContractId(String.valueOf(contractInfo.getId()));
+            projectContractArea.setProjectId(contractInfo.getPId());
 //                QueryWrapper<ProjectContractArea> queryWrapper = new QueryWrapper<>();
 //                queryWrapper.eq("project_id", contractInfo.getPId());
 //                queryWrapper.eq("contract_id", contractInfo.getId());
@@ -1085,15 +1089,12 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
 //                    int res = projectContractAreaMapper.insert(projectContractArea);
 //                    return res > 0;
 //                }
-                //删除之前所有的地址,再新增
-                projectContractAreaMapper.delete(new LambdaQueryWrapper<ProjectContractArea>()
-                        .eq(ProjectContractArea::getContractId, projectContractArea.getContractId()));
-                int res = projectContractAreaMapper.insert(projectContractArea);
-                return res > 0;
+            //删除之前所有的地址,再新增
+            projectContractAreaMapper.delete(new LambdaQueryWrapper<ProjectContractArea>()
+                    .eq(ProjectContractArea::getContractId, projectContractArea.getContractId()));
+            int res = projectContractAreaMapper.insert(projectContractArea);
+            return res > 0;
 //                return true;
-            } catch (IOException e) {
-                throw new ServiceException("施工台账初始化失败");
-            }
         }
         return false;
     }