Explorar el Código

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

wangliang hace 4 años
padre
commit
bcb1cc9816

+ 12 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/config/DictionaryConfig.java

@@ -1,9 +1,6 @@
 package com.qmth.distributed.print.business.config;
 
-import com.qmth.distributed.print.business.domain.AliYunOssDomain;
-import com.qmth.distributed.print.business.domain.PrefixUrlDomain;
-import com.qmth.distributed.print.business.domain.SmsDomain;
-import com.qmth.distributed.print.business.domain.SysDomain;
+import com.qmth.distributed.print.business.domain.*;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -61,4 +58,15 @@ public class DictionaryConfig {
     public AliYunOssDomain aliYunOssDomain() {
         return new AliYunOssDomain();
     }
+
+    /**
+     * 机构用户中心配置
+     *
+     * @return
+     */
+    @Bean
+    @ConfigurationProperties(prefix = "org.center", ignoreUnknownFields = false)
+    public OrgCenterDomain orgCenterDomain() {
+        return new OrgCenterDomain();
+    }
 }

+ 34 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/domain/OrgCenterDomain.java

@@ -0,0 +1,34 @@
+package com.qmth.distributed.print.business.domain;
+
+/**
+ * @Description: 机构用户中心配置
+ * @Author: CaoZixuan
+ * @Date: 2021-04-02
+ */
+public class OrgCenterDomain {
+    private static final long serialVersionUID = 7510626406622200443L;
+
+    private String url;
+
+    private String orgQueryApi;
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getOrgQueryApi() {
+        return orgQueryApi;
+    }
+
+    public void setOrgQueryApi(String orgQueryApi) {
+        this.orgQueryApi = orgQueryApi;
+    }
+}

+ 34 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/OrgCenterTypeEnum.java

@@ -0,0 +1,34 @@
+package com.qmth.distributed.print.business.enums;
+
+/**
+ * @Description: 机构用户中心机构类别
+ * @Author: CaoZixuan
+ * @Date: 2021-03-27
+ */
+public enum OrgCenterTypeEnum {
+    NETWORK("NETWORK","高校网院"),
+    COLLEGE("COLLEGE","高校教务处"),
+    UNDERGRADUATE("UNDERGRADUATE","本科招办"),
+    POSTGRADUATE("COLLEGE","研究生招办"),
+    MINISTRY("MINISTRY","考试院"),
+    AOPENG("AOPENG","奥鹏"),
+    PARTNER("PARTNER","合作机构"),
+    OTHER("OTHER","其他"),
+    ;
+
+    OrgCenterTypeEnum(String typeCode, String typeName) {
+        this.typeCode = typeCode;
+        this.typeName = typeName;
+    }
+
+    private final String typeCode;
+    private final String typeName;
+
+    public String getTypeCode() {
+        return typeCode;
+    }
+
+    public String getTypeName() {
+        return typeName;
+    }
+}

+ 21 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CallApiOrgCenterService.java

@@ -0,0 +1,21 @@
+package com.qmth.distributed.print.business.service;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 机构用户中心接口调用服务
+ * @Author: CaoZixuan
+ * @Date: 2021-04-02
+ */
+public interface CallApiOrgCenterService {
+
+    /**
+     * 查询机构信息
+     * @return 机构信息(包含学校和合作方)
+     * @throws IOException 异常
+     */
+    List<Map> callOrgInfo() throws IOException;
+
+}

+ 13 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/OrgCenterDataDisposeService.java

@@ -0,0 +1,13 @@
+package com.qmth.distributed.print.business.service;
+
+import java.io.IOException;
+
+/**
+ * @Description: 机构中心数据处理服务
+ * @Author: CaoZixuan
+ * @Date: 2021-04-02
+ */
+public interface OrgCenterDataDisposeService {
+
+    void updateSchoolInfo() throws IOException;
+}

+ 65 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CallApiOrgCenterServiceImpl.java

@@ -0,0 +1,65 @@
+package com.qmth.distributed.print.business.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.boot.tools.signature.SignatureEntity;
+import com.qmth.boot.tools.signature.SignatureType;
+import com.qmth.distributed.print.business.config.DictionaryConfig;
+import com.qmth.distributed.print.business.service.CallApiOrgCenterService;
+import com.qmth.distributed.print.business.util.HttpUtil;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @Description: 机构用户中心接口调取服务实现类
+ * @Author: CaoZixuan
+ * @Date: 2021-03-26
+ */
+@Service
+public class CallApiOrgCenterServiceImpl implements CallApiOrgCenterService {
+    @Resource
+    private DictionaryConfig dictionaryConfig;
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public List<Map> callOrgInfo() throws IOException {
+        String url = dictionaryConfig.orgCenterDomain().getUrl() + dictionaryConfig.orgCenterDomain().getOrgQueryApi();
+
+        Map<String,Object> params = new HashMap<>();
+        int pageNumber = 1;
+        int pageSize = 100;
+
+        List<Map> orgList = null;
+
+        while (true){
+            params.put("pageNumber",pageNumber);
+            params.put("pageSize",pageSize);
+            long timestamp = System.currentTimeMillis();
+            String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, dictionaryConfig.orgCenterDomain().getOrgQueryApi(), timestamp, dictionaryConfig.sysDomain().getAccessKey(), dictionaryConfig.sysDomain().getAccessSecret());
+            String result = HttpUtil.post(url, params, accessToken, timestamp);
+            if (Objects.nonNull(result)) {
+                if (result.contains("HTTP Status 401 – 未经授权的")) {
+                    throw ExceptionResultEnum.ERROR.exception("机构用户中心鉴权失败");
+                }
+                List<Map> tempList = JSONObject.parseArray(result, Map.class);
+                if (Objects.nonNull(tempList) && tempList.size() > 0) {
+                    if (Objects.isNull(orgList)) {
+                        orgList = new ArrayList<>();
+                    }
+                    orgList.addAll(tempList);
+                    pageNumber++;
+                } else {
+                    break;
+                }
+            } else {
+                break;
+            }
+        }
+        return orgList;
+    }
+}

+ 65 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/OrgCenterDataDisposeServiceImpl.java

@@ -0,0 +1,65 @@
+package com.qmth.distributed.print.business.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.distributed.print.business.entity.BasicSchool;
+import com.qmth.distributed.print.business.enums.OrgCenterTypeEnum;
+import com.qmth.distributed.print.business.service.BasicSchoolService;
+import com.qmth.distributed.print.business.service.CallApiOrgCenterService;
+import com.qmth.distributed.print.business.service.OrgCenterDataDisposeService;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @Description: 机构数据中心数据处理服务实现类
+ * @Author: CaoZixuan
+ * @Date: 2021-04-02
+ */
+@Service
+public class OrgCenterDataDisposeServiceImpl implements OrgCenterDataDisposeService {
+    @Resource
+    private CallApiOrgCenterService callApiOrgCenterService;
+    @Resource
+    private BasicSchoolService basicSchoolService;
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void updateSchoolInfo() throws IOException {
+        // 删除原有学校
+        basicSchoolService.remove(new QueryWrapper<BasicSchool>().lambda().gt(BasicSchool::getId,0));
+
+        List<Map> result = callApiOrgCenterService.callOrgInfo();
+        for (Map map : result) {
+            Long id = SystemConstant.convertIdToLong(String.valueOf(map.get("id")));
+            String code = String.valueOf(map.get("code"));
+            String name = String.valueOf(map.get("name"));
+            String accessKey = String.valueOf(map.get("accessKey"));
+            String accessSecret = String.valueOf(map.get("accessSecret"));
+            Map typeMap = JSONObject.parseObject(String.valueOf(map.get("type")));
+            String typeCode = String.valueOf(typeMap.get("code"));
+            String typeName = String.valueOf(typeMap.get("name"));
+            if (!Arrays.stream(OrgCenterTypeEnum.values()).map(OrgCenterTypeEnum::getTypeCode).collect(Collectors.toList()).contains(typeCode)){
+                throw ExceptionResultEnum.ERROR.exception("机构类型在枚举中不存在 + typeCode = " + typeCode);
+            }
+            if (!OrgCenterTypeEnum.PARTNER.getTypeCode().equals(typeCode)){
+                BasicSchool school = new BasicSchool();
+                school.setId(id);
+                school.setCode(code);
+                school.setName(name);
+                school.setEnable(true);
+                school.setAccessKey(accessKey);
+                school.setAccessSecret(accessSecret);
+                basicSchoolService.save(school);
+            }
+        }
+    }
+}

+ 11 - 0
distributed-print-common/src/main/java/com/qmth/distributed/print/common/contant/SystemConstant.java

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.common.contant;
 
 import java.nio.charset.Charset;
+import java.util.Objects;
 
 /**
  * @Description: 系统常量
@@ -19,6 +20,7 @@ public class SystemConstant {
     public static final String MD5 = "MD5";
     public static final String SUCCESS = "success";
     public static final String EXTEND_COLUMN = "extendColumn";
+    public static final String METHOD = "post";
 
     /**
      * 鉴权
@@ -41,4 +43,13 @@ public class SystemConstant {
     public static final String AES_MODE_PKCS5 = "AES/CBC/PKCS5Padding";//用这个模式,规则必须为16位
     public static final String AES_MODE_PKCS7 = "AES/CBC/PKCS7Padding";//用这个模式,规则必须为16位
     public static final String AES_RULE = "1234567890123456";//aes密钥
+
+    /**
+     * id转换为long
+     *
+     * @return
+     */
+    public static Long convertIdToLong(String id) {
+        return Objects.nonNull(id) && id.length() > 0 ? Long.parseLong(id) : null;
+    }
 }

+ 7 - 0
distributed-print/src/main/java/com/qmth/distributed/print/start/StartRunning.java

@@ -1,10 +1,13 @@
 package com.qmth.distributed.print.start;
 
+import com.qmth.distributed.print.business.service.OrgCenterDataDisposeService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
+
 /**
  * @Description: 服务启动时初始化运行,哪个微服务模块需要则拿此模版去用
  * @Param:
@@ -16,9 +19,13 @@ import org.springframework.stereotype.Component;
 public class StartRunning implements CommandLineRunner {
     private final static Logger log = LoggerFactory.getLogger(StartRunning.class);
 
+    @Resource
+    private OrgCenterDataDisposeService orgCenterDataDisposeService;
+
     @Override
     public void run(String... args) throws Exception {
         log.info("服务器启动时执行 start");
+        orgCenterDataDisposeService.updateSchoolInfo();
         log.info("服务器启动时执行 end");
     }
 }

+ 3 - 0
distributed-print/src/main/resources/application.properties

@@ -53,6 +53,9 @@ sys.config.accessKey=0bce69d94a7b4aef8bc0badf150351a9
 sys.config.accessSecret=LdUwb5X4etmjW7fDn0KAdoXG0Yt7AkDu
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 
+org.center.url=https://solar.qmth.com.cn
+org.center.orgQueryApi=/api/open/org/query
+
 #com.qmth.api.uri-prefix=/aaa
 #\u7EDF\u8BA1\u9875\u9762\u914D\u7F6E
 com.qmth.api.metrics-endpoint=/metrics-count