refactor(asset): 优化保养项目设计,使用折中方案
变更内容: 1. 删除 maintainItemId 字段(冗余,无实际作用) 2. 保留 maintainItem 字段(直接存储项目名称) 3. 新增接口:获取已使用的保养项目列表(去重) 4. 前端可使用该接口提供下拉提示,提升用户体验 5. 添加 maintainItem 字段的非空校验 设计思路: - 不引入保养项目字典表(避免过度设计) - 通过 DISTINCT 查询提供已使用项目列表 - 用户可以输入新项目,也可以从已有项目中选择 - 后续如需规范化,可平滑升级到字典表方案
This commit is contained in:
@@ -104,4 +104,11 @@ public class VehicleModelController {
|
||||
return success(BeanUtils.toBean(list, VehicleModelRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/maintain-item/used-list")
|
||||
@Operation(summary = "获取已使用的保养项目列表", description = "用于前端下拉提示,返回去重后的保养项目名称")
|
||||
public CommonResult<List<String>> getUsedMaintainItems() {
|
||||
List<String> list = vehicleModelService.getUsedMaintainItems();
|
||||
return success(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
@@ -19,10 +20,8 @@ public class VehicleModelMaintainItemVO {
|
||||
@Schema(description = "主键", example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "维保项目ID", example = "1")
|
||||
private Long maintainItemId;
|
||||
|
||||
@Schema(description = "保养项目", example = "更换机油")
|
||||
@Schema(description = "保养项目", requiredMode = Schema.RequiredMode.REQUIRED, example = "机油更换")
|
||||
@NotBlank(message = "保养项目不能为空")
|
||||
private String maintainItem;
|
||||
|
||||
@Schema(description = "保养内容", example = "更换机油、机滤")
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 车型维保项目关联 DO
|
||||
* 车型维保项目 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@@ -35,12 +35,7 @@ public class VehicleModelMaintainItemDO extends BaseDO {
|
||||
private Long vehicleModelId;
|
||||
|
||||
/**
|
||||
* 维保项目ID
|
||||
*/
|
||||
private Long maintainItemId;
|
||||
|
||||
/**
|
||||
* 保养项目
|
||||
* 保养项目名称
|
||||
*/
|
||||
private String maintainItem;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.asset.dal.mysql.vehiclemodel;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.asset.dal.dataobject.vehiclemodel.VehicleModelMaintainItemDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,4 +23,10 @@ public interface VehicleModelMaintainItemMapper extends BaseMapperX<VehicleModel
|
||||
delete(VehicleModelMaintainItemDO::getVehicleModelId, vehicleModelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有已使用的保养项目名称(去重)
|
||||
*/
|
||||
@Select("SELECT DISTINCT maintain_item FROM asset_vehicle_model_maintain_item WHERE deleted = 0 AND maintain_item IS NOT NULL AND maintain_item != '' ORDER BY maintain_item")
|
||||
List<String> selectDistinctMaintainItems();
|
||||
|
||||
}
|
||||
|
||||
@@ -85,4 +85,11 @@ public interface VehicleModelService {
|
||||
*/
|
||||
List<VehicleModelMaintainItemDO> getVehicleModelMaintainItems(Long vehicleModelId);
|
||||
|
||||
/**
|
||||
* 获取已使用的保养项目列表(去重)
|
||||
*
|
||||
* @return 保养项目名称列表
|
||||
*/
|
||||
List<String> getUsedMaintainItems();
|
||||
|
||||
}
|
||||
|
||||
@@ -114,6 +114,11 @@ public class VehicleModelServiceImpl implements VehicleModelService {
|
||||
return vehicleModelMaintainItemMapper.selectListByVehicleModelId(vehicleModelId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsedMaintainItems() {
|
||||
return vehicleModelMaintainItemMapper.selectDistinctMaintainItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存维保项目
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user