Commit fc723696 by 崔彦峰

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

- 创建 CarBrandController 提供车辆品牌查询接口
- 添加 CarBrandRemote 远程调用接口定义
- 实现 CarBrandRemoteImpl 远程服务调用
- 创建 CarBrandListResDTO 和 CarBrandResDTO 数据传输对象
- 实现 CarBrandService 业务逻辑从配置中读取品牌数据
- 配置 DubboConfig 中注册 CarBrandRemote Bean
1 parent a28f5689
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 CarBrandListResDTO implements Serializable {
private static final long serialVersionUID = -6921209396593157562L;
@ApiModelProperty("品牌ID")
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;
@Data
@ApiModel("车辆品牌响应")
public class CarBrandResDTO 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.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.com.glsx.framework.core.annotation.ApiService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
@ApiService(value = "车辆品牌管理", owner = "yangwei")
public interface CarBrandRemote {
@ApiMethod("车辆品牌列表")
@ApiParam(name = "request", notes = "请求对象", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("车辆品牌列表")
RpcResponse<CarBrandListResDTO> getCarBrandList();
}
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.CarBrandListResDTO;
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;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@DubboService
@RequiredArgsConstructor
public class CarBrandRemoteImpl implements CarBrandRemote{
@Autowired
private CarBrandService carBrandService;
@Override
public RpcResponse<CarBrandListResDTO> getCarBrandList() {
try {
CarBrandListResDTO carBrandList = carBrandService.getCarBrandList();
return RpcResponse.success(carBrandList);
} 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.strategy.dto.CarBrandListResDTO;
import cn.com.glsx.dj.strategy.dto.CarBrandResDTO;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
public class CarBrandService {
@Autowired
private Environment env;
public CarBrandListResDTO getCarBrandList() {
log.info("获取车品牌列表:{}", env.getProperty("car.brand.list"));
String property = env.getProperty("car.brand.list");
List<CarBrandResDTO> carBrandResDTOS = JSON.parseArray(property, CarBrandResDTO.class);
CarBrandListResDTO carBrandListResDTO = new CarBrandListResDTO();
carBrandListResDTO.setBrands(carBrandResDTOS);
return carBrandListResDTO;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!