From 30e441f2c87e5558e2a8b4301149d126bf813dab Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Mon, 18 Jan 2021 16:37:27 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E4=B8=8A=E4=BC=A0controller=EF=BC=8Cserv?= =?UTF-8?q?ice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/epmet/controller/SsoController.java | 13 +++++++++++++ .../main/java/com/epmet/service/SsoService.java | 8 ++++++++ .../com/epmet/service/impl/SsoServiceImpl.java | 14 ++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 epmet-auth/src/main/java/com/epmet/controller/SsoController.java create mode 100644 epmet-auth/src/main/java/com/epmet/service/SsoService.java create mode 100644 epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java diff --git a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java new file mode 100644 index 0000000000..117a891f2c --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java @@ -0,0 +1,13 @@ +package com.epmet.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午4:33 + */ +@RestController +@RequestMapping("sso/resi") +public class SsoController { +} diff --git a/epmet-auth/src/main/java/com/epmet/service/SsoService.java b/epmet-auth/src/main/java/com/epmet/service/SsoService.java new file mode 100644 index 0000000000..d65cbcfe95 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/service/SsoService.java @@ -0,0 +1,8 @@ +package com.epmet.service; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午4:34 + */ +public interface SsoService { +} diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java new file mode 100644 index 0000000000..c40737fd92 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -0,0 +1,14 @@ +package com.epmet.service.impl; + +import com.epmet.service.SsoService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午4:35 + */ +@Service +@Slf4j +public class SsoServiceImpl implements SsoService { +} From 882af3333e126183d15ffb9c1243a4e65643dcf6 Mon Sep 17 00:00:00 2001 From: wangchao Date: Mon, 18 Jan 2021 17:33:06 +0800 Subject: [PATCH 02/25] =?UTF-8?q?/sso=20=E6=A0=B9=E6=8D=AE=E5=9C=B0?= =?UTF-8?q?=E5=8C=BA=E7=A0=81=E8=8E=B7=E5=8F=96=E7=9B=B8=E5=85=B3=E7=BD=91?= =?UTF-8?q?=E6=A0=BC=E5=88=97=E8=A1=A8=EF=BC=9B=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9C=80=E8=BF=91=E8=AE=BF=E9=97=AE=E7=9A=84=E7=BD=91?= =?UTF-8?q?=E6=A0=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StrangerResiGuideController.java | 13 ++++++ .../service/StrangerAccessRecordService.java | 10 +++++ .../impl/StrangerAccessRecordServiceImpl.java | 43 +++++++++++++++++++ .../controller/ResiMineGridController.java | 12 ++++++ .../grid/service/ResiMineGridService.java | 9 ++++ .../service/impl/ResiMineGridServiceImpl.java | 26 +++++++++++ 6 files changed, 113 insertions(+) diff --git a/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/controller/StrangerResiGuideController.java b/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/controller/StrangerResiGuideController.java index f190314b1c..47660b3ea2 100644 --- a/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/controller/StrangerResiGuideController.java +++ b/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/controller/StrangerResiGuideController.java @@ -79,6 +79,19 @@ public class StrangerResiGuideController { } + /** + * @Description H5版 自动/选定定位获取地附近网格列表 + * @param customerGridListFormDTO + * @return com.epmet.commons.tools.utils.Result> + * @author wangc + * @date 2021.01.18 16:39 + */ + @PostMapping("sso/publiclocationgridlist") + Result> locationGridList(@RequestBody CustomerGridListFormDTO customerGridListFormDTO){ + ValidatorUtils.validateEntity(customerGridListFormDTO); + return strangerAccessRecordService.listCustomerGridH5(customerGridListFormDTO); + } + /** * @Description 陌生访客手动选定位置获取附近网格数据 * @Param CustomerGridListFormDTO diff --git a/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/StrangerAccessRecordService.java b/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/StrangerAccessRecordService.java index 9dbd10519d..ffbd90e0e1 100644 --- a/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/StrangerAccessRecordService.java +++ b/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/StrangerAccessRecordService.java @@ -120,4 +120,14 @@ public interface StrangerAccessRecordService extends BaseService> thirdCustomerGridList(PublicCustomerGridListFormDTO formDTO); + + /** + * @Description H5版 自动/选定定位获取地附近网格列表 + * @param customerGridListFormDTO + * @return com.epmet.commons.tools.utils.Result> + * @author wangc + * @date 2021.01.18 16:39 + */ + Result> listCustomerGridH5(CustomerGridListFormDTO customerGridListFormDTO); + } diff --git a/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/impl/StrangerAccessRecordServiceImpl.java b/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/impl/StrangerAccessRecordServiceImpl.java index 72e16e1dfd..e7e5c6cca9 100644 --- a/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/impl/StrangerAccessRecordServiceImpl.java +++ b/epmet-module/resi-guide/resi-guide-server/src/main/java/com/epmet/service/impl/StrangerAccessRecordServiceImpl.java @@ -31,6 +31,7 @@ import com.epmet.feign.GovOrgFeignClient; import com.epmet.feign.OperCustomizeFeignClient; import com.epmet.service.StrangerAccessRecordService; import com.epmet.utils.ModuleConstant; +import com.github.pagehelper.PageHelper; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -303,6 +304,48 @@ public class StrangerAccessRecordServiceImpl extends BaseServiceImpl> + * @author wangc + * @date 2021.01.18 16:39 + */ + @Override + public Result> listCustomerGridH5(CustomerGridListFormDTO customerGridListFormDTO) { + + ListCustomerGridFormDTO listCustomerGridFormDTO = new ListCustomerGridFormDTO(); + listCustomerGridFormDTO.setAreaCode(StringUtils.isBlank(customerGridListFormDTO.getSelectedAreaCode()) ? + customerGridListFormDTO.getAreaCode() : customerGridListFormDTO.getSelectedAreaCode()); + + listCustomerGridFormDTO.setPageNo(null == customerGridListFormDTO.getPageNo() ? ModuleConstant.MIN_CURRENT_PAGE_NO : customerGridListFormDTO.getPageNo()); + listCustomerGridFormDTO.setPageSize(customerGridListFormDTO.getPageSize()); + + + Result> queryResult = + govOrgFeignClient + .queryGridListByAreaCode(listCustomerGridFormDTO); + + //Feign调用成功 + if (queryResult.success()) { + List queryList = queryResult.getData(); + if (null != queryResult && queryList.size() > 0) { + StrangerAccessRecordEntity strangerTrance = new StrangerAccessRecordEntity(); + strangerTrance.setLocationAreaCode(listCustomerGridFormDTO.getAreaCode()); + strangerTrance.setIsAuthorized(customerGridListFormDTO.getIsAuthorized()); + strangerTrance.setGridNumber(queryList.size()); + strangerTrance.setVisitTime(new Date()); + strangerTrance.setProvince(customerGridListFormDTO.getProvince()); + strangerTrance.setCity(customerGridListFormDTO.getCity()); + strangerTrance.setArea(customerGridListFormDTO.getArea()); + insert(strangerTrance); + } + } + + return queryResult; + + } + /** * @Description 获取客户信息 * @param appId diff --git a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java index 62449677da..e025d6ccc3 100644 --- a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java +++ b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java @@ -63,4 +63,16 @@ public class ResiMineGridController { return new Result().ok(resiMineGridService.latestGridInfo(formDTO)); } + /** + * @return com.epmet.resi.mine.dto.result.LatestGridInfoResultDTO + * @param tokenDto + * @Author yinzuomei + * @Description 获取用户最近访问网格 + * @Date 2020/3/24 11:10 + **/ + @GetMapping("sso/latestgridinfo") + public Result latestGridInfo(@LoginUser TokenDto tokenDto){ + LatestGridInfoResultDTO latestGridInfoResultDTO=resiMineGridService.getLatestGridInfoH5(tokenDto); + return new Result().ok(latestGridInfoResultDTO); + } } diff --git a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/ResiMineGridService.java b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/ResiMineGridService.java index 0d1c3f3f8f..e6d8a70398 100644 --- a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/ResiMineGridService.java +++ b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/ResiMineGridService.java @@ -39,4 +39,13 @@ public interface ResiMineGridService { * @Date 2020/8/3 **/ LatestGridInfoResultDTO latestGridInfo(LatestGridInfoFormDTO formDTO); + + /** + * H5版本 - 获取用户最近访问网格 + * + * @Author + * @param tokenDto + * @return com.epmet.commons.tools.utils.Result + */ + LatestGridInfoResultDTO getLatestGridInfoH5(TokenDto tokenDto); } diff --git a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/impl/ResiMineGridServiceImpl.java b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/impl/ResiMineGridServiceImpl.java index a60d242550..455b7c0cbf 100644 --- a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/impl/ResiMineGridServiceImpl.java +++ b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/service/impl/ResiMineGridServiceImpl.java @@ -138,4 +138,30 @@ public class ResiMineGridServiceImpl implements ResiMineGridService { return userResult.getData(); } + /** + * @Description H5版本 - 获取用户最近访问网格 + * @param tokenDto + * @return com.epmet.dto.result.LatestGridInfoResultDTO + * @author wangc + * @date 2021.01.18 17:22 + */ + @Override + public LatestGridInfoResultDTO getLatestGridInfoH5(TokenDto tokenDto) { + if (null == tokenDto || StringUtils.isBlank(tokenDto.getUserId())) { + logger.error(String.format("居民端获取用户最近访问的网格失败:tokenDto is null or userId is null")); + throw new RenException(ModuleConstant.USER_NOT_NULL); + } + if(!AppClientConstant.APP_RESI.equals(tokenDto.getApp())){ + logger.error(String.format("居民端获取用户最近访问的网格失败,userId:%s,错误提示:%s",tokenDto.getUserId(),ModuleConstant.FOR_RESI_CALL)); + throw new RenException(ModuleConstant.FOR_RESI_CALL); + } + logger.info(String.format("居民端获取用户最近访问网格入参%s", JSON.toJSONString(tokenDto))); + Result userResult=epmetUserFeignClient.getLatestGridInfoByUserId(tokenDto.getUserId()); + if(userResult.success()&&null!=userResult.getData()){ + return userResult.getData(); + } + logger.warn(String.format("居民端获取用户最近访问网格失败,调用epmet-user-server服务返回%s",JSON.toJSONString(userResult))); + return null ; + } + } From 5db91f665d5368c8dfa0a61b80a0a91089f65ed9 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 19 Jan 2021 10:11:01 +0800 Subject: [PATCH 03/25] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=B9=B3=E5=8F=B0=E6=A8=A1=E5=9D=97=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-auth/pom.xml | 5 ++ epmet-auth/src/main/resources/bootstrap.yml | 9 ++- epmet-commons/epmet-commons-thirdplat/pom.xml | 22 +++++ .../com/epmet/commons/thirdplat/DemoApp.java | 35 ++++++++ .../apiservice/AbstractApiService.java | 34 ++++++++ .../apiservice/jcet/JcetApiService.java | 81 +++++++++++++++++++ .../thirdplat/config/ThirdplatConfig.java | 14 ++++ .../thirdplat/constants/JcetApiUrls.java | 8 ++ .../dto/form/jcet/SsoTicketFormDTO.java | 8 ++ .../dto/form/jcet/SsoTokenFormDTO.java | 8 ++ .../thirdplat/dto/result/jcet/JcetResult.java | 13 +++ .../dto/result/jcet/UserInfoResultDTO.java | 13 +++ .../thirdplat/encrypt/EncryptUtils.java | 51 ++++++++++++ .../commons/thirdplat/encrypt/SignUtils.java | 15 ++++ .../properties/JcetThirdplatProps.java | 13 +++ .../thirdplat/properties/ThirdplatProps.java | 12 +++ .../tools/exception/EpmetErrorCode.java | 2 +- epmet-commons/pom.xml | 3 +- 18 files changed, 343 insertions(+), 3 deletions(-) create mode 100644 epmet-commons/epmet-commons-thirdplat/pom.xml create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index 69713f1908..4164a50134 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -18,6 +18,11 @@ + + com.epmet + epmet-commons-thirdplat + 2.0.0 + com.epmet epmet-admin-client diff --git a/epmet-auth/src/main/resources/bootstrap.yml b/epmet-auth/src/main/resources/bootstrap.yml index e7fa54d000..865035f3f7 100644 --- a/epmet-auth/src/main/resources/bootstrap.yml +++ b/epmet-auth/src/main/resources/bootstrap.yml @@ -131,4 +131,11 @@ dingTalk: shutdown: graceful: enable: true #是否开启优雅停机 - waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 \ No newline at end of file + waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 + +# 调用第三方平台相关参数 +thirdplat: + jcet: + domain: http://101.206.141.251:21006 + appkey: soXDEoM1 + appsecret: V7ea0KnlYt7eSyzc \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/pom.xml b/epmet-commons/epmet-commons-thirdplat/pom.xml new file mode 100644 index 0000000000..8689c09054 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/pom.xml @@ -0,0 +1,22 @@ + + + + epmet-commons + com.epmet + 2.0.0 + + 4.0.0 + + epmet-commons-thirdplat + + + + com.epmet + epmet-commons-tools + 2.0.0 + + + + \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java new file mode 100644 index 0000000000..92d525b186 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java @@ -0,0 +1,35 @@ +package com.epmet.commons.thirdplat; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO; +import com.epmet.commons.thirdplat.encrypt.SignUtils; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; + +public class DemoApp { + + private static String appid = "soXDEoM1"; + private static String appsecret = "V7ea0KnlYt7eSyzc"; + + public static void main(String[] args) throws UnsupportedEncodingException { + + //SsoToken ssoToken = new SsoToken(); + //ssoToken.setSsoToken("wxz"); + + SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); + ssoTicket.setSsoTicket("wxz"); + + int bodyLength = JSON.toJSONString(ssoTicket).getBytes("utf-8").length; + + Map headers = new HashMap(); + long timestamp = System.currentTimeMillis(); + headers.put("openTimestamp", String.valueOf(timestamp)); + headers.put("openAppId", appid); + String encryptContent = appid + timestamp + bodyLength; + headers.put("openSign", SignUtils.generate(encryptContent, appsecret)); + System.out.println(headers); + } + +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java new file mode 100644 index 0000000000..7950526fd1 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java @@ -0,0 +1,34 @@ +package com.epmet.commons.thirdplat.apiservice; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.thirdplat.dto.result.jcet.JcetResult; +import com.epmet.commons.thirdplat.properties.ThirdplatProps; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.Result; + +public class AbstractApiService { + + protected ThirdplatProps thirdplatProps; + + /** + * @Description 解析请求结果 + * @return + * @author wxz + * @date 2021.01.19 09:53 + */ + protected R parseResult(Result thResult, Class resultType) { + if (!thResult.success()) { + throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), + EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getMsg().concat(":").concat(thResult.getInternalMsg())); + } + + JcetResult jcetResult = JSON.parseObject(thResult.getData(), JcetResult.class); + if (!jcetResult.isSuccess()) { + throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), + jcetResult.getMsg().concat(",错误码:") + jcetResult.getCode()); + } + + return JSON.parseObject(jcetResult.getMsg(), resultType); + } +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java new file mode 100644 index 0000000000..edb59e6611 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -0,0 +1,81 @@ +package com.epmet.commons.thirdplat.apiservice.jcet; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.thirdplat.apiservice.AbstractApiService; +import com.epmet.commons.thirdplat.constants.JcetApiUrls; +import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO; +import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; +import com.epmet.commons.thirdplat.encrypt.SignUtils; +import com.epmet.commons.thirdplat.properties.JcetThirdplatProps; +import com.epmet.commons.thirdplat.properties.ThirdplatProps; +import com.epmet.commons.tools.utils.HttpClientManager; +import com.epmet.commons.tools.utils.Result; +import org.springframework.stereotype.Component; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; + +@Component +public class JcetApiService extends AbstractApiService { + + private JcetThirdplatProps jcetThirdplatProps; + + public JcetApiService(ThirdplatProps props) { + this.thirdplatProps = props; + jcetThirdplatProps = props.getJcet(); + } + + public UserInfoResultDTO login(String ticket) { + + try { + UserInfoResultDTO userInfoByTicket = getUserInfoByTicket(ticket); + // todo + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + return null; + } + + private UserInfoResultDTO getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { + SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); + ssoTicket.setSsoTicket(ticket); + Result result = HttpClientManager.getInstance().sendPostByJSONAndHeader( + jcetThirdplatProps.getDomain().concat(JcetApiUrls.GET_USER_BY_TICKET), + JSON.toJSONString(ssoTicket), getHeaders(ssoTicket)); + + UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); + return resultDTO; + } + + private UserInfoResultDTO getUserInfoByToken(String ticket) throws UnsupportedEncodingException { + SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); + ssoTicket.setSsoTicket(ticket); + Result result = HttpClientManager.getInstance().sendPostByJSONAndHeader( + jcetThirdplatProps.getDomain().concat(JcetApiUrls.GET_USER_BY_TICKET), + JSON.toJSONString(ssoTicket), getHeaders(ssoTicket)); + + UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); + return resultDTO; + } + + /** + * 获取请求所需要的头信息 + * @param contentObject + * @return + * @throws UnsupportedEncodingException + */ + private Map getHeaders(Object contentObject) throws UnsupportedEncodingException { + int bodyLength = JSON.toJSONString(contentObject).getBytes("utf-8").length; + + Map headers = new HashMap(); + long timestamp = System.currentTimeMillis(); + headers.put("openTimestamp", String.valueOf(timestamp)); + headers.put("openAppId", jcetThirdplatProps.getAppkey()); + String encryptContent = jcetThirdplatProps.getAppkey() + timestamp + bodyLength; + headers.put("openSign", SignUtils.generate(encryptContent, jcetThirdplatProps.getAppsecret())); + return headers; + } + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java new file mode 100644 index 0000000000..16258ed150 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java @@ -0,0 +1,14 @@ +package com.epmet.commons.thirdplat.config; + +import com.epmet.commons.thirdplat.properties.ThirdplatProps; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * 第三方平台的相关配置 + */ +@Configuration +@EnableConfigurationProperties(ThirdplatProps.class) +public class ThirdplatConfig { + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java new file mode 100644 index 0000000000..ee0438c5cd --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java @@ -0,0 +1,8 @@ +package com.epmet.commons.thirdplat.constants; + +public interface JcetApiUrls { + + // 根据ticket查询用户 + String GET_USER_BY_TICKET = "/openapi-cgw/openapi-login/sso/getUserInfoByTicket"; + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java new file mode 100644 index 0000000000..b0f905d972 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java @@ -0,0 +1,8 @@ +package com.epmet.commons.thirdplat.dto.form.jcet; + +import lombok.Data; + +@Data +public class SsoTicketFormDTO { + private String ssoTicket; +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java new file mode 100644 index 0000000000..f3a7707082 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java @@ -0,0 +1,8 @@ +package com.epmet.commons.thirdplat.dto.form.jcet; + +import lombok.Data; + +@Data +public class SsoTokenFormDTO { + private String ssoToken; +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java new file mode 100644 index 0000000000..aea748f51a --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java @@ -0,0 +1,13 @@ +package com.epmet.commons.thirdplat.dto.result.jcet; + +import lombok.Data; + +@Data +public class JcetResult { + + private boolean success; + private String msg; + private Object data; + private int code; + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java new file mode 100644 index 0000000000..5adf33436d --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java @@ -0,0 +1,13 @@ +package com.epmet.commons.thirdplat.dto.result.jcet; + +import lombok.Data; + +@Data +public class UserInfoResultDTO { + + private String name; + private String mobile; + private String uid; + private String account; + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java new file mode 100644 index 0000000000..699d12ea40 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java @@ -0,0 +1,51 @@ +package com.epmet.commons.thirdplat.encrypt; + + +import com.epmet.commons.tools.exception.RenException; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class EncryptUtils { + private final static char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + /** + * 32位 MD5加密 + * + * @param s + * @return + */ + public static String md5Hex(String s) throws UnsupportedEncodingException { + byte[] result = digest("MD5", s.getBytes(Charset.defaultCharset())); + return hex(result); + } + /** + * 32 位 sha256加密 + * + * @param s + * @return + */ + public static String sha256(String s) { + byte[] result = digest("SHA-256", s.getBytes(Charset.defaultCharset())); + return hex(result); + } + private static byte[] digest(String algorithm, byte[] data) { + try { + MessageDigest digest = MessageDigest.getInstance(algorithm); + digest.update(data, 0, data.length); + return digest.digest(); + } catch (NoSuchAlgorithmException e) { + throw new RenException(algorithm + " error", e); + } + } + private static String hex(byte[] data) { + char[] result = new char[data.length * 2]; + int c = 0; + for (byte b : data) { + result[c++] = HEX_DIGITS[(b >> 4) & 0xf]; + result[c++] = HEX_DIGITS[b & 0xf]; + } + return new String(result); + } +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java new file mode 100644 index 0000000000..1c45e44b6b --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java @@ -0,0 +1,15 @@ +package com.epmet.commons.thirdplat.encrypt; + +import java.io.UnsupportedEncodingException; + +public class SignUtils { + public static String generate(String content, String secret) throws UnsupportedEncodingException { + String sign = EncryptUtils.sha256(content); + sign = EncryptUtils.md5Hex(sign + secret); + return sign; + } + + public static void main(String[] args) { + System.out.println(777); + } +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java new file mode 100644 index 0000000000..1682a86fce --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java @@ -0,0 +1,13 @@ +package com.epmet.commons.thirdplat.properties; + +import lombok.Data; + +/** + * 酒城e通三方平台配置 + */ +@Data +public class JcetThirdplatProps { + private String domain; + private String appkey; + private String appsecret; +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java new file mode 100644 index 0000000000..07c4919bd9 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java @@ -0,0 +1,12 @@ +package com.epmet.commons.thirdplat.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@Data +@ConfigurationProperties(prefix = "thirdplat") +public class ThirdplatProps { + + private JcetThirdplatProps jcet; + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 4d3c107de3..8bdcadf260 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -71,6 +71,7 @@ public enum EpmetErrorCode { NOT_DEL_AGENCY_GRID(8207, "该机关存在网格,不允许删除"), REQUIRE_PERMISSION(8301, "您没有足够的操作权限"), + THIRD_PLAT_REQUEST_ERROR(8302, "请求第三方平台错误"), NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"), MOBILE_USED(8402,"该手机号已注册"), @@ -143,7 +144,6 @@ public enum EpmetErrorCode { TOPIC_IS_HIDDEN(9006,"该话题已被屏蔽,请先解除屏蔽"), TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"); - private int code; private String msg; diff --git a/epmet-commons/pom.xml b/epmet-commons/pom.xml index d4b8e270b4..dbec54a340 100644 --- a/epmet-commons/pom.xml +++ b/epmet-commons/pom.xml @@ -23,6 +23,7 @@ epmet-commons-tools-wx-mp epmet-commons-service-call epmet-commons-extapp-auth - + epmet-commons-thirdplat + From 973c253b4bcef3b359fc0f933e2f0e0c562609e2 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 19 Jan 2021 10:14:53 +0800 Subject: [PATCH 04/25] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=B9=B3=E5=8F=B0=E6=A8=A1=E5=9D=97=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java index edb59e6611..ca2e1ac1a8 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -38,7 +38,7 @@ public class JcetApiService extends AbstractApiService { return null; } - private UserInfoResultDTO getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { + public UserInfoResultDTO getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); ssoTicket.setSsoTicket(ticket); Result result = HttpClientManager.getInstance().sendPostByJSONAndHeader( From 4f4977c24d9cb2a1a0c83e8cb7429673b3a573ec Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Tue, 19 Jan 2021 10:48:37 +0800 Subject: [PATCH 05/25] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=EF=BC=8C=E5=8F=AA=E6=9C=89=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=AE=A2=E6=88=B7=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/service/impl/CustomerServiceImpl.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java index 9857f910c5..f67c225748 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java @@ -32,6 +32,7 @@ import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.ModuleConstant; import com.epmet.constant.RoleKeyConstants; +import com.epmet.constant.ThirdConstant; import com.epmet.constant.UserWorkType; import com.epmet.dao.CustomerDao; import com.epmet.dto.*; @@ -520,13 +521,15 @@ public class CustomerServiceImpl extends BaseServiceImpl Date: Tue, 19 Jan 2021 13:51:35 +0800 Subject: [PATCH 06/25] =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8C=89=E5=AE=A2=E6=88=B7=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/constant/UserMessageConstans.java | 10 +++++ .../service/impl/WxmpMessageServiceImpl.java | 43 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/constant/UserMessageConstans.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/constant/UserMessageConstans.java index b67f9251df..455169adf9 100644 --- a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/constant/UserMessageConstans.java +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/constant/UserMessageConstans.java @@ -8,4 +8,14 @@ package com.epmet.constant; public interface UserMessageConstans { String READ = "read"; String UNREAD = "unread"; + + /** + * 小程序 + */ + String MINI = "mini"; + /** + * 第三方app + */ + String APP = "app"; + } diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/WxmpMessageServiceImpl.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/WxmpMessageServiceImpl.java index c5e1bf1ec6..c533112ed2 100644 --- a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/WxmpMessageServiceImpl.java +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/WxmpMessageServiceImpl.java @@ -26,12 +26,14 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.commons.tools.utils.Result; +import com.epmet.constant.UserMessageConstans; import com.epmet.constant.WxMsgTemplateSubscribeStatus; import com.epmet.constant.WxmpMessageConstant; import com.epmet.dao.WxmpResiUserSubscribeDao; import com.epmet.dao.WxmpTemplateMsgSubscribeStatusDao; import com.epmet.dao.WxmpUserSubscribeRecordDao; import com.epmet.dao.WxmpWorkUserSubscribeDao; +import com.epmet.dto.PaCustomerDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.entity.*; @@ -140,6 +142,13 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { if (!(msgList.size() > NumConstant.ZERO)) { throw new RenException("待发送消息不能为空"); } + //2021.1.19 根据客户类型判断是否允许推送微信消息【兼容泸州】 sun start + PaCustomerDTO pc = thirdCustomer(msgList.get(NumConstant.ZERO).getCustomerId()); + if (!pc.getType().equals(UserMessageConstans.MINI)) { + logger.warn(String.format("当前客户不允许推送微信消息,客户Id->%s", msgList.get(NumConstant.ZERO).getCustomerId())); + return; + } + //2021.1.19 end int succecssCount = 0; // 获取templateId CustomerTemplateListFormDTO customerTemplateListFormDTO = new CustomerTemplateListFormDTO(); @@ -337,6 +346,13 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { if (msgList.size() == 0){ return; } + //2021.1.19 根据客户类型判断是否允许推送微信消息【兼容泸州】 sun start + PaCustomerDTO pc = thirdCustomer(msgList.get(NumConstant.ZERO).getCustomerId()); + if (!pc.getType().equals(UserMessageConstans.MINI)) { + logger.warn(String.format("当前客户不允许推送微信消息,客户Id->%s", msgList.get(NumConstant.ZERO).getCustomerId())); + return; + } + //2021.1.19 end // 获取templateId TemplateListV2FormDTO templateListV2FormDTO = new TemplateListV2FormDTO(); templateListV2FormDTO.setCustomerId(msgList.get(0).getCustomerId()); @@ -873,8 +889,33 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { if(msgSubscribeStatusDao.updateUserSubscribe(formDTO) data = HttpClientManager.getInstance().sendGet(url, null); + logger.info("WxmpMessageServiceImpl.thirdCustomer:httpclient->url:" + url + ",结果->" + data); + if (!data.success()) { + logger.error(String.format("调用third服务查询客户基础数据失败,客户Id->%s", customerId)); + throw new RenException(data.getCode(), data.getInternalMsg()); + } + JSONObject toResult = JSON.parseObject(data.getData()); + Result result = ConvertUtils.mapToEntity(toResult, Result.class); + if (null != toResult.get("code")) { + result.setCode(((Integer) toResult.get("code")).intValue()); + } + if (!result.success()) { + throw new RenException(result.getCode()); + } + Object RegisterResult = result.getData(); + JSONObject jsonObject = JSON.parseObject(RegisterResult.toString()); + PaCustomerDTO resultDTO = ConvertUtils.mapToEntity(jsonObject, PaCustomerDTO.class); + return resultDTO; } } From 5596bf1bbf77742e63d098ebc6240189237b3e78 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 19 Jan 2021 14:01:29 +0800 Subject: [PATCH 07/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=B8=8E=E7=AC=AC=E4=B8=89=E6=96=B9=E5=B9=B3=E5=8F=B0=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/commons/thirdplat/DemoApp.java | 1 + .../apiservice/jcet/JcetApiService.java | 58 ++++++++++++------- .../thirdplat/constants/JcetApiUrls.java | 8 --- .../thirdplat/constants/JcetConstants.java | 14 +++++ .../tools/utils/HttpClientManager.java | 48 +++++++++++++++ 5 files changed, 99 insertions(+), 30 deletions(-) delete mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetConstants.java diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java index 92d525b186..43b27e385b 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java @@ -2,6 +2,7 @@ package com.epmet.commons.thirdplat; import com.alibaba.fastjson.JSON; import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO; +import com.epmet.commons.thirdplat.dto.form.jcet.SsoTokenFormDTO; import com.epmet.commons.thirdplat.encrypt.SignUtils; import java.io.UnsupportedEncodingException; diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java index ca2e1ac1a8..7100d71b3b 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -2,8 +2,9 @@ package com.epmet.commons.thirdplat.apiservice.jcet; import com.alibaba.fastjson.JSON; import com.epmet.commons.thirdplat.apiservice.AbstractApiService; -import com.epmet.commons.thirdplat.constants.JcetApiUrls; +import com.epmet.commons.thirdplat.constants.JcetConstants; import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO; +import com.epmet.commons.thirdplat.dto.form.jcet.SsoTokenFormDTO; import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; import com.epmet.commons.thirdplat.encrypt.SignUtils; import com.epmet.commons.thirdplat.properties.JcetThirdplatProps; @@ -26,35 +27,47 @@ public class JcetApiService extends AbstractApiService { jcetThirdplatProps = props.getJcet(); } - public UserInfoResultDTO login(String ticket) { - - try { - UserInfoResultDTO userInfoByTicket = getUserInfoByTicket(ticket); - // todo - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - return null; - } - + /** + * @return + * @Description 通过第三方平台ticket获取用户信息 + * @author wxz + * @date 2021.01.19 10:26 + */ public UserInfoResultDTO getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); ssoTicket.setSsoTicket(ticket); - Result result = HttpClientManager.getInstance().sendPostByJSONAndHeader( - jcetThirdplatProps.getDomain().concat(JcetApiUrls.GET_USER_BY_TICKET), - JSON.toJSONString(ssoTicket), getHeaders(ssoTicket)); + + String domain = jcetThirdplatProps.getDomain(); + Result result = HttpClientManager.getInstance().sendPost( + domain.concat(JcetConstants.URL_GET_USER_BY_TICKET), + domain.startsWith("https://"), + JSON.toJSONString(ssoTicket), + getHeaders(ssoTicket)); UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); return resultDTO; } - private UserInfoResultDTO getUserInfoByToken(String ticket) throws UnsupportedEncodingException { - SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); - ssoTicket.setSsoTicket(ticket); - Result result = HttpClientManager.getInstance().sendPostByJSONAndHeader( - jcetThirdplatProps.getDomain().concat(JcetApiUrls.GET_USER_BY_TICKET), - JSON.toJSONString(ssoTicket), getHeaders(ssoTicket)); + /** + * @return + * @Description 通过token获取用户信息 + * @author wxz + * @date 2021.01.19 10:28 + */ + public UserInfoResultDTO getUserInfoByToken(String token) throws UnsupportedEncodingException { + SsoTokenFormDTO ssoToken = new SsoTokenFormDTO(); + ssoToken.setSsoToken(token); + + HashMap paramMap = new HashMap<>(); + paramMap.put(JcetConstants.PLAT_TOKEN_NAME, token); + + String domain = jcetThirdplatProps.getDomain(); + + Result result = HttpClientManager.getInstance().sendGet( + domain.concat(JcetConstants.URL_GET_USER_BY_TOKEN), + domain.startsWith("https://"), + paramMap, + getHeaders(ssoToken)); UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); return resultDTO; @@ -62,6 +75,7 @@ public class JcetApiService extends AbstractApiService { /** * 获取请求所需要的头信息 + * * @param contentObject * @return * @throws UnsupportedEncodingException diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java deleted file mode 100644 index ee0438c5cd..0000000000 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.epmet.commons.thirdplat.constants; - -public interface JcetApiUrls { - - // 根据ticket查询用户 - String GET_USER_BY_TICKET = "/openapi-cgw/openapi-login/sso/getUserInfoByTicket"; - -} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetConstants.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetConstants.java new file mode 100644 index 0000000000..34d4995bd7 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetConstants.java @@ -0,0 +1,14 @@ +package com.epmet.commons.thirdplat.constants; + +public interface JcetConstants { + + String URL_GET_USER_BY_TICKET = "/openapi-cgw/openapi-login/sso/getUserInfoByTicket"; + String URL_GET_USER_BY_TOKEN = "/openapi-cgw/openapi-login/sso/getUserInfoByToken"; + + String PLAT_TICKET_NAME = "ssoTicket"; + String PLAT_TOKEN_NAME = "ssoToken"; + + String PLAT_HEADER_OPEN_TIMESTAMP = "openTimestamp"; + String PLAT_HEADER_OPEN_APP_ID = "openAppId"; + String PLAT_HEADER_OPEN_SIGN = "openSign"; +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java index ff83e56210..0c83bfdede 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java @@ -188,6 +188,29 @@ public class HttpClientManager { } + public Result sendPost(String url, boolean isHttps, String jsonStrParam,Map headerMap) { + + try { + HttpPost httppost = new HttpPost(url); + httppost.setConfig(requestConfig); + httppost.addHeader(HEADER_CONTENT_TYPE, HEADER_APPLICATION_JSON); + if (null != headerMap){ + headerMap.forEach((k,v) -> { + httppost.addHeader(k,v); + }); + } + if (StringUtils.isNotEmpty(jsonStrParam)) { + StringEntity se = new StringEntity(jsonStrParam, UTF8); + httppost.setEntity(se); + } + return execute(httppost, isHttps); + } catch (Exception e) { + log.error("send exception", e); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); + } + + } + /** * 上传临时素材 * @author zhaoqifeng @@ -325,6 +348,31 @@ public class HttpClientManager { } } + public Result sendGet(String url, boolean isHttps, Map params, Map headerMap) { + + try { + URIBuilder builder = new URIBuilder(url); + if (!CollectionUtils.isEmpty(params)) { + Set set = params.keySet(); + for (String key : set) { + builder.setParameter(key, params.get(key) == null ? "" : String.valueOf(params.get(key))); + } + } + + HttpGet httpGet = new HttpGet(builder.build()); + httpGet.setConfig(requestConfig); + if (null != headerMap){ + headerMap.forEach((k,v) -> { + httpGet.addHeader(k,v); + }); + } + return execute(httpGet, isHttps); + } catch (Exception e) { + log.error("sendGet exception", e); + return new Result().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); + } + } + private Result execute(HttpRequestBase httpMethod, boolean isHttps) { CloseableHttpResponse response = null; try { From 4c43dca2ade36d1f8f6069b53ee364d22278beda Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 19 Jan 2021 14:08:58 +0800 Subject: [PATCH 08/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/epmet/constant/SsoConstant.java | 18 +++ .../com/epmet/controller/SsoController.java | 24 +++ .../com/epmet/dto/form/SsoLoginFormDTO.java | 39 +++++ .../epmet/dto/result/SsoLoginResultDTO.java | 21 +++ .../main/java/com/epmet/redis/SsoRedis.java | 39 +++++ .../java/com/epmet/service/SsoService.java | 12 ++ .../epmet/service/impl/SsoServiceImpl.java | 143 ++++++++++++++++++ .../com/epmet/dto/form/UserInfoFormDTO.java | 40 +++++ .../epmet/feign/EpmetUserOpenFeignClient.java | 9 ++ .../EpmetUserOpenFeignClientFallback.java | 5 + .../java/com/epmet/constant/UserConstant.java | 5 + .../com/epmet/controller/UserController.java | 12 ++ .../java/com/epmet/dao/UserWechatDao.java | 18 +++ .../java/com/epmet/service/UserService.java | 8 + .../epmet/service/impl/UserServiceImpl.java | 42 +++++ .../main/resources/mapper/UserWechatDao.xml | 29 ++++ 16 files changed, 464 insertions(+) create mode 100644 epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java create mode 100644 epmet-auth/src/main/java/com/epmet/dto/form/SsoLoginFormDTO.java create mode 100644 epmet-auth/src/main/java/com/epmet/dto/result/SsoLoginResultDTO.java create mode 100644 epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java create mode 100644 epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserInfoFormDTO.java diff --git a/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java new file mode 100644 index 0000000000..b3b86fd45d --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java @@ -0,0 +1,18 @@ +package com.epmet.constant; + +/** + * @Author zxc + * @DateTime 2021/1/19 上午10:26 + */ +public interface SsoConstant { + + /** + * 酒城e通appId + */ + String WINE_CITY_E_OPEN_APP_ID = ""; + + String USER_INFO_IS_NULL = "【jcetApiService.getUserInfoByTicket(formDTO.getTicket()】结果为空......"; + + String INSERT_UPDATE_USER_FAILURE = "新增或更新user_weChat失败......"; + +} diff --git a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java index 117a891f2c..3251b5a06c 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java @@ -1,5 +1,13 @@ package com.epmet.controller; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.SsoLoginFormDTO; +import com.epmet.dto.result.SsoLoginResultDTO; +import com.epmet.service.SsoService; +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; @@ -10,4 +18,20 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("sso/resi") public class SsoController { + + @Autowired + private SsoService ssoService; + + /** + * @Description 0、入口:得到token + * @Param formDTO + * @author zxc + * @date 2021/1/18 下午4:59 + */ + @PostMapping("login") + public Result ssoLogin(@RequestBody SsoLoginFormDTO formDTO){ + ValidatorUtils.validateEntity(formDTO, SsoLoginFormDTO.SsoLoginForm.class); + return new Result().ok(ssoService.ssoLogin(formDTO)); + } + } diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/SsoLoginFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/SsoLoginFormDTO.java new file mode 100644 index 0000000000..b50818d3cc --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/form/SsoLoginFormDTO.java @@ -0,0 +1,39 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午4:43 + */ +@Data +public class SsoLoginFormDTO implements Serializable { + + private static final long serialVersionUID = -6543952487970013031L; + + public interface SsoLoginForm{} + + /** + * sso票据,有效期为300秒 + */ + @NotBlank(message = "sso票据不能为空",groups = SsoLoginForm.class) + private String ticket; + + /** + * 三方平台应用AppId + */ + @NotBlank(message = "三方平台应用AppId不能为空",groups = SsoLoginForm.class) + private String appId; + + /** + * app类型 resi;居民段,work:工作端 + */ + @NotBlank(message = "app不能为空",groups = SsoLoginForm.class) + private String app; + + @NotBlank(message = "client不能为空",groups = SsoLoginForm.class) + private String client; +} diff --git a/epmet-auth/src/main/java/com/epmet/dto/result/SsoLoginResultDTO.java b/epmet-auth/src/main/java/com/epmet/dto/result/SsoLoginResultDTO.java new file mode 100644 index 0000000000..09e4bdb32d --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dto/result/SsoLoginResultDTO.java @@ -0,0 +1,21 @@ +package com.epmet.dto.result; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午4:45 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SsoLoginResultDTO implements Serializable { + + private static final long serialVersionUID = 3491079788196180035L; + + private String token = ""; +} diff --git a/epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java b/epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java new file mode 100644 index 0000000000..4bd3f1e0fb --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java @@ -0,0 +1,39 @@ +package com.epmet.redis; + +import cn.hutool.core.bean.BeanUtil; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.security.dto.TokenDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午5:09 + */ +@Component +public class SsoRedis { + + @Autowired + private RedisUtils redisUtils; + + /** + * @Description token放入缓存 + * @Param user + * @Param expire + * @author zxc + * @date 2021/1/18 下午5:10 + */ + public void set(TokenDto user, long expire) { + if (user == null) { + return; + } + String key = RedisKeys.getCpUserKey(user.getApp(), "wxmp", user.getUserId()); + //bean to map + Map map = BeanUtil.beanToMap(user, false, true); + redisUtils.hMSet(key, map, expire); + } + +} diff --git a/epmet-auth/src/main/java/com/epmet/service/SsoService.java b/epmet-auth/src/main/java/com/epmet/service/SsoService.java index d65cbcfe95..3cbd2b9af2 100644 --- a/epmet-auth/src/main/java/com/epmet/service/SsoService.java +++ b/epmet-auth/src/main/java/com/epmet/service/SsoService.java @@ -1,8 +1,20 @@ package com.epmet.service; +import com.epmet.dto.form.SsoLoginFormDTO; +import com.epmet.dto.result.SsoLoginResultDTO; + /** * @Author zxc * @DateTime 2021/1/18 下午4:34 */ public interface SsoService { + + /** + * @Description 0、入口:得到token + * @Param formDTO + * @author zxc + * @date 2021/1/18 下午4:59 + */ + SsoLoginResultDTO ssoLogin(SsoLoginFormDTO formDTO); + } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index c40737fd92..3872ae1faf 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -1,9 +1,34 @@ package com.epmet.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; +import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.commons.tools.utils.HttpClientManager; +import com.epmet.commons.tools.utils.Result; +import com.epmet.constant.SsoConstant; +import com.epmet.dto.PaCustomerDTO; +import com.epmet.dto.UserDTO; +import com.epmet.dto.form.SsoLoginFormDTO; +import com.epmet.dto.form.UserInfoFormDTO; +import com.epmet.dto.result.SsoLoginResultDTO; +import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.jwt.JwtTokenProperties; +import com.epmet.jwt.JwtTokenUtils; +import com.epmet.redis.SsoRedis; import com.epmet.service.SsoService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; + /** * @Author zxc * @DateTime 2021/1/18 下午4:35 @@ -11,4 +36,122 @@ import org.springframework.stereotype.Service; @Service @Slf4j public class SsoServiceImpl implements SsoService { + + @Autowired + private SsoRedis ssoRedis; + + @Autowired + private JwtTokenUtils jwtTokenUtils; + + @Autowired + private JwtTokenProperties jwtTokenProperties; + + @Autowired + private JcetApiService jcetApiService; + + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + + /** + * @Description 0、入口:得到token + * @Param formDTO + * @author zxc + * @date 2021/1/18 下午4:59 + */ + @Override + public SsoLoginResultDTO ssoLogin(SsoLoginFormDTO formDTO) { + String userId = ""; + if (formDTO.getAppId().equals(SsoConstant.WINE_CITY_E_OPEN_APP_ID)) { + UserInfoResultDTO userInfo = null; + try { + userInfo = jcetApiService.getUserInfoByTicket(formDTO.getTicket()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + if (null == userInfo){ + throw new RenException(SsoConstant.USER_INFO_IS_NULL); + } + UserInfoFormDTO userInfoFormDTO = ConvertUtils.sourceToTarget(userInfo, UserInfoFormDTO.class); + userInfoFormDTO.setApp(formDTO.getApp()); + Result userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); + if (!userDTOResult.success()){ + throw new RenException(SsoConstant.INSERT_UPDATE_USER_FAILURE); + } + userId = userDTOResult.getData().getId(); + } + //生成业务token + String token = this.generateToken(formDTO.getApp(),formDTO.getClient(), userId); + //存放Redis + this.disposeTokenDto(formDTO, userId, token, getCustomerId(formDTO.getAppId())); + return new SsoLoginResultDTO(token); + } + + /** + * @Description token放缓存 + * @Param formDTO + * @Param userId + * @Param token + * @Param customerId + * @author zxc + * @date 2021/1/18 下午5:32 + */ + public void disposeTokenDto(SsoLoginFormDTO formDTO, String userId, String token, String customerId){ + int expire = jwtTokenProperties.getExpire(); + TokenDto tokenDto = new TokenDto(); + tokenDto.setCustomerId(customerId); + tokenDto.setApp(formDTO.getApp()); + tokenDto.setClient(formDTO.getClient()); + tokenDto.setUserId(userId); + tokenDto.setToken(token); + tokenDto.setUpdateTime(System.currentTimeMillis()); + tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); + ssoRedis.set(tokenDto, expire); + log.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); + } + + /** + * @Description 居民端登陆生成业务token的key + * @Param app + * @Param client + * @Param userId + * @author zxc + * @date 2021/1/18 下午5:14 + */ + private String generateToken(String app,String client, String userId) { + Map map = new HashMap<>(16); + map.put("app", app); + map.put("client", client); + map.put("userId", userId); + String token = jwtTokenUtils.createToken(map); + log.info("app:" + app + ";client:" + client + ";userId:" + userId + ";生成token[" + token + "]"); + return token; + } + + /** + * @Description 获取customerId + * @Param appId + * @author zxc + * @date 2021/1/19 下午1:47 + */ + public String getCustomerId(String appId){ + JSONObject jsonObject = new JSONObject(); + String customerMsgUrl = "https://epmet-cloud.elinkservice.cn/api/third/customermp/getcustomermsg/"; + String data = HttpClientManager.getInstance().sendPostByJSON(customerMsgUrl + appId, JSON.toJSONString(jsonObject)).getData(); + log.info("调用third服务,根据appId查询客户信息:httpclient->url:" + customerMsgUrl + ",结果->" + data); + JSONObject toResult = JSON.parseObject(data); + Result mapToResult = ConvertUtils.mapToEntity(toResult, Result.class); + if (null != toResult.get("code")) { + mapToResult.setCode(((Integer) toResult.get("code")).intValue()); + } + if (!mapToResult.success()) { + log.error(String.format("根据appId查询客户信息失败,对应appId->" + appId)); + throw new RenException(mapToResult.getMsg()); + } + Object publicCustomerResultDTO = mapToResult.getData(); + JSONObject json = JSON.parseObject(publicCustomerResultDTO.toString()); + Map map = (Map) json.get("customer"); + PaCustomerDTO customer = ConvertUtils.mapToEntity(map, PaCustomerDTO.class); + log.info("小程序登陆third服务获取客户用户信息PaCustomerDTO->" + customer); + return customer.getId(); + } } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserInfoFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserInfoFormDTO.java new file mode 100644 index 0000000000..6c349d424e --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserInfoFormDTO.java @@ -0,0 +1,40 @@ +package com.epmet.dto.form; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2021/1/19 上午10:31 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class UserInfoFormDTO implements Serializable { + + private static final long serialVersionUID = 3394557656494741201L; + + public interface UserInfoForm{} + + /** + * 工作端:WORK、居民端:resi、运营端:oper + */ + @NotBlank(message = "app类型不能为空",groups = {UserInfoForm.class}) + private String app; + + /** + * UID 用户唯一标识 即wx_open_id + */ + @NotBlank(message = "UID不能为空",groups = {UserInfoForm.class}) + private String uid; + + private String name; + private String mobile; + private String account; + + private String userId; +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index b31f94ddff..2e8729fb15 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -469,4 +469,13 @@ public interface EpmetUserOpenFeignClient { @PostMapping(value = "epmetuser/staffrole/specificrolesstaffs", consumes = MediaType.APPLICATION_JSON_VALUE) Result> specificRolesStaffs(RolesUsersListFormDTO rolesUsersListFormDTO); + + /** + * @Description 新增或更新用户信息 + * @Param formDTO + * @author zxc + * @date 2021/1/19 上午10:35 + */ + @PostMapping(value = "/epmetuser/user/saveuserinfo") + Result saveUserInfo(@RequestBody UserInfoFormDTO formDTO); } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java index 69371a19cd..3ed6c85e73 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java @@ -331,4 +331,9 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien public Result> specificRolesStaffs(RolesUsersListFormDTO rolesUsersListFormDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "specificRolesStaffs", rolesUsersListFormDTO); } + + @Override + public Result saveUserInfo(UserInfoFormDTO formDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "saveUserInfo", formDTO); + } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserConstant.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserConstant.java index a82038d368..2214369866 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserConstant.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserConstant.java @@ -28,6 +28,11 @@ public interface UserConstant { */ String CLIENT_WEB = "web"; + /** + * app + */ + String APP = "app"; + /** * 微信端 */ diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/UserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/UserController.java index a5959e0825..a88a812828 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/UserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/UserController.java @@ -154,4 +154,16 @@ public class UserController { return new Result().ok(userService.getUserBasicInfo(formDTO)); } + /** + * @Description 新增或更新用户信息 + * @Param formDTO + * @author zxc + * @date 2021/1/19 上午10:35 + */ + @PostMapping("saveuserinfo") + public Result saveUserInfo(@RequestBody UserInfoFormDTO formDTO){ + ValidatorUtils.validateEntity(formDTO, UserInfoFormDTO.UserInfoForm.class); + return new Result().ok(userService.saveUserInfo(formDTO)); + } + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/UserWechatDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/UserWechatDao.java index d0f6b2def7..bd6839ac59 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/UserWechatDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/UserWechatDao.java @@ -4,6 +4,7 @@ import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.UserDTO; import com.epmet.dto.UserHeadPhotoDTO; import com.epmet.dto.UserWechatDTO; +import com.epmet.dto.form.UserInfoFormDTO; import com.epmet.dto.form.WxLoginUserInfoFormDTO; import com.epmet.dto.result.CertifiedResultDTO; import com.epmet.dto.result.CustomerUser4PointResultDTO; @@ -77,4 +78,21 @@ public interface UserWechatDao extends BaseDao{ //临时用下in List selectNotInUserBaseInfoTemp(); + + /** + * @Description 根据app、uid查询用户是否存在 + * @Param uid + * @Param app + * @author zxc + * @date 2021/1/19 上午10:42 + */ + UserDTO selectUserDTOByUid(@Param("uid")String uid,@Param("app")String app); + + /** + * @Description 修改user_weChat信息 + * @Param formDTO + * @author zxc + * @date 2021/1/19 上午11:04 + */ + int editByUserId(UserInfoFormDTO formDTO); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/UserService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/UserService.java index b83d85af51..cc2fb1aecf 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/UserService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/UserService.java @@ -86,4 +86,12 @@ public interface UserService extends BaseService { * @Description 居民端-查询用户基础信息 **/ UserBasicInfo getUserBasicInfo(UserBasicInfoFormDTO formDTO); + + /** + * @Description 新增或更新用户信息 + * @Param formDTO + * @author zxc + * @date 2021/1/19 上午10:35 + */ + UserDTO saveUserInfo(UserInfoFormDTO formDTO); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java index 103a7a16c0..fe21e876d8 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java @@ -279,4 +279,46 @@ public class UserServiceImpl extends BaseServiceImpl implem return baseDao.selectUserBasicInfo(formDTO); } + /** + * @Description 新增或更新用户信息 + * @Param formDTO + * @author zxc + * @date 2021/1/19 上午10:35 + */ + @Override + public UserDTO saveUserInfo(UserInfoFormDTO formDTO) { + UserDTO result = new UserDTO(); + UserDTO userDTO = userWechatDao.selectUserDTOByUid(formDTO.getUid(), formDTO.getApp()); + if (null == userDTO){ + // 用户不存在 + //user表新增 + UserEntity userEntity = new UserEntity(); + userEntity.setFromApp(UserConstant.APP_RESI); + userEntity.setFromClient(UserConstant.APP); + if (baseDao.insert(userEntity) < NumConstant.ONE) { + log.error("小程序登陆,居民端user表新增数据失败"); + throw new RenException(UserConstant.SAVE_USER); + } + UserWechatEntity entity = new UserWechatEntity(); + entity.setMobile(formDTO.getMobile()); + entity.setUserId(userEntity.getId()); + entity.setNickname(formDTO.getName()); + entity.setWxOpenId(formDTO.getUid()); + if (userWechatDao.insert(entity) < NumConstant.ONE) { + log.error("小程序登陆,居民端user_wechat表新增数据失败"); + throw new RenException(UserConstant.SAVE_USER_WECHAT); + } + result.setId(userEntity.getId()); + }else { + // 用户已存在 + formDTO.setUserId(userDTO.getId()); + if (userWechatDao.editByUserId(formDTO) < NumConstant.ONE) { + log.error("小程序登陆,居民端user_weChat表更新数据失败"); + throw new RenException(UserConstant.UPDATE_USER_WECHAT); + } + result.setId(userDTO.getId()); + } + return result; + } + } diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/UserWechatDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/UserWechatDao.xml index d51c98cf19..f59dc05973 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/UserWechatDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/UserWechatDao.xml @@ -38,6 +38,24 @@ USER_ID = #{userId} + + + UPDATE user_wechat + + + NICKNAME = #{name}, + + + MOBILE = #{mobile}, + + UPDATED_BY = #{userId}, + UPDATED_TIME = NOW() + + WHERE + DEL_FLAG = 0 + AND USER_ID = #{userId} + + + + + From 2fbbe4b4e99d6672484951e88514fed4f70ba7cb Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 19 Jan 2021 14:45:29 +0800 Subject: [PATCH 09/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/constant/SsoConstant.java | 3 +++ .../java/com/epmet/service/impl/SsoServiceImpl.java | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java index b3b86fd45d..88b4f56389 100644 --- a/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java +++ b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java @@ -15,4 +15,7 @@ public interface SsoConstant { String INSERT_UPDATE_USER_FAILURE = "新增或更新user_weChat失败......"; + String USER_ID_IS_NULL = "userId为空,生成token失败......"; + String CUSTOMER_ID_IS_NULL = "customerId为空,缓存放置token失败......"; + } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index 3872ae1faf..bafae81684 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -22,6 +22,7 @@ import com.epmet.jwt.JwtTokenUtils; import com.epmet.redis.SsoRedis; import com.epmet.service.SsoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -79,10 +80,17 @@ public class SsoServiceImpl implements SsoService { } userId = userDTOResult.getData().getId(); } + if (StringUtils.isBlank(userId)){ + throw new RenException(SsoConstant.USER_ID_IS_NULL); + } //生成业务token String token = this.generateToken(formDTO.getApp(),formDTO.getClient(), userId); //存放Redis - this.disposeTokenDto(formDTO, userId, token, getCustomerId(formDTO.getAppId())); + String customerId = getCustomerId(formDTO.getAppId()); + if (StringUtils.isBlank(customerId)){ + throw new RenException(SsoConstant.CUSTOMER_ID_IS_NULL); + } + this.disposeTokenDto(formDTO, userId, token, customerId); return new SsoLoginResultDTO(token); } From 37bac23a5fa03ee24b90ed550ac9927419202ba1 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 19 Jan 2021 15:56:20 +0800 Subject: [PATCH 10/25] =?UTF-8?q?=E5=B0=86jcetApiService=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=8C=96=EF=BC=8C=E4=BB=8E@Component=E6=94=B9?= =?UTF-8?q?=E4=B8=BAThirdplatConfig=E4=B8=AD=E7=BB=9F=E4=B8=80=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/thirdplat/apiservice/jcet/JcetApiService.java | 2 -- .../epmet/commons/thirdplat/config/ThirdplatConfig.java | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java index 7100d71b3b..b6a01d729d 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -11,13 +11,11 @@ import com.epmet.commons.thirdplat.properties.JcetThirdplatProps; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.commons.tools.utils.Result; -import org.springframework.stereotype.Component; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; -@Component public class JcetApiService extends AbstractApiService { private JcetThirdplatProps jcetThirdplatProps; diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java index 16258ed150..4e8f0dbf3d 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java @@ -1,7 +1,9 @@ package com.epmet.commons.thirdplat.config; +import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -11,4 +13,9 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(ThirdplatProps.class) public class ThirdplatConfig { + @Bean + public JcetApiService JcetApiService(ThirdplatProps props) { + return new JcetApiService(props); + } + } From 9c6835bb48f3fcc1dbeb30d9804ab2f5bb720ee4 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 19 Jan 2021 16:11:20 +0800 Subject: [PATCH 11/25] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E7=94=9F=E6=88=90=E7=AD=BE=E5=90=8D=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=E4=BB=A3=E6=9B=BF=E9=AD=94=E6=B3=95=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/thirdplat/apiservice/jcet/JcetApiService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java index b6a01d729d..b24803fa09 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -83,10 +83,10 @@ public class JcetApiService extends AbstractApiService { Map headers = new HashMap(); long timestamp = System.currentTimeMillis(); - headers.put("openTimestamp", String.valueOf(timestamp)); - headers.put("openAppId", jcetThirdplatProps.getAppkey()); + headers.put(JcetConstants.PLAT_HEADER_OPEN_TIMESTAMP, String.valueOf(timestamp)); + headers.put(JcetConstants.PLAT_HEADER_OPEN_APP_ID, jcetThirdplatProps.getAppkey()); String encryptContent = jcetThirdplatProps.getAppkey() + timestamp + bodyLength; - headers.put("openSign", SignUtils.generate(encryptContent, jcetThirdplatProps.getAppsecret())); + headers.put(JcetConstants.PLAT_HEADER_OPEN_SIGN, SignUtils.generate(encryptContent, jcetThirdplatProps.getAppsecret())); return headers; } From 9d7b1cfff265a1a659278fdedc50099841f83bf0 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 19 Jan 2021 17:49:01 +0800 Subject: [PATCH 12/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java index 88b4f56389..235525cfe8 100644 --- a/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java +++ b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java @@ -9,7 +9,7 @@ public interface SsoConstant { /** * 酒城e通appId */ - String WINE_CITY_E_OPEN_APP_ID = ""; + String WINE_CITY_E_OPEN_APP_ID = "hw0f263b5d3dc4f7c5"; String USER_INFO_IS_NULL = "【jcetApiService.getUserInfoByTicket(formDTO.getTicket()】结果为空......"; From facda9c629e266b487c809fce525858fe183a850 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 19 Jan 2021 18:20:24 +0800 Subject: [PATCH 13/25] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=EF=BC=9A=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7byTicket=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/controller/SsoController.java | 18 ++++++++++++++ .../apiservice/AbstractApiService.java | 4 +++- .../dto/result/jcet/UserInfoResultDTO.java | 24 +++++++++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java index 3251b5a06c..cc53f86f2e 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java @@ -1,5 +1,7 @@ package com.epmet.controller; +import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; +import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.SsoLoginFormDTO; @@ -11,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.io.UnsupportedEncodingException; + /** * @Author zxc * @DateTime 2021/1/18 下午4:33 @@ -22,6 +26,9 @@ public class SsoController { @Autowired private SsoService ssoService; + @Autowired + private JcetApiService jcetApiService; + /** * @Description 0、入口:得到token * @Param formDTO @@ -34,4 +41,15 @@ public class SsoController { return new Result().ok(ssoService.ssoLogin(formDTO)); } + @PostMapping("testlogin") + public Result testssoLogin(){ + UserInfoResultDTO userInfoByTicket = null; + try { + userInfoByTicket = jcetApiService.getUserInfoByTicket("ssoTicket-vYtMRuXAQZri3wpA2vyq5D8n3Q9oO7ui"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return new Result().ok(userInfoByTicket); + } + } diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java index 7950526fd1..b0aa1e0d0b 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java @@ -1,6 +1,7 @@ package com.epmet.commons.thirdplat.apiservice; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.epmet.commons.thirdplat.dto.result.jcet.JcetResult; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import com.epmet.commons.tools.exception.EpmetErrorCode; @@ -29,6 +30,7 @@ public class AbstractApiService { jcetResult.getMsg().concat(",错误码:") + jcetResult.getCode()); } - return JSON.parseObject(jcetResult.getMsg(), resultType); + JSONObject jo = (JSONObject) jcetResult.getData(); + return jo.toJavaObject(resultType); } } diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java index 5adf33436d..09fc1bcace 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java @@ -4,10 +4,26 @@ import lombok.Data; @Data public class UserInfoResultDTO { - - private String name; + private String id; + /** + * 用户名称 + */ + private String userName; + /** + * 手机号码 + */ private String mobile; - private String uid; - private String account; + /** + * 姓名 + */ + private String name; + /** + * 邮箱 + */ + private String email; + /** + * sessionId,用于维持在线状态 + */ + private String oaSessionId; } From 0d4c800432443f53f16b4402e60e2d74dc8c545d Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 19 Jan 2021 18:27:23 +0800 Subject: [PATCH 14/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/service/impl/SsoServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index bafae81684..482738566f 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -74,6 +74,8 @@ public class SsoServiceImpl implements SsoService { } UserInfoFormDTO userInfoFormDTO = ConvertUtils.sourceToTarget(userInfo, UserInfoFormDTO.class); userInfoFormDTO.setApp(formDTO.getApp()); + userInfoFormDTO.setUid(userInfo.getId()); + userInfoFormDTO.setName(userInfo.getUserName()); Result userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); if (!userDTOResult.success()){ throw new RenException(SsoConstant.INSERT_UPDATE_USER_FAILURE); From 3d1a571cd3ba2e0ef8c86ff0510afab517279dc6 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Wed, 20 Jan 2021 09:46:53 +0800 Subject: [PATCH 15/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/controller/SsoController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java index cc53f86f2e..0d63d18538 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java @@ -20,7 +20,7 @@ import java.io.UnsupportedEncodingException; * @DateTime 2021/1/18 下午4:33 */ @RestController -@RequestMapping("sso/resi") +@RequestMapping("sso") public class SsoController { @Autowired @@ -35,7 +35,7 @@ public class SsoController { * @author zxc * @date 2021/1/18 下午4:59 */ - @PostMapping("login") + @PostMapping("resi/login") public Result ssoLogin(@RequestBody SsoLoginFormDTO formDTO){ ValidatorUtils.validateEntity(formDTO, SsoLoginFormDTO.SsoLoginForm.class); return new Result().ok(ssoService.ssoLogin(formDTO)); From 60b3184fea5167943e14aebe87987f7deddbe20e Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Wed, 20 Jan 2021 09:49:55 +0800 Subject: [PATCH 16/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java index 235525cfe8..e7da64ccff 100644 --- a/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java +++ b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java @@ -9,7 +9,7 @@ public interface SsoConstant { /** * 酒城e通appId */ - String WINE_CITY_E_OPEN_APP_ID = "hw0f263b5d3dc4f7c5"; + String WINE_CITY_E_OPEN_APP_ID = "64929543"; String USER_INFO_IS_NULL = "【jcetApiService.getUserInfoByTicket(formDTO.getTicket()】结果为空......"; From 1cb0bc2ec9d6a72c702cbe70078f37be0470e3bd Mon Sep 17 00:00:00 2001 From: wangchao Date: Wed, 20 Jan 2021 13:44:37 +0800 Subject: [PATCH 17/25] =?UTF-8?q?/sso=20=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9C=80=E8=BF=91=E8=AE=BF=E9=97=AE=E7=9A=84=E7=BD=91?= =?UTF-8?q?=E6=A0=BC=E8=AF=B7=E6=B1=82=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/modules/grid/controller/ResiMineGridController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java index e025d6ccc3..7ea7b24f3d 100644 --- a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java +++ b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/grid/controller/ResiMineGridController.java @@ -70,7 +70,7 @@ public class ResiMineGridController { * @Description 获取用户最近访问网格 * @Date 2020/3/24 11:10 **/ - @GetMapping("sso/latestgridinfo") + @PostMapping("sso/latestgridinfo") public Result latestGridInfo(@LoginUser TokenDto tokenDto){ LatestGridInfoResultDTO latestGridInfoResultDTO=resiMineGridService.getLatestGridInfoH5(tokenDto); return new Result().ok(latestGridInfoResultDTO); From 9ae6528aaa19a80810528e9c15e0980e73b78165 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Wed, 20 Jan 2021 14:28:00 +0800 Subject: [PATCH 18/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/service/impl/SsoServiceImpl.java | 2 +- .../src/main/java/com/epmet/service/impl/UserServiceImpl.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index 482738566f..268b1b2f07 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -75,7 +75,7 @@ public class SsoServiceImpl implements SsoService { UserInfoFormDTO userInfoFormDTO = ConvertUtils.sourceToTarget(userInfo, UserInfoFormDTO.class); userInfoFormDTO.setApp(formDTO.getApp()); userInfoFormDTO.setUid(userInfo.getId()); - userInfoFormDTO.setName(userInfo.getUserName()); + userInfoFormDTO.setName(userInfo.getName()); Result userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); if (!userDTOResult.success()){ throw new RenException(SsoConstant.INSERT_UPDATE_USER_FAILURE); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java index fe21e876d8..f821ff27da 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java @@ -304,6 +304,7 @@ public class UserServiceImpl extends BaseServiceImpl implem entity.setUserId(userEntity.getId()); entity.setNickname(formDTO.getName()); entity.setWxOpenId(formDTO.getUid()); + entity.setSex(NumConstant.ZERO); if (userWechatDao.insert(entity) < NumConstant.ONE) { log.error("小程序登陆,居民端user_wechat表新增数据失败"); throw new RenException(UserConstant.SAVE_USER_WECHAT); From cf4c1d02e76377ca56b634ffe2f85058245ec9f1 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Wed, 20 Jan 2021 14:36:23 +0800 Subject: [PATCH 19/25] =?UTF-8?q?login=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/service/impl/SsoServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index 268b1b2f07..c778d58498 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -76,6 +76,7 @@ public class SsoServiceImpl implements SsoService { userInfoFormDTO.setApp(formDTO.getApp()); userInfoFormDTO.setUid(userInfo.getId()); userInfoFormDTO.setName(userInfo.getName()); + userInfoFormDTO.setMobile(userInfo.getMobile()); Result userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); if (!userDTOResult.success()){ throw new RenException(SsoConstant.INSERT_UPDATE_USER_FAILURE); From 65558cd14f960d9513b46721693fd5bb68cfddf9 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 20 Jan 2021 14:50:43 +0800 Subject: [PATCH 20/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9sso=E7=99=BB=E5=BD=95?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E6=9B=B4=E7=81=B5=E6=B4=BB...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/service/impl/SsoServiceImpl.java | 20 ++++++++++--------- .../apiservice/AbstractApiService.java | 13 +++++++++++- .../thirdplat/bean/ThirdPlatUserInfo.java | 5 +++++ .../thirdplat/config/ThirdplatConfig.java | 9 ++++++++- .../constants/ApiServiceBeansConstants.java | 9 +++++++++ 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java create mode 100644 epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index 482738566f..34f6ee588b 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -2,14 +2,13 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.epmet.commons.thirdplat.apiservice.AbstractApiService; import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; +import com.epmet.commons.thirdplat.constants.ApiServiceBeansConstants; import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; -import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.utils.DateUtils; -import com.epmet.commons.tools.utils.HttpClientManager; -import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.*; import com.epmet.constant.SsoConstant; import com.epmet.dto.PaCustomerDTO; import com.epmet.dto.UserDTO; @@ -23,6 +22,8 @@ import com.epmet.redis.SsoRedis; import com.epmet.service.SsoService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -38,6 +39,8 @@ import java.util.Map; @Slf4j public class SsoServiceImpl implements SsoService { + Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired private SsoRedis ssoRedis; @@ -47,9 +50,6 @@ public class SsoServiceImpl implements SsoService { @Autowired private JwtTokenProperties jwtTokenProperties; - @Autowired - private JcetApiService jcetApiService; - @Autowired private EpmetUserOpenFeignClient epmetUserOpenFeignClient; @@ -65,8 +65,10 @@ public class SsoServiceImpl implements SsoService { if (formDTO.getAppId().equals(SsoConstant.WINE_CITY_E_OPEN_APP_ID)) { UserInfoResultDTO userInfo = null; try { - userInfo = jcetApiService.getUserInfoByTicket(formDTO.getTicket()); - } catch (UnsupportedEncodingException e) { + AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(ApiServiceBeansConstants.JCET_API_SERVICE); + userInfo = apiService.getUserInfoByTicket(formDTO.getTicket()); + } catch (Exception e) { + logger.error("调用第三方平台,根据用户ticket查询用户信息失败,错误信息"); e.printStackTrace(); } if (null == userInfo){ diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java index b0aa1e0d0b..3209a9ea44 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java @@ -3,15 +3,26 @@ package com.epmet.commons.thirdplat.apiservice; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.epmet.commons.thirdplat.dto.result.jcet.JcetResult; +import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; -public class AbstractApiService { +import java.io.UnsupportedEncodingException; + +public abstract class AbstractApiService { protected ThirdplatProps thirdplatProps; + /** + * 通过ticket查询用户信息 + * @param ticket + * @return + * @throws Exception + */ + public abstract UserInfoResultDTO getUserInfoByTicket(String ticket) throws Exception; + /** * @Description 解析请求结果 * @return diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java new file mode 100644 index 0000000000..365e142a0f --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java @@ -0,0 +1,5 @@ +package com.epmet.commons.thirdplat.bean; + +public class ThirdPlatUserInfo { + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java index 4e8f0dbf3d..11e941ab93 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java @@ -1,6 +1,7 @@ package com.epmet.commons.thirdplat.config; import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; +import com.epmet.commons.thirdplat.constants.ApiServiceBeansConstants; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -13,7 +14,13 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(ThirdplatProps.class) public class ThirdplatConfig { - @Bean + /** + * @Description 酒城e通的apiService,这个name需要注册进数据库,使用的时候去数据库根据客户id找对应的apiService出来用 + * @return + * @author wxz + * @date 2021.01.20 13:50 + */ + @Bean(name = ApiServiceBeansConstants.JCET_API_SERVICE) public JcetApiService JcetApiService(ThirdplatProps props) { return new JcetApiService(props); } diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java new file mode 100644 index 0000000000..2d79aebcfa --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/ApiServiceBeansConstants.java @@ -0,0 +1,9 @@ +package com.epmet.commons.thirdplat.constants; + +/** + * ApiService常量 + */ +public interface ApiServiceBeansConstants { + // 酒城e通apiService + String JCET_API_SERVICE = "jcetApiService"; +} From 3b2f78a0fd76e8af5587af6bd103299ec5165955 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 20 Jan 2021 16:37:34 +0800 Subject: [PATCH 21/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9sso=E7=99=BB=E5=BD=95?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E6=9B=B4=E7=81=B5=E6=B4=BB...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/controller/SsoController.java | 14 ++-- .../main/java/com/epmet/redis/SsoRedis.java | 2 +- .../epmet/service/impl/SsoServiceImpl.java | 75 +++++++++++-------- .../apiservice/AbstractApiService.java | 6 +- .../apiservice/jcet/JcetApiService.java | 51 +++++++------ .../thirdplat/bean/ThirdPlatUserInfo.java | 7 +- ...ultDTO.java => JcetUserInfoResultDTO.java} | 2 +- .../com/epmet/dto/form/ApiServiceFormDTO.java | 20 +++++ .../result/ThirdplatApiserviceResultDTO.java | 16 ++++ .../epmet/feign/OperCrmOpenFeignClient.java | 15 +++- .../OperCrmOpenFeignClientFallback.java | 11 ++- .../epmet/controller/CustomerController.java | 22 +++++- .../dao/CustomerThirdplatApiserviceDao.java | 36 +++++++++ .../CustomerThirdplatApiserviceEntity.java | 51 +++++++++++++ .../CustomerThirdplatApiServiceService.java | 16 ++++ ...ustomerThirdplatApiServiceServiceImpl.java | 20 +++++ .../V0.0.6__create_thirdplat_apiservice.sql | 14 ++++ .../mapper/CustomerThirdplatApiserviceDao.xml | 33 ++++++++ 18 files changed, 331 insertions(+), 80 deletions(-) rename epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/{UserInfoResultDTO.java => JcetUserInfoResultDTO.java} (92%) create mode 100644 epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/form/ApiServiceFormDTO.java create mode 100644 epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ThirdplatApiserviceResultDTO.java create mode 100644 epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java create mode 100644 epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerThirdplatApiserviceEntity.java create mode 100644 epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java create mode 100644 epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java create mode 100644 epmet-module/oper-crm/oper-crm-server/src/main/resources/db/migration/V0.0.6__create_thirdplat_apiservice.sql create mode 100644 epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml diff --git a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java index 0d63d18538..6d17e1a9a0 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/SsoController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java @@ -1,7 +1,7 @@ package com.epmet.controller; import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; -import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; +import com.epmet.commons.thirdplat.bean.ThirdPlatUserInfo; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.SsoLoginFormDTO; @@ -13,8 +13,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.UnsupportedEncodingException; - /** * @Author zxc * @DateTime 2021/1/18 下午4:33 @@ -41,15 +39,15 @@ public class SsoController { return new Result().ok(ssoService.ssoLogin(formDTO)); } - @PostMapping("testlogin") - public Result testssoLogin(){ - UserInfoResultDTO userInfoByTicket = null; + @PostMapping("test") + public Result testssoLogin(){ + ThirdPlatUserInfo userInfoByTicket = null; try { userInfoByTicket = jcetApiService.getUserInfoByTicket("ssoTicket-vYtMRuXAQZri3wpA2vyq5D8n3Q9oO7ui"); - } catch (UnsupportedEncodingException e) { + } catch (Exception e) { e.printStackTrace(); } - return new Result().ok(userInfoByTicket); + return new Result().ok(userInfoByTicket); } } diff --git a/epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java b/epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java index 4bd3f1e0fb..16ee7ab3ce 100644 --- a/epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java +++ b/epmet-auth/src/main/java/com/epmet/redis/SsoRedis.java @@ -30,7 +30,7 @@ public class SsoRedis { if (user == null) { return; } - String key = RedisKeys.getCpUserKey(user.getApp(), "wxmp", user.getUserId()); + String key = RedisKeys.getCpUserKey(user.getApp(), user.getClient(), user.getUserId()); //bean to map Map map = BeanUtil.beanToMap(user, false, true); redisUtils.hMSet(key, map, expire); diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index 75c463d94b..ede5acd988 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -3,19 +3,20 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.epmet.commons.thirdplat.apiservice.AbstractApiService; -import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; -import com.epmet.commons.thirdplat.constants.ApiServiceBeansConstants; -import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; +import com.epmet.commons.thirdplat.bean.ThirdPlatUserInfo; +import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.*; -import com.epmet.constant.SsoConstant; import com.epmet.dto.PaCustomerDTO; import com.epmet.dto.UserDTO; +import com.epmet.dto.form.ApiServiceFormDTO; import com.epmet.dto.form.SsoLoginFormDTO; import com.epmet.dto.form.UserInfoFormDTO; import com.epmet.dto.result.SsoLoginResultDTO; +import com.epmet.dto.result.ThirdplatApiserviceResultDTO; import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.feign.OperCrmOpenFeignClient; import com.epmet.jwt.JwtTokenProperties; import com.epmet.jwt.JwtTokenUtils; import com.epmet.redis.SsoRedis; @@ -27,7 +28,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; @@ -53,6 +53,9 @@ public class SsoServiceImpl implements SsoService { @Autowired private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + @Autowired + private OperCrmOpenFeignClient operCrmOpenFeignClient; + /** * @Description 0、入口:得到token * @Param formDTO @@ -61,39 +64,51 @@ public class SsoServiceImpl implements SsoService { */ @Override public SsoLoginResultDTO ssoLogin(SsoLoginFormDTO formDTO) { + String customerId = getCustomerId(formDTO.getAppId()); String userId = ""; - if (formDTO.getAppId().equals(SsoConstant.WINE_CITY_E_OPEN_APP_ID)) { - UserInfoResultDTO userInfo = null; - try { - AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(ApiServiceBeansConstants.JCET_API_SERVICE); - userInfo = apiService.getUserInfoByTicket(formDTO.getTicket()); - } catch (Exception e) { - logger.error("调用第三方平台,根据用户ticket查询用户信息失败,错误信息"); - e.printStackTrace(); - } - if (null == userInfo){ - throw new RenException(SsoConstant.USER_INFO_IS_NULL); - } - UserInfoFormDTO userInfoFormDTO = ConvertUtils.sourceToTarget(userInfo, UserInfoFormDTO.class); - userInfoFormDTO.setApp(formDTO.getApp()); - userInfoFormDTO.setUid(userInfo.getId()); - userInfoFormDTO.setName(userInfo.getName()); - userInfoFormDTO.setMobile(userInfo.getMobile()); - Result userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); - if (!userDTOResult.success()){ - throw new RenException(SsoConstant.INSERT_UPDATE_USER_FAILURE); - } - userId = userDTOResult.getData().getId(); + + Result apiServiceResult = operCrmOpenFeignClient.getApiServiceByCustomerId(new ApiServiceFormDTO(customerId)); + if (!apiServiceResult.success()) { + throw new RenException("【SSO登录】调用OperCrm获取ApiService接口失败:", apiServiceResult.getInternalMsg()); + } + + if (apiServiceResult.getData() == null || StringUtils.isBlank(apiServiceResult.getData().getApiServiceName())) { + throw new RenException("【SSO登录】调用OperCrm获取ApiService,查询到的结果为空:", apiServiceResult.toString()); + } + + ThirdPlatUserInfo userInfo; + try { + AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(apiServiceResult.getData().getApiServiceName()); + userInfo = apiService.getUserInfoByTicket(formDTO.getTicket()); + } catch (Exception e) { + throw new RenException(e.getMessage()); } + + if (null == userInfo){ + throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), + "【SSO登录】调用第三方平台查询用户信息失败,用户信息为空"); + } + UserInfoFormDTO userInfoFormDTO = new UserInfoFormDTO(); + userInfoFormDTO.setApp(formDTO.getApp()); + userInfoFormDTO.setUid(userInfo.getOpenId()); + userInfoFormDTO.setName(userInfo.getName()); + userInfoFormDTO.setMobile(userInfo.getMobile()); + + Result userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); + if (!userDTOResult.success()){ + throw new RenException("【SSO登录】新增或更新user_weChat失败"); + } + userId = userDTOResult.getData().getId(); + if (StringUtils.isBlank(userId)){ - throw new RenException(SsoConstant.USER_ID_IS_NULL); + throw new RenException("【SSO登录】userId为空,生成token失败"); } //生成业务token String token = this.generateToken(formDTO.getApp(),formDTO.getClient(), userId); //存放Redis - String customerId = getCustomerId(formDTO.getAppId()); + if (StringUtils.isBlank(customerId)){ - throw new RenException(SsoConstant.CUSTOMER_ID_IS_NULL); + throw new RenException("【SSO登录】customerId为空,缓存放置token失败"); } this.disposeTokenDto(formDTO, userId, token, customerId); return new SsoLoginResultDTO(token); diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java index 3209a9ea44..fbf0f7781e 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java @@ -2,15 +2,13 @@ package com.epmet.commons.thirdplat.apiservice; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.epmet.commons.thirdplat.bean.ThirdPlatUserInfo; import com.epmet.commons.thirdplat.dto.result.jcet.JcetResult; -import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; import com.epmet.commons.thirdplat.properties.ThirdplatProps; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; -import java.io.UnsupportedEncodingException; - public abstract class AbstractApiService { protected ThirdplatProps thirdplatProps; @@ -21,7 +19,7 @@ public abstract class AbstractApiService { * @return * @throws Exception */ - public abstract UserInfoResultDTO getUserInfoByTicket(String ticket) throws Exception; + public abstract ThirdPlatUserInfo getUserInfoByTicket(String ticket) throws Exception; /** * @Description 解析请求结果 diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java index b24803fa09..a975dc6a27 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -2,10 +2,10 @@ package com.epmet.commons.thirdplat.apiservice.jcet; import com.alibaba.fastjson.JSON; import com.epmet.commons.thirdplat.apiservice.AbstractApiService; +import com.epmet.commons.thirdplat.bean.ThirdPlatUserInfo; import com.epmet.commons.thirdplat.constants.JcetConstants; import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO; -import com.epmet.commons.thirdplat.dto.form.jcet.SsoTokenFormDTO; -import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; +import com.epmet.commons.thirdplat.dto.result.jcet.JcetUserInfoResultDTO; import com.epmet.commons.thirdplat.encrypt.SignUtils; import com.epmet.commons.thirdplat.properties.JcetThirdplatProps; import com.epmet.commons.thirdplat.properties.ThirdplatProps; @@ -31,7 +31,7 @@ public class JcetApiService extends AbstractApiService { * @author wxz * @date 2021.01.19 10:26 */ - public UserInfoResultDTO getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { + public ThirdPlatUserInfo getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); ssoTicket.setSsoTicket(ticket); @@ -42,8 +42,13 @@ public class JcetApiService extends AbstractApiService { JSON.toJSONString(ssoTicket), getHeaders(ssoTicket)); - UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); - return resultDTO; + JcetUserInfoResultDTO resultDTO = parseResult(result, JcetUserInfoResultDTO.class); + + ThirdPlatUserInfo userInfo = new ThirdPlatUserInfo(); + userInfo.setOpenId(resultDTO.getId()); + userInfo.setName(resultDTO.getName()); + userInfo.setMobile(resultDTO.getMobile()); + return userInfo; } /** @@ -52,24 +57,24 @@ public class JcetApiService extends AbstractApiService { * @author wxz * @date 2021.01.19 10:28 */ - public UserInfoResultDTO getUserInfoByToken(String token) throws UnsupportedEncodingException { - SsoTokenFormDTO ssoToken = new SsoTokenFormDTO(); - ssoToken.setSsoToken(token); - - HashMap paramMap = new HashMap<>(); - paramMap.put(JcetConstants.PLAT_TOKEN_NAME, token); - - String domain = jcetThirdplatProps.getDomain(); - - Result result = HttpClientManager.getInstance().sendGet( - domain.concat(JcetConstants.URL_GET_USER_BY_TOKEN), - domain.startsWith("https://"), - paramMap, - getHeaders(ssoToken)); - - UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); - return resultDTO; - } + //public JcetUserInfoResultDTO getUserInfoByToken(String token) throws UnsupportedEncodingException { + // SsoTokenFormDTO ssoToken = new SsoTokenFormDTO(); + // ssoToken.setSsoToken(token); + // + // HashMap paramMap = new HashMap<>(); + // paramMap.put(JcetConstants.PLAT_TOKEN_NAME, token); + // + // String domain = jcetThirdplatProps.getDomain(); + // + // Result result = HttpClientManager.getInstance().sendGet( + // domain.concat(JcetConstants.URL_GET_USER_BY_TOKEN), + // domain.startsWith("https://"), + // paramMap, + // getHeaders(ssoToken)); + // + // JcetUserInfoResultDTO resultDTO = parseResult(result, JcetUserInfoResultDTO.class); + // return resultDTO; + //} /** * 获取请求所需要的头信息 diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java index 365e142a0f..f1539efba7 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java @@ -1,5 +1,10 @@ package com.epmet.commons.thirdplat.bean; -public class ThirdPlatUserInfo { +import lombok.Data; +@Data +public class ThirdPlatUserInfo { + private String openId; + private String name; + private String mobile; } diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetUserInfoResultDTO.java similarity index 92% rename from epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java rename to epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetUserInfoResultDTO.java index 09fc1bcace..8c025e5b9b 100644 --- a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetUserInfoResultDTO.java @@ -3,7 +3,7 @@ package com.epmet.commons.thirdplat.dto.result.jcet; import lombok.Data; @Data -public class UserInfoResultDTO { +public class JcetUserInfoResultDTO { private String id; /** * 用户名称 diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/form/ApiServiceFormDTO.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/form/ApiServiceFormDTO.java new file mode 100644 index 0000000000..a111ca87c6 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/form/ApiServiceFormDTO.java @@ -0,0 +1,20 @@ +package com.epmet.dto.form; + +import com.epmet.commons.tools.dto.form.PageFormDTO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ApiServiceFormDTO { + + public interface GetByCustomerId extends PageFormDTO.AddUserShowGroup {} + + @NotBlank(message = "客户ID不能为空", groups = { GetByCustomerId.class }) + private String customerId; + +} diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ThirdplatApiserviceResultDTO.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ThirdplatApiserviceResultDTO.java new file mode 100644 index 0000000000..4737bf32d4 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/result/ThirdplatApiserviceResultDTO.java @@ -0,0 +1,16 @@ +package com.epmet.dto.result; + +import lombok.Data; + +@Data +public class ThirdplatApiserviceResultDTO { + /** + * 客户id + */ + private String customerId; + + /** + * aipService名称 + */ + private String apiServiceName; +} diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java index 496dcd636a..4c733ab45a 100644 --- a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/OperCrmOpenFeignClient.java @@ -4,12 +4,10 @@ import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerAppDTO; import com.epmet.dto.CustomerDTO; -import com.epmet.dto.form.CrmParameterFormDTO; -import com.epmet.dto.form.CustomerAppSecretFormDTO; -import com.epmet.dto.form.CustomerManagerFormDTO; -import com.epmet.dto.form.GridCountFormDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.CrmParameterResultDTO; import com.epmet.dto.result.GridCountResultDTO; +import com.epmet.dto.result.ThirdplatApiserviceResultDTO; import com.epmet.feign.fallback.OperCrmOpenFeignClientFallback; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; @@ -94,4 +92,13 @@ public interface OperCrmOpenFeignClient { */ @PostMapping("/oper/crm/parameter/parameterupdate") Result updateParamInfo(@RequestBody List formDTOS); + + /** + * @Description 根据客户id查询配置的apiService + * @return + * @author wxz + * @date 2021.01.20 15:55 + */ + @PostMapping("/oper/crm/customer/get-apiservice-by-customerid") + Result getApiServiceByCustomerId(@RequestBody ApiServiceFormDTO form); } diff --git a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java index d18f98065a..8a3a1483f5 100644 --- a/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java +++ b/epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/feign/fallback/OperCrmOpenFeignClientFallback.java @@ -5,12 +5,10 @@ import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerAppDTO; import com.epmet.dto.CustomerDTO; -import com.epmet.dto.form.CrmParameterFormDTO; -import com.epmet.dto.form.CustomerAppSecretFormDTO; -import com.epmet.dto.form.CustomerManagerFormDTO; -import com.epmet.dto.form.GridCountFormDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.CrmParameterResultDTO; import com.epmet.dto.result.GridCountResultDTO; +import com.epmet.dto.result.ThirdplatApiserviceResultDTO; import com.epmet.feign.OperCrmOpenFeignClient; import org.springframework.stereotype.Component; @@ -69,4 +67,9 @@ public class OperCrmOpenFeignClientFallback implements OperCrmOpenFeignClient { public Result updateParamInfo(List formDTOS) { return ModuleUtils.feignConError(ServiceConstant.OPER_CRM_SERVER, "updateParamInfo", formDTOS); } + + @Override + public Result getApiServiceByCustomerId(ApiServiceFormDTO form) { + return ModuleUtils.feignConError(ServiceConstant.OPER_CRM_SERVER, "getApiServiceByCustomerId", form); + } } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java index e4ae80fc6e..51cc0fa29c 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java @@ -31,13 +31,11 @@ import com.epmet.commons.tools.validator.group.DefaultGroup; import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.dto.CustomerDTO; import com.epmet.dto.form.*; -import com.epmet.dto.result.CustomerDetailResultDTO; -import com.epmet.dto.result.CustomerInfoResultDTO; -import com.epmet.dto.result.GridCountResultDTO; -import com.epmet.dto.result.ValidCustomerResultDTO; +import com.epmet.dto.result.*; import com.epmet.excel.CustomerExcel; import com.epmet.feign.GovOrgFeignClient; import com.epmet.service.CustomerService; +import com.epmet.service.CustomerThirdplatApiServiceService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -67,6 +65,9 @@ public class CustomerController { @Autowired private GovOrgFeignClient govOrgFeignClient; + @Autowired + private CustomerThirdplatApiServiceService customerThirdplatApiServiceService; + @GetMapping("page") public Result> page(@RequestParam Map params) { PageData page = customerService.page(params); @@ -330,4 +331,17 @@ public class CustomerController { return new Result(); } + /** + * @Description 根据客户id查询配置的apiService + * @return + * @author wxz + * @date 2021.01.20 15:55 + */ + @PostMapping("get-apiservice-by-customerid") + public Result getApiServiceByCustomerId(@RequestBody ApiServiceFormDTO form) { + ValidatorUtils.validateEntity(form, ApiServiceFormDTO.GetByCustomerId.class); + String customerId = form.getCustomerId(); + return new Result().ok(customerThirdplatApiServiceService.getByCustomerId(customerId)); + } + } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java new file mode 100644 index 0000000000..52f05556b1 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/dao/CustomerThirdplatApiserviceDao.java @@ -0,0 +1,36 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.result.ThirdplatApiserviceResultDTO; +import com.epmet.entity.CustomerThirdplatApiserviceEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 客户所属的第三方平台的apiService列表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-01-20 + */ +@Mapper +public interface CustomerThirdplatApiserviceDao extends BaseDao { + + ThirdplatApiserviceResultDTO getByCustomerId(@Param("customerId") String customerId); +} \ No newline at end of file diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerThirdplatApiserviceEntity.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerThirdplatApiserviceEntity.java new file mode 100644 index 0000000000..59be94ffb9 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/entity/CustomerThirdplatApiserviceEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 客户所属的第三方平台的apiService列表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-01-20 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("customer_thirdplat_apiservice") +public class CustomerThirdplatApiserviceEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * aipService名称 + */ + private String apiServiceName; + +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java new file mode 100644 index 0000000000..a1f9fa91e9 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerThirdplatApiServiceService.java @@ -0,0 +1,16 @@ +package com.epmet.service; + +import com.epmet.dto.result.ThirdplatApiserviceResultDTO; +import com.epmet.entity.CustomerThirdplatApiserviceEntity; + +public interface CustomerThirdplatApiServiceService { + + /** + * @Description 根据客户id查询客户第三方平台的ApiService + * @return + * @author wxz + * @date 2021.01.20 15:47 + */ + ThirdplatApiserviceResultDTO getByCustomerId(String customerId); + +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java new file mode 100644 index 0000000000..410fd1aa3f --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java @@ -0,0 +1,20 @@ +package com.epmet.service.impl; + +import com.epmet.dao.CustomerThirdplatApiserviceDao; +import com.epmet.dto.result.ThirdplatApiserviceResultDTO; +import com.epmet.entity.CustomerThirdplatApiserviceEntity; +import com.epmet.service.CustomerThirdplatApiServiceService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class CustomerThirdplatApiServiceServiceImpl implements CustomerThirdplatApiServiceService { + + @Autowired + private CustomerThirdplatApiserviceDao thirdplatApiserviceDao; + + @Override + public ThirdplatApiserviceResultDTO getByCustomerId(String customerId) { + return thirdplatApiserviceDao.getByCustomerId(customerId); + } +} diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/resources/db/migration/V0.0.6__create_thirdplat_apiservice.sql b/epmet-module/oper-crm/oper-crm-server/src/main/resources/db/migration/V0.0.6__create_thirdplat_apiservice.sql new file mode 100644 index 0000000000..491d1d14c9 --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/resources/db/migration/V0.0.6__create_thirdplat_apiservice.sql @@ -0,0 +1,14 @@ +create table customer_thirdplat_apiservice +( + `ID` varchar(64) NOT NULL COMMENT '唯一标识', + `CUSTOMER_ID` varchar(64) not null comment '客户id', + `API_SERVICE_NAME` varchar(64) not null comment 'aipService名称', + `DEL_FLAG` int(11) NOT NULL COMMENT '删除标识:0.未删除 1.已删除', + `REVISION` int(11) NOT NULL COMMENT '乐观锁', + `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间' +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + collate utf8mb4_general_ci COMMENT ='客户所属的第三方平台的apiService列表'; diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml b/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml new file mode 100644 index 0000000000..8390e5647f --- /dev/null +++ b/epmet-module/oper-crm/oper-crm-server/src/main/resources/mapper/CustomerThirdplatApiserviceDao.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 44e1f4e79e06872ea4aae04b14512da774af533d Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 20 Jan 2021 17:10:20 +0800 Subject: [PATCH 22/25] =?UTF-8?q?=E3=80=90sso=E7=99=BB=E5=BD=95=E3=80=91?= =?UTF-8?q?=E6=A0=B9=E6=8D=AEcustomerid=E6=9F=A5=E8=AF=A2apiService?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8Ccrm=E6=9C=8D=E5=8A=A1=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0redis=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisKeys.java | 10 ++++++++ ...ustomerThirdplatApiServiceServiceImpl.java | 24 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 444077098f..098dd1c14d 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -360,4 +360,14 @@ public class RedisKeys { public static String getResiUserKey(String userId){ return rootPrefix.concat("resi:user:").concat(userId); } + + /** + * @Description 客户的ApiService + * @return + * @author wxz + * @date 2021.01.20 16:56 + */ + public static String getCustomerApiServiceKey(String customerId) { + return rootPrefix.concat("customer:thirdplat:apiservice:").concat(customerId); + } } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java index 410fd1aa3f..9cfa19a820 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerThirdplatApiServiceServiceImpl.java @@ -1,20 +1,42 @@ package com.epmet.service.impl; +import cn.hutool.core.bean.BeanUtil; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.dao.CustomerThirdplatApiserviceDao; import com.epmet.dto.result.ThirdplatApiserviceResultDTO; import com.epmet.entity.CustomerThirdplatApiserviceEntity; import com.epmet.service.CustomerThirdplatApiServiceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.Map; @Service public class CustomerThirdplatApiServiceServiceImpl implements CustomerThirdplatApiServiceService { + @Autowired + private RedisUtils redisUtils; + @Autowired private CustomerThirdplatApiserviceDao thirdplatApiserviceDao; @Override public ThirdplatApiserviceResultDTO getByCustomerId(String customerId) { - return thirdplatApiserviceDao.getByCustomerId(customerId); + ThirdplatApiserviceResultDTO apiService = null; + + // 查redis,存redis + Map apiServiceMap = redisUtils.hGetAll(RedisKeys.getCustomerApiServiceKey(customerId)); + if (!CollectionUtils.isEmpty(apiServiceMap)) { + apiService = BeanUtil.mapToBean(apiServiceMap, ThirdplatApiserviceResultDTO.class, true); + } + + if (apiService == null) { + apiService = thirdplatApiserviceDao.getByCustomerId(customerId); + redisUtils.hMSet(RedisKeys.getCustomerApiServiceKey(customerId), BeanUtil.beanToMap(apiService)); + } + + return apiService; } } From 4de7a3a272428536ffd37ac6239ca5b8c840902a Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 21 Jan 2021 09:34:40 +0800 Subject: [PATCH 23/25] =?UTF-8?q?=E3=80=90sso=E7=99=BB=E5=BD=95=E3=80=91?= =?UTF-8?q?=E5=B0=86=E9=85=8D=E7=BD=AE=E6=94=BE=E5=88=B0pom=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-auth/pom.xml | 20 ++++++++++++++++++++ epmet-auth/src/main/resources/bootstrap.yml | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index 4164a50134..0fea96f5c1 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -198,6 +198,11 @@ SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + http://101.206.141.251:21006 + soXDEoM1 + V7ea0KnlYt7eSyzc @@ -242,6 +247,11 @@ SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + http://101.206.141.251:21006 + soXDEoM1 + V7ea0KnlYt7eSyzc @@ -281,6 +291,11 @@ SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + http://101.206.141.251:21006 + soXDEoM1 + V7ea0KnlYt7eSyzc @@ -324,6 +339,11 @@ SEC95f4f40b533ad379ea6a6d1af6dd37029383cfe1b7cd96dfac2678be2c1c3ed1 + + + diff --git a/epmet-auth/src/main/resources/bootstrap.yml b/epmet-auth/src/main/resources/bootstrap.yml index 865035f3f7..6efee6a635 100644 --- a/epmet-auth/src/main/resources/bootstrap.yml +++ b/epmet-auth/src/main/resources/bootstrap.yml @@ -136,6 +136,6 @@ shutdown: # 调用第三方平台相关参数 thirdplat: jcet: - domain: http://101.206.141.251:21006 - appkey: soXDEoM1 - appsecret: V7ea0KnlYt7eSyzc \ No newline at end of file + domain: @thirdplat.jcet.domain@ + appkey: @thirdplat.jcet.appkey@ + appsecret: @thirdplat.jcet.appsecret@ \ No newline at end of file From 4883b644557a80900e6fd36c89610f4e8283a8a7 Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Thu, 21 Jan 2021 15:30:41 +0800 Subject: [PATCH 24/25] =?UTF-8?q?=E5=B7=B2=E8=BD=AC=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gov-issue-server/src/main/resources/mapper/IssueDao.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueDao.xml b/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueDao.xml index 4c2878e0e5..1b9dbdec01 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueDao.xml +++ b/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueDao.xml @@ -54,6 +54,8 @@ AND GRID_ID = #{gridId} AND ISSUE_STATUS = 'shift_project' ORDER BY UPDATED_TIME DESC + LIMIT #{pageNo}, + #{pageSize} From c548d2e4cacd2d185eb631d85cde686d1d7b0747 Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 28 Jan 2021 15:06:10 +0800 Subject: [PATCH 25/25] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E7=9A=84jcet=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-auth/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index 0fea96f5c1..5015feb391 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -341,9 +341,9 @@ - + https://jcytc.lzjczl.com:21009 + 2cy0a9lA + 6hU3PQgxLcXr27SE