From c28a6afe1f87acecbe7aad4559a3842b1e3d5acb Mon Sep 17 00:00:00 2001 From: seatonwan9 Date: 星期五, 15 八月 2025 18:57:09 +0800 Subject: [PATCH] 积分管理 --- src/main/java/com/webmanage/entity/PointsRule.java | 25 ++ src/main/java/com/webmanage/mapper/PointsFlowMapper.java | 15 - src/main/java/com/webmanage/service/impl/PointsFlowServiceImpl.java | 219 ++++++++++++++++----- src/main/java/com/webmanage/service/impl/PointsRuleServiceImpl.java | 86 ++++---- src/main/java/com/webmanage/dto/PointsFlowQueryDTO.java | 11 src/main/java/com/webmanage/service/PointsRuleService.java | 2 src/main/java/com/webmanage/emun/RuleTypeEnum.java | 8 src/main/java/com/webmanage/mapper/PointsRuleMapper.java | 5 src/main/java/com/webmanage/controller/PointsController.java | 32 ++- src/main/java/com/webmanage/vo/PointsRuleVO.java | 20 ++ src/main/java/com/webmanage/entity/PointsFlow.java | 8 src/main/java/com/webmanage/dto/AddPointsFlowDTO.java | 26 + src/main/java/com/webmanage/dto/PointsRuleDTO.java | 40 ++- /dev/null | 40 ---- src/main/java/com/webmanage/service/PointsFlowService.java | 15 15 files changed, 342 insertions(+), 210 deletions(-) diff --git a/src/main/java/com/webmanage/controller/PointsController.java b/src/main/java/com/webmanage/controller/PointsController.java index 942a46d..8f4214f 100644 --- a/src/main/java/com/webmanage/controller/PointsController.java +++ b/src/main/java/com/webmanage/controller/PointsController.java @@ -2,12 +2,10 @@ 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; @@ -91,7 +89,7 @@ @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) { @@ -252,10 +250,10 @@ @GetMapping("/total/user/{userId}") @ApiOperation("鑾峰彇鐢ㄦ埛绉垎缁熻") - public Result<Object> getUserPointsTotal(@ApiParam("鐢ㄦ埛ID") @PathVariable Long userId) { + public Result<UserPoints> getUserPointsTotal(@ApiParam("鐢ㄦ埛ID") @PathVariable Long 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()); @@ -264,13 +262,27 @@ @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()); } } + + // ==================== 绉垎娴佹按鏁版嵁绫荤洰 ==================== + + @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()); + } + } } diff --git a/src/main/java/com/webmanage/dto/AddPointsFlowDTO.java b/src/main/java/com/webmanage/dto/AddPointsFlowDTO.java index 5fbb5c0..4712c53 100644 --- a/src/main/java/com/webmanage/dto/AddPointsFlowDTO.java +++ b/src/main/java/com/webmanage/dto/AddPointsFlowDTO.java @@ -22,20 +22,28 @@ @NotNull(message = "鍗曚綅ID涓嶈兘涓虹┖") private Long unitId; - @ApiModelProperty("瑙勫垯绫诲瀷(鑾峰緱/娑堣垂)") - @NotBlank(message = "瑙勫垯绫诲瀷涓嶈兘涓虹┖") - private String ruleType; + @ApiModelProperty("瑙勫垯绫诲瀷(0鑾峰緱/1娑堣垂)") + @NotNull(message = "瑙勫垯绫诲瀷涓嶈兘涓虹┖") + private Integer ruleType; - @ApiModelProperty("瑙勫垯鍚嶇О") - @NotBlank(message = "瑙勫垯鍚嶇О涓嶈兘涓虹┖") - private String ruleName; + @ApiModelProperty("绉垎瑙勫垯绫诲埆(璧勬簮璐$尞銆佽祫婧愪紶鎾�佽祫婧愪氦鏄撱�佷氦娴佺ぞ鍖轰簰鍔�)") + @NotBlank(message = "瑙勫垯绫诲埆涓嶈兘涓虹┖") + private String category; + + @ApiModelProperty("绉垎瑙勫垯绫诲埆(璧勬簮璐$尞銆佽祫婧愪紶鎾�佽祫婧愪氦鏄撱�佷氦娴佺ぞ鍖轰簰鍔�)") + @NotBlank(message = "绉垎瑙勫垯缂栫爜") + private String ruleNameCode; + + @ApiModelProperty("鏁版嵁绫荤洰)") + @NotBlank(message = "鏁版嵁绫荤洰涓嶈兘涓虹┖") + private String dataCategoty; @ApiModelProperty("鍏宠仈璁㈠崟ID") private String orderId; - @ApiModelProperty("绉垎娴佹按鎻忚堪") - private String description; - @ApiModelProperty("瑙﹀彂娆℃暟(榛樿涓�1)") private Integer count = 1; + + @ApiModelProperty("娴佹按鎻忚堪(鍙�夛紝涓嶅~鍒欎娇鐢ㄨ鍒欐弿杩�)") + private String description; } diff --git a/src/main/java/com/webmanage/dto/PointsFlowQueryDTO.java b/src/main/java/com/webmanage/dto/PointsFlowQueryDTO.java index 3234cf0..98aaa5c 100644 --- a/src/main/java/com/webmanage/dto/PointsFlowQueryDTO.java +++ b/src/main/java/com/webmanage/dto/PointsFlowQueryDTO.java @@ -25,20 +25,23 @@ @ApiModelProperty("鍗曚綅ID") private Long unitId; - @ApiModelProperty("娴佹按绫诲瀷(鑾峰緱/娑堣垂)") - private String flowType; + @ApiModelProperty("娴佹按绫诲瀷(0鑾峰緱1/娑堣垂)") + private Integer dataType; @ApiModelProperty("绉垎鏉ユ簮") private String pointsSource; + + @ApiModelProperty("鏁版嵁绫荤洰") + private String dataCategory; @ApiModelProperty("鍏宠仈璁㈠崟ID") private String orderId; @ApiModelProperty("寮�濮嬫椂闂�") - private LocalDateTime startTime; + private LocalDateTime flowStartTime; @ApiModelProperty("缁撴潫鏃堕棿") - private LocalDateTime endTime; + private LocalDateTime flowEndTime; @ApiModelProperty("鎺掑簭瀛楁") private String orderBy = "created_at"; diff --git a/src/main/java/com/webmanage/dto/PointsRuleDTO.java b/src/main/java/com/webmanage/dto/PointsRuleDTO.java index e816a14..e65ff38 100644 --- a/src/main/java/com/webmanage/dto/PointsRuleDTO.java +++ b/src/main/java/com/webmanage/dto/PointsRuleDTO.java @@ -1,5 +1,6 @@ package com.webmanage.dto; +import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -16,39 +17,44 @@ public class PointsRuleDTO { @ApiModelProperty("涓婚敭ID") - private Long id; + private Long pointsId; @ApiModelProperty("瑙勫垯鍚嶇О") @NotBlank(message = "瑙勫垯鍚嶇О涓嶈兘涓虹┖") private String ruleName; + @ApiModelProperty("瑙勫垯缂栫爜") + @NotBlank(message = "瑙勫垯缂栫爜涓嶈兘涓虹┖") + private String ruleNameCode; + + @ApiModelProperty("瑙勫垯绫诲瀷(鑾峰緱/娑堣垂)") - @NotBlank(message = "瑙勫垯绫诲瀷涓嶈兘涓虹┖") - private String ruleType; + @NotNull(message = "瑙勫垯绫诲瀷涓嶈兘涓虹┖") + private Integer ruleType; + + @ApiModelProperty("瑙勫垯绫诲埆") + private String category; @ApiModelProperty("绉垎鍊�") @NotNull(message = "绉垎鍊间笉鑳戒负绌�") private Integer pointsValue; - @ApiModelProperty("瑙﹀彂鏉′欢") - @NotBlank(message = "瑙﹀彂鏉′欢涓嶈兘涓虹┖") - private String triggerCondition; - - @ApiModelProperty("瑙﹀彂閲戦") - private BigDecimal triggerAmount; - @ApiModelProperty("瑙勫垯鎻忚堪") - private String description; + private String ruleDescription; @ApiModelProperty("鏄惁鍚敤") private Boolean isEnabled = true; - @ApiModelProperty("浼樺厛绾�") - private Integer priority = 1; + @ApiModelProperty("姣忔棩涓婇檺") + private Integer dailyLimit; - @ApiModelProperty("鏈夋晥鏈熷紑濮嬫椂闂�") - private String validStartTime; + @ApiModelProperty("绉垎鎷ユ湁鑰�(0璐$尞鍊�1鐢ㄦ埛)") + private Integer pointsWinner; - @ApiModelProperty("鏈夋晥鏈熺粨鏉熸椂闂�") - private String validEndTime; + @ApiModelProperty("绉垎鏄惁鏈変笂闄�(0鏈�1娌℃湁)") + private Integer isLimit; + + @ApiModelProperty("鎺掑簭") + private Integer ruleOrder; + } diff --git a/src/main/java/com/webmanage/dto/PointsRuleDetailDTO.java b/src/main/java/com/webmanage/dto/PointsRuleDetailDTO.java deleted file mode 100644 index 3ba8ca5..0000000 --- a/src/main/java/com/webmanage/dto/PointsRuleDetailDTO.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.webmanage.dto; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.validation.constraints.NotNull; -import java.math.BigDecimal; -import java.time.LocalDateTime; - -/** - * 绉垎瑙勫垯璇︽儏DTO - */ -@Data -@ApiModel(value = "PointsRuleDetailDTO", description = "绉垎瑙勫垯璇︽儏") -public class PointsRuleDetailDTO { - - @ApiModelProperty("涓婚敭ID") - private Long id; - - @ApiModelProperty("鍏宠仈绉垎瑙勫垯ID") - @NotNull(message = "鍏宠仈绉垎瑙勫垯ID涓嶈兘涓虹┖") - private Long ruleId; - - @ApiModelProperty("鍏宠仈绉垎ID") - @NotNull(message = "鍏宠仈绉垎ID涓嶈兘涓虹┖") - private Long pointsId; - - @ApiModelProperty("绉垎鍊�") - @NotNull(message = "绉垎鍊间笉鑳戒负绌�") - private Integer pointsValue; - - @ApiModelProperty("姣忔棩绉垎涓婇檺鍊�") - private Integer dailyLimit; - - @ApiModelProperty("姣忔湀绉垎涓婇檺鍊�") - private Integer monthlyLimit; - - @ApiModelProperty("姣忓勾绉垎涓婇檺鍊�") - private Integer yearlyLimit; - - @ApiModelProperty("鏈�灏忓��") - private Integer minValue; - - @ApiModelProperty("鏈�澶у��") - private Integer maxValue; - - @ApiModelProperty("杞崲姣旂巼") - private BigDecimal conversionRate; - - @ApiModelProperty("鐢熸晥寮�濮嬫椂闂�") - private LocalDateTime effectiveStart; - - @ApiModelProperty("鐢熸晥缁撴潫鏃堕棿") - private LocalDateTime effectiveEnd; -} \ No newline at end of file diff --git a/src/main/java/com/webmanage/emun/RuleTypeEnum.java b/src/main/java/com/webmanage/emun/RuleTypeEnum.java index 284c77e..c933b80 100644 --- a/src/main/java/com/webmanage/emun/RuleTypeEnum.java +++ b/src/main/java/com/webmanage/emun/RuleTypeEnum.java @@ -9,16 +9,16 @@ */ public enum RuleTypeEnum { - GET(0L,"鑾峰彇"),CONSUME(1L,"娑堣垂"); - private Long code; + GET(0,"鑾峰彇"),CONSUME(1,"娑堣垂"); + private Integer code; private String name; - RuleTypeEnum(Long code, String name) { + RuleTypeEnum(Integer code, String name) { this.code = code; this.name = name; } - public Long getCode() { + public Integer getCode() { return code; } diff --git a/src/main/java/com/webmanage/entity/PointsFlow.java b/src/main/java/com/webmanage/entity/PointsFlow.java index 0066883..c10a3de 100644 --- a/src/main/java/com/webmanage/entity/PointsFlow.java +++ b/src/main/java/com/webmanage/entity/PointsFlow.java @@ -48,7 +48,7 @@ * 鏁版嵁绫诲瀷 */ @TableField("data_type") - private String dataType; + private Integer dataType; /** * 鍚嶇О/鎻忚堪 @@ -86,4 +86,10 @@ @TableLogic @TableField("deleted") private Integer deleted; + + /** + * 瑙勫垯ID + */ + @TableField("rule_id") + private Long rlueId; } diff --git a/src/main/java/com/webmanage/entity/PointsRule.java b/src/main/java/com/webmanage/entity/PointsRule.java index 11bfdf7..96c2ee7 100644 --- a/src/main/java/com/webmanage/entity/PointsRule.java +++ b/src/main/java/com/webmanage/entity/PointsRule.java @@ -28,9 +28,13 @@ @TableId(value = "id", type = IdType.AUTO) private Long id; + @ApiModelProperty("points_id") + @TableField("points_id") + private Long pointsId; + @ApiModelProperty("瑙勫垯绫诲瀷(0鑾峰緱/1娑堣垂)") @TableField("rule_type") - private Long ruleType; + private Integer ruleType; @ApiModelProperty("瑙勫垯绫诲埆") @TableField("category") @@ -40,13 +44,17 @@ @TableField("rule_name") private String ruleName; + @ApiModelProperty("瑙勫垯缂栫爜") + @TableField("rule_name_code") + private String ruleNameCode; + @ApiModelProperty("瑙勫垯鎻忚堪") @TableField("rule_description") private String ruleDescription; @ApiModelProperty("鏄惁鍚敤") @TableField("is_enabled") - private Boolean isEnabled; + private Integer isEnabled; @ApiModelProperty("鍒涘缓鏃堕棿") @TableField(value = "created_at", fill = FieldFill.INSERT) @@ -69,4 +77,17 @@ @ApiModelProperty("绉垎鏄惁鏈変笂闄�(0鏈�1娌℃湁)") @TableField("is_limit") private Integer isLimit; + + @ApiModelProperty("鎺掑簭") + @TableField("rule_order") + private Integer ruleOrder; + + @ApiModelProperty("绉垎鍊�") + @TableField("points_value") + private Integer pointsValue; + + @ApiModelProperty("姣忔棩涓婇檺") + @TableField("daily_limit") + private Integer dailyLimit; + } diff --git a/src/main/java/com/webmanage/entity/PointsRuleDetail.java b/src/main/java/com/webmanage/entity/PointsRuleDetail.java deleted file mode 100644 index 15025d9..0000000 --- a/src/main/java/com/webmanage/entity/PointsRuleDetail.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.webmanage.entity; - -import com.baomidou.mybatisplus.annotation.*; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.time.LocalDateTime; - -/** - * 绉垎瑙勫垯璇︽儏瀹炰綋 - * - * @author webmanage - * @date 2024-08-07 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@TableName("points_rule_detail") -@ApiModel(value = "PointsRuleDetail", description = "绉垎瑙勫垯璇︽儏") -public class PointsRuleDetail implements Serializable { - - private static final long serialVersionUID = 1L; - - @ApiModelProperty("涓婚敭ID") - @TableId(value = "id", type = IdType.AUTO) - private Long id; - - @ApiModelProperty("鍏宠仈绉垎瑙勫垯ID") - @TableField("rule_id") - private Long ruleId; - - @ApiModelProperty("鍏宠仈绉垎ID") - @TableField("points_id") - private Long pointsId; - - @ApiModelProperty("绉垎鍊�") - @TableField("points_value") - private Integer pointsValue; - - @ApiModelProperty("姣忔棩绉垎涓婇檺鍊�") - @TableField("daily_limit") - private Integer dailyLimit; - - @ApiModelProperty("姣忔湀绉垎涓婇檺鍊�") - @TableField("monthly_limit") - private Integer monthlyLimit; - - @ApiModelProperty("姣忓勾绉垎涓婇檺鍊�") - @TableField("yearly_limit") - private Integer yearlyLimit; - - @ApiModelProperty("鏈�灏忓��") - @TableField("min_value") - private Integer minValue; - - @ApiModelProperty("鏈�澶у��") - @TableField("max_value") - private Integer maxValue; - - @ApiModelProperty("杞崲姣旂巼") - @TableField("conversion_rate") - private BigDecimal conversionRate; - - @ApiModelProperty("鐢熸晥寮�濮嬫椂闂�") - @TableField("effective_start") - private LocalDateTime effectiveStart; - - @ApiModelProperty("鐢熸晥缁撴潫鏃堕棿") - @TableField("effective_end") - private LocalDateTime effectiveEnd; - - @ApiModelProperty("鍒涘缓鏃堕棿") - @TableField(value = "created_at", fill = FieldFill.INSERT) - private LocalDateTime createdAt; - - @ApiModelProperty("鏇存柊鏃堕棿") - @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) - private LocalDateTime updatedAt; - - @ApiModelProperty("閫昏緫鍒犻櫎") - @TableLogic - @TableField("deleted") - private Integer deleted; -} \ No newline at end of file diff --git a/src/main/java/com/webmanage/entity/PointsRuleEntity.java b/src/main/java/com/webmanage/entity/PointsRuleEntity.java deleted file mode 100644 index 6245c1d..0000000 --- a/src/main/java/com/webmanage/entity/PointsRuleEntity.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.webmanage.entity; - -import com.baomidou.mybatisplus.annotation.*; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; -import java.time.LocalDateTime; - -/** - * 绉垎瑙勫垯琛ㄥ疄浣� - * - * @author webmanage - * @date 2024-08-07 - */ -@Data -@EqualsAndHashCode(callSuper = false) -@TableName("points_rule") -@ApiModel(value = "PointsRuleEntity", description = "绉垎瑙勫垯") -public class PointsRuleEntity implements Serializable { - - private static final long serialVersionUID = 1L; - - @ApiModelProperty("涓婚敭ID") - @TableId(value = "id", type = IdType.AUTO) - private Long id; - - @ApiModelProperty("鍏宠仈绉垎ID") - @TableField("points_id") - private Long pointsId; - - @ApiModelProperty("绉垎瑙勫垯绫诲瀷") - @TableField("rule_type") - private String ruleType; - - @ApiModelProperty("绉垎绫诲埆") - @TableField("category") - private String category; - - @ApiModelProperty("瑙勫垯鍚嶇О") - @TableField("rule_name") - private String ruleName; - - @ApiModelProperty("瑙勫垯鎻忚堪") - @TableField("rule_description") - private String ruleDescription; - - @ApiModelProperty("瑙勫垯鐘舵��") - @TableField("status") - private String status; - - @ApiModelProperty("鍒涘缓鏃堕棿") - @TableField(value = "created_at", fill = FieldFill.INSERT) - private LocalDateTime createdAt; - - @ApiModelProperty("鏇存柊鏃堕棿") - @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) - private LocalDateTime updatedAt; - - @ApiModelProperty("閫昏緫鍒犻櫎") - @TableLogic - @TableField("deleted") - private Integer deleted; -} \ No newline at end of file diff --git a/src/main/java/com/webmanage/mapper/PointsFlowMapper.java b/src/main/java/com/webmanage/mapper/PointsFlowMapper.java index 71d0e43..6e30697 100644 --- a/src/main/java/com/webmanage/mapper/PointsFlowMapper.java +++ b/src/main/java/com/webmanage/mapper/PointsFlowMapper.java @@ -15,18 +15,5 @@ */ @Mapper public interface PointsFlowMapper extends BaseMapper<PointsFlow> { - - /** - * 鍒嗛〉鏌ヨ绉垎娴佹按 - */ - IPage<PointsFlow> selectPage(Page<PointsFlow> page, - @Param("userId") Long userId, - @Param("unitId") Long unitId, - @Param("dataCategory") String dataCategory, - @Param("dataType") String dataType, - @Param("startTime") String startTime, - @Param("endTime") String endTime, - @Param("year") String year, - @Param("month") String month, - @Param("day") String day); + } diff --git a/src/main/java/com/webmanage/mapper/PointsRuleDetailMapper.java b/src/main/java/com/webmanage/mapper/PointsRuleDetailMapper.java deleted file mode 100644 index 0830499..0000000 --- a/src/main/java/com/webmanage/mapper/PointsRuleDetailMapper.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.webmanage.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.webmanage.entity.PointsRuleDetail; -import org.apache.ibatis.annotations.Mapper; - -/** - * 绉垎瑙勫垯璇︽儏Mapper鎺ュ彛 - * - * @author webmanage - * @date 2024-08-07 - */ -@Mapper -public interface PointsRuleDetailMapper extends BaseMapper<PointsRuleDetail> { -} \ No newline at end of file diff --git a/src/main/java/com/webmanage/mapper/PointsRuleMapper.java b/src/main/java/com/webmanage/mapper/PointsRuleMapper.java index 22a5edf..d93e189 100644 --- a/src/main/java/com/webmanage/mapper/PointsRuleMapper.java +++ b/src/main/java/com/webmanage/mapper/PointsRuleMapper.java @@ -3,6 +3,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.webmanage.entity.PointsRule; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; /** * 绉垎瑙勫垯Mapper鎺ュ彛 @@ -12,4 +16,5 @@ */ @Mapper public interface PointsRuleMapper extends BaseMapper<PointsRule> { + } diff --git a/src/main/java/com/webmanage/service/PointsFlowService.java b/src/main/java/com/webmanage/service/PointsFlowService.java index 7ff3d0d..75c1211 100644 --- a/src/main/java/com/webmanage/service/PointsFlowService.java +++ b/src/main/java/com/webmanage/service/PointsFlowService.java @@ -5,6 +5,7 @@ import com.webmanage.dto.AddPointsFlowDTO; import com.webmanage.dto.PointsFlowQueryDTO; import com.webmanage.entity.PointsFlow; +import com.webmanage.entity.UserPoints; import java.util.List; @@ -33,11 +34,6 @@ */ List<PointsFlow> getPointsFlowByUnitId(Long unitId); - /** - * 璁板綍绉垎娴佹按 - */ - boolean recordPointsFlow(Long userId, Long unitId, String flowType, String pointsSource, - Integer pointsValue, String orderId, String description); /** * 鏂板绉垎娴佹按锛堟牴鎹鍒欒嚜鍔ㄨ绠楋級 @@ -47,10 +43,15 @@ /** * 鑾峰彇鐢ㄦ埛绉垎缁熻 */ - Integer getUserPointsTotal(Long userId); + UserPoints getUserPointsTotal(Long userId); /** * 鑾峰彇鍗曚綅绉垎缁熻 */ - Integer getUnitPointsTotal(Long unitId); + UserPoints getUnitPointsTotal(Long unitId); + + /** + * 鑾峰彇绉垎娴佹按鏁版嵁绫荤洰鍒楄〃 + */ + List<String> getPointsFlowCategories(); } diff --git a/src/main/java/com/webmanage/service/PointsRuleDetailService.java b/src/main/java/com/webmanage/service/PointsRuleDetailService.java deleted file mode 100644 index 2777f6d..0000000 --- a/src/main/java/com/webmanage/service/PointsRuleDetailService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.webmanage.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.webmanage.entity.PointsRuleDetail; - -/** - * 绉垎瑙勫垯璇︽儏Service鎺ュ彛 - */ -public interface PointsRuleDetailService extends IService<PointsRuleDetail> { - // 绉垎瑙勫垯璇︽儏鐩稿叧涓氬姟閫昏緫鏂规硶鍙湪姝ゆ坊鍔� -} \ No newline at end of file diff --git a/src/main/java/com/webmanage/service/PointsRuleService.java b/src/main/java/com/webmanage/service/PointsRuleService.java index ab3455c..8a566e5 100644 --- a/src/main/java/com/webmanage/service/PointsRuleService.java +++ b/src/main/java/com/webmanage/service/PointsRuleService.java @@ -27,7 +27,7 @@ /** * 淇敼绉垎瑙勫垯 */ - boolean updatePointsRule(PointsRuleDTO pointsRuleDTO); + boolean updatePointsRule(List<PointsRuleDTO> pointsRuleDetailsVOS); /** * 鍒犻櫎绉垎瑙勫垯 diff --git a/src/main/java/com/webmanage/service/impl/PointsFlowServiceImpl.java b/src/main/java/com/webmanage/service/impl/PointsFlowServiceImpl.java index 9188feb..8cdf5be 100644 --- a/src/main/java/com/webmanage/service/impl/PointsFlowServiceImpl.java +++ b/src/main/java/com/webmanage/service/impl/PointsFlowServiceImpl.java @@ -8,6 +8,7 @@ import com.webmanage.common.PageResult; import com.webmanage.dto.AddPointsFlowDTO; import com.webmanage.dto.PointsFlowQueryDTO; +import com.webmanage.emun.RuleTypeEnum; import com.webmanage.entity.PointsFlow; import com.webmanage.entity.PointsRule; import com.webmanage.entity.UserPoints; @@ -24,6 +25,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; +import java.util.stream.Collectors; /** * 绉垎娴佹按Service瀹炵幇绫� @@ -47,8 +49,7 @@ Page<PointsFlow> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize()); QueryWrapper<PointsFlow> wrapper = new QueryWrapper<>(); - wrapper.eq("deleted", 0) - .eq("user_id", queryDTO.getUserId()); + wrapper.eq("user_id", queryDTO.getUserId()); buildQueryWrapper(wrapper, queryDTO); @@ -72,8 +73,7 @@ Page<PointsFlow> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize()); QueryWrapper<PointsFlow> wrapper = new QueryWrapper<>(); - wrapper.eq("deleted", 0) - .eq("unit_id", queryDTO.getUnitId()); + wrapper.eq("unit_id", queryDTO.getUnitId()); buildQueryWrapper(wrapper, queryDTO); @@ -118,36 +118,6 @@ @Override @Transactional(rollbackFor = Exception.class) - public boolean recordPointsFlow(Long userId, Long unitId, String flowType, String pointsSource, - Integer pointsValue, String orderId, String description) { - if (userId == null || unitId == null || !StringUtils.hasText(flowType) || - !StringUtils.hasText(pointsSource) || pointsValue == null) { - throw new BusinessException("鍙傛暟涓嶅畬鏁�"); - } - - // 鍒涘缓绉垎娴佹按璁板綍 - PointsFlow pointsFlow = new PointsFlow(); - pointsFlow.setUserId(userId); - pointsFlow.setUnitId(unitId); - pointsFlow.setDataType(flowType); - pointsFlow.setDataCategory(pointsSource); - pointsFlow.setPoints(pointsValue); - pointsFlow.setName(description); - pointsFlow.setFlowTime(LocalDateTime.now()); - - boolean saved = save(pointsFlow); - if (!saved) { - throw new BusinessException("淇濆瓨绉垎娴佹按澶辫触"); - } - - // 鏇存柊鐢ㄦ埛绉垎 - updateUserPoints(userId, unitId, pointsValue); - - return true; - } - - @Override - @Transactional(rollbackFor = Exception.class) public boolean addPointsFlowByRule(AddPointsFlowDTO addPointsFlowDTO) { if (addPointsFlowDTO == null) { throw new BusinessException("鍙傛暟涓嶈兘涓虹┖"); @@ -155,14 +125,15 @@ Long userId = addPointsFlowDTO.getUserId(); Long unitId = addPointsFlowDTO.getUnitId(); - String ruleType = addPointsFlowDTO.getRuleType(); - String ruleName = addPointsFlowDTO.getRuleName(); + Integer ruleType = addPointsFlowDTO.getRuleType(); + String category = addPointsFlowDTO.getCategory(); + String ruleNameCode = addPointsFlowDTO.getRuleNameCode(); Integer count = addPointsFlowDTO.getCount() != null ? addPointsFlowDTO.getCount() : 1; - // 鏌ヨ绉垎瑙勫垯 - PointsRule pointsRule = pointsRuleService.getRuleByTriggerCondition(ruleName); + // 鏍规嵁ruleType銆乺uleNameCode銆乧ategory鏌ヨ鐢熸晥鏃堕棿鏈�鏂扮殑绉垎瑙勫垯 + PointsRule pointsRule = getLatestEffectiveRule(ruleType, ruleNameCode, category); if (pointsRule == null) { - throw new BusinessException("绉垎瑙勫垯涓嶅瓨鍦ㄦ垨鏈惎鐢�: " + ruleName); + throw new BusinessException("绉垎瑙勫垯涓嶅瓨鍦ㄦ垨鏈惎鐢�: ruleType=" + ruleType + ", ruleNameCode=" + ruleNameCode + ", category=" + category); } // 楠岃瘉瑙勫垯绫诲瀷鏄惁鍖归厤 @@ -171,17 +142,22 @@ } // 璁$畻绉垎鍊� - Integer basePoints = 0; //pointsRule.getPointsValue() != null ? pointsRule.getPointsValue() : 0; + Integer basePoints = pointsRule.getPointsValue() != null ? pointsRule.getPointsValue() : 0; Integer totalPoints = basePoints * count; // 濡傛灉鏄秷璐圭被鍨嬶紝绉垎涓鸿礋鏁� - if ("娑堣垂".equals(ruleType)) { + if (ruleType == RuleTypeEnum.CONSUME.getCode()) { // 1琛ㄧず娑堣垂绫诲瀷 totalPoints = -totalPoints; } // 妫�鏌ユ瘡鏃ョН鍒嗕笂闄� - if (basePoints > 0) { - checkDailyLimit(userId, unitId, ruleName, totalPoints, 0); + if (pointsRule.getIsLimit() != null && pointsRule.getIsLimit() == 0) { // 0琛ㄧず鏈夋瘡鏃ヤ笂闄� + checkDailyLimitByRule(userId, unitId, pointsRule, totalPoints); + } + + // 濡傛灉鏄墸绉垎鎿嶄綔锛屽厛妫�鏌ヤ綑棰濇槸鍚﹁冻澶� + if (totalPoints < 0) { + checkBalanceSufficient(userId, unitId, Math.abs(totalPoints)); } // 鍒涘缓绉垎娴佹按璁板綍 @@ -189,10 +165,11 @@ pointsFlow.setUserId(userId); pointsFlow.setUnitId(unitId); pointsFlow.setDataType(ruleType); - pointsFlow.setDataCategory(ruleName); + pointsFlow.setDataCategory(addPointsFlowDTO.getCategory()); pointsFlow.setPoints(totalPoints); pointsFlow.setName(addPointsFlowDTO.getDescription() != null ? addPointsFlowDTO.getDescription() : pointsRule.getRuleDescription()); pointsFlow.setFlowTime(LocalDateTime.now()); + pointsFlow.setRlueId(pointsRule.getId()); boolean saved = save(pointsFlow); if (!saved) { @@ -200,15 +177,15 @@ } // 鏇存柊鐢ㄦ埛绉垎璐︽埛 - updateUserPointsByRule(userId, unitId, totalPoints, ruleType); + updateUserPointsByRule(userId, unitId, totalPoints); return true; } @Override - public Integer getUserPointsTotal(Long userId) { + public UserPoints getUserPointsTotal(Long userId) { if (userId == null) { - return 0; + throw new BusinessException("鐢ㄦ埛ID涓嶈兘涓簄ull"); } QueryWrapper<UserPoints> wrapper = new QueryWrapper<>(); @@ -216,13 +193,13 @@ .eq("user_id", userId); UserPoints userPoints = userPointsMapper.selectOne(wrapper); - return userPoints != null ? userPoints.getBalance() : 0; + return userPoints ; } @Override - public Integer getUnitPointsTotal(Long unitId) { + public UserPoints getUnitPointsTotal(Long unitId) { if (unitId == null) { - return 0; + throw new BusinessException("鐢ㄦ埛ID涓嶈兘涓簄ull"); } QueryWrapper<UserPoints> wrapper = new QueryWrapper<>(); @@ -230,15 +207,37 @@ .eq("unit_id", unitId); UserPoints userPoints = userPointsMapper.selectOne(wrapper); - return userPoints != null ? userPoints.getBalance() : 0; + return userPoints; + } + + @Override + public List<String> getPointsFlowCategories() { + QueryWrapper<PointsFlow> wrapper = new QueryWrapper<>(); + wrapper.select("DISTINCT data_category") + .isNotNull("data_category") + .ne("data_category", "") + .ne("data_category", "null") + .eq("deleted", 0) + .orderByAsc("data_category"); + + List<PointsFlow> flows = list(wrapper); + return flows.stream() + .map(PointsFlow::getDataCategory) + .filter(category -> category != null && !category.trim().isEmpty()) + .distinct() + .sorted() + .collect(Collectors.toList()); } /** * 鏋勫缓鏌ヨ鏉′欢 */ private void buildQueryWrapper(QueryWrapper<PointsFlow> wrapper, PointsFlowQueryDTO queryDTO) { - if (StringUtils.hasText(queryDTO.getFlowType())) { - wrapper.eq("flow_type", queryDTO.getFlowType()); + if(StringUtils.hasText(queryDTO.getDataCategory())){ + wrapper.eq("data_category", queryDTO.getDataCategory()); + } + if (queryDTO.getDataType()!=null) { + wrapper.eq("data_type", queryDTO.getDataType()); } if (StringUtils.hasText(queryDTO.getPointsSource())) { wrapper.eq("points_source", queryDTO.getPointsSource()); @@ -246,18 +245,100 @@ if (StringUtils.hasText(queryDTO.getOrderId())) { wrapper.eq("order_id", queryDTO.getOrderId()); } - if (queryDTO.getStartTime() != null) { - wrapper.ge("flow_time", queryDTO.getStartTime()); + if (queryDTO.getFlowEndTime() != null) { + wrapper.ge("flow_time", queryDTO.getFlowStartTime()); } - if (queryDTO.getEndTime() != null) { - wrapper.le("flow_time", queryDTO.getEndTime()); + if (queryDTO.getFlowEndTime() != null) { + wrapper.le("flow_time", queryDTO.getFlowEndTime()); } wrapper.orderByDesc("flow_time"); } /** - * 妫�鏌ユ瘡鏃ョН鍒嗕笂闄� + * 鏍规嵁ruleType銆乺uleNameCode銆乧ategory鏌ヨ鐢熸晥鏃堕棿鏈�鏂扮殑绉垎瑙勫垯 + */ + private PointsRule getLatestEffectiveRule(Integer ruleType, String ruleNameCode, String category) { + QueryWrapper<PointsRule> wrapper = new QueryWrapper<>(); + wrapper.eq("deleted", 0) + .eq("is_enabled", 0) // 0琛ㄧず鍚敤 + .eq("rule_type", ruleType) + .eq("rule_name_code", ruleNameCode) + .eq("category", category) + .orderByDesc("created_at") // 鎸夊垱寤烘椂闂村�掑簭锛岃幏鍙栨渶鏂扮殑瑙勫垯 + .last("LIMIT 1"); + + return pointsRuleService.getOne(wrapper); + } + + /** + * 妫�鏌ユ瘡鏃ョН鍒嗕笂闄愶紙鍩轰簬瑙勫垯锛� + */ + private void checkDailyLimitByRule(Long userId, Long unitId, PointsRule pointsRule, Integer currentPoints) { + // 鑾峰彇浠婃棩寮�濮嬪拰缁撴潫鏃堕棿 + LocalDate today = LocalDate.now(); + LocalDateTime startOfDay = today.atStartOfDay(); + LocalDateTime endOfDay = today.atTime(23, 59, 59); + + // 鏌ヨ浠婃棩璇ヨ鍒欑殑绉垎娴佹按 + QueryWrapper<PointsFlow> wrapper = new QueryWrapper<>(); + wrapper.eq("deleted", 0) + .eq("user_id", userId) + .eq("unit_id", unitId) +// .eq("data_category", pointsRule.getRuleName()) + .eq("rule_id",pointsRule.getId()) + .ge("flow_time", startOfDay) + .le("flow_time", endOfDay); + + List<PointsFlow> todayFlows = list(wrapper); + + // 璁$畻浠婃棩绱绉垎 + int todayTotal = todayFlows.stream() + .mapToInt(flow -> flow.getPoints() != null ? flow.getPoints() : 0) + .sum(); + + // 鑾峰彇瑙勫垯鐨勬瘡鏃ョН鍒嗕笂闄� + Integer dailyLimit = pointsRule.getDailyLimit(); + if (dailyLimit != null && dailyLimit > 0) { + // 濡傛灉浠婃棩绱绉垎瓒呰繃姣忔棩涓婇檺锛屽垯鎶涘嚭寮傚父 + if (Math.abs(todayTotal) >= dailyLimit) { + throw new BusinessException("浠婃棩璇ヨ鍒欑Н鍒嗗凡杈句笂闄�: " + dailyLimit); + } + + // 濡傛灉鍔犱笂褰撳墠绉垎浼氳秴杩囨瘡鏃ヤ笂闄愶紝鍒欐姏鍑哄紓甯� + if (Math.abs(todayTotal + currentPoints) > dailyLimit) { + throw new BusinessException("鏈绉垎鎿嶄綔灏嗚秴杩囨瘡鏃ヤ笂闄�: " + dailyLimit + "锛屽綋鍓嶅凡绱: " + Math.abs(todayTotal)); + } + } + } + + /** + * 妫�鏌ョН鍒嗕綑棰濇槸鍚﹁冻澶� + */ + private void checkBalanceSufficient(Long userId, Long unitId, Integer requiredPoints) { + // 妫�鏌ヤ釜浜虹Н鍒嗕綑棰� + QueryWrapper<UserPoints> userWrapper = new QueryWrapper<>(); + userWrapper.eq("deleted", 0) + .eq("user_id", userId); + + UserPoints userPoints = userPointsMapper.selectOne(userWrapper); + if (userPoints == null || userPoints.getBalance() < requiredPoints) { + throw new BusinessException("涓汉绉垎浣欓涓嶈冻锛屽綋鍓嶄綑棰�: " + (userPoints != null ? userPoints.getBalance() : 0) + "锛岄渶瑕佹墸闄�: " + requiredPoints); + } + + // 妫�鏌ュ崟浣嶇Н鍒嗕綑棰� + QueryWrapper<UserPoints> unitWrapper = new QueryWrapper<>(); + unitWrapper.eq("deleted", 0) + .eq("unit_id", unitId); + + UserPoints unitPoints = userPointsMapper.selectOne(unitWrapper); + if (unitPoints == null || unitPoints.getBalance() < requiredPoints) { + throw new BusinessException("鍗曚綅绉垎浣欓涓嶈冻锛屽綋鍓嶄綑棰�: " + (unitPoints != null ? unitPoints.getBalance() : 0) + "锛岄渶瑕佹墸闄�: " + requiredPoints); + } + } + + /** + * 妫�鏌ユ瘡鏃ョН鍒嗕笂闄愶紙鏃ф柟娉曪紝淇濈暀鍏煎鎬э級 */ private void checkDailyLimit(Long userId, Long unitId, String ruleName, Integer currentPoints, Integer priority) { // 鑾峰彇浠婃棩寮�濮嬪拰缁撴潫鏃堕棿 @@ -331,7 +412,7 @@ /** * 鏍规嵁瑙勫垯鏇存柊鐢ㄦ埛绉垎璐︽埛 */ - private void updateUserPointsByRule(Long userId, Long unitId, Integer pointsValue, String ruleType) { + private void updateUserPointsByRule(Long userId, Long unitId, Integer pointsValue) { // 鏇存柊涓汉绉垎璐︽埛 QueryWrapper<UserPoints> userWrapper = new QueryWrapper<>(); userWrapper.eq("deleted", 0) @@ -339,6 +420,11 @@ UserPoints userPoints = userPointsMapper.selectOne(userWrapper); if (userPoints == null) { + // 濡傛灉鏄柊鐢ㄦ埛涓旀槸鎵gН鍒嗘搷浣滐紝浣欓涓嶈冻 + if (pointsValue < 0) { + throw new BusinessException("绉垎浣欓涓嶈冻锛屾棤娉曟墸闄ょН鍒�"); + } + userPoints = new UserPoints(); userPoints.setUserId(userId); userPoints.setUnitId(unitId); @@ -347,6 +433,11 @@ userPoints.setTotalConsumed(pointsValue < 0 ? Math.abs(pointsValue) : 0); userPointsMapper.insert(userPoints); } else { + // 妫�鏌ユ墸绉垎鏃朵綑棰濇槸鍚﹁冻澶� + if (pointsValue < 0 && userPoints.getBalance() + pointsValue < 0) { + throw new BusinessException("绉垎浣欓涓嶈冻锛屽綋鍓嶄綑棰�: " + userPoints.getBalance() + "锛岄渶瑕佹墸闄�: " + Math.abs(pointsValue)); + } + userPoints.setBalance(userPoints.getBalance() + pointsValue); // 鏇存柊绱鑾峰彇绉垎 @@ -372,6 +463,11 @@ UserPoints unitPoints = userPointsMapper.selectOne(unitWrapper); if (unitPoints == null) { + // 濡傛灉鏄柊鍗曚綅涓旀槸鎵gН鍒嗘搷浣滐紝浣欓涓嶈冻 + if (pointsValue < 0) { + throw new BusinessException("鍗曚綅绉垎浣欓涓嶈冻锛屾棤娉曟墸闄ょН鍒�"); + } + unitPoints = new UserPoints(); unitPoints.setUserId(userId); unitPoints.setUnitId(unitId); @@ -380,6 +476,11 @@ unitPoints.setTotalConsumed(pointsValue < 0 ? Math.abs(pointsValue) : 0); userPointsMapper.insert(unitPoints); } else { + // 妫�鏌ユ墸绉垎鏃朵綑棰濇槸鍚﹁冻澶� + if (pointsValue < 0 && unitPoints.getBalance() + pointsValue < 0) { + throw new BusinessException("鍗曚綅绉垎浣欓涓嶈冻锛屽綋鍓嶄綑棰�: " + unitPoints.getBalance() + "锛岄渶瑕佹墸闄�: " + Math.abs(pointsValue)); + } + unitPoints.setBalance(unitPoints.getBalance() + pointsValue); // 鏇存柊绱鑾峰彇绉垎 diff --git a/src/main/java/com/webmanage/service/impl/PointsRuleDetailServiceImpl.java b/src/main/java/com/webmanage/service/impl/PointsRuleDetailServiceImpl.java deleted file mode 100644 index 657f145..0000000 --- a/src/main/java/com/webmanage/service/impl/PointsRuleDetailServiceImpl.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.webmanage.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.webmanage.entity.PointsRuleDetail; -import com.webmanage.mapper.PointsRuleDetailMapper; -import com.webmanage.service.PointsRuleDetailService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -/** - * 绉垎瑙勫垯璇︽儏Service瀹炵幇绫� - */ -@Slf4j -@Service -public class PointsRuleDetailServiceImpl extends ServiceImpl<PointsRuleDetailMapper, PointsRuleDetail> implements PointsRuleDetailService { - // 绉垎瑙勫垯璇︽儏鐩稿叧涓氬姟閫昏緫瀹炵幇鍙湪姝ゆ坊鍔� -} \ No newline at end of file diff --git a/src/main/java/com/webmanage/service/impl/PointsRuleServiceImpl.java b/src/main/java/com/webmanage/service/impl/PointsRuleServiceImpl.java index 05d9e37..1512773 100644 --- a/src/main/java/com/webmanage/service/impl/PointsRuleServiceImpl.java +++ b/src/main/java/com/webmanage/service/impl/PointsRuleServiceImpl.java @@ -5,24 +5,30 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.webmanage.common.BusinessException; import com.webmanage.dto.PointsRuleDTO; + import com.webmanage.emun.RuleTypeEnum; import com.webmanage.entity.Points; import com.webmanage.entity.PointsRule; -import com.webmanage.entity.PointsRuleDetail; import com.webmanage.mapper.PointsRuleMapper; import com.webmanage.service.PointsRuleService; import com.webmanage.service.PointsService; -import com.webmanage.service.PointsRuleDetailService; + import com.webmanage.vo.PointsRuleResultVO; import com.webmanage.vo.PointsRuleVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import java.beans.Transient; +import java.text.DateFormat; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -36,9 +42,7 @@ @Autowired private PointsService pointsService; - - @Autowired - private PointsRuleDetailService pointsRuleDetailService; + @Override public PointsRuleResultVO getPointsRuleList(Long ruleId) { @@ -46,7 +50,7 @@ QueryWrapper<PointsRule> wrapper = new QueryWrapper<>(); wrapper.eq("deleted", 0).eq("is_enabled",0); - + if(ruleId != null){ wrapper.eq("points_id", ruleId); } @@ -54,7 +58,7 @@ List<PointsRule> list = list(wrapper); PointsRuleResultVO pointsRuleResultVO = new PointsRuleResultVO(); if (!CollectionUtil.isEmpty(list)) { - Map<Long, List<PointsRule>> collect = list.stream().collect(Collectors.groupingBy(PointsRule::getRuleType)); + Map<Integer, List<PointsRule>> collect = list.stream().collect(Collectors.groupingBy(PointsRule::getRuleType)); Map<String, List<PointsRule>> getRules = collect.get(RuleTypeEnum.GET.getCode()).stream().collect(Collectors.groupingBy(PointsRule::getCategory)); Map<String, List<PointsRule>> consumeRules = collect.get(RuleTypeEnum.CONSUME.getCode()).stream().collect(Collectors.groupingBy(PointsRule::getCategory)); @@ -62,6 +66,7 @@ List<PointsRuleVO> consumePointsRuleVOList = new ArrayList<>(); getRules.forEach((k,v)->{ PointsRuleVO pointsRuleVO = new PointsRuleVO(); + pointsRuleVO.setRlueSort(v.get(0).getRuleOrder()); pointsRuleVO.setCategory(k); pointsRuleVO.setPointsRules(v); getPointsRuleVOList.add(pointsRuleVO); @@ -69,11 +74,14 @@ }); consumeRules.forEach((k,v)->{ PointsRuleVO pointsRuleVO = new PointsRuleVO(); + pointsRuleVO.setRlueSort(v.get(0).getRuleOrder()); pointsRuleVO.setCategory(k); pointsRuleVO.setPointsRules(v); consumePointsRuleVOList.add(pointsRuleVO); }); + getPointsRuleVOList.sort(Comparator.comparing(PointsRuleVO::getRlueSort)); + consumePointsRuleVOList.sort(Comparator.comparing(PointsRuleVO::getRlueSort)); pointsRuleResultVO.setGetPointsRuleList(getPointsRuleVOList); pointsRuleResultVO.setConsumePointsRuleList(consumePointsRuleVOList); } @@ -99,48 +107,42 @@ } @Override - public boolean updatePointsRule(PointsRuleDTO pointsRuleDTO) { - if (pointsRuleDTO.getId() == null) { - throw new BusinessException("瑙勫垯ID涓嶈兘涓虹┖"); + @Transactional(rollbackFor = Exception.class) + public boolean updatePointsRule(List<PointsRuleDTO> pointsRuleDTO) { + if (CollectionUtils.isEmpty(pointsRuleDTO)){ + return false; } - - PointsRule existingRule = getById(pointsRuleDTO.getId()); - if (existingRule == null) { - throw new BusinessException("绉垎瑙勫垯涓嶅瓨鍦�"); - } - - // 楠岃瘉瑙勫垯鍚嶇О鏄惁閲嶅锛堟帓闄よ嚜韬級 - QueryWrapper<PointsRule> wrapper = new QueryWrapper<>(); - wrapper.eq("rule_name", pointsRuleDTO.getRuleName()) - .eq("deleted", 0) - .ne("id", pointsRuleDTO.getId()); - - if (count(wrapper) > 0) { - throw new BusinessException("瑙勫垯鍚嶇О宸插瓨鍦�"); - } - + + // 鏌ヨ瑙勫垯鍚嶇О + Points pointsOld = pointsService.query().eq("id", pointsRuleDTO.get(0).getPointsId()) + .eq("deleted", 0).one(); + // 鏌ヨ褰撳ぉ鏄惁鏈夌増鏈洿鏂拌褰� + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("YYYY-MM-DD HH:mm:ss"); + LocalDateTime nowDatetime = LocalDateTime.now(); + LocalDateTime localDateTimeStart = nowDatetime.toLocalDate().atStartOfDay(); + LocalDateTime localDateTimeEnd = nowDatetime.toLocalDate().atStartOfDay(); + // dateTimeFormatter.format(localDateTimeStart), dateTimeFormatter.format(localDateTimeEnd) + Long counts = pointsService.query().between("created_at", localDateTimeStart, localDateTimeEnd).count(); // 鍒涘缓鏂扮殑绉垎涓昏〃璁板綍 Points points = new Points(); - points.setPointsName(pointsRuleDTO.getRuleName() + "_" + System.currentTimeMillis()); + points.setPointsName(pointsOld.getPointsName()); points.setEffectiveStart(LocalDateTime.now()); - points.setModifierId(1L); // 杩欓噷搴旇浠庝笂涓嬫枃涓幏鍙栧綋鍓嶇敤鎴稩D + points.setModifierId(pointsOld.getModifierId()); // 杩欓噷搴旇浠庝笂涓嬫枃涓幏鍙栧綋鍓嶇敤鎴稩D points.setModifierName("admin"); // 杩欓噷搴旇浠庝笂涓嬫枃涓幏鍙栧綋鍓嶇敤鎴峰悕 - points.setVersion(1.0f); + points.setVersion(counts>0 ? pointsOld.getVersion() + 0.1f: 1.0f); points.setStatus(0); pointsService.save(points); - // 鍒涘缓绉垎瑙勫垯璇︽儏璁板綍 - PointsRuleDetail pointsRuleDetail = new PointsRuleDetail(); - pointsRuleDetail.setRuleId(pointsRuleDTO.getId()); - pointsRuleDetail.setPointsId(points.getId()); - pointsRuleDetail.setPointsValue(pointsRuleDTO.getPointsValue()); - pointsRuleDetail.setEffectiveStart(LocalDateTime.now()); - pointsRuleDetailService.save(pointsRuleDetail); - - BeanUtils.copyProperties(pointsRuleDTO, existingRule); - existingRule.setUpdatedAt(LocalDateTime.now()); - - return updateById(existingRule); + // 鍒涘缓绉垎瑙勫垯璁板綍 + for (PointsRuleDTO ruleDTO : pointsRuleDTO) { + PointsRule pointsRule = new PointsRule(); + BeanUtils.copyProperties(ruleDTO,pointsRule); + pointsRule.setPointsId(points.getId()); + pointsRule.setUpdatedAt(LocalDateTime.now()); + save(pointsRule); + } + + return true; } @Override @@ -168,7 +170,7 @@ throw new BusinessException("绉垎瑙勫垯涓嶅瓨鍦�"); } - pointsRule.setIsEnabled(isEnabled); + pointsRule.setIsEnabled(isEnabled ? 0: 1); pointsRule.setUpdatedAt(LocalDateTime.now()); return updateById(pointsRule); diff --git a/src/main/java/com/webmanage/vo/PointsRuleVO.java b/src/main/java/com/webmanage/vo/PointsRuleVO.java new file mode 100644 index 0000000..54233cb --- /dev/null +++ b/src/main/java/com/webmanage/vo/PointsRuleVO.java @@ -0,0 +1,20 @@ +package com.webmanage.vo; + +import com.webmanage.entity.PointsRule; +import lombok.Data; + +import java.util.List; + +/** + * @ClassName PointsRuleVO + * @Description TODO + * @Author wangxudong + * @Date 2025/8/14 21:05 + * @Version 1.0 + **/ +@Data +public class PointsRuleVO { + private String category; + List<PointsRule> pointsRules; + private Integer rlueSort; +} diff --git a/src/main/resources/mapper/PointsFlowMapper.xml b/src/main/resources/mapper/PointsFlowMapper.xml deleted file mode 100644 index 9f25c8b..0000000 --- a/src/main/resources/mapper/PointsFlowMapper.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="com.webmanage.mapper.PointsFlowMapper"> - - <!-- 鍒嗛〉鏌ヨ绉垎娴佹按锛堟敮鎸佺敤鎴�/鍗曚綅缁村害杩囨护锛� --> - <select id="selectPage" resultType="com.webmanage.entity.PointsFlow"> - SELECT * - FROM points_flow - WHERE deleted = 0 - <if test="userId != null"> - AND user_id = #{userId} - </if> - <if test="unitId != null"> - AND unit_id = #{unitId} - </if> - <if test="dataCategory != null and dataCategory != ''"> - AND data_category = #{dataCategory} - </if> - <if test="dataType != null and dataType != ''"> - AND data_type = #{dataType} - </if> - <if test="startTime != null and startTime != ''"> - AND flow_time >= #{startTime}::timestamp - </if> - <if test="endTime != null and endTime != ''"> - AND flow_time <= #{endTime}::timestamp - </if> - <if test="year != null and year != ''"> - AND EXTRACT(YEAR FROM flow_time) = #{year}::integer - </if> - <if test="month != null and month != ''"> - AND EXTRACT(MONTH FROM flow_time) = #{month}::integer - </if> - <if test="day != null and day != ''"> - AND EXTRACT(DAY FROM flow_time) = #{day}::integer - </if> - ORDER BY flow_time DESC - </select> - -</mapper> -- Gitblit v1.8.0