Commit 72a253bb authored by 万成波's avatar 万成波

优化代码

parent 2ccaa28c
......@@ -39,10 +39,9 @@ public class BbsTopicServiceImpl extends ServiceImpl<BbsTopicMapper, BbsTopic> i
@Override
public List<BbsTopic> selectBbsTopicList(BbsTopic topic) {
LambdaQueryWrapper<BbsTopic> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(BbsTopic::getCreateTime);
lqw.like(StringUtils.isNotBlank(topic.getSource()), BbsTopic::getSource, topic.getSource());
lqw.like(StringUtils.isNotBlank(topic.getName()), BbsTopic::getName, topic.getName());
lqw.orderByAsc(BbsTopic::getIsTop);
lqw.orderByDesc(BbsTopic::getIsTop);
lqw.orderByDesc(BbsTopic::getTopTime);
lqw.orderByAsc(BbsTopic::getSort);
return bbsTopicMapper.selectList(lqw);
......
......@@ -13,6 +13,8 @@ import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 用户积分对象 bbs_user_points
*
......@@ -48,6 +50,21 @@ public class BbsUserPoints extends BaseEntity {
@ApiModelProperty("当前积分")
private Integer currentPoints;
/** 当前等级编码 */
@Excel(name = "当前等级编码")
@ApiModelProperty("当前等级编码")
private String gradeCode;
/** 当前等级名称 */
@Excel(name = "当前等级名称")
@ApiModelProperty("当前等级名称")
private String gradeName;
/** 等级升级时间 */
@Excel(name = "等级升级时间")
@ApiModelProperty("等级升级时间")
private Date lastUpgradeTime;
/**
* 用户姓名
......@@ -57,7 +74,7 @@ public class BbsUserPoints extends BaseEntity {
private String nikeName;
/**
* 用户部门名称
* 用户部门
*/
@Excel(name = "部门名称")
@TableField(exist = false)
......
......@@ -53,4 +53,12 @@ public interface IBbsGradeService extends IService<BbsGrade> {
*/
void deleteGrade(Long gradeId);
/**
* 查询初始等级
*
* @return 等级
*/
BbsGrade getInitialGrade();
}
......@@ -166,4 +166,17 @@ public class BbsGradeServiceImpl extends ServiceImpl<BbsGradeMapper, BbsGrade> i
this.removeById(gradeId);
}
/**
* 查询初始等级
*
* @return 等级
*/
@Override
public BbsGrade getInitialGrade() {
return this.getOne(
Wrappers.lambdaQuery(BbsGrade.class).eq(BbsGrade::getIsInitial, IsInitialGrade.YES.getValue())
);
}
}
package com.tangguo.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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;
import com.tangguo.service.IBbsUserPointsService;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -32,11 +32,14 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Resource
private BbsUserPointsMapper bbsUserPointsMapper;
@Resource
private BbsUserPointsServiceImpl pointsServiceImpl;
@Resource
private IBbsUserPointsDetailService pointsDetailService;
@Resource
private BbsUserPointsServiceImpl userPointsServiceImpl;
private IBbsGradeService gradeService;
/**
......@@ -63,14 +66,21 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
BbsUserPoints dbUserPoints = this.baseMapper.selectUserPoints(userName);
if (Objects.isNull(dbUserPoints)) {
QwmhSysUserVO qwmhSysUser = this.baseMapper.selectQwmhUser(userName);
if (Objects.nonNull(qwmhSysUser)) {
if (Objects.isNull(qwmhSysUser)) {
throw new ServiceException("查询用户积分失败,未查询到当前用户数据。");
} else {
dbUserPoints = new BbsUserPoints();
// 用户初始积分
dbUserPoints.setUserName(userName);
dbUserPoints.setAccumulatedPoints(0);
dbUserPoints.setCurrentPoints(0);
// 用户初始等级
BbsGrade dbGrade = this.gradeService.getInitialGrade();
if (Objects.nonNull(dbGrade)) {
dbUserPoints.setGradeCode(dbGrade.getCode());
dbUserPoints.setGradeName(dbGrade.getName());
}
this.save(dbUserPoints);
} else {
throw new ServiceException("查询用户积分失败,未查询到当前用户数据。");
}
}
return dbUserPoints;
......@@ -121,7 +131,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Override
public void incrUserPoints(PointsDetail detail) {
synchronized (detail.getUserName().intern()) {
this.userPointsServiceImpl.privIncrUserPoints(detail);
this.pointsServiceImpl.privIncrUserPoints(detail);
}
}
......@@ -134,7 +144,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
@Override
public void decrUserPoints(PointsDetail detail) {
synchronized (detail.getUserName().intern()) {
this.userPointsServiceImpl.privDecrUserPoints(detail);
this.pointsServiceImpl.privDecrUserPoints(detail);
}
}
......@@ -153,7 +163,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
// 更新用户积分
String userName = detail.getUserName();
BbsUserPoints userPoints = this.userPointsServiceImpl.getUserPoints(userName);
BbsUserPoints userPoints = this.pointsServiceImpl.getUserPoints(userName);
Integer currentPoints = userPoints.getCurrentPoints();
int incrCurrentPoints = currentPoints + points;
userPoints.setCurrentPoints(incrCurrentPoints);
......@@ -187,7 +197,7 @@ public class BbsUserPointsServiceImpl extends ServiceImpl<BbsUserPointsMapper, B
// 更新用户积分
String userName = detail.getUserName();
BbsUserPoints userPoints = this.userPointsServiceImpl.getUserPoints(userName);
BbsUserPoints userPoints = this.pointsServiceImpl.getUserPoints(userName);
Integer currentPoints = userPoints.getCurrentPoints();
if (points > currentPoints) {
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.BbsUserGradeMapper">
</mapper>
......@@ -6,14 +6,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectPointsUsers" resultType="com.tangguo.domain.vo.QwmhSysUserVO">
SELECT
uv.*,
g.grade_name,
uv.user_name,
uv.nike_name,
IFNULL(p.current_points, 0) AS current_points,
IFNULL(p.accumulated_points, 0) AS accumulated_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_grade g ON g.user_name = uv.user_name
CROSS JOIN (
SELECT (SELECT name FROM bbs_grade WHERE is_initial = 1) AS name
) ug
LEFT JOIN
bbs_user_points p ON p.user_name = uv.user_name
<where>
......@@ -22,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
ORDER BY
uv.user_id
uv.create_time DESC
</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