Browse Source

公众号部分接口调整

master
sunyuchao 5 years ago
parent
commit
ad2fbb2d22
  1. 2
      epmet-auth/src/main/java/com/epmet/constant/ThirdApiConstant.java
  2. 10
      epmet-auth/src/main/java/com/epmet/controller/PublicUserLoginController.java
  3. 5
      epmet-auth/src/main/java/com/epmet/dto/form/LoginByPhoneFormDTO.java
  4. 6
      epmet-auth/src/main/java/com/epmet/dto/form/PublicSendSmsCodeFormDTO.java
  5. 21
      epmet-auth/src/main/java/com/epmet/service/impl/PublicUserLoginServiceImpl.java
  6. 27
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CheckPaUserFormDTO.java
  7. 5
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RegisterFormDTO.java
  8. 7
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PaUserController.java
  9. 15
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserDao.java
  10. 7
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PaUserService.java
  11. 14
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java
  12. 7
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserServiceImpl.java
  13. 1
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserVisitedServiceImpl.java
  14. 19
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml
  15. 3
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserVisitedDao.xml

2
epmet-auth/src/main/java/com/epmet/constant/ThirdApiConstant.java

@ -13,7 +13,7 @@ public interface ThirdApiConstant {
/**
* 根据手机号查询公众号用户基本信息校验用户是否存在
*/
String THIRD_PAUSER_CHECKPAUSER = "https://epmet-cloud.elinkservice.cn/api/third/pauser/checkpauser/";
String THIRD_PAUSER_CHECKPAUSER = "https://epmet-cloud.elinkservice.cn/api/third/pauser/checkpauser";
/**
* 用户登陆新增访问记录数据
*/

10
epmet-auth/src/main/java/com/epmet/controller/PublicUserLoginController.java

@ -54,11 +54,12 @@ public class PublicUserLoginController {
* @Description 公众号登录-发送验证码
**/
@PostMapping(value = "/sendsmscode")
public Result sendSmsCode(@RequestBody PublicSendSmsCodeFormDTO formDTO) {
public Result sendSmsCode(@RequestHeader("source") String source, @RequestBody PublicSendSmsCodeFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO,PublicSendSmsCodeFormDTO.AddUserShowGroup.class);
if(formDTO.getIsLogon()!=true&&formDTO.getIsLogon()!=false){
if (formDTO.getIsLogon() != true && formDTO.getIsLogon() != false) {
throw new RenException(PublicUserLoginConstant.PARAMETER_EXCEPTION);
}
formDTO.setSource(source);
publicUserLoginService.sendSmsCode(formDTO);
return new Result();
}
@ -72,7 +73,7 @@ public class PublicUserLoginController {
@PostMapping(value = "/loginbyphone")
public Result<UserTokenResultDTO> loginByPhone(@RequestHeader("source") String source, @LoginUser TokenDto tokenDTO, @RequestBody LoginByPhoneFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, LoginByPhoneFormDTO.AddUserShowGroup.class, LoginByPhoneFormDTO.LoginByPhone.class);
System.out.println(source);
formDTO.setSource(source);
return new Result<UserTokenResultDTO>().ok(publicUserLoginService.loginByPhone(tokenDTO, formDTO));
}
@ -83,9 +84,10 @@ public class PublicUserLoginController {
* @Description 公众号-手机号注册
**/
@PostMapping(value = "/register")
public Result<UserTokenResultDTO> register(@LoginUser TokenDto tokenDTO, @RequestBody RegisterFormDTO formDTO) {
public Result<UserTokenResultDTO> register(@RequestHeader("source") String source, @LoginUser TokenDto tokenDTO, @RequestBody RegisterFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, RegisterFormDTO.AddUserInternalGroup.class, RegisterFormDTO.AddUserShowGroup.class);
formDTO.setUserId(tokenDTO.getUserId());
formDTO.setSource(source);
return new Result<UserTokenResultDTO>().ok(publicUserLoginService.register(formDTO));
}

5
epmet-auth/src/main/java/com/epmet/dto/form/LoginByPhoneFormDTO.java

@ -34,5 +34,10 @@ public class LoginByPhoneFormDTO implements Serializable {
@NotBlank(message="验证码不能为空", groups = {LoginByPhone.class})
private String smsCode;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
private String source;
}

6
epmet-auth/src/main/java/com/epmet/dto/form/PublicSendSmsCodeFormDTO.java

@ -26,8 +26,14 @@ public class PublicSendSmsCodeFormDTO implements Serializable {
*/
@NotBlank(message = "手机号不能为空", groups = {AddUserShowGroup.class})
private String phone;
/**
* 是否登陆登陆true 注册false
*/
private Boolean isLogon;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
private String source;
}

21
epmet-auth/src/main/java/com/epmet/service/impl/PublicUserLoginServiceImpl.java

@ -162,9 +162,12 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService {
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getPhone(), EpmetErrorCode.ERROR_PHONE.getCode(), EpmetErrorCode.ERROR_PHONE.getMsg()));
throw new RenException(EpmetErrorCode.ERROR_PHONE.getCode());
}
//2、根据手机号校验用户是否存在
String url = ThirdApiConstant.THIRD_PAUSER_CHECKPAUSER + formDTO.getPhone();
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, null);
//2、根据数据来源和手机号校验用户是否存在
CheckPaUserFormDTO dto = new CheckPaUserFormDTO();
dto.setPhone(formDTO.getPhone());
dto.setSource(formDTO.getSource());
String url = ThirdApiConstant.THIRD_PAUSER_CHECKPAUSER;
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(dto));
if (!result.success()) {
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getPhone(), result.getCode(), result.getMsg()));
throw new RenException(result.getCode());
@ -201,9 +204,12 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService {
**/
@Override
public UserTokenResultDTO loginByPhone(TokenDto tokenDTO, LoginByPhoneFormDTO formDTO) {
//1.根据手机号查询到用户、客户信息
String url = ThirdApiConstant.THIRD_PAUSER_CHECKPAUSER + formDTO.getPhone();
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, null);
//1.根据数据来源和手机号查询用户、客户信息
CheckPaUserFormDTO dto = new CheckPaUserFormDTO();
dto.setPhone(formDTO.getPhone());
dto.setSource(formDTO.getSource());
String url = ThirdApiConstant.THIRD_PAUSER_CHECKPAUSER;
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(dto));
if (!result.success()) {
logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getPhone(), result.getCode(), result.getMsg()));
throw new RenException(result.getCode());
@ -244,6 +250,7 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService {
visited.setUserId(userDTO.getId());
visited.setLogonUserId(tokenDTO.getUserId());
visited.setPhone(formDTO.getPhone());
visited.setSource(formDTO.getSource());
String saveUserVisitedUrl = ThirdApiConstant.THIRD_PAUSERVISITED_SAVEUSERVISITED;
Result<String> visitedResult = HttpClientManager.getInstance().sendPostByJSON(saveUserVisitedUrl, JSON.toJSONString(visited));
if(!visitedResult.success()){
@ -269,7 +276,7 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService {
JSONObject toResult = JSON.parseObject(data);
Result result = ConvertUtils.mapToEntity(toResult, Result.class);
if (!result.success()) {
logger.error("调用epmet_third服务初始化用户信息失败");
logger.error(String.format("调用epmet_third服务初始化用户信息失败,数据来源[%s],手机号[%s],userId:[%S]", formDTO.getSource(), formDTO.getPhone(), formDTO.getUserId()));
throw new RenException(result.getCode());
}
Object RegisterResult = result.getData();

27
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CheckPaUserFormDTO.java

@ -0,0 +1,27 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 公众号-发送短信验证码-接口入参
* @Author sun
*/
@Data
public class CheckPaUserFormDTO implements Serializable {
private static final long serialVersionUID = -6163303184086480522L;
/**
* s手机号
*/
private String phone;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
private String source;
}

5
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RegisterFormDTO.java

@ -51,4 +51,9 @@ public class RegisterFormDTO implements Serializable {
*/
private String userId;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
private String source;
}

7
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PaUserController.java

@ -26,6 +26,7 @@ import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.form.CheckPaUserFormDTO;
import com.epmet.dto.form.WxCodeToTokenFormDTO;
import com.epmet.dto.result.CustomerUserResultDTO;
import com.epmet.dto.result.SaveUserResultDTO;
@ -106,14 +107,14 @@ public class PaUserController {
}
/**
* @param phone
* @param formDTO
* @return
* @Author sun
* @Description 根据手机号查询公众号用户基本信息校验用户是否存在
**/
@PostMapping(value = "/checkpauser/{phone}")
public Result<CustomerUserResultDTO> checkPaUser(@PathVariable("phone") String phone) {
return new Result<CustomerUserResultDTO>().ok(paUserService.checkPaUser(phone));
public Result<CustomerUserResultDTO> checkPaUser(@RequestBody CheckPaUserFormDTO formDTO) {
return new Result<CustomerUserResultDTO>().ok(paUserService.checkPaUser(formDTO));
}
}

15
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserDao.java

@ -19,6 +19,7 @@ package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.form.CheckPaUserFormDTO;
import com.epmet.entity.PaUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -35,12 +36,12 @@ import java.util.List;
public interface PaUserDao extends BaseDao<PaUserEntity> {
/**
* @param phone
* @param phone source
* @return
* @Author sun
* @Description 根据手机号查询公众号用户基本信息校验用户是否存在
* @Description 根据数据来源和手机号查询公众号用户基本信息校验用户是否存在
**/
List<PaUserDTO> selectUserByPhone(@Param("phone") String phone);
List<PaUserDTO> selectUserByPhone(@Param("phone") String phone, @Param("source") String source);
/**
* @param customerId
@ -49,4 +50,12 @@ public interface PaUserDao extends BaseDao<PaUserEntity> {
* @Description 根据客户Id级联查询客户管理员注册信息
**/
PaUserDTO selectPaUser(@Param("customerId") String customerId);
/**
* @param id source
* @return
* @Author sun
* @Description 根据数据来源和手机号查询公众号用户基本信息校验用户是否存在
**/
PaUserDTO selectUser(@Param("id") String id, @Param("source") String source);
}

7
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PaUserService.java

@ -20,6 +20,7 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.form.CheckPaUserFormDTO;
import com.epmet.dto.form.WxCodeToTokenFormDTO;
import com.epmet.dto.result.CustomerUserResultDTO;
import com.epmet.dto.result.SaveUserResultDTO;
@ -105,10 +106,10 @@ public interface PaUserService extends BaseService<PaUserEntity> {
SaveUserResultDTO saveUser(WxCodeToTokenFormDTO formDTO);
/**
* @param phone
* @param formDTO
* @return
* @Author sun
* @Description 根据手机号查询公众号用户基本信息校验用户是否存在
* @Description 根据数据来源和手机号查询公众号用户基本信息校验用户是否存在
**/
CustomerUserResultDTO checkPaUser(String phone);
CustomerUserResultDTO checkPaUser(CheckPaUserFormDTO formDTO);
}

14
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java

@ -164,21 +164,21 @@ public class PaCustomerServiceImpl extends BaseServiceImpl<PaCustomerDao, PaCust
throw new RenException(EpmetErrorCode.MOBILE_CODE_ERROR.getCode());
}
//1.根据手机号查询到用户信息,判断用户是否存
List<PaUserDTO> userList = paUserDao.selectUserByPhone(formDTO.getPhone());
//1.根据数据来源和手机号查询到用户信息,判断用户是否存
List<PaUserDTO> userList = paUserDao.selectUserByPhone(formDTO.getPhone(), formDTO.getSource());
if (null != userList && userList.size() > NumConstant.ZERO) {
throw new RenException(EpmetErrorCode.MOBILE_USED.getCode());
}
//2.根据token中的userId查询pa_user表数据,根据手机号是否为空判断后续是新增还是更新user数据
PaUserEntity paUserEntity = paUserDao.selectById(formDTO.getUserId());
if (null == paUserEntity) {
logger.error("根据token中userId查询pa_user表信息失败,userId->"+formDTO.getUserId());
//2.根据数据来源和token中的userId查询pa_user表数据,根据手机号是否为空判断后续是新增还是更新user数据
PaUserDTO paUserDTO= paUserDao.selectUser(formDTO.getUserId(), formDTO.getSource());
if (null == paUserDTO) {
logger.error("根据数据来源和token中userId查询pa_user表信息失败,数据来源->" + formDTO.getSource() + ",userId->" + formDTO.getUserId());
throw new RenException(PaConstant.SELECT_USER_EXCEPTION);
}
//3.手机号不为空说明是同一个微信用户用第二个手机号注册,手机为空说明当前微信用户用第一个手机号注册
if(StringUtils.isNotBlank(paUserEntity.getPhone())){
if(StringUtils.isNotBlank(paUserDTO.getPhone())){
//手机号不为空说明是同一个微信用户用第二个手机号注册,新增user和user_wechat表数据
//3-1.user表新增数据
PaUserEntity userEntity = new PaUserEntity();

7
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserServiceImpl.java

@ -34,6 +34,7 @@ import com.epmet.dto.PaCustomerDTO;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.PaUserVisitedDTO;
import com.epmet.dto.PaUserWechatDTO;
import com.epmet.dto.form.CheckPaUserFormDTO;
import com.epmet.dto.form.SaveUserVisitedFormDTO;
import com.epmet.dto.form.WxCodeToTokenFormDTO;
import com.epmet.dto.result.CustomerUserResultDTO;
@ -201,16 +202,16 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity>
}
/**
* @param phone
* @param formDTO
* @return
* @Author sun
* @Description 根据手机号查询公众号用户基本信息校验用户是否存在
**/
@Override
public CustomerUserResultDTO checkPaUser(String phone) {
public CustomerUserResultDTO checkPaUser(CheckPaUserFormDTO formDTO) {
CustomerUserResultDTO resultDTO = new CustomerUserResultDTO();
//1.根据手机号查询用户信息
List<PaUserDTO> userList = baseDao.selectUserByPhone(phone);
List<PaUserDTO> userList = baseDao.selectUserByPhone(formDTO.getPhone(), formDTO.getSource());
if (null == userList || userList.size() < NumConstant.ONE) {
resultDTO.setPaUserResult(null);
resultDTO.setPaCustomerResult(null);

1
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserVisitedServiceImpl.java

@ -135,6 +135,7 @@ public class PaUserVisitedServiceImpl extends BaseServiceImpl<PaUserVisitedDao,
entity.setWxOpenId(userEntity.getWxOpenId());
entity.setOpenId(openId);
entity.setPhone(visited.getPhone());
entity.setSource(visited.getSource());
baseDao.insert(entity);
}

19
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml

@ -8,12 +8,14 @@
id,
phone,
real_name,
gender
gender,
source
FROM
pa_user
WHERE
del_flag = '0'
AND phone = #{phone}
AND source = #{source}
</select>
<select id="selectPaUser" resultType="com.epmet.dto.PaUserDTO">
@ -33,4 +35,19 @@
LIMIT 1
</select>
<select id="selectUser" resultType="com.epmet.dto.PaUserDTO">
SELECT
id,
phone,
real_name,
gender,
source
FROM
pa_user
WHERE
del_flag = '0'
AND id = #{id}
AND source = #{source}
</select>
</mapper>

3
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserVisitedDao.xml

@ -9,7 +9,8 @@
user_id,
wx_open_id,
open_id,
phone
phone,
source
FROM
pa_user_visited
WHERE

Loading…
Cancel
Save