Przeglądaj źródła

Merge remote-tracking branch 'origin/master' into master

yangyj 1 rok temu
rodzic
commit
88b4acd626

+ 5 - 1
blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java

@@ -68,6 +68,11 @@ public interface CommonConstant {
 
     String SG_THE_LOG = "SG.theLog";
 
+    /**
+     * 白马公司ids
+     */
+    String BM_COMPANY_IDS = "bm.company.ids";
+
     /**
      * 默认排序字段
      */
@@ -83,5 +88,4 @@ public interface CommonConstant {
      */
     Integer API_SCOPE_CATEGORY = 2;
 
-
 }

+ 47 - 11
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -707,10 +707,15 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
         List<ArchiveTreeContract> authlist = authFilter(list, contractId, nodeId);
 
         //步骤三:遍历归档树节点整理出 默认规则节点,分类并卷节点,单独组卷节点 三个集合。
+		List<ArchiveTreeContract> list0 = new ArrayList<>();
         List<ArchiveTreeContract> list1 = new ArrayList<>();
 		List<ArchiveTreeContract> list2= new ArrayList<>();
 		List<ArchiveTreeContract> list3= new ArrayList<>();
 		for(ArchiveTreeContract treeContract:authlist){
+			if (treeContract.getArchiveAutoType() == null || treeContract.getArchiveAutoType() == -1) {
+				list0.add(treeContract);
+				continue;
+			}
 			Integer archiveAutoType = treeContract.getArchiveAutoType();
 			switch (archiveAutoType){
 				case 1:
@@ -728,21 +733,29 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 
 		//分盒文件集合
 		Map<String,List<ArchiveFile>> boxMap = new LinkedHashMap<>();
+		Map<Long,String> boxFileMap = new LinkedHashMap<>();
 
-		archiveAutoMethod3(list3,boxMap);//单独组卷
+		archiveAutoMethod3(list3,boxMap,boxFileMap);//单独组卷
 		//设置完成度30%
 		projectClient.updateIsArchivesAutoById(projectId,30);
-		archiveAutoMethod2(list2,projectId,boxMap);//分类组卷
+		archiveAutoMethod2(list2,projectId,boxMap,boxFileMap);//分类组卷
 		//设置完成度50%
 		projectClient.updateIsArchivesAutoById(projectId,50);
-		archiveAutoMethod1(list1,boxMap);//默认组卷
+		archiveAutoMethod1(list1,boxMap,boxFileMap);//默认组卷
+
+		//分盒组卷的且节点没配置组卷类型的
+		archiveAutoMethod0(list0,boxMap,boxFileMap);//默认组卷
 		//设置完成度70%
 		projectClient.updateIsArchivesAutoById(projectId,70);
 		archiveAutoMethodBox(boxMap);//分盒组卷
 	}
 
-	private void addBoxMap(ArchiveFile file,Map<String,List<ArchiveFile>> boxMap){
+	private void addBoxMap(ArchiveFile file,Map<String,List<ArchiveFile>> boxMap,Map<Long,String> boxFileMap){
 		String boxName = file.getBoxName();
+		if (boxFileMap.containsKey(file.getId())) {
+			return;
+		}
+
 		if(boxMap.containsKey(boxName)){
 			List<ArchiveFile> boxFiles = boxMap.get(boxName);
 			boxFiles.add(file);
@@ -752,6 +765,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 			boxFiles.add(file);
 			boxMap.put(boxName,boxFiles);
 		}
+		boxFileMap.put(file.getId(),"1");
 	}
 
 	@Override
@@ -1377,7 +1391,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 					//步骤5:判断文件是否存在分盒设置
 					if(file.getBoxNumber()!=null && file.getBoxNumber()!=-1){
 						//添加到分盒文件集合
-						addBoxMap(file,boxMap);
+						addBoxMap(file,boxMap,null);
 						if(archiveFilesSize==archiveFiles.size() && waitArchiveFiles.size()>0){
 							//最后一个文件直接将waitArchiveFiles组卷
 							createArchive3(waitArchiveFiles,node,archivesSize);
@@ -1451,7 +1465,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 	 * @param list
 	 * @param boxMap
 	 */
-	private void archiveAutoMethod3(List<ArchiveTreeContract> list,Map<String,List<ArchiveFile>> boxMap){
+	private void archiveAutoMethod3(List<ArchiveTreeContract> list,Map<String,List<ArchiveFile>> boxMap,Map<Long,String> boxFileMap){
 		//步骤1:遍历节点集合
 		for(ArchiveTreeContract node:list){
 			//步骤2:查询节点下的未组卷文件
@@ -1466,7 +1480,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 					//步骤4:断文件是否存在分盒设置
 					if(file.getBoxNumber()!=null && file.getBoxNumber()!=-1){
 						//添加到分盒文件集合
-						addBoxMap(file,boxMap);
+						addBoxMap(file,boxMap,boxFileMap);
 					}else{
 						//单独组卷流程
 						Integer filePage = file.getFilePage();
@@ -1488,7 +1502,8 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 	/**
 	 * 分类并卷组卷  设置分类的节点下只有一个案卷,节点下的所有文件都组成这个案卷。如果设置分类节点(select=1的)多个,案卷归属排序第一个节点。
 	 */
-	private void archiveAutoMethod2(List<ArchiveTreeContract> list,Long projectId,Map<String,List<ArchiveFile>> boxMap){
+	private void archiveAutoMethod2(List<ArchiveTreeContract> list,Long projectId,
+									Map<String,List<ArchiveFile>> boxMap,Map<Long,String> boxFileMap){
 
 		//分类并卷集合<groupId,List<文件>>
 		Map<Long,List<ArchiveFile>> archiveMap = new HashMap<>();
@@ -1507,7 +1522,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 					//步骤4:判断文件是否存在分盒设置
 					if(file.getBoxNumber()!=null && file.getBoxNumber()!=-1){
 						//添加到分盒文件集合
-						addBoxMap(file,boxMap);
+						addBoxMap(file,boxMap,boxFileMap);
 					}else{
 						//分类并卷流程
 						//步骤5:将文件按照<groupId,List<文件>>放入集合
@@ -1539,7 +1554,8 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 	/**
 	 * 默认组卷流程 文件可以跨节点组卷,受最高并卷节点限制范围,跨节点文件组卷时,案卷规格按照第一个文件所在的节点规格 组卷。
 	 */
-	private void archiveAutoMethod1(List<ArchiveTreeContract> list,Map<String,List<ArchiveFile>> boxMap){
+	private void archiveAutoMethod1(List<ArchiveTreeContract> list,Map<String,List<ArchiveFile>> boxMap,
+									Map<Long,String> boxFileMap){
 		//最高并卷节点
 		Long archiveAutoNodeId=null;
 
@@ -1593,7 +1609,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 				//步骤3.4:判断文件是否存在分盒设置
 				if(file.getBoxNumber()!=null && file.getBoxNumber()!=-1) {
 					//添加到分盒文件集合
-					addBoxMap(file,boxMap);
+					addBoxMap(file,boxMap,boxFileMap);
 					if(nodeSize==list.size() && archiveFilesSize==archiveFiles.size()){
 						//如果当前是最后一个文件直接将waitArchiveFiles组卷
 						createArchive1(waitArchiveFiles,archivesSize);
@@ -1678,6 +1694,26 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 
 	}
 
+
+	/**
+	 * 默认组卷流程 文件可以跨节点组卷,受最高并卷节点限制范围,跨节点文件组卷时,案卷规格按照第一个文件所在的节点规格 组卷。
+	 */
+	private void archiveAutoMethod0(List<ArchiveTreeContract> list,Map<String,List<ArchiveFile>> boxMap,Map<Long,String> boxFileMap){
+
+		for(ArchiveTreeContract node:list){
+			//步骤3.2:查询出当前节点未组卷的文件
+			List<ArchiveFile> archiveFiles = archiveFileClient.getListByNodeID(node.getId().toString());
+			//步骤3.3:遍历未组卷文件
+			for(ArchiveFile file:archiveFiles) {
+				//步骤3.4:判断文件是否存在分盒设置
+				if (file.getBoxNumber() != null && file.getBoxNumber() != -1) {
+					//添加到分盒文件集合
+					addBoxMap(file, boxMap,boxFileMap);
+				}
+			}
+		}
+	}
+
 	/**
 	 * 分盒组卷流程
 	 * @param boxMap

+ 4 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/ArchiveTreeContractImpl.java

@@ -47,6 +47,10 @@ public class ArchiveTreeContractImpl implements ArchiveTreeContractClient {
     @Override
     public List<ArchiveTreeContract> getHavedFileNodeByProjectID(Long projectId) {
         List<ArchiveTreeContract> list = archiveTreeContractMapper.getHavedFileNodeByProjectID(projectId);
+
+        List<ArchiveTreeContract> boxList = archiveTreeContractMapper.getHavedBoxFileNodeByProjectID(projectId);
+
+        list.addAll(boxList);
         return list;
     }
 

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ArchiveTreeContractMapper.java

@@ -75,6 +75,8 @@ public interface ArchiveTreeContractMapper extends BaseMapper<ArchiveTreeContrac
 
     List<ArchiveTreeContract> getHavedFileNodeByProjectID(@Param("projectId") Long projectId);
 
+    List<ArchiveTreeContract> getHavedBoxFileNodeByProjectID(@Param("projectId") Long projectId);
+
     List<ArchiveTreeContract> getListByProjectId(@Param("projectId") Long projectId);
 
     List<ArchiveTreeContract> getStorageNodeByGroupId(@Param("projectId") Long projectId, @Param("archiveAutoGroupId") Long archiveAutoGroupId);

+ 27 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ArchiveTreeContractMapper.xml

@@ -338,6 +338,33 @@
         )
         order by ancestors asc,tree_sort asc
     </select>
+
+    <select id="getHavedBoxFileNodeByProjectID" resultMap="archiveTreeContractResultMap">
+        SELECT
+            *
+        FROM
+            m_archive_tree_contract
+        WHERE
+            1 = 1
+          AND project_id = #{projectId}
+          AND is_deleted = 0
+          AND id IN (
+            SELECT
+                node_id
+            FROM
+                u_archive_file
+            WHERE
+                1 = 1
+              AND project_id = #{projectId}
+              AND is_deleted = 0
+              AND ( is_archive = 0 OR is_archive IS NULL )
+              AND node_id IS NOT NULL
+              AND box_number IS NOT NULL
+        )
+        order by ancestors asc,tree_sort asc
+    </select>
+
+
     <select id="getListByProjectId" resultType="org.springblade.manager.entity.ArchiveTreeContract">
         select id,project_id as projectId,contract_id as contractId,parent_id as parentId,ancestors,node_name as nodeName,status,tree_code as treeCode, ext_type as extType,
                is_deleted as isDeleted,create_time as createTime, file_number_prefix as fileNumberPrefix

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeContractMapper.java

@@ -1,5 +1,6 @@
 package org.springblade.manager.mapper;
 
+import org.apache.ibatis.annotations.CacheNamespace;
 import org.apache.ibatis.annotations.Param;
 import org.springblade.business.entity.InformationQuery;
 import org.springblade.manager.entity.*;
@@ -8,6 +9,7 @@ import org.springblade.manager.vo.*;
 
 import java.util.List;
 
+@CacheNamespace
 public interface WbsTreeContractMapper extends EasyBaseMapper<WbsTreeContract> {
 
     int deleteByIds(@Param("ids") List<Long> ids);

+ 77 - 37
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -285,8 +285,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         String names = StringUtils.join(nodeNames, " , ");
                         throw new ServiceException(StringUtil.format("节点下的 {} 中存在填报数据,删除失败!", names));
                     }
-                    baseMapper.deleteBatch(ids1, pawDTO.getWbsId(), pawDTO.getProjectId(), pawDTO.getContractId());
                 }
+                baseMapper.deleteBatch(ids1, pawDTO.getWbsId(), pawDTO.getProjectId(), pawDTO.getContractId());
             }
 
             //TODO ---------新增---------
@@ -688,29 +688,46 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                 if (new Integer(1).equals(contractInfo.getContractType())) {
                     //获取当前合同段所有缓存节点信息
                     List<WbsTreeContractLazyVO> nodesAll;
-                    Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + contractId);
+                    /*Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + contractId);
                     if (data != null) {
                         nodesAll = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
-                    } else {
-                        nodesAll = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + contractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
-                        if (nodesAll.size() > 0) {
-                            //判断是否有子级,赋值
-                            Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAll.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
-                            for (WbsTreeContractLazyVO vo : nodesAll) {
-                                if (vo.getParentId() == 0) {
-                                    vo.setHasChildren(1);
-                                }
-                                List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
-                                if (childNodes != null && childNodes.size() > 0) {
-                                    vo.setHasChildren(1);
-                                } else {
-                                    vo.setHasChildren(0);
-                                }
+                    } else {*/
+
+                    //long startTime1 = System.currentTimeMillis();
+
+                    /*开启mybatis-plus二级缓存*/
+                    List<WbsTreeContract> wbsTreeContracts = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                            .select(WbsTreeContract::getId, WbsTreeContract::getPKeyId, WbsTreeContract::getParentId)
+                            .eq(WbsTreeContract::getType, 1)
+                            .eq(WbsTreeContract::getStatus, 1)
+                            .eq(WbsTreeContract::getContractId, contractId)
+                    );
+
+                    /*long endTime1 = System.currentTimeMillis();
+                    long executionTime1 = endTime1 - startTime1;
+                    System.out.println("1111111111111:" + executionTime1);*/
+
+                    nodesAll = BeanUtil.copyProperties(wbsTreeContracts, WbsTreeContractLazyVO.class);
+
+                    //nodesAll = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + contractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
+                    if (nodesAll.size() > 0) {
+                        //判断是否有子级,赋值
+                        Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAll.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
+                        for (WbsTreeContractLazyVO vo : nodesAll) {
+                            if (vo.getParentId() == 0) {
+                                vo.setHasChildren(1);
+                            }
+                            List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
+                            if (childNodes != null && childNodes.size() > 0) {
+                                vo.setHasChildren(1);
+                            } else {
+                                vo.setHasChildren(0);
                             }
-                            JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
-                            redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + contractId, JSON.toJSON(array).toString());
                         }
+                        /*JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
+                        redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + contractId, JSON.toJSON(array).toString());*/
                     }
+                    //}
 
                     //获取当前层懒加载节点
                     List<WbsTreeContractLazyVO> lazyNodes = jdbcTemplate.query("select p_key_id,contract_id,(SELECT id FROM u_contract_tree_drawings where process_id = p_key_id) AS drawingsId,id,parent_id,node_type,type,wbs_type,is_concrete,major_data_type,partition_code,old_id,contract_id_relation,is_concealed_works_node,CASE (SELECT count(1) FROM u_tree_contract_first AS tcf WHERE tcf.is_deleted = 0 AND tcf.wbs_node_id = a.p_key_id) WHEN 0 THEN 'false' ELSE 'true' END AS isFirst,IFNULL(if(length(trim(full_name))>0,full_name,node_name),node_name) AS title,(SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_wbs_tree_contract b WHERE b.parent_id = a.id AND b.type = 1 and b.status = 1 AND b.contract_id = " + contractId + " AND b.is_deleted = 0 ) AS hasChildren from m_wbs_tree_contract a where a.node_type != 111 and a.type = 1 and a.status = 1 and a.is_deleted = 0 and parent_id = " + (StringUtils.isNotEmpty(id) ? id : 0) + " and contract_id = " + contractId + " ORDER BY a.sort,title,a.create_time", new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
@@ -757,13 +774,21 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                 .collect(Collectors.toMap(WbsTreeContractLazyQueryInfoVO::getWbsId, WbsTreeContractLazyQueryInfoVO::getStatus, (existingValue, newValue) -> existingValue));
                         List<Long> pKeyIdList = new ArrayList<>(queryInfoMaps.keySet());
 
+
                         //TODO 处理数量
                         //填报过的所有最底层节点
                         List<WbsTreeContractLazyVO> lowestNodesTB = distinctLowestNodesAll.parallelStream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
                         List<Long> lowestNodeParentIdsTB = lowestNodesTB.parallelStream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
                         List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
+
+                        //long startTime2 = System.currentTimeMillis();
+
                         this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
 
+                        /*long endTime2 = System.currentTimeMillis();
+                        long executionTime2 = endTime2 - startTime2;
+                        System.out.println("2222222222222:" + executionTime2);*/
+
                         //最底层节点颜色构造后Map
                         Map<Long, WbsTreeContractLazyVO> lowestNodesMap = lowestNodesTB.stream()
                                 .peek(vo -> {
@@ -778,6 +803,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                     }
                                 }).collect(Collectors.toMap(WbsTreeContractLazyVO::getPKeyId, Function.identity()));
 
+                        //long startTime3 = System.currentTimeMillis();
                         //TODO 处理颜色
                         //先将WbsTreeContractLazyVO转为NodeVO
                         List<NodeVO> nodeVOList = distinctNodesAll.stream().map(this::convertToNodeVO).collect(Collectors.toList());
@@ -792,6 +818,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         //获取所有节点颜色Map
                         Map<Long, Integer> nodeColorStatusMap = nodeVOS.stream().collect(Collectors.toMap(NodeVO::getPKeyId, NodeVO::getStatus, (existing, replacement) -> existing));
 
+                        /*long endTime3 = System.currentTimeMillis();
+                        long executionTime3 = endTime3- startTime3;
+                        System.out.println("3333333333333:" + executionTime3);*/
+
                         //TODO 处理最终结果集
                         if (lazyNodes.size() > 0) {
                             //处理填报数量
@@ -853,29 +883,39 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         if (sgContractInfo != null) {
                             //获取当前合同段所有缓存节点信息
                             List<WbsTreeContractLazyVO> nodesAll;
-                            Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + sgContractId);
+                            /*Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + sgContractId);
                             if (data != null) {
                                 nodesAll = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
-                            } else {
-                                nodesAll = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + sgContractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
-                                if (nodesAll.size() > 0) {
-                                    //判断是否有子级,赋值
-                                    Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAll.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
-                                    for (WbsTreeContractLazyVO vo : nodesAll) {
-                                        if (vo.getParentId() == 0) {
-                                            vo.setHasChildren(1);
-                                        }
-                                        List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
-                                        if (childNodes != null && childNodes.size() > 0) {
-                                            vo.setHasChildren(1);
-                                        } else {
-                                            vo.setHasChildren(0);
-                                        }
+                            } else {*/
+
+                            List<WbsTreeContract> wbsTreeContracts = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                                    .select(WbsTreeContract::getId, WbsTreeContract::getPKeyId, WbsTreeContract::getParentId)
+                                    .eq(WbsTreeContract::getType, 1)
+                                    .eq(WbsTreeContract::getStatus, 1)
+                                    .eq(WbsTreeContract::getContractId, sgContractId)
+                            );
+                            nodesAll = BeanUtil.copyProperties(wbsTreeContracts, WbsTreeContractLazyVO.class);
+
+                            //nodesAll = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + sgContractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
+                            if (nodesAll.size() > 0) {
+                                //判断是否有子级,赋值
+                                Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAll.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
+                                for (WbsTreeContractLazyVO vo : nodesAll) {
+                                    if (vo.getParentId() == 0) {
+                                        vo.setHasChildren(1);
+                                    }
+                                    List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
+                                    if (childNodes != null && childNodes.size() > 0) {
+                                        vo.setHasChildren(1);
+                                    } else {
+                                        vo.setHasChildren(0);
                                     }
-                                    JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
-                                    redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + sgContractId, JSON.toJSON(array).toString());
                                 }
+
+                                /*JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
+                                redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + sgContractId, JSON.toJSON(array).toString());*/
                             }
+                            //}
 
                             //获取当前层懒加载节点
                             List<WbsTreeContractLazyVO> lazyNodes = jdbcTemplate.query("select p_key_id,contract_id,(SELECT id FROM u_contract_tree_drawings where process_id = p_key_id) AS drawingsId,id,parent_id,node_type,type,wbs_type,major_data_type,partition_code,old_id,contract_id_relation,is_concealed_works_node,CASE (SELECT count(1) FROM u_tree_contract_first AS tcf WHERE tcf.is_deleted = 0 AND tcf.wbs_node_id = a.p_key_id) WHEN 0 THEN 'false' ELSE 'true' END AS isFirst,IFNULL(if(length(trim(full_name))>0,full_name,node_name),node_name) AS title,(SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_wbs_tree_contract b WHERE b.parent_id = a.id AND  b.type = 1 and b.status = 1 AND b.contract_id = " + sgContractId + " AND b.is_deleted = 0 ) AS hasChildren from m_wbs_tree_contract a where a.node_type != 111 and a.type = 1 and a.status = 1 and a.is_deleted = 0 and parent_id = " + (StringUtils.isNotEmpty(id) ? id : 0) + " and contract_id = " + sgContractId + " ORDER BY a.sort,title,a.create_time", new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));

+ 6 - 1
blade-service/blade-manager/src/main/resources/application-dev.yml

@@ -16,4 +16,9 @@ oss:
   endpoint: https://oss-cn-chengdu.aliyuncs.com/
   access-key: LTAI4FmSV1pWZAJ9xSvHg5rP
   secret-key: 5D3XQj4pBe8VbOAVFNqdioJA8riH4S
-  bucket-name: bladex-test-info
+  bucket-name: bladex-test-info
+
+#Mybatis-plus配置
+mybatis-plus:
+  configuration:
+    cache-enabled: true #开启mybatis的二级缓存

+ 17 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/bean/GetBMTokenDTO.java

@@ -0,0 +1,17 @@
+package org.springblade.system.user.bean;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+public class GetBMTokenDTO implements Serializable {
+
+    private String uuid;
+    private String username;
+    private String password;
+    private String source;
+
+}

+ 306 - 33
blade-service/blade-user/src/main/java/org/springblade/system/user/thirdparty/ThirdPartySystemApi.java

@@ -2,7 +2,9 @@ package org.springblade.system.user.thirdparty;
 
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.Consts;
@@ -13,22 +15,34 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.message.BasicNameValuePair;
+import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.DigestUtil;
+import org.springblade.core.tool.utils.ObjectUtil;
+import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.feign.SaveUserInfoByProjectClient;
 import org.springblade.system.entity.AuthClient;
+import org.springblade.system.user.bean.GetBMTokenDTO;
 import org.springblade.system.user.bean.GetTokenDTO;
 import org.springblade.system.user.entity.User;
+import org.springblade.system.user.service.IUserService;
+import org.springblade.system.user.util.AesInfoUtil;
+import org.springblade.system.user.util.HttpClientUtil;
+import org.springblade.system.user.util.RsaUtilToken;
 import org.springblade.system.user.util.RsaUtils;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.data.redis.core.RedisTemplate;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.text.ParseException;
+import java.time.Duration;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
@@ -46,55 +60,85 @@ public class ThirdPartySystemApi {
 
     private final JdbcTemplate jdbcTemplate;
     private final RedisTemplate<String, String> redisTemplate;
+    private final IUserService userService;
+    private final SaveUserInfoByProjectClient saveUserInfoByProjectClient;
+
+    /*白马相关常量*/
+    private final static String IP_PORT = "http://219.152.86.38:13427";
+    private final static String PK_URL = IP_PORT + "/prod-api/auth/touch";
+    private final static String TOKEN_URL = IP_PORT + "/prod-api/auth/login";
+    private final static String USER_LIST_URL = IP_PORT + "/prod-api/openapi/biz-v1/user/list";
+    private final static String USERNAME = "白马质检";
+    private final static String PASSWORD = "Bmzj@654321";
+    private final static String SOURCE = "HongChuangBm";
+    private final static String APP_KEY = "9F3C78FC22D07EAB2AEB4DD6CA9644DB";
 
     /**
-     * 获取公钥信息
+     * 根据appKey获取本系统的公钥信息
+     *
+     * @param appKey = blade_client id
      */
     @GetMapping("/auth/public-key")
     public Map<String, Object> getPublicKey(@RequestParam String appKey) {
-        /*查询Redis中已有的键值对数量*/
-        String redisKeyPattern = "bm-secret-key:*";
-        if (Objects.requireNonNull(redisTemplate.keys(redisKeyPattern)).size() >= 10) {
-            throw new ServiceException("请求频率超过限制,请2分钟后重试");
-        }
-
+        Map<String, Object> resultMap = new HashMap<>();
         if (StringUtils.isEmpty(appKey)) {
-            throw new ServiceException("appKey不能为空");
-        }
-        if (!isValidAppKey(appKey)) {
-            throw new ServiceException("appKey验证失败");
+            resultMap.put("uuid", null);
+            resultMap.put("pk", null);
+            resultMap.put("code", 500);
+            resultMap.put("msg", "param cannot be null");
+            return resultMap;
         }
 
-        /*创建秘钥对*/
-        Map<String, String> keyPair = RsaUtils.createKeyPair();
-        String pk = keyPair.get("pk");
-        String sk = keyPair.get("sk");
-        Long uuid = SnowFlakeUtil.getId();
+        /*Redis加锁,10秒过期*/
+        String lockRedisKey = "bm-secret-key-request-limit:" + appKey;
+        Long currentTime = System.currentTimeMillis();
+        Boolean isAbsent = redisTemplate.opsForValue().setIfAbsent(lockRedisKey, String.valueOf(currentTime), Duration.ofSeconds(10));
 
-        Map<String, Object> resultMap = new HashMap<>();
-        try {
-            //存储到Redis,并设置过期时间为2分钟
-            String redisKey = "bm-secret-key:" + uuid;
-            redisTemplate.opsForValue().set(redisKey + ":pk", pk, 2, TimeUnit.MINUTES);
-            redisTemplate.opsForValue().set(redisKey + ":sk", sk, 2, TimeUnit.MINUTES);
-
-            resultMap.put("uuid", uuid);
-            resultMap.put("pk", pk);
-            resultMap.put("code", 200);
-            resultMap.put("msg", "操作成功");
-            return resultMap;
-        } catch (Exception e) {
+        if (isAbsent != null && isAbsent) {
+            if (!isValidAppKey(appKey)) {
+                resultMap.put("uuid", null);
+                resultMap.put("pk", null);
+                resultMap.put("code", 500);
+                resultMap.put("msg", "appKey authentication failed");
+                return resultMap;
+            }
+
+            /*创建秘钥对*/
+            Map<String, String> keyPair = RsaUtils.createKeyPair();
+            String pk = keyPair.get("pk");
+            String sk = keyPair.get("sk");
+            Long uuid = SnowFlakeUtil.getId();
+
+            try {
+                /*存储到Redis,2分钟过期*/
+                String redisKey = "bm-secret-key:" + uuid;
+                redisTemplate.opsForValue().set(redisKey + ":pk", pk, 2, TimeUnit.MINUTES);
+                redisTemplate.opsForValue().set(redisKey + ":sk", sk, 2, TimeUnit.MINUTES);
+
+                resultMap.put("uuid", uuid);
+                resultMap.put("pk", pk);
+                resultMap.put("code", 200);
+                resultMap.put("msg", "操作成功");
+                return resultMap;
+            } catch (Exception e) {
+                resultMap.put("uuid", null);
+                resultMap.put("pk", null);
+                resultMap.put("code", 500);
+                resultMap.put("msg", e.getMessage());
+                return resultMap;
+            }
+        } else {
             resultMap.put("uuid", null);
             resultMap.put("pk", null);
-            resultMap.put("code", 400);
-            resultMap.put("msg", e.getMessage());
+            resultMap.put("code", 500);
+            resultMap.put("msg", "try again in 10 seconds");
             return resultMap;
         }
     }
 
     private boolean isValidAppKey(String appKey) {
         List<AuthClient> bladeClients = jdbcTemplate.query(
-                "SELECT (1) FROM blade_client WHERE client_id = ?",
+                "SELECT (1) FROM blade_client WHERE id = ? AND status = 1 AND is_deleted = 0",
                 new Object[]{appKey},
                 new BeanPropertyRowMapper<>(AuthClient.class)
         );
@@ -102,7 +146,9 @@ public class ThirdPartySystemApi {
     }
 
     /**
-     * 获取token
+     * 根据idcard获取本系统的token信息
+     *
+     * @param dto
      */
     @PostMapping("/auth/token")
     public R<Object> getToken(@RequestBody GetTokenDTO dto) {
@@ -188,6 +234,7 @@ public class ThirdPartySystemApi {
         return R.data(451, null, "未获取到对应的私钥信息");
     }
 
+
     /*public static void main(String[] args) {
         //公钥
         String pk = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJnZ0kMi0AG9sR97sdRD0/kqX9a7kSsVM56DUwmEbxf9n5SW0aRwxYcoyZQUC7ZW2MrXSNbzwbtmdD0RfQ4TJI0CAwEAAQ==";
@@ -201,5 +248,231 @@ public class ThirdPartySystemApi {
         System.out.println("Encrypted Id Card: " + encryptedIdCard);
     }*/
 
+
+    /**
+     * 获取白马系统token
+     *
+     * @return
+     */
+    public static R<Object> getBMToken() {
+        /*获取uuid与公钥*/
+        Map<String, String> param = new HashMap<>();
+        param.put("appKey", APP_KEY);
+        String pkAndUuid = HttpClientUtil.doGet(PK_URL, param);
+        JSONObject jsonObject = JSON.parseObject(pkAndUuid);
+        String pk = jsonObject.getString("pk");
+        String uuid = jsonObject.getString("uuid");
+        String code = jsonObject.getString("code");
+        /*获取token*/
+        if (StringUtils.isNotEmpty(pk) && StringUtils.isNotEmpty(uuid) && ("200").equals(code)) {
+            String username = RsaUtilToken.encryptWithPk(USERNAME, pk);
+            String password = RsaUtilToken.encryptWithPk(PASSWORD, pk);
+            //移除换行符
+            String usernameRe = username.replaceAll("\\r|\\n", "");
+            String passwordRe = password.replaceAll("\\r|\\n", "");
+
+            String result = HttpClientUtil.doPostJson(TOKEN_URL, JSON.toJSONString(new GetBMTokenDTO(uuid, usernameRe, passwordRe, SOURCE)));
+            return R.data(result);
+        } else {
+            return R.data(jsonObject);
+        }
+    }
+
+
+    /*public static void main(String[] args) {
+     *//*Object data = getBMToken().getData();
+        System.out.println(data);*//*
+
+        syncBMUserInfosToSystemProject();
+    }*/
+
+
+    /**
+     * 同步白马用户信息到系统项目中
+     */
+    /*@Scheduled(cron = "0 0 4 * * ?")*/
+    @PostMapping("/auth/test666")
+    public void syncBMUserInfosToSystemProject() {
+        /*获取token*/
+        Object dataR = getBMToken().getData();
+        JSONObject jsonObject = JSON.parseObject(String.valueOf(dataR));
+        String code = jsonObject.getString("code");
+        String dataToken = jsonObject.getString("data");
+        JSONObject jsonObjectToken = JSON.parseObject(dataToken);
+        String token = jsonObjectToken.getString("access_token");
+
+        if (("200").equals(code) && StringUtils.isNotEmpty(token)) {
+            /*获取白马公司ids*/
+            //String bmCompanyIds = CommonConstant.BM_COMPANY_IDS;
+
+            /*测试公司id*/
+            String bmCompanyIds = "1722072427562467328";
+
+            String[] bmCompanyIdsArr = bmCompanyIds.split(",");
+            for (String companyId : bmCompanyIdsArr) {
+                /*获取用户信息*/
+                Map<String, String> param = new HashMap<>();
+                param.put("pid", companyId);
+                String responseData = HttpClientUtil.doGet(USER_LIST_URL, param, token);
+
+                /*解析响应数据*/
+                JSONObject jsonObjectResponse = JSONObject.parseObject(responseData);
+                String responseStringCode = jsonObjectResponse.getString("code");
+                if (("200").equals(responseStringCode)) {
+                    JSONArray userList = jsonObjectResponse.getJSONArray("data");
+                    if (userList != null && userList.size() >= 1) {
+                        for (int i = 0; i < userList.size(); i++) {
+                            JSONObject jsonUser = userList.getJSONObject(i);
+                            String userid = jsonUser.getString("userid");
+                            //String username = jsonUser.getString("username");
+                            String nickname = jsonUser.getString("nickname");
+                            String idCard = jsonUser.getString("idcard");
+                            String phone = jsonUser.getString("phonenumber");
+                            String status = jsonUser.getString("status");
+
+                            JSONArray companies = jsonUser.getJSONArray("companies");
+                            if (companies != null && companies.size() >= 1) {
+                                for (int j = 0; j < companies.size(); j++) {
+                                    JSONObject companiesJSONObject = companies.getJSONObject(j);
+                                    //String companiesId = companiesJSONObject.getString("id");
+                                    String companyName = companiesJSONObject.getString("name");
+
+                                    if (companyName.contains("重庆白马航运发展有限公司")
+                                            || companyName.contains("四川二滩国际工程咨询有限责任公司")
+                                            || companyName.contains("中国水利水电第四工程局中电建路桥集团联合体")
+                                            || companyName.contains("中国水利水电第八工程局有限公司")
+                                            || companyName.contains("重庆市交通工程监理咨询有限责任公司")
+                                            || companyName.contains("中铁长江交通设计集团有限公司")
+                                            || companyName.contains("中铁八局集团有限公司")) {
+                                        List<User> sysUser = userService.getBaseMapper().selectList(Wrappers.<User>lambdaQuery().eq(User::getSysType, 2).apply("(sys_id = '" + userid + "' OR id_number = '" + idCard + "')"));
+
+                                        /*修改电话号码*/
+                                        if (sysUser.size() > 0 && ObjectUtil.isNotEmpty(phone) && phone.length() == 11) {
+                                            for (User user : sysUser) {
+                                                if (ObjectUtil.isEmpty(user.getPhone())) {
+                                                    userService.lambdaUpdate()
+                                                            .set(User::getPhone, phone)
+                                                            .eq(User::getId, user.getId())
+                                                            .update();
+                                                }
+                                            }
+                                        }
+
+                                        /*只有本系统不存在时才去新增*/
+                                        if (sysUser.size() == 0L) {
+                                            User newUser = new User();
+                                            newUser.setId(SnowFlakeUtil.getId());
+                                            newUser.setDeptId("1588069957940674562"); //白马部门
+
+                                            newUser.setSysType(9); //之前=2是表示同步,现在由于修改了接口,改为9,以便处理数据
+
+                                            newUser.setIsDeleted(0);
+                                            newUser.setCreateUser(Long.parseLong("1541381503819694081"));
+                                            newUser.setUpdateUser(Long.parseLong("1541381503819694081"));
+                                            newUser.setTenantId("000000");
+                                            newUser.setSysId(userid);
+                                            newUser.setUpdateTime(new Date());
+                                            newUser.setCreateTime(new Date());
+                                            newUser.setUserType("1,2");
+                                            newUser.setAccount(idCard);
+                                            newUser.setRealName(nickname);
+                                            newUser.setName(nickname);
+                                            newUser.setPassword("10470c3b4b1fed12c3baac014be15fac67c6e815");
+                                            newUser.setPlaintextPassword("123456");
+                                            newUser.setName(nickname);
+                                            newUser.setStatus(Integer.parseInt(status));
+                                            newUser.setIdNumber(idCard);
+                                            newUser.setCompanyName(companyName);
+                                            newUser.setPhone(ObjectUtil.isNotEmpty(phone) && phone.length() == 11 ? phone : null);
+
+                                            /*所有合同段(白马)*/
+                                            if (companyName.contains("重庆白马航运发展有限公司")) {
+                                                List<ContractInfo> contractInfos = jdbcTemplate.query("select id from m_contract_info where p_id = 1612329251049537537 and is_deleted = 0 and status = 1", new BeanPropertyRowMapper<>(ContractInfo.class));
+                                                for (ContractInfo contractInfo : contractInfos) {
+                                                    Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and project_id = 1612329251049537537 " + " and contract_id = " + contractInfo.getId() + " and post_id is null " + " and status = 1 and is_deleted = 0", Long.class);
+                                                    if (count == null || count == 0L) {
+                                                        /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;所有合同段id:contractInfo.getId();角色施工-资料员id:1537249581371707394*/
+                                                        saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, contractInfo.getId(), 1537249581371707394L);
+                                                        newUser.setRoleId("1537249581371707394");
+                                                    }
+                                                }
+                                            }
+
+                                            /*二期合同段(八局、二滩、长江设计单位、中国水利水电第八工程局有限公司)*/
+                                            if (companyName.contains("中铁八局集团有限公司") || companyName.contains("四川二滩国际工程咨询有限责任公司")
+                                                    || companyName.contains("中铁长江交通设计集团有限公司") || companyName.contains("中国水利水电第八工程局有限公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1612335077269143554 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;第二期合同段id:1612335077269143554;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1612335077269143554L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*一期合同段(四局、长江设计单位)*/
+                                            if (companyName.contains("中国水利水电第四工程局中电建路桥集团联合体") || companyName.contains("中铁长江交通设计集团有限公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1613022750656921601 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;第一期合同段id:1613022750656921601;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1613022750656921601L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*二监办合同段(二滩)*/
+                                            if (companyName.contains("四川二滩国际工程咨询有限责任公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1687370619295309826 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;二监办合同段id:1687370619295309826;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1687370619295309826L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*一监办合同段(重庆市交通工程监理咨询有限责任公司)*/
+                                            if (companyName.contains("重庆市交通工程监理咨询有限责任公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1687370014959017986 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;一监办合同段id:1687370014959017986;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1687370014959017986L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*入库*/
+                                            userService.save(newUser);
+                                            userService.submitUserDept(newUser);
+
+                                        }
+                                    }
+                                }
+                            }
+
+                            /*JSONArray projects = jsonUser.getJSONArray("projects");
+                            if (projects != null && projects.size() >= 1) {
+                                for (int k = 0; k < projects.size(); k++) {
+                                    JSONObject projectsJSONObject = projects.getJSONObject(k);
+                                    String projectId = projectsJSONObject.getString("projectid");
+                                    String projectName = projectsJSONObject.getString("projectname");
+                                    String subprojectId = projectsJSONObject.getString("subprojectid");
+                                    String subprojectName = projectsJSONObject.getString("subprojectname");
+                                    String contractId = projectsJSONObject.getString("contractid");
+                                    String contractName = projectsJSONObject.getString("contractname");
+                                    String sectionId = projectsJSONObject.getString("sectionid");
+                                    String sectionName = projectsJSONObject.getString("sectionname");
+
+                                    //TODO
+
+                                }
+                            }*/
+
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
 }
 

+ 184 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/util/HttpClientUtil.java

@@ -0,0 +1,184 @@
+package org.springblade.system.user.util;
+
+ 
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+
+public class HttpClientUtil {
+ 
+    public static String doGet(String url, Map<String, String> param) {
+ 
+        // 创建Httpclient对象
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+ 
+        String resultString = "";
+        CloseableHttpResponse response = null;
+        try {
+            // 创建uri
+            URIBuilder builder = new URIBuilder(url);
+            if (param != null) {
+                for (String key : param.keySet()) {
+                    builder.addParameter(key, param.get(key));
+                }
+            }
+            URI uri = builder.build();
+ 
+            // 创建http GET请求
+            HttpGet httpGet = new HttpGet(uri);
+ 
+            // 执行请求
+            response = httpclient.execute(httpGet);
+            // 判断返回状态是否为200
+            if (response.getStatusLine().getStatusCode() == 200) {
+                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return resultString;
+    }
+
+    public static String doGet(String url, Map<String, String> param, String token) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+        String resultString = "";
+        CloseableHttpResponse response = null;
+
+        try {
+            // 创建uri
+            URIBuilder builder = new URIBuilder(url);
+            if (param != null) {
+                for (String key : param.keySet()) {
+                    builder.addParameter(key, param.get(key));
+                }
+            }
+            URI uri = builder.build();
+
+            // 创建http GET请求
+            HttpGet httpGet = new HttpGet(uri);
+
+            // 设置认证信息到请求头
+            httpGet.setHeader("Authorization", "Bearer " + token);
+
+            // 执行请求
+            response = httpclient.execute(httpGet);
+
+            // 判断返回状态是否为200
+            if (response.getStatusLine().getStatusCode() == 200) {
+                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+
+    public static String doGet(String url) {
+        return doGet(url, null);
+    }
+ 
+    public static String doPost(String url, Map<String, String> param) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            // 创建参数列表
+            if (param != null) {
+                List<NameValuePair> paramList = new ArrayList<>();
+                for (String key : param.keySet()) {
+                    paramList.add(new BasicNameValuePair(key, param.get(key)));
+                }
+                // 模拟表单
+                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,"utf-8");
+                httpPost.setEntity(entity);
+            }
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                response.close();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+ 
+        return resultString;
+    }
+ 
+    public static String doPost(String url) {
+        return doPost(url, null);
+    }
+ 
+    public static String doPostJson(String url, String json) {
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+
+        try {
+            HttpPost httpPost = new HttpPost(url);
+
+            // 添加请求头参数时间戳
+            httpPost.setHeader("timestamp", String.valueOf(System.currentTimeMillis()));
+
+            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
+            httpPost.setEntity(entity);
+
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+}

+ 80 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/util/RsaUtilToken.java

@@ -0,0 +1,80 @@
+package org.springblade.system.user.util;
+
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+import javax.crypto.Cipher;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyFactory;
+import java.security.interfaces.RSAPublicKey;
+import java.security.spec.X509EncodedKeySpec;
+
+public final class RsaUtilToken {
+
+    /**
+     * RSA公钥加密
+     *
+     * @param data      加密字符串
+     * @param publicKey 公钥
+     * @return 密文
+     */
+    public static String encryptWithPk(String data, String publicKey) {
+        try {
+            //base64编码的公钥
+            byte[] decoded = decryptBASE64(publicKey);
+            RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
+            //RSA加密
+            Cipher cipher = Cipher.getInstance("RSA");
+            cipher.init(Cipher.ENCRYPT_MODE, pubKey);
+            return encryptBASE64(cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)));
+        } catch (Exception ex) {
+            throw new RuntimeException("数据加密处理失败(encrypt with pk)");
+        }
+    }
+
+    /**
+     * RSA公钥解密
+     *
+     * @param data      加密字符串
+     * @param publicKey 公钥
+     * @return 明文
+     */
+    public static String decryptWithPk(String data, String publicKey) {
+        try {
+            //64位解码加密后的字符串
+            byte[] inputByte = decryptBASE64(data);
+            //base64编码的私钥
+            byte[] decoded = decryptBASE64(publicKey);
+            RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
+            //RSA解密
+            Cipher cipher = Cipher.getInstance("RSA");
+            cipher.init(Cipher.DECRYPT_MODE, pubKey);
+            return new String(cipher.doFinal(inputByte));
+        } catch (Exception ex) {
+            throw new RuntimeException("数据解析处理失败(decrypt with pk)");
+        }
+    }
+
+    /**
+     * 编码返回字符串
+     */
+    private static String encryptBASE64(byte[] key) {
+        try {
+            return (new BASE64Encoder()).encodeBuffer(key);
+        } catch (Exception ex) {
+            throw new RuntimeException("编码返回字符串失败");
+        }
+    }
+
+    /**
+     * 解码返回byte
+     */
+    private static byte[] decryptBASE64(String key) {
+        try {
+            return (new BASE64Decoder()).decodeBuffer(key);
+        } catch (Exception ex) {
+            throw new RuntimeException("解码返回byte失败");
+        }
+    }
+
+}