Commit 2da489e7 by 崔彦峰

feat(car): 新增车辆品牌车系管理功能

- 在CarBrandController中添加@RestController注解并实现车系查询接口
- 新增CarSeriesListResDTO和CarSeriesResDTO数据传输对象
- 扩展CarBrandRemote远程接口支持车系列表查询
- 实现CarBrandService中的getCarSeriesList业务逻辑
- 集成GopCarInfoRemote获取车辆品牌车系层级数据
- 修复CarBrandListResDTO中brands字段的文档描述
- 优化车系数据解析和转换逻辑
1 parent 09f51cc0
......@@ -12,7 +12,7 @@ import java.util.List;
public class CarBrandListResDTO implements Serializable {
private static final long serialVersionUID = -6921209396593157562L;
@ApiModelProperty("品牌ID")
@ApiModelProperty("品牌列表")
private List<CarBrandResDTO> brands;
}
package cn.com.glsx.dj.strategy.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@ApiModel("车辆车系响应")
public class CarSeriesListResDTO implements Serializable {
private static final long serialVersionUID = -6921209396593157562L;
@ApiModelProperty("车系列表")
private List<CarSeriesResDTO> series;
}
package cn.com.glsx.dj.strategy.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel("车辆车系响应")
public class CarSeriesResDTO implements Serializable {
private static final long serialVersionUID = -6921209396593157562L;
@ApiModelProperty("车系ID")
private Integer id;
@ApiModelProperty("车系名称")
private String name;
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.CarBrandListResDTO;
import cn.com.glsx.dj.strategy.dto.CarSeriesListResDTO;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
......@@ -15,4 +16,9 @@ public interface CarBrandRemote {
@ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("车辆品牌列表")
RpcResponse<CarBrandListResDTO> getCarBrandList();
@ApiMethod("车辆车系列表")
@ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("车辆车系列表")
RpcResponse<CarSeriesListResDTO> getCarSeriesList();
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.CarBrandListResDTO;
import cn.com.glsx.dj.strategy.dto.CarSeriesListResDTO;
import cn.com.glsx.dj.strategy.service.CarBrandService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
......@@ -29,4 +30,18 @@ public class CarBrandRemoteImpl implements CarBrandRemote{
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<CarSeriesListResDTO> getCarSeriesList() {
try {
CarSeriesListResDTO carSeriesList = carBrandService.getCarSeriesList();
return RpcResponse.success(carSeriesList);
} catch (RpcServiceException e) {
log.error("getCarBrandList occur RpcServiceException", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("getCarBrandList occur Exception", e);
return RpcResponse.error(e);
}
}
}
package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.gop.remote.GopCarInfoRemote;
import cn.com.glsx.dj.gop.response.common.CarInfoResponse;
import cn.com.glsx.dj.strategy.dto.CarBrandListResDTO;
import cn.com.glsx.dj.strategy.dto.CarBrandResDTO;
import cn.com.glsx.dj.strategy.dto.CarSeriesListResDTO;
import cn.com.glsx.dj.strategy.dto.CarSeriesResDTO;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -9,7 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
......@@ -19,6 +26,9 @@ public class CarBrandService {
@Autowired
private Environment env;
@Autowired
private GopCarInfoRemote gopCarInfoRemote;
public CarBrandListResDTO getCarBrandList() {
log.info("获取车品牌列表:{}", env.getProperty("car.brand.list"));
String property = env.getProperty("car.brand.list");
......@@ -27,4 +37,37 @@ public class CarBrandService {
carBrandListResDTO.setBrands(carBrandResDTOS);
return carBrandListResDTO;
}
public CarSeriesListResDTO getCarSeriesList() {
log.info("获取车品牌列表:{}", env.getProperty("car.brand.list"));
String property = env.getProperty("car.brand.list");
List<CarBrandResDTO> carBrandResDTOS = JSON.parseArray(property, CarBrandResDTO.class);
if (carBrandResDTOS == null) {
return null;
}
List<Integer> carBrandIds = carBrandResDTOS.stream().map(CarBrandResDTO::getId).collect(Collectors.toList());
RpcResponse<List<CarInfoResponse>> carBrandList = gopCarInfoRemote.getCarBrandList(true);
if (!carBrandList.hasResult()) {
return null;
}
List<CarInfoResponse> result = carBrandList.getResult();
//筛选配置的一级品牌信息
List<CarInfoResponse> carInfoResponses = result.stream().filter(carInfoResponse -> carBrandIds.contains(carInfoResponse.getId())).collect(Collectors.toList());
log.info("筛选后的车品牌列表:{}", JSON.toJSONString(carInfoResponses));
CarSeriesListResDTO carBrandListResDTO = new CarSeriesListResDTO();
List<CarSeriesResDTO> series = new ArrayList<>();
for (CarInfoResponse firstCarInfo : carInfoResponses) {
List<CarInfoResponse> secondCarInfos = firstCarInfo.getChilds();
for (CarInfoResponse secondCarInfo : secondCarInfos) {
List<CarInfoResponse> thirdCarInfos = secondCarInfo.getChilds();
List<CarSeriesResDTO> carSeriesResDTOS = JSON.parseArray(JSON.toJSONString(thirdCarInfos), CarSeriesResDTO.class);
series.addAll(carSeriesResDTOS);
}
}
carBrandListResDTO.setSeries(series);
return carBrandListResDTO;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!