feat(shop): 修改经销商设置实体ID生成策略并优化保存更新逻辑
- 将ShopDealerSetting实体的@TableId注解type从AUTO改为INPUT - 新增saveOrUpdateByKey方法统一处理保存和更新操作 - 移除LambdaQueryWrapper手动构建的更新逻辑 - 简化控制器中的保存和更新接口实现 - 优化多租户场景下的数据操作逻辑
This commit is contained in:
@@ -13,7 +13,6 @@ 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.*;
|
||||
|
||||
@@ -63,10 +62,10 @@ public class ShopDealerSettingController extends BaseController {
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody ShopDealerSettingSaveParam param) {
|
||||
ShopDealerSetting shopDealerSetting = buildEntity(param);
|
||||
if (shopDealerSettingService.save(shopDealerSetting)) {
|
||||
return success("添加成功");
|
||||
if (shopDealerSettingService.saveOrUpdateByKey(shopDealerSetting)) {
|
||||
return success("保存成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
return fail("保存失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:shopDealerSetting:update')")
|
||||
@@ -75,16 +74,10 @@ public class ShopDealerSettingController extends BaseController {
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody ShopDealerSettingSaveParam param) {
|
||||
ShopDealerSetting shopDealerSetting = buildEntity(param);
|
||||
if (shopDealerSetting.getKey() == null || shopDealerSetting.getTenantId() == null) {
|
||||
if (shopDealerSetting.getKey() == null) {
|
||||
return fail("修改失败");
|
||||
}
|
||||
boolean updated = shopDealerSettingService.update(
|
||||
shopDealerSetting,
|
||||
new LambdaQueryWrapper<ShopDealerSetting>()
|
||||
.eq(ShopDealerSetting::getKey, shopDealerSetting.getKey())
|
||||
.eq(ShopDealerSetting::getTenantId, shopDealerSetting.getTenantId())
|
||||
);
|
||||
if (updated) {
|
||||
if (shopDealerSettingService.saveOrUpdateByKey(shopDealerSetting)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ShopDealerSetting implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "设置项标示")
|
||||
@TableId(value = "key", type = IdType.AUTO)
|
||||
@TableId(value = "key", type = IdType.INPUT)
|
||||
private String key;
|
||||
|
||||
@Schema(description = "设置项描述")
|
||||
|
||||
@@ -39,4 +39,12 @@ public interface ShopDealerSettingService extends IService<ShopDealerSetting> {
|
||||
*/
|
||||
ShopDealerSetting getByIdRel(String key);
|
||||
|
||||
/**
|
||||
* 根据 key + tenantId 保存或更新
|
||||
*
|
||||
* @param setting 设置项
|
||||
* @return boolean
|
||||
*/
|
||||
boolean saveOrUpdateByKey(ShopDealerSetting setting);
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.gxwebsoft.shop.entity.ShopDealerSetting;
|
||||
import com.gxwebsoft.shop.param.ShopDealerSettingParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -44,4 +45,17 @@ public class ShopDealerSettingServiceImpl extends ServiceImpl<ShopDealerSettingM
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveOrUpdateByKey(ShopDealerSetting setting) {
|
||||
if (setting == null || setting.getKey() == null) {
|
||||
return false;
|
||||
}
|
||||
LambdaQueryWrapper<ShopDealerSetting> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ShopDealerSetting::getKey, setting.getKey());
|
||||
if (setting.getTenantId() != null) {
|
||||
wrapper.eq(ShopDealerSetting::getTenantId, setting.getTenantId());
|
||||
}
|
||||
return this.saveOrUpdate(setting, wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user