| | |
| | | package com.webmanage.controller; |
| | | |
| | | import com.webmanage.common.PageResult; |
| | | import com.webmanage.common.Result; |
| | | import com.webmanage.dto.AddPointsFlowDTO; |
| | | import com.webmanage.dto.PointsFlowQueryDTO; |
| | | import com.webmanage.dto.PointsMainQueryDTO; |
| | | import com.webmanage.dto.PointsRuleDTO; |
| | | import com.webmanage.dto.*; |
| | | import com.webmanage.entity.Points; |
| | | import com.webmanage.entity.PointsRule; |
| | | import com.webmanage.entity.UserPoints; |
| | | import com.webmanage.service.PointsFlowService; |
| | | import com.webmanage.service.PointsRuleService; |
| | | import com.webmanage.service.PointsService; |
| | | import com.webmanage.vo.PointsRuleResultVO; |
| | | import com.webmanage.vo.PointsRuleVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | |
| | | |
| | | @PostMapping("/main/page") |
| | | @ApiOperation("分页查询积分主表") |
| | | public Result<Object> getPointsMainPage(@Valid @RequestBody PointsMainQueryDTO queryDTO) { |
| | | public Result<PageResult<Points>> getPointsMainPage(@Valid @RequestBody PointsMainQueryDTO queryDTO) { |
| | | try { |
| | | return Result.success(pointsService.getPointsMainPage(queryDTO)); |
| | | } catch (Exception e) { |
| | |
| | | |
| | | // ==================== 积分规则管理 ==================== |
| | | |
| | | @PostMapping("/rule/page") |
| | | @ApiOperation("分页查询积分规则") |
| | | public Result<Object> getPointsRulePage(@RequestParam(defaultValue = "1") Integer pageNum, |
| | | @RequestParam(defaultValue = "10") Integer pageSize, |
| | | @RequestParam(required = false) String ruleName, |
| | | @RequestParam(required = false) String ruleType) { |
| | | @PostMapping("/rule/list") |
| | | @ApiOperation("根据规则主表ID查询积分规则") |
| | | public Result<PointsRuleResultVO> getPointsRuleListById( |
| | | @RequestParam(required = true) @NotNull Long ruleId) { |
| | | try { |
| | | return Result.success(pointsRuleService.getPointsRulePage(pageNum, pageSize, ruleName, ruleType)); |
| | | return Result.success(pointsRuleService.getPointsRuleList(ruleId)); |
| | | } catch (Exception e) { |
| | | log.error("查询积分规则失败", e); |
| | | return Result.error("查询积分规则失败:" + e.getMessage()); |
| | |
| | | |
| | | @PostMapping("/rule/update") |
| | | @ApiOperation("修改积分规则") |
| | | public Result<Object> updatePointsRule(@Valid @RequestBody PointsRuleDTO pointsRuleDTO) { |
| | | public Result<Object> updatePointsRule(@Valid @RequestBody List<PointsRuleDTO> pointsRuleDTO) { |
| | | try { |
| | | boolean result = pointsRuleService.updatePointsRule(pointsRuleDTO); |
| | | if (result) { |
| | |
| | | |
| | | @GetMapping("/total/user/{userId}") |
| | | @ApiOperation("获取用户积分统计") |
| | | public Result<Object> getUserPointsTotal(@ApiParam("用户ID") @PathVariable Long userId) { |
| | | public Result<UserPoints> getUserPointsTotal(@ApiParam("用户ID") @PathVariable String userId) { |
| | | try { |
| | | Integer total = pointsFlowService.getUserPointsTotal(userId); |
| | | return Result.success(total); |
| | | UserPoints userPoints = pointsFlowService.getUserPointsTotal(userId); |
| | | return Result.success(userPoints); |
| | | } catch (Exception e) { |
| | | log.error("获取用户积分统计失败", e); |
| | | return Result.error("获取用户积分统计失败:" + e.getMessage()); |
| | |
| | | |
| | | @GetMapping("/total/unit/{unitId}") |
| | | @ApiOperation("获取单位积分统计") |
| | | public Result<Object> getUnitPointsTotal(@ApiParam("单位ID") @PathVariable Long unitId) { |
| | | public Result<UserPoints> getUnitPointsTotal(@ApiParam("单位ID") @PathVariable Long unitId) { |
| | | try { |
| | | Integer total = pointsFlowService.getUnitPointsTotal(unitId); |
| | | UserPoints total = pointsFlowService.getUnitPointsTotal(unitId); |
| | | return Result.success(total); |
| | | } catch (Exception e) { |
| | | log.error("获取单位积分统计失败", e); |
| | | return Result.error("获取单位积分统计失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // ==================== 积分扣减 ==================== |
| | | |
| | | @PostMapping("/user/deduct") |
| | | @ApiOperation("扣减用户积分") |
| | | public Result<Object> deductUserPoints(@Valid @RequestBody DeductUserPointsDTO deductDTO) { |
| | | try { |
| | | boolean result = pointsFlowService.deductUserPoints(deductDTO); |
| | | if (result) { |
| | | return Result.success("积分扣减成功"); |
| | | } else { |
| | | return Result.error("积分扣减失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("积分扣减失败", e); |
| | | return Result.error("积分扣减失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // ==================== 积分流水数据类目 ==================== |
| | | |
| | | @GetMapping("/flow/categories") |
| | | @ApiOperation("获取积分流水数据类目列表") |
| | | public Result<Object> getPointsFlowCategories() { |
| | | try { |
| | | List<String> categories = pointsFlowService.getPointsFlowCategories(); |
| | | return Result.success(categories); |
| | | } catch (Exception e) { |
| | | log.error("获取积分流水数据类目失败", e); |
| | | return Result.error("获取积分流水数据类目失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |