|
|
|
|
@@ -1,170 +0,0 @@
|
|
|
|
|
package com.zf.foodpurchase.fdsafe.wxapp.common;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.zf.foodpurchase.common.config.RuoYiConfig;
|
|
|
|
|
import com.zf.foodpurchase.common.constant.Constants;
|
|
|
|
|
import com.zf.foodpurchase.common.constant.UserConstants;
|
|
|
|
|
import com.zf.foodpurchase.common.core.controller.BaseController;
|
|
|
|
|
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
|
|
|
|
import com.zf.foodpurchase.common.core.domain.entity.LoginWxUser;
|
|
|
|
|
import com.zf.foodpurchase.common.core.domain.entity.User;
|
|
|
|
|
import com.zf.foodpurchase.common.core.domain.entity.WxAppUserVO;
|
|
|
|
|
import com.zf.foodpurchase.common.core.domain.model.WxAppLoginBody;
|
|
|
|
|
import com.zf.foodpurchase.common.core.domain.model.WxAppLoginUser;
|
|
|
|
|
import com.zf.foodpurchase.common.exception.ServiceException;
|
|
|
|
|
import com.zf.foodpurchase.common.exception.user.UserPasswordNotMatchException;
|
|
|
|
|
import com.zf.foodpurchase.common.utils.MessageUtils;
|
|
|
|
|
import com.zf.foodpurchase.common.utils.SecurityUtils;
|
|
|
|
|
import com.zf.foodpurchase.common.utils.StringUtils;
|
|
|
|
|
import com.zf.foodpurchase.common.utils.file.FileUploadUtils;
|
|
|
|
|
import com.zf.foodpurchase.common.utils.file.MimeTypeUtils;
|
|
|
|
|
import com.zf.foodpurchase.fdsafe.entity.WxAppUser;
|
|
|
|
|
import com.zf.foodpurchase.fdsafe.service.IWxAppUserService;
|
|
|
|
|
import com.zf.foodpurchase.fdsafe.vo.WxAppUserViewVO;
|
|
|
|
|
import com.zf.foodpurchase.framework.manager.AsyncManager;
|
|
|
|
|
import com.zf.foodpurchase.framework.manager.factory.AsyncFactory;
|
|
|
|
|
import com.zf.foodpurchase.framework.web.service.WxAppLoginService;
|
|
|
|
|
import com.zf.foodpurchase.framework.web.service.WxAppTokenService;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author:lilj
|
|
|
|
|
* @date:2025/5/12
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/wxapp/userLogin")
|
|
|
|
|
public class WxAppUserLoginController extends BaseController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IWxAppUserService wxAppUserService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxAppTokenService wxAppTokenService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxAppLoginService wxAppLoginService;
|
|
|
|
|
private WxAppUserVO loginWxUser;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
|
|
public AjaxResult login(@RequestBody @Valid WxAppLoginBody wxAppLoginBody) {
|
|
|
|
|
String token = wxAppLoginService.login(wxAppLoginBody);
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
ajax.put(Constants.TOKEN, token);
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/getCurrentUser")
|
|
|
|
|
public AjaxResult getCurrentUser() {
|
|
|
|
|
WxAppLoginUser loginWxUser = getWxAppLoginUser();
|
|
|
|
|
WxAppUserVO user = loginWxUser.getUser();
|
|
|
|
|
AjaxResult response = success("查询成功");
|
|
|
|
|
response.put("user", user);
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 可修改项:用户密码,昵称,头像,性别
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/updateUser")
|
|
|
|
|
public AjaxResult updateUser(@RequestBody WxAppUserViewVO user) {
|
|
|
|
|
if (user == null || user.getId() == null) {
|
|
|
|
|
return error("用户id不能为空");
|
|
|
|
|
}
|
|
|
|
|
LambdaUpdateWrapper<WxAppUser> updateWrapper = new LambdaUpdateWrapper<WxAppUser>();
|
|
|
|
|
updateWrapper.eq(WxAppUser::getId, user.getId());
|
|
|
|
|
updateWrapper.set(WxAppUser::getNickname, user.getNickname());
|
|
|
|
|
updateWrapper.set(WxAppUser::getRealName, user.getRealName());
|
|
|
|
|
updateWrapper.set(WxAppUser::getAvatarUrl, user.getAvatarUrl());
|
|
|
|
|
updateWrapper.set(WxAppUser::getGender, user.getGender());
|
|
|
|
|
updateWrapper.set(WxAppUser::getUpdateTime, new Date());
|
|
|
|
|
boolean isUpdate = wxAppUserService.update(updateWrapper);
|
|
|
|
|
if (!isUpdate) {
|
|
|
|
|
return error("修改失败");
|
|
|
|
|
}
|
|
|
|
|
WxAppUserVO newUser = wxAppUserService.getUserVOById(user.getId());
|
|
|
|
|
WxAppLoginUser loginUser = getWxAppLoginUser();
|
|
|
|
|
// 设置部门名称
|
|
|
|
|
WxAppUserVO oldUser = loginUser.getUser();
|
|
|
|
|
newUser.setDeptName(oldUser.getDeptName());
|
|
|
|
|
loginUser.setUser(newUser);
|
|
|
|
|
|
|
|
|
|
wxAppTokenService.setLoginWxAppUser(loginUser);
|
|
|
|
|
return isUpdate ? success("修改成功") : error("修改失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改用户密码
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/updateUserPassword")
|
|
|
|
|
public AjaxResult updateUserPassword(@RequestBody WxAppUserViewVO user) {
|
|
|
|
|
if (user == null || user.getId() == null) {
|
|
|
|
|
return error("用户id不能为空");
|
|
|
|
|
}
|
|
|
|
|
pwdCheck(user.getNewPassword());
|
|
|
|
|
WxAppUser old = wxAppUserService.getById(user.getId());
|
|
|
|
|
if (old == null) {
|
|
|
|
|
return error("用户不存在");
|
|
|
|
|
}
|
|
|
|
|
// 校验密码是否正确
|
|
|
|
|
boolean isMatch = SecurityUtils.matchesPassword(user.getPassword(), old.getPassword());
|
|
|
|
|
if (!isMatch) {
|
|
|
|
|
throw new ServiceException("原密码有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WxAppUser updateUser = new WxAppUser();
|
|
|
|
|
updateUser.setId(user.getId());
|
|
|
|
|
updateUser.setPassword(SecurityUtils.encryptPassword(user.getNewPassword()));
|
|
|
|
|
boolean isUpdate = wxAppUserService.updateById(updateUser);
|
|
|
|
|
return isUpdate ? success("密码修改成功") : error("密码修改失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/logout")
|
|
|
|
|
public AjaxResult logout() {
|
|
|
|
|
WxAppLoginUser wxAppLoginUser = getWxAppLoginUser();
|
|
|
|
|
if (wxAppLoginUser != null) {
|
|
|
|
|
String token = wxAppLoginUser.getToken();
|
|
|
|
|
wxAppTokenService.delLoginWxAppUser(token);
|
|
|
|
|
}
|
|
|
|
|
return AjaxResult.success("退出登录成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void pwdCheck(String userPwd) {
|
|
|
|
|
if (StringUtils.isBlank(userPwd)) {
|
|
|
|
|
throw new ServiceException("新密码不能为空");
|
|
|
|
|
}
|
|
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
|
|
if (userPwd.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|
|
|| userPwd.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
|
|
throw new ServiceException("新密码位数应大于" + UserConstants.PASSWORD_MIN_LENGTH + ",小于" + UserConstants.PASSWORD_MAX_LENGTH + "位");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信头像上传
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping(value = "/avatar", produces = "application/json;charset=UTF-8")
|
|
|
|
|
public AjaxResult avatar(MultipartFile file) throws Exception {
|
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
|
WxAppLoginUser loginWxUser = getWxAppLoginUser();
|
|
|
|
|
// 上传文件路径
|
|
|
|
|
String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
|
// D:/ruoyi/wxprofile/avatar
|
|
|
|
|
String avatar = FileUploadUtils.upload(filePath, file, MimeTypeUtils.IMAGE_EXTENSION);
|
|
|
|
|
|
|
|
|
|
avatar = RuoYiConfig.getImagePrefix() + avatar;
|
|
|
|
|
return AjaxResult.success().put("avatarUrl", avatar);
|
|
|
|
|
}
|
|
|
|
|
return error("上传图片异常");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|