Commit 2f3f5e92 authored by 万成波's avatar 万成波

优化代码

parent 63de3ec6
......@@ -6,6 +6,7 @@ import com.tangguo.common.core.domain.entity.SysMenu;
import com.tangguo.common.core.domain.entity.SysUser;
import com.tangguo.common.core.domain.model.LoginBody;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.common.core.domain.model.WxcpCodeLogin;
import com.tangguo.framework.web.service.SysLoginService;
import com.tangguo.framework.web.service.SysPermissionService;
import com.tangguo.system.service.ISysMenuService;
......@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
......@@ -80,4 +82,32 @@ public class SysLoginController {
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
return AjaxResult.success(menuService.buildMenus(menus));
}
/**
* 企微用户Code登录
*
* @param bo 登录参数
* @return 登录结果
*/
@PostMapping("/bbs/mobile/user/code/login")
public AjaxResult codeLogin(@RequestBody WxcpCodeLogin bo) {
Map<String, Object> tokenMap = this.loginService.codeLogin(bo);
return AjaxResult.success(tokenMap);
}
/**
* 查询用户信息
*
* @return 用户信息
*/
@GetMapping("/bbs/mobile/user/profile")
public AjaxResult getUserProfile() {
SysUser sysUser = SecurityUtils.getLoginUser().getUser();
return AjaxResult.success(sysUser);
}
}
......@@ -6,7 +6,7 @@
<el-input v-model="queryParams.content" placeholder="请输入"></el-input>
</el-form-item>
<el-form-item label="姓名">
<el-input v-model="queryParams.nikeName" placeholder="请输入"></el-input>
<el-input v-model="queryParams.nickName" placeholder="请输入"></el-input>
</el-form-item>
<el-form-item label="账号">
<el-input v-model="queryParams.userName" placeholder="请输入"></el-input>
......@@ -24,7 +24,7 @@
<el-table-column label="评论内容" prop="content" align="center"></el-table-column>
<el-table-column label="所属动态" prop="momentContent" align="center"></el-table-column>
<el-table-column label="账号" prop="userName" align="center"></el-table-column>
<el-table-column label="姓名" prop="nikeName" align="center"></el-table-column>
<el-table-column label="姓名" prop="nickName" align="center"></el-table-column>
<el-table-column label="创建时间" prop="createTime" align="center"></el-table-column>
<el-table-column label="操作" align="center">
<template #default="{ row }">
......@@ -110,4 +110,4 @@ export default {
overflow: auto;
}
}
</style>
\ No newline at end of file
</style>
......@@ -3,7 +3,7 @@
<div class="dynamic-item">
<div class="user-info-box">
<img class="avatar" src="@/assets/images/default-avatar.png"></img>
<div class="user-name">{{ form.nikeName }}</div>
<div class="user-name">{{ form.nickName }}</div>
<img class="more-icon" src="@/assets/images/more-icon.png"></img>
</div>
<div class="topics-box" v-if="form.topicNames && form.topicNames.length > 0">
......@@ -54,7 +54,7 @@
<div class="comment-display-box" v-if="form.comments && form.comments.length > 0">
<div class="comment-item" v-for="(item, index) in form.comments">
<div class="user-info">
<div class="username">{{ item.nikeName }}:</div>
<div class="username">{{ item.nickName }}:</div>
<div class="datetime">2025-07-01 04:21:21</div>
</div>
<div class="content">{{ item.content }}</div>
......@@ -333,4 +333,4 @@ export default {
}
}
}
</style>
\ No newline at end of file
</style>
......@@ -23,7 +23,7 @@
<el-table-column label="动态内容" prop="content" align="center"></el-table-column>
<el-table-column label="话题" align="center" prop="topicNames" width="240"></el-table-column>
<el-table-column label="帐号" prop="userName" align="center" width="140"></el-table-column>
<el-table-column label="姓名" prop="nikeName" align="center" width="120"></el-table-column>
<el-table-column label="姓名" prop="nickName" align="center" width="120"></el-table-column>
<el-table-column label="点赞数" prop="likeCount" align="center" width="100"></el-table-column>
<el-table-column label="评论数" prop="commentCount" align="center" width="100"></el-table-column>
<el-table-column label="创建时间" prop="createTime" align="center" width="160"></el-table-column>
......@@ -76,7 +76,7 @@ export default {
this.total = res.total
})
},
// 新增
handleDetail(row) {
this.$refs.detailDialogRef.openModal(row)
......@@ -121,4 +121,4 @@ export default {
overflow: auto;
}
}
</style>
\ No newline at end of file
</style>
......@@ -30,7 +30,7 @@
</el-row>
<el-table :data="tableList">
<el-table-column label="序号" width="55" type="index" align="center"></el-table-column>
<el-table-column label="兑换人" prop="nikeName" align="center"></el-table-column>
<el-table-column label="兑换人" prop="nickName" align="center"></el-table-column>
<el-table-column label="兑换商品" align="center" prop="goodsName"></el-table-column>
<el-table-column label="兑换积分" prop="goodsExchangePoints" align="center"></el-table-column>
<el-table-column label="兑换时间" prop="createTime" align="center"></el-table-column>
......@@ -145,4 +145,4 @@ export default {
overflow: auto;
}
}
</style>
\ No newline at end of file
</style>
......@@ -4,7 +4,7 @@
<el-form-item label="兑换人">
<el-select placeholder="请选择" style="width: 100%;" v-model="form.userName" @change="handleUserChange">
<el-option v-for="(item, index) in userList" :key="index" :value="item.userName"
:label="item.nikeName"></el-option>
:label="item.nickName"></el-option>
</el-select>
</el-form-item>
<el-form-item label="会员等级">
......@@ -60,7 +60,7 @@ export default {
if (row && row.userName) {
res.data.forEach((item) => {
if (item.userName == row.userName) {
this.form.nikeName = item.nikeName;
this.form.nickName = item.nickName;
this.form.gradeName = item.gradeName
}
})
......@@ -71,7 +71,7 @@ export default {
handleUserChange(val) {
this.userList.forEach((item) => {
if (item.userName == val) {
this.form.nikeName = item.nikeName;
this.form.nickName = item.nickName;
this.form.gradeName = item.gradeName
this.form.currentPoints = item.currentPoints
}
......@@ -85,8 +85,8 @@ export default {
})
},
handleConfirm() {
let { nikeName, userName, userGradeName, goodsCode } = this.form
let data = { nikeName, userName, userGradeName, goodsCode }
let { nickName, userName, userGradeName, goodsCode } = this.form
let data = { nickName, userName, userGradeName, goodsCode }
this.$refs.formRef.validate((valid) => {
if (valid) {
exchange(data).then(res => {
......@@ -115,4 +115,4 @@ export default {
padding: 0 20px !important;
}
}
</style>
\ No newline at end of file
</style>
......@@ -3,7 +3,7 @@
<div class="page-container">
<el-form :model="queryParams" :inline="true" label-width="80px">
<el-form-item label="姓名">
<el-input v-model="queryParams.nikeName" placeholder="请输入" style="width: 220px;"></el-input>
<el-input v-model="queryParams.nickName" placeholder="请输入" style="width: 220px;"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleQuery">查询</el-button>
......@@ -17,7 +17,7 @@
</el-row>
<el-table :data="tableList">
<el-table-column label="序号" width="55" type="index" align="center"></el-table-column>
<el-table-column label="姓名" prop="nikeName" align="center"></el-table-column>
<el-table-column label="姓名" prop="nickName" align="center"></el-table-column>
<el-table-column label="帐号" prop="userName" align="center"></el-table-column>
<el-table-column label="部门" prop="deptName" align="center"></el-table-column>
<el-table-column label="总积分" prop="accumulatedPoints" align="center"></el-table-column>
......@@ -180,4 +180,4 @@ export default {
overflow: auto;
}
}
</style>
\ No newline at end of file
</style>
......@@ -12,7 +12,7 @@
<view class="comment-display-box" v-else>
<view class="comment-item" v-for="(item,index) in list">
<view class="user-info">
<view class="username">{{item.nikeName}}</view>
<view class="username">{{item.nickName}}</view>
<view class="datetime">{{item.createTime}}</view>
</view>
<view class="content">
......@@ -28,7 +28,7 @@
<view v-if="form.isSelf==1&&activeIndex==1" @click="handleDelete(item)">删除</view>
</view>
</view>
</view>
</view>
......@@ -221,7 +221,7 @@
display: flex;
align-items: center;
justify-content: space-between;
}
.add-text {
......@@ -231,4 +231,4 @@
}
}
}
</style>
\ No newline at end of file
</style>
......@@ -3,7 +3,7 @@
<view class="dynamic-item" @click="toDynamicDetailPage">
<view class="user-info-box">
<image class="avatar" src="/static/images/default-avatar.png"></image>
<view class="user-name">{{form.nikeName}}</view>
<view class="user-name">{{form.nickName}}</view>
<image class="more-icon" src="/static/images/more-icon.png"></image>
</view>
<view class="topics-box" v-if="form.topicNames && form.topicNames.length >0">
......@@ -67,7 +67,7 @@
<view class="results-item right-item"></view>
</view>
</view>
<view class="results-sum" @click.stop="toPKDetailPage(0)">
<view>{{form.voteCount}}人参与</view>
<image src="/static/images/detail-icon.png" class="icon"></image>
......@@ -79,7 +79,7 @@
<view class="comment-display-box" v-if="form.comments&& form.comments.length>0">
<view class="comment-item" v-for="(item,index) in form.comments">
<view class="user-info">
<view class="username">{{item.nikeName}}:</view>
<view class="username">{{item.nickName}}:</view>
<view class="datetime">2025-07-01 04:21:21</view>
</view>
<view class="content" v-if="!item.replyNikeName" @click.stop="handleReplayComment(item)">{{item.content}}</view>
......@@ -99,7 +99,7 @@
<script>
import {
dynamicLikeUnlike,
dynamicVote
} from '@/api/api.js'
import PublishComment from './PublishComment.vue';
......@@ -145,7 +145,7 @@
console.log(item)
this.$refs.publishCommentRef.openModal(item)
},
// 投票
handleVote(item) {
let data = {
......@@ -190,4 +190,4 @@
<style lang="scss">
@import '@/static/styles/index.scss';
</style>
\ No newline at end of file
</style>
......@@ -34,7 +34,7 @@
if(item){
// 不为空为回复
this.parentId = item.id;
this.placeholder = '回复:'+item.nikeName
this.placeholder = '回复:'+item.nickName
}
},
// 关闭评论区
......@@ -66,4 +66,4 @@
<style lang="scss">
@import '@/static/styles/index.scss';
</style>
\ No newline at end of file
</style>
......@@ -6,7 +6,7 @@
<image v-if="!userInfo.avatarUrl" src="/static/images/default-avatar.png" class="avatar"></image>
<image v-else :src="userInfo.avatarUrl" class="avatar"></image>
<view class="name-class">
<view class="name">{{userInfo.nikeName}}</view>
<view class="name">{{userInfo.nickName}}</view>
<view class="class-name">{{userInfo.deptName}}</view>
</view>
<image src="/static/images/mine/detail-icon-white.png" class="more"></image>
......@@ -172,4 +172,4 @@
margin-top: 40rpx;
height: calc(100vh - 570rpx);
}
</style>
\ No newline at end of file
</style>
......@@ -9,11 +9,11 @@
<scroll-view class="scroll-view-pk" v-if="list.length>0">
<view class="list-item" v-for="(item,index) in list">
<image src="/static/images/default-avatar.png" class="avatar"></image>
<view class="name">{{item.nikeName}}</view>
<view class="name">{{item.nickName}}</view>
<view class="datetime">{{item.createTime}}</view>
</view>
</scroll-view>
</view>
</template>
......@@ -127,4 +127,4 @@
}
}
}
</style>
\ No newline at end of file
</style>
package com.tangguo.domain.bo;
package com.tangguo.common.core.domain.model;
import lombok.Data;
......@@ -9,7 +9,7 @@ import lombok.Data;
* @createTime 2025-09-02 14:53:19 星期二
*/
@Data
public class CodeLoginBO {
public class WxcpCodeLogin {
/**
* 企微Code
......
package com.tangguo.common.domain;
import lombok.Data;
/**
* 企微门户用户
*
* @author 谈笑
* @createTime 2025-08-29 16:13:32 星期五
*/
@Data
public class QwmhUserInfo {
/**
* 用户Id
*/
private String userId;
/**
* 用户名
*/
private String userName;
/**
* 用户姓名
*/
private String nikeName;
/**
* 用户头像
*/
private String avatarUrl;
/**
* 部门名称
*/
private String deptName;
/**
* 用户等级
*/
private String gradeName;
/**
* 当前积分
*/
private Integer currentPoints;
/**
* 累计积分
*/
private Integer accumulatedPoints;
}
package com.tangguo.common.mauth;
import lombok.Getter;
/**
* 移动端用户身份认证失败异常类
*
* @author 谈笑
* @createTime 2025-09-02 14:42:17 星期二
*/
@Getter
public class Mobile401Exception extends RuntimeException {
private static final long serialVersionUID = -4189845692674690824L;
/**
* 状态码
*/
private final int code = 401;
/**
* 异常消息
*/
private final String message;
public Mobile401Exception(String message) {
this.message = message;
}
public Mobile401Exception(String message, Throwable cause) {
super(message, cause);
this.message = message;
}
}
package com.tangguo.common.mauth;
import lombok.Getter;
/**
* 移动端用户鉴权失败异常类
*
* @author 谈笑
* @createTime 2025-09-02 14:42:17 星期二
*/
@Getter
public class Mobile403Exception extends RuntimeException {
private static final long serialVersionUID = 4027402152375922779L;
/**
* 状态码
*/
private final int code = 403;
/**
* 异常消息
*/
private final String message;
public Mobile403Exception(String message) {
this.message = message;
}
public Mobile403Exception(String message, Throwable cause) {
super(message, cause);
this.message = message;
}
}
package com.tangguo.common.mauth;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 移动端用户身份认证注解
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MobileAuth {
}
package com.tangguo.common.mauth;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.time.Duration;
/**
* 移动端用户Token配置参数
*
* @author 谈笑
* @createTime 2025-09-02 14:42:17 星期二
*/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "mobile.auth")
public class MobileProperties {
/**
* 生成时Token参数名
*/
private String resTokenName;
/**
* 请求时Token参数名
*/
private String reqTokenName;
/**
* Token签发人
*/
private String issuer = "MobileAuth";
/**
* Token签名算法
*/
private String algorithmId = "HS512";
/**
* Token签名密钥
*/
private String signKey = "SignKey2025@.";
/**
* Token有效时间
*/
private Duration effectiveTime = Duration.ofDays(7);
/**
* 拦截器拦截路径
*/
private String[] pathPatterns = {"/mobile/**"};
}
package com.tangguo.common.mauth;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTValidator;
import cn.hutool.jwt.signers.JWTSigner;
import cn.hutool.jwt.signers.JWTSignerUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.Instant;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
/**
* 移动端用户Token处理
*
* @author 谈笑
* @createTime 2025-09-02 14:42:17 星期二
*/
@Component
public class MobileTokenHelper {
private static MobileProperties properties;
@Resource
public void setProperties(MobileProperties properties) {
MobileTokenHelper.properties = properties;
}
/**
* 计算Token过期时间
*
* @return Token过期时间
*/
private static Date getTokenExpiredTime() {
return Date.from(Instant.now().plus(properties.getEffectiveTime()));
}
/**
* 获取Token签名器
*
* @return Token签名器
*/
private static JWTSigner getTokenSigner() {
return JWTSignerUtil.createSigner(
properties.getAlgorithmId(), properties.getSignKey().getBytes()
);
}
/**
* 构建JWT实体 (只填充了关键参数,并未签名。)
*
* @return JWT实体
*/
private static JWT buildJWT() {
JWT jwtToken = JWT.create();
jwtToken.setIssuer(properties.getIssuer());
jwtToken.setIssuedAt(new Date());
jwtToken.setExpiresAt(getTokenExpiredTime());
jwtToken.setSigner(getTokenSigner());
return jwtToken;
}
/**
* 创建Token
*
* @param payloads 荷载参数
* @return Token字符串
*/
public static String createToken(Map<String, Object> payloads) {
JWT jwtToken = buildJWT();
if (MapUtil.isNotEmpty(payloads)) {
payloads.forEach(jwtToken::setPayload);
}
return jwtToken.sign();
}
/**
* 创建Token,并返回Token明细信息。
*
* @param payloads 荷载参数
* @return Token字符串
*/
public static Map<String, Object> createDetailToken(Map<String, Object> payloads) {
String token = createToken(payloads);
Map<String, Object> detailTokenMap = new LinkedHashMap<>(2);
detailTokenMap.put(properties.getResTokenName(), token);
detailTokenMap.put("expiredTime", DateUtil.formatDateTime(getTokenExpiredTime()));
return detailTokenMap;
}
/**
* 获取当前用户Token
*
* @return 用户Token
*/
public static String getCurrentToken() {
try {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) attributes;
if (Objects.isNull(requestAttributes)) {
return null;
}
HttpServletRequest request = requestAttributes.getRequest();
String tokenValue = request.getHeader(properties.getReqTokenName());
if (tokenValue.startsWith("Bearer")) {
tokenValue = tokenValue.replace("Bearer ", "");
}
return tokenValue;
} catch (Exception e) {
return null;
}
}
/**
* 验证Token
*
* @param token Token字符串
* @return 验证结果
*/
public static boolean verifyToken(String token) {
if (StrUtil.isBlank(token)) {
return false;
}
try {
// 验证Token的签名和时效
return JWT.of(token).setSigner(getTokenSigner()).validate(0L);
} catch (Exception e) {
return false;
}
}
/**
* 校验Token
*
* @param token Token字符串
*/
public static JWT verifyParseToken(String token) {
if (StrUtil.isBlank(token)) {
throw new Mobile401Exception("身份认证失败,未获取到用户认证信息。");
}
try {
// 验证Token的签名和时效
JWTValidator.of(token).validateAlgorithm(getTokenSigner()).validateDate();
return JWT.of(token);
} catch (Exception e) {
throw new Mobile401Exception("身份认证失败,当前用户认证信息已失效或已过期。");
}
}
/**
* 获取当前用户Token荷载信息
*
* @return Token荷载信息
*/
public static JSONObject getTokenPayloads() {
return verifyParseToken(getCurrentToken()).getPayloads();
}
/**
* 获取当前用户名
*
* @return 用户名
*/
public static String getUserName() {
try {
String username = getTokenPayloads().getStr("userName");
if (StrUtil.isNotBlank(username)) {
return username;
} else {
throw new Mobile401Exception("身份认证失败,未获取到当前用户身份信息。");
}
} catch (Mobile401Exception e) {
throw e;
} catch (Exception e) {
throw new Mobile401Exception("获取当前用户身份信息获取失败。");
}
}
/**
* 获取当前用户姓名
*
* @return 用户名
*/
public static String getNikeName() {
try {
String nikeName = getTokenPayloads().getStr("nikeName");
if (StrUtil.isNotBlank(nikeName)) {
return nikeName;
} else {
throw new Mobile401Exception("身份认证失败,未获取到当前用户身份信息。");
}
} catch (Mobile401Exception e) {
throw e;
} catch (Exception e) {
throw new Mobile401Exception("获取当前用户身份信息获取失败。");
}
}
}
......@@ -2,7 +2,6 @@ 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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
......@@ -28,9 +27,6 @@ public class ResourcesConfig implements WebMvcConfigurer {
@Autowired
private RepeatSubmitInterceptor repeatSubmitInterceptor;
@Resource
private MobileProperties mobileProperties;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
......@@ -50,8 +46,7 @@ public class ResourcesConfig implements WebMvcConfigurer {
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**")
.excludePathPatterns(this.mobileProperties.getPathPatterns());
registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
}
/**
......
package com.tangguo.framework.config;
import com.tangguo.common.mauth.MobileProperties;
import com.tangguo.framework.config.properties.PermitAllUrlProperties;
import com.tangguo.framework.security.filter.JwtAuthenticationTokenFilter;
import com.tangguo.framework.security.handle.AuthenticationEntryPointImpl;
......@@ -66,10 +65,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private PermitAllUrlProperties permitAllUrl;
@Resource
private MobileProperties mobileProperties;
/**
* 解决 无法直接注入 AuthenticationManager
*
......@@ -115,14 +110,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 过滤请求
.authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/register", "/captchaImage").permitAll()
.antMatchers("/login", "/bbs/mobile/user/code/login", "/register", "/captchaImage").permitAll()
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
// 移动端接口
.antMatchers(this.mobileProperties.getPathPatterns()).permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated()
.and()
......
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;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.Objects;
/**
* 移动端用户认证拦截器
*
* @author 谈笑
* @createTime 2025-09-02 14:42:17 星期二
*/
@Slf4j
@Component
public class MobileAuthInterceptor implements HandlerInterceptor {
/**
* 请求被处理之前调用
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if (!(handler instanceof HandlerMethod)) {
return true;
}
// 获取处理器方法上的标识注解
Method method = ((HandlerMethod) handler).getMethod();
MobileAuth mobileAuth = method.getAnnotation(MobileAuth.class);
if (Objects.isNull(mobileAuth)) {
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;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 移动端Web配置
*
* @author 谈笑
* @createTime 2025-09-02 14:42:17 星期二
*/
@RequiredArgsConstructor
@Configuration
public class MobileWebMvcConfig implements WebMvcConfigurer {
private final MobileProperties mobileProperties;
private final MobileAuthInterceptor mobileAuthInterceptor;
/**
* 自定义拦截规则
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(this.mobileAuthInterceptor).addPathPatterns(this.mobileProperties.getPathPatterns());
}
}
......@@ -5,8 +5,6 @@ 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;
......@@ -107,22 +105,4 @@ public class GlobalExceptionHandler {
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());
}
}
......@@ -5,6 +5,7 @@ import com.tangguo.common.constant.Constants;
import com.tangguo.common.constant.UserConstants;
import com.tangguo.common.core.domain.entity.SysUser;
import com.tangguo.common.core.domain.model.LoginUser;
import com.tangguo.common.core.domain.model.WxcpCodeLogin;
import com.tangguo.common.core.redis.RedisCache;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.exception.user.*;
......@@ -17,20 +18,29 @@ import com.tangguo.framework.manager.factory.AsyncFactory;
import com.tangguo.framework.security.context.AuthenticationContextHolder;
import com.tangguo.system.service.ISysConfigService;
import com.tangguo.system.service.ISysUserService;
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.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
/**
* 登录校验方法
*
* @author ruoyi
*/
@Slf4j
@Component
public class SysLoginService {
@Autowired
......@@ -48,6 +58,13 @@ public class SysLoginService {
@Autowired
private ISysConfigService configService;
@Autowired
private UserDetailsServiceImpl userDetailsServiceImpl;
@Autowired
private WxCpService wxCpService;
/**
* 登录验证
*
......@@ -156,4 +173,35 @@ public class SysLoginService {
sysUser.setLoginDate(DateUtils.getNowDate());
userService.updateUserProfile(sysUser);
}
/**
* 企微用户Code登录
*
* @param bo 登录参数
* @return 登录结果
*/
public Map<String, Object> codeLogin(WxcpCodeLogin 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 {
UserDetails userDetails = this.userDetailsServiceImpl.loadUserByUsername2(userName);
String token = this.tokenService.createToken((LoginUser) userDetails);
Map<String, Object> resultMap = new LinkedHashMap<>(2);
resultMap.put("token", token);
return resultMap;
} catch (Exception e) {
log.error("=> 移动端用户登录失败,生成用户Token失败:", e);
throw new ServiceException("登录失败:" + e.getMessage());
}
}
}
......@@ -51,6 +51,23 @@ public class UserDetailsServiceImpl implements UserDetailsService {
return createLoginUser(user);
}
public UserDetails loadUserByUsername2(String username) throws UsernameNotFoundException {
SysUser user = userService.selectUserByUserName(username);
if (StringUtils.isNull(user)) {
log.info("登录用户:{} 不存在.", username);
throw new ServiceException("登录用户:" + username + " 不存在");
} else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
log.info("登录用户:{} 已被删除.", username);
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
log.info("登录用户:{} 已被停用.", username);
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
}
return createLoginUser(user);
}
public UserDetails createLoginUser(SysUser user) {
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
}
......
......@@ -2,9 +2,8 @@ package com.tangguo.controller.mobile;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.common.utils.PageUtils;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.common.utils.ValidateOperations;
import com.tangguo.domain.bo.*;
import com.tangguo.domain.vo.BbsCommentDetailVO;
......@@ -50,7 +49,6 @@ public class MBbsMomentController {
*
* @return 动态
*/
@MobileAuth
@GetMapping("/moments")
public TableDataInfo getMoments(QueryMomentBO bo) {
PageUtils.clearPage();
......@@ -64,7 +62,6 @@ public class MBbsMomentController {
*
* @return 动态
*/
@MobileAuth
@GetMapping("/{id}")
public AjaxResult getMomentDetail(@PathVariable Long id) {
BbsMomentListVO dbMoment = this.momentService.getMomentDetail(id);
......@@ -78,7 +75,6 @@ public class MBbsMomentController {
* @param bo 动态
* @return 创建结果
*/
@MobileAuth
@PostMapping("/create")
public AjaxResult createMoment(@RequestBody CreateMomentBO bo) {
this.momentService.userCreateMoment(bo);
......@@ -92,7 +88,6 @@ public class MBbsMomentController {
* @param momentId 动态Id
* @return 删除结果
*/
@MobileAuth
@DeleteMapping("/delete/{momentId}")
public AjaxResult deleteMoment(@PathVariable Long momentId) {
this.momentService.userDeleteMoment(momentId);
......@@ -106,7 +101,6 @@ public class MBbsMomentController {
* @param bo 动态
* @return 点赞结果
*/
@MobileAuth
@PostMapping("/like")
public AjaxResult likeMoment(@RequestBody LikeMomentBO bo) {
ValidateOperations.generalValidate(bo);
......@@ -123,7 +117,6 @@ public class MBbsMomentController {
* @param bo 动态
* @return 投票结果
*/
@MobileAuth
@PostMapping("/vote")
public AjaxResult voteMoment(@RequestBody VoteMomentBO bo) {
ValidateOperations.generalValidate(bo);
......@@ -140,7 +133,6 @@ public class MBbsMomentController {
* @param momentId 动态Id
* @return 投票结果
*/
@MobileAuth
@GetMapping("/vote/count")
public AjaxResult getMomentVoteCount(@RequestParam Long momentId) {
List<BbsVoteOptionVO> dbOptionCount = this.momentVoteOptionService.getVoteOptionCount(momentId);
......@@ -158,7 +150,6 @@ public class MBbsMomentController {
* @param momentId 动态Id
* @return 投票记录
*/
@MobileAuth
@GetMapping("/votes")
public TableDataInfo getMomentVotes(@RequestParam Long momentId, @RequestParam String optionCode) {
PageUtils.startPage();
......@@ -172,12 +163,11 @@ public class MBbsMomentController {
*
* @return 动态
*/
@MobileAuth
@GetMapping("/comments")
public TableDataInfo getMomentComments(@RequestParam Long momentId) {
String userName = MobileTokenHelper.getUserName();
String username = SecurityUtils.getUsername();
PageUtils.clearPage();
List<BbsCommentDetailVO> dbComments = this.momentCommentService.getMomentComments(momentId, userName);
List<BbsCommentDetailVO> dbComments = this.momentCommentService.getMomentComments(momentId, username);
return TableDataInfo.getDataTable(dbComments);
}
......@@ -188,7 +178,6 @@ public class MBbsMomentController {
* @param bo 动态
* @return 投票结果
*/
@MobileAuth
@PostMapping("/comment")
public AjaxResult commentMoment(@RequestBody CommentMomentBO bo) {
ValidateOperations.generalValidate(bo);
......@@ -205,7 +194,6 @@ public class MBbsMomentController {
* @param commentId 评论Id
* @return 删除结果
*/
@MobileAuth
@DeleteMapping("/comment/delete/{commentId}")
public AjaxResult deleteComment(@PathVariable Long commentId) {
this.momentService.userDeleteComment(commentId);
......@@ -219,7 +207,6 @@ public class MBbsMomentController {
* @param bo 评论
* @return 精选结果
*/
@MobileAuth
@PostMapping("/comment/featured")
public AjaxResult featuredComment(@RequestBody FeaturedCommentBO bo) {
ValidateOperations.generalValidate(bo);
......
......@@ -2,7 +2,6 @@ package com.tangguo.controller.mobile;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.utils.PageUtils;
import com.tangguo.common.utils.ValidateOperations;
import com.tangguo.domain.bo.CreateTopicBO;
......@@ -39,7 +38,6 @@ public class MBbsTopicController {
* @param name 话题名称
* @return 话题
*/
@MobileAuth
@GetMapping("/select")
public TableDataInfo getSelectTopics(String name) {
PageUtils.startPage();
......@@ -54,7 +52,6 @@ public class MBbsTopicController {
* @param bo 话题
* @return 创建结果
*/
@MobileAuth
@PostMapping("/create")
public AjaxResult createTopic(@RequestBody CreateTopicBO bo) {
ValidateOperations.generalValidate(bo);
......@@ -68,7 +65,6 @@ public class MBbsTopicController {
*
* @return 话题
*/
@MobileAuth
@GetMapping("/ranking")
public AjaxResult getRankingTopic() {
List<BbsTopicListVO> dbTopics = this.topicService.getRankingTopic();
......@@ -82,7 +78,6 @@ public class MBbsTopicController {
* @param bo 查询参数
* @return 话题明细
*/
@MobileAuth
@GetMapping("/moments")
public TableDataInfo getTopicMoments(QueryMomentBO bo) {
PageUtils.clearPage();
......
......@@ -2,19 +2,17 @@ package com.tangguo.controller.mobile;
import com.tangguo.common.core.domain.AjaxResult;
import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.common.utils.PageUtils;
import com.tangguo.domain.bo.CodeLoginBO;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsUserMomentCountVO;
import com.tangguo.service.IBbsMomentService;
import com.tangguo.service.impl.BbsUserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 移动端用户控制器
......@@ -26,48 +24,18 @@ import java.util.Map;
@RequestMapping("/bbs/mobile/user")
public class MBbsUserController {
@Resource
private BbsUserService bbsUserService;
@Resource
private IBbsMomentService momentService;
/**
* 企微用户Code登录
*
* @param bo 登录参数
* @return 登录结果
*/
@PostMapping("/code/login")
public AjaxResult codeLogin(@RequestBody CodeLoginBO bo) {
Map<String, Object> tokenMap = this.bbsUserService.codeLogin(bo);
return AjaxResult.success(tokenMap);
}
/**
* 查询用户信息
*
* @return 用户信息
*/
@MobileAuth
@GetMapping("/profile")
public AjaxResult getUserProfile() {
Map<String, Object> profileMap = this.bbsUserService.getUserProfile();
return AjaxResult.success(profileMap);
}
/**
* 查询用户动态统计
*
* @return 动态统计
*/
@MobileAuth
@GetMapping("/moment/count")
public AjaxResult getUserMomentCount() {
String username = MobileTokenHelper.getUserName();
String username = SecurityUtils.getUsername();
BbsUserMomentCountVO momentCount = this.momentService.getUserMomentCount(username);
return AjaxResult.success(momentCount);
}
......@@ -78,10 +46,9 @@ public class MBbsUserController {
*
* @return 动态
*/
@MobileAuth
@GetMapping("/moments")
public TableDataInfo getUserMoments(String content) {
String username = MobileTokenHelper.getUserName();
String username = SecurityUtils.getUsername();
PageUtils.clearPage();
List<BbsMomentListVO> moments = this.momentService.getUserMoments(username, content);
return TableDataInfo.getDataTable(moments);
......
......@@ -121,7 +121,7 @@ public class BbsMoment extends BaseEntity {
/** 用户姓名 */
@TableField(exist = false)
private String nikeName;
private String nickName;
/** 用户部门 */
@TableField(exist = false)
......
......@@ -43,7 +43,7 @@ public class BbsMomentComment extends BaseEntity {
/** 评论用户姓名 */
@Excel(name = "评论用户姓名")
@ApiModelProperty("评论用户姓名")
private String nikeName;
private String nickName;
/** 评论用户名 */
@Excel(name = "评论用户名")
......
......@@ -22,7 +22,7 @@ public class BbsCommentDetailVO {
private Date createTime;
/** 评论用户姓名 */
private String nikeName;
private String nickName;
/** 评论用户名 */
private String userName;
......
......@@ -22,7 +22,7 @@ public class BbsCommentVO {
private Date createTime;
/** 评论用户姓名 */
private String nikeName;
private String nickName;
/** 评论用户名 */
private String userName;
......
......@@ -25,7 +25,7 @@ public class BbsMomentDetailVO {
private Long id;
/** 发布人用户姓名 */
private String nikeName;
private String nickName;
/** 发布人用户名 */
private String userName;
......
......@@ -25,7 +25,7 @@ public class BbsMomentListVO {
private Long id;
/** 发布人用户姓名 */
private String nikeName;
private String nickName;
/** 发布人用户名 */
private String userName;
......
......@@ -19,6 +19,6 @@ public class BbsVoteVO {
private Date createTime;
/** 用户姓名 */
private String nikeName;
private String nickName;
}
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);
}
......@@ -5,9 +5,9 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.dfa.FoundWord;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.core.domain.entity.SysUser;
import com.tangguo.common.enums.*;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.common.utils.SensitiveWordUtils;
import com.tangguo.domain.BbsMoment;
......@@ -131,7 +131,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
*/
@Override
public List<BbsMomentListVO> getMoments(QueryMomentBO bo) {
String userName = MobileTokenHelper.getUserName();
String userName = SecurityUtils.getUsername();
List<BbsMomentListVO> dbMoments = this.baseMapper.selectMoments(userName, bo);
this.fillMoment(dbMoments, userName);
return dbMoments;
......@@ -146,7 +146,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
*/
@Override
public BbsMomentListVO getMomentDetail(Long momentId) {
String userName = MobileTokenHelper.getUserName();
String userName = SecurityUtils.getUsername();
BbsMomentListVO dbMoment = this.baseMapper.selectMomentDetail(momentId, userName);
this.fillMoment(Collections.singletonList(dbMoment), userName);
dbMoment.setComments(null);
......@@ -163,7 +163,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
@Override
public void userCreateMoment(CreateMomentBO bo) {
// 添加动态
String username = MobileTokenHelper.getUserName();
String username = SecurityUtils.getUsername();
BbsMoment newMoment = this.buildMoment(bo);
newMoment.setUserName(username);
this.save(newMoment);
......@@ -190,7 +190,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
@Transactional(rollbackFor = Exception.class)
@Override
public void userDeleteMoment(Long momentId) {
String username = MobileTokenHelper.getUserName();
String username = SecurityUtils.getUsername();
BbsMoment dbMoment = this.getById(momentId);
if (Objects.isNull(dbMoment)) {
throw new ServiceException("删除失败,未查询到当前动态数据。");
......@@ -215,7 +215,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("点赞失败,未查询到当前动态数据。");
}
String userName = MobileTokenHelper.getUserName();
String userName = SecurityUtils.getUsername();
long likeStatus = this.likeService.getUserMomentLikeCount(dbMoment.getId(), userName);
int likeCount = dbMoment.getLikeCount();
......@@ -259,7 +259,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("投票失败,当前动态未开启投票。");
}
String username = MobileTokenHelper.getUserName();
String username = SecurityUtils.getUsername();
long voteCount = this.voteService.getUserMomentVoteCount(dbMoment.getId(), username);
if (voteCount > 0) {
throw new ServiceException("投票失败,已对当前动态投票。");
......@@ -313,10 +313,11 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
}
// 添加动态评论
SysUser dbUser = SecurityUtils.getLoginUser().getUser();
BbsMomentComment newComment = new BbsMomentComment();
newComment.setMomentId(dbMoment.getId());
newComment.setUserName(MobileTokenHelper.getUserName());
newComment.setNikeName(MobileTokenHelper.getNikeName());
newComment.setUserName(dbUser.getUserName());
newComment.setNickName(dbUser.getNickName());
newComment.setContent(bo.getContent());
newComment.setStatus(CommentStatus.ZC.getStatus());
newComment.setIsFeatured(0);
......@@ -327,7 +328,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
updComment.setId(newComment.getId());
if (Objects.nonNull(dbParentComment)) {
updComment.setParentId(dbParentComment.getId());
updComment.setReplyNikeName(dbParentComment.getNikeName());
updComment.setReplyNikeName(dbParentComment.getNickName());
updComment.setAncestorPath(dbParentComment.getAncestorPath() + "," + newComment.getId());
} else {
updComment.setAncestorPath(String.valueOf(newComment.getId()));
......@@ -355,7 +356,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("删除失败,未查询到当前动态评论数据。");
}
String userName = MobileTokenHelper.getUserName();
String userName = SecurityUtils.getUsername();
if (!dbComment.getUserName().equals(userName)) {
throw new ServiceException("删除失败,没有对当前动态评论的操作权限。");
}
......@@ -380,7 +381,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
throw new ServiceException("操作失败,未查询到当前动态数据。");
}
String userName = MobileTokenHelper.getUserName();
String userName = SecurityUtils.getUsername();
if (!dbMoment.getUserName().equals(userName)) {
throw new ServiceException("操作失败,没有对当前动态评论的操作权限。");
}
......@@ -585,7 +586,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
BbsCommentVO cv = new BbsCommentVO();
cv.setId(c.getId());
cv.setCreateTime(c.getCreateTime());
cv.setNikeName(c.getNikeName());
cv.setNickName(c.getNickName());
cv.setUserName(c.getUserName());
cv.setContent(c.getContent());
cvs.add(cv);
......
......@@ -10,7 +10,7 @@ import com.tangguo.common.constant.TopicConstant;
import com.tangguo.common.core.redis.RedisCache;
import com.tangguo.common.enums.TopicTopStatus;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.common.utils.SensitiveWordUtils;
import com.tangguo.common.utils.StringUtils;
import com.tangguo.domain.BbsTopic;
......@@ -211,7 +211,7 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i
}
BbsTopic newTopic = new BbsTopic();
newTopic.setCreateBy(MobileTokenHelper.getUserName());
newTopic.setCreateBy(SecurityUtils.getUsername());
newTopic.setSource("移动端用户");
newTopic.setName(topicName);
this.save(newTopic);
......
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("登录失败,查询当前企微用户数据失败。");
}
QwmhUserInfo dbUser = this.bbsUserMapper.selectQwmhUserInfo(userName);
if (Objects.nonNull(dbUser)) {
Map<String, Object> payloads = new LinkedHashMap<>(2);
payloads.put("userName", dbUser.getUserName());
payloads.put("nikeName", dbUser.getNikeName());
return MobileTokenHelper.createDetailToken(payloads);
} else {
throw new ServiceException("登录失败,未查询到当前登录用户数据。");
}
}
/**
* 查询用户信息
*
* @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("操作失败,未查询到当前登录用户信息。");
}
}
}
......@@ -45,11 +45,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.id,
c.create_time,
c.moment_id,
c.nike_name,
c.nick_name,
c.user_name,
c.content,
c.parent_id,
c.reply_nike_name,
c.reply_nick_name,
ROW_NUMBER() OVER (PARTITION BY moment_id ORDER BY create_time) AS rn
FROM
bbs_moment_comment c
......@@ -85,11 +85,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.id,
c.create_time,
c.moment_id,
c.nike_name,
c.nick_name,
c.user_name,
c.content,
c.parent_id,
c.reply_nike_name,
c.reply_nick_name,
c.is_featured,
IF(c.user_name = #{userName}, 1, 0) AS is_self
FROM
......
......@@ -7,12 +7,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBbsMomentList" resultType="com.tangguo.domain.BbsMoment">
SELECT
m.*,
uv.nike_name,
uv.dept_name
uv.nick_name,
ud.dept_name
FROM
bbs_moment m
LEFT JOIN
qwmh_sys_user_view uv ON uv.user_name = m.user_name
sys_user uv ON uv.user_name = m.user_name
LEFT JOIN
sys_dept ud ON ud.dept_id = uv.dept_id
<where>
<if test="moment.content != null and moment.content != ''">
m.content LIKE CONCAT('%', #{moment.content}, '%')
......@@ -78,14 +80,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectMoments" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT
m.*,
uv.nike_name,
uv.nick_name,
IF(l.id IS NOT NULL, 1, 0) AS is_like,
IF(v.id IS NOT NULL, 1, 0) AS is_vote,
IF(m.user_name = #{userName}, 1, 0) AS is_self
FROM
bbs_moment m
LEFT JOIN
qwmh_sys_user_view uv ON uv.user_name = m.user_name
sys_user uv ON uv.user_name = m.user_name
LEFT JOIN
(
SELECT
......@@ -120,14 +122,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectMomentDetail" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT
m.*,
uv.nike_name,
uv.nick_name,
IF(l.id IS NOT NULL, 1, 0) AS is_like,
IF(v.id IS NOT NULL, 1, 0) AS is_vote,
IF(m.user_name = #{userName}, 1, 0) AS is_self
FROM
bbs_moment m
LEFT JOIN
qwmh_sys_user_view uv ON uv.user_name = m.user_name
sys_user uv ON uv.user_name = m.user_name
LEFT JOIN
(
SELECT
......
......@@ -7,7 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectVotes" resultType="com.tangguo.domain.vo.BbsVoteVO">
SELECT
v.create_time,
uv.nike_name
uv.nick_name
FROM
bbs_moment_vote v
LEFT JOIN
......
<?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
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
LEFT JOIN
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
) ug
WHERE
uv.user_name = #{userName}
</select>
</mapper>
......@@ -7,12 +7,10 @@ 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.mapper.BbsUserPointsExchangeMapper;
import com.tangguo.service.IBbsPointsGoodsService;
import com.tangguo.service.IBbsUserPointsExchangeService;
import io.swagger.annotations.Api;
......@@ -35,9 +33,6 @@ import java.util.List;
@RequestMapping("/bbs/points/exchange")
public class BbsUserPointsExchangeController extends BaseController {
@Resource
private BbsUserPointsExchangeMapper userPointsExchangeMapper;
@Resource
private IBbsUserPointsExchangeService bbsUserPointsExchangeService;
......@@ -45,18 +40,6 @@ public class BbsUserPointsExchangeController extends BaseController {
private IBbsPointsGoodsService pointsGoodsService;
/**
* 查询兑换人
*/
@ApiOperation("查询兑换人")
@PreAuthorize("@ss.hasPermi('points:points:list')")
@GetMapping("/select/users")
public AjaxResult selectUsers(String keyword) {
List<QwmhUserInfo> users = this.userPointsExchangeMapper.selectPointsUsers(keyword);
return AjaxResult.success(users);
}
/**
* 查询兑换商品
*/
......
......@@ -71,7 +71,7 @@ public class BbsUserPoints extends BaseEntity {
*/
@Excel(name = "用户姓名")
@TableField(exist = false)
private String nikeName;
private String nickName;
/**
* 用户部门
......
......@@ -35,7 +35,7 @@ public class BbsUserPointsExchange extends BaseEntity {
/** 用户姓名 */
@Excel(name = "用户姓名")
@ApiModelProperty("用户姓名")
private String nikeName;
private String nickName;
/** 用户名 */
@Excel(name = "用户名")
......
package com.tangguo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tangguo.common.domain.QwmhUserInfo;
import com.tangguo.domain.BbsUserPointsExchange;
import org.apache.ibatis.annotations.Param;
......@@ -17,7 +16,4 @@ public interface BbsUserPointsExchangeMapper extends BaseMapper<BbsUserPointsExc
List<BbsUserPointsExchange> selectBbsUserPointsExchangeList(@Param("exchange") BbsUserPointsExchange exchange);
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 org.apache.ibatis.annotations.Param;
......@@ -18,13 +17,7 @@ public interface BbsUserPointsMapper extends BaseMapper<BbsUserPoints> {
List<BbsUserPoints> selectBbsUserPointsList(@Param("points") BbsUserPoints points);
QwmhUserInfo selectQwmhUser(@Param("userName") String userName);
BbsUserPoints selectUserPoints(@Param("userName") String userName);
int initUserPointsGrade();
int selectUserCount(@Param("userName") String userName);
int refreshUserPointsGrade();
......
......@@ -23,6 +23,15 @@ public interface IBbsUserPointsService extends IService<BbsUserPoints> {
List<BbsUserPoints> selectBbsUserPointsList(BbsUserPoints bbsUserPoints);
/**
* 查询用户积分
*
* @param userName 用户名
* @return 积分
*/
BbsUserPoints getUserPoints(String userName);
/**
* 查询用户积分
*
......
......@@ -95,7 +95,7 @@ public class BbsUserPointsExchangeServiceImpl extends ServiceImpl<BbsUserPointsE
// 添加兑换记录
BbsUserPointsExchange addExchange = new BbsUserPointsExchange();
addExchange.setNikeName(exchange.getNikeName());
addExchange.setNickName(exchange.getNickName());
addExchange.setUserName(dbUserPoints.getUserName());
addExchange.setUserGradeName(dbUserPoints.getGradeName());
addExchange.setGoodsName(dbGoods.getName());
......
package com.tangguo.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.domain.PointsDetail;
import com.tangguo.common.domain.QwmhUserInfo;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.common.utils.SecurityUtils;
import com.tangguo.domain.BbsGrade;
......@@ -55,6 +55,20 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
}
/**
* 查询用户积分
*
* @param userName 用户名
* @return 积分
*/
@Override
public BbsUserPoints getUserPoints(String userName) {
return this.getOne(
Wrappers.lambdaQuery(BbsUserPoints.class).eq(BbsUserPoints::getUserName, userName)
);
}
/**
* 查询用户积分
*
......@@ -64,12 +78,10 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
@Override
public BbsUserPoints getAndInitUserPoints(String userName) {
BbsUserPoints dbUserPoints = this.baseMapper.selectUserPoints(userName);
BbsUserPoints dbUserPoints = this.getUserPoints(userName);
if (Objects.isNull(dbUserPoints)) {
QwmhUserInfo qwmhSysUser = this.baseMapper.selectQwmhUser(userName);
if (Objects.isNull(qwmhSysUser)) {
throw new ServiceException("查询用户积分失败,未查询到当前用户数据。");
} else {
int dbUserCount = this.baseMapper.selectUserCount(userName);
if (dbUserCount > 0) {
// 初始积分
dbUserPoints = new BbsUserPoints();
dbUserPoints.setUserName(userName);
......@@ -83,6 +95,8 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
dbUserPoints.setLastUpgradeTime(new Date());
}
this.save(dbUserPoints);
} else {
throw new ServiceException("查询用户积分失败,未查询到当前用户数据。");
}
}
return dbUserPoints;
......
......@@ -4,6 +4,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsGradeMapper">
</mapper>
......@@ -4,5 +4,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tangguo.mapper.BbsPointsSettingMapper">
</mapper>
......@@ -10,8 +10,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
FROM
bbs_user_points_exchange e
<where>
<if test="exchange.nikeName != null and exchange.nikeName != ''">
e.nike_name LIKE CONCAT('%', #{exchange.nikeName}, '%')
<if test="exchange.nickName != null and exchange.nickName != ''">
e.nick_name LIKE CONCAT('%', #{exchange.nickName}, '%')
</if>
<if test="exchange.userName != null and exchange.userName != ''">
AND e.user_name LIKE CONCAT('%', #{exchange.userName}, '%')
......@@ -33,29 +33,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
e.create_time DESC
</select>
<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
FROM
qwmh_sys_user_view uv
LEFT JOIN
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
) ug
<where>
<if test="keyword != null and keyword != ''">
nike_name LIKE CONCAT('%', #{keyword}, '%') OR user_name LIKE CONCAT('%', #{keyword}, '%')
</if>
</where>
ORDER BY
uv.create_time DESC
</select>
</mapper>
......@@ -6,22 +6,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBbsUserPointsList" resultType="com.tangguo.domain.BbsUserPoints">
SELECT
uv.nike_name,
uv.nick_name AS nick_name,
uv.user_name,
uv.dept_name,
ud.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
sys_user uv
LEFT JOIN
sys_dept ud ON ud.dept_id = uv.dept_id
LEFT JOIN
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
) ug
<where>
<if test="points.nikeName != null and points.nikeName != ''">
uv.nike_name LIKE CONCAT('%', #{points.nikeName}, '%')
<if test="points.keyword != null and points.keyword != ''">
uv.nick_name LIKE CONCAT('%', #{points.keyword}, '%') OR uv.user_name LIKE CONCAT('%', #{points.keyword}, '%')
</if>
<if test="points.nickName != null and points.nickName != ''">
AND uv.nick_name LIKE CONCAT('%', #{points.nickName}, '%')
</if>
<if test="points.userName != null and points.userName != ''">
AND uv.user_name LIKE CONCAT('%', #{points.userName}, '%')
......@@ -38,21 +43,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectQwmhUser" resultType="com.tangguo.common.domain.QwmhUserInfo">
SELECT * FROM qwmh_sys_user_view WHERE user_name = #{userName}
</select>
<select id="selectUserPoints" resultType="com.tangguo.domain.BbsUserPoints">
SELECT * FROM bbs_user_points WHERE user_name = #{userName}
<select id="selectUserCount" resultType="java.lang.Integer">
SELECT COUNT(*) FROM sys_user WHERE user_name = #{userName}
</select>
<update id="initUserPointsGrade">
</update>
<update id="refreshUserPointsGrade">
UPDATE
bbs_user_points p
......
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