Commit 37626852 by 丁伟峰

Merge branch 'feature-dingwf-0715' into develop

2 parents 8e51050c 1a054066
...@@ -23,12 +23,12 @@ public class SaasUtils { ...@@ -23,12 +23,12 @@ public class SaasUtils {
/** /**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空 * 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
*/ */
public List<BlockInfo> queryBlocks(String location, String address) { public List<BlockInfo> queryBlocksByLocation(String location) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队; // 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回 // 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式 // todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例 // 创建RestTemplate实例
log.info("===> queryBlocks({}, {})", location, address); log.info("===> queryBlocksByLocation({})", location);
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
// 设置请求头 // 设置请求头
...@@ -39,14 +39,62 @@ public class SaasUtils { ...@@ -39,14 +39,62 @@ public class SaasUtils {
String url; String url;
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add("ak", "284c57cbabad4755a9c657885a8df3e2"); params.add("ak", "284c57cbabad4755a9c657885a8df3e2");
if (StringUtils.isNotEmpty(location)) {
url = "https://pea-test.bshg.com.cn/v1/xyfendan"; url = "https://pea-test.bshg.com.cn/v1/xyfendan";
String[] coordinates = location.split(","); String[] coordinates = location.split(",");
params.add("coordinate", String.format("{\"x\":%s, \"y\":%s}", coordinates[0], coordinates[1])); params.add("coordinate", String.format("{\"x\":%s, \"y\":%s}", coordinates[0], coordinates[1]));
} else {
params.add("need_district", "false");
params.add("need_layer", "true");
// params.add("related_point_fields", "");
params.add("area_fields", "名称,唯一编号,区块");
log.info("request params ==> {}", params);
// 构建请求实体
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
// 发送POST请求
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
// 获取响应结果
String responseBody = responseEntity.getBody();
log.info("after call saas ==> {}", responseEntity.getBody());
// 使用Jackson库解析JSON数据
List<BlockInfo> blocks = new ArrayList<>();
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonNode responseJson = objectMapper.readTree(responseBody);
// 坐标模式
for (JsonNode r : responseJson.get("result")) {
// 分单接口暂时无图层返回
if (r.get("field3") != null && r.get("field1") != null) {
blocks.add(new BlockInfo().setBlockId(r.get("field3").asText()).setBlockName(r.get("field1").asText()));
}
}
} catch (Exception e) {
log.error("处理异常: {}", e.getMessage());
}
return blocks;
}
public List<BlockInfo> queryBlocksByAddress(String address) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
log.info("===> queryBlocksByAddress({})", address);
RestTemplate restTemplate = new RestTemplate();
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// 构建请求参数
String url;
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add("ak", "284c57cbabad4755a9c657885a8df3e2");
url = "https://pea-test.bshg.com.cn/v2/fendan"; url = "https://pea-test.bshg.com.cn/v2/fendan";
params.add("addresses", String.format("[{\"address\":\"%s\"}]", address)); params.add("addresses", String.format("[{\"address\":\"%s\"}]", address));
}
params.add("need_district", "false"); params.add("need_district", "false");
params.add("need_layer", "true"); params.add("need_layer", "true");
// params.add("related_point_fields", ""); // params.add("related_point_fields", "");
...@@ -67,26 +115,24 @@ public class SaasUtils { ...@@ -67,26 +115,24 @@ public class SaasUtils {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
try { try {
JsonNode responseJson = objectMapper.readTree(responseBody); JsonNode responseJson = objectMapper.readTree(responseBody);
// 地址模式
// 获取areaResults[0]的值 // 获取areaResults[0]的值
for (JsonNode r : responseJson.get("result").get(0).get("areaResults")) { for (JsonNode r : responseJson.get("result").get(0).get("areaResults")) {
// 分单接口暂时无图层返回 // 分单接口暂时无图层返回
if(r.get("field3") != null && r.get("field1") != null) { if (r.get("field3") != null && r.get("field1") != null) {
blocks.add(new BlockInfo().setBlockId(r.get("field3").asText()).setBlockName(r.get("field1").asText())); blocks.add(new BlockInfo().setBlockId(r.get("field3").asText()).setBlockName(r.get("field1").asText()));
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error("处理异常: {}", e.getMessage());
} }
return blocks; return blocks;
} }
public List<String> queryBlockIds(String location, String address) {
return queryBlocks(location, address).stream().map(BlockInfo::getBlockId).collect(Collectors.toList());
}
@lombok.Data @lombok.Data
@Accessors(chain = true) @Accessors(chain = true)
static class BlockInfo { public static class BlockInfo {
private String layer; private String layer;
private String blockId; private String blockId;
private String blockName; private String blockName;
......
...@@ -12,6 +12,7 @@ import com.dituhui.pea.order.entity.*; ...@@ -12,6 +12,7 @@ import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.service.CapacityQueryService; import com.dituhui.pea.order.service.CapacityQueryService;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -49,12 +50,17 @@ public class CapacityQueryServiceImpl implements CapacityQueryService { ...@@ -49,12 +50,17 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
// 单条容量查询 // 单条容量查询
log.info("===> queryMatchCapacityData()"); log.info("===> queryMatchCapacityData()");
List<String> layerIds = capacityUtils.getLayers(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill()); List<String> layerIds = capacityUtils.getLayers(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill());
List<String> blockIds = saasUtils.queryBlockIds(reqDTO.getLocation(), reqDTO.getAddress());
if (blockIds == null || blockIds.size() == 0) { List<String> blockIds = null;
if (StringUtils.isNotBlank(reqDTO.getLocation())) {
blockIds = saasUtils.queryBlocksByLocation(reqDTO.getLocation()).stream().map(SaasUtils.BlockInfo::getBlockId).collect(Collectors.toList());
} else {
blockIds = saasUtils.queryBlocksByAddress(reqDTO.getAddress()).stream().map(SaasUtils.BlockInfo::getBlockId).collect(Collectors.toList());
}
if (blockIds.size() == 0) {
log.error("分单接口没有查到对应的结果"); log.error("分单接口没有查到对应的结果");
Result.failed(String.format("分单接口(address:%s)(location:%s) 没有查到配置区块", reqDTO.getAddress(), reqDTO.getLocation())); Result.failed(String.format("分单接口(address:%s)(location:%s) 没有查到配置区块", reqDTO.getAddress(), reqDTO.getLocation()));
} }
List<String> teamIds = capacityUtils.getTeamIdsByBlockIdsAndLayerIds(blockIds, layerIds); List<String> teamIds = capacityUtils.getTeamIdsByBlockIdsAndLayerIds(blockIds, layerIds);
if (teamIds == null || teamIds.size() == 0) { if (teamIds == null || teamIds.size() == 0) {
Result.failed("没有找到匹配的工作队"); Result.failed("没有找到匹配的工作队");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!