package com.ks.app.controller.client.api;
|
|
import com.ks.app.dto.user.LoginInfoDTO;
|
import com.ks.app.entity.user.UserInfo;
|
import com.ks.app.entity.user.UserLoginRecord;
|
import com.ks.app.entity.vip.UserVIPInfo;
|
import com.ks.app.exception.user.LoginException;
|
import com.ks.app.service.inter.user.UserAccountService;
|
import com.ks.app.service.inter.user.UserInfoService;
|
import com.ks.app.service.inter.vip.VIPService;
|
import com.ks.app.service.manager.VerifyCodeManager;
|
import com.ks.app.utils.ApiCodeConstant;
|
import com.ks.app.utils.annotation.UserLogin;
|
import com.ks.app.vo.AcceptData;
|
import com.ks.app.vo.user.UserInfoVO;
|
import com.ks.lib.common.exception.ParamsException;
|
import com.ks.push.exception.BPushDeviceTokenException;
|
import com.ks.push.pojo.DO.BPushDeviceToken;
|
import com.ks.push.pojo.DO.PushPlatform;
|
import com.ks.push.service.BDeviceTokenService;
|
import org.apache.dubbo.config.annotation.Reference;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.StringUtil;
|
import org.yeshi.utils.ThreadUtil;
|
|
import javax.annotation.Resource;
|
|
/**
|
* @author hxh
|
* @title: UserController
|
* @description: 用户接口
|
* @date 2021/11/16 17:37
|
*/
|
@Controller
|
@RequestMapping("api/v1/user")
|
public class UserController {
|
|
@Resource
|
private UserAccountService userAccountService;
|
|
@Resource
|
private UserInfoService userInfoService;
|
|
@Resource
|
private VIPService vipService;
|
|
@Resource
|
private VerifyCodeManager verifyCodeManager;
|
|
@Reference(version = "1.0", check = false)
|
private BDeviceTokenService bDeviceTokenService;
|
|
@ResponseBody
|
@RequestMapping("loginPhone")
|
public String loginPhone(AcceptData acceptData, String phone, String vcode, String token) {
|
LoginInfoDTO loginInfo = new LoginInfoDTO();
|
loginInfo.setLoginType(UserLoginRecord.TYPE_LOGIN_PHONE);
|
if (!StringUtil.isNullOrEmpty(phone)) {
|
if (StringUtil.isNullOrEmpty(vcode)) {
|
return JsonUtil.loadFalseResult("请上传验证码");
|
}
|
|
loginInfo.setPhone(phone);
|
loginInfo.setVcode(vcode);
|
|
} else if (!StringUtil.isNullOrEmpty(token)) {
|
loginInfo.setPhoneAuthInfo(token);
|
} else {
|
return JsonUtil.loadFalseResult("信息不完整");
|
}
|
loginInfo.setSystem(acceptData.getSystem());
|
try {
|
UserInfo userInfo = userAccountService.login(loginInfo);
|
ThreadUtil.run(new Runnable() {
|
@Override
|
public void run() {
|
try {
|
//登录成功
|
bDeviceTokenService.bindUid(acceptData.getSystem().name(), acceptData.getUtdId(), userInfo.getId() + "");
|
} catch (Exception e) {
|
|
}
|
}
|
});
|
|
return JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(userInfo));
|
} catch (LoginException e) {
|
return JsonUtil.loadFalseResult(e.getMessage());
|
}
|
|
}
|
|
@UserLogin(uid = "#uid")
|
@ResponseBody
|
@RequestMapping("logout")
|
public String logout(AcceptData acceptData, Long uid) {
|
try {
|
//解绑UID
|
bDeviceTokenService.unBindUid(acceptData.getSystem().name(), acceptData.getUtdId());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return JsonUtil.loadTrueResult("");
|
}
|
|
|
@UserLogin(uid = "#uid")
|
@ResponseBody
|
@RequestMapping("unRegister")
|
public String unRegister(AcceptData acceptData, String vcode, String phone) {
|
|
if (StringUtil.isNullOrEmpty(vcode)) {
|
return JsonUtil.loadFalseResult("验证码不能为空");
|
}
|
|
if (StringUtil.isNullOrEmpty(phone)) {
|
return JsonUtil.loadFalseResult("手机号不能为空");
|
}
|
|
if (!verifyCodeManager.isPhoneCodeRight(acceptData.getSystem(), phone, vcode)) {
|
return JsonUtil.loadFalseResult("验证码错误");
|
}
|
|
UserInfo user = userInfoService.selectValidByPhone(acceptData.getSystem(), phone);
|
if (user == null) {
|
return JsonUtil.loadFalseResult("不存在绑定该手机号的用户");
|
}
|
//注销
|
userAccountService.unRegister(user.getId());
|
return JsonUtil.loadTrueResult("");
|
}
|
|
@UserLogin(uid = "#uid")
|
@ResponseBody
|
@RequestMapping("getUserInfo")
|
public String getUserInfo(AcceptData acceptData, Long uid) {
|
|
UserInfo user = userInfoService.get(uid);
|
|
if (user == null) {
|
return JsonUtil.loadFalseResult("用户不存在");
|
}
|
if (user.getStatus() == UserInfo.STATUS_FORBIDDEN) {
|
return JsonUtil.loadFalseResult(ApiCodeConstant.CODE_FAIL_USER_FORBIDDEN, "账号被封禁");
|
}
|
|
if (user.getStatus() == UserInfo.STATUS_OWN_DELETE) {
|
return JsonUtil.loadFalseResult(ApiCodeConstant.CODE_FAIL_USER_DELETE, "用户已被删除");
|
}
|
|
UserInfoVO vo = new UserInfoVO();
|
vo.setId(user.getId() + "");
|
vo.setNickName(user.getNickName());
|
vo.setPortrait(user.getPortrait());
|
|
UserVIPInfo userVIPInfo = vipService.getVIPInfo(user.getId());
|
if (userVIPInfo != null) {
|
vo.setVipExpireTime(userVIPInfo.getExpireDate().getTime());
|
}
|
|
|
return JsonUtil.loadTrueResult(vo);
|
}
|
|
@ResponseBody
|
@RequestMapping("uploadPushRegId")
|
public String uploadPushRegId(AcceptData acceptData, Long uid, String regId) {
|
|
BPushDeviceToken deviceToken = new BPushDeviceToken();
|
deviceToken.setAppCode(acceptData.getSystem().name());
|
deviceToken.setDeviceId(acceptData.getUtdId());
|
deviceToken.setBuildModel(acceptData.getDeviceType());
|
deviceToken.setBuildVersion(acceptData.getOsVersion());
|
deviceToken.setToken(regId);
|
deviceToken.setType(PushPlatform.jpush);
|
if (uid != null) {
|
deviceToken.setUid(uid + "");
|
}
|
deviceToken.setVersionCode(acceptData.getVersion());
|
|
try {
|
bDeviceTokenService.save(deviceToken);
|
return JsonUtil.loadTrueResult("");
|
} catch (BPushDeviceTokenException e) {
|
return JsonUtil.loadTrueResult(e.getMessage());
|
} catch (ParamsException e) {
|
return JsonUtil.loadTrueResult(e.getMessage());
|
}
|
|
|
}
|
|
|
}
|