diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index bd603be105..9d1876810e 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -149,6 +149,9 @@ wx9b6102a8ee5add65 16fdb68bc2b3e732324ba5d8b8a9b5e2 + + wx3d1372029eb816a3 + 651f02d71ed3f123dfb584b8bf0f4d8b @@ -183,6 +186,9 @@ wx9b6102a8ee5add65 16fdb68bc2b3e732324ba5d8b8a9b5e2 + + wx3d1372029eb816a3 + 651f02d71ed3f123dfb584b8bf0f4d8b @@ -217,6 +223,9 @@ wx9b6102a8ee5add65 16fdb68bc2b3e732324ba5d8b8a9b5e2 + + wx3d1372029eb816a3 + 651f02d71ed3f123dfb584b8bf0f4d8b diff --git a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java index e1e896d06c..4e16236906 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java @@ -2,7 +2,9 @@ package com.epmet.controller; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.LoginByPhoneFormDTO; import com.epmet.dto.form.SendSmsCodeFormDTO; +import com.epmet.dto.result.UserTokenResultDTO; import com.epmet.service.GovLoginService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; @@ -34,4 +36,17 @@ public class GovLoginController { ValidatorUtils.validateEntity(formDTO); return govLoginService.sendSmsCode(formDTO); } + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机验证码登录 + * @Date 2020/4/18 21:14 + **/ + @PostMapping(value = "loginbyphone") + public Result loginByPhone(LoginByPhoneFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); + return govLoginService.loginByPhone(formDTO); + } } diff --git a/epmet-auth/src/main/java/com/epmet/controller/LoginController.java b/epmet-auth/src/main/java/com/epmet/controller/LoginController.java index 99b094eb1a..10977f08b0 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/LoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/LoginController.java @@ -1,15 +1,14 @@ package com.epmet.controller; -import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; -import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; -import com.epmet.common.token.dto.result.UserTokenResultDTO; import com.epmet.commons.tools.annotation.LoginUser; -import com.epmet.commons.tools.constant.Constant; import com.epmet.commons.tools.exception.ErrorCode; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.LoginByPassWordFormDTO; +import com.epmet.dto.form.LoginByWxCodeFormDTO; +import com.epmet.dto.result.UserTokenResultDTO; import com.epmet.service.CaptchaService; import com.epmet.service.LoginService; import org.springframework.beans.factory.annotation.Autowired; diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByPassWordFormDTO.java similarity index 94% rename from epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java rename to epmet-auth/src/main/java/com/epmet/dto/form/LoginByPassWordFormDTO.java index 742a38844e..89e751e249 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByPassWordFormDTO.java @@ -1,4 +1,4 @@ -package com.epmet.common.token.dto.form; +package com.epmet.dto.form; import lombok.Data; diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/LoginByPhoneFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByPhoneFormDTO.java index d4eba4f08d..591e6063b1 100644 --- a/epmet-auth/src/main/java/com/epmet/dto/form/LoginByPhoneFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByPhoneFormDTO.java @@ -11,7 +11,7 @@ import java.io.Serializable; * @Date 2020/4/18 10:38 */ @Data -public class LoginByPhoneFormDTO implements Serializable { +public class LoginByPhoneFormDTO extends LoginCommonFormDTO implements Serializable { private static final long serialVersionUID = 4193133227120225342L; @NotBlank(message = "wxCode不能为空") @@ -20,7 +20,8 @@ public class LoginByPhoneFormDTO implements Serializable { @NotBlank(message = "手机号不能为空") private String phone; - @NotBlank(message="手机号不能为空") + @NotBlank(message="验证码不能为空") private String smsCode; + } diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java similarity index 93% rename from epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java rename to epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java index 0f61c36255..6a6559df59 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java @@ -1,4 +1,4 @@ -package com.epmet.common.token.dto.form; +package com.epmet.dto.form; import lombok.Data; diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/LoginCommonFormDTO.java similarity index 94% rename from epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java rename to epmet-auth/src/main/java/com/epmet/dto/form/LoginCommonFormDTO.java index 9b2390388e..af4df891c5 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/LoginCommonFormDTO.java @@ -1,4 +1,4 @@ -package com.epmet.common.token.dto.form; +package com.epmet.dto.form; import lombok.Data; diff --git a/epmet-auth/src/main/java/com/epmet/dto/form/SendSmsCodeFormDTO.java b/epmet-auth/src/main/java/com/epmet/dto/form/SendSmsCodeFormDTO.java index af5fa8bfa0..806ddc43e2 100644 --- a/epmet-auth/src/main/java/com/epmet/dto/form/SendSmsCodeFormDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/form/SendSmsCodeFormDTO.java @@ -11,15 +11,9 @@ import java.io.Serializable; * @Date 2020/04/18 10:26 */ @Data -public class SendSmsCodeFormDTO implements Serializable { +public class SendSmsCodeFormDTO extends LoginCommonFormDTO implements Serializable { private static final long serialVersionUID = -1852541457359282018L; - @NotBlank(message = "app不能为空(resi、gov、oper)") - private String app; - - @NotBlank(message = "client不能为空(wxmp、web)") - private String client; - @NotBlank(message = "手机号不能为空") private String phone; } diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java b/epmet-auth/src/main/java/com/epmet/dto/result/UserTokenResultDTO.java similarity index 88% rename from epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java rename to epmet-auth/src/main/java/com/epmet/dto/result/UserTokenResultDTO.java index e5296bf42b..8e4b715422 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java +++ b/epmet-auth/src/main/java/com/epmet/dto/result/UserTokenResultDTO.java @@ -1,4 +1,4 @@ -package com.epmet.common.token.dto.result; +package com.epmet.dto.result; import lombok.Data; diff --git a/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index fa00d9e73c..5b339e18ce 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -2,9 +2,11 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerStaffDTO; import com.epmet.dto.UserDTO; import com.epmet.dto.UserWechatDTO; import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.StaffWechatFormDTO; import com.epmet.dto.form.WxLoginUserInfoFormDTO; import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; import com.epmet.feign.fallback.EpmetUserFeignClientFallback; @@ -63,5 +65,15 @@ public interface EpmetUserFeignClient { * @Date 2020/4/18 14:03 **/ @GetMapping(value = "epmetuser/customerstaff/getcustsomerstaffbyphone/{phone}") - Result checkCustomerStaff(@PathVariable("phone") String phone); + Result checkCustomerStaff(@PathVariable("phone") String phone); + + /** + * @param staffWechatFormDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 机验证码登录时记录微信openId与当前用户的关系 + * @Date 2020/4/18 22:44 + **/ + @PostMapping(value = "epmetuser/staffwechat/savestaffwechat", consumes = MediaType.APPLICATION_JSON_VALUE) + Result savestaffwechat(@RequestBody StaffWechatFormDTO staffWechatFormDTO); } diff --git a/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java b/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java index 2d32ef7a8b..60b63d04da 100644 --- a/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java +++ b/epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java @@ -3,9 +3,11 @@ package com.epmet.feign.fallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerStaffDTO; import com.epmet.dto.UserDTO; import com.epmet.dto.UserWechatDTO; import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; +import com.epmet.dto.form.StaffWechatFormDTO; import com.epmet.dto.form.WxLoginUserInfoFormDTO; import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; import com.epmet.feign.EpmetUserFeignClient; @@ -35,8 +37,13 @@ public class EpmetUserFeignClientFallback implements EpmetUserFeignClient { } @Override - public Result checkCustomerStaff(String phone) { + public Result checkCustomerStaff(String phone) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustsomerStaffByPhone", phone); } + @Override + public Result savestaffwechat(StaffWechatFormDTO staffWechatFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "saveStaffWechat", staffWechatFormDTO); + } + } diff --git a/epmet-auth/src/main/java/com/epmet/redis/CaptchaRedis.java b/epmet-auth/src/main/java/com/epmet/redis/CaptchaRedis.java index 50b31182ff..7363eb93c2 100644 --- a/epmet-auth/src/main/java/com/epmet/redis/CaptchaRedis.java +++ b/epmet-auth/src/main/java/com/epmet/redis/CaptchaRedis.java @@ -10,6 +10,7 @@ package com.epmet.redis; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.dto.form.LoginByPhoneFormDTO; import com.epmet.dto.form.SendSmsCodeFormDTO; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -64,9 +65,21 @@ public class CaptchaRedis { * @Date 2020/4/18 13:53 **/ public void saveSmsCode(SendSmsCodeFormDTO sendSmsCodeFormDTO, String smsCode) { - String smsCodeKey = RedisKeys.getLoginSmsCodeKey(sendSmsCodeFormDTO.getApp(), sendSmsCodeFormDTO.getClient(), sendSmsCodeFormDTO.getPhone(), smsCode); + String smsCodeKey = RedisKeys.getLoginSmsCodeKey(sendSmsCodeFormDTO.getApp(), sendSmsCodeFormDTO.getClient(), sendSmsCodeFormDTO.getPhone()); logger.info(String.format("短信验证码key=%s", smsCodeKey)); redisUtils.set(smsCodeKey, smsCode, MINUTE_THIRTY_EXPIRE); } + /** + * @param formDTO + * @return java.lang.String + * @Author yinzuomei + * @Description 获取登录时发送的验证码 + * @Date 2020/4/18 21:33 + **/ + public String getSmsCode(LoginByPhoneFormDTO formDTO) { + String smsCodeKey = RedisKeys.getLoginSmsCodeKey(formDTO.getApp(), formDTO.getClient(), formDTO.getPhone()); + String smsCode = (String) redisUtils.get(smsCodeKey); + return smsCode; + } } diff --git a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java index 9f329487bb..d8c24bf966 100644 --- a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java @@ -1,7 +1,9 @@ package com.epmet.service; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.LoginByPhoneFormDTO; import com.epmet.dto.form.SendSmsCodeFormDTO; +import com.epmet.dto.result.UserTokenResultDTO; /** * @Description 政府端登录 @@ -18,4 +20,13 @@ public interface GovLoginService { * @Date 2020/4/18 10:59 **/ Result sendSmsCode(SendSmsCodeFormDTO formDTO); + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机验证码登录 + * @Date 2020/4/18 21:11 + **/ + Result loginByPhone(LoginByPhoneFormDTO formDTO); } diff --git a/epmet-auth/src/main/java/com/epmet/service/LoginService.java b/epmet-auth/src/main/java/com/epmet/service/LoginService.java index dd37bfc58f..6beae83483 100644 --- a/epmet-auth/src/main/java/com/epmet/service/LoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/LoginService.java @@ -1,10 +1,11 @@ package com.epmet.service; -import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; -import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; -import com.epmet.common.token.dto.result.UserTokenResultDTO; +import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.LoginByPassWordFormDTO; +import com.epmet.dto.form.LoginByWxCodeFormDTO; +import com.epmet.dto.result.UserTokenResultDTO; /** * @Description @@ -38,4 +39,14 @@ public interface LoginService { * @Date 2020/3/18 22:44 **/ Result logoutByToken(TokenDto tokenDto); + + /** + * @return cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult + * @param app + * @param wxCode + * @Author yinzuomei + * @Description 解析wxCode + * @Date 2020/4/19 0:24 + **/ + WxMaJscode2SessionResult getWxMaUser(String app, String wxCode); } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java index 1cdc6b5b70..1b68026fa0 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java @@ -1,18 +1,31 @@ package com.epmet.service.impl; +import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.CpUserDetailRedis; +import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.PhoneValidatorUtils; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.form.LoginByPhoneFormDTO; +import com.epmet.dto.form.LoginCommonFormDTO; import com.epmet.dto.form.SendSmsCodeFormDTO; +import com.epmet.dto.form.StaffWechatFormDTO; +import com.epmet.dto.result.UserTokenResultDTO; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.feign.MessageFeignClient; +import com.epmet.jwt.JwtTokenProperties; +import com.epmet.jwt.JwtTokenUtils; import com.epmet.redis.CaptchaRedis; import com.epmet.service.GovLoginService; +import com.epmet.service.LoginService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; import java.util.Map; /** @@ -29,6 +42,14 @@ public class GovLoginServiceImpl implements GovLoginService { private MessageFeignClient messageFeignClient; @Autowired private CaptchaRedis captchaRedis; + @Autowired + private LoginService loginService; + @Autowired + private JwtTokenUtils jwtTokenUtils; + @Autowired + private JwtTokenProperties jwtTokenProperties; + @Autowired + private CpUserDetailRedis cpUserDetailRedis; private static final String SEND_SMS_CODE_ERROR="发送短信验证码异常,手机号[%s],code[%s],msg[%s]"; @@ -47,9 +68,9 @@ public class GovLoginServiceImpl implements GovLoginService { return new Result().error(EpmetErrorCode.ERROR_PHONE.getCode()); } //2、根据手机号校验用户是否存在 - Result customerStaffResult=epmetUserFeignClient.checkCustomerStaff(formDTO.getPhone()); + Result customerStaffResult=epmetUserFeignClient.checkCustomerStaff(formDTO.getPhone()); if(!customerStaffResult.success()){ - logger.error(String.format(SEND_SMS_CODE_ERROR,formDTO.getPhone(),EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(),EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg())); + logger.error(String.format(SEND_SMS_CODE_ERROR,formDTO.getPhone(),customerStaffResult.getCode(),customerStaffResult.getMsg())); return new Result().error(customerStaffResult.getCode()); } //3、发送短信验证码 @@ -63,5 +84,98 @@ public class GovLoginServiceImpl implements GovLoginService { logger.info(String.format("发送短信验证码成功,手机号[%s]",formDTO.getPhone())); return new Result(); } + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机验证码登录 + * @Date 2020/4/18 21:11 + **/ + @Override + public Result loginByPhone(LoginByPhoneFormDTO formDTO) { + //1、根据手机号查询到用户信息 + Result customerStaffResult=epmetUserFeignClient.checkCustomerStaff(formDTO.getPhone()); + if(!customerStaffResult.success()){ + logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]",formDTO.getPhone(),customerStaffResult.getCode(),customerStaffResult.getMsg())); + return new Result().error(customerStaffResult.getCode()); + } + //2、验证码是否正确 + String rightSmsCode=captchaRedis.getSmsCode(formDTO); + if(!formDTO.getSmsCode().equals(rightSmsCode)){ + return new Result().error(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); + } + //3、解析wxCode + UserTokenResultDTO userTokenResultDTO=this.getAuthorizationInfo(formDTO,customerStaffResult.getData()); + return new Result().ok(userTokenResultDTO); + } + + private UserTokenResultDTO getAuthorizationInfo(LoginByPhoneFormDTO formDTO, CustomerStaffDTO customerStaff) { + //1、解析微信用户 + WxMaJscode2SessionResult wxMaJscode2SessionResult=loginService.getWxMaUser(formDTO.getApp(),formDTO.getWxCode()); + //2、记录staff_wechat + this.savestaffwechat(customerStaff.getUserId(),wxMaJscode2SessionResult.getOpenid()); + //3、获取用户token + String token=this.generateToken(formDTO,customerStaff.getUserId()); + //4、保存到redis + this.saveTokenDto(formDTO,customerStaff.getUserId(),wxMaJscode2SessionResult,token); + UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); + userTokenResultDTO.setToken(token); + return userTokenResultDTO; + } + + /** + * @return com.epmet.commons.tools.utils.Result + * @param userId + * @param openid + * @Author yinzuomei + * @Description 保存微信和当前登录用户关系 + * @Date 2020/4/18 22:54 + **/ + private Result savestaffwechat(String userId, String openid) { + StaffWechatFormDTO staffWechatFormDTO = new StaffWechatFormDTO(); + staffWechatFormDTO.setUserId(userId); + staffWechatFormDTO.setWxOpenId(openid); + return epmetUserFeignClient.savestaffwechat(staffWechatFormDTO); + } + + /** + * @Description 生成token + * @Date 2020/4/18 23:04 + **/ + private String generateToken(LoginCommonFormDTO formDTO,String userId){ + Map map = new HashMap<>(); + map.put("app", formDTO.getApp()); + map.put("client", formDTO.getClient()); + map.put("userId", userId); + String token = jwtTokenUtils.createToken(map); + logger.info("app:"+formDTO.getApp()+";client:"+formDTO.getClient()+";userId:"+userId+";生成token["+token+"]"); + return token; + } + + /** + * @Description 生成token + * @Date 2020/4/18 23:04 + **/ + private String saveTokenDto(LoginCommonFormDTO formDTO, + String userId, + WxMaJscode2SessionResult wxMaJscode2SessionResult, + String token) { + int expire = jwtTokenProperties.getExpire(); + TokenDto tokenDto = new TokenDto(); + tokenDto.setApp(formDTO.getApp()); + tokenDto.setClient(formDTO.getClient()); + tokenDto.setUserId(userId); + tokenDto.setOpenId(wxMaJscode2SessionResult.getOpenid()); + tokenDto.setSessionKey(wxMaJscode2SessionResult.getSessionKey()); + tokenDto.setUnionId(wxMaJscode2SessionResult.getUnionid()); + tokenDto.setToken(token); + tokenDto.setUpdateTime(System.currentTimeMillis()); + tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); + cpUserDetailRedis.set(tokenDto, expire); + logger.info("截止时间:"+ DateUtils.format(jwtTokenUtils.getExpiration(token),"yyyy-MM-dd HH:mm:ss")); + return token; + } + } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java index 4280c7d0f6..127006790a 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java @@ -3,9 +3,6 @@ package com.epmet.service.impl; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; import com.epmet.common.token.constant.LoginConstant; -import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; -import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; -import com.epmet.common.token.dto.result.UserTokenResultDTO; import com.epmet.commons.tools.exception.ErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; @@ -14,9 +11,12 @@ import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.UserDTO; import com.epmet.dto.UserWechatDTO; +import com.epmet.dto.form.LoginByPassWordFormDTO; +import com.epmet.dto.form.LoginByWxCodeFormDTO; import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; import com.epmet.dto.form.WxLoginUserInfoFormDTO; import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; +import com.epmet.dto.result.UserTokenResultDTO; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.jwt.JwtTokenProperties; import com.epmet.jwt.JwtTokenUtils; @@ -73,7 +73,7 @@ public class LoginServiceImpl implements LoginService { @Override public Result loginByWxCode(LoginByWxCodeFormDTO formDTO) { //1、根据wxCode获取微信信息 - WxMaJscode2SessionResult wxMaJscode2SessionResult = this.getWxMaUser(formDTO); + WxMaJscode2SessionResult wxMaJscode2SessionResult = this.getWxMaUser(formDTO.getApp(),formDTO.getWxCode()); logger.info("openId=[" + wxMaJscode2SessionResult.getOpenid() + "]unionId=[" + wxMaJscode2SessionResult.getUnionid() + "]"); //2、根据openId查询数据库,没有则直接插入一条记录 String userId = this.getUserId(formDTO, wxMaJscode2SessionResult); @@ -91,27 +91,31 @@ public class LoginServiceImpl implements LoginService { /** * 解析微信code获取小程序用户信息 * - * @param formDTO + * @param app + * @param wxCode * @return cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult * @author yinzuomei * @date 2020/3/14 20:16 */ - private WxMaJscode2SessionResult getWxMaUser(LoginByWxCodeFormDTO formDTO) { + @Override + public WxMaJscode2SessionResult getWxMaUser(String app,String wxCode) { WxMaJscode2SessionResult wxMaJscode2SessionResult = null; try { - if (LoginConstant.APP_GOV.equals(formDTO.getApp())) { - wxMaJscode2SessionResult = wxMaServiceUtils.govWxMaService().jsCode2SessionInfo(formDTO.getWxCode()); - } else if (LoginConstant.APP_OPER.equals(formDTO.getApp())) { - wxMaJscode2SessionResult = wxMaServiceUtils.operWxMaService().jsCode2SessionInfo(formDTO.getWxCode()); - } else if (LoginConstant.APP_RESI.equals(formDTO.getApp())) { - wxMaJscode2SessionResult = wxMaServiceUtils.resiWxMaService().jsCode2SessionInfo(formDTO.getWxCode()); + if (LoginConstant.APP_GOV.equals(app)) { + wxMaJscode2SessionResult = wxMaServiceUtils.govWxMaService().jsCode2SessionInfo(wxCode); + } else if (LoginConstant.APP_OPER.equals(app)) { + wxMaJscode2SessionResult = wxMaServiceUtils.operWxMaService().jsCode2SessionInfo(wxCode); + } else if (LoginConstant.APP_RESI.equals(app)) { + wxMaJscode2SessionResult = wxMaServiceUtils.resiWxMaService().jsCode2SessionInfo(wxCode); } } catch (WxErrorException e) { log.error("->[getMaOpenId]::error[{}]", "解析微信code失败"); } if (null == wxMaJscode2SessionResult) { + log.error(String.format("解析微信用户信息失败,app[%s],wxCode[%s]",app,wxCode)); throw new RenException("解析微信用户信息失败"); } else if (StringUtils.isBlank(wxMaJscode2SessionResult.getOpenid())) { + log.error(String.format("获取微信openid失败,app[%s],wxCode[%s]",app,wxCode)); throw new RenException("获取微信openid失败"); } return wxMaJscode2SessionResult; diff --git a/epmet-auth/src/main/resources/bootstrap.yml b/epmet-auth/src/main/resources/bootstrap.yml index 7b50c86084..f3c4a05e89 100644 --- a/epmet-auth/src/main/resources/bootstrap.yml +++ b/epmet-auth/src/main/resources/bootstrap.yml @@ -104,11 +104,11 @@ wx: token: #微信小程序消息服务器配置的token aesKey: #微信小程序消息服务器配置的EncodingAESKey msgDataFormat: JSON -# - appid: @gov.wx.ma.appId@ -# secret: @gov.wx.ma.secret@ -# token: #微信小程序消息服务器配置的token -# aesKey: #微信小程序消息服务器配置的EncodingAESKey -# msgDataFormat: JSON + - appid: @gov.wx.ma.appId@ + secret: @gov.wx.ma.secret@ + token: #微信小程序消息服务器配置的token + aesKey: #微信小程序消息服务器配置的EncodingAESKey + msgDataFormat: JSON # - appid: @oper.wx.ma.appId@ # secret: @oper.wx.ma.secret@ # token: #微信小程序消息服务器配置的token @@ -118,6 +118,6 @@ wx: # 党群e事通-居民端小程序配置appId resi: @resi.wx.ma.appId@ # 党群e事通-政府端小程序配置的appId - #gov: @gov.wx.ma.appId@ + gov: @gov.wx.ma.appId@ # 党群e事通-运营端小程序配置的appId #oper: @oper.wx.ma.appId@ diff --git a/epmet-cloud-generator/src/main/resources/application.yml b/epmet-cloud-generator/src/main/resources/application.yml index aec8fffa7f..ec95859518 100644 --- a/epmet-cloud-generator/src/main/resources/application.yml +++ b/epmet-cloud-generator/src/main/resources/application.yml @@ -9,7 +9,7 @@ spring: type: com.alibaba.druid.pool.DruidDataSource #MySQL配置 driverClassName: com.mysql.jdbc.Driver - url: jdbc:mysql://localhost:3306/epmet_gov_org?useUnicode=true&characterEncoding=UTF-8&useSSL=false + url: jdbc:mysql://localhost:3306/epmet_user?useUnicode=true&characterEncoding=UTF-8&useSSL=false username: epmet password: elink@833066 #oracle配置 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 e0c31a9709..199e38e235 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 @@ -204,7 +204,7 @@ public class RedisKeys { * @Description 政府端登录发送验证码 epmet:app:client:phone * @Date 2020/4/18 13:54 **/ - public static String getLoginSmsCodeKey(String app, String client, String phone, String smsCode) { + public static String getLoginSmsCodeKey(String app, String client, String phone) { return String.format(rootPrefix+"smsCode:login:%s:%s:%s",app,client,phone); } } diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index dbdf2ef12c..a451ebf0b2 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -144,13 +144,17 @@ http://127.0.0.1:8092 + http://127.0.0.1:8093 + http://127.0.0.1:8094 + http://127.0.0.1:8095 http://127.0.0.1:8096 + diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/StaffWechatDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/StaffWechatDTO.java new file mode 100644 index 0000000000..905ab9e741 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/StaffWechatDTO.java @@ -0,0 +1,127 @@ +/** + * 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.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 工作人员微信关系表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-18 + */ +@Data +public class StaffWechatDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 唯一标识 + */ + private String id; + + /** + * 用户Id user.id + */ + private String userId; + + /** + * openId + */ + private String wxOpenId; + + /** + * 微信unionId + */ + private String wxUnionId; + + /** + * 手机号 + */ + private String mobile; + + /** + * 昵称 + */ + private String nickname; + + /** + * 性别 + */ + private Integer sex; + + /** + * 头像 + */ + private String headImgUrl; + + /** + * 国家 + */ + private String country; + + /** + * 省份 + */ + private String province; + + /** + * 城市 + */ + private String city; + + /** + * 语言 + */ + private String language; + + /** + * 删除标识:0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffWechatFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffWechatFormDTO.java new file mode 100644 index 0000000000..37687e0b1b --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffWechatFormDTO.java @@ -0,0 +1,28 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description 保存工作人员-微信关系表 入参DTO + * @Author yinzuomei + * @Date 2020/4/18 22:25 + */ +@Data +public class StaffWechatFormDTO implements Serializable { + private static final long serialVersionUID = -2234700477129260997L; + /** + * 用户Id user.id + */ + @NotBlank(message = "userId不能为空") + private String userId; + + /** + * openId + */ + @NotBlank(message = "openId不能为空") + private String wxOpenId; +} + diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index 0cc107aeb7..f097f86d5e 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -99,7 +99,7 @@ public class CustomerStaffController { * @Date 2020/4/18 14:07 **/ @GetMapping(value = "getcustsomerstaffbyphone/{phone}") - public Result getCustsomerStaffByPhone(@PathVariable("phone") String phone) { + public Result getCustsomerStaffByPhone(@PathVariable("phone") String phone) { return customerStaffService.getCustsomerStaffByPhone(phone); } } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffWechatController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffWechatController.java new file mode 100644 index 0000000000..5a0e1cb06f --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffWechatController.java @@ -0,0 +1,57 @@ +/** + * 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.controller; + +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.StaffWechatFormDTO; +import com.epmet.service.StaffWechatService; +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 generator generator@elink-cn.com + * @since v1.0.0 2020-04-18 + */ +@RestController +@RequestMapping("staffwechat") +public class StaffWechatController { + + @Autowired + private StaffWechatService staffWechatService; + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机验证码登录时记录微信openId与当前用户的关系 + * @Date 2020/4/18 22:33 + **/ + @PostMapping(value = "savestaffwechat") + public Result saveStaffWechat(@RequestBody StaffWechatFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); + return staffWechatService.savesaveStaffWechat(formDTO); + } +} \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffWechatDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffWechatDao.java new file mode 100644 index 0000000000..b65f262f94 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffWechatDao.java @@ -0,0 +1,43 @@ +/** + * 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.StaffWechatDTO; +import com.epmet.entity.StaffWechatEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 工作人员微信关系表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-18 + */ +@Mapper +public interface StaffWechatDao extends BaseDao { + /** + * @param userId + * @param wxOpenId + * @return com.epmet.dto.StaffWechatDTO + * @Author yinzuomei + * @Description 根据userId+wxOpenId查询记录 + * @Date 2020/4/18 22:37 + **/ + StaffWechatDTO selectByUserIdAndOpenId(@Param("userId") String userId, @Param("wxOpenId") String wxOpenId); +} \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/StaffWechatEntity.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/StaffWechatEntity.java new file mode 100644 index 0000000000..d2ebd5c411 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/StaffWechatEntity.java @@ -0,0 +1,93 @@ +/** + * 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; + +/** + * 工作人员微信关系表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-18 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("staff_wechat") +public class StaffWechatEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 用户Id user.id + */ + private String userId; + + /** + * openId + */ + private String wxOpenId; + + /** + * 微信unionId + */ + private String wxUnionId; + + /** + * 手机号 + */ + private String mobile; + + /** + * 昵称 + */ + private String nickname; + + /** + * 性别 + */ + private Integer sex; + + /** + * 头像 + */ + private String headImgUrl; + + /** + * 国家 + */ + private String country; + + /** + * 省份 + */ + private String province; + + /** + * 城市 + */ + private String city; + + /** + * 语言 + */ + private String language; + +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index 5a9ef31f29..ef5d1559b9 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -101,5 +101,5 @@ public interface CustomerStaffService extends BaseService { * @Description 根据手机号查询政府端工作人员基本信息,校验用户是否存在 * @Date 2020/4/18 14:07 **/ - Result getCustsomerStaffByPhone(String phone); + Result getCustsomerStaffByPhone(String phone); } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffWechatService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffWechatService.java new file mode 100644 index 0000000000..a3a771abc9 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffWechatService.java @@ -0,0 +1,106 @@ +/** + * 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.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.StaffWechatDTO; +import com.epmet.dto.form.StaffWechatFormDTO; +import com.epmet.entity.StaffWechatEntity; + +import java.util.List; +import java.util.Map; + +/** + * 工作人员微信关系表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-18 + */ +public interface StaffWechatService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-04-18 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-04-18 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return StaffWechatDTO + * @author generator + * @date 2020-04-18 + */ + StaffWechatDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-18 + */ + void save(StaffWechatDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-18 + */ + void update(StaffWechatDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2020-04-18 + */ + void delete(String[] ids); + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机验证码登录时记录微信openId与当前用户的关系 + * @Date 2020/4/18 22:34 + **/ + Result savesaveStaffWechat(StaffWechatFormDTO formDTO); +} \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index a3f8883655..7470edc96d 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -107,7 +107,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl getCustsomerStaffByPhone(String phone) { //判断用户是否存在 QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(phone), FieldConstant.MOBILE, phone); @@ -122,7 +122,8 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl + * 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.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dao.StaffWechatDao; +import com.epmet.dto.StaffWechatDTO; +import com.epmet.dto.form.StaffWechatFormDTO; +import com.epmet.entity.StaffWechatEntity; +import com.epmet.service.StaffWechatService; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 工作人员微信关系表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-18 + */ +@Service +public class StaffWechatServiceImpl extends BaseServiceImpl implements StaffWechatService { + private Logger logger = LogManager.getLogger(getClass()); + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, StaffWechatDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, StaffWechatDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public StaffWechatDTO get(String id) { + StaffWechatEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, StaffWechatDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(StaffWechatDTO dto) { + StaffWechatEntity entity = ConvertUtils.sourceToTarget(dto, StaffWechatEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(StaffWechatDTO dto) { + StaffWechatEntity entity = ConvertUtils.sourceToTarget(dto, StaffWechatEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机验证码登录时记录微信openId与当前用户的关系 + * @Date 2020/4/18 22:34 + **/ + @Override + public Result savesaveStaffWechat(StaffWechatFormDTO formDTO) { + StaffWechatDTO staffWechatDTO = baseDao.selectByUserIdAndOpenId(formDTO.getUserId(), formDTO.getWxOpenId()); + if (null == staffWechatDTO) { + StaffWechatDTO staffWechat = ConvertUtils.sourceToTarget(formDTO, StaffWechatDTO.class); + this.save(staffWechat); + logger.info(String.format("staff_Wechat保存成功,userId[%s],wxOpenId[%s]", formDTO.getUserId(), formDTO.getWxOpenId())); + } else { + logger.info(String.format("staff_Wechat记录已存在,userId[%s],wxOpenId[%s]", formDTO.getUserId(), formDTO.getWxOpenId())); + this.update(staffWechatDTO); + } + return new Result(); + } + +} \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/db/migration/epmet_user.sql b/epmet-user/epmet-user-server/src/main/resources/db/migration/epmet_user.sql index fc7bb25e13..76ffc92239 100644 --- a/epmet-user/epmet-user-server/src/main/resources/db/migration/epmet_user.sql +++ b/epmet-user/epmet-user-server/src/main/resources/db/migration/epmet_user.sql @@ -10,4 +10,27 @@ alter table customer_staff add column ENABLE_FLAG VARCHAR(20) not null COMMENT alter table customer_staff add column WORK_TYPE VARCHAR(20) not null comment 'fulltime专职parttime兼职'; -- --2020-04-18 -alter table customer_staff add column CUSTOMER_ID varchar(64) NOT NULL COMMENT '客户Id CUSTOMER.id'; \ No newline at end of file +alter table customer_staff add column CUSTOMER_ID varchar(64) NOT NULL COMMENT '客户Id CUSTOMER.id'; + +-- --2020-04-18v2 +CREATE TABLE `staff_wechat` ( + `ID` varchar(64) NOT NULL COMMENT '唯一标识', + `USER_ID` varchar(64) NOT NULL COMMENT '用户Id user.id', + `WX_OPEN_ID` varchar(64) NOT NULL COMMENT 'openId', + `WX_UNION_ID` varchar(64) DEFAULT NULL COMMENT '微信unionId', + `MOBILE` varchar(11) DEFAULT NULL COMMENT '手机号', + `NICKNAME` varchar(32) DEFAULT NULL COMMENT '昵称', + `SEX` int(11) DEFAULT NULL COMMENT '性别', + `HEAD_IMG_URL` varchar(1024) DEFAULT NULL COMMENT '头像', + `COUNTRY` varchar(32) DEFAULT NULL COMMENT '国家', + `PROVINCE` varchar(32) DEFAULT NULL COMMENT '省份', + `CITY` varchar(32) DEFAULT NULL COMMENT '城市', + `LANGUAGE` varchar(32) DEFAULT NULL COMMENT '语言', + `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 '更新时间', + PRIMARY KEY (`ID`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='工作人员微信关系表 '; \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/StaffWechatDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/StaffWechatDao.xml new file mode 100644 index 0000000000..96364611eb --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/StaffWechatDao.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file