Browse Source

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

zero 1 year ago
parent
commit
3bf7a13b3d

+ 13 - 1
src/main/java/cn/cslg/pas/common/utils/DateUtils2.java

@@ -272,7 +272,7 @@ public class DateUtils2 {
     }
 
 
-    public static List<String> getWeekRange(LocalDate localDate){
+    public static List<String> getWeekRange (LocalDate localDate){
         List<String> ranges =new ArrayList<>();
         LocalDate firstDayOfWeek = localDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
         LocalDate lastDayOfWeek = firstDayOfWeek.plusDays(6);
@@ -285,6 +285,18 @@ public class DateUtils2 {
         return ranges;
     }
 
+    public static List<String> getWDWeekRange(LocalDate localDate){
+        List<String> ranges =new ArrayList<>();
+        LocalDate firstDayOfWeek = localDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
+        LocalDate lastDayOfWeek = firstDayOfWeek.plusDays(6);
+        java.time.format.DateTimeFormatter formatter =java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd");
+        // 使用formatter将LocalDate转换为字符串
+        String formattedDate1 = firstDayOfWeek.format(formatter);
+        String formattedDate2 =lastDayOfWeek.format(formatter);
+        ranges.add(formattedDate1);
+        ranges.add(formattedDate2);
+        return ranges;
+    }
     public static List<String> getMonthRange(LocalDate localDate){
         List<String> ranges =new ArrayList<>();
         LocalDate firstDayOfMonth = localDate.with(TemporalAdjusters.firstDayOfMonth());

+ 4 - 0
src/main/java/cn/cslg/pas/common/vo/business/EventVO.java

@@ -44,6 +44,10 @@ public class EventVO {
             timezone = "GMT+8"
     )
     private Date eventDate;
+    @JsonFormat(
+            pattern = "yyyy-MM-dd",
+            timezone = "GMT+8"
+    )
     @Schema(description = "创建时间")
     private Date createTime;
     @Schema(description = "创建人")

+ 12 - 0
src/main/java/cn/cslg/pas/controller/InvalidStatutesController.java

@@ -201,4 +201,16 @@ public class InvalidStatutesController {
         }
         return Response.success("删除成功");
     }
+
+    @Operation(summary = "查询无效理由里的无效法条")
+    @PostMapping("/queryStatuesVOS")
+    public Response queryStatuesVOS(@RequestBody GetInvalidReasonClaimsDTO vo) {
+        List<Integer> list = new ArrayList<>();
+        try {
+            list = finalInvalidStatueService.queryStatuesVOS(vo);
+        } catch (Exception e) {
+            return Response.error(e.getMessage());
+        }
+        return Response.success(list);
+    }
 }

+ 4 - 2
src/main/java/cn/cslg/pas/factorys/EsCountAnalyseBuilderFactory/ChildCountAnalysisBuilder.java

@@ -1,9 +1,11 @@
 package cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory;
 
+import co.elastic.clients.elasticsearch._types.SortOrder;
 import co.elastic.clients.elasticsearch._types.aggregations.*;
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
 import co.elastic.clients.json.JsonData;
+import co.elastic.clients.util.NamedValue;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
@@ -56,7 +58,7 @@ public class ChildCountAnalysisBuilder implements IEsCountAnalysisBuilder {
                             .gte(JsonData.of(valueOne)).lte(JsonData.of(valueTwo)));
                     queryList.add(query);
                 }
-                Aggregation terms = AggregationBuilders.terms(i -> i.field("custom_field.stats_value.raw").size(topN));
+                Aggregation terms = AggregationBuilders.terms(i -> i.field("custom_field.stats_value.raw").order(NamedValue.of("_key",SortOrder.Desc)).size(topN));
                 termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList)))
                         .aggregations(new HashMap() {{
                             put("filterAgg", terms);
@@ -77,7 +79,7 @@ public class ChildCountAnalysisBuilder implements IEsCountAnalysisBuilder {
                             .gte(JsonData.of(valueOne)).lte(JsonData.of(valueTwo)));
                     queryList.add(query);
                 }
-                Aggregation terms = AggregationBuilders.terms(i -> i.field("custom_field.field_value.raw").size(topN));
+                Aggregation terms = AggregationBuilders.terms(i -> i.field("custom_field.field_value.raw").order(NamedValue.of("_key",SortOrder.Desc)).size(topN));
                 termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList)))
                         .aggregations(new HashMap() {{
                             put("filterAgg", terms);

+ 11 - 0
src/main/java/cn/cslg/pas/service/FinalInvalidStatueService.java

@@ -465,6 +465,17 @@ public class FinalInvalidStatueService extends ServiceImpl<FinalInvalidStatueMap
         editProofSort(proofGroup.getFinalInvalidStatueId(), proofGroup.getFeatureSort(), 2);
         proofGroupMapper.deleteById(proofGroup.getId());
     }
+
+    /**
+     * 查询无效理由里的无效发条
+     * @param vo
+     * @return
+     */
+    public List<Integer> queryStatuesVOS(GetInvalidReasonClaimsDTO vo) {
+        List<FinalInvalidStatue> list = invalidStatueMapper.selectList(new LambdaQueryWrapper<FinalInvalidStatue>()
+                .eq(FinalInvalidStatue::getProjectId, vo.getProjectId()));
+        return list.stream().map(FinalInvalidStatue::getStatuteId).distinct().collect(Collectors.toList());
+    }
 }
 
 

+ 1 - 0
src/main/java/cn/cslg/pas/service/business/CustomOptionService.java

@@ -165,6 +165,7 @@ public class CustomOptionService extends ServiceImpl<CustomOptionMapper, CustomO
                 List<String> createIds = new ArrayList<>();
                 LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
                 queryWrapper.eq(CustomOption::getCustomFieldId, customFieldId);
+                queryWrapper.orderByDesc(CustomOption::getCreateTime);
                 List<CustomOption> customOptions = this.list(queryWrapper);
                 customOptions.forEach(
                         item -> {

+ 0 - 2
src/main/java/cn/cslg/pas/service/business/EventService.java

@@ -465,12 +465,10 @@ public class EventService extends ServiceImpl<EventMapper, Event> implements Bus
         Integer scenarioId = null;
         if (object instanceof EventDTO) {
             EventDTO eventDTO = (EventDTO) object;
-            eventDTO.getScenarioId();
             name = eventDTO.getName();
             scenarioId = eventDTO.getScenarioId();
         } else if (object instanceof UpdateEventDTO) {
             UpdateEventDTO eventDTO = (UpdateEventDTO) object;
-            eventDTO.getScenarioId();
             name = eventDTO.getName();
             scenarioId = eventDTO.getScenarioId();
             id = eventDTO.getId();

+ 36 - 10
src/main/java/cn/cslg/pas/service/business/ImportTaskService.java

@@ -88,6 +88,7 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
     private MailSendService mailSendService;
     @Autowired
     private PatentProjectService patentProjectService;
+
     @Override
     public Object queryMessage(QueryRequest queryRequest) throws Exception {
         List<String> sqls = formatQueryService.reSqls(queryRequest, "importTask");
@@ -556,10 +557,10 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
         return importTask.getId();
     }
 
-    public void addImportTaskByCondition(ImportTaskCondition importTaskCondition,PatentProject project) {
+    public void addImportTaskByCondition(ImportTaskCondition importTaskCondition, PatentProject project) {
         String condition = importTaskCondition.getSearchCondition();
         String updateCycle = project.getUpdateCycle();
-
+        String dbType = importTaskCondition.getDbType();
         if (updateCycle == null) {
             return;
         }
@@ -567,19 +568,40 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
         List<String> dateRange = new ArrayList<>();
         switch (updateCycle) {
             case Cycle.WEEK:
-                LocalDate localDateWeek = localDate.minusWeeks(2);
+                LocalDate localDateWeek = null;
+                if (dbType != null && dbType.equals("CN")) {
+                    localDateWeek = localDate.minusMonths(1).minusWeeks(1);
+                } else {
+                    localDateWeek = localDate.minusWeeks(1);
+
+                }
                 dateRange = DateUtils2.getWeekRange(localDateWeek);
                 break;
             case Cycle.MONTH:
-                LocalDate localDateMonth = localDate.minusMonths(1);
+                LocalDate localDateMonth = null;
+                if (dbType != null && dbType.equals("CN")) {
+                    localDateMonth = localDate.minusMonths(1);
+                } else {
+                    localDateMonth = localDate.minusMonths(2);
+                }
                 dateRange = DateUtils2.getMonthRange(localDateMonth);
                 break;
             case Cycle.QUARTER:
-                LocalDate localDateQuartz = localDate.minusMonths(4);
+                LocalDate localDateQuartz = null;
+                if (dbType != null && dbType.equals("CN")) {
+                    localDateQuartz = localDate.minusMonths(4);
+                } else {
+                    localDateQuartz = localDate.minusMonths(5);
+                }
                 dateRange = DateUtils2.getQuartzRange(localDateQuartz);
                 break;
             case Cycle.YEAR:
-                LocalDate localYear = localDate.minusYears(1);
+                LocalDate localYear = null;
+                if (dbType != null && dbType.equals("CN")) {
+                    localYear = localDate.minusMonths(1).minusYears(1);
+                } else {
+                    localYear= localDate.minusYears(1);
+                }
                 dateRange = DateUtils2.getYearRange(localYear);
                 break;
         }
@@ -599,11 +621,15 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
         ImportTask importTask = new ImportTask();
 
 
-            String fromDateStr = DateUtils2.dateTimeToPatentStr(start);
-            String todateStr = DateUtils2.dateTimeToPatentStr(end);
-            importTask.setLastUpdateToDate(start);
-            importTask.setUpdateToDate(end);
+        String fromDateStr = DateUtils2.dateTimeToPatentStr(start);
+        String todateStr = DateUtils2.dateTimeToPatentStr(end);
+        importTask.setLastUpdateToDate(start);
+        importTask.setUpdateToDate(end);
+        if (dbType != null && dbType.equals("CN")) {
             condition = condition + " and (PD=" + fromDateStr + "~" + todateStr + " or GD=" + fromDateStr + "~" + todateStr + ")";
+        } else {
+            condition = condition + " and (PD=" + fromDateStr + "~" + todateStr + " or GD=" + fromDateStr + "~" + todateStr + ")";
+        }
 
         PatentStarListDTO patentStarListDto = new PatentStarListDTO()
                 .setCurrentQuery(condition)

+ 4 - 4
src/main/java/cn/cslg/pas/service/importPatent/WebVOTransformService.java

@@ -464,7 +464,7 @@ public class WebVOTransformService {
      * @param cpcs
      */
     public void loadPatentCPC(Patent patent, String cpcs) {
-        //装载IPC分类号
+        //装载cpc分类号
         if (cpcs != null && !cpcs.equals("")) {
             List<PatentClassify> patentClassifies = new ArrayList<>();
             List<String> cpcArr = Arrays.asList(cpcs.split(";"));
@@ -472,7 +472,7 @@ public class WebVOTransformService {
                 PatentClassify patentClassify = PatentClassifySplitter.split(cpcArr.get(i));
                 patentClassifies.add(patentClassify);
             }
-            patent.setIpc(patentClassifies);
+            patent.setCpc(patentClassifies);
         }
     }
 
@@ -480,13 +480,13 @@ public class WebVOTransformService {
         if (cpcArr == null) {
             return;
         }
-        //装载IPC分类号
+        //装载cpc分类号
         List<PatentClassify> patentClassifies = new ArrayList<>();
         for (int i = 0; i < cpcArr.size(); i++) {
             PatentClassify patentClassify = PatentClassifySplitter.split(cpcArr.get(i));
             patentClassifies.add(patentClassify);
         }
-        patent.setIpc(patentClassifies);
+        patent.setCpc(patentClassifies);
 
     }
 

+ 31 - 23
src/main/java/cn/cslg/pas/service/quartzService/SysImportPatentJobService.java

@@ -35,29 +35,15 @@ public class SysImportPatentJobService extends QuartzJobBean {
     @Override
     public void executeInternal(JobExecutionContext context) throws JobExecutionException {
         mailSendService.sendSysCycleStartEmail();
-        CheckDateConditionVO checkDateConditionVO = DateUtils2.checkDateCycleCondition(null);
-        Boolean ifMeetMonth = checkDateConditionVO.getIfMeetMonth();
-        Boolean ifMeetQuarter = checkDateConditionVO.getIfMeetQuarter();
-        Boolean ifMeetYear = checkDateConditionVO.getIfMeetYear();
-        List<String> cycles = new ArrayList<>();
-            cycles.add(Cycle.WEEK);
+        this.addChinesePatent();
 
-        if (ifMeetMonth != null && ifMeetMonth) {
-            cycles.add(Cycle.MONTH);
-        }
-        if (ifMeetQuarter != null && ifMeetQuarter) {
-            cycles.add(Cycle.QUARTER);
-        }
-        if (ifMeetYear != null && ifMeetYear) {
-            cycles.add(Cycle.YEAR);
-        }
+    }
 
-        if (cycles.size() <= 0) {
-            return;
-        }
+
+    public void addChinesePatent() {
+         List<String> cycles =this.getCnCycles();
         LambdaQueryWrapper<PatentProject> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(PatentProject::getIfUpdate, true)
-                .in(PatentProject::getUpdateCycle, cycles);
+        queryWrapper.eq(PatentProject::getIfUpdate, true);
         List<PatentProject> patentProjects = patentProjectService.list(queryWrapper);
         if (patentProjects != null && patentProjects.size() != 0) {
             List<Integer> projectId = patentProjects.stream().map(PatentProject::getProjectId).collect(Collectors.toList());
@@ -69,15 +55,37 @@ public class SysImportPatentJobService extends QuartzJobBean {
             List<ImportTaskCondition> importTaskConditions = importTaskConditionService.list(queryWrapper1);
 
             importTaskConditions.forEach(item -> {
-            PatentProject project=    patentProjects.stream().filter(t->t.getProjectId().equals(item.getProjectId())).findFirst().orElse(null);
-                importTaskService.addImportTaskByCondition(item,project);
+
+                PatentProject project = patentProjects.stream().filter(t -> t.getProjectId().equals(item.getProjectId())).findFirst().orElse(null);
+                if(item.getDbType()==null||!item.getDbType().equals("CN")||(item.getDbType().equals("CN")&&cycles.contains(project.getUpdateCycle())))
+                {                importTaskService.addImportTaskByCondition(item, project);
+                }
             });
         }
 
-
     }
 
 
+    public List<String> getCnCycles() {
+        CheckDateConditionVO checkDateConditionVO = DateUtils2.checkDateCycleCondition(null);
+        Boolean ifMeetMonth = checkDateConditionVO.getIfMeetMonth();
+        Boolean ifMeetQuarter = checkDateConditionVO.getIfMeetQuarter();
+        Boolean ifMeetYear = checkDateConditionVO.getIfMeetYear();
+        List<String> cycles = new ArrayList<>();
+        cycles.add(Cycle.WEEK);
+
+        if (ifMeetMonth != null && ifMeetMonth) {
+            cycles.add(Cycle.MONTH);
+        }
+        if (ifMeetQuarter != null && ifMeetQuarter) {
+            cycles.add(Cycle.QUARTER);
+        }
+        if (ifMeetYear != null && ifMeetYear) {
+            cycles.add(Cycle.YEAR);
+        }
+        return cycles;
+
+    }
 }
 
 

+ 39 - 0
src/main/java/cn/cslg/pas/service/test/AESUtils.java

@@ -0,0 +1,39 @@
+package cn.cslg.pas.service.test;
+
+import org.springframework.stereotype.Component;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.SecureRandom;
+import java.util.Base64;
+
+@Component
+public class AESUtils {
+
+    private static final String ALGORITHM = "AES";
+    private static final int KEY_SIZE = 128;
+
+    public static String generateKey() throws Exception {
+        KeyGenerator keyGenerator = KeyGenerator.getInstance(ALGORITHM);
+        keyGenerator.init(KEY_SIZE, new SecureRandom());
+        SecretKey secretKey = keyGenerator.generateKey();
+        return Base64.getEncoder().encodeToString(secretKey.getEncoded());
+    }
+
+    public static String encrypt(String data, String key) throws Exception {
+        Cipher cipher = Cipher.getInstance(ALGORITHM);
+        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(Base64.getDecoder().decode(key), ALGORITHM));
+        byte[] encryptedData = cipher.doFinal(data.getBytes());
+        return Base64.getEncoder().encodeToString(encryptedData);
+    }
+
+    public static String decrypt(String encryptedData, String key) throws Exception {
+        Cipher cipher = Cipher.getInstance(ALGORITHM);
+        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.getDecoder().decode(key), ALGORITHM));
+        byte[] decryptedData = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
+        return new String(decryptedData);
+    }
+
+}

+ 26 - 0
src/main/java/cn/cslg/pas/service/test/EncryptionFunctionDTO.java

@@ -0,0 +1,26 @@
+package cn.cslg.pas.service.test;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class EncryptionFunctionDTO {
+
+    /**
+     * 请求的secret
+     */
+    private String sign;
+
+    /**
+     * 应用key
+     */
+    private String appKey;
+
+    /**
+     * 发起请求时的时间戳
+     */
+    private Long currentTimeMillis;
+
+    private List<String> permissions;
+}

+ 13 - 0
src/main/java/cn/cslg/pas/service/test/EncryptionFunctionFinalVO.java

@@ -0,0 +1,13 @@
+package cn.cslg.pas.service.test;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class EncryptionFunctionFinalVO {
+
+    private String key;
+
+    private List<EncryptionFunctionVO> functionVOS;
+}

+ 14 - 0
src/main/java/cn/cslg/pas/service/test/EncryptionFunctionVO.java

@@ -0,0 +1,14 @@
+package cn.cslg.pas.service.test;
+
+import lombok.Data;
+
+@Data
+public class EncryptionFunctionVO {
+
+    //权限
+    private String permission;
+
+    //加密后的权限对应的模块化代码
+    private String encryptionModuleCode;
+
+}

+ 39 - 0
src/main/java/cn/cslg/pas/service/test/EncryptionLoginDTO.java

@@ -0,0 +1,39 @@
+package cn.cslg.pas.service.test;
+
+import lombok.Data;
+
+@Data
+public class EncryptionLoginDTO {
+
+    /**
+     * 用户名
+     */
+    private String username;
+
+    /**
+     * 密码
+     */
+    private String password;
+
+    /**
+     * 机器码
+     */
+    private String machineCode;
+
+    /**
+     * 请求的secret
+     */
+    private String sign;
+
+    /**
+     * 应用key
+     */
+    private String appKey;
+
+    /**
+     * 发起请求时的时间戳
+     */
+    private Long currentTimeMillis;
+
+
+}

+ 94 - 0
src/main/java/cn/cslg/pas/service/test/PermissionService2.java

@@ -0,0 +1,94 @@
+package cn.cslg.pas.service.test;
+
+import cn.cslg.pas.common.utils.LoginUtils;
+import cn.hutool.crypto.SecureUtil;
+import com.google.gson.Gson;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+@Service
+public class PermissionService2 {
+    @Value("${authorUrl}")
+    private String PCSUrl;
+
+    public String LogFromPCS(EncryptionLoginDTO encryptionLoginDTO) throws IOException {
+        String param = new Gson().toJson(encryptionLoginDTO);
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        OkHttpClient okHttpClient = new OkHttpClient();
+        Request request = new Request.Builder()
+                .url("http://47.116.194.135:8085" + "/api/permission/api/admin/loginByEncryption")
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    public String getPermission(String token) throws IOException {
+        String appKey = "4e95e3d926a2a4befa5d913acc0aa9f5";
+        EncryptionFunctionDTO encryptionFunctionDTO =new EncryptionFunctionDTO();
+        long currentTimeMillis = System.currentTimeMillis();
+        encryptionFunctionDTO.setCurrentTimeMillis(currentTimeMillis);
+        encryptionFunctionDTO.setAppKey(appKey);
+        String appSecret = appKey + currentTimeMillis / 1000;
+        String md5Sign = SecureUtil.md5(appSecret);
+        encryptionFunctionDTO.setSign(md5Sign);
+        String param = new Gson().toJson(encryptionFunctionDTO);
+
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        OkHttpClient okHttpClient = new OkHttpClient();
+        Request request = new Request.Builder()
+                .url("http://47.116.194.135:8085" + "/api/permission/api/admin/functionByEncryption")
+                .addHeader("Cookie", "token="+token)
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    public String LogFromPCS1(EncryptionLoginDTO encryptionLoginDTO) throws IOException {
+        String param = new Gson().toJson(encryptionLoginDTO);
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(60, TimeUnit.SECONDS)
+                .readTimeout(60, TimeUnit.SECONDS)
+                .build();
+        Request request = new Request.Builder()
+                .url(PCSUrl + "/permission/api/admin/loginByEncryption")
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    public String getPermission1(String token) throws IOException {
+        String appKey = "4e95e3d926a2a4befa5d913acc0aa9f5";
+        EncryptionFunctionDTO encryptionFunctionDTO =new EncryptionFunctionDTO();
+        long currentTimeMillis = System.currentTimeMillis();
+        encryptionFunctionDTO.setCurrentTimeMillis(currentTimeMillis);
+        encryptionFunctionDTO.setAppKey(appKey);
+        String appSecret = appKey + currentTimeMillis / 1000;
+        String md5Sign = SecureUtil.md5(appSecret);
+        encryptionFunctionDTO.setSign(md5Sign);
+        String param = new Gson().toJson(encryptionFunctionDTO);
+
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(60, TimeUnit.SECONDS)
+                .readTimeout(60, TimeUnit.SECONDS)
+                .build();
+        Request request = new Request.Builder()
+                .url(PCSUrl + "/permission/api/admin/functionByEncryption")
+                .addHeader("Cookie", "token="+token)
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+}

+ 263 - 0
src/main/java/cn/cslg/pas/service/test/RSAUtils.java

@@ -0,0 +1,263 @@
+package cn.cslg.pas.service.test;
+
+import org.springframework.stereotype.Component;
+
+import javax.crypto.Cipher;
+import java.io.ByteArrayOutputStream;
+import java.security.*;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class RSAUtils {
+
+    //签名算法名称
+    private static final String RSA_KEY_ALGORITHM = "RSA";
+
+    //标准签名算法名称
+    private static final String RSA_SIGNATURE_ALGORITHM = "SHA1withRSA";
+    private static final String RSA2_SIGNATURE_ALGORITHM = "SHA256withRSA";
+
+    //RSA密钥长度,默认密钥长度是1024,密钥长度必须是64的倍数,在512到65536位之间,不管是RSA还是RSA2长度推荐使用2048
+    private static final int KEY_SIZE = 2048;
+    //RSA最大加密明文大小
+    private static final int MAX_ENCRYPT_BLOCK = 245;
+    //RSA最大解密密文大小
+    private static final int MAX_DECRYPT_BLOCK = 256;
+
+    /**
+     * 生成密钥对
+     *
+     * @return 返回包含公私钥的map
+     */
+    public static Map<String, String> generateKey() {
+        KeyPairGenerator keygen;
+        try {
+            keygen = KeyPairGenerator.getInstance(RSA_KEY_ALGORITHM);
+        } catch (Exception e) {
+            throw new RuntimeException("RSA初始化密钥出现错误,算法异常");
+        }
+        SecureRandom secrand = new SecureRandom();
+        //初始化随机产生器
+        secrand.setSeed("China".getBytes());
+        //初始化密钥生成器
+        keygen.initialize(KEY_SIZE, secrand);
+        KeyPair keyPair = keygen.genKeyPair();
+        //获取公钥并转成base64编码
+        byte[] publicKey = keyPair.getPublic().getEncoded();
+        String publicKeyStr = Base64.getEncoder().encodeToString(publicKey);
+        //获取私钥并转成base64编码
+        byte[] privateKey = keyPair.getPrivate().getEncoded();
+        String privateKeyStr = Base64.getEncoder().encodeToString(privateKey);
+        //创建一个Map返回结果
+        Map<String, String> keyPairMap = new HashMap<>();
+        keyPairMap.put("publicKeyStr", publicKeyStr);
+        keyPairMap.put("privateKeyStr", privateKeyStr);
+        return keyPairMap;
+    }
+
+    /**
+     * 公钥加密(用于数据加密)
+     *
+     * @param data         加密前的字符串
+     * @param publicKeyStr base64编码后的公钥
+     * @return base64编码后的字符串
+     * @throws Exception
+     */
+    public static String encryptByPublicKey(String data, String publicKeyStr) throws Exception {
+        //Java原生base64解码
+        byte[] pubKey = Base64.getDecoder().decode(publicKeyStr);
+        //创建X509编码密钥规范
+        X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKey);
+        //返回转换指定算法的KeyFactory对象
+        KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
+        //根据X509编码密钥规范产生公钥对象
+        PublicKey publicKey = keyFactory.generatePublic(x509KeySpec);
+        //根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
+        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
+        //用公钥初始化此Cipher对象(加密模式)
+        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
+        //对数据加密
+        int inputLen = data.getBytes().length;
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int offset = 0;
+        byte[] cache;
+        int i = 0;
+        // 对数据分段加密
+        while (inputLen - offset > 0) {
+            if (inputLen - offset > MAX_ENCRYPT_BLOCK) {
+                cache = cipher.doFinal(data.getBytes(), offset, MAX_ENCRYPT_BLOCK);
+            } else {
+                cache = cipher.doFinal(data.getBytes(), offset, inputLen - offset);
+            }
+            out.write(cache, 0, cache.length);
+            i++;
+            offset = i * MAX_ENCRYPT_BLOCK;
+        }
+        byte[] encryptedData = out.toByteArray();
+        out.close();
+        //返回base64编码后的字符串
+        return Base64.getEncoder().encodeToString(encryptedData);
+    }
+
+    /**
+     * 私钥解密(用于数据解密)
+     *
+     * @param data          解密前的字符串
+     * @param privateKeyStr 私钥
+     * @return 解密后的字符串
+     * @throws Exception
+     */
+    public static String decryptByPrivateKey(String data, String privateKeyStr) throws Exception {
+        //Java原生base64解码
+        byte[] priKey = Base64.getDecoder().decode(privateKeyStr);
+        //创建PKCS8编码密钥规范
+        PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(priKey);
+        //返回转换指定算法的KeyFactory对象
+        KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
+        //根据PKCS8编码密钥规范产生私钥对象
+        PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
+        //根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
+        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
+        //用私钥初始化此Cipher对象(解密模式)
+        cipher.init(Cipher.DECRYPT_MODE, privateKey);
+        byte[] decodeBytes = Base64.getDecoder().decode(data);
+        //对数据分段解密
+        int inputLen = decodeBytes.length;
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int offset = 0;
+        byte[] cache;
+        int i = 0;
+        // 对数据分段解密
+        while (inputLen - offset > 0) {
+            if (inputLen - offset > MAX_DECRYPT_BLOCK) {
+                cache = cipher.doFinal(decodeBytes, offset, MAX_DECRYPT_BLOCK);
+            } else {
+                cache = cipher.doFinal(decodeBytes, offset, inputLen - offset);
+            }
+            out.write(cache, 0, cache.length);
+            i++;
+            offset = i * MAX_DECRYPT_BLOCK;
+        }
+        byte[] decryptedData = out.toByteArray();
+        out.close();
+        //返回字符串
+        return new String(decryptedData, "UTF-8");
+    }
+
+    /**
+     * 私钥加密(用于数据签名)
+     *
+     * @param data          加密前的字符串
+     * @param privateKeyStr base64编码后的私钥
+     * @return base64编码后后的字符串
+     * @throws Exception
+     */
+    public static String encryptByPrivateKey(String data, String privateKeyStr) throws Exception {
+        //Java原生base64解码
+        byte[] priKey = Base64.getDecoder().decode(privateKeyStr);
+        //创建PKCS8编码密钥规范
+        PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(priKey);
+        //返回转换指定算法的KeyFactory对象
+        KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
+        //根据PKCS8编码密钥规范产生私钥对象
+        PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
+        //根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
+        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
+        //用私钥初始化此Cipher对象(加密模式)
+        cipher.init(Cipher.ENCRYPT_MODE, privateKey);
+        //对数据加密
+        byte[] encrypt = cipher.doFinal(data.getBytes());
+        //返回base64编码后的字符串
+        return Base64.getEncoder().encodeToString(encrypt);
+    }
+
+    /**
+     * 公钥解密(用于数据验签)
+     *
+     * @param data         解密前的字符串
+     * @param publicKeyStr base64编码后的公钥
+     * @return 解密后的字符串
+     * @throws Exception
+     */
+    public static String decryptByPublicKey(String data, String publicKeyStr) throws Exception {
+        //Java原生base64解码
+        byte[] pubKey = Base64.getDecoder().decode(publicKeyStr);
+        //创建X509编码密钥规范
+        X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKey);
+        //返回转换指定算法的KeyFactory对象
+        KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
+        //根据X509编码密钥规范产生公钥对象
+        PublicKey publicKey = keyFactory.generatePublic(x509KeySpec);
+        //根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
+        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
+        //用公钥初始化此Cipher对象(解密模式)
+        cipher.init(Cipher.DECRYPT_MODE, publicKey);
+        //对数据解密
+        byte[] decrypt = cipher.doFinal(Base64.getDecoder().decode(data));
+        //返回字符串
+        return new String(decrypt);
+    }
+
+    /**
+     * RSA签名
+     *
+     * @param data     待签名数据
+     * @param priKey   私钥
+     * @param signType RSA或RSA2
+     * @return 签名
+     * @throws Exception
+     */
+    public static String sign(byte[] data, byte[] priKey, String signType) throws Exception {
+        //创建PKCS8编码密钥规范
+        PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(priKey);
+        //返回转换指定算法的KeyFactory对象
+        KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
+        //根据PKCS8编码密钥规范产生私钥对象
+        PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
+        //标准签名算法名称(RSA还是RSA2)
+        String algorithm = RSA_KEY_ALGORITHM.equals(signType) ? RSA_SIGNATURE_ALGORITHM : RSA2_SIGNATURE_ALGORITHM;
+        //用指定算法产生签名对象Signature
+        Signature signature = Signature.getInstance(algorithm);
+        //用私钥初始化签名对象Signature
+        signature.initSign(privateKey);
+        //将待签名的数据传送给签名对象(须在初始化之后)
+        signature.update(data);
+        //返回签名结果字节数组
+        byte[] sign = signature.sign();
+        //返回Base64编码后的字符串
+        return Base64.getEncoder().encodeToString(sign);
+    }
+
+    /**
+     * RSA校验数字签名
+     *
+     * @param data     待校验数据
+     * @param sign     数字签名
+     * @param pubKey   公钥
+     * @param signType RSA或RSA2
+     * @return boolean 校验成功返回true,失败返回false
+     */
+    public static boolean verify(byte[] data, byte[] sign, byte[] pubKey, String signType) throws Exception {
+        //返回转换指定算法的KeyFactory对象
+        KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
+        //创建X509编码密钥规范
+        X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKey);
+        //根据X509编码密钥规范产生公钥对象
+        PublicKey publicKey = keyFactory.generatePublic(x509KeySpec);
+        //标准签名算法名称(RSA还是RSA2)
+        String algorithm = RSA_KEY_ALGORITHM.equals(signType) ? RSA_SIGNATURE_ALGORITHM : RSA2_SIGNATURE_ALGORITHM;
+        //用指定算法产生签名对象Signature
+        Signature signature = Signature.getInstance(algorithm);
+        //用公钥初始化签名对象,用于验证签名
+        signature.initVerify(publicKey);
+        //更新签名内容
+        signature.update(data);
+        //得到验证结果
+        return signature.verify(sign);
+    }
+
+}

File diff suppressed because it is too large
+ 167 - 0
src/test/java/cn/cslg/pas/test/TempServiceTests.java