Commit 9ba11b47 by zhouhaibao

[+]新增品牌查询

1 parent 333a94bd
package cn.com.glsx.dj.controller;
import cn.com.glsx.dj.gop.remote.GopCarInfoRemote;
import cn.com.glsx.dj.gop.response.common.CarInfoResponse;
import cn.com.glsx.dj.mindworkplate.dto.monitoring.MonitorBaseRequest;
import cn.com.glsx.dj.mindworkplate.model.warning.CoefficientListMsgDTO;
import cn.com.glsx.dj.mindworkplate.model.warning.MonitoringMsgDTO;
......@@ -11,13 +13,18 @@ import cn.com.glsx.dj.util.CommonUtil;
import cn.com.glsx.merchants.dto.merchant.CarBrandProvinceRequestDTO;
import cn.com.glsx.merchants.model.response.MerchantProvinceDTO;
import cn.com.glsx.merchants.remote.MerchantRemote;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -46,6 +53,9 @@ public class ReportSubscribeController {
*/
protected final Logger logger = LoggerFactory.getLogger(getClass());
// 品牌列表缓存,有效期1天(86400秒)
private static final Cache<String, List<CarInfoResponse>> BRAND_CACHE = CacheUtil.newTimedCache(86400000);
@Autowired
private ReportSubscribeRemote reportSubscribeRemote;
......@@ -55,6 +65,9 @@ public class ReportSubscribeController {
@Autowired
private MerchantRemote merchantRemote;
@Autowired
private GopCarInfoRemote gopCarInfoRemote;
/**
* 更新展业周报订阅状态
* @param req UpdateWeeklyReportSubscribeRequest
......@@ -227,5 +240,53 @@ public class ReportSubscribeController {
}
}
@ServiceMethod(method = "org.ore.api.report.subscribe.getAllBrandIds", needInSession = NeedInSessionType.NO)
@ApiOperation("根据品牌名称查询品牌")
public RopResponse<List<CarInfoResponse>> getAllBrandIds(
MerchantRequestRop request) {
try {
// 从缓存获取品牌列表
List<CarInfoResponse> brandList = BRAND_CACHE.get("brandList");
if (CollectionUtils.isEmpty(brandList)) {
// 缓存未命中,从远程服务获取
brandList = gopCarInfoRemote.getCarBrandList(false).getResult();
if (CollectionUtils.isNotEmpty(brandList)) {
// 放入缓存,有效期1天
BRAND_CACHE.put("brandList", brandList);
}
}
// 根据品牌名称进行模糊匹配
String brandName = request.getBrandName();
if (brandName != null && !brandName.isEmpty() && CollectionUtils.isNotEmpty(brandList)) {
List<CarInfoResponse> filteredBrands = new ArrayList<>();
for (CarInfoResponse brand : brandList) {
// 检查子品牌是否匹配
try {
// 尝试获取子品牌列表
List<CarInfoResponse> childs = brand.getChilds();
if (CollectionUtils.isNotEmpty(childs)) {
for (CarInfoResponse child : childs) {
if (child.getBrandName() != null && child.getBrandName().contains(brandName)) {
filteredBrands.add(child);
}
}
}
} catch (Exception e) {
// 如果没有childs字段,忽略异常
logger.debug("CarInfoResponse没有childs字段", e);
}
}
brandList = filteredBrands;
}
return RopResponse.success(brandList);
} catch (Exception e) {
logger.error("根据品牌名称查询品牌失败: {}", e);
return RopResponse.error("根据品牌名称查询品牌失败");
}
}
}
\ No newline at end of file
......@@ -25,4 +25,8 @@ public class MerchantRequestRop extends AbstractRopRequest {
@ApiModelProperty(notes = "省份")
private List<Integer> provinceIds;
@ApiModelProperty(notes = "品牌名称")
private String brandName;
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!