From 85a8d17194c7d91277797b8d3532cdd56595867e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Thu, 5 Feb 2026 14:33:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop):=20=E6=9B=B4=E6=96=B0=E5=88=86?= =?UTF-8?q?=E9=94=80=E5=95=86=E8=AE=BE=E7=BD=AE=E8=A1=A8=E7=9A=84=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 ShopDealerSettingSaveParam 参数类用于保存和修改操作 - 修改 save 方法使用新的参数类并实现实体构建逻辑 - 更新 update 方法使用 LambdaQueryWrapper 进行精确更新 - 添加 buildEntity 方法用于将参数转换为实体对象 - 实现 normalizeUpdateTime 方法处理时间戳溢出问题 - 添加租户ID默认值获取逻辑 - 增强更新操作的数据验证和错误处理机制 --- .../ShopDealerSettingController.java | 44 +++++++++++++++++-- .../param/ShopDealerSettingSaveParam.java | 35 +++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/gxwebsoft/shop/param/ShopDealerSettingSaveParam.java diff --git a/src/main/java/com/gxwebsoft/shop/controller/ShopDealerSettingController.java b/src/main/java/com/gxwebsoft/shop/controller/ShopDealerSettingController.java index 039cf2c..e067ae8 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/ShopDealerSettingController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/ShopDealerSettingController.java @@ -4,6 +4,7 @@ import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.shop.service.ShopDealerSettingService; import com.gxwebsoft.shop.entity.ShopDealerSetting; import com.gxwebsoft.shop.param.ShopDealerSettingParam; +import com.gxwebsoft.shop.param.ShopDealerSettingSaveParam; import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageParam; @@ -12,6 +13,7 @@ import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.system.entity.User; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -59,7 +61,8 @@ public class ShopDealerSettingController extends BaseController { @OperationLog @Operation(summary = "添加分销商设置表") @PostMapping() - public ApiResult save(@RequestBody ShopDealerSetting shopDealerSetting) { + public ApiResult save(@RequestBody ShopDealerSettingSaveParam param) { + ShopDealerSetting shopDealerSetting = buildEntity(param); if (shopDealerSettingService.save(shopDealerSetting)) { return success("添加成功"); } @@ -70,13 +73,48 @@ public class ShopDealerSettingController extends BaseController { @OperationLog @Operation(summary = "修改分销商设置表") @PutMapping() - public ApiResult update(@RequestBody ShopDealerSetting shopDealerSetting) { - if (shopDealerSettingService.updateById(shopDealerSetting)) { + public ApiResult update(@RequestBody ShopDealerSettingSaveParam param) { + ShopDealerSetting shopDealerSetting = buildEntity(param); + if (shopDealerSetting.getKey() == null || shopDealerSetting.getTenantId() == null) { + return fail("修改失败"); + } + boolean updated = shopDealerSettingService.update( + shopDealerSetting, + new LambdaQueryWrapper() + .eq(ShopDealerSetting::getKey, shopDealerSetting.getKey()) + .eq(ShopDealerSetting::getTenantId, shopDealerSetting.getTenantId()) + ); + if (updated) { return success("修改成功"); } return fail("修改失败"); } + private ShopDealerSetting buildEntity(ShopDealerSettingSaveParam param) { + ShopDealerSetting shopDealerSetting = new ShopDealerSetting(); + shopDealerSetting.setKey(param.getKey()); + shopDealerSetting.setDescribe(param.getDescribe()); + shopDealerSetting.setValues(param.getValues()); + Integer tenantId = param.getTenantId(); + if (tenantId == null) { + tenantId = getTenantId(); + } + shopDealerSetting.setTenantId(tenantId); + shopDealerSetting.setUpdateTime(normalizeUpdateTime(param.getUpdateTime())); + return shopDealerSetting; + } + + private Integer normalizeUpdateTime(Long updateTime) { + long value = updateTime != null ? updateTime : System.currentTimeMillis(); + if (value > Integer.MAX_VALUE) { + value = value / 1000; + } + if (value > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } + return (int) value; + } + @PreAuthorize("hasAuthority('shop:shopDealerSetting:remove')") @OperationLog @Operation(summary = "删除分销商设置表") diff --git a/src/main/java/com/gxwebsoft/shop/param/ShopDealerSettingSaveParam.java b/src/main/java/com/gxwebsoft/shop/param/ShopDealerSettingSaveParam.java new file mode 100644 index 0000000..6136aa4 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/param/ShopDealerSettingSaveParam.java @@ -0,0 +1,35 @@ +package com.gxwebsoft.shop.param; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** + * Shop dealer setting save parameters. + * + * @author WebSoft + * @since 2025-08-11 23:51:41 + */ +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +@Schema(name = "ShopDealerSettingSaveParam", description = "Shop dealer setting save parameters") +public class ShopDealerSettingSaveParam implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "Setting key") + private String key; + + @Schema(description = "Setting description") + private String describe; + + @Schema(description = "Settings JSON content") + private String values; + + @Schema(description = "Tenant ID") + private Integer tenantId; + + @Schema(description = "Update time") + private Long updateTime; +}