Commit 6cd6bfbe by 刘鑫

feat(工程师容量): 改派到人容量查询接口逻辑完善

1 parent 1c76361d
......@@ -5,9 +5,6 @@ import com.dituhui.pea.common.Result;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.order.common.jackson.DateUtil;
import com.dituhui.pea.order.common.jackson.JsonUtil;
import com.dituhui.pea.order.dto.param.*;
import com.dituhui.pea.order.enums.OrderStatusEnum;
import com.dituhui.pea.order.enums.ServiceStatusEnum;
import com.dituhui.pea.order.dao.TableCodeCheckDao;
import com.dituhui.pea.order.dto.param.BaseDistance;
import com.dituhui.pea.order.dto.param.BaseDistanceParam;
......@@ -43,13 +40,11 @@ import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.stream.Collectors;
/**
......@@ -127,15 +122,15 @@ public class PeaApiController {
.map(source -> {
TypeCodeCheckTableEntity brand = tableCodeCheckDao.findByTypeAndCode("BRAND", source.getBrand());
if (Objects.isNull(brand)) {
throw new BusinessException("查询不到:"+ source.getBrand() + "对应的品牌");
throw new BusinessException("查询不到:" + source.getBrand() + "对应的品牌");
}
TypeCodeCheckTableEntity type = tableCodeCheckDao.findByTypeAndCode("TYPE", source.getProductType());
if (Objects.isNull(type)) {
throw new BusinessException("查询不到:"+ source.getProductType() + "对应的产品类型");
throw new BusinessException("查询不到:" + source.getProductType() + "对应的产品类型");
}
TypeCodeCheckTableEntity skill = tableCodeCheckDao.findByTypeAndCode("SKILL", source.getServiceType());
if (Objects.isNull(skill)) {
throw new BusinessException("查询不到:"+ source.getServiceType() + "对应的技能");
throw new BusinessException("查询不到:" + source.getServiceType() + "对应的技能");
}
CapacityQueryDTO.Service service = new CapacityQueryDTO.Service();
......@@ -172,22 +167,11 @@ public class PeaApiController {
@RequestParam("beginDate") Date beginDate,
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
Date endDate) throws IOException {
Date endDate) {
ArrayList<String> strings = new ArrayList<>();
strings.add(half_capacity);
strings.add(day_capacity);
strings.add(half_capacity2);
strings.add(date_capacity);
Random random = new Random();
int i = random.nextInt(4);
CapacityQueryDTO.Result resultTemp = JsonUtil.parse(strings.get(i), CapacityQueryDTO.Result.class).get();
CapacityQueryDTO.PersonalResult result = new CapacityQueryDTO.PersonalResult();
result.setDatas(resultTemp.getDatas());
result.setEngineerCode(engineerCode);
CapacityQueryDTO.PersonalResult result = capacityQueryService.queryEngineerCapacity(engineerCode,
beginDate.toInstant().atZone(ZoneId.of("+8")).toLocalDate(),
endDate.toInstant().atZone(ZoneId.of("+8")).toLocalDate());
return Result.success(result);
}
......
......@@ -156,7 +156,6 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
LocalTime.of(8, 0),
LocalTime.of(18, 0)));
LocalDate currentDate = beginDate;
//定义返回值
CapacityQueryDTO.Result result = new CapacityQueryDTO.Result();
result.setGroupId(groupList.get(0));
......@@ -168,6 +167,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
Semaphore semaphore = new Semaphore(corePoolSize);
List<Future<CapacityQueryDTO.Data>> futureDatas = new ArrayList<>();
LocalDate currentDate = beginDate;
while (!currentDate.isAfter(endDate)) {
log.info("【matchCapacityData】----------->开始计算{}的容量", currentDate);
Task task = new Task(allFulfillEngineer, currentDate, halfDayTypeTimeSlice,
......@@ -245,8 +245,37 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
@Override
public CapacityQueryDTO.PersonalResult queryEngineerCapacity(String engineerCode, LocalDate startDate, LocalDate endDate) {
//
return null;
// 根据工程师编号获取工程师信息
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(engineerCode);
if (Objects.isNull(engineerInfo)) {
throw new BusinessException("未查找到工号为" + engineerCode + "的工程师信息");
}
//查询单个工程师日期范围内的技能容量信息 后加和汇总
CopyOnWriteArrayList<TimeSliceEntity> halfDayTypeTimeSlice = new CopyOnWriteArrayList<>(timeSliceDao.findByType("HALF_DAY"));
CopyOnWriteArrayList<TimeSliceEntity> allDayTypeTimeSlice = new CopyOnWriteArrayList<>(timeSliceDao.findByType("ALL_DAY"));
CopyOnWriteArrayList<TimeSliceEntity> timeSliceEntities = new CopyOnWriteArrayList<>(sliceTime(LocalDate.now(),
LocalTime.of(8, 0),
LocalTime.of(18, 0)));
LocalDate currentDate = startDate;
ArrayList<CapacityQueryDTO.Data> resultData = new ArrayList<>();
while (!currentDate.isAfter(endDate)) {
log.info("【matchCapacityData】----------->开始计算工程师{}在{}的容量", engineerCode, currentDate);
//获取工程师当天不同时间类型的容量数据
List<CapacityEngineerSliceUsedEntity> engineerTimeSlice = engineerSliceUsedCapacityDao
.findByWorkdayAndEngineerCode(DateTimeUtil.formatDate(currentDate), engineerCode);
CapacityQueryDTO.Data data = getData(currentDate, halfDayTypeTimeSlice, 1, allDayTypeTimeSlice,
timeSliceEntities, engineerTimeSlice);
resultData.add(data);
currentDate = currentDate.plusDays(1);
}
CapacityQueryDTO.PersonalResult result = new CapacityQueryDTO.PersonalResult();
result.setEngineerCode(engineerInfo.getEngineerCode());
result.setEngineerName(engineerInfo.getName());
result.setDatas(resultData);
return result;
}
@Override
......@@ -396,28 +425,37 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
allEngineerTimeSlice.addAll(engineerTimeSlice);
}
}
List<CapacityQueryDTO.Segment> objects = new ArrayList<>();
//计算所有工程师全天天类型容量
if (CollectionUtils.isNotEmpty(allDayTypeTimeSlice)) {
List<CapacityQueryDTO.Segment> engineerAllDay = CapacityUtils.getEngineerTypeDay(allDayTypeTimeSlice,
allEngineerTimeSlice, currentDate, totalTakeTime);
objects.addAll(engineerAllDay);
}
//计算所有工程师半天类型容量
if (CollectionUtils.isNotEmpty(halfDayTypeTimeSlice)) {
List<CapacityQueryDTO.Segment> engineerHalfDay = CapacityUtils.getEngineerTypeDay(halfDayTypeTimeSlice,
allEngineerTimeSlice, currentDate, totalTakeTime);
objects.addAll(engineerHalfDay);
}
//计算所有工程师时间段类型容量
List<CapacityQueryDTO.Segment> timeSliceTwoHour = CapacityUtils.getEngineerTypeDay(timeSliceEntities,
return CapacityQueryServiceImpl.getData(currentDate, halfDayTypeTimeSlice, totalTakeTime,
allDayTypeTimeSlice, timeSliceEntities, allEngineerTimeSlice);
}
}
private static CapacityQueryDTO.Data getData(LocalDate currentDate, List<TimeSliceEntity> halfDayTypeTimeSlice,
int totalTakeTime,
List<TimeSliceEntity> allDayTypeTimeSlice,
List<TimeSliceEntity> timeSliceEntities,
List<CapacityEngineerSliceUsedEntity> allEngineerTimeSlice) {
List<CapacityQueryDTO.Segment> objects = new ArrayList<>();
//计算所有工程师全天天类型容量
if (CollectionUtils.isNotEmpty(allDayTypeTimeSlice)) {
List<CapacityQueryDTO.Segment> engineerAllDay = CapacityUtils.getEngineerTypeDay(allDayTypeTimeSlice,
allEngineerTimeSlice, currentDate, totalTakeTime);
objects.addAll(timeSliceTwoHour);
CapacityQueryDTO.Data data = new CapacityQueryDTO.Data();
data.setDate(DateUtil.toDate(currentDate));
data.setSegments(objects);
return data;
objects.addAll(engineerAllDay);
}
//计算所有工程师半天类型容量
if (CollectionUtils.isNotEmpty(halfDayTypeTimeSlice)) {
List<CapacityQueryDTO.Segment> engineerHalfDay = CapacityUtils.getEngineerTypeDay(halfDayTypeTimeSlice,
allEngineerTimeSlice, currentDate, totalTakeTime);
objects.addAll(engineerHalfDay);
}
//计算所有工程师时间段类型容量
List<CapacityQueryDTO.Segment> timeSliceTwoHour = CapacityUtils.getEngineerTypeDay(timeSliceEntities,
allEngineerTimeSlice, currentDate, totalTakeTime);
objects.addAll(timeSliceTwoHour);
CapacityQueryDTO.Data data = new CapacityQueryDTO.Data();
data.setDate(DateUtil.toDate(currentDate));
data.setSegments(objects);
return data;
}
private SpanInfo getTimeSpanInfo(String teamId, String date, String timeSpan, String timeSpanDetail) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!