|
|
@@ -1,546 +0,0 @@
|
|
|
-package com.fs.app.controller;
|
|
|
-
|
|
|
-
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
-import com.fs.app.annotation.Login;
|
|
|
-import com.fs.app.param.FsUserEditPhoneParam;
|
|
|
-import com.fs.app.param.FsUserLoginByWeChatParam;
|
|
|
-import com.fs.app.param.FsUserLoginParam;
|
|
|
-import com.fs.app.param.LoginParam;
|
|
|
-import com.fs.app.utils.WxUtil;
|
|
|
-import com.fs.app.websocket.constant.NickNameConstant;
|
|
|
-import com.fs.common.annotation.RepeatSubmit;
|
|
|
-import com.fs.common.constant.Constants;
|
|
|
-import com.fs.common.core.domain.AjaxResult;
|
|
|
-import com.fs.common.core.domain.R;
|
|
|
-import com.fs.common.core.redis.RedisCache;
|
|
|
-import com.fs.common.exception.user.CaptchaException;
|
|
|
-import com.fs.common.exception.user.CaptchaExpireException;
|
|
|
-import com.fs.common.utils.MessageUtils;
|
|
|
-import com.fs.common.utils.StringUtils;
|
|
|
-import com.fs.common.utils.sign.Md5Utils;
|
|
|
-import com.fs.company.domain.CompanyUser;
|
|
|
-import com.fs.company.service.ICompanyPostService;
|
|
|
-import com.fs.company.service.ICompanyUserService;
|
|
|
-import com.fs.framework.manager.AsyncManager;
|
|
|
-import com.fs.framework.manager.factory.AsyncFactory;
|
|
|
-import com.fs.his.domain.FsUser;
|
|
|
-import com.fs.his.domain.FsUserAddress;
|
|
|
-import com.fs.his.mapper.FsUserMapper;
|
|
|
-import com.fs.his.service.IFsUserNewTaskService;
|
|
|
-import com.fs.his.service.IFsUserService;
|
|
|
-import com.fs.his.vo.FsUserRegisterParam;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.annotations.ApiParam;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
-import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
|
|
|
-import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
|
|
-import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
-import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
-import me.chanjar.weixin.mp.api.WxMpUserService;
|
|
|
-import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-
|
|
|
-import static com.fs.his.utils.PhoneUtil.decryptPhoneMk;
|
|
|
-import static com.fs.his.utils.PhoneUtil.encryptPhone;
|
|
|
-
|
|
|
-
|
|
|
-@Api("用户接口")
|
|
|
-@RestController
|
|
|
-@AllArgsConstructor
|
|
|
-@RequestMapping(value="/app/user")
|
|
|
-public class UserController extends AppBaseController {
|
|
|
- private final ICompanyPostService postService;
|
|
|
- private final ICompanyUserService companyUserService;
|
|
|
- private final RedisCache redisCache;
|
|
|
- private final WxMpService wxMpService;
|
|
|
- private final IFsUserService userService;
|
|
|
-
|
|
|
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private FsUserMapper userMapper;
|
|
|
- @Autowired
|
|
|
- private IFsUserNewTaskService userNewTaskService;
|
|
|
-
|
|
|
- private static final String APP_ID = "wxd70f99287830cb51";
|
|
|
- private static final String APP_SECRET = "51129ad15e25fb63b4e6c025df56a541";
|
|
|
-
|
|
|
-
|
|
|
- @ApiOperation("课程短链公众号登录")
|
|
|
- @PostMapping("/loginByMp")
|
|
|
- public R loginByMp( @RequestBody LoginParam param) {
|
|
|
- if (StringUtils.isBlank(param.getCode())) {
|
|
|
- return R.error("code不存在");
|
|
|
- }
|
|
|
- try{
|
|
|
- WxOAuth2AccessToken wxMpOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(param.getCode());
|
|
|
- WxOAuth2UserInfo wxMpUser = wxMpService.getOAuth2Service().getUserInfo(wxMpOAuth2AccessToken, null);
|
|
|
- WxMpUserService wxMpUserService = wxMpService.getUserService();
|
|
|
- WxMpUser userInfo = wxMpUserService.userInfo(wxMpUser.getOpenid());
|
|
|
- if (!userInfo.getSubscribe()){
|
|
|
- return R.error("请关注公众号进行登录");
|
|
|
- }
|
|
|
- FsUser user=userService.selectFsUserByUnionid(param.getUnionId());
|
|
|
- if(user!=null){
|
|
|
- FsUser userMap=new FsUser();
|
|
|
- userMap.setUserId(user.getUserId());
|
|
|
- userMap.setNickName(wxMpUser.getNickname());
|
|
|
- userMap.setAvatar(wxMpUser.getHeadImgUrl());
|
|
|
- userMap.setMpOpenId(wxMpUser.getOpenid());
|
|
|
- userMap.setUpdateTime(new DateTime());
|
|
|
- userService.updateFsUser(userMap);
|
|
|
- }
|
|
|
- else{
|
|
|
- //写入
|
|
|
- user=new FsUser();
|
|
|
- user.setNickName(wxMpUser.getNickname());
|
|
|
- user.setAvatar(wxMpUser.getHeadImgUrl());
|
|
|
- user.setStatus(1);
|
|
|
- user.setSex(wxMpUser.getSex());
|
|
|
- user.setMpOpenId(wxMpUser.getOpenid());
|
|
|
- user.setUnionId(wxMpUser.getUnionId());
|
|
|
- user.setCreateTime(new Date());
|
|
|
- userService.insertFsUser(user);
|
|
|
- }
|
|
|
- String token = jwtUtils.generateToken(user.getUserId());
|
|
|
- redisCache.setCacheObject("token:"+user.getUserId(),token,604800, TimeUnit.SECONDS);
|
|
|
- Map<String,Object> map=new HashMap<>();
|
|
|
- map.put("token",token);
|
|
|
- map.put("user",user);
|
|
|
- return R.ok(map);
|
|
|
- }
|
|
|
- catch (WxErrorException e){
|
|
|
- if(e.getError().getErrorCode()==40163){
|
|
|
- return R.error(40163,e.getError().getErrorMsg());
|
|
|
- }
|
|
|
- else{
|
|
|
- return R.error("授权失败,"+e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取用户信息
|
|
|
- */
|
|
|
- @Login
|
|
|
- @ApiOperation("获取用户信息")
|
|
|
- @GetMapping("/getUserInfo")
|
|
|
- public R getUserInfo(){
|
|
|
- try {
|
|
|
- CompanyUser companyUser=companyUserService.selectCompanyUserById(Long.parseLong(getUserId()));
|
|
|
- List<String> postList=postService.selectPostNameListByUserId(Long.parseLong(getUserId()));
|
|
|
- if(companyUser==null){
|
|
|
- return R.error(40001,"用户不存在");
|
|
|
- }
|
|
|
- if(companyUser.getStatus().equals("1")){
|
|
|
- return R.error(40002,"用户已停用");
|
|
|
- }
|
|
|
- return R.ok().put("user",companyUser).put("post",postList);
|
|
|
- } catch (Exception e){
|
|
|
-
|
|
|
- return R.error("操作异常");
|
|
|
- }
|
|
|
- }
|
|
|
- @Login
|
|
|
- @ApiOperation("获取用户信息ByUserId")
|
|
|
- @GetMapping("/getUserInfoByUserId")
|
|
|
- public R getUserInfoByUserId(
|
|
|
- @ApiParam(required = true, name = "userId", value = "用户ID") @RequestParam(value = "userId", required = false) Long userId,
|
|
|
- HttpServletRequest request){
|
|
|
- try {
|
|
|
- CompanyUser user=companyUserService.selectCompanyUserById(userId);
|
|
|
- List<String> postList=postService.selectPostNameListByUserId(userId);
|
|
|
- if(user==null){
|
|
|
- return R.error(40001,"用户不存在");
|
|
|
- }
|
|
|
- if(user.getStatus().equals("1")){
|
|
|
- return R.error(40002,"用户已停用");
|
|
|
- }
|
|
|
- return R.ok().put("user",user).put("post",postList);
|
|
|
- } catch (Exception e){
|
|
|
-
|
|
|
- return R.error("操作异常");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-// @Login
|
|
|
- @ApiOperation("获取用户名称")
|
|
|
- @GetMapping("/getUserNickName")
|
|
|
- public R getUserInfoByUserId(@RequestParam(value = "userId") Long userId){
|
|
|
- try {
|
|
|
- FsUser user=userMapper.selectFsUserByUserId(userId);
|
|
|
- if(user==null){
|
|
|
- return R.error(40001,"用户不存在");
|
|
|
- }
|
|
|
- return R.ok().put("nickName", user.getNickName());
|
|
|
- } catch (Exception e){
|
|
|
- return R.error("操作异常");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("检测是否登录")
|
|
|
- @GetMapping("/checkLogin")
|
|
|
- public R checkLogin(HttpServletRequest request){
|
|
|
- if(StringUtils.isEmpty(getUserId())){
|
|
|
- //未登录
|
|
|
- return R.error("未登录");
|
|
|
- }
|
|
|
- else{
|
|
|
- //登录
|
|
|
- String token = jwtUtils.generateToken(Long.parseLong(getUserId()));
|
|
|
- Map<String,Object> map=new HashMap<>();
|
|
|
- map.put("token",token);
|
|
|
- return R.ok("认证成功").put("userId",getUserId()).put("token",token);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("注册app用户")
|
|
|
- @PostMapping("/register")
|
|
|
- @RepeatSubmit
|
|
|
- public R registerDoctor(@Validated @RequestBody FsUserRegisterParam param){
|
|
|
- FsUser fsUser = findUserByPhone(param.getPhone());
|
|
|
-
|
|
|
-// if (fsUser == null) {
|
|
|
-// // 尝试使用加密后的手机号查询
|
|
|
-// fsUser = userService.selectFsUserByPhone(encryptPhone(param.getPhone()));
|
|
|
-// }
|
|
|
-
|
|
|
- if (fsUser != null && org.apache.commons.lang3.StringUtils.isNotEmpty(fsUser.getPassword())) {
|
|
|
- return R.error("此账号已经注册");
|
|
|
- }
|
|
|
-
|
|
|
- FsUser user = new FsUser();
|
|
|
- if (fsUser != null) {
|
|
|
- // 更新已有用户的密码
|
|
|
- user.setUserId(fsUser.getUserId());
|
|
|
- user.setPassword(Md5Utils.hash(param.getPassword()));
|
|
|
- user.setUpdateTime(new DateTime());
|
|
|
- userService.updateFsUser(user);
|
|
|
- return R.ok("注册成功");
|
|
|
- } else {
|
|
|
- // 创建新用户
|
|
|
- user.setPhone(param.getPhone());
|
|
|
- user.setNickName("app用户" + param.getPhone().substring(param.getPhone().length() - 4));
|
|
|
- user.setStatus(1);
|
|
|
- user.setAvatar("https://cos.his.cdwjyyh.com/fs/20240926/420728ee06e54575ba82665dedb4756b.png");
|
|
|
- user.setPassword(Md5Utils.hash(param.getPassword()));
|
|
|
- user.setCreateTime(new Date());
|
|
|
-
|
|
|
- if (userService.insertFsUser(user) > 0) {
|
|
|
- return R.ok("注册成功");
|
|
|
- } else {
|
|
|
- return R.error("注册失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * app登录
|
|
|
- * */
|
|
|
- @ApiOperation("登录")
|
|
|
- @PostMapping("/loginByApp")
|
|
|
- @Transactional
|
|
|
- public R login(@Validated @RequestBody FsUserLoginParam param) {
|
|
|
- int loginType = param.getLoginType();
|
|
|
- switch (loginType) {
|
|
|
- case 1:
|
|
|
- return handleLoginType1(param); // 手机密码登录
|
|
|
- case 3:
|
|
|
- return handleLoginType3(param);
|
|
|
- default:
|
|
|
- return R.error("请选择正确的登陆类型!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("获取用户收货地址")
|
|
|
- @GetMapping(value = "/getUserAddr/{userId}")
|
|
|
- public AjaxResult getUserAddr(@PathVariable("userId") Long userId)
|
|
|
- {
|
|
|
- List<FsUserAddress> fsUserAddresses = userService.selectFsUserAddressByUserId(userId);
|
|
|
- for (FsUserAddress fsUserAddress : fsUserAddresses) {
|
|
|
- if (fsUserAddress.getPhone()!=null&&fsUserAddress.getPhone()!=""){
|
|
|
- if (fsUserAddress.getPhone().length()>11){
|
|
|
- fsUserAddress.setPhone(decryptPhoneMk(fsUserAddress.getPhone()));
|
|
|
- }else {
|
|
|
- fsUserAddress.setPhone(fsUserAddress.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return AjaxResult.success(fsUserAddresses);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("微信登录")
|
|
|
- @PostMapping("/loginByWeChat")
|
|
|
- @Transactional
|
|
|
- public R loginByWeChat(@Validated @RequestBody FsUserLoginByWeChatParam param) {
|
|
|
- try {
|
|
|
- if (org.apache.commons.lang3.StringUtils.isBlank(param.getCode())) {
|
|
|
- return R.error("code不存在");
|
|
|
- }
|
|
|
- logger.info("zyp app微信登录,param:{}", param);
|
|
|
- Map result = WxUtil.getAccessToken(param.getCode(),APP_ID,APP_SECRET);
|
|
|
- String accessToken = result.get("access_token").toString();
|
|
|
- String unionid = result.get("unionid").toString();
|
|
|
-
|
|
|
- String openid = result.get("openid").toString();
|
|
|
-
|
|
|
- Map userInfo = WxUtil.getUserInfo(accessToken, openid);
|
|
|
-
|
|
|
- String nickname = userInfo.get("nickname").toString();
|
|
|
- Integer sex = (Integer) userInfo.get("sex");
|
|
|
- String avatar = userInfo.get("headimgurl").toString();
|
|
|
- FsUser user = userService.selectFsUserByUnionid(unionid);
|
|
|
-
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- if (user == null) {
|
|
|
- user = new FsUser();
|
|
|
- user.setLoginDevice(param.getLoginDevice()!=null ? param.getLoginDevice() : null);
|
|
|
- user.setSource(param.getSource()!=null ? param.getSource() : null);
|
|
|
- user.setNickName(nickname);
|
|
|
- user.setAvatar(avatar);
|
|
|
- if (sex!=0){
|
|
|
- user.setSex(sex);
|
|
|
- }
|
|
|
- user.setUnionId(unionid);
|
|
|
- user.setCreateTime(new Date());
|
|
|
- user.setStatus(1);
|
|
|
- if (org.apache.commons.lang3.StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
- user.setJpushId(param.getJpushId());
|
|
|
- }
|
|
|
- userService.insertFsUser(user);
|
|
|
- map.put("isNew", true);
|
|
|
- map.put("unionid",unionid);
|
|
|
-// if (org.apache.commons.lang3.StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
-// try {
|
|
|
-// //发送注册优惠券
|
|
|
-// fsUserCouponService.sendRegisterCoupon(user);
|
|
|
-// } catch (Exception e) {
|
|
|
-// logger.error("发送注册优惠券失败:{}",e.getMessage());
|
|
|
-// }
|
|
|
-// }
|
|
|
- return R.ok(map);
|
|
|
- } else {
|
|
|
- if (org.apache.commons.lang3.StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
- updateExistingUserJpushId(user, param.getJpushId());
|
|
|
-// try {
|
|
|
-// //发送注册优惠券
|
|
|
-// fsUserCouponService.sendRegisterCoupon(user);
|
|
|
-// } catch (Exception e) {
|
|
|
-// logger.error("发送注册优惠券失败:{}",e.getMessage());
|
|
|
-// }
|
|
|
- }
|
|
|
- if (org.apache.commons.lang3.StringUtils.isEmpty(user.getPhone())) {
|
|
|
- map.put("isNew", true);
|
|
|
- map.put("unionid",user.getUnionId());
|
|
|
- return R.ok(map);
|
|
|
- }
|
|
|
- }
|
|
|
- if (user.getStatus()==0&& org.apache.commons.lang3.StringUtils.isNotEmpty(param.getSource())&&!param.getSource().equals("iOS")){
|
|
|
- return R.error("登录失败,账户被禁用");
|
|
|
- }
|
|
|
- int isFirstLogin = userNewTaskService.performTaskOne(user.getUserId());
|
|
|
- String token = jwtUtils.generateToken(user.getUserId());
|
|
|
- redisCache.setCacheObject("userToken:" + user.getUserId(), token, 604800, TimeUnit.SECONDS);
|
|
|
- map.put("token", token);
|
|
|
- map.put("user", user);
|
|
|
- map.put("isFirst",isFirstLogin);
|
|
|
- return R.ok(map);
|
|
|
- }catch (Exception e){
|
|
|
- logger.error("zyp 登录失败:{}", e.getMessage());
|
|
|
- return R.error("登录失败");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("绑定手机号")
|
|
|
- @PostMapping("/setIPhoneNumber")
|
|
|
- public R setIPhoneNumber(@Validated @RequestBody FsUserEditPhoneParam param) {
|
|
|
- FsUser userMap = findUserByPhone(param.getPhone());
|
|
|
- if (userMap != null) {
|
|
|
- if (org.apache.commons.lang3.StringUtils.isNotEmpty(userMap.getAppleKey()) && !param.getAppleKey().equals(userMap.getAppleKey())) {
|
|
|
- return R.error("该手机号已绑定其他账号");
|
|
|
- }
|
|
|
- if (param.getSimExist() == 0 && !Md5Utils.hash(param.getPassword()).equals(userMap.getPassword())) {
|
|
|
- return R.error("密码不正确");
|
|
|
- }
|
|
|
- } else {
|
|
|
- userMap = createNewAppleUser(param, param.getPhone());
|
|
|
- }
|
|
|
-
|
|
|
- userMap.setLoginDevice(param.getLoginDevice());
|
|
|
- userMap.setSource(param.getSource());
|
|
|
- if (userMap.getNickName().equals("匿名用户**")) {
|
|
|
- userMap.setNickName("苹果用户" + param.getPhone().substring(param.getPhone().length() - 4));
|
|
|
- }
|
|
|
- userMap.setAppleKey(param.getAppleKey());
|
|
|
- if (userService.updateFsUser(userMap)>0){
|
|
|
- return generateTokenAndReturn(userMap);
|
|
|
- }
|
|
|
- return R.error("绑定手机号失败");
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("绑定手机号")
|
|
|
- @PostMapping("/setPhone")
|
|
|
- public R setPhone(@Validated @RequestBody FsUserEditPhoneParam param) {
|
|
|
- FsUser user = userService.selectFsUserByUnionid(param.getUnionId());
|
|
|
- if (user == null) {
|
|
|
- return R.error("用户数据不存在");
|
|
|
- }
|
|
|
- FsUser userMap = findUserByPhone(param.getPhone());
|
|
|
- if (userMap != null) {
|
|
|
- return R.error("该手机号已绑定其他账号");
|
|
|
- }
|
|
|
- user.setPhone(param.getPhone());
|
|
|
- user.setLoginDevice(param.getLoginDevice() != null ? param.getLoginDevice() : null );
|
|
|
- user.setSource(param.getSource()!= null ? param.getSource() : null);
|
|
|
- userMap = new FsUser();
|
|
|
- userMap.setLoginDevice(param.getLoginDevice());
|
|
|
- userMap.setSource(param.getSource());
|
|
|
- if (user.getNickName().equals("匿名用户**")) {
|
|
|
- userMap.setNickName("匿名用户" + param.getPhone().substring(param.getPhone().length() - 4));
|
|
|
- }
|
|
|
- userMap.setUserId(user.getUserId());
|
|
|
- userMap.setPhone(param.getPhone());
|
|
|
- if (userService.updateFsUser(userMap)>0){
|
|
|
- return generateTokenAndReturn(user);
|
|
|
- }
|
|
|
- return R.error("绑定手机号失败");
|
|
|
- }
|
|
|
-
|
|
|
- private R handleLoginType1(FsUserLoginParam param) {
|
|
|
-
|
|
|
- if (org.apache.commons.lang3.StringUtils.isEmpty(param.getPhone()) || org.apache.commons.lang3.StringUtils.isEmpty(param.getPassword())) {
|
|
|
- return R.error("账号或密码不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- FsUser user = findUserByPhone(param.getPhone());
|
|
|
-
|
|
|
- // 校验用户是否存在及账号状态
|
|
|
- if (user == null) {
|
|
|
- return R.error("账号不存在,请先注册账号");
|
|
|
- } else if (user.getStatus() == 0) {
|
|
|
- return R.error("账号已停用");
|
|
|
- } else if (org.apache.commons.lang3.StringUtils.isEmpty(user.getPassword())) {
|
|
|
- return R.error("账号不存在,请先注册账号");
|
|
|
- }
|
|
|
-
|
|
|
- if (!Md5Utils.hash(param.getPassword()).equals(user.getPassword())) {
|
|
|
- return R.error("密码不正确");
|
|
|
- }
|
|
|
-
|
|
|
- return generateTokenAndReturn(user);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private R handleLoginType3(FsUserLoginParam param) {
|
|
|
- if (org.apache.commons.lang3.StringUtils.isEmpty(param.getPhone())) {
|
|
|
- return R.error("获取手机号失败");
|
|
|
- }
|
|
|
- // 根据手机号查询用户
|
|
|
- FsUser user = findUserByPhone(param.getPhone());
|
|
|
- if (user == null) {
|
|
|
- createNewUser(param);
|
|
|
- return R.ok().put("isNew",true).put("phone",encryptPhone(param.getPhone()));
|
|
|
- } else {
|
|
|
- if (user.getUnionId()==null){
|
|
|
- if (user.getPhone().length()<=11){
|
|
|
- FsUser fsUser = new FsUser();
|
|
|
- fsUser.setUserId(user.getUserId());
|
|
|
- fsUser.setPhone(param.getPhone());
|
|
|
- userMapper.updateFsUser(fsUser);
|
|
|
- logger.info("zyp \n【手机加密】:{}",encryptPhone(param.getPhone()));
|
|
|
- }
|
|
|
- return R.ok().put("isNew",true).put("phone",encryptPhone(param.getPhone()));
|
|
|
- }
|
|
|
- /*if (org.apache.commons.lang3.StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
- updateExistingUserJpushId(user, param.getJpushId());
|
|
|
- }*/
|
|
|
- }
|
|
|
- return generateTokenAndReturn(user);
|
|
|
- }
|
|
|
-
|
|
|
- private FsUser createNewAppleUser(FsUserEditPhoneParam param, String phoneNumber) {
|
|
|
- FsUser newUser = new FsUser();
|
|
|
- newUser.setLoginDevice(param.getLoginDevice()!=null ? param.getLoginDevice() : null);
|
|
|
- newUser.setSource(param.getSource()!=null ? param.getSource() : null);
|
|
|
- newUser.setAppleKey(param.getAppleKey());
|
|
|
- newUser.setPhone(param.getPhone());
|
|
|
- newUser.setPassword(Md5Utils.hash(param.getPassword()));
|
|
|
- newUser.setNickName("苹果用户" + param.getPhone().substring(param.getPhone().length() - 4));
|
|
|
- newUser.setCreateTime(new Date());
|
|
|
- newUser.setStatus(1);
|
|
|
- newUser.setAvatar("https://cos.his.cdwjyyh.com/fs/20240926/420728ee06e54575ba82665dedb4756b.png");
|
|
|
- if (org.apache.commons.lang3.StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
- newUser.setJpushId(param.getJpushId());
|
|
|
- }
|
|
|
- userService.insertFsUser(newUser);
|
|
|
- return newUser;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void updateExistingUserJpushId(FsUser user, String jpushId) {
|
|
|
- FsUser userMap = new FsUser();
|
|
|
- userMap.setUserId(user.getUserId());
|
|
|
- userMap.setJpushId(jpushId);
|
|
|
- userService.updateFsUser(userMap);
|
|
|
- }
|
|
|
-
|
|
|
- private R generateTokenAndReturn(FsUser user) {
|
|
|
- String token = jwtUtils.generateToken(user.getUserId());
|
|
|
- redisCache.setCacheObject("userToken:" + user.getUserId(), token, 604800, TimeUnit.SECONDS);
|
|
|
- int isFirstLogin = userNewTaskService.performTaskOne(user.getUserId());
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("token", token);
|
|
|
- map.put("user", user);
|
|
|
- map.put("isFirst",isFirstLogin);
|
|
|
- return R.ok(map);
|
|
|
- }
|
|
|
-
|
|
|
- private FsUser findUserByPhone(String phone) {
|
|
|
- // 先根据加密手机号查询用户
|
|
|
- String jiami = (encryptPhone(phone));
|
|
|
- FsUser user = userMapper.selectFsUserByPhoneLimitOne(jiami);
|
|
|
-
|
|
|
- // 如果没有找到用户,再根据手机号查询
|
|
|
- if (user == null) {
|
|
|
- user = userMapper.selectFsUserByPhoneLimitOne(phone);
|
|
|
-
|
|
|
- }
|
|
|
- return user;
|
|
|
- }
|
|
|
-
|
|
|
- private FsUser createNewUser(FsUserLoginParam param) {
|
|
|
- FsUser newUser = new FsUser();
|
|
|
- newUser.setLoginDevice(param.getLoginDevice() != null ? param.getLoginDevice() : null);
|
|
|
- newUser.setSource(param.getSource() != null ? param.getSource() : null );
|
|
|
- newUser.setNickName(NickNameConstant.getNickName());
|
|
|
- newUser.setPhone(param.getPhone());
|
|
|
- newUser.setCreateTime(new Date());
|
|
|
- newUser.setStatus(1);
|
|
|
- newUser.setAvatar("https://cos.his.cdwjyyh.com/fs/20240926/420728ee06e54575ba82665dedb4756b.png");
|
|
|
- /*if (org.apache.commons.lang3.StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
- newUser.setJpushId(param.getJpushId());
|
|
|
- }*/
|
|
|
- userService.insertFsUser(newUser);
|
|
|
- return newUser;
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
-}
|