//package com.backendsys.controller.Systems; // //import com.backendsys.aspect.HttpRequestAspect; //import com.backendsys.exception.CustException; //import com.backendsys.entity.PageDTO; //import com.backendsys.entity.System.SysUserPointsDTO; //import com.backendsys.enums.UserPointActivityType; //import com.backendsys.enums.UserPointOperatorType; //import com.backendsys.mapper.System.SysUserPointsHistoryMapper; //import com.backendsys.modules.common.config.security.utils.SecurityUtil; //import com.backendsys.service.System.SysUserPointHistoryService; //import com.backendsys.utils.response.Result; //import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.security.access.prepost.PreAuthorize; //import org.springframework.transaction.annotation.Transactional; //import org.springframework.validation.annotation.Validated; //import org.springframework.web.bind.annotation.GetMapping; //import org.springframework.web.bind.annotation.PutMapping; //import org.springframework.web.bind.annotation.RequestBody; //import org.springframework.web.bind.annotation.RestController; // //import java.util.Map; // //@Validated //@RestController //public class SysUserPointController { // // @Autowired // private HttpRequestAspect httpRequestAspect; // // @Autowired // private SysUserPointHistoryService sysUserPointHistoryService; // // @Autowired // private SysUserPointsHistoryMapper sysUserPointsHistoryMapper; // // /** // * 检查积分操作,制定相应规则: // * - 判断如果该值为空值,则获取自己 // * - 判断如果查询的不是自己,则判断是否为超管,都不是则抛出异常 // */ // private void inspectPointOperation(SysUserPointsDTO sysUserPointsDTO) { // Long user_id = httpRequestAspect.getUserId(); // // 如果目标用户ID为空,则设置为当前用户ID // // if (sysUserPointsDTO.getTarget_user_id() == null) { // sysUserPointsDTO.setTarget_user_id(user_id); // } // // 检查是否为超级管理员 // boolean isSuper = SecurityUtil.isSuper(); // // 如果非超级管理员且目标用户ID与当前用户ID不匹配,则抛出权限异常 // if (!isSuper && sysUserPointsDTO.getTarget_user_id() != null && !sysUserPointsDTO.getTarget_user_id().equals(user_id)) { // throw new CustException("当前用户没有权限查看或操作其他用户积分"); // } // } // // /** // * 操作用户积分 (增加/减少) // */ // @Transactional // @PreAuthorize("@sr.hasPermission('3.3.8')") // @PutMapping("/api/system/user/adjustmentUserPoint") // public Result adjustmentUserPoint(@Validated(SysUserPointsDTO.Adjustment.class) @RequestBody SysUserPointsDTO sysUserPointsDTO) { // // // 检查积分操作 // inspectPointOperation(sysUserPointsDTO); // // Map resp = sysUserPointHistoryService.adjustmentUserPoint(sysUserPointsDTO); // // // -- 积分操作记录 ---------------------------------------------------------- // // 触发事件类型 (枚举) // sysUserPointsDTO.setActivity_type(UserPointActivityType.BACKEND.getCode()); // sysUserPointsDTO.setActivity_type_description(UserPointActivityType.BACKEND.getDescription()); // // // 操作人类型 (枚举) // sysUserPointsDTO.setOperator_type(UserPointOperatorType.USER.getCode()); // // 操作人 (用户ID) (查询) 自身 UserId // Long user_id = httpRequestAspect.getUserId(); // sysUserPointsDTO.setOperator_user_id(user_id); // sysUserPointsDTO.setActivity_detail("手动操作积分"); // // [插入] 积分操作记录 // System.out.println(sysUserPointsDTO); // sysUserPointsHistoryMapper.insertUserPointsHistory(sysUserPointsDTO); // // -------------------------------------------------------------------------- // // return Result.success(resp, "更新成功"); // } // // /** // * 查询单个用户积分 (超级管理员可查看其他人) // */ // @PreAuthorize("@sr.hasPermission('3.3.9')") // @GetMapping("/api/system/user/getUserPoint") // public Result getUserPoint(@Validated(SysUserPointsDTO.Detail.class) SysUserPointsDTO sysUserPointsDTO) { // // 检查积分操作 // inspectPointOperation(sysUserPointsDTO); // return Result.success(sysUserPointHistoryService.queryUserPoint(sysUserPointsDTO)); // } // // /** // * 查询用户积分操作记录列表 // */ // @PreAuthorize("@sr.hasPermission('3.3.10')") // @GetMapping("/api/system/user/getUserPointHistory") // public Result getUserPointHistory(@Validated PageDTO pageDTO, @Validated SysUserPointsDTO sysUserPointsDTO) { // // 检查积分操作 // inspectPointOperation(sysUserPointsDTO); //// return Result.success(sysUserService.queryUserPointHistoryList(pageDTO.getPage_num(), pageDTO.getPage_size(), sysUserPointsDTO)); // return Result.success(sysUserPointHistoryService.queryUserPointHistoryList(pageDTO.getPage_num(), pageDTO.getPage_size(), sysUserPointsDTO)); // } // //}