Commit 9c30ae54 by chamberone

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

…oject.git into develop
2 parents b34d651e 8e51050c
Showing with 344 additions and 231 deletions
package com.dituhui.pea.order.common;
import com.dituhui.pea.order.dao.MapBlockInfoDao;
import com.dituhui.pea.order.dao.SkillInfoDao;
import com.dituhui.pea.order.entity.MapBlockInfoEntity;
import com.dituhui.pea.order.entity.SkillInfoEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
@Slf4j
public class CapacityUtils {
@Autowired
private SkillInfoDao skillInfoDao;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
public List<String> getTeamIdsByBlockIdsAndLayerIds(List<String> blockIds, List<String> layerIds) {
List<String> teamIds = mapBlockInfoDao.findByBlockIdInAndLayerIdIn(blockIds, layerIds).stream().map(MapBlockInfoEntity::getTeamId).collect(Collectors.toList());
log.info("根据输入信息返回对应的可能的工作队列表({}/{}) ===> {}", blockIds, layerIds, teamIds);
return teamIds;
}
public List<String> getLayers(String brand, String type, String skill) {
List<String> layers = new ArrayList<>();
SkillInfoEntity entity = skillInfoDao.getByBrandAndTypeAndSkill(brand, type, skill);
if (entity != null) {
layers.add(entity.getLayerId());
}
return layers;
}
}
......@@ -2,18 +2,39 @@ package com.dituhui.pea.order.common;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Locale;
public class DateUtil {
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATETIME;
public class DateUtils {
public static String toWeekChinese(String date) {
LocalDate d = LocalDate.parse(date);
return DateUtil.toWeekChinese(d.getDayOfWeek().getValue());
return DateUtils.toWeekChinese(d.getDayOfWeek().getValue());
}
public static String toWeekChinese(int dayOfWeek) {
// TextStyle: SHORT 周一;LONG 星期一;NARROW 一
return DayOfWeek.of(dayOfWeek).getDisplayName(TextStyle.SHORT, Locale.CHINESE);
}
public static String formatDateTime(LocalDateTime d, String format){
return d.format(DateTimeFormatter.ofPattern(format));
}
public static String formatDateTime(LocalDateTime d){
return formatDateTime(d, PATTERN_DATETIME);
}
public static String formatDate(LocalDate d, String format){
return d.format(DateTimeFormatter.ofPattern(format));
}
public static String formatDate(LocalDate d){
return formatDate(d, PATTERN_DATE);
}
}
......@@ -22,7 +22,7 @@ import java.util.List;
import java.util.stream.Collectors;
@Component
public class EngineerUtil {
public class EngineerUtils {
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
......@@ -72,6 +72,7 @@ public class EngineerUtil {
private Specification<EngineerInfoEntity> buildSpecification(String keyword) {
// 动态查询
return new Specification<EngineerInfoEntity>() {
@Override
public Predicate toPredicate(Root<EngineerInfoEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
......
package com.dituhui.pea.order.common;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
@Component
@Slf4j
public class SaasUtils {
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
*/
public List<BlockInfo> queryBlocks(String location, String address) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
log.info("===> queryBlocks({}, {})", location, 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");
if (StringUtils.isNotEmpty(location)) {
url = "https://pea-test.bshg.com.cn/v1/xyfendan";
String[] coordinates = location.split(",");
params.add("coordinate", String.format("{\"x\":%s, \"y\":%s}", coordinates[0], coordinates[1]));
} else {
url = "https://pea-test.bshg.com.cn/v2/fendan";
params.add("addresses", String.format("[{\"address\":\"%s\"}]", address));
}
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);
// 获取areaResults[0]的值
for (JsonNode r : responseJson.get("result").get(0).get("areaResults")) {
// 分单接口暂时无图层返回
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<String> queryBlockIds(String location, String address) {
return queryBlocks(location, address).stream().map(BlockInfo::getBlockId).collect(Collectors.toList());
}
@lombok.Data
@Accessors(chain = true)
static class BlockInfo {
private String layer;
private String blockId;
private String blockName;
}
}
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dituhui.pea.order.controller;
import com.dituhui.pea.common.BusinessException;
......@@ -63,7 +47,7 @@ public class OrderCreateController {
public Result<?> capacityQuery(@Validated @RequestBody CapacityOrderQueryDTO.Request reqDTO) {
Result<?> res = null;
try {
res = capacityQueryService.getOneCapacityData(reqDTO);
res = capacityQueryService.queryMatchCapacityData(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
......
......@@ -3,7 +3,11 @@ package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.CapacityEngineerStatEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CapacityEngineerStatDao extends JpaRepository<CapacityEngineerStatEntity, Integer> {
CapacityEngineerStatEntity getByEngineerCodeAndWorkday(String engineerCode, String workday);
CapacityEngineerStatEntity getByWorkdayAndEngineerCode(String workday, String engineerCode);
List<CapacityEngineerStatEntity> getByWorkdayAndEngineerCodeIn(String workday, List<String> engineerCodes);
}
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.EngineerSkillEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface EngineerSkillDao extends JpaRepository<EngineerSkillEntity, Long> {
List<EngineerSkillEntity> findAllByBrandAndTypeAndSkillAndEngineerCodeIn(String brand, String type, String skill, List<String> engineerCodes);
}
......@@ -6,10 +6,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@Where(clause = "status = 1")
public interface MapBlockInfoDao extends JpaRepository<MapBlockInfoEntity, Integer> {
@Query("select s.teamId from MapBlockInfoEntity s where s.blockId = :blockId and s.layer = :layer")
String getTeamIdByBlockIdAndLayer(String blockId, String layer);
List<MapBlockInfoEntity> findByBlockIdInAndLayerIdIn(List<String> blockIds, List<String> layerIds);
}
......@@ -10,4 +10,5 @@ import java.util.List;
public interface SkillInfoDao extends JpaRepository<SkillInfoEntity, Long> {
List<SkillInfoEntity> findAll();
Page<SkillInfoEntity> findAll(Pageable pageable);
SkillInfoEntity getByBrandAndTypeAndSkill(String brand, String type, String skill);
}
package com.dituhui.pea.order.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Entity
@Table(name="v_engineer_skill")
public class EngineerSkillEntity {
@Id
@GeneratedValue
private Long id;
private String engineerCode;
private String skillGroupCode;
private String brand;
private String type;
private String skill;
}
......@@ -2,9 +2,7 @@ package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.CapacityOrderQueryDTO;
import com.dituhui.pea.order.dto.CapacityStatQueryDTO;
import com.fasterxml.jackson.core.JsonProcessingException;
public interface CapacityQueryService {
Result<?> getOneCapacityData(CapacityOrderQueryDTO.Request capacityQueryReqDTO);
Result<?> queryMatchCapacityData(CapacityOrderQueryDTO.Request capacityQueryReqDTO);
}
......@@ -6,9 +6,6 @@ import java.util.List;
public interface CommonService {
String getTeamIdByInput(String location, String address, String layer);
void addOrderEvent(String orderId, String subOrderId, String source, String operator, String event, String content, String memo);
List<LabelValueDTO> getSpecialParams(String catalog, String biztype);
......
......@@ -2,7 +2,7 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.IdUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtil;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.OrgGroupEntity;
......@@ -89,7 +89,7 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
List<String> days = Arrays.asList(workDays.split(","));
Collections.sort(days);
return days.stream().map(e -> {
return DateUtil.toWeekChinese(Integer.parseInt(e));
return DateUtils.toWeekChinese(Integer.parseInt(e));
}).collect(Collectors.toList());
}
......
......@@ -2,24 +2,26 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.CapacityUtils;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.common.SaasUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.CapacityOrderQueryDTO;
import com.dituhui.pea.order.dto.CapacityStatQueryDTO;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.service.CapacityQueryService;
import com.dituhui.pea.order.service.CommonService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
......@@ -27,41 +29,55 @@ import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
@Slf4j
public class CapacityQueryServiceImpl implements CapacityQueryService {
private final String[] fullDay = {"08:00", "18:00"};
@Autowired
private CapacityTeamStatDao capacityTeamStatDao;
private SkillInfoDao skillInfoDao;
@Autowired
private CapacityOrgStatDao capacityOrgStatDao;
private CapacityUtils capacityUtils;
@Autowired
private ProductCategoryDao productCategoryDao;
private SaasUtils saasUtils;
@Autowired
private OrgGroupDao orgGroupDao;
private EngineerUtils engineerUtil;
@Autowired
private OrgTeamDao orgTeamDao;
private EngineerSkillDao engineerSkillDao;
@Autowired
private CommonService commonService;
private CapacityEngineerStatDao capacityEngineerStatDao;
@Autowired
private OrgBranchDao orgBranchDao;
private OrgTeamDao orgTeamDao;
@Override
public Result<?> getOneCapacityData(CapacityOrderQueryDTO.Request reqDTO) {
public Result<?> queryMatchCapacityData(CapacityOrderQueryDTO.Request reqDTO) {
// 单条容量查询
log.info("===> getOneCapacityData()");
String layer = productCategoryDao.getLayerByBrandAndTypeAndSkill(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill());
String teamId = commonService.getTeamIdByInput(reqDTO.getLocation(), reqDTO.getAddress(), layer);
log.info("teamId[{}]layer[{}]", teamId, layer);
log.info("===> queryMatchCapacityData()");
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) {
log.error("分单接口没有查到对应的结果");
Result.failed(String.format("分单接口(address:%s)(location:%s) 没有查到配置区块", reqDTO.getAddress(), reqDTO.getLocation()));
}
List<String> teamIds = capacityUtils.getTeamIdsByBlockIdsAndLayerIds(blockIds, layerIds);
if (teamIds == null || teamIds.size() == 0) {
Result.failed("没有找到匹配的工作队");
}
// 选择一个工作队(理论上,只有1个合适的工作队),然后遍历下面的各个技术员,从符合技能的技术员中,汇总相关的容量
// 遍历工作队,每个工作队
String teamId = teamIds.get(0);
List<String> engineerCodes = engineerUtil.getEngineersByLevel("team", teamId).stream()
.map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
List<String> matchEngineerCodes = engineerSkillDao.findAllByBrandAndTypeAndSkillAndEngineerCodeIn(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill(), engineerCodes).stream()
.map(EngineerSkillEntity::getEngineerCode).collect(Collectors.toList());
log.info("符合技能要求的工作队[{}]符合技能要求的技术员[{}]", teamId, matchEngineerCodes);
SkillInfoEntity skillInfoEntity = skillInfoDao.getByBrandAndTypeAndSkill(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill());
List<CapacityOrderQueryDTO.CalendarDTO> calendars = getSummaryOfEngineersCapacity(teamId, matchEngineerCodes, reqDTO.getStartDate(), reqDTO.getEndDate(), skillInfoEntity.getTakeTime());
CapacityOrderQueryDTO.Result rs = new CapacityOrderQueryDTO.Result();
rs.setCalendar(calendars);
rs.setStartDate(reqDTO.getStartDate()).setEndDate(reqDTO.getEndDate());
rs.setCalendar(getTeamCapacityByLayerAndDays(teamId, layer, reqDTO.getStartDate(), reqDTO.getEndDate()));
rs.setLegend(getLengends());
rs.setRemark(String.format("%s-%s", teamId, layer));
rs.setRemark(String.format("%s-%s", teamId, layerIds));
return Result.success(rs);
}
......@@ -73,6 +89,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
return legends;
}
private int getSpanType(int capLeft, int capTotal) {
float ratio = (float) capLeft / capTotal;
if (ratio < 0.3) {
......@@ -84,62 +101,69 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
}
}
private Object[] getTimeSpanInfo(String date, String timeSpan, String timeSpanDetail) {
@Data
static class SpanInfo {
private String title;
private String timeBegin;
private String timeEnd;
}
private SpanInfo getTimeSpanInfo(String teamId, String date, String timeSpan, String timeSpanDetail) {
// 如果是"全天",直接返回标题和2个时间点;否则,解析timeSpanDetail中的数据返回
Object[] result = new Object[3];
OrgTeamEntity orgTeamEntity = orgTeamDao.getByTeamId(teamId);
SpanInfo r = new SpanInfo();
if ("全天".equals(timeSpan)) {
result[0] = "全天都可以";
result[1] = String.format("%s %s:00", date, fullDay[0]);
result[2] = String.format("%s %s:00", date, fullDay[1]);
return result;
r.setTitle("全天都可以");
r.setTimeBegin(String.format("%s %s:00", date, orgTeamEntity.getWorkOn()));
r.setTimeEnd(String.format("%s %s:00", date, orgTeamEntity.getWorkOff()));
} else {
String[] times = timeSpanDetail.split("~");
r.setTitle(String.format("%s:00-%s:00", times[0], times[1]));
r.setTimeBegin(String.format("%s %s:00", date, times[0]));
r.setTimeEnd(String.format("%s %s:00", date, times[1]));
}
String[] times = timeSpanDetail.split("~");
result[0] = String.format("%s:00-%s:00", times[0], times[1]);
result[1] = String.format("%s %s:00", date, times[0]);
result[2] = String.format("%s %s:00", date, times[1]);
return result;
return r;
}
/**
* 根据工作队、技能,返回对应时间段内的容量
*
* @param teamId
* @param layer
* @param beginDate
* @param endDate
* @return
* 查询日期范围内,技术员的容量。由于与具体的技能场景相关,因此,还需要检查最小需要的时间,如果不满足不返回;
*/
private List<CapacityOrderQueryDTO.CalendarDTO> getTeamCapacityByLayerAndDays(String teamId, String layer, String beginDate, String endDate) {
log.info("==> getTimeRangeByTeamSkill({}, {}, {}, {})", teamId, layer, beginDate, endDate);
Map<String, CapacityOrderQueryDTO.CalendarDTO> dayMaps = new HashMap<>();
List<CapacityTeamStatEntity> capacityTeamStatEntityList = capacityTeamStatDao.findAllByTeamIdAndLayerAndWorkdayBetween(teamId, layer, beginDate, endDate);
for (CapacityTeamStatEntity e : capacityTeamStatEntityList) {
log.info("CapacityTeamStatEntity ==> {}", e);
CapacityOrderQueryDTO.TimeDTO timeDTO = new CapacityOrderQueryDTO.TimeDTO();
timeDTO.setType(getSpanType(e.getCapLeft(), e.getCapTotal()));
Object[] timeSpans = getTimeSpanInfo(e.getWorkday(), e.getTimeSpan(), e.getTimeSpanDetail());
timeDTO.setText((String) timeSpans[0]);
timeDTO.setBegin((String) timeSpans[1]);
timeDTO.setEnd((String) timeSpans[2]);
CapacityOrderQueryDTO.CalendarDTO calendarDTO = null;
if (dayMaps.containsKey(e.getWorkday())) {
calendarDTO = dayMaps.get(e.getWorkday());
} else {
calendarDTO = new CapacityOrderQueryDTO.CalendarDTO();
calendarDTO.setDate(e.getWorkday()).setWeek(getWeekday(e.getWorkday()));
calendarDTO.setTimes(new ArrayList<>());
}
calendarDTO.getTimes().add(timeDTO);
dayMaps.put(e.getWorkday(), calendarDTO);
private List<CapacityOrderQueryDTO.CalendarDTO> getSummaryOfEngineersCapacity(String teamId, List<String> engineerCodes, String bdate, String edate, Integer leastMinutes) {
log.info("==> getSummaryOfEngineersCapacity({}, {}, {})", engineerCodes, bdate, edate);
List<CapacityOrderQueryDTO.CalendarDTO> rs = new ArrayList<>();
LocalDate startDate = LocalDate.parse(bdate);
LocalDate endDate = LocalDate.parse(edate);
List<String> datesInRange = Stream.iterate(startDate, date -> date.plusDays(1))
.limit(ChronoUnit.DAYS.between(startDate, endDate.plusDays(1)))
.map(DateUtils::formatDate)
.collect(Collectors.toList());
for (String date : datesInRange) {
CapacityOrderQueryDTO.CalendarDTO calendar = getCapacityOneDay(teamId, engineerCodes, date, leastMinutes);
rs.add(calendar);
}
return new ArrayList<>(dayMaps.values()).stream()
.sorted(Comparator.comparing(CapacityOrderQueryDTO.CalendarDTO::getDate)).collect(Collectors.toList());
return rs;
}
private String getWeekday(String day) {
LocalDate date = LocalDateTimeUtil.parseDate(day, PATTERN_DATE);
DayOfWeek weekday = date.getDayOfWeek();
return weekday.getDisplayName(TextStyle.SHORT, Locale.CHINA);
private CapacityOrderQueryDTO.CalendarDTO getCapacityOneDay(String teamId, List<String> engineerCodes, String date, Integer leastMinutes) {
CapacityOrderQueryDTO.CalendarDTO calendar = new CapacityOrderQueryDTO.CalendarDTO();
calendar.setDate(date);
calendar.setWeek(DateUtils.toWeekChinese(date));
// 暂时是全天
// 总的容量
// List<CapacityEngineerStatEntity> stats = capacityEngineerStatDao.getByWorkdayAndEngineerCodeIn(date, engineerCodes).stream().filter(e->e.getMaxDuration()>leastMinutes).collect(Collectors.toList());
List<CapacityEngineerStatEntity> stats = capacityEngineerStatDao.getByWorkdayAndEngineerCodeIn(date, engineerCodes);
CapacityOrderQueryDTO.TimeDTO timeDTO = new CapacityOrderQueryDTO.TimeDTO();
SpanInfo info = getTimeSpanInfo(teamId, date, "全天", "08~18");
timeDTO.setText(info.getTitle());
timeDTO.setBegin(info.getTimeBegin());
timeDTO.setEnd(info.getTimeEnd());
int total = stats.stream().mapToInt(CapacityEngineerStatEntity::getCapTotal).sum();
int left = stats.stream().mapToInt(CapacityEngineerStatEntity::getCapLeft).sum();
timeDTO.setType(getSpanType(left, total));
calendar.setTimes(List.of(timeDTO));
return calendar;
}
}
......@@ -31,113 +31,11 @@ import java.util.stream.Collectors;
public class CommonServiceImpl implements CommonService {
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private CapacityTeamStatDao capacityTeamStatDao;
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private PubParamsDao pubParamsDao;
public String getTeamIdByInput(String location, String address, String layer) {
// todo 目前会随机兜底,后面将合理化
log.info("====== getTeamIdByInput ===");
String teamId = null;
List<LayerAndArea> layerAndAreas = getLayerAndAreas(location, address);
if (layerAndAreas == null || layerAndAreas.size() == 0) {
// 分单接口没有查到,本地随机处理一下
teamId = capacityTeamStatDao.getRandomTeamIdByLayer(layer);
log.info("分单接口没有查到,本地随机处理一下 ==> {}", teamId);
} else {
// 分单接口查到了areaId(blockId),查询map_block_info,从而限定groupId,然后再随机teamId,这样就相对真实一点
// 生成随机索引
int randomIndex = new Random().nextInt(layerAndAreas.size());
// 获取随机元素
LayerAndArea layerAndArea = layerAndAreas.get(randomIndex);
teamId = mapBlockInfoDao.getTeamIdByBlockIdAndLayer(layerAndArea.areaId, layer);
log.info("分单接口查询返回区块,layerAndArea=={}, teamId=={}", layerAndArea, teamId);
}
if (StringUtils.isEmpty(teamId)) {
teamId = capacityTeamStatDao.getRandomTeamId();
log.info("查询没有teamId,需要随机生成teamId=={}", teamId);
}
log.info("teamId ==> {}", teamId);
assert (StringUtils.isNotEmpty(teamId));
return teamId;
}
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
* 目前layer_info表中,area_data是保存位置围栏的json数据,后面可能会是对于其他图层的引用;
*
* @param location
* @return
*/
private List<LayerAndArea> getLayerAndAreas(String location, String address) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
log.info("===> getLayerAndAreas({}, {})", location, 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");
if (StringUtils.isNotEmpty(location)) {
url = "https://pea-test.bshg.com.cn/v1/xyfendan";
String[] coordinates = location.split(",");
params.add("coordinate", String.format("{\"x\":%s, \"y\":%s}", coordinates[0], coordinates[1]));
} else {
url = "https://pea-test.bshg.com.cn/v2/fendan";
params.add("addresses", String.format("[{\"address\":\"%s\"}]", address));
}
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数据
ObjectMapper objectMapper = new ObjectMapper();
try {
List<LayerAndArea> results = new ArrayList<>();
JsonNode responseJson = objectMapper.readTree(responseBody);
// 获取areaResults[0]的值
for (JsonNode r : responseJson.get("result").get(0).get("areaResults")) {
// 分单接口暂时无图层返回
results.add(new LayerAndArea().setAreaId(r.get("field3").asText()).setAreaName(r.get("field1").asText()));
}
return results;
} catch (Exception e) {
return null;
}
}
@lombok.Data
@Accessors(chain = true)
private static class LayerAndArea {
private String layer;
private String areaId;
private String areaName;
}
public void addOrderEvent(String orderId, String subOrderId, String source, String operator, String event, String content, String memo) {
OrderEventEntity entity = new OrderEventEntity();
......
......@@ -73,8 +73,8 @@ public class DispatchServiceImpl implements DispatchService {
item.setRemark(o.getApplyNote());
item.setCustomerName(o.getName());
String description = String.format("%s:%s%s-%s\n%s:%s", o.getOrderId(), o.getSkill(),
o.getType(), o.getBrand(), o.getName(), o.getAddress());
String description = String.format("%s:%s%s-%s\n%s:%s-%s-%s", o.getOrderId(), o.getSkill(),
o.getType(), o.getBrand(), o.getName(), o.getCity(), o.getCounty(), o.getAddress());
item.setDescription(description);
String key = String.format("%s%s%s", o.getBrand(), o.getType(), o.getSkill());
......
......@@ -2,8 +2,8 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtil;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.CapacityEngineerCalendarDao;
import com.dituhui.pea.order.dao.OrgTeamDao;
import com.dituhui.pea.order.dao.OrgTeamEngineerDao;
......@@ -34,7 +34,7 @@ import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATETIME;
public class EngineerCalendarServiceImpl implements EngineerCalendarService {
@Autowired
private EngineerUtil engineerUtil;
private EngineerUtils engineerUtil;
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
......@@ -141,7 +141,7 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
EngineerCalendarDTO.Calendar calendar = new EngineerCalendarDTO.Calendar();
calendar.setDate(date);
int dayOfWeek = LocalDate.parse(date).getDayOfWeek().getValue();
calendar.setWeek(DateUtil.toWeekChinese(dayOfWeek));
calendar.setWeek(DateUtils.toWeekChinese(dayOfWeek));
EngineerCalendarDTO.Content content = new EngineerCalendarDTO.Content();
List<String> workdays = Arrays.asList(e.getWorkdays().split(","));
if (workdays.contains(String.valueOf(dayOfWeek))) {
......
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.CapacityEngineerStatDao;
import com.dituhui.pea.order.dao.EngineerInfoDao;
import com.dituhui.pea.order.dao.OrderAppointmentDao;
......@@ -39,7 +39,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
private OrderRequestDao orderRequestDao;
@Autowired
private EngineerUtil engineerUtil;
private EngineerUtils engineerUtils;
@Override
public Result<?> getEngineersGanttList(EngineersGanttDTO.Request reqDTO) {
......@@ -85,7 +85,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
.setEngineerName(engineerInfo.getName())
.setGrade(engineerInfo.getGrade());
CapacityEngineerStatEntity capacityEngineerStat = capacityEngineerStatDao.getByEngineerCodeAndWorkday(engineerCode, reqDTO.getDate());
CapacityEngineerStatEntity capacityEngineerStat = capacityEngineerStatDao.getByWorkdayAndEngineerCode(reqDTO.getDate(), engineerCode);
if (capacityEngineerStat == null) {
log.warn("技术员当日的容量数据不存在,{}{}", engineerCode, reqDTO.getDate());
} else {
......@@ -108,39 +108,38 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
if (teamIds != null && teamIds.size() > 0) {
for (String teamId : teamIds) {
engineerCodes.addAll(
engineerUtil.getEngineersByLevel("team", teamId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerUtils.getEngineersByLevel("team", teamId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
} else if (groupIds != null && groupIds.size() > 0) {
for (String groupId : groupIds) {
engineerCodes.addAll(
engineerUtil.getEngineersByLevel("group", groupId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerUtils.getEngineersByLevel("group", groupId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
} else if (branchIds != null && branchIds.size() > 0) {
for (String branchId : branchIds) {
engineerCodes.addAll(
engineerUtil.getEngineersByLevel("branch", branchId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerUtils.getEngineersByLevel("branch", branchId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
} else {
engineerCodes.addAll(engineerUtil.getEngineersByLevel(levelType, levelValue).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerCodes.addAll(engineerUtils.getEngineersByLevel(levelType, levelValue).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
engineerCodes = new ArrayList<>(new HashSet<>(engineerCodes));
if (StringUtils.isBlank(key)) {
return engineerCodes;
} else {
// 最后,还需要根据key进行过滤(需要结合数据库表)
return engineerUtil.filterEngineersByKey(engineerCodes, key).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
return engineerUtils.filterEngineersByKey(engineerCodes, key).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
}
}
public Map<String, OrderRequestEntity> getOrdersByOrderIds(List<String> orderIds) {
List<OrderRequestEntity> orders = orderRequestDao.findAllByOrderIdIn(orderIds);
return orders.stream()
.collect(Collectors.toMap(OrderRequestEntity::getOrderId, order -> order));
return orders.stream().collect(Collectors.toMap(OrderRequestEntity::getOrderId, order -> order));
}
private List<?> getOrderTips(String orderId) {
log.info("==> getOrderTips: orderId[{}]", orderId);
// log.info("==> getOrderTips: orderId[{}]", orderId);
OrderRequestEntity order = orderRequestDao.getByOrderId(orderId);
if (order == null) {
log.error("对应的订单不存在!{}", orderId);
......
......@@ -19,6 +19,8 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.CapacityUtils;
import com.dituhui.pea.order.common.SaasUtils;
import com.dituhui.pea.order.dao.OrderRequestDao;
import com.dituhui.pea.order.dao.OrgTeamDao;
import com.dituhui.pea.order.dao.ProductCategoryDao;
......@@ -59,6 +61,10 @@ public class OrderCreateServiceImpl implements OrderCreateService {
@Autowired
private CommonService commonService;
@Autowired
private CapacityUtils capacityUtils;
@Autowired
private SaasUtils saasUtils;
private List<LabelValueDTO> getPriorities() {
String[] priorities = {"紧急", "正常"};
......@@ -116,9 +122,23 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setCounty(location.getDistrict());
entity.setAddress(location.getFormattedAddress());
// 根据分单,填写clusterId/branchId/groupId/teamId等
String layer = productCategoryDao.getLayerByBrandAndTypeAndSkill(req.getBrand(), req.getType(), req.getSkill());
String loc = String.format("%f,%f", req.getLocation().getLng(), req.getLocation().getLat());
String teamId = commonService.getTeamIdByInput(loc, req.getAddress(), layer);
List<String> layerIds = capacityUtils.getLayers(req.getBrand(), req.getType(), req.getSkill());
List<String> blockIds = saasUtils .queryBlockIds(loc, req.getAddress());
if (blockIds == null || blockIds.size() == 0) {
log.error("分单接口没有查到对应的结果");
Result.failed(String.format("分单接口(address:%s)(location:%s) 没有查到配置区块", req.getAddress(), req.getLocation()));
}
List<String> teamIds = capacityUtils.getTeamIdsByBlockIdsAndLayerIds(blockIds, layerIds);
if (teamIds == null || teamIds.size() == 0) {
Result.failed("没有找到匹配的工作队");
}
// 选择一个工作队(理论上,只有1个合适的工作队),然后遍历下面的各个技术员,从符合技能的技术员中,汇总相关的容量
// 遍历工作队,每个工作队
String teamId = teamIds.get(0);
OrgTeamEntity teamEntity = orgTeamDao.getByTeamId(teamId);
entity.setOrgClusterId(teamEntity.getClusterId());
entity.setOrgBranchId(teamEntity.getBranchId());
......
......@@ -119,7 +119,7 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
record.setSkill(o.getSkill());
record.setName(o.getName());
record.setPhone(o.getPhone());
record.setAddress(o.getAddress());
record.setAddress(String.format("%s-%s-%s", o.getCity(), o.getCounty(),o.getAddress()));
record.setX(o.getX());
record.setY(o.getY());
record.setSource(o.getSource());
......
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*;
......@@ -33,7 +33,7 @@ public class OrganizationServiceImpl implements OrganizationService {
private OrgTeamDao orgTeamDao;
@Autowired
private EngineerUtil engineerUtil;
private EngineerUtils engineerUtils;
@Override
public Result<?> getOrganizationTree(String levelType, String levelValue) {
......@@ -115,7 +115,7 @@ public class OrganizationServiceImpl implements OrganizationService {
@Override
public Result<?> getEngineersByLevel(String levelType, String levelValue) {
List<EngineerInfoEntity> engineers = engineerUtil.getEngineersByLevel(levelType, levelValue);
List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue);
List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> {
return new OrganizationEngineersDTO.Engineer()
.setEngineerCode(entity.getEngineerCode())
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!