Просмотр исходного кода

Merge branch 'develop' into 'release-2.2.4'

feature(新增appSecret字段): 新增appSecret字段

See merge request dcuc-tjdsj/app-service!74
黄资权 3 лет назад
Родитель
Сommit
c061e9e260
21 измененных файлов с 565 добавлено и 335 удалено
  1. 8 8
      Jenkinsfile
  2. 4 0
      README.md
  3. 5 0
      dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppInfoAcceptDTO.java
  4. 2 5
      dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppResourceAcceptDTO.java
  5. 5 0
      dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppResourceDTO.java
  6. 25 0
      dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppStrAcceptDTO.java
  7. 24 24
      dcuc-app-service/pom.xml
  8. 3 0
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/DcucAppApplication.java
  9. 27 19
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/business/impl/ResourceBusiness.java
  10. 0 1
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/facade/ApplyInfoFacade.java
  11. 7 2
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/IApplyInfoService.java
  12. 7 0
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/IApplyOauthService.java
  13. 296 223
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ApplyInfoServiceImpl.java
  14. 8 0
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ApplyOauthServiceImpl.java
  15. 19 5
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ManufacturerInfoServiceImpl.java
  16. 25 9
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ResourceServiceImpl.java
  17. 7 4
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ServiceResourceServiceImpl.java
  18. 48 15
      dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/strategy/AppResourceStrategy.java
  19. 31 5
      dcuc-app-service/src/main/resources/application-base.yml
  20. 0 6
      dcuc-app-service/src/main/resources/application-oracle.yml
  21. 14 9
      dcuc-app-service/src/main/resources/config/mysql/V4_1_0007__app_del_orgid.sql

+ 8 - 8
Jenkinsfile

@@ -5,9 +5,9 @@ def build = new org.devops.build()
 def color = new org.devops.color()
 def systemtime = new org.devops.systemtime()
 
-def String cpu = "${env.cpu}"
-def String imagePrefix = "${env.imagePrefix}"
-def String buildImage = "${env.buildImage}"
+String cpu = "${env.cpu}"
+String imagePrefix = "${env.imagePrefix}"
+String buildImage = "${env.buildImage}"
 
 pipeline {
     agent {
@@ -46,12 +46,12 @@ pipeline {
                     script {
                         version = build.GetMvnParentVersion()
                         systime = systemtime.GetSysTime('yyMMdd')
-                        //将打出来的tar包,按照命名规范命名。根据实际情况,修改对应的系统简称和区域标识(DCUC-APP-SERVICE-TJDSJ
+                        //将打出来的tar包,按照命名规范命名。根据实际情况,修改对应的系统简称和区域标识(DCUC-APP-SERVICE-BJZ
                         sh """cd dcuc-app-service/target
-                            cp dcuc-app-service-*.tar.gz DCUC-APP-SERVICE-TJDSJ-${version}-${env.GIT_COMMIT.take(8)}-BETA-${systime}.tar.gz
+                            cp dcuc-app-service-*.tar.gz DCUC-APP-SERVICE-BJZ-${version}-${env.GIT_COMMIT.take(8)}-BETA-${systime}.tar.gz
                         """
-                        //将复制的按照命名规范的tar包提取到Jenkins的面板,方便下载。根据实际情况,修改对应的系统简称和区域标识(DCUC-APP-SERVICE-TJDSJ
-                        archiveArtifacts artifacts: 'dcuc-app-service/target/DCUC-APP-SERVICE-TJDSJ-*.tar.gz'
+                        //将复制的按照命名规范的tar包提取到Jenkins的面板,方便下载。根据实际情况,修改对应的系统简称和区域标识(DCUC-APP-SERVICE-BJZ
+                        archiveArtifacts artifacts: 'dcuc-app-service/target/DCUC-APP-SERVICE-BJZ-*.tar.gz'
                     }
                 }
             }
@@ -60,7 +60,7 @@ pipeline {
         stage('DOCKER-BUILD') {
             when {
                 expression {
-                    return (buildImage  == 'true')
+                    return (buildImage == 'true')
                 }
             }
             steps {

+ 4 - 0
README.md

@@ -2,6 +2,10 @@
 ## 简介
 1. 提供对应用、厂商的增删改查
 2. 当厂商、应用状态发生变更时,会发送相应消息到消息中心
+
+## 更新日志
+### 2.0.1
+- 从应用资源目录同步应用秘钥
 ## 更新日志
 ### 2.1.0
   - 新增同步应用资源目录、服务资源目录、数据资源目录

+ 5 - 0
dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppInfoAcceptDTO.java

@@ -92,4 +92,9 @@ public class AppInfoAcceptDTO {
      */
     private String yyxttb;
 
+    /**
+     * 应用授权码
+     */
+    private String appsecret;
+
 }

+ 2 - 5
dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppResourceAcceptDTO.java

@@ -1,7 +1,6 @@
 package com.dragoninfo.dcuc.app.dto;
 
 
-import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.List;
@@ -15,14 +14,12 @@ import java.util.List;
 public class AppResourceAcceptDTO {
 
     /**
-     * 推送过来的应用实体类Vo
+     * 推送过来的应用实体类DTO
      */
-    @ApiModelProperty(value = "推送应用资源vo")
     private AppInfoAcceptDTO tappSystem;
     /**
-     * 推送过来的应用对应的菜单实体类Vo
+     * 推送过来的应用对应的菜单实体类DTO
      */
-    @ApiModelProperty(value = "推送菜单资源vo")
     private List<MenuResourceAcceptDTO> tappFunctionList;
 
 

+ 5 - 0
dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppResourceDTO.java

@@ -49,6 +49,11 @@ public class AppResourceDTO extends ResourceDTO implements Serializable {
      */
     private Date registrationTime;
 
+    /**
+     * 应用授权码
+     */
+    private String appSecret;
+
     /**
      * 应用系统运维单位名称
      */

+ 25 - 0
dcuc-app-model/src/main/java/com/dragoninfo/dcuc/app/dto/AppStrAcceptDTO.java

@@ -0,0 +1,25 @@
+package com.dragoninfo.dcuc.app.dto;
+
+
+import lombok.Data;
+
+/**
+ * 推送应用和菜单数据DTO
+ * 为保存全量json数据,字段设置为str类型
+ * @author mazq
+ * @date 2021/2/19
+ */
+@Data
+public class AppStrAcceptDTO {
+
+    /**
+     * 推送过来的应用信息字符串
+     */
+    private String tappSystem;
+    /**
+     * 推送过来的功能信息字符串
+     */
+    private String tappFunctionList;
+
+
+}

+ 24 - 24
dcuc-app-service/pom.xml

@@ -45,7 +45,7 @@
             <artifactId>duceap-cloud-starter-config-apollo</artifactId>
         </dependency>
         <!--审计-->
-        <!--<dependency>
+        <dependency>
             <groupId>com.dragonsoft</groupId>
             <artifactId>duceap-boot-starter-auditlog</artifactId>
             <exclusions>
@@ -54,26 +54,31 @@
                     <groupId>com.dragonsoft</groupId>
                 </exclusion>
             </exclusions>
-        </dependency>-->
-
-        <!--<dependency>
-            <groupId>com.dragonsoft</groupId>
-            <artifactId>auditlog-qm-tj</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>-->
-
-
+        </dependency>
         <!--MyBatis-Plus-->
         <dependency>
             <groupId>com.dragonsoft</groupId>
             <artifactId>duceap-boot-starter-mybatis</artifactId>
         </dependency>
-        <!--配置 duceap 结束-->
+
+        <!--redis缓存-->
+        <dependency>
+            <groupId>com.dragonsoft</groupId>
+            <artifactId>duceap-boot-starter-cache-redis</artifactId>
+            <exclusions>
+                <exclusion>
+                    <artifactId>lettuce-core</artifactId>
+                    <groupId>io.lettuce</groupId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
         <!--许可-->
         <dependency>
             <groupId>com.dragonsoft</groupId>
             <artifactId>duceap-support-license</artifactId>
         </dependency>
+        <!--配置 duceap 结束-->
 
         <!--许可依赖包 结束-->
 
@@ -105,31 +110,21 @@
             <version>2.1.2-SNAPSHOT</version>
         </dependency>
 
-        <dependency>
-            <groupId>com.dragoninfo</groupId>
-            <artifactId>dcuc-org-api</artifactId>
-            <version>2.0.3-tjdsj-SNAPSHOT</version>
-        </dependency>
 
         <dependency>
             <groupId>com.dragoninfo</groupId>
             <artifactId>dcuc-user-api</artifactId>
-            <version>2.0.4-tjdsj-SNAPSHOT</version>
+            <version>2.1.0-tjdsj-SNAPSHOT</version>
         </dependency>
 
         <dependency>
             <groupId>com.dragoninfo</groupId>
             <artifactId>dcuc-auth-api</artifactId>
-            <version>2.4.2-tjdsj-SNAPSHOT</version>
+            <version>2.4.1-tjdsj-SNAPSHOT</version>
         </dependency>
         <!--配置 dcuc 结束-->
 
         <!--配置第三方组件开始-->
-        <!--oracle 引入-->
-        <dependency>
-            <groupId>com.oracle</groupId>
-            <artifactId>ojdbc6</artifactId>
-        </dependency>
         <!--mysql 引入-->
         <dependency>
             <groupId>mysql</groupId>
@@ -141,6 +136,11 @@
             <artifactId>lombok</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+            <version>3.6.0</version>
+        </dependency>
         <!--配置第三方组件结束-->
 
         <!--配置 spring 开始-->
@@ -203,7 +203,7 @@
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-war-plugin</artifactId>
-                        <version>2.3.0</version>
+                        <version>2.1.1</version>
                         <configuration>
                             <failOnMissingWebXml>false</failOnMissingWebXml>
                             <!--排除licenseignore包,用来禁用许可开关,防止生产环境通过关闭开关,绕过许可-->

+ 3 - 0
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/DcucAppApplication.java

@@ -3,6 +3,8 @@ package com.dragoninfo.dcuc.app;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 
@@ -11,6 +13,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
  *
  * @author huangzqa
  */
+@EnableCaching
 @SpringBootApplication(scanBasePackages = {"com.dragonsoft.*", "com.dragoninfo.*"})
 @EnableDiscoveryClient
 @EnableFeignClients(basePackages = {"com.dragonsoft.*", "com.dragoninfo.*"})

+ 27 - 19
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/business/impl/ResourceBusiness.java

@@ -19,6 +19,7 @@ import com.dragoninfo.dcuc.app.service.IApplyInfoService;
 import com.dragoninfo.dcuc.app.service.IResourceService;
 import com.dragoninfo.dcuc.app.service.IResourceSyncService;
 import com.dragoninfo.dcuc.app.service.IServiceResourceService;
+import com.dragoninfo.dcuc.app.service.impl.ResourceServiceImpl;
 import com.dragoninfo.dcuc.app.vo.BusSendReqVO;
 import com.dragoninfo.dcuc.auth.auth.facade.IBimBusinessFacade;
 import com.dragoninfo.dcuc.common.Constants;
@@ -131,7 +132,7 @@ public class ResourceBusiness implements IResourceBusiness {
             logger.info("appIncrSync get appInfo is null. appCode is:{}", appCode);
             return false;
         }
-        acceptAppResource(appMenuDTO);
+        acceptAppResource(appStr, appMenuDTO);
         return false;
     }
 
@@ -352,18 +353,22 @@ public class ResourceBusiness implements IResourceBusiness {
     /**
      * 增量新增/更新应用资源和应用相关的菜单资源
      *
+     * @param appStr
      * @param acceptDTO
      * @return
      */
-    public boolean acceptAppResource(AppResourceAcceptDTO acceptDTO) {
+    public boolean acceptAppResource(String appStr, AppResourceAcceptDTO acceptDTO) {
+        AppStrAcceptDTO strAcceptDTO = JSON.parseObject(appStr, AppStrAcceptDTO.class);
+
         ResourceTypeEnum appEnum = ResourceTypeEnum.TJ_APP;
         ResourceSyncDTO syncDTO = new ResourceSyncDTO(appEnum.getResourceId()
                 , appEnum.getResourceType(), appEnum.getResourceProvider());
         AppInfoAcceptDTO appAcceptDTO = acceptDTO.getTappSystem();
+
         syncDTO.setAppCode(appAcceptDTO.getYyxtbh());
         syncDTO.setAppName(appAcceptDTO.getYyxtmc());
         syncDTO.setExtId(appAcceptDTO.getId());
-        syncDTO.setContent(JSON.toJSONString(appAcceptDTO));
+        syncDTO.setContent(strAcceptDTO.getTappSystem());
         syncDTO.setDeleted(BooleanEnum.FALSE.getValue());
         syncDTO.setSync(BooleanEnum.TRUE.getValue());
         syncService.insertRemoteResourceSync(syncDTO);
@@ -374,7 +379,7 @@ public class ResourceBusiness implements IResourceBusiness {
         menuSyncDTO.setAppCode(appAcceptDTO.getYyxtbh());
         menuSyncDTO.setAppName(appAcceptDTO.getYyxtmc());
         menuSyncDTO.setExtId(appAcceptDTO.getId());
-        menuSyncDTO.setContent(JSON.toJSONString(acceptDTO.getTappFunctionList()));
+        menuSyncDTO.setContent(strAcceptDTO.getTappFunctionList());
         menuSyncDTO.setDeleted(BooleanEnum.FALSE.getValue());
         menuSyncDTO.setSync(BooleanEnum.TRUE.getValue());
         syncService.insertRemoteResourceSync(menuSyncDTO);
@@ -426,6 +431,7 @@ public class ResourceBusiness implements IResourceBusiness {
         dto.setApplyCategory(appInfoAcceptDTO.getYyxtfldm());
         dto.setPoliceSpecies(appInfoAcceptDTO.getGajzfldm());
         dto.setManagerDescribe(appInfoAcceptDTO.getYyxtsm());
+        AppResourceDTO appResourceDTO = ResourceServiceImpl.convertToAppDTO(appInfoAcceptDTO);
         //设置菜单资源
         List<MenuResourceAcceptDTO> tAppFunctionList = acceptDTO.getTappFunctionList();
         List<MenuResourceDTO> dtoArrayList = new ArrayList<>();
@@ -438,8 +444,11 @@ public class ResourceBusiness implements IResourceBusiness {
             menuDTO.setStatus(menuResourceAcceptDTO.getZyzt());
             dtoArrayList.add(menuDTO);
         }
-        dto.setMenusResources(dtoArrayList);
-        return dto;
+        appResourceDTO.setMenusResources(dtoArrayList);
+        String appCode = appInfoAcceptDTO.getYyxtbh();
+        List<MenuResourceDTO> menusDTOs = ResourceServiceImpl.convertToMenuDTOs(appCode, tAppFunctionList);
+        appResourceDTO.setMenusResources(menusDTOs);
+        return appResourceDTO;
     }
 
     /**
@@ -496,10 +505,10 @@ public class ResourceBusiness implements IResourceBusiness {
         Integer pageSize = requestParamDTO.getPageSize();
         Boolean listingAll = requestParamDTO.getListingAll();
         Boolean menuSync = requestParamDTO.getMenuSync();
-        if(null == listingAll) {
+        if (null == listingAll) {
             listingAll = true;
         }
-        if(null == menuSync) {
+        if (null == menuSync) {
             menuSync = false;
         }
         pageSize = (pageSize == null ? 50 : pageSize);
@@ -511,8 +520,8 @@ public class ResourceBusiness implements IResourceBusiness {
             Integer currentPageNo = requestParamDTO.getCurrentPageNo();
             List<String> resourceTypeList = requestParamDTO.getListAllResourceType();
             for (ResourceTypeEnum resourceEnum : ResourceTypeEnum.values()) {
-                if(CollectionUtils.isNotEmpty(resourceTypeList)
-                    && !resourceTypeList.contains(resourceEnum.getResourceType())) {
+                if (CollectionUtils.isNotEmpty(resourceTypeList)
+                        && !resourceTypeList.contains(resourceEnum.getResourceType())) {
                     continue;
                 }
                 //若是增量获取currentPage = 数据库中上次同步的页数
@@ -540,7 +549,6 @@ public class ResourceBusiness implements IResourceBusiness {
     /**
      * 根据页码获取资源列表
      *
-     *
      * @param menuSync
      * @param pageSize
      * @param listingParam
@@ -569,7 +577,6 @@ public class ResourceBusiness implements IResourceBusiness {
     /**
      * 从currentPageNo页获取全量的资源列表
      *
-     *
      * @param menuSync
      * @param pageSize
      * @return
@@ -608,9 +615,9 @@ public class ResourceBusiness implements IResourceBusiness {
         }
         String idcard = UserContextUtils.getCurrentUser().getIdcard();
         MenuTask menuTask = new MenuTask(extAppIds, idcard);
-        if(!menuSync){
+        if (!menuSync) {
             executor.submit(menuTask);
-        }else {
+        } else {
             menuTask.run();
         }
     }
@@ -799,7 +806,7 @@ public class ResourceBusiness implements IResourceBusiness {
         } else if (ResourceTypeEnum.TJ_SERVICE.equals(resourceTypeEnum)) {
             httpResult = getServiceResource(pageNo, pageSize);
         } else if (ResourceTypeEnum.BU_SERVICE.equals(resourceTypeEnum)) {
-            httpResult = getBuServiceResource(pageNo,pageSize);
+            httpResult = getBuServiceResource(pageNo, pageSize);
         } else {
             httpResult = new HttpResult();
             httpResult.setCode(ResponseStatus.SUCCESS_CODE);
@@ -811,6 +818,7 @@ public class ResourceBusiness implements IResourceBusiness {
 
     /**
      * 从大数据平台获取
+     *
      * @param pageNo
      * @param pageSize
      * @return
@@ -819,12 +827,12 @@ public class ResourceBusiness implements IResourceBusiness {
         String resourceUrl = resourceConfig.getBuServiceUrl();
         HttpResult httpResult = new HttpResult();
         Map<String, Object> map = new HashMap<>();
-        map.put("page", pageNo -1);
+        map.put("page", pageNo - 1);
         map.put("size", pageSize);
         JSONArray array = new JSONArray();
         JSONObject searchCondition = new JSONObject();
-        searchCondition.put("name","isDeleted");
-        searchCondition.put("op","=");
+        searchCondition.put("name", "isDeleted");
+        searchCondition.put("op", "=");
         searchCondition.put("value", BooleanEnum.FALSE.value);
         array.add(searchCondition);
         map.put("searchCondition", array.toJSONString());
@@ -966,7 +974,7 @@ public class ResourceBusiness implements IResourceBusiness {
                     resourceEnum.getResourceType(), resourceEnum.getResourceProvider());
             dto.setContent(jsonString);
             JSONObject jsonObject = JSONObject.parseObject(jsonString);
-            if(ResourceTypeEnum.TJ_APP.equals(resourceEnum)) {
+            if (ResourceTypeEnum.TJ_APP.equals(resourceEnum)) {
                 String appCode = jsonObject.getString("yyxtbh");
                 String appName = jsonObject.getString("yyxtmc");
                 dto.setAppCode(appCode);

+ 0 - 1
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/facade/ApplyInfoFacade.java

@@ -3,7 +3,6 @@ package com.dragoninfo.dcuc.app.facade;
 import com.dragoninfo.dcuc.app.dto.ApplyInfoDTO;
 import com.dragoninfo.dcuc.app.entity.ApplyInfo;
 import com.dragoninfo.dcuc.app.service.IApplyInfoService;
-import com.dragoninfo.dcuc.user.user.enumresources.OperateTypeEnum;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
 import org.springframework.beans.factory.annotation.Autowired;

+ 7 - 2
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/IApplyInfoService.java

@@ -4,7 +4,6 @@ import com.dragoninfo.dcuc.app.dto.ApplyInfoDTO;
 import com.dragoninfo.dcuc.app.entity.ApplyInfo;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
-import com.dragonsoft.duceap.core.service.IBaseService;
 import org.springframework.data.domain.Page;
 
 import java.util.List;
@@ -15,7 +14,7 @@ import java.util.Map;
  * @author yica huangzqa
  * @date 2018/8/7
  */
-public interface IApplyInfoService extends IBaseService<ApplyInfo, String> {
+public interface IApplyInfoService {
 
     /**
      * 详情
@@ -212,6 +211,7 @@ public interface IApplyInfoService extends IBaseService<ApplyInfo, String> {
 
     /**
      * 根据应用url获取应用信息
+     *
      * @param applyUrl
      * @return
      */
@@ -219,11 +219,16 @@ public interface IApplyInfoService extends IBaseService<ApplyInfo, String> {
 
     /**
      * 获取机构id集合
+     *
      * @param appCodes 应用code集合
      * @return
      */
     List<ApplyInfo> getIdsByCodes(List<String> appCodes);
 
+    ApplyInfo getOne(String id);
+
+    List<ApplyInfo> findAll();
+
     ResponseStatus impExcel(String fileId);
 
     /**

+ 7 - 0
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/IApplyOauthService.java

@@ -38,4 +38,11 @@ public interface IApplyOauthService extends IBaseService<ApplyOauth, String> {
      */
     List<ApplyOauth> applyOauthList(Map<String, Object> map);
 
+    /**
+     * 根据Appid获取应用密钥
+     * @param applyId
+     * @return
+     */
+    ApplyOauth getByAppId(String applyId);
+
 }

+ 296 - 223
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ApplyInfoServiceImpl.java

@@ -1,14 +1,14 @@
 package com.dragoninfo.dcuc.app.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.dragoninfo.dcuc.app.dto.AppEventDTO;
 import com.dragoninfo.dcuc.app.dto.ApplyInfoDTO;
+import com.dragoninfo.dcuc.app.dto.UpdateUserInfoEventDTO;
 import com.dragoninfo.dcuc.app.entity.ApplyInfo;
 import com.dragoninfo.dcuc.app.entity.ManufacturerInfo;
-import com.dragoninfo.dcuc.app.enumresources.AppMsgTypeEnum;
 import com.dragoninfo.dcuc.app.mapper.ApplyInfoMapper;
 import com.dragoninfo.dcuc.app.service.IApplyInfoService;
 import com.dragoninfo.dcuc.app.service.IApplyOauthService;
@@ -19,15 +19,13 @@ import com.dragoninfo.dcuc.common.utils.LangUtil;
 import com.dragoninfo.dcuc.duceap.facade.IDuceapUploadFacade;
 import com.dragoninfo.dcuc.duceap.upload.dto.DocContentDTO;
 import com.dragoninfo.dcuc.duceap.upload.dto.FileUploadDTO;
-import com.dragoninfo.dcuc.org.entity.OrgInfo;
-import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade;
+import com.dragoninfo.dcuc.user.entity.org.OrgInfo;
+import com.dragoninfo.dcuc.user.facade.org.IOrgInfoFacade;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
 import com.dragonsoft.duceap.base.entity.uploader.FileHolder;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
-import com.dragonsoft.duceap.core.context.ContextUtils;
 import com.dragonsoft.duceap.core.search.Searchable;
-import com.dragonsoft.duceap.mybaitsplus.core.services.BaseMybatisService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -37,6 +35,9 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
@@ -55,20 +56,16 @@ import java.util.stream.Collectors;
  * @author huangzqa
  * @date 2020/10/27
  */
-@Transactional(rollbackFor = Exception.class)
+@CacheConfig(cacheNames = "DCUC-APP-APP")
 @Service
-public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String> implements IApplyInfoService {
+public class ApplyInfoServiceImpl implements IApplyInfoService {
 
-    private final ApplyInfoMapper applyInfoMapper;
+    @Autowired
+    private ApplyInfoMapper applyInfoMapper;
 
     @Resource
     private IDuceapUploadFacade uploadhandler;
 
-    public ApplyInfoServiceImpl(ApplyInfoMapper applyInfoMapper) {
-        super(applyInfoMapper);
-        this.applyInfoMapper = applyInfoMapper;
-    }
-
     @Autowired
     private IManufacturerInfoService manufacturerInfoService;
 
@@ -84,94 +81,88 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
     @Autowired
     private IOrgInfoFacade orgInfoFacade;
 
+    @Cacheable(key = "targetClass +#p0")
     @Override
     public ApplyInfo applyDetail(String id) {
         return applyInfoMapper.selectById(id);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public Page<ApplyInfo> applyInfoPage(SearchDTO searchDTO) {
 
         Searchable searchable = Searchable.toSearchable(searchDTO);
         searchable.addSort(Sort.Direction.DESC, "SORT");
         searchable.addSort(Sort.Direction.DESC, "REGISTRATION_TIME");
-      //  searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.TRUE.getValue());
         return applyInfoMapper.pagingBySearchable(searchable);
     }
 
-    @Override
-    public ApplyInfo saveAppIy(ApplyInfoDTO applyInfoDTO) {
-        ApplyInfo applyInfo = new ApplyInfo();
-        BeanUtils.copyProperties(applyInfoDTO, applyInfo);
-
-        List<FileHolder> file = applyInfoDTO.getFile();
-
-        String manufacturerId = applyInfo.getManufacturerId();
-        if(StringUtils.isNotBlank(manufacturerId)) {
-            ManufacturerInfo manufacturerInfo = manufacturerInfoService.getOne(manufacturerId);
-            if (manufacturerInfo != null) {
-                String manufacturerName = manufacturerInfo.getManufacturerName();
-                applyInfo.setManufacturerName(manufacturerName);
-            }
+    /**
+     * 校验数据是否为空
+     *
+     * @param cell
+     * @param i
+     * @param row
+     */
+    private static void checkServiceResourceCellData(Cell cell, int i, int row) {
+        if (!(cell == null || StringUtils.isEmpty(cell.getStringCellValue()))) {
+            return;
         }
-
-        String applyCode = applyInfo.getApplyCode();
-        String secretKey = getApiKeys(applyCode);
-        String apiKey = getApiKeys(applyCode);
-        applyInfo.setSecretKey(secretKey);
-        applyInfo.setApiKey(apiKey);
-        applyInfo.setDeleted(BooleanEnum.FALSE.getValue());
-        applyInfoMapper.insert(applyInfo);
-        // 保存 appId
-        applyOauthService.saveOauth(applyInfo);
-        String id = applyInfo.getId();
-        // 保存图片
-        if(null != file) {
-            saveOrUpdateFile(id, file);
+        switch (i) {
+            case 0:
+                throw new NumberFormatException("第" + (row + 1) + "行'应用系统名称'为空!");
+            case 1:
+                throw new NumberFormatException("第" + (row + 1) + "行'应用系统编号'为空!");
+            case 2:
+                throw new NumberFormatException("第" + (row + 1) + "行'应用系统英文名称'为空!");
+            case 3:
+                throw new NumberFormatException("第" + (row + 1) + "行'系统在用标识'为空!");
+            default:
+                break;
         }
 
-        return applyInfo;
     }
 
-
-    @Override
-    public ApplyInfo updateApply(ApplyInfoDTO applyInfoDTO) {
-        ApplyInfo applyInfo = new ApplyInfo();
-        BeanUtils.copyProperties(applyInfoDTO, applyInfo);
-        List<FileHolder> file = applyInfoDTO.getFile();
-
-        String manufacturerId = applyInfo.getManufacturerId();
-        if (!StringUtils.isEmpty(manufacturerId)) {
-            ManufacturerInfo manufacturerInfo = manufacturerInfoService.getOne(manufacturerId);
-            if (manufacturerInfo != null) {
-                String manufacturerName = manufacturerInfo.getManufacturerName();
-                applyInfo.setManufacturerName(manufacturerName);
-            }
+    /**
+     * 校验列头
+     *
+     * @param r
+     */
+    private static void checkRowTitle(Row r) {
+        if (!r.getCell(0).getStringCellValue().equals("应用系统名称")) {
+            throw new NumberFormatException("缺少'应用系统名称'列!");
         }
-
-        String id = applyInfo.getId();
-        //旧应用
-        ApplyInfo oldApplyInfo = applyInfoMapper.selectById(id);
-        if(null == oldApplyInfo) {
-            return null;
+        if (!r.getCell(1).getStringCellValue().equals("应用系统编号")) {
+            throw new NumberFormatException("缺少'应用系统编号'列!");
         }
-        applyInfo.setDeleted(BooleanEnum.FALSE.getValue());
-        applyOauthService.updateOauth(applyInfo);
-        applyInfoMapper.updateById(applyInfo);
-
-        if (CollectionUtils.isNotEmpty(file)) {
-            saveOrUpdateFile(id, file);
+        if (!r.getCell(2).getStringCellValue().equals("应用系统英文名称")) {
+            throw new NumberFormatException("缺少'应用系统英文名称'列!");
         }
-        //权限变更通知
-        boolean isNotification = StringUtils.isNotEmpty(oldApplyInfo.getApplyUrl())&&( !oldApplyInfo.getApplyUrl().equals(applyInfo.getApplyUrl())
-                || !oldApplyInfo.getApplyStatus().equals(applyInfo.getApplyStatus()));
-        // 应用 url 当发送变更时进行通知
-        if (isNotification) {
-            permissionNotificationFacade.sendAppAppUpdate(id);
+        if (!r.getCell(3).getStringCellValue().equals("系统在用标识")) {
+            throw new NumberFormatException("缺少'系统在用标识'列!");
+        }
+        if (!r.getCell(4).getStringCellValue().equals("上线日期")) {
+            throw new NumberFormatException("缺少'上线日期'列!");
+        }
+        if (!r.getCell(5).getStringCellValue().equals("应用负责人")) {
+            throw new NumberFormatException("缺少'应用负责人'列!");
+        }
+        if (!r.getCell(6).getStringCellValue().equals("应用系统事权单位代码")) {
+            throw new NumberFormatException("缺少'应用系统事权单位代码'列!");
+        }
+        if (!r.getCell(7).getStringCellValue().equals("应用系统管理单位名称")) {
+            throw new NumberFormatException("缺少'应用系统管理单位名称'列!");
+        }
+        if (!r.getCell(8).getStringCellValue().equals("应用系统运维单位名称")) {
+            throw new NumberFormatException("缺少'应用系统运维单位名称'列!");
+        }
+        if (!r.getCell(9).getStringCellValue().equals("应用系统说明")) {
+            throw new NumberFormatException("缺少'应用系统说明'列!");
         }
-        return applyInfo;
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void del(String id) {
         ApplyInfo applyInfo = applyInfoMapper.selectById(id);
@@ -182,11 +173,14 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         permissionNotificationFacade.sendAppAppUpdate(id);
     }
 
+    @Cacheable(key = "targetClass + methodName")
     @Override
     public String getNewSort() {
         return applyInfoMapper.getNewSort();
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public String startOrStop(String id) {
         ApplyInfo applyInfo = applyInfoMapper.selectById(id);
@@ -208,6 +202,8 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return message;
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void sortApp(String id, String target) {
         ApplyInfo applyInfo = applyInfoMapper.selectById(id);
@@ -225,6 +221,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         applyInfoMapper.updateById(targetApplyInfo);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public String codeConvertToId(String appCode) {
 
@@ -244,6 +241,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return id;
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public String convertIdsToNames(String projectIds) {
 
@@ -262,6 +260,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return LangUtil.array2String(stringList, StrUtil.COMMA);
     }
 
+    @Cacheable(key = "targetClass +methodName+#p0")
     @Override
     public ApplyInfo getAppByCode(String appCode) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -271,11 +270,13 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public List<ApplyInfo> getAppById(List<String> ids) {
         return applyInfoMapper.selectBatchIds(ids);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public List<ApplyInfo> getAppByAppNameLike(String applyName) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -283,27 +284,126 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectList(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public ApplyInfo getAppByAppUrl(String applyUrl) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(ApplyInfo::getApplyUrl,applyUrl);
+        queryWrapper.eq(ApplyInfo::getApplyUrl, applyUrl);
         List<ApplyInfo> applyInfos = applyInfoMapper.selectList(queryWrapper);
-        if(CollectionUtils.isNotEmpty(applyInfos)){
+        if (CollectionUtils.isNotEmpty(applyInfos)) {
             return applyInfos.get(0);
-        }else{
+        } else {
             return null;
         }
 
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public List<ApplyInfo> getIdsByCodes(List<String> appCodes) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.select(ApplyInfo::getId,ApplyInfo::getApplyCode)
-                    .in(ApplyInfo::getApplyCode,appCodes);
+        queryWrapper.select(ApplyInfo::getId, ApplyInfo::getApplyCode)
+                .in(ApplyInfo::getApplyCode, appCodes);
         return applyInfoMapper.selectList(queryWrapper);
     }
 
+    @Override
+    public ApplyInfo getOne(String id) {
+        return applyInfoMapper.selectById(id);
+    }
+
+    @Override
+    public List<ApplyInfo> findAll() {
+        return applyInfoMapper.selectList(Wrappers.emptyWrapper());
+    }
+
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public ApplyInfo saveAppIy(ApplyInfoDTO applyInfoDTO) {
+        ApplyInfo applyInfo = new ApplyInfo();
+        BeanUtils.copyProperties(applyInfoDTO, applyInfo);
+
+        List<FileHolder> file = applyInfoDTO.getFile();
+
+        String manufacturerId = applyInfo.getManufacturerId();
+        if (StringUtils.isNotBlank(manufacturerId)) {
+            ManufacturerInfo manufacturerInfo = manufacturerInfoService.getOne(manufacturerId);
+            if (manufacturerInfo != null) {
+                String manufacturerName = manufacturerInfo.getManufacturerName();
+                applyInfo.setManufacturerName(manufacturerName);
+            }
+        }
+
+        String applyCode = applyInfo.getApplyCode();
+        String secretKey = applyInfoDTO.getSecretKey();
+        if (StrUtil.isBlank(secretKey)) {
+            secretKey = getApiKeys(applyCode);
+        }
+        String apiKey = applyInfoDTO.getApiKey();
+        if (StrUtil.isBlank(apiKey)) {
+            apiKey = getApiKeys(applyCode);
+        }
+
+        applyInfo.setSecretKey(secretKey);
+        applyInfo.setApiKey(apiKey);
+        applyInfo.setDeleted(BooleanEnum.FALSE.getValue());
+
+        applyInfoMapper.insert(applyInfo);
+        // 保存 appId
+        applyOauthService.saveOauth(applyInfo);
+        String id = applyInfo.getId();
+        // 保存图片
+        if (null != file) {
+            saveOrUpdateFile(id, file);
+        }
+
+        return applyInfo;
+    }
+
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public ApplyInfo updateApply(ApplyInfoDTO applyInfoDTO) {
+        ApplyInfo applyInfo = new ApplyInfo();
+        BeanUtils.copyProperties(applyInfoDTO, applyInfo);
+        List<FileHolder> file = applyInfoDTO.getFile();
+
+        String manufacturerId = applyInfo.getManufacturerId();
+        if (!StringUtils.isEmpty(manufacturerId)) {
+            ManufacturerInfo manufacturerInfo = manufacturerInfoService.getOne(manufacturerId);
+            if (manufacturerInfo != null) {
+                String manufacturerName = manufacturerInfo.getManufacturerName();
+                applyInfo.setManufacturerName(manufacturerName);
+            }
+        }
+
+        String id = applyInfo.getId();
+        //旧应用
+        ApplyInfo oldApplyInfo = applyInfoMapper.selectById(id);
+        if (null == oldApplyInfo) {
+            return null;
+        }
+        applyInfo.setDeleted(BooleanEnum.FALSE.getValue());
+        applyOauthService.updateOauth(applyInfo);
+        applyInfoMapper.updateById(applyInfo);
+
+        if (CollectionUtils.isNotEmpty(file)) {
+            saveOrUpdateFile(id, file);
+        }
+
+        //发送消息
+        //权限变更通知
+        boolean isNotification = StringUtils.isNotEmpty(oldApplyInfo.getApplyUrl()) && (!oldApplyInfo.getApplyUrl().equals(applyInfo.getApplyUrl())
+                || !oldApplyInfo.getApplyStatus().equals(applyInfo.getApplyStatus()));
+        // 应用 url 当发送变更时进行通知
+        if (isNotification) {
+            permissionNotificationFacade.sendAppAppUpdate(id);
+        }
+        return applyInfo;
+    }
+
+    @CacheEvict(allEntries = true)
     @Override
     public ResponseStatus impExcel(String fileId) {
         try {
@@ -311,34 +411,36 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
             byte[] fileData = fileContent.getFileData();
             InputStream inputStream = new ByteArrayInputStream(fileData);
             List<ApplyInfo> list = loadInfo(inputStream);
-            if(list.size() > 1000) {
-                return ResponseStatus.fail("300","导入数据超过1000行");
+            if (list.size() > 1000) {
+                return ResponseStatus.fail("300", "导入数据超过1000行");
             }
             //设置事权单位id和code
             setOrgInfos(list);
-            saveAll(list);
-        }catch (IOException e) {
-            return ResponseStatus.fail("300","导入文件类型错误");
+            for (ApplyInfo applyInfo : list) {
+                applyInfoMapper.insert(applyInfo);
+            }
+        } catch (IOException e) {
+            return ResponseStatus.fail("300", "导入文件类型错误");
         } catch (NumberFormatException e) {
-            return ResponseStatus.fail("300",e.getMessage());
+            return ResponseStatus.fail("300", e.getMessage());
         } catch (Exception e) {
-            return ResponseStatus.fail("300","导入失败");
+            return ResponseStatus.fail("300", "导入失败");
         }
         return ResponseStatus.success();
 
     }
 
     private void setOrgInfos(List<ApplyInfo> list) {
-        if(CollectionUtils.isEmpty(list)) {
+        if (CollectionUtils.isEmpty(list)) {
             return;
         }
         List<ApplyInfo> apps = list.stream()
                 .filter(item -> StringUtils.isNotBlank(item.getOrgCode()))
                 .collect(Collectors.toList());
         List<String> orgCodes = apps.stream().map(ApplyInfo::getOrgCode).collect(Collectors.toList());
-        if(CollectionUtils.isNotEmpty(orgCodes)) {
+        if (CollectionUtils.isNotEmpty(orgCodes)) {
             List<OrgInfo> orgInfos = orgInfoFacade.getOrgsByCodes(orgCodes);
-            Map<String, OrgInfo> map = orgInfos.stream().collect(Collectors.toMap(OrgInfo::getCode, item->item, (old,last)->last));
+            Map<String, OrgInfo> map = orgInfos.stream().collect(Collectors.toMap(OrgInfo::getCode, item -> item, (old, last) -> last));
             for (ApplyInfo app : apps) {
                 String orgCode = app.getOrgCode();
                 OrgInfo orgInfo = map.get(orgCode);
@@ -349,77 +451,22 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         }
     }
 
+    @Override
+    public List<ApplyInfo> appInfoSearch(SearchDTO searchDTO) {
+        return applyInfoMapper.findBySearchable(Searchable.toSearchable(searchDTO));
+    }
+
     @Override
     public List<ApplyInfo> findList(String applyStatus) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<ApplyInfo> wrapper = queryWrapper.select();
-        if(StringUtils.isNotBlank(applyStatus)){
-            wrapper.eq(ApplyInfo::getApplyStatus,applyStatus);
+        if (StringUtils.isNotBlank(applyStatus)) {
+            wrapper.eq(ApplyInfo::getApplyStatus, applyStatus);
         }
         wrapper.eq(ApplyInfo::getDeleted, BooleanEnum.FALSE.value);
         return applyInfoMapper.selectList(wrapper);
     }
 
-    @Override
-    public List<ApplyInfo> getListByCodes(List<String> appCodes) {
-        LambdaQueryWrapper<ApplyInfo> queryWrapper = new LambdaQueryWrapper<>();
-        LambdaQueryWrapper<ApplyInfo> wrapper = queryWrapper.select().in(ApplyInfo::getApplyCode,appCodes);
-        return applyInfoMapper.selectList(wrapper);
-    }
-
-    @Override
-    public List<ApplyInfo> appInfoSearch(SearchDTO searchDTO) {
-        return applyInfoMapper.findBySearchable(Searchable.toSearchable(searchDTO));
-    }
-
-    private List<ApplyInfo> loadInfo(InputStream inputStream) throws IOException, ParseException {
-        //根据指定的文件输入流导入Excel从而产生Workbook对象
-        Workbook wb0 = new HSSFWorkbook(inputStream);
-        //获取Excel文档中的第一个表单
-        Sheet sht0 = wb0.getSheetAt(0);
-        List<ApplyInfo> list = new ArrayList<>();
-        List<String> codeList = new ArrayList<>();
-        for (Row r : sht0) {
-            if (r.getRowNum() == 0) {
-                checkRowTitle(r);
-                continue;
-            }else {
-                //循环每行的每一列
-                ApplyInfo entity = new ApplyInfo();
-                boolean isAllEmpty = true;
-                for (int i = 0; i < 10; i++){
-                    Cell cell = r.getCell(i);
-                    if (cell != null){
-                        r.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
-                    }
-                    if (cell != null && StringUtils.isNotEmpty(cell.getStringCellValue())){
-                        isAllEmpty = false;
-                        break;
-                    }
-                }
-                if (!isAllEmpty){
-                    for (int i = 0; i < 10; i++) {
-                        Cell cell = r.getCell(i);
-                        if (cell != null){
-                            r.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
-                        }
-                        checkServiceResourceCellData(cell, i, r.getRowNum());
-                        checkServiceResourceCellDataValid(cell, i, r.getRowNum(), entity, codeList);
-                    }
-                    entity.setDeleted(YesNotEnum.NO.getValue());
-                    list.add(entity);
-                }
-
-
-            }
-
-        }
-
-        return list;
-    }
-
-
-
 
     @Override
     public ResponseStatus isRepeat(ApplyInfo applyInfo) {
@@ -457,6 +504,29 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return ResponseStatus.success();
     }
 
+//    @CacheEvict(allEntries = true)
+//    @Transactional(rollbackFor = Exception.class)
+//    @Override
+//    public void updateOrgInfos(String orgId, String orgName) {
+//        applyInfoMapper.updateOrgInfo(orgId, orgName);
+//    }
+//
+//    @Cacheable(key = "targetClass + methodName+#p0")
+//    @Override
+//    public List<String> getAppIdsByOrgId(String orgId) {
+//
+//        LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
+//
+//        queryWrapper.eq(ApplyInfo::getOrgId, orgId)
+//                .eq(ApplyInfo::getDeleted, BooleanEnum.FALSE.getValue());
+//
+//        List<ApplyInfo> applyInfos = applyInfoMapper.selectList(queryWrapper);
+//
+//        return applyInfos.stream().map(ApplyInfo::getId)
+//                .collect(Collectors.toList());
+//    }
+
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public List<ApplyInfo> fzxmList(String userId) {
 
@@ -468,6 +538,8 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectList(queryWrapper);
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void saveDutyMan(String dutyProject, String userId, String mobileWork) {
         Object[] projectIdArray = dutyProject.split(StrUtil.COMMA);
@@ -480,6 +552,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         applyInfoMapper.update(new ApplyInfo(), updateWrapper);
     }
 
+    @Cacheable(key = "targetClass + methodName")
     @Override
     public Map<String, String> findAppNameMap() {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -494,15 +567,16 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return stringStringMap;
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public Page<ApplyInfo> findApplyList(SearchDTO searchDTO) {
-        // todo 逻辑
         Searchable searchable = Searchable.toSearchable(searchDTO);
         searchable.removeSearchFilter("userBusiness_eq");
         searchable.addSort(Sort.Direction.DESC, "sort");
         return applyInfoMapper.pagingBySearchable(searchable);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public Integer countByManufacturerId(String manufacturerId) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -512,6 +586,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectCount(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public List<ApplyInfo> getAppListByManufacturerId(String manufacturerId) {
 
@@ -522,6 +597,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectList(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass + methodName")
     @Override
     public Map<String, String> getAllIdNameMap() {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -533,6 +609,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
                 .collect(Collectors.toMap(ApplyInfo::getId, ApplyInfo::getApplyName));
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0+#p1")
     @Override
     public ApplyInfo getOneByCodeAndName(String appCode, String appName) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -541,6 +618,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0 +#p1")
     @Override
     public ApplyInfo getOneByNameAndManufacturerId(String applyName, String manufacturerId) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -550,6 +628,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass + methodName+#p0")
     @Override
     public ApplyInfo getOneByName(String applyName) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -580,6 +659,9 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
      * @param fileHolderList 文件
      */
     private void saveOrUpdateFile(String busiId, List<FileHolder> fileHolderList) {
+        if (CollectionUtil.isEmpty(fileHolderList)) {
+            return;
+        }
         FileHolder[] fileHolders = fileHolderList.toArray(new FileHolder[]{});
 
         String busiType = "";
@@ -587,9 +669,62 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         uploadHandler.saveOrUpdate(fileUploadDTO);
     }
 
+    @Override
+    public List<ApplyInfo> getListByCodes(List<String> appCodes) {
+        LambdaQueryWrapper<ApplyInfo> queryWrapper = new LambdaQueryWrapper<>();
+        LambdaQueryWrapper<ApplyInfo> wrapper = queryWrapper.select().in(ApplyInfo::getApplyCode, appCodes);
+        return applyInfoMapper.selectList(wrapper);
+    }
+
+    private List<ApplyInfo> loadInfo(InputStream inputStream) throws IOException, ParseException {
+        //根据指定的文件输入流导入Excel从而产生Workbook对象
+        Workbook wb0 = new HSSFWorkbook(inputStream);
+        //获取Excel文档中的第一个表单
+        Sheet sht0 = wb0.getSheetAt(0);
+        List<ApplyInfo> list = new ArrayList<>();
+        List<String> codeList = new ArrayList<>();
+        for (Row r : sht0) {
+            if (r.getRowNum() == 0) {
+                checkRowTitle(r);
+                continue;
+            } else {
+                //循环每行的每一列
+                ApplyInfo entity = new ApplyInfo();
+                boolean isAllEmpty = true;
+                for (int i = 0; i < 10; i++) {
+                    Cell cell = r.getCell(i);
+                    if (cell != null) {
+                        r.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
+                    }
+                    if (cell != null && StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                        isAllEmpty = false;
+                        break;
+                    }
+                }
+                if (!isAllEmpty) {
+                    for (int i = 0; i < 10; i++) {
+                        Cell cell = r.getCell(i);
+                        if (cell != null) {
+                            r.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
+                        }
+                        checkServiceResourceCellData(cell, i, r.getRowNum());
+                        checkServiceResourceCellDataValid(cell, i, r.getRowNum(), entity, codeList);
+                    }
+                    entity.setDeleted(YesNotEnum.NO.getValue());
+                    list.add(entity);
+                }
+
+
+            }
+
+        }
+
+        return list;
+    }
 
     /**
      * 校验参数和设置参数
+     *
      * @param cell
      * @param num
      * @param row
@@ -609,10 +744,10 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
                 break;
             case 1:
                 ApplyInfo applyInfo = getAppByCode(value);
-                if (applyInfo != null){
+                if (applyInfo != null) {
                     throw new NumberFormatException("第" + (row + 1) + "行'应用系统编号'已存在!");
                 }
-                if (codeList.contains(value)){
+                if (codeList.contains(value)) {
                     throw new NumberFormatException("第" + (row + 1) + "行'应用系统编号'重复!");
                 }
                 codeList.add(value);
@@ -626,13 +761,13 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
                 break;
             case 3:
                 String activeCode = null;
-                if (value.equals("停用")){
+                if (value.equals("停用")) {
                     activeCode = "1";
                 }
-                if (value.equals("启用")){
+                if (value.equals("启用")) {
                     activeCode = "0";
                 }
-                if (StringUtils.isEmpty(activeCode)){
+                if (StringUtils.isEmpty(activeCode)) {
                     throw new NumberFormatException("第" + (row + 1) + "行'系统在用标识'不存在!");
                 }
                 resource.setApplyStatus(activeCode);
@@ -640,7 +775,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
                 break;
             case 4:
 
-                if (StringUtils.isNotEmpty(value)){
+                if (StringUtils.isNotEmpty(value)) {
                     try {
                         SimpleDateFormat importFormat = new SimpleDateFormat("yyyyMMdd");
                         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -687,66 +822,4 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
 
         }
     }
-
-    /**
-     * 校验数据是否为空
-     * @param cell
-     * @param i
-     * @param row
-     */
-    private static void checkServiceResourceCellData(Cell cell, int i, int row) {
-        if (!(cell == null || StringUtils.isEmpty(cell.getStringCellValue()))) {
-            return;
-        }
-        switch (i) {
-            case 0:
-                throw new NumberFormatException("第" + (row + 1) + "行'应用系统名称'为空!");
-            case 1:
-                throw new NumberFormatException("第" + (row + 1) + "行'应用系统编号'为空!");
-            case 2:
-                throw new NumberFormatException("第" + (row + 1) + "行'应用系统英文名称'为空!");
-            case 3:
-                throw new NumberFormatException("第" + (row + 1) + "行'系统在用标识'为空!");
-            default:
-                break;
-        }
-
-    }
-
-    /**
-     * 校验列头
-     * @param r
-     */
-    private static void checkRowTitle(Row r) {
-        if (!r.getCell(0).getStringCellValue().equals("应用系统名称")) {
-            throw new NumberFormatException("缺少'应用系统名称'列!");
-        }
-        if (!r.getCell(1).getStringCellValue().equals("应用系统编号")) {
-            throw new NumberFormatException("缺少'应用系统编号'列!");
-        }
-        if (!r.getCell(2).getStringCellValue().equals("应用系统英文名称")) {
-            throw new NumberFormatException("缺少'应用系统英文名称'列!");
-        }
-        if (!r.getCell(3).getStringCellValue().equals("系统在用标识")) {
-            throw new NumberFormatException("缺少'系统在用标识'列!");
-        }
-        if (!r.getCell(4).getStringCellValue().equals("上线日期")) {
-            throw new NumberFormatException("缺少'上线日期'列!");
-        }
-        if (!r.getCell(5).getStringCellValue().equals("应用负责人")) {
-            throw new NumberFormatException("缺少'应用负责人'列!");
-        }
-        if (!r.getCell(6).getStringCellValue().equals("应用系统事权单位代码")) {
-            throw new NumberFormatException("缺少'应用系统事权单位代码'列!");
-        }
-        if (!r.getCell(7).getStringCellValue().equals("应用系统管理单位名称")) {
-            throw new NumberFormatException("缺少'应用系统管理单位名称'列!");
-        }
-        if (!r.getCell(8).getStringCellValue().equals("应用系统运维单位名称")) {
-            throw new NumberFormatException("缺少'应用系统运维单位名称'列!");
-        }
-        if (!r.getCell(9).getStringCellValue().equals("应用系统说明")) {
-            throw new NumberFormatException("缺少'应用系统说明'列!");
-        }
-    }
 }

+ 8 - 0
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ApplyOauthServiceImpl.java

@@ -70,4 +70,12 @@ public class ApplyOauthServiceImpl extends BaseMybatisService<ApplyOauth, String
     public List<ApplyOauth> applyOauthList(Map<String, Object> map) {
         return applyOauthMapper.selectByMap(map);
     }
+
+    @Override
+    public ApplyOauth getByAppId(String applyId) {
+        LambdaQueryWrapper<ApplyOauth> queryWrapper = new LambdaQueryWrapper<>();
+        LambdaQueryWrapper<ApplyOauth> wrapper = queryWrapper.select()
+                .eq(ApplyOauth::getApplyId, applyId);
+        return applyOauthMapper.selectOne(wrapper);
+    }
 }

+ 19 - 5
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ManufacturerInfoServiceImpl.java

@@ -2,18 +2,18 @@ package com.dragoninfo.dcuc.app.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.dragoninfo.dcuc.app.dto.ManufacturerEventDTO;
 import com.dragoninfo.dcuc.app.entity.ManufacturerInfo;
-import com.dragoninfo.dcuc.app.enumresources.ManufacturerMsgTypeEnum;
 import com.dragoninfo.dcuc.app.mapper.ManufacturerInfoMapper;
 import com.dragoninfo.dcuc.app.service.IManufacturerInfoService;
 import com.dragonsoft.duceap.base.entity.metadata.CodeRecord;
 import com.dragonsoft.duceap.base.entity.search.SearchDTO;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
-import com.dragonsoft.duceap.core.context.ContextUtils;
 import com.dragonsoft.duceap.core.search.Searchable;
 import com.dragonsoft.duceap.core.search.enums.SearchOperator;
 import com.dragonsoft.duceap.mybaitsplus.core.services.BaseMybatisService;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -26,7 +26,7 @@ import java.util.stream.Collectors;
  * @author huangzqa
  * @date 2020/10/26
  */
-@Transactional(rollbackFor = Exception.class)
+@CacheConfig(cacheNames = "DCUC-APP-MANU")
 @Service
 public class ManufacturerInfoServiceImpl extends BaseMybatisService<ManufacturerInfo, String> implements IManufacturerInfoService {
 
@@ -38,6 +38,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         this.manufacturerInfoMapper = manufacturerInfoMapper;
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public Page<ManufacturerInfo> manufacturerInfoPage(SearchDTO searchDTO) {
         Searchable searchable = Searchable.toSearchable(searchDTO);
@@ -45,11 +46,14 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.pagingBySearchable(searchable);
     }
 
+    @Cacheable(key = "targetClass +#p0")
     @Override
     public ManufacturerInfo manufacturerInfoDetail(String id) {
         return manufacturerInfoMapper.selectById(id);
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public ManufacturerInfo saveManufacturer(ManufacturerInfo info) {
         info.setDeleted(BooleanEnum.FALSE.getValue());
@@ -57,12 +61,16 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return info;
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public ManufacturerInfo updateManufacturer(ManufacturerInfo info) {
         manufacturerInfoMapper.updateById(info);
         return info;
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void del(String id) {
         ManufacturerInfo manufacturerInfo = manufacturerInfoMapper.selectById(id);
@@ -71,6 +79,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         manufacturerInfoMapper.deleteById(manufacturerInfo);
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public ManufacturerInfo detailByCode(String code) {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -80,6 +89,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public ManufacturerInfo getOneByName(String manufacturerName) {
 
@@ -90,6 +100,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0+p1")
     @Override
     public ManufacturerInfo getOneByCodeName(String code, String manufacturerName) {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -98,6 +109,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass +methodName")
     @Override
     public List<CodeRecord> getAllCodeRecord() {
 
@@ -119,6 +131,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
                 .collect(Collectors.toList());
     }
 
+    @Cacheable(key = "targetClass +methodName")
     @Override
     public Map<String, String> getAllIdNameMap() {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -130,11 +143,12 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
                 .collect(Collectors.toMap(ManufacturerInfo::getId, ManufacturerInfo::getManufacturerName));
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public List<ManufacturerInfo> getByCodes(List<String> list) {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.select()
-                    .in(ManufacturerInfo::getCode);
+                .in(ManufacturerInfo::getCode);
         return manufacturerInfoMapper.selectList(queryWrapper);
     }
 

+ 25 - 9
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ResourceServiceImpl.java

@@ -3,6 +3,7 @@ package com.dragoninfo.dcuc.app.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.TypeReference;
 import com.dragoninfo.dcuc.app.config.DcucResourceConfig;
 import com.dragoninfo.dcuc.app.cons.ServiceStatusCons;
 import com.dragoninfo.dcuc.app.dto.*;
@@ -16,8 +17,8 @@ import com.dragoninfo.dcuc.app.service.IResourceService;
 import com.dragoninfo.dcuc.app.strategy.ResourceOperateStrategy;
 import com.dragoninfo.dcuc.auth.auth.entity.AppFunInfo;
 import com.dragoninfo.dcuc.auth.power.facade.IAppFunInfoFacade;
-import com.dragoninfo.dcuc.org.entity.OrgInfo;
-import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade;
+import com.dragoninfo.dcuc.user.entity.org.OrgInfo;
+import com.dragoninfo.dcuc.user.facade.org.IOrgInfoFacade;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.base.exception.ApplicationException;
 import com.dragonsoft.duceap.core.entity.page.PageImpl;
@@ -302,18 +303,22 @@ public class ResourceServiceImpl extends BaseMybatisService<ServiceResource,Stri
      * @return
      */
     private List<MenuResourceDTO> getMenuResourceDTOs(ResourceSync resourceSync) {
-        List<MenuResourceDTO> list = new ArrayList<>();
+        String appCode = resourceSync.getAppCode();
         String content = resourceSync.getContent();
-        JSONArray array = JSON.parseArray(content);
-        for (int i = 0; i < array.size(); i++) {
-            String menuStr = array.getJSONObject(i).toJSONString();
+        List<MenuResourceAcceptDTO> acceptDTOS = JSON.parseObject(content, new TypeReference<List<MenuResourceAcceptDTO>>() {{
+        }});
+        return convertToMenuDTOs(appCode, acceptDTOS);
+    }
+
+    public static List<MenuResourceDTO> convertToMenuDTOs(String appCode, List<MenuResourceAcceptDTO> acceptDTOS) {
+        List<MenuResourceDTO> list = new ArrayList<>();
+        for (MenuResourceAcceptDTO acceptDTO : acceptDTOS) {
             MenuResourceDTO dto = new MenuResourceDTO();
-            MenuResourceAcceptDTO acceptDTO = JSON.parseObject(menuStr, MenuResourceAcceptDTO.class);
             dto.setFunCode(acceptDTO.getGnbh());
             dto.setPFunCode(acceptDTO.getSjgnbh());
             dto.setFunName(acceptDTO.getGnmc());
             dto.setStatus(acceptDTO.getZyzt());
-            dto.setAppCode(resourceSync.getAppCode());
+            dto.setAppCode(appCode);
             list.add(dto);
         }
         return list;
@@ -357,6 +362,11 @@ public class ResourceServiceImpl extends BaseMybatisService<ServiceResource,Stri
     private ServiceResourceDTO getServiceResourceDTO(ResourceSync resourceSync) {
         String content = resourceSync.getContent();
         ServiceResourceAcceptDTO acceptDTO = JSON.parseObject(content,ServiceResourceAcceptDTO.class);
+        ServiceResourceDTO dto = convertToServiceDTO(acceptDTO);
+        return dto;
+    }
+
+    public static ServiceResourceDTO convertToServiceDTO(ServiceResourceAcceptDTO acceptDTO) {
         ServiceResourceDTO dto = new ServiceResourceDTO();
         ResourceTypeEnum resourceEnum = ResourceTypeEnum.TJ_SERVICE;
         dto.setResourceId(resourceEnum.getResourceId());
@@ -384,9 +394,14 @@ public class ResourceServiceImpl extends BaseMybatisService<ServiceResource,Stri
      */
     private AppResourceDTO getAppResourceDTO(ResourceSync resourceSync) {
         String content = resourceSync.getContent();
-        AppResourceDTO dto = new AppResourceDTO();
         AppInfoAcceptDTO acceptDTO = JSON.parseObject(content, AppInfoAcceptDTO.class);
+        AppResourceDTO dto = convertToAppDTO(acceptDTO);
+        return dto;
+    }
+
+    public static AppResourceDTO convertToAppDTO(AppInfoAcceptDTO acceptDTO) {
         ResourceTypeEnum resourceEnum = ResourceTypeEnum.TJ_APP;
+        AppResourceDTO dto = new AppResourceDTO();
         dto.setResourceId(resourceEnum.getResourceId());
         dto.setResourceType(resourceEnum.getResourceType());
         dto.setResourceProvider(resourceEnum.getResourceProvider());
@@ -422,6 +437,7 @@ public class ResourceServiceImpl extends BaseMybatisService<ServiceResource,Stri
         }
         dto.setApplyCategory(acceptDTO.getYyxtfldm());
         dto.setPoliceSpecies(acceptDTO.getGajzfldm());
+        dto.setAppSecret(acceptDTO.getAppsecret());
         return dto;
     }
 

+ 7 - 4
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ServiceResourceServiceImpl.java

@@ -16,8 +16,7 @@ import com.dragoninfo.dcuc.duceap.enums.ServiceProvideWayEnum;
 import com.dragoninfo.dcuc.duceap.enums.ServiceResourceTypeEnum;
 import com.dragoninfo.dcuc.duceap.facade.IDuceapUploadFacade;
 import com.dragoninfo.dcuc.duceap.upload.dto.DocContentDTO;
-import com.dragoninfo.dcuc.org.entity.OrgInfo;
-import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade;
+import com.dragoninfo.dcuc.user.facade.org.IOrgInfoFacade;
 import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
 import com.dragonsoft.duceap.commons.util.string.StringUtils;
@@ -42,7 +41,10 @@ import javax.annotation.Resource;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -319,8 +321,9 @@ public class ServiceResourceServiceImpl extends BaseMybatisService<ServiceResour
      * @param resource
      */
     private void checkServiceResourceCellDataValid(Cell cell, int num, int row, ServiceResource resource, List<String> codeList) {
-        if (cell == null)
+        if (cell == null) {
             return;
+        }
         String value = cell.getStringCellValue();
         switch (num) {
             case 0:

+ 48 - 15
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/strategy/AppResourceStrategy.java

@@ -3,12 +3,14 @@ package com.dragoninfo.dcuc.app.strategy;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.dragoninfo.dcuc.app.dto.AppResourceDTO;
-import com.dragoninfo.dcuc.app.dto.ResourceDTO;
+import com.dragoninfo.dcuc.app.dto.ApplyInfoDTO;
 import com.dragoninfo.dcuc.app.entity.ApplyInfo;
+import com.dragoninfo.dcuc.app.entity.ApplyOauth;
 import com.dragoninfo.dcuc.app.enumresources.ResourceTypeEnum;
 import com.dragoninfo.dcuc.app.service.IApplyInfoService;
 import com.dragoninfo.dcuc.app.service.IApplyOauthService;
 import com.dragonsoft.duceap.base.enums.BooleanEnum;
+import com.dragonsoft.duceap.commons.util.string.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -18,7 +20,7 @@ import org.springframework.stereotype.Component;
  * @create 2020-11-25 14:21
  */
 @Component
-public class AppResourceStrategy implements ResourceOperateStrategy<AppResourceDTO,ApplyInfo> {
+public class AppResourceStrategy implements ResourceOperateStrategy<AppResourceDTO, ApplyInfo> {
 
     @Autowired
     private IApplyInfoService applyInfoService;
@@ -31,7 +33,7 @@ public class AppResourceStrategy implements ResourceOperateStrategy<AppResourceD
         ApplyInfo applyInfo;
         ApplyInfo exist = applyInfoService.getAppByCode(appResourceDTO.getAppCode());
         if (null == exist) {
-            applyInfo = inserApplyInfo(appResourceDTO);
+            applyInfo = insertApplyInfo(appResourceDTO);
         } else {
             applyInfo = updateApplyInfo(exist, appResourceDTO);
         }
@@ -43,32 +45,61 @@ public class AppResourceStrategy implements ResourceOperateStrategy<AppResourceD
         return ResourceTypeEnum.TJ_APP.getResourceId().equals(resourceType);
     }
 
-    private ApplyInfo inserApplyInfo(AppResourceDTO dto) {
+    private ApplyInfo insertApplyInfo(AppResourceDTO dto) {
         ApplyInfo applyInfo = convertToApplyInfo(dto);
         //删除的应用,不插入数据库
-        if(BooleanEnum.TRUE.getValue().equals(dto.getDeleted())){
+        if (BooleanEnum.TRUE.getValue().equals(dto.getDeleted())) {
             return applyInfo;
         }
-        String secretKey = getApiKeys(applyInfo.getApplyCode());
-        String apiKey = getApiKeys(applyInfo.getApplyCode());
-        applyInfo.setSecretKey(secretKey);
-        applyInfo.setApiKey(apiKey);
-        applyInfoService.save(applyInfo);
-        applyOauthService.saveOauth(applyInfo);
+        String appSecret = dto.getAppSecret();
+        if (StringUtils.isNotBlank(appSecret)) {
+            insertAppOauth(applyInfo, appSecret);
+        }
+        ApplyInfoDTO applyInfoDTO = new ApplyInfoDTO();
+        BeanUtil.copyProperties(applyInfo, applyInfoDTO);
+        applyInfoService.saveAppIy(applyInfoDTO);
         return applyInfo;
     }
 
     private ApplyInfo updateApplyInfo(ApplyInfo applyInfo, AppResourceDTO dto) {
+        //是需要删除的应用
+        if (BooleanEnum.TRUE.getValue().equals(dto.getDeleted())) {
+            applyInfoService.del(applyInfo.getId());
+            return applyInfo;
+        }
         ApplyInfo infoNew = convertToApplyInfo(dto);
         BeanUtil.copyProperties(infoNew, applyInfo, "id", "apiKey", "secretKey");
-        applyInfoService.update(applyInfo);
-        //删除的应用
-        if(BooleanEnum.TRUE.getValue().equals(dto.getDeleted())){
-            applyInfoService.deleteById(applyInfo.getId());
+        //更新Secret
+        String appSecret = dto.getAppSecret();
+        ApplyOauth auth = applyOauthService.getByAppId(applyInfo.getId());
+        if (null == auth && StringUtils.isNotBlank(appSecret)) {
+            insertAppOauth(applyInfo, appSecret);
+        } else if (null != auth && StringUtils.isNotBlank(appSecret)) {
+            String secretKey = auth.getSecretKey();
+            if (!appSecret.equals(secretKey)) {
+                updateAppOauth(applyInfo, appSecret);
+            }
+        } else if (null != auth && StringUtils.isBlank(appSecret)) {
+            applyOauthService.deleteById(auth.getId());
         }
+        ApplyInfoDTO applyInfoDTO = new ApplyInfoDTO();
+        BeanUtil.copyProperties(applyInfo, applyInfoDTO);
+        applyInfoService.updateApply(applyInfoDTO);
         return applyInfo;
     }
 
+    private void updateAppOauth(ApplyInfo applyInfo, String appSecret) {
+        applyInfo.setSecretKey(appSecret);
+        applyInfo.setApiKey(appSecret);
+        applyOauthService.updateOauth(applyInfo);
+    }
+
+    private void insertAppOauth(ApplyInfo applyInfo, String appSecret) {
+        applyInfo.setSecretKey(appSecret);
+        applyInfo.setApiKey(appSecret);
+        applyOauthService.saveOauth(applyInfo);
+    }
+
 
     private ApplyInfo convertToApplyInfo(AppResourceDTO dto) {
         String appCode = dto.getAppCode();
@@ -88,6 +119,8 @@ public class AppResourceStrategy implements ResourceOperateStrategy<AppResourceD
         applyInfo.setPoliceSpecies(dto.getPoliceSpecies());
         applyInfo.setRegistrationTime(dto.getRegistrationTime());
         applyInfo.setApplyStatus(dto.getAppStatus());
+        applyInfo.setSecretKey(dto.getAppSecret());
+        applyInfo.setApiKey(dto.getAppSecret());
         applyInfo.setAppOpsDepName(dto.getAppOpsDepName());
         applyInfo.setOrgCode(dto.getBuildUnitCode());
         applyInfo.setLineTime(dto.getLineTime());

+ 31 - 5
dcuc-app-service/src/main/resources/application-base.yml

@@ -1,13 +1,14 @@
 spring:
-  profiles:
-    active: default
   datasource:
     username: dcuc
     password: 123
     driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://10.254.10.31:3306/dcuc_tjdsj_2.0?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
+    url: jdbc:mysql://10.254.10.31:3306/dcuc_tjdsj_2.0?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
     druid:
-      filters: sqlaudit
+      filters: stat,sqlaudit
+      max-active: 60
+      initial-size: 20
+      min-idle: 20
   application:
     name: dcuc-app
   cloud:
@@ -20,6 +21,24 @@ spring:
       # 设置文件上传大小,springboot默认的最大上传大小是1MB
       max-file-size: 150MB
       max-request-size: 150MB
+  redis:
+    host: 10.254.10.15
+    port: 6379
+    password:
+    jedis:
+      pool:
+        max-active: 500
+  cache:
+    # 缓存类型,默认根据环境自动检测,ehcache、redis、simple、caffeine、jcache、infinispan、Hazeleast、none
+    type: redis
+    # 如果底层缓存管理器支持缓存名的话,可以在这里指定要创建的缓存名列表,用逗号分 隔。通常这会禁用运行时创建其他额外缓存的能力。
+    cache-names: DCUC-APP-APP,DCUC-APP-MANU
+    # 缓存连接超时时间
+    #多cacheManager支持 CacheManager(ex:ehCacheCacheManager,simpleCacheManager,redisCacheManager,caffeineCacheManager)
+    init-cache-managers: redisCacheManager
+    redis-time-live:
+      DCUC-APP-APP: 1800000
+      DCUC-APP-MANU: 1800000
   kafka:
     producer:
       bootstrap-servers: 192.168.10.20:9093
@@ -61,7 +80,14 @@ duceap:
     locations: classpath:/config/mysql
   mybatis-plus:
     map-camel-case-to-underscore: true
-
+  auditlog:
+    login:
+      enabled: false
+    audit:
+      enabled: false
+    sqlaudit:
+      output: kafka
+      exclude-tables: T_LOG_*
   license:
     enabled: false
     #配置用来指定license对接的后端项目地址(格式:ip:port/context,如http://10.10.10.10:8080/ctx),

+ 0 - 6
dcuc-app-service/src/main/resources/application-oracle.yml

@@ -1,6 +0,0 @@
-spring:
-  datasource:
-    username: DCUC2_GD
-    password: dragon
-    driver-class-name: oracle.jdbc.OracleDriver
-    url: jdbc:oracle:thin:@192.168.6.122:1521:orcl

+ 14 - 9
dcuc-app-service/src/main/resources/config/mysql/V4_1_0007__app_del_orgid.sql

@@ -1,10 +1,15 @@
-ALTER TABLE T_APPLY_INFO DROP COLUMN ORG_ID;
-ALTER TABLE T_APPLY_INFO DROP COLUMN MANAGER_ORG_ID;
-ALTER TABLE T_SERVICE_RESOURCE DROP COLUMN BUILD_UNIT_ID;
-ALTER TABLE T_SERVICE_RESOURCE DROP COLUMN MANAGER_UNIT_ID;
-ALTER TABLE T_SERVICE_RESOURCE DROP COLUMN CONTRACT_UNIT_ID;
-
 -- 历史数据处理
--- UPDATE t_apply_info a
--- JOIN t_org_info o ON a.org_id = o.id
--- SET a.org_code = o. CODE;
+UPDATE t_apply_info a
+    JOIN t_org_info o ON a.org_id = o.id
+SET a.org_code = o.CODE;
+
+ALTER TABLE T_APPLY_INFO
+    DROP COLUMN ORG_ID;
+ALTER TABLE T_APPLY_INFO
+    DROP COLUMN MANAGER_ORG_ID;
+ALTER TABLE T_SERVICE_RESOURCE
+    DROP COLUMN BUILD_UNIT_ID;
+ALTER TABLE T_SERVICE_RESOURCE
+    DROP COLUMN MANAGER_UNIT_ID;
+ALTER TABLE T_SERVICE_RESOURCE
+    DROP COLUMN CONTRACT_UNIT_ID;