diff --git a/service/src/main/java/com/hfkj/service/user/BsUserService.java b/service/src/main/java/com/hfkj/service/user/BsUserService.java index a4342b1..d8b4a9c 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserService.java @@ -78,4 +78,11 @@ public interface BsUserService { */ SessionObject updateSession(String token); + /** + * 获取积分数量 + * @param userId + * @return + */ + Long getIntegral(Long userId); + } diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java index 811ac76..bcf6103 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java @@ -155,4 +155,15 @@ public class BsUserServiceImpl implements BsUserService { return newSession; } + @Override + public Long getIntegral(Long userId) { + BsUserExample example = new BsUserExample(); + example.createCriteria().andIdEqualTo(userId).andStatusNotEqualTo(UserStatusEnum.status0.getCode()); + List list = userMapper.selectByExample(example); + if (!list.isEmpty()) { + return list.get(0).getIntegral(); + } + return null; + } + } diff --git a/user/src/main/java/com/user/controller/UserIntegralController.java b/user/src/main/java/com/user/controller/UserIntegralController.java new file mode 100644 index 0000000..dc5cabd --- /dev/null +++ b/user/src/main/java/com/user/controller/UserIntegralController.java @@ -0,0 +1,55 @@ +package com.user.controller; + +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.security.UserCenter; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.model.ResponseData; +import com.hfkj.model.UserSessionObject; +import com.hfkj.service.user.BsUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * @className: UserIntegralController + * @author: HuRui + * @date: 2024/5/20 + **/ +@Controller +@RequestMapping(value="/userIntegral") +@Api(value="用户积分业务") +public class UserIntegralController { + Logger log = LoggerFactory.getLogger(UserIntegralController.class); + @Resource + private BsUserService userService; + @Resource + private UserCenter userCenter; + + @RequestMapping(value="/queryIntegral",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "获取积分数量") + public ResponseData queryIntegral() { + try { + // 用户 + UserSessionObject userSessionObject = userCenter.getSessionModel(UserSessionObject.class); + if (userSessionObject == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, ""); + } + + return ResponseMsgUtil.success(userService.getIntegral(userSessionObject.getUser().getId())); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + +}