diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index 69713f1908..5015feb391 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 @@ -193,6 +198,11 @@ SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + http://101.206.141.251:21006 + soXDEoM1 + V7ea0KnlYt7eSyzc @@ -237,6 +247,11 @@ SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + http://101.206.141.251:21006 + soXDEoM1 + V7ea0KnlYt7eSyzc @@ -276,6 +291,11 @@ SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + http://101.206.141.251:21006 + soXDEoM1 + V7ea0KnlYt7eSyzc @@ -319,6 +339,11 @@ SEC95f4f40b533ad379ea6a6d1af6dd37029383cfe1b7cd96dfac2678be2c1c3ed1 + + + https://jcytc.lzjczl.com:21009 + 2cy0a9lA + 6hU3PQgxLcXr27SE 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..e7da64ccff --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/constant/SsoConstant.java @@ -0,0 +1,21 @@ +package com.epmet.constant; + +/** + * @Author zxc + * @DateTime 2021/1/19 上午10:26 + */ +public interface SsoConstant { + + /** + * 酒城e通appId + */ + String WINE_CITY_E_OPEN_APP_ID = "64929543"; + + String USER_INFO_IS_NULL = "【jcetApiService.getUserInfoByTicket(formDTO.getTicket()】结果为空......"; + + 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/controller/SsoController.java b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java new file mode 100644 index 0000000000..6d17e1a9a0 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/controller/SsoController.java @@ -0,0 +1,53 @@ +package com.epmet.controller; + +import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; +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; +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; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午4:33 + */ +@RestController +@RequestMapping("sso") +public class SsoController { + + @Autowired + private SsoService ssoService; + + @Autowired + private JcetApiService jcetApiService; + + /** + * @Description 0、入口:得到token + * @Param formDTO + * @author zxc + * @date 2021/1/18 下午4:59 + */ + @PostMapping("resi/login") + public Result ssoLogin(@RequestBody SsoLoginFormDTO formDTO){ + ValidatorUtils.validateEntity(formDTO, SsoLoginFormDTO.SsoLoginForm.class); + return new Result().ok(ssoService.ssoLogin(formDTO)); + } + + @PostMapping("test") + public Result testssoLogin(){ + ThirdPlatUserInfo userInfoByTicket = null; + try { + userInfoByTicket = jcetApiService.getUserInfoByTicket("ssoTicket-vYtMRuXAQZri3wpA2vyq5D8n3Q9oO7ui"); + } catch (Exception e) { + e.printStackTrace(); + } + return new Result().ok(userInfoByTicket); + } + +} 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..16ee7ab3ce --- /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(), 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/SsoService.java b/epmet-auth/src/main/java/com/epmet/service/SsoService.java new file mode 100644 index 0000000000..3cbd2b9af2 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/service/SsoService.java @@ -0,0 +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 new file mode 100644 index 0000000000..ede5acd988 --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -0,0 +1,185 @@ +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.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.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; +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; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author zxc + * @DateTime 2021/1/18 下午4:35 + */ +@Service +@Slf4j +public class SsoServiceImpl implements SsoService { + + Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private SsoRedis ssoRedis; + + @Autowired + private JwtTokenUtils jwtTokenUtils; + + @Autowired + private JwtTokenProperties jwtTokenProperties; + + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + + @Autowired + private OperCrmOpenFeignClient operCrmOpenFeignClient; + + /** + * @Description 0、入口:得到token + * @Param formDTO + * @author zxc + * @date 2021/1/18 下午4:59 + */ + @Override + public SsoLoginResultDTO ssoLogin(SsoLoginFormDTO formDTO) { + String customerId = getCustomerId(formDTO.getAppId()); + String userId = ""; + + 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("【SSO登录】userId为空,生成token失败"); + } + //生成业务token + String token = this.generateToken(formDTO.getApp(),formDTO.getClient(), userId); + //存放Redis + + if (StringUtils.isBlank(customerId)){ + throw new RenException("【SSO登录】customerId为空,缓存放置token失败"); + } + this.disposeTokenDto(formDTO, userId, token, customerId); + 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-auth/src/main/resources/bootstrap.yml b/epmet-auth/src/main/resources/bootstrap.yml index e7fa54d000..6efee6a635 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: @thirdplat.jcet.domain@ + appkey: @thirdplat.jcet.appkey@ + appsecret: @thirdplat.jcet.appsecret@ \ 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..43b27e385b --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java @@ -0,0 +1,36 @@ +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; +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..fbf0f7781e --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java @@ -0,0 +1,45 @@ +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.properties.ThirdplatProps; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.Result; + +public abstract class AbstractApiService { + + protected ThirdplatProps thirdplatProps; + + /** + * 通过ticket查询用户信息 + * @param ticket + * @return + * @throws Exception + */ + public abstract ThirdPlatUserInfo getUserInfoByTicket(String ticket) throws Exception; + + /** + * @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()); + } + + JSONObject jo = (JSONObject) jcetResult.getData(); + return jo.toJavaObject(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..a975dc6a27 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -0,0 +1,98 @@ +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.result.jcet.JcetUserInfoResultDTO; +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 java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; + +public class JcetApiService extends AbstractApiService { + + private JcetThirdplatProps jcetThirdplatProps; + + public JcetApiService(ThirdplatProps props) { + this.thirdplatProps = props; + jcetThirdplatProps = props.getJcet(); + } + + /** + * @return + * @Description 通过第三方平台ticket获取用户信息 + * @author wxz + * @date 2021.01.19 10:26 + */ + public ThirdPlatUserInfo getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { + SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); + ssoTicket.setSsoTicket(ticket); + + 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)); + + JcetUserInfoResultDTO resultDTO = parseResult(result, JcetUserInfoResultDTO.class); + + ThirdPlatUserInfo userInfo = new ThirdPlatUserInfo(); + userInfo.setOpenId(resultDTO.getId()); + userInfo.setName(resultDTO.getName()); + userInfo.setMobile(resultDTO.getMobile()); + return userInfo; + } + + /** + * @return + * @Description 通过token获取用户信息 + * @author wxz + * @date 2021.01.19 10:28 + */ + //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; + //} + + /** + * 获取请求所需要的头信息 + * + * @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(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(JcetConstants.PLAT_HEADER_OPEN_SIGN, SignUtils.generate(encryptContent, jcetThirdplatProps.getAppsecret())); + return headers; + } + +} 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..f1539efba7 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/bean/ThirdPlatUserInfo.java @@ -0,0 +1,10 @@ +package com.epmet.commons.thirdplat.bean; + +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/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..11e941ab93 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java @@ -0,0 +1,28 @@ +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; +import org.springframework.context.annotation.Configuration; + +/** + * 第三方平台的相关配置 + */ +@Configuration +@EnableConfigurationProperties(ThirdplatProps.class) +public class ThirdplatConfig { + + /** + * @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"; +} 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-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/JcetUserInfoResultDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetUserInfoResultDTO.java new file mode 100644 index 0000000000..8c025e5b9b --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetUserInfoResultDTO.java @@ -0,0 +1,29 @@ +package com.epmet.commons.thirdplat.dto.result.jcet; + +import lombok.Data; + +@Data +public class JcetUserInfoResultDTO { + private String id; + /** + * 用户名称 + */ + private String userName; + /** + * 手机号码 + */ + private String mobile; + /** + * 姓名 + */ + private String name; + /** + * 邮箱 + */ + private String email; + + /** + * sessionId,用于维持在线状态 + */ + private String oaSessionId; +} 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 e3a02b4696..ac6d50bd9f 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 @@ -72,6 +72,7 @@ public enum EpmetErrorCode { NOT_DEL_AGENCY_GRID(8207, "该机关存在网格,不允许删除"), REQUIRE_PERMISSION(8301, "您没有足够的操作权限"), + THIRD_PLAT_REQUEST_ERROR(8302, "请求第三方平台错误"), NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"), MOBILE_USED(8402,"该手机号已注册"), @@ -144,7 +145,6 @@ public enum EpmetErrorCode { TOPIC_IS_HIDDEN(9006,"该话题已被屏蔽,请先解除屏蔽"), TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"); - private int code; private String msg; 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-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 { diff --git a/epmet-commons/pom.xml b/epmet-commons/pom.xml index 0bf8dd9c9f..636480c48f 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 epmet-commons-rocketmq 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; } } 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} 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/CustomerServiceImpl.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java index 9080d1573f..f1c5896f0e 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 @@ -33,6 +33,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.SystemMessageType; import com.epmet.constant.UserWorkType; import com.epmet.dao.CustomerDao; @@ -538,13 +539,15 @@ public class CustomerServiceImpl extends BaseServiceImpl 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; + } +} 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 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..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 @@ -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 + **/ + @PostMapping("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 ; + } + } 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 494fce4e3f..d48703ffb4 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 @@ -477,4 +477,13 @@ public interface EpmetUserOpenFeignClient { */ @PostMapping("/epmetuser/staffrole/initrolesforcustomer/{customerId}") Result initGovStaffRolesForCustomer(@PathVariable String customerId); + + /** + * @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 7137d3ad1d..195f1a0c38 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 @@ -332,6 +332,11 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "specificRolesStaffs", rolesUsersListFormDTO); } + @Override + public Result saveUserInfo(UserInfoFormDTO formDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "saveUserInfo", formDTO); + } + @Override public Result initGovStaffRolesForCustomer(String customerId) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "initGovStaffRolesForCustomer", customerId); 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..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 @@ -279,4 +279,47 @@ 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()); + entity.setSex(NumConstant.ZERO); + 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} + + + + +