feat(shop): 更新分销商设置表的保存和修改功能
- 添加 ShopDealerSettingSaveParam 参数类用于保存和修改操作 - 修改 save 方法使用新的参数类并实现实体构建逻辑 - 更新 update 方法使用 LambdaQueryWrapper 进行精确更新 - 添加 buildEntity 方法用于将参数转换为实体对象 - 实现 normalizeUpdateTime 方法处理时间戳溢出问题 - 添加租户ID默认值获取逻辑 - 增强更新操作的数据验证和错误处理机制
This commit is contained in:
@@ -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<ShopDealerSetting>()
|
||||
.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 = "删除分销商设置表")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user