测试环境配置及带租房的登录功能

This commit is contained in:
2026-07-06 09:28:20 +08:00
parent 7c319a80a4
commit c43915105c
40 changed files with 1975 additions and 468 deletions

View File

@@ -14,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.xml.ws.soap.Addressing;
import java.util.List;
/**

View File

@@ -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("上传图片异常");
}
}

View File

@@ -63,12 +63,7 @@ public class SysLoginController {
*/
@PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody) {
AjaxResult ajax = AjaxResult.success();
// 生成令牌
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
loginBody.getUuid());
ajax.put(Constants.TOKEN, token);
return ajax;
return loginService.login(loginBody.getTenantId(), loginBody.getUsername(), loginBody.getPassword());
}
/**

View File

@@ -9,16 +9,16 @@ spring:
# url: jdbc:mysql://localhost:3306/zf_shopping_mall?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: root123456
url: jdbc:mysql://125.46.39.9:3306/zf_school_food?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://39.165.209.170:3307/zf_school_food?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: wXn*QFs_6aNvFq@qDr.gPYsfBL-XN_o2
password: zheng_wXn_fan*QFs_6aNvFq@keji_qDr.gPYsfBL
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
#enabled: false
url: jdbc:mysql://39.165.209.170:3307/zf_shopping_mall?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: zheng_wXn_fan*QFs_6aNvFq@keji_qDr.gPYsfBL
# 初始连接数
initialSize: 5
# 最小连接池数量