Commit cfae5224 authored by 万成波's avatar 万成波

移动端用户

parent 3abb82e1
package com.tangguo;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.domain.dto.PointsDetail;
import com.tangguo.common.domain.PointsDetailInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jms.core.JmsTemplate;
......@@ -23,7 +23,7 @@ public class ApplicationTest {
@Test
public void test() {
PointsDetail detail = new PointsDetail();
PointsDetailInfo detail = new PointsDetailInfo();
detail.setUserName("TanXiaoIng");
detail.setDetailPoints(10);
detail.setDetailName("外部系统");
......
......@@ -142,7 +142,6 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<!-- Java工具类库 -->
......
package com.tangguo.domain.dto;
package com.tangguo.common.domain;
import lombok.Data;
......@@ -11,7 +11,7 @@ import java.io.Serializable;
* @createTime 2025-08-29 17:23:29 星期五
*/
@Data
public class PointsDetail implements Serializable {
public class PointsDetailInfo implements Serializable {
private static final long serialVersionUID = 8057307839793769207L;
......
package com.tangguo.domain.vo;
package com.tangguo.common.domain;
import lombok.Data;
/**
* 企微门户用户VO
* 企微门户用户
*
* @author 谈笑
* @createTime 2025-08-29 16:13:32 星期五
*/
@Data
public class QwmhSysUserVO {
public class QwmhUserInfo {
/**
* 用户Id
......@@ -26,6 +26,11 @@ public class QwmhSysUserVO {
*/
private String nikeName;
/**
* 用户头像
*/
private String avatarUrl;
/**
* 部门名称
*/
......
package com.tangguo.framework.mauth;
package com.tangguo.common.mauth;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
......
package com.tangguo.framework.mauth;
package com.tangguo.common.mauth;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
......
......@@ -2,8 +2,8 @@ package com.tangguo.framework.config;
import com.tangguo.common.config.RuoYiConfig;
import com.tangguo.common.constant.Constants;
import com.tangguo.common.mauth.MobileProperties;
import com.tangguo.framework.interceptor.RepeatSubmitInterceptor;
import com.tangguo.framework.mauth.MobileProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......
package com.tangguo.framework.mauth;
import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.mauth.MobileTokenHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
......@@ -36,6 +38,8 @@ public class MobileAuthInterceptor implements HandlerInterceptor {
return true;
}
String username = MobileTokenHelper.getUsername();
log.info("=> 当前移动端请求用户:{}", username);
return true;
}
......
package com.tangguo.framework.mauth;
import com.tangguo.common.mauth.MobileProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
......
......@@ -2,8 +2,11 @@ package com.tangguo.framework.web.exception;
import com.tangguo.common.constant.HttpStatus;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.domain.R;
import com.tangguo.common.exception.DemoModeException;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.mauth.Mobile401Exception;
import com.tangguo.common.mauth.Mobile403Exception;
import com.tangguo.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -103,4 +106,23 @@ public class GlobalExceptionHandler {
public AjaxResult handleDemoModeException(DemoModeException e) {
return AjaxResult.error("演示模式,不允许操作");
}
/**
* 处理用户身份认证失败异常
*/
@ExceptionHandler(Mobile401Exception.class)
public R<Object> mobile401Exception(Mobile401Exception e) {
return R.fail(401, e.getMessage());
}
/**
* 处理用户权限校验失败异常
*/
@ExceptionHandler(Mobile403Exception.class)
public R<Object> mobile403Exception(Mobile403Exception e) {
return R.fail(403, e.getMessage());
}
}
package com.tangguo.controller.mobile;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.domain.bo.CodeLoginBO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tangguo.service.impl.BbsUserService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
/**
* 动态用户管理控制器
......@@ -17,6 +19,10 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/bbs/mobile/user")
public class BbsUserController {
@Resource
private BbsUserService bbsUserService;
/**
* 企微用户Code登录
*
......@@ -25,7 +31,8 @@ public class BbsUserController {
*/
@PostMapping("/code/login")
public AjaxResult codeLogin(@RequestBody CodeLoginBO bo) {
return AjaxResult.success();
Map<String, Object> tokenMap = this.bbsUserService.codeLogin(bo);
return AjaxResult.success(tokenMap);
}
......@@ -34,9 +41,11 @@ public class BbsUserController {
*
* @return 用户信息
*/
@PostMapping("/profile")
public AjaxResult profile() {
return AjaxResult.success();
@MobileAuth
@GetMapping("/profile")
public AjaxResult getUserProfile() {
Map<String, Object> profileMap = this.bbsUserService.getUserProfile();
return AjaxResult.success(profileMap);
}
}
package com.tangguo.mapper;
import com.tangguo.common.domain.QwmhUserInfo;
import org.apache.ibatis.annotations.Param;
/**
* 动态用户Mapper
*
* @author 谈笑
* @createTime 2025-09-02 15:30:05 星期二
*/
public interface BbsUserMapper {
QwmhUserInfo selectQwmhUserInfo(@Param("userName") String userName);
}
package com.tangguo.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.tangguo.common.domain.QwmhUserInfo;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.domain.bo.CodeLoginBO;
import com.tangguo.mapper.BbsUserMapper;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
/**
* 动态用户业务类
*
* @author 谈笑
* @createTime 2025-09-02 14:55:04 星期二
*/
@Slf4j
@Service
public class BbsUserService {
@Resource
private WxCpService wxCpService;
@Resource
private BbsUserMapper bbsUserMapper;
/**
* 企微用户Code登录
*
* @param bo 登录参数
* @return 登录结果
*/
public Map<String, Object> codeLogin(CodeLoginBO bo) {
String userName;
try {
log.info("=> 移动端用户登录:{}", bo);
WxCpOauth2UserInfo authUserInfo = this.wxCpService.getOauth2Service().getAuthUserInfo(bo.getCode());
userName = authUserInfo.getUserId();
} catch (WxErrorException e) {
log.error("=> 移动端用户登录失败,查询企微用户信息失败:", e);
throw new ServiceException("登录失败,查询企微用户信息失败。");
}
try {
QwmhUserInfo dbUser = this.bbsUserMapper.selectQwmhUserInfo(userName);
if (Objects.nonNull(dbUser)) {
Map<String, Object> payloads = new LinkedHashMap<>(1);
payloads.put("userName", dbUser.getUserName());
return MobileTokenHelper.createDetailToken(payloads);
} else {
throw new ServiceException("登录失败,未查询到当前登录用户数据。");
}
} catch (ServiceException e) {
log.error("=> 移动端用户登录失败:", e);
throw e;
} catch (Exception e) {
log.error("=> 移动端用户登录失败:", e);
throw new ServiceException("登录失败:" + e.getMessage());
}
}
/**
* 查询用户信息
*
* @return 用户信息
*/
public Map<String, Object> getUserProfile() {
String username = MobileTokenHelper.getUsername();
QwmhUserInfo dbUser = this.bbsUserMapper.selectQwmhUserInfo(username);
if (Objects.nonNull(dbUser)) {
return BeanUtil.beanToMap(dbUser, false, false);
} else {
throw new ServiceException("操作失败,未查询到当前用户信息。");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsUserMapper">
<select id="selectQwmhUserInfo" resultType="com.tangguo.common.domain.QwmhUserInfo">
SELECT * FROM qwmh_sys_user_view WHERE user_name = #{userName}
</select>
</mapper>
......@@ -7,11 +7,11 @@ import com.tangguo.common.annotation.RepeatSubmit;
import com.tangguo.common.core.controller.BaseController;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.domain.QwmhUserInfo;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.common.utils.poi.ExcelUtil;
import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.domain.vo.QwmhSysUserVO;
import com.tangguo.mapper.BbsUserPointsExchangeMapper;
import com.tangguo.service.IBbsPointsGoodsService;
import com.tangguo.service.IBbsUserPointsExchangeService;
......@@ -52,7 +52,7 @@ public class BbsUserPointsExchangeController extends BaseController {
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/select/users")
public AjaxResult selectUsers(String keyword) {
List<QwmhSysUserVO> users = this.userPointsExchangeMapper.selectPointsUsers(keyword);
List<QwmhUserInfo> users = this.userPointsExchangeMapper.selectPointsUsers(keyword);
return AjaxResult.success(users);
}
......
package com.tangguo.listener;
import com.tangguo.common.constant.ActiveMQConstant;
import com.tangguo.domain.dto.PointsDetail;
import com.tangguo.common.domain.PointsDetailInfo;
import com.tangguo.service.IBbsUserPointsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;
......@@ -30,7 +30,7 @@ public class UserPointsListener {
* @param detail 积分明细
*/
@JmsListener(destination = ActiveMQConstant.Points.INCR_USER_POINTS_QUEUE, containerFactory = ActiveMQConstant.QUEUE_CONTAINER_BEAN)
public void incrUserPointsListener(PointsDetail detail, Message message) {
public void incrUserPointsListener(PointsDetailInfo detail, Message message) {
try {
log.info("=> 开始处理增加用户积分消息:{}", detail);
this.userPointsService.incrUserPoints(detail);
......@@ -47,7 +47,7 @@ public class UserPointsListener {
* @param detail 积分明细
*/
@JmsListener(destination = ActiveMQConstant.Points.DECR_USER_POINTS_QUEUE, containerFactory = ActiveMQConstant.QUEUE_CONTAINER_BEAN)
public void decrUserPointsListener(PointsDetail detail, Message message) {
public void decrUserPointsListener(PointsDetailInfo detail, Message message) {
try {
log.info("=> 扣减用户积分消息:{}", detail);
this.userPointsService.decrUserPoints(detail);
......
package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.common.domain.QwmhUserInfo;
import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.domain.vo.QwmhSysUserVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -18,6 +18,6 @@ public interface BbsUserPointsExchangeMapper extends BaseMapper<BbsUserPointsExc
List<BbsUserPointsExchange> selectBbsUserPointsExchangeList(@Param("exchange") BbsUserPointsExchange exchange);
List<QwmhSysUserVO> selectPointsUsers(@Param("keyword") String keyword);
List<QwmhUserInfo> selectPointsUsers(@Param("keyword") String keyword);
}
package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.common.domain.QwmhUserInfo;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.vo.QwmhSysUserVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -18,7 +18,7 @@ public interface BbsUserPointsMapper extends BaseMapper<BbsUserPoints> {
List<BbsUserPoints> selectBbsUserPointsList(@Param("points") BbsUserPoints points);
QwmhSysUserVO selectQwmhUsers(@Param("userName") String userName);
QwmhUserInfo selectQwmhUser(@Param("userName") String userName);
BbsUserPoints selectUserPoints(@Param("userName") String userName);
......
package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.common.domain.PointsDetailInfo;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.dto.PointsDetail;
import java.util.List;
......@@ -53,7 +53,7 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> {
*
* @param detail 积分明细
*/
void incrUserPoints(PointsDetail detail);
void incrUserPoints(PointsDetailInfo detail);
/**
......@@ -61,6 +61,6 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> {
*
* @param detail 积分明细
*/
void decrUserPoints(PointsDetail detail);
void decrUserPoints(PointsDetailInfo detail);
}
package com.tangguo.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.domain.PointsDetailInfo;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsPointsGoods;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsExchange;
import com.tangguo.domain.dto.PointsDetail;
import com.tangguo.mapper.BbsUserPointsExchangeMapper;
import com.tangguo.service.IBbsPointsGoodsService;
import com.tangguo.service.IBbsUserPointsExchangeService;
......@@ -85,7 +85,7 @@ public class BbsUserPointsExchangeServiceImpl extends ServiceImpl<BbsUserPointsE
this.pointsGoodsService.incrGoodsSales(goodsId, 1);
// 扣减用户积分
PointsDetail detail = new PointsDetail();
PointsDetailInfo detail = new PointsDetailInfo();
detail.setUserName(userName);
detail.setDetailPoints(exchangePoints);
detail.setDetailName(dbGoods.getName());
......
package com.tangguo.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.domain.PointsDetailInfo;
import com.tangguo.common.domain.QwmhUserInfo;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.domain.BbsGrade;
import com.tangguo.domain.BbsUserPoints;
import com.tangguo.domain.BbsUserPointsDetail;
import com.tangguo.domain.dto.PointsDetail;
import com.tangguo.domain.vo.QwmhSysUserVO;
import com.tangguo.mapper.BbsUserPointsMapper;
import com.tangguo.service.IBbsGradeService;
import com.tangguo.service.IBbsUserPointsDetailService;
......@@ -66,7 +66,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
public BbsUserPoints getUserPoints(String userName) {
BbsUserPoints dbUserPoints = this.baseMapper.selectUserPoints(userName);
if (Objects.isNull(dbUserPoints)) {
QwmhSysUserVO qwmhSysUser = this.baseMapper.selectQwmhUsers(userName);
QwmhUserInfo qwmhSysUser = this.baseMapper.selectQwmhUser(userName);
if (Objects.isNull(qwmhSysUser)) {
throw new ServiceException("查询用户积分失败,未查询到当前用户数据。");
} else {
......@@ -96,7 +96,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Override
public void addUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
PointsDetail detail = new PointsDetail();
PointsDetailInfo detail = new PointsDetailInfo();
detail.setUserName(userName);
detail.setDetailPoints(points.getIncrOrDecrPoints());
detail.setDetailName("后台手动增加");
......@@ -114,7 +114,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Override
public void deleteUserPoints(BbsUserPoints points) {
String userName = points.getUserName();
PointsDetail detail = new PointsDetail();
PointsDetailInfo detail = new PointsDetailInfo();
detail.setUserName(userName);
detail.setDetailPoints(points.getIncrOrDecrPoints());
detail.setDetailName("后台手动扣减");
......@@ -129,7 +129,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* @param detail 积分明细
*/
@Override
public void incrUserPoints(PointsDetail detail) {
public void incrUserPoints(PointsDetailInfo detail) {
synchronized (detail.getUserName().intern()) {
this.pointsServiceImpl.privIncrUserPoints(detail);
}
......@@ -142,7 +142,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* @param detail 积分明细
*/
@Override
public void decrUserPoints(PointsDetail detail) {
public void decrUserPoints(PointsDetailInfo detail) {
synchronized (detail.getUserName().intern()) {
this.pointsServiceImpl.privDecrUserPoints(detail);
}
......@@ -155,7 +155,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* @param detail 积分明细
*/
@Transactional(rollbackFor = Exception.class)
public void privIncrUserPoints(PointsDetail detail) {
public void privIncrUserPoints(PointsDetailInfo detail) {
int points = detail.getDetailPoints();
if (points < 1) {
throw new ServiceException("增加用户积分失败,增加的积分分值不能小于0。");
......@@ -198,7 +198,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
* @param detail 积分明细
*/
@Transactional(rollbackFor = Exception.class)
public void privDecrUserPoints(PointsDetail detail) {
public void privDecrUserPoints(PointsDetailInfo detail) {
int points = detail.getDetailPoints();
if (points < 1) {
throw new ServiceException("扣减用户积分失败,扣减的积分分值不能小于0。");
......
......@@ -34,20 +34,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectPointsUsers" resultType="com.tangguo.domain.vo.QwmhSysUserVO">
<select id="selectPointsUsers" resultType="com.tangguo.common.domain.QwmhUserInfo">
SELECT
uv.nike_name,
uv.user_name,
uv.dept_name,
IFNULL(p.current_points, 0) AS current_points,
IFNULL(p.accumulated_points, 0) AS accumulated_points,
IFNULL(p.grade_name, ug.name) AS grade_name
uv.nike_name,
uv.user_name,
uv.dept_name,
IFNULL(p.current_points, 0) AS current_points,
IFNULL(p.accumulated_points, 0) AS accumulated_points,
IFNULL(p.grade_name, ug.name) AS grade_name
FROM
qwmh_sys_user_view uv
qwmh_sys_user_view uv
LEFT JOIN
bbs_user_points p ON p.user_name = uv.user_name
bbs_user_points p ON p.user_name = uv.user_name
CROSS JOIN (
SELECT (SELECT name FROM bbs_grade WHERE is_initial = 1 ORDER BY create_time DESC LIMIT 1) AS name
SELECT (SELECT name FROM bbs_grade WHERE is_initial = 1 ORDER BY create_time DESC LIMIT 1) AS name
) ug
<where>
<if test="keyword != null and keyword != ''">
......
......@@ -38,7 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectQwmhUsers" resultType="com.tangguo.domain.vo.QwmhSysUserVO">
<select id="selectQwmhUser" resultType="com.tangguo.common.domain.QwmhUserInfo">
SELECT * FROM qwmh_sys_user_view WHERE user_name = #{userName}
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment