品牌型号选择器

This commit is contained in:
“hhk” 2024-08-07 18:01:16 +08:00
parent b58f2a9d67
commit 03db497bfe
10 changed files with 210 additions and 13 deletions

View File

@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.custom.controller.admin;
import cn.iocoder.yudao.module.custom.entity.CarModel;
import cn.iocoder.yudao.module.custom.service.CarModelService;
import cn.iocoder.yudao.module.custom.vo.CarMainRespVO;
import cn.iocoder.yudao.module.custom.vo.CarModelReqVO;
import cn.iocoder.yudao.module.custom.vo.CarModelRespVO;
import cn.iocoder.yudao.module.custom.vo.*;
import cn.iocoder.yudao.module.custom.vo.CarModelReqVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
@ -137,8 +135,7 @@ public class CarModelController {
@GetMapping("/export-excel")
@Operation(summary = "导出车辆品牌型号 Excel")
@PreAuthorize("@ss.hasPermission('base:car-model:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportCarModelExcel(CarModelReqVO pageReqVO,
public void searchBrand(CarModelReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<CarModelRespVO> list = carModelService.getCarModelPage(pageReqVO).getRecords();
@ -146,4 +143,19 @@ public class CarModelController {
ExcelUtils.write(response, "车辆品牌型号.xls", "数据", CarModelRespVO.class, list);
}
/**
* 筛选品牌型号
*
* @param reqVO
* @return
*/
@PostMapping("/searchBrand")
@Operation(summary = "筛选品牌型号")
@PreAuthorize("@ss.hasPermission('base:car-main:query')")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<List<CascaderOptionsVO>> searchBrand(@RequestBody CarModelReqVO reqVO) {
List<CascaderOptionsVO> result = carModelService.searchBrand(reqVO);
return success(result);
}
}

View File

@ -3,15 +3,15 @@ package cn.iocoder.yudao.module.custom.mapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.custom.entity.CarBrand;
import cn.iocoder.yudao.module.custom.entity.CarMain;
import cn.iocoder.yudao.module.custom.vo.CarBrandReqVO;
import cn.iocoder.yudao.module.custom.vo.CarBrandRespVO;
import cn.iocoder.yudao.module.custom.vo.CarMainRespVO;
import cn.iocoder.yudao.module.custom.vo.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 车辆品牌维护 Mapper
*
@ -22,4 +22,6 @@ public interface CarBrandMapper extends BaseMapper<CarBrand> {
IPage<CarBrandRespVO> findPage(Page<CarBrandReqVO> page,@Param("dto") CarBrandReqVO reqVO);
List<CascaderOptionsVO> searchBrand(@Param("dto") CarBrandReqVO reqVO);
}

View File

@ -3,16 +3,15 @@ package cn.iocoder.yudao.module.custom.mapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.custom.entity.CarMain;
import cn.iocoder.yudao.module.custom.entity.CarModel;
import cn.iocoder.yudao.module.custom.vo.CarMainReqVO;
import cn.iocoder.yudao.module.custom.vo.CarMainRespVO;
import cn.iocoder.yudao.module.custom.vo.CarModelReqVO;
import cn.iocoder.yudao.module.custom.vo.CarModelRespVO;
import cn.iocoder.yudao.module.custom.vo.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 车辆品牌型号 Mapper
*
@ -25,5 +24,11 @@ public interface CarModelMapper extends BaseMapper<CarModel> {
IPage<CarModelRespVO> getCarModelPageByBrandId(Page<CarModelReqVO> page, @Param("dto") CarModelReqVO reqVO);
List<CascaderOptionsVO> searchModelByBrandid(@Param("dto") CarModelReqVO reqVO);
// List<CarModelRespVO> searchModel(@Param("dto") CarModelReqVO reqVO);
}

View File

@ -6,8 +6,12 @@ import cn.iocoder.yudao.module.custom.entity.CarModel;
import cn.iocoder.yudao.module.custom.vo.CarModelReqVO;
import cn.iocoder.yudao.module.custom.vo.CarModelReqVO;
import cn.iocoder.yudao.module.custom.vo.CarModelRespVO;
import cn.iocoder.yudao.module.custom.vo.CascaderOptionsVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* 车辆品牌型号 Service 接口
@ -62,4 +66,12 @@ public interface CarModelService extends IService<CarModel> {
*/
IPage<CarModelRespVO> getCarModelPageByBrandId(CarModelReqVO pageReqVO);
/**
* 筛选品牌型号
*
* @param reqVO
* @return
*/
List<CascaderOptionsVO> searchBrand(CarModelReqVO reqVO);
}

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.custom.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.custom.entity.CarBrand;
import cn.iocoder.yudao.module.custom.entity.CarMain;
import cn.iocoder.yudao.module.custom.entity.CarModel;
import cn.iocoder.yudao.module.custom.mapper.CarBrandMapper;
import cn.iocoder.yudao.module.custom.mapper.CarModelMapper;
import cn.iocoder.yudao.module.custom.service.CarModelService;
import cn.iocoder.yudao.module.custom.vo.*;
@ -9,6 +12,7 @@ import cn.iocoder.yudao.module.custom.vo.CarModelReqVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -16,6 +20,8 @@ import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
@ -27,6 +33,9 @@ import java.util.UUID;
@Validated
public class CarModelServiceImpl extends ServiceImpl<CarModelMapper, CarModel> implements CarModelService {
@Autowired
CarBrandMapper carBrandMapper;
@Override
public String createCarModel(CarModelReqVO createReqVO) {
// 插入
@ -71,4 +80,68 @@ public class CarModelServiceImpl extends ServiceImpl<CarModelMapper, CarModel> i
return baseMapper.findPage(page,pageReqVO);
}
@Override
public List<CascaderOptionsVO> searchBrand(CarModelReqVO reqVO) {
// if (ObjectUtil.isNotEmpty(reqVO.getModelName() ) && !"".equals(reqVO.getModelName()) ){
//有筛选的情况要根据条件查出相关父项品牌和所有子项型号加入result仅展示关联父项
CarBrandReqVO brandQuery = new CarBrandReqVO();
brandQuery.setBrandName(reqVO.getModelName());
List<CascaderOptionsVO> nameResult = carBrandMapper.searchBrand(brandQuery);
// CarBrandReqVO brandQueryAbbName = new CarBrandReqVO();
// brandQueryAbbName.setAbbName(reqVO.getModelName());
//
// List<CarBrandRespVO> brands = carBrandMapper.searchBrand(brandQueryAbbName);
//// result.addAll(getChildModel(brands));
//
//
//
// CarModelReqVO modelQueryModelName = new CarModelReqVO();
// modelQueryModelName.setModelName(reqVO.getModelName());
// baseMapper.searchModel(modelQueryModelName);
//
// CarModelReqVO modelQueryAbbName = new CarModelReqVO();
// modelQueryAbbName.setAbbName(reqVO.getModelName());
// baseMapper.searchModel(modelQueryAbbName);
// }else {
// //无筛选的情况要查出所有父项品牌然后根据id加入其下所有子项型号
//
// //取所有品牌
// List<CarBrandRespVO> brands = carBrandMapper.searchBrand(new CarBrandReqVO());
// //根据父级品牌集合取所有的型号子选项
//// result = getChildModel(brands);
//
// }
return getChildModel(nameResult,reqVO.getModelName());
}
/**
* 根据父级品牌集合取所有的型号子选项
*
* @param brands
* @return
*/
private List<CascaderOptionsVO> getChildModel(List<CascaderOptionsVO> brands,String name){
//遍历父级数据
for (CascaderOptionsVO brandItem: brands) {
CarModelReqVO query = new CarModelReqVO();
query.setBrandId(brandItem.getValue());
query.setModelName(name);
//取品牌下属型号选项
List<CascaderOptionsVO> models = baseMapper.searchModelByBrandid(query);
//父级数据拼装
brandItem.setChildren(models);
}
return brands;
}
}

View File

@ -44,4 +44,5 @@ public class CarModelReqVO extends PageParam {
}

View File

@ -17,4 +17,9 @@ public class CarModelRespVO extends CarModel {
@ExcelProperty("创建时间")
private LocalDateTime createTime;
// /**
// * 车辆品牌型号选项
// */
// List<CascaderOptionsVO> modelOptions;
}

View File

@ -1,2 +1,29 @@
package cn.iocoder.yudao.module.custom.vo;public class CascaderOptionsVO {
package cn.iocoder.yudao.module.custom.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
@Schema(description = "级联选择器选项")
public class CascaderOptionsVO {
/**
* 选项值
*/
private String value;
/**
* 选项名
*/
private String label;
/**
* 选项子项
*/
List<CascaderOptionsVO> children;
/**
* 懒加载是否为叶子节点 0父 1子
*/
int leaf;
}

View File

@ -54,4 +54,22 @@
tbcb.create_time DESC
</select>
<select id="searchBrand" resultType="cn.iocoder.yudao.module.custom.vo.CascaderOptionsVO">
SELECT
main.brand_name AS 'label',
main.id AS 'value',
'0' AS 'leaf'
FROM
base_car_brand main
LEFT JOIN base_car_model tbcm ON main.id = tbcm.brand_id
WHERE
main.deleted = '0'
AND tbcm.deleted = '0'
<if test="dto.brandName != null and dto.brandName != ''">
AND CONCAT( '',main.brand_name, tbcm.model_name, main.abb_name, tbcm.abb_name ) LIKE CONCAT('%',#{dto.brandName},'%')
</if>
GROUP BY
main.id
</select>
</mapper>

View File

@ -68,4 +68,46 @@
tbcmod.sort DESC
</select>
<select id="searchModelByBrandid" resultType="cn.iocoder.yudao.module.custom.vo.CascaderOptionsVO">
SELECT
main.model_name AS 'label',
main.id AS 'value',
'1' AS 'leaf'
FROM
base_car_model main
WHERE
main.deleted = '0'
<if test="dto.modelName != null and dto.modelName != ''">
AND CONCAT( '', main.model_name, main.abb_name ) LIKE CONCAT('%',#{dto.modelName},'%')
</if>
AND main.brand_id = #{dto.brandId}
GROUP BY
main.id
</select>
<select id="searchModel" resultType="cn.iocoder.yudao.module.custom.vo.CarModelRespVO">
SELECT
<include refid="baseCarModelColumn"></include>
FROM `base_car_model` tbcmod
WHERE
tbcmod.deleted = 0
<if test="dto.brandId != null and dto.brandId != ''">
AND tbcmod.brand_id = #{dto.brandId}
</if>
<if test="dto.modelName != null and dto.modelName != ''">
AND tbcmod.model_name LIKE CONCAT('%',#{dto.modelName},'%')
</if>
<if test="dto.modelValue != null and dto.modelValue != ''">
AND tbcmod.model_value = #{dto.modelValue}
</if>
<if test="dto.remark != null and dto.remark != ''">
AND tbcmod.remark LIKE CONCAT('%',#{dto.remark},'%')
</if>
<if test="dto.abbName != null and dto.abbName != ''">
AND tbcmod.abb_name LIKE CONCAT('%',#{dto.abbName},'%')
</if>
ORDER BY
tbcmod.sort DESC
</select>
</mapper>