package com.webmanage.controller;
|
|
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.entity.Points;
|
import com.webmanage.entity.PointsRule;
|
import com.webmanage.service.PointsFlowService;
|
import com.webmanage.service.PointsRuleService;
|
import com.webmanage.service.PointsService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.validation.Valid;
|
import javax.validation.constraints.NotNull;
|
import java.util.List;
|
import com.webmanage.entity.PointsFlow;
|
|
/**
|
* 积分管理Controller
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/api/points")
|
@Api(tags = "积分管理")
|
@Validated
|
public class PointsController {
|
|
@Resource
|
private PointsRuleService pointsRuleService;
|
|
@Resource
|
private PointsFlowService pointsFlowService;
|
|
@Resource
|
private PointsService pointsService;
|
|
// ==================== 积分主表管理 ====================
|
|
@PostMapping("/main/page")
|
@ApiOperation("分页查询积分主表")
|
public Result<Object> getPointsMainPage(@Valid @RequestBody PointsMainQueryDTO queryDTO) {
|
try {
|
return Result.success(pointsService.getPointsMainPage(queryDTO));
|
} catch (Exception e) {
|
log.error("查询积分主表失败", e);
|
return Result.error("查询积分主表失败:" + e.getMessage());
|
}
|
}
|
|
|
// ==================== 积分规则管理 ====================
|
|
@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) {
|
try {
|
return Result.success(pointsRuleService.getPointsRulePage(pageNum, pageSize, ruleName, ruleType));
|
} catch (Exception e) {
|
log.error("查询积分规则失败", e);
|
return Result.error("查询积分规则失败:" + e.getMessage());
|
}
|
}
|
|
@PostMapping("/rule/add")
|
@ApiOperation("新增积分规则")
|
public Result<Object> addPointsRule(@Valid @RequestBody PointsRuleDTO pointsRuleDTO) {
|
try {
|
boolean result = pointsRuleService.addPointsRule(pointsRuleDTO);
|
if (result) {
|
return Result.success("新增积分规则成功");
|
} else {
|
return Result.error("新增积分规则失败");
|
}
|
} catch (Exception e) {
|
log.error("新增积分规则失败", e);
|
return Result.error("新增积分规则失败:" + e.getMessage());
|
}
|
}
|
|
@PostMapping("/rule/update")
|
@ApiOperation("修改积分规则")
|
public Result<Object> updatePointsRule(@Valid @RequestBody PointsRuleDTO pointsRuleDTO) {
|
try {
|
boolean result = pointsRuleService.updatePointsRule(pointsRuleDTO);
|
if (result) {
|
return Result.success("修改积分规则成功");
|
} else {
|
return Result.error("修改积分规则失败");
|
}
|
} catch (Exception e) {
|
log.error("修改积分规则失败", e);
|
return Result.error("修改积分规则失败:" + e.getMessage());
|
}
|
}
|
|
@DeleteMapping("/rule/{id}")
|
@ApiOperation("删除积分规则")
|
public Result<Object> deletePointsRule(@ApiParam("规则ID") @PathVariable Long id) {
|
try {
|
boolean result = pointsRuleService.deletePointsRule(id);
|
if (result) {
|
return Result.success("删除积分规则成功");
|
} else {
|
return Result.error("删除积分规则失败");
|
}
|
} catch (Exception e) {
|
log.error("删除积分规则失败", e);
|
return Result.error("删除积分规则失败:" + e.getMessage());
|
}
|
}
|
|
@PostMapping("/rule/toggle/{id}")
|
@ApiOperation("启用/禁用积分规则")
|
public Result<Object> togglePointsRuleStatus(@ApiParam("规则ID") @PathVariable Long id,
|
@ApiParam("是否启用") @RequestParam @NotNull Boolean isEnabled) {
|
try {
|
boolean result = pointsRuleService.togglePointsRuleStatus(id, isEnabled);
|
if (result) {
|
return Result.success("操作成功");
|
} else {
|
return Result.error("操作失败");
|
}
|
} catch (Exception e) {
|
log.error("操作积分规则状态失败", e);
|
return Result.error("操作积分规则状态失败:" + e.getMessage());
|
}
|
}
|
|
@GetMapping("/rule/type/{ruleType}")
|
@ApiOperation("根据规则类型查询启用的规则")
|
public Result<Object> getEnabledRulesByType(@ApiParam("规则类型") @PathVariable String ruleType) {
|
try {
|
List<PointsRule> rules = pointsRuleService.getEnabledRulesByType(ruleType);
|
return Result.success(rules);
|
} catch (Exception e) {
|
log.error("查询积分规则失败", e);
|
return Result.error("查询积分规则失败:" + e.getMessage());
|
}
|
}
|
|
// ==================== 积分流水查询 ====================
|
|
@PostMapping("/flow/personal/page")
|
@ApiOperation("分页查询个人积分流水")
|
public Result<Object> getPersonalPointsFlowPage(@Valid @RequestBody PointsFlowQueryDTO queryDTO) {
|
try {
|
return Result.success(pointsFlowService.getPersonalPointsFlowPage(queryDTO));
|
} catch (Exception e) {
|
log.error("查询个人积分流水失败", e);
|
return Result.error("查询个人积分流水失败:" + e.getMessage());
|
}
|
}
|
|
@PostMapping("/flow/unit/page")
|
@ApiOperation("分页查询单位积分流水")
|
public Result<Object> getUnitPointsFlowPage(@Valid @RequestBody PointsFlowQueryDTO queryDTO) {
|
try {
|
return Result.success(pointsFlowService.getUnitPointsFlowPage(queryDTO));
|
} catch (Exception e) {
|
log.error("查询单位积分流水失败", e);
|
return Result.error("查询单位积分流水失败:" + e.getMessage());
|
}
|
}
|
|
@GetMapping("/flow/user/{userId}")
|
@ApiOperation("根据用户ID查询积分流水")
|
public Result<Object> getPointsFlowByUserId(@ApiParam("用户ID") @PathVariable Long userId) {
|
try {
|
List<PointsFlow> flows = pointsFlowService.getPointsFlowByUserId(userId);
|
return Result.success(flows);
|
} catch (Exception e) {
|
log.error("查询用户积分流水失败", e);
|
return Result.error("查询用户积分流水失败:" + e.getMessage());
|
}
|
}
|
|
@GetMapping("/flow/unit/{unitId}")
|
@ApiOperation("根据单位ID查询积分流水")
|
public Result<Object> getPointsFlowByUnitId(@ApiParam("单位ID") @PathVariable Long unitId) {
|
try {
|
List<PointsFlow> flows = pointsFlowService.getPointsFlowByUnitId(unitId);
|
return Result.success(flows);
|
} catch (Exception e) {
|
log.error("查询单位积分流水失败", e);
|
return Result.error("查询单位积分流水失败:" + e.getMessage());
|
}
|
}
|
|
// ==================== 新增积分流水 ====================
|
|
@PostMapping("/flow/add")
|
@ApiOperation("新增积分流水(根据规则自动计算)")
|
public Result<Object> addPointsFlow(@Valid @RequestBody AddPointsFlowDTO addPointsFlowDTO) {
|
try {
|
boolean result = pointsFlowService.addPointsFlowByRule(addPointsFlowDTO);
|
if (result) {
|
return Result.success("新增积分流水成功");
|
} else {
|
return Result.error("新增积分流水失败");
|
}
|
} catch (Exception e) {
|
log.error("新增积分流水失败", e);
|
return Result.error("新增积分流水失败:" + e.getMessage());
|
}
|
}
|
|
@PostMapping("/flow/add/personal")
|
@ApiOperation("新增个人积分流水")
|
public Result<Object> addPersonalPointsFlow(@Valid @RequestBody AddPointsFlowDTO addPointsFlowDTO) {
|
try {
|
boolean result = pointsFlowService.addPointsFlowByRule(addPointsFlowDTO);
|
if (result) {
|
return Result.success("新增个人积分流水成功");
|
} else {
|
return Result.error("新增个人积分流水失败");
|
}
|
} catch (Exception e) {
|
log.error("新增个人积分流水失败", e);
|
return Result.error("新增个人积分流水失败:" + e.getMessage());
|
}
|
}
|
|
@PostMapping("/flow/add/unit")
|
@ApiOperation("新增单位积分流水")
|
public Result<Object> addUnitPointsFlow(@Valid @RequestBody AddPointsFlowDTO addPointsFlowDTO) {
|
try {
|
boolean result = pointsFlowService.addPointsFlowByRule(addPointsFlowDTO);
|
if (result) {
|
return Result.success("新增单位积分流水成功");
|
} else {
|
return Result.error("新增单位积分流水失败");
|
}
|
} catch (Exception e) {
|
log.error("新增单位积分流水失败", e);
|
return Result.error("新增单位积分流水失败:" + e.getMessage());
|
}
|
}
|
|
// ==================== 积分统计 ====================
|
|
@GetMapping("/total/user/{userId}")
|
@ApiOperation("获取用户积分统计")
|
public Result<Object> getUserPointsTotal(@ApiParam("用户ID") @PathVariable Long userId) {
|
try {
|
Integer total = pointsFlowService.getUserPointsTotal(userId);
|
return Result.success(total);
|
} 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) {
|
try {
|
Integer total = pointsFlowService.getUnitPointsTotal(unitId);
|
return Result.success(total);
|
} catch (Exception e) {
|
log.error("获取单位积分统计失败", e);
|
return Result.error("获取单位积分统计失败:" + e.getMessage());
|
}
|
}
|
}
|