提交 eaf999d0 作者: 刘明祎-运维用途

添加获取用户基本信息的接口让ims调用

上级 7980f652
流水线 #7448 已通过 于阶段
in 2 分 21 秒
......@@ -16,6 +16,7 @@ import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
......@@ -75,6 +76,14 @@ public class UserPointsController extends BaseController {
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@GetMapping("/changeUserPoints")
public ResultBody changeUserPoints(HttpServletRequest request,@RequestParam("id") Integer id) {
return userPointsService.changeUserPoints(this.getUserLoginInfoFromRedis(request).getUserAccountId(), id);
return userPointsService.changeUserPoints(this.getUserLoginInfoFromRedis(request).getUserAccountId(), id,0,null);
}
@ApiOperation(value = "远程调用——积分变动接口")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@GetMapping("/feignChangeUserPoints")
@ApiIgnore
public ResultBody feignChangeUserPoints(HttpServletRequest request,@RequestParam("id") int changePoint,String reason) {
return userPointsService.changeUserPoints(this.getUserLoginInfoFromRedis(request).getUserAccountId(), null,changePoint,reason);
}
}
......@@ -25,10 +25,13 @@ public interface UserPointsService {
/**
* 改变用户积分,
* 改变用户积分,一种是前端传用户userid和扣除积分的pointChangeTypeId(数据库查找变动积分多少和积分变更原因)
* 另一种是供别的服务使用 直接传入用户userid和变动多少积分changePoint和变动原因
* @param userId 用户id
* @param pointChangeTypeId 根据这个id去user_points_change_type表中查找需要修改多少积分
* @param pointChangeTypeId 根据这个id去user_points_change_type表中查找需要修改多少积分和原因
* @param changePoint 修改多少积分
* @return {@link ResultBody}
*/
ResultBody changeUserPoints(Integer userId,Integer pointChangeTypeId);
ResultBody changeUserPoints(Integer userId,Integer pointChangeTypeId,int changePoint,String reason);
}
......@@ -114,21 +114,25 @@ public class UserPointsServiceImpl implements UserPointsService {
}
@Override
public ResultBody changeUserPoints(Integer userId, Integer pointChangeTypeId) {
public ResultBody changeUserPoints(Integer userId, Integer pointChangeTypeId,int changePoint,String reason) {
//先根据积分变动id pointChangeTypeId 去找到积分变动类型信息
UserPointChangeTypeDO userPointChangeTypeDO = userPointsDetailsDao.selectChangePoint(pointChangeTypeId);
if(userPointChangeTypeDO == null) {
return ResultBody.error("扣除积分类型不存在");
if(pointChangeTypeId != null) {
UserPointChangeTypeDO userPointChangeTypeDO = userPointsDetailsDao.selectChangePoint(pointChangeTypeId);
if (userPointChangeTypeDO == null) {
return ResultBody.error("扣除积分类型不存在");
}
//用户更改完积分后如果小于0就代表积分不够 大于0就去修改数据库用户总积分
//改变的积分
changePoint = userPointChangeTypeDO.getChangePoint();
//改变积分的原因
reason = userPointChangeTypeDO.getPointSource();
}
UserPointsDO userPointsDO = userPointsDao.selectUserPoints(userId);
if(userPointsDO == null) {
if (userPointsDO == null) {
userPointsDO.setUserAccountId(userId);
userPointsDO.setTotalPoints(0);
userPointsDao.insertPoints(userPointsDO);
}
//用户更改完积分后如果小于0就代表积分不够 大于0就去修改数据库用户总积分
//改变的积分
Integer changePoint = userPointChangeTypeDO.getChangePoint();
//改变后的用户总积分
Integer userNowPoints = userPointsDO.getTotalPoints() + changePoint;
if(userNowPoints < 0) {
......@@ -136,8 +140,9 @@ public class UserPointsServiceImpl implements UserPointsService {
}
userPointsDO.setTotalPoints(userNowPoints);
userPointsDao.updatePoints(userPointsDO);
//添加一条积分变动记录
UserPointsDetails userPointsDetails = new UserPointsDetails(userId,changePoint,userPointChangeTypeDO.getPointSource());
UserPointsDetails userPointsDetails = new UserPointsDetails(userId,changePoint,reason);
userPointsDetailsDao.insertPointsDetails(userPointsDetails);
return ResultBody.success();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论