提交 ac11ef5f 编写于 作者: dong.an's avatar dong.an

账号微服务

上级 8fa6f17d
流水线 #9200 已失败 于阶段
in 0 second
...@@ -61,13 +61,41 @@ public class AccountController extends AccountBaseController { ...@@ -61,13 +61,41 @@ public class AccountController extends AccountBaseController {
return PicaResponse.toResponse(authCode); return PicaResponse.toResponse(authCode);
} }
@ApiOperation("登录") @ApiOperation("微信登录")
@PostMapping("/login/wechat")
public PicaResponse<String> wechatLogin(@RequestBody AccountReq req) {
if (StringUtils.isBlank(req.getUnionid())) {
return PicaResponse.toResponse(null, PicaResultCode.PARAM_IS_INVALID.code(), "缺少unionid");
}
Account account = accountService.getByUnionid(req.getUnionid()); //获取账号信息
if (account == null) {
return PicaResponse.toResponse(null, PicaResultCode.RESULE_DATA_NONE.code(), "该unionid未绑定云鹊医账号");
}
//已经绑定过云鹊医账号,登录成功,返回token
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
String newToken;
switch (deviceType) { //设备信息,pc没有微信登录
case "2": //android
case "3": //ios
//TODO 更新设备信息
newToken = StringUtils.EMPTY;
break;
default: //H5
newToken = this.generateH5Token(account.getId());
}
return PicaResponse.toResponse(newToken);
}
@ApiOperation("密码或验证码登录")
@PostMapping("/login") @PostMapping("/login")
public PicaResponse<String> login(@RequestBody AccountReq req) { public PicaResponse<String> login(@RequestBody AccountReq req) {
this.checkMobilePhone(req.getMobilePhone()); this.checkMobilePhone(req.getMobilePhone());
Account account = accountService.getByMobilePhone(req.getMobilePhone()); //获取账号信息 Account account = accountService.getByMobilePhone(req.getMobilePhone()); //获取账号信息
if (account == null) { if (account == null) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "该手机号尚未注册"); return PicaResponse.toResponse(null, PicaResultCode.RESULE_DATA_NONE.code(), "该手机号尚未注册");
} }
if (StringUtils.isBlank(req.getPassword())) { //验证码登录 if (StringUtils.isBlank(req.getPassword())) { //验证码登录
...@@ -75,7 +103,7 @@ public class AccountController extends AccountBaseController { ...@@ -75,7 +103,7 @@ public class AccountController extends AccountBaseController {
this.checkAuthCode(req); //校验验证码 this.checkAuthCode(req); //校验验证码
} else { //密码登录 } else { //密码登录
if (StringUtils.equals(req.getPassword(), account.getPassword())) { if (StringUtils.equals(req.getPassword(), account.getPassword())) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的密码"); return PicaResponse.toResponse(null, PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的密码");
} }
} }
...@@ -83,12 +111,17 @@ public class AccountController extends AccountBaseController { ...@@ -83,12 +111,17 @@ public class AccountController extends AccountBaseController {
Account update = new Account(); Account update = new Account();
update.setId(account.getId()); update.setId(account.getId());
update.setLastLoginTime(new Date()); update.setLastLoginTime(new Date());
if (StringUtils.isBlank(account.getUnionid()) && StringUtils.isNotBlank(req.getUnionid())) {
update.setUnionid(req.getUnionid()); //绑定微信unionid
update.setModifyId(account.getId());
update.setModifyTime(new Date());
}
accountService.updateAccountById(update); accountService.updateAccountById(update);
//登录成功,清除旧token,生成新token //登录成功,清除旧token,生成新token
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
String newToken; String newToken;
switch (deviceType) { //注册来源 switch (deviceType) { //设备信息
case "1": //pc case "1": //pc
//TODO //TODO
newToken = StringUtils.EMPTY; newToken = StringUtils.EMPTY;
......
...@@ -23,4 +23,7 @@ public interface AccountMapper { ...@@ -23,4 +23,7 @@ public interface AccountMapper {
//根据手机号获取账号 //根据手机号获取账号
Account getByMobilePhone(@Param("mobilePhone") String mobilePhone); Account getByMobilePhone(@Param("mobilePhone") String mobilePhone);
//根据微信unionid获取账号
Account getByUnionid(@Param("unionid") String unionid);
} }
...@@ -11,6 +11,9 @@ public interface AccountService { ...@@ -11,6 +11,9 @@ public interface AccountService {
//根据手机号获取账号 //根据手机号获取账号
Account getByMobilePhone(String mobilePhone); Account getByMobilePhone(String mobilePhone);
//根据微信unionid获取账号
Account getByUnionid(String unionid);
//创建账号 //创建账号
void createAccount(Account account); void createAccount(Account account);
......
...@@ -26,12 +26,18 @@ public class AccountServiceImpl implements AccountService { ...@@ -26,12 +26,18 @@ public class AccountServiceImpl implements AccountService {
return accountMapper.getByMobilePhone(encryptMobilePhone); return accountMapper.getByMobilePhone(encryptMobilePhone);
} }
//根据微信unionid获取账号
public Account getByUnionid(String unionid) {
return accountMapper.getByUnionid(unionid);
}
//创建账号 //创建账号
@Override @Override
@Transactional @Transactional
public void createAccount(Account account) { public void createAccount(Account account) {
Date currentTime = new Date(); Date currentTime = new Date();
account.setMobilePhone(EncryptCreateUtil.encrypt(account.getMobilePhone())); //手机号加密 account.setMobilePhone(EncryptCreateUtil.encrypt(account.getMobilePhone())); //手机号加密
account.setDeleteFlag(1);
account.setCreatId(0L); account.setCreatId(0L);
account.setModifyId(0L); account.setModifyId(0L);
account.setCreatTime(currentTime); account.setCreatTime(currentTime);
......
...@@ -292,4 +292,12 @@ ...@@ -292,4 +292,12 @@
limit 1 limit 1
</select> </select>
<select id="getByUnionid" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from p_doctor
where unionid = #{unionid} and delete_flag = 1
limit 1
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册