Browse Source

Merge remote-tracking branch 'origin/dev_screen_data_2.0' into dev_temp

dev_shibei_match
zxc 5 years ago
parent
commit
d76e9d0224
  1. 23
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java
  2. 22
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/form/TreeByTypeFormDTO.java
  3. 5
      epmet-module/data-report/data-report-server/pom.xml
  4. 2
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/constant/FactConstant.java
  5. 27
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/backdoor/BackDoorController.java
  6. 4
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/screen/AgencyController.java
  7. 13
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/backdoor/BackDoorService.java
  8. 49
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/backdoor/impl/BackDoorServiceImpl.java
  9. 11
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/AgencyService.java
  10. 6
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java
  11. 15
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerAgencyEntity.java
  12. 13
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerAgencyServiceImpl.java
  13. 13
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/GetJwtAccessTokenFormDTO.java
  14. 32
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/AppIdInfoResultDTO.java
  15. 16
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/GetJwtAccessTokenResultDTO.java
  16. 18
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java
  17. 6
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java
  18. 27
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java
  19. 9
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java
  20. 6
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java
  21. 28
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java
  22. 36
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/utils/externalapp/ExtAppJwtTokenUtils.java
  23. 14
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml

23
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java

@ -159,6 +159,29 @@ public class HttpClientManager {
}
public Result<String> sendPostByJSONAndHeader(String url, String jsonStrParam,Map<String,String> headerMap) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
if (null != headerMap){
headerMap.forEach((k,v) -> {
httppost.addHeader(k,v);
});
}
if (StringUtils.isNotEmpty(jsonStrParam)) {
StringEntity se = new StringEntity(jsonStrParam, "utf-8");
httppost.setEntity(se);
}
return execute(httppost, false);
} catch (Exception e) {
log.error("send exception", e);
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
/**
* 上传临时素材
* @author zhaoqifeng

22
epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/form/TreeByTypeFormDTO.java

@ -0,0 +1,22 @@
package com.epmet.evaluationindex.screen.dto.form;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2020/10/22 10:52 上午
*/
@Data
public class TreeByTypeFormDTO implements Serializable {
private static final long serialVersionUID = -1438758394814978472L;
public interface TreeByType extends CustomerClientShowGroup{}
@NotBlank(message = "bizType不能为空",groups = TreeByType.class)
private String bizType;
}

5
epmet-module/data-report/data-report-server/pom.xml

@ -28,6 +28,11 @@
<artifactId>epmet-user-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>common-service-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

2
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/constant/FactConstant.java

@ -61,4 +61,6 @@ public interface FactConstant {
* 评价指标类型-百分比
*/
String PERCENT = "percent";
String URL = "https://epmet-dev.elinkservice.cn/api/";
}

27
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/backdoor/BackDoorController.java

@ -0,0 +1,27 @@
package com.epmet.datareport.controller.backdoor;
import com.epmet.commons.tools.utils.Result;
import com.epmet.datareport.service.backdoor.BackDoorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author zxc
* @DateTime 2020/10/21 5:17 下午
*/
@RestController
@RequestMapping("backdoor")
public class BackDoorController {
@Autowired
private BackDoorService backDoorService;
@PostMapping("backdoor")
public Result backDoor(@RequestHeader("Data-Type")String dataType, @RequestHeader("AppId")String appId, @RequestHeader("target")String target){
return new Result().ok(backDoorService.backDoor(dataType,appId,target));
}
}

4
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/screen/AgencyController.java

@ -4,6 +4,7 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.datareport.service.evaluationindex.screen.AgencyService;
import com.epmet.evaluationindex.screen.dto.form.CompartmentFormDTO;
import com.epmet.evaluationindex.screen.dto.form.TreeByTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.result.CompartmentResultDTO;
import com.epmet.evaluationindex.screen.dto.result.TreeResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
@ -41,7 +42,8 @@ public class AgencyController {
* @date 2020/10/21 2:49 下午
*/
@PostMapping("treebytype")
public Result<TreeResultDTO> treeByType(@RequestHeader("CustomerId") String customerId,@RequestParam("bizType")String bizType){
public Result<TreeResultDTO> treeByType(@RequestHeader("CustomerId") String customerId,@RequestBody TreeByTypeFormDTO bizType){
ValidatorUtils.validateEntity(bizType, TreeByTypeFormDTO.TreeByType.class);
return new Result<TreeResultDTO>().ok(agencyService.treeByType(customerId,bizType));
}

13
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/backdoor/BackDoorService.java

@ -0,0 +1,13 @@
package com.epmet.datareport.service.backdoor;
import com.epmet.commons.tools.utils.Result;
/**
* @Author zxc
* @DateTime 2020/10/21 5:17 下午
*/
public interface BackDoorService {
Object backDoor(String dataType, String appId, String target);
}

49
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/backdoor/impl/BackDoorServiceImpl.java

@ -0,0 +1,49 @@
package com.epmet.datareport.service.backdoor.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.commons.tools.utils.Result;
import com.epmet.datareport.constant.*;
import com.epmet.datareport.service.backdoor.BackDoorService;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @Author zxc
* @DateTime 2020/10/21 5:17 下午
*/
@Service
public class BackDoorServiceImpl implements BackDoorService {
@Autowired
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@Override
public Object backDoor(String dataType, String appId, String target) {
Result<AppIdInfoResultDTO> appIdInfoResultDTOResult = commonServiceOpenFeignClient.appIdInfo(appId);
if (!appIdInfoResultDTOResult.success()){
throw new RenException("获取accessToken失败......");
}
AppIdInfoResultDTO data = appIdInfoResultDTOResult.getData();
String url = FactConstant.URL.concat(target);
Map map = new HashMap(16);
Map<String,String> headerMap = new HashMap<>(16);
headerMap.put("AccessToken",data.getAccessToken());
headerMap.put("AppId",data.getAppId());
headerMap.put("AuthType","jwt");
headerMap.put("Data-Type",dataType);
// headerMap.put("Authorization","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJhcHAiOiJnb3YiLCJjbGllbnQiOiJ3eG1wIiwiZXhwIjoxNjAzODY2MjY2LCJ1c2VySWQiOiI0ZWYwYTA4YTBiNWVmOTM0ZjBiOGE4YzQ2ODJjMzY2NSIsImlhdCI6MTYwMzI2MTQ2Nn0.pW1Wzss-xtj6vUuJbvglUltdDWlUKqTyVQ6rGQ7WpSaE_Iz1uAd5XWI5OGLajyU4-aYCW14Dw3C-XoFepyiZJQ");
map.put("bizType","community");
Result<String> stringResult = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(map),headerMap);
JSONObject jsonObject = JSON.parseObject(stringResult.getData());
System.out.println(jsonObject);
return jsonObject;
}
}

11
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/AgencyService.java

@ -1,6 +1,7 @@
package com.epmet.datareport.service.evaluationindex.screen;
import com.epmet.evaluationindex.screen.dto.form.CompartmentFormDTO;
import com.epmet.evaluationindex.screen.dto.form.TreeByTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.result.CompartmentResultDTO;
import com.epmet.evaluationindex.screen.dto.result.TreeResultDTO;
@ -20,14 +21,8 @@ public interface AgencyService {
*/
TreeResultDTO tree(String customerId);
/**
* @Description 智慧社区的tree
* @Param customerId
* @Param bizType
* @author zxc
* @date 2020/10/21 2:49 下午
*/
TreeResultDTO treeByType(String customerId,String bizType);
TreeResultDTO treeByType(String customerId, TreeByTypeFormDTO bizType);
/**
* @Description 2组织区域查询

6
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java

@ -9,6 +9,7 @@ import com.epmet.datareport.dao.evaluationindex.screen.ScreenCustomerGridDao;
import com.epmet.datareport.service.evaluationindex.screen.AgencyService;
import com.epmet.evaluationindex.screen.constant.ScreenConstant;
import com.epmet.evaluationindex.screen.dto.form.CompartmentFormDTO;
import com.epmet.evaluationindex.screen.dto.form.TreeByTypeFormDTO;
import com.epmet.evaluationindex.screen.dto.result.AgencyDistributionResultDTO;
import com.epmet.evaluationindex.screen.dto.result.CompartmentResultDTO;
import com.epmet.evaluationindex.screen.dto.result.TreeResultDTO;
@ -73,11 +74,12 @@ public class AgencyServiceImpl implements AgencyService {
* @author zxc
* @date 2020/10/21 2:49 下午
*/
@DataSource(value = DataSourceConstant.EVALUATION_INDEX, datasourceNameFromArg = true)
@Override
public TreeResultDTO treeByType(String customerId, String bizType) {
public TreeResultDTO treeByType(String customerId, TreeByTypeFormDTO bizType) {
TreeResultDTO rootAgency = null;
try {
rootAgency = screenCustomerAgencyDao.selectRootAgencyIdByBizType(customerId,bizType);
rootAgency = screenCustomerAgencyDao.selectRootAgencyIdByBizType(customerId,bizType.getBizType());
if (null == rootAgency) {
return new TreeResultDTO();
}

15
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/screen/ScreenCustomerAgencyEntity.java

@ -89,15 +89,20 @@ public class ScreenCustomerAgencyEntity extends BaseEpmetEntity {
private String level;
/**
* 行政地区编码
*/
* 行政地区编码
*/
private String areaCode;
private String sourceType;
/**
* 数据更新至: yyyy|yyyyMM|yyyyMMdd(08-21新增)
*/
/**
* 数据更新至: yyyy|yyyyMM|yyyyMMdd(08-21新增)
*/
private String dataEndTime;
/**
* desc: 是否显示 1显示 0不显示
*/
private String isDisplay;
}

13
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenCustomerAgencyServiceImpl.java

@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.stream.Collectors;
@ -131,6 +132,12 @@ public class ScreenCustomerAgencyServiceImpl implements ScreenCustomerAgencyServ
exists.setLevel(e.getLevel());
exists.setDataEndTime(dateEndTime);
exists.setAreaCode(e.getAreaCode());
//如果没有区划 则默认暂时不显示
if (StringUtils.isEmpty(e.getAreaCode())) {
exists.setIsDisplay(NumConstant.ZERO_STR);
} else {
exists.setIsDisplay(NumConstant.ONE_STR);
}
exists.setAllParentNames(e.getAllParentName());
updateAgency(exists);
}
@ -221,6 +228,12 @@ public class ScreenCustomerAgencyServiceImpl implements ScreenCustomerAgencyServ
cae.setAllParentNames(e.getAllParentName());
cae.setAreaCode(e.getAreaCode());
//cae.setAreaMarks(e);
//如果没有区划 则默认暂时不显示
if (StringUtils.isEmpty(e.getAreaCode())) {
cae.setIsDisplay(NumConstant.ZERO_STR);
} else {
cae.setIsDisplay(NumConstant.ONE_STR);
}
cae.setCustomerId(e.getCustomerId());
cae.setDataEndTime(dateEndTime);
cae.setLevel(e.getLevel());

13
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/GetJwtAccessTokenFormDTO.java

@ -0,0 +1,13 @@
package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class GetJwtAccessTokenFormDTO {
@NotBlank(message = "AppId不能为空")
private String appId;
}

32
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/AppIdInfoResultDTO.java

@ -0,0 +1,32 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2020/10/21 5:30 下午
*/
@Data
public class AppIdInfoResultDTO implements Serializable {
private static final long serialVersionUID = 4556971930323763712L;
/**
* 应用ID
*/
private String appId;
/**
* 客户ID
*/
private String customerId;
/**
* 密钥
*/
private String secret;
private String accessToken;
}

16
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/GetJwtAccessTokenResultDTO.java

@ -0,0 +1,16 @@
package com.epmet.dto.result;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetJwtAccessTokenResultDTO {
private String customerId;
private String token;
private Long ts;
}

18
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java

@ -3,7 +3,9 @@ package com.epmet.feign;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.ExternalAppAuthFormDTO;
import com.epmet.dto.form.GetJwtAccessTokenFormDTO;
import com.epmet.dto.form.WorkDayFormDTO;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.WorkDayResultDTO;
import com.epmet.feign.fallback.EpmetCommonServiceOpenFeignClientFallback;
@ -19,8 +21,8 @@ import java.util.List;
* @author yinzuomei@elink-cn.com
* @date 2020/6/4 10:28
*/
@FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class)
//@FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class, url = "http://localhost:8103")
//@FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class)
@FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class, url = "localhost:8103")
public interface EpmetCommonServiceOpenFeignClient {
/**
* @param formDTO
@ -53,4 +55,16 @@ public interface EpmetCommonServiceOpenFeignClient {
*/
@PostMapping("/commonservice/externalapp/get-secret")
Result getSecret(@RequestBody String appId);
/**
* @Description 获取AccessToken
* @return Result
* @author wxz
* @date 2020.10.22 10:19
*/
@PostMapping("/commonservice/externalapp/get-jwt-accesstoken")
Result getAccessToken(@RequestBody GetJwtAccessTokenFormDTO form);
@PostMapping("/commonservice/externalapp/appidinfo")
Result<AppIdInfoResultDTO> appIdInfo(@RequestBody String appId);
}

6
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java

@ -5,6 +5,7 @@ import com.epmet.commons.tools.utils.ModuleUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.ExternalAppAuthFormDTO;
import com.epmet.dto.form.WorkDayFormDTO;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.WorkDayResultDTO;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
@ -39,4 +40,9 @@ public class EpmetCommonServiceOpenFeignClientFallback implements EpmetCommonSer
public Result getSecret(String appId) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "getSecret", appId);
}
@Override
public Result<AppIdInfoResultDTO> appIdInfo(String appId) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "appIdInfo", appId);
}
}

27
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java

@ -8,8 +8,11 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.ExternalAppAuthFormDTO;
import com.epmet.dto.form.ExternalAppFormDTO;
import com.epmet.dto.form.GetJwtAccessTokenFormDTO;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppAuthResultDTO;
import com.epmet.dto.result.ExternalAppResultDTO;
import com.epmet.dto.result.GetJwtAccessTokenResultDTO;
import com.epmet.service.ExternalAppAuthService;
import com.epmet.service.ExternalAppSecretService;
import com.epmet.service.ExternalAppService;
@ -17,10 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -146,4 +146,23 @@ public class ExternalAppController {
return new Result().ok(secret);
}
/**
* @Description 获取AccessToken
* @return Result
* @author wxz
* @date 2020.10.22 10:19
*/
@PostMapping("get-jwt-accesstoken")
public Result getAccessToken(@RequestBody GetJwtAccessTokenFormDTO form) {
ValidatorUtils.validateEntity(form);
String appId = form.getAppId();
GetJwtAccessTokenResultDTO jwtAccessToken = externalAppService.getJwtAccessToken(appId);
return new Result().ok(jwtAccessToken);
}
@PostMapping("appidinfo")
public Result<AppIdInfoResultDTO> appIdInfo(@RequestBody String appId){
return new Result<AppIdInfoResultDTO>().ok(externalAppService.appIdInfo(appId));
}
}

9
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java

@ -18,6 +18,7 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppResultDTO;
import com.epmet.entity.ExternalAppEntity;
import org.apache.ibatis.annotations.Mapper;
@ -41,4 +42,12 @@ public interface ExternalAppDao extends BaseDao<ExternalAppEntity> {
List<ExternalAppResultDTO> list(@Param("customerId") String customerId);
List<String> getCustomerIds();
/**
* @Description 根据appId查询客户ID和密钥
* @Param appId
* @author zxc
* @date 2020/10/21 5:50 下午
*/
AppIdInfoResultDTO appIdInfo(@Param("appId")String appId);
}

6
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java

@ -18,7 +18,9 @@
package com.epmet.service;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppResultDTO;
import com.epmet.dto.result.GetJwtAccessTokenResultDTO;
import java.util.List;
@ -38,4 +40,8 @@ public interface ExternalAppService {
List<String> getCustomerIds();
String resetSecret(String appId);
GetJwtAccessTokenResultDTO getJwtAccessToken(String appId);
AppIdInfoResultDTO appIdInfo(String appId);
}

28
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java

@ -27,12 +27,15 @@ import com.epmet.dao.ExternalAppDao;
import com.epmet.dao.ExternalAppSecretDao;
import com.epmet.dao.ExternalCustomerDao;
import com.epmet.dto.CustomerDTO;
import com.epmet.dto.result.AppIdInfoResultDTO;
import com.epmet.dto.result.ExternalAppResultDTO;
import com.epmet.dto.result.GetJwtAccessTokenResultDTO;
import com.epmet.entity.ExternalAppEntity;
import com.epmet.entity.ExternalAppSecretEntity;
import com.epmet.enu.CustomerTypeEnum;
import com.epmet.feign.OperCrmOpenFeignClient;
import com.epmet.service.ExternalAppService;
import com.epmet.utils.externalapp.ExtAppJwtTokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@ -41,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
@ -70,6 +74,9 @@ public class ExternalAppServiceImpl implements ExternalAppService {
@Autowired
private RedisUtils redisUtils;
@Autowired
private ExtAppJwtTokenUtils tokenUtils;
@Transactional
@Override
public ExternalAppResultDTO add(String appName, String customerId, String customerType) {
@ -197,4 +204,25 @@ public class ExternalAppServiceImpl implements ExternalAppService {
return null;
}
@Override
public GetJwtAccessTokenResultDTO getJwtAccessToken(String appId) {
ExternalAppEntity externalAppEntity = externalAppDao.selectById(appId);
String customerId = externalAppEntity.getCustomerId();
String secret = externalAppSecretDao.getSecretByAppId(appId);
long ts = System.currentTimeMillis();
String token = tokenUtils.genToken(secret, appId, customerId, ts);
return new GetJwtAccessTokenResultDTO(customerId, token, ts);
}
@Override
public AppIdInfoResultDTO appIdInfo(String appId) {
AppIdInfoResultDTO appIdInfoResultDTO = externalAppDao.appIdInfo(appId);
if (null == appIdInfoResultDTO){
throw new RenException("没查到对应appId【"+appId+"】的信息");
}
String accessToken = tokenUtils.genToken(appIdInfoResultDTO.getSecret(), appId, appIdInfoResultDTO.getCustomerId(), System.currentTimeMillis());
appIdInfoResultDTO.setAccessToken(accessToken);
return appIdInfoResultDTO;
}
}

36
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/utils/externalapp/ExtAppJwtTokenUtils.java

@ -49,7 +49,7 @@ public class ExtAppJwtTokenUtils {
}
}
public String createToken(Map<String, Object> map, String secret) {
private String createToken(Map<String, Object> map, String secret) {
return Jwts.builder()
.setHeaderParam("typ", "JWT")
.setClaims(map)
@ -59,21 +59,7 @@ public class ExtAppJwtTokenUtils {
.compact();
}
// /**
// * token是否过期
// *
// * @return true:过期
// */
// public boolean isTokenExpired(Date expiration) {
// return expiration.before(new Date());
// }
public static void main(String[] args) {
genToken();
// getClaim();
}
public static void genToken() {
public static void genTestToken() {
HashMap<String, Object> claim = new HashMap<>();
//市北
//String secret = "612d304095c50369c3ef06e490f05779eeb8f19ff16566c73aeafafc5fa01970";
@ -89,21 +75,19 @@ public class ExtAppJwtTokenUtils {
String appId = "f358d63a89f3670c197c62ca4c3a0366";
String customrId = "45687aa479955f9d06204d415238f7cc";
claim.put("customerId", customrId);
claim.put("appId", appId);
long ts = System.currentTimeMillis() + 1000 * 60 * 1;
System.out.println("时间戳:" + ts);
claim.put("ts", ts);
String abc = new ExtAppJwtTokenUtils().createToken(claim, secret);
System.out.println(abc);
String token = new ExtAppJwtTokenUtils().genToken(secret, appId, customrId, ts);
System.out.println(token);
}
public static void getClaim() {
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJhcHBJZCI6IjEiLCJjdXN0b21lcklkIjoiYzEiLCJpYXQiOjE1OTc3NDI2NTB9.09Vop0Nobg3LENAJoAZaCUKtgAjADAK48BS11ky3YdAp6h-cXYtGeqUxbgvE_4F6239rc7UE2fjxtEvMuWEJuA";
public String genToken(String secret, String appId, String customrId, Long ts) {
HashMap<String, Object> claim = new HashMap<>();
claim.put("customerId", customrId);
claim.put("appId", appId);
claim.put("ts", ts);
Claims claimByToken = new ExtAppJwtTokenUtils().getClaimByToken(token, "4a762660254c57996343f8ee42fbc0a6");
System.out.println(claimByToken);
return createToken(claim, secret);
}
}

14
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml

@ -66,5 +66,19 @@
SELECT CUSTOMER_ID FROM external_app WHERE DEL_FLAG = 0
</select>
<!-- 根据appId查询客户ID和密钥 -->
<select id="appIdInfo" resultType="com.epmet.dto.result.AppIdInfoResultDTO">
SELECT
ea.ID AS appId,
ea.CUSTOMER_ID,
eas.SECRET
FROM external_app ea
LEFT JOIN external_app_secret eas ON eas.APP_ID = ea.id
WHERE
ea.DEL_FLAG = 0
AND eas.DEL_FLAG = 0
AND ea.ID = #{appId}
</select>
</mapper>
Loading…
Cancel
Save