Browse Source

登陆接口v1

master
yinzuomei 5 years ago
parent
commit
7c76facd1e
  1. 9
      epmet-auth/pom.xml
  2. 15
      epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java
  3. 7
      epmet-auth/src/main/java/com/epmet/controller/LoginController.java
  4. 2
      epmet-auth/src/main/java/com/epmet/dto/form/LoginByPassWordFormDTO.java
  5. 5
      epmet-auth/src/main/java/com/epmet/dto/form/LoginByPhoneFormDTO.java
  6. 2
      epmet-auth/src/main/java/com/epmet/dto/form/LoginByWxCodeFormDTO.java
  7. 2
      epmet-auth/src/main/java/com/epmet/dto/form/LoginCommonFormDTO.java
  8. 8
      epmet-auth/src/main/java/com/epmet/dto/form/SendSmsCodeFormDTO.java
  9. 2
      epmet-auth/src/main/java/com/epmet/dto/result/UserTokenResultDTO.java
  10. 14
      epmet-auth/src/main/java/com/epmet/feign/EpmetUserFeignClient.java
  11. 9
      epmet-auth/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java
  12. 15
      epmet-auth/src/main/java/com/epmet/redis/CaptchaRedis.java
  13. 11
      epmet-auth/src/main/java/com/epmet/service/GovLoginService.java
  14. 17
      epmet-auth/src/main/java/com/epmet/service/LoginService.java
  15. 118
      epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java
  16. 28
      epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java
  17. 12
      epmet-auth/src/main/resources/bootstrap.yml
  18. 2
      epmet-cloud-generator/src/main/resources/application.yml
  19. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  20. 4
      epmet-gateway/pom.xml
  21. 127
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/StaffWechatDTO.java
  22. 28
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/StaffWechatFormDTO.java
  23. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java
  24. 57
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffWechatController.java
  25. 43
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffWechatDao.java
  26. 93
      epmet-user/epmet-user-server/src/main/java/com/epmet/entity/StaffWechatEntity.java
  27. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java
  28. 106
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffWechatService.java
  29. 5
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java
  30. 125
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffWechatServiceImpl.java
  31. 25
      epmet-user/epmet-user-server/src/main/resources/db/migration/epmet_user.sql
  32. 18
      epmet-user/epmet-user-server/src/main/resources/mapper/StaffWechatDao.xml

9
epmet-auth/pom.xml

@ -149,6 +149,9 @@
<!--居民端小程序配置-->
<resi.wx.ma.appId>wx9b6102a8ee5add65</resi.wx.ma.appId>
<resi.wx.ma.secret>16fdb68bc2b3e732324ba5d8b8a9b5e2</resi.wx.ma.secret>
<!--政府端小程序配置-->
<resi.wx.ma.appId>wx3d1372029eb816a3</resi.wx.ma.appId>
<resi.wx.ma.secret>651f02d71ed3f123dfb584b8bf0f4d8b</resi.wx.ma.secret>
</properties>
</profile>
@ -183,6 +186,9 @@
<!--居民端小程序配置-->
<resi.wx.ma.appId>wx9b6102a8ee5add65</resi.wx.ma.appId>
<resi.wx.ma.secret>16fdb68bc2b3e732324ba5d8b8a9b5e2</resi.wx.ma.secret>
<!--政府端小程序配置-->
<resi.wx.ma.appId>wx3d1372029eb816a3</resi.wx.ma.appId>
<resi.wx.ma.secret>651f02d71ed3f123dfb584b8bf0f4d8b</resi.wx.ma.secret>
</properties>
</profile>
@ -217,6 +223,9 @@
<!--居民端小程序配置-->
<resi.wx.ma.appId>wx9b6102a8ee5add65</resi.wx.ma.appId>
<resi.wx.ma.secret>16fdb68bc2b3e732324ba5d8b8a9b5e2</resi.wx.ma.secret>
<!--政府端小程序配置-->
<resi.wx.ma.appId>wx3d1372029eb816a3</resi.wx.ma.appId>
<resi.wx.ma.secret>651f02d71ed3f123dfb584b8bf0f4d8b</resi.wx.ma.secret>
</properties>
</profile>
</profiles>

15
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<com.epmet.common.token.dto.result.UserTokenResultDTO>
* @Author yinzuomei
* @Description 手机验证码登录
* @Date 2020/4/18 21:14
**/
@PostMapping(value = "loginbyphone")
public Result<UserTokenResultDTO> loginByPhone(LoginByPhoneFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return govLoginService.loginByPhone(formDTO);
}
}

7
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;

2
epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java → 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;

5
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;
}

2
epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java → 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;

2
epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java → 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;

8
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;
}

2
epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java → 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;

14
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<CustomerStaffDTO> 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);
}

9
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<CustomerStaffDTO> 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);
}
}

15
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;
}
}

11
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<com.epmet.common.token.dto.result.UserTokenResultDTO>
* @Author yinzuomei
* @Description 手机验证码登录
* @Date 2020/4/18 21:11
**/
Result<UserTokenResultDTO> loginByPhone(LoginByPhoneFormDTO formDTO);
}

17
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);
}

118
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<CustomerStaffDTO> 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<com.epmet.common.token.dto.result.UserTokenResultDTO>
* @Author yinzuomei
* @Description 手机验证码登录
* @Date 2020/4/18 21:11
**/
@Override
public Result<UserTokenResultDTO> loginByPhone(LoginByPhoneFormDTO formDTO) {
//1、根据手机号查询到用户信息
Result<CustomerStaffDTO> 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<UserTokenResultDTO>().error(EpmetErrorCode.MOBILE_CODE_ERROR.getCode());
}
//3、解析wxCode
UserTokenResultDTO userTokenResultDTO=this.getAuthorizationInfo(formDTO,customerStaffResult.getData());
return new Result<UserTokenResultDTO>().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<String, Object> 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;
}
}

28
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<UserTokenResultDTO> 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;

12
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@

2
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配置

2
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);
}
}

4
epmet-gateway/pom.xml

@ -144,13 +144,17 @@
<!-- <gateway.routes.gov-org-server.uri>lb://gov-org-server</gateway.routes.gov-org-server.uri>-->
<gateway.routes.gov-org-server.uri>http://127.0.0.1:8092</gateway.routes.gov-org-server.uri>
<!-- 14、#运营端访问权限控制 -->
<!-- <gateway.routes.oper-access-server.uri>lb://oper-access-server</gateway.routes.oper-access-server.uri>-->
<gateway.routes.oper-access-server.uri>http://127.0.0.1:8093</gateway.routes.oper-access-server.uri>
<!-- 15、居民端个人信息 -->
<!-- <gateway.routes.resi-mine-server.uri>lb://resi-mine-server</gateway.routes.resi-mine-server.uri>-->
<gateway.routes.resi-mine-server.uri>http://127.0.0.1:8094</gateway.routes.resi-mine-server.uri>
<!-- 16、居民端楼院校组 -->
<!-- <gateway.routes.resi-group-server.uri>lb://resi-group-server</gateway.routes.resi-group-server.uri>-->
<gateway.routes.resi-group-server.uri>http://127.0.0.1:8095</gateway.routes.resi-group-server.uri>
<!-- 17、党员认证、热心居民申请 -->
<gateway.routes.resi-partymember-server.uri>http://127.0.0.1:8096</gateway.routes.resi-partymember-server.uri>
<!-- <gateway.routes.resi-partymember-server.uri>lb://resi-partymember-server</gateway.routes.resi-partymember-server.uri>-->
</properties>
</profile>
<profile>

127
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/StaffWechatDTO.java

@ -0,0 +1,127 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

28
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;
}

2
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<CustomerStaffDTO> getCustsomerStaffByPhone(@PathVariable("phone") String phone) {
return customerStaffService.getCustsomerStaffByPhone(phone);
}
}

57
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffWechatController.java

@ -0,0 +1,57 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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);
}
}

43
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffWechatDao.java

@ -0,0 +1,43 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<StaffWechatEntity> {
/**
* @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);
}

93
epmet-user/epmet-user-server/src/main/java/com/epmet/entity/StaffWechatEntity.java

@ -0,0 +1,93 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

2
epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java

@ -101,5 +101,5 @@ public interface CustomerStaffService extends BaseService<CustomerStaffEntity> {
* @Description 根据手机号查询政府端工作人员基本信息校验用户是否存在
* @Date 2020/4/18 14:07
**/
Result getCustsomerStaffByPhone(String phone);
Result<CustomerStaffDTO> getCustsomerStaffByPhone(String phone);
}

106
epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffWechatService.java

@ -0,0 +1,106 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<StaffWechatEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<StaffWechatDTO>
* @author generator
* @date 2020-04-18
*/
PageData<StaffWechatDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<StaffWechatDTO>
* @author generator
* @date 2020-04-18
*/
List<StaffWechatDTO> list(Map<String, Object> 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);
}

5
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java

@ -107,7 +107,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
}
@Override
public Result getCustsomerStaffByPhone(String phone) {
public Result<CustomerStaffDTO> getCustsomerStaffByPhone(String phone) {
//判断用户是否存在
QueryWrapper<CustomerStaffEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(phone), FieldConstant.MOBILE, phone);
@ -122,7 +122,8 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
logger.error(String.format("根据手机号查询用户异常,手机号:[%s],code[%s],msg[%s]",phone,EpmetErrorCode.GOV_STAFF_DISABLED.getCode(),EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()));
return new Result().error(EpmetErrorCode.GOV_STAFF_DISABLED.getCode());
}
return new Result();
CustomerStaffDTO customerStaffDTO=ConvertUtils.sourceToTarget(customerStaff, CustomerStaffDTO.class);
return new Result().ok(customerStaffDTO);
}
}

125
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffWechatServiceImpl.java

@ -0,0 +1,125 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<StaffWechatDao, StaffWechatEntity> implements StaffWechatService {
private Logger logger = LogManager.getLogger(getClass());
@Override
public PageData<StaffWechatDTO> page(Map<String, Object> params) {
IPage<StaffWechatEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
getWrapper(params)
);
return getPageData(page, StaffWechatDTO.class);
}
@Override
public List<StaffWechatDTO> list(Map<String, Object> params) {
List<StaffWechatEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, StaffWechatDTO.class);
}
private QueryWrapper<StaffWechatEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
QueryWrapper<StaffWechatEntity> 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();
}
}

25
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';
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='工作人员微信关系表 ';

18
epmet-user/epmet-user-server/src/main/resources/mapper/StaffWechatDao.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.StaffWechatDao">
<!-- 根据userId+wxOpenId查询记录 -->
<select id="selectByUserIdAndOpenId" parameterType="map" resultType="com.epmet.dto.StaffWechatDTO">
SELECT
*
FROM
staff_wechat sw
WHERE
sw.DEL_FLAG = '0'
AND sw.USER_ID = #{userId}
AND sw.WX_OPEN_ID = #{wxOpenId}
</select>
</mapper>
Loading…
Cancel
Save