Commit 0349ba83 by chamberone

Merge branch 'develop' of https://zhangguoping@gitlab.dituhui.com/bsh/project/pr…

…oject.git into develop
2 parents 71eef2ea 8ae9766e
...@@ -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;
......
...@@ -2,17 +2,14 @@ package com.dituhui.pea.order.entity; ...@@ -2,17 +2,14 @@ package com.dituhui.pea.order.entity;
import lombok.Data; import lombok.Data;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Data @Data
@Entity @Entity
@Table(name="v_engineer_skill") @Table(name="v_engineer_skill")
public class EngineerSkillEntity { public class EngineerSkillEntity {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
private String engineerCode; private String engineerCode;
private String skillGroupCode; private String skillGroupCode;
......
package com.dituhui.pea.order.service.impl; package com.dituhui.pea.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.CapacityUtils; import com.dituhui.pea.order.common.CapacityUtils;
import com.dituhui.pea.order.common.DateUtils; import com.dituhui.pea.order.common.DateUtils;
...@@ -12,19 +11,16 @@ import com.dituhui.pea.order.entity.*; ...@@ -12,19 +11,16 @@ 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;
import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
@Service @Service
@Slf4j @Slf4j
public class CapacityQueryServiceImpl implements CapacityQueryService { public class CapacityQueryServiceImpl implements CapacityQueryService {
...@@ -49,12 +45,17 @@ public class CapacityQueryServiceImpl implements CapacityQueryService { ...@@ -49,12 +45,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("没有找到匹配的工作队");
......
...@@ -42,6 +42,7 @@ import org.springframework.stereotype.Service; ...@@ -42,6 +42,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE; import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATETIME; import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATETIME;
...@@ -122,11 +123,16 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -122,11 +123,16 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setCounty(location.getDistrict()); entity.setCounty(location.getDistrict());
entity.setAddress(location.getFormattedAddress()); entity.setAddress(location.getFormattedAddress());
// 根据分单,填写clusterId/branchId/groupId/teamId等 // 根据分单,填写clusterId/branchId/groupId/teamId等
String loc = String.format("%f,%f", req.getLocation().getLng(), req.getLocation().getLat());
List<String> blockIds = null;
List<String> layerIds = capacityUtils.getLayers(req.getBrand(), req.getType(), req.getSkill()); List<String> layerIds = capacityUtils.getLayers(req.getBrand(), req.getType(), req.getSkill());
List<String> blockIds = saasUtils .queryBlockIds(loc, req.getAddress()); if(req.getLocation() != null){
if (blockIds == null || blockIds.size() == 0) { String loc = String.format("%f,%f", req.getLocation().getLng(), req.getLocation().getLat());
blockIds = saasUtils.queryBlocksByLocation(loc).stream().map(SaasUtils.BlockInfo::getBlockId).collect(Collectors.toList());
} else {
blockIds = saasUtils.queryBlocksByAddress(req.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) 没有查到配置区块", req.getAddress(), req.getLocation())); Result.failed(String.format("分单接口(address:%s)(location:%s) 没有查到配置区块", req.getAddress(), req.getLocation()));
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!