package com.qianwen.smartman.modules.andon.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.google.common.collect.Lists;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.LocalTime;
|
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.TemporalUnit;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
import com.qianwen.smartman.common.cache.cps.TimeSliceCache;
|
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
|
import com.qianwen.core.mp.support.Query;
|
import com.qianwen.core.tool.support.Kv;
|
import com.qianwen.core.tool.utils.DateUtil;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.andon.dto.ShiftTimeDTO;
|
import com.qianwen.smartman.modules.andon.entity.AndonRecord;
|
import com.qianwen.smartman.modules.andon.enums.WorkType;
|
import com.qianwen.smartman.modules.andon.service.IAndonRecordService;
|
import com.qianwen.smartman.modules.andon.service.IAndonStatisticsService;
|
import com.qianwen.smartman.modules.andon.vo.AndonStatisticalCardVO;
|
import com.qianwen.smartman.modules.andon.vo.AndonStatisticsSearchVO;
|
import com.qianwen.smartman.modules.andon.vo.AndonTableStatisticalVO;
|
import com.qianwen.smartman.modules.andon.vo.CallTimeDateChartVO;
|
import com.qianwen.smartman.modules.andon.vo.CallTimeSearchVO;
|
import com.qianwen.smartman.modules.andon.vo.CallTimeShiftChartVO;
|
import com.qianwen.smartman.modules.andon.vo.CallTimeTableVO;
|
import com.qianwen.smartman.modules.andon.wrapper.StatisticsAndonWrapper;
|
import com.qianwen.smartman.modules.cps.entity.ShiftDetail;
|
import com.qianwen.smartman.modules.cps.entity.Workstation;
|
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
|
import org.springframework.stereotype.Service;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/andon/service/impl/AndonStatisticsServiceImpl.class */
|
public class AndonStatisticsServiceImpl implements IAndonStatisticsService {
|
private final IAndonRecordService recordService;
|
private final IWorkstationService workstationService;
|
|
public AndonStatisticsServiceImpl(final IAndonRecordService recordService, final IWorkstationService workstationService) {
|
this.recordService = recordService;
|
this.workstationService = workstationService;
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonStatisticsService
|
public AndonStatisticalCardVO statisticalCard(AndonStatisticsSearchVO vo) {
|
switch (WorkType.findByType(vo.getWorkType())) {
|
case GROUP:
|
return groupCard(vo);
|
case WORKSTATION:
|
return workstationCard(vo);
|
default:
|
return new AndonStatisticalCardVO();
|
}
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonStatisticsService
|
public IPage<AndonTableStatisticalVO> tableAndon(Query query, AndonStatisticsSearchVO vo) {
|
switch (WorkType.findByType(vo.getWorkType())) {
|
case GROUP:
|
return groupTableAndon(query, vo);
|
case WORKSTATION:
|
return workstationTableAndon(query, vo);
|
default:
|
return new Page();
|
}
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonStatisticsService
|
public CallTimeShiftChartVO callTimeShiftChart(AndonStatisticsSearchVO vo) {
|
switch (WorkType.findByType(vo.getWorkType())) {
|
case GROUP:
|
return groupCallTimeShiftChart(vo);
|
case WORKSTATION:
|
return workstationCallTimeShiftChart(vo);
|
default:
|
return new CallTimeShiftChartVO();
|
}
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonStatisticsService
|
public CallTimeDateChartVO callTimeDateChart(AndonStatisticsSearchVO vo) {
|
switch (WorkType.findByType(vo.getWorkType())) {
|
case GROUP:
|
return groupCallTimeDateChart(vo);
|
case WORKSTATION:
|
return workstationCallTimeDateChart(vo);
|
default:
|
return new CallTimeDateChartVO();
|
}
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonStatisticsService
|
public IPage<CallTimeTableVO> callTimeTable(CallTimeSearchVO vo) {
|
return null;
|
}
|
|
private CallTimeDateChartVO groupCallTimeDateChart(AndonStatisticsSearchVO vo) {
|
List<Workstation> workstations = this.workstationService.listWorkStationByGroup(vo.getIds());
|
if (Func.isEmpty(workstations)) {
|
return new CallTimeDateChartVO();
|
}
|
List<Long> workstationIds = (List) workstations.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());
|
List<AndonRecord> records = this.recordService.queryCallTime(vo.getStartTime(), vo.getEndTime(), workstationIds);
|
return StatisticsAndonWrapper.build().entity(records, vo);
|
}
|
|
private CallTimeDateChartVO workstationCallTimeDateChart(AndonStatisticsSearchVO vo) {
|
return null;
|
}
|
|
private CallTimeShiftChartVO groupCallTimeShiftChart(AndonStatisticsSearchVO vo) {
|
List<Workstation> workstations = this.workstationService.listWorkStationByGroup(vo.getIds());
|
if (Func.isEmpty(workstations)) {
|
return new CallTimeShiftChartVO();
|
}
|
return getCallTimeShiftChartVO(vo, workstations);
|
}
|
|
private CallTimeShiftChartVO getCallTimeShiftChartVO(AndonStatisticsSearchVO vo, List<Workstation> workstations) {
|
Date startTime = vo.getStartTime();
|
Date endTime = vo.getEndTime();
|
List<LocalDate> dateList = LocalDateTimeUtils.getDateList(LocalDateTimeUtils.dateToLocalDate(startTime), LocalDateTimeUtils.dateToLocalDate(endTime));
|
List<String> calendarCodes = (List) workstations.stream().map((v0) -> {
|
return v0.getCalendarCode();
|
}).filter((v0) -> {
|
return Func.notNull(v0);
|
}).collect(Collectors.toList());
|
Map<String, Map<Integer, List<ShiftTimeDTO>>> timeMap = Kv.newMap();
|
for (LocalDate date : dateList) {
|
List<ShiftTimeDTO> timeDto = Lists.newArrayList();
|
for (String code : calendarCodes) {
|
List<ShiftDetail> detail = TimeSliceCache.getTimeShiftDetail(code, date);
|
List<ShiftTimeDTO> collect = (List) detail.stream().map(dt -> {
|
LocalDateTime start = LocalDateTime.of(date, LocalTime.MIN).plus(dt.getShiftStartTime().intValue(), (TemporalUnit) ChronoUnit.MINUTES);
|
LocalDateTime end = LocalDateTime.of(date, LocalTime.MIN).plus(dt.getShiftEndTime().intValue(), (TemporalUnit) ChronoUnit.MINUTES);
|
return ShiftTimeDTO.builder().indexName(Func.isBlank(dt.getIndexName()) ? "班次" + dt.getShiftIndex() : dt.getIndexName()).shiftIndex(dt.getShiftIndex()).startTime(start).endTime(end).build();
|
}).collect(Collectors.toList());
|
timeDto.addAll(collect);
|
}
|
Map<Integer, List<ShiftTimeDTO>> collect2 = (Map) timeDto.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getShiftIndex();
|
}));
|
timeMap.put(DateUtil.formatDate(date), collect2);
|
}
|
List<Long> workstationIds = (List) workstations.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());
|
List<AndonRecord> records = this.recordService.queryCallTime(startTime, endTime, workstationIds);
|
return StatisticsAndonWrapper.build().entity(timeMap, records, dateList);
|
}
|
|
private CallTimeShiftChartVO workstationCallTimeShiftChart(AndonStatisticsSearchVO vo) {
|
List<Workstation> workstations = this.workstationService.listByIds(vo.getIds());
|
if (Func.isEmpty(workstations)) {
|
return new CallTimeShiftChartVO();
|
}
|
return getCallTimeShiftChartVO(vo, workstations);
|
}
|
|
private IPage<AndonTableStatisticalVO> groupTableAndon(Query query, AndonStatisticsSearchVO vo) {
|
List<Long> ids = vo.getIds();
|
if (Func.isEmpty(ids)) {
|
return new Page();
|
}
|
List<Workstation> workstations = this.workstationService.listWorkStationByGroup(ids);
|
if (Func.isEmpty(workstations)) {
|
return new Page();
|
}
|
return getTableAndon(query, vo, workstations);
|
}
|
|
private IPage<AndonTableStatisticalVO> workstationTableAndon(Query query, AndonStatisticsSearchVO vo) {
|
List<Long> ids = vo.getIds();
|
if (Func.isEmpty(ids)) {
|
return new Page();
|
}
|
List<Workstation> workstations = this.workstationService.listByIds(ids);
|
if (Func.isEmpty(workstations)) {
|
return new Page();
|
}
|
return getTableAndon(query, vo, workstations);
|
}
|
|
private IPage<AndonTableStatisticalVO> getTableAndon(Query query, AndonStatisticsSearchVO vo, List<Workstation> workstations) {
|
return this.recordService.getTableAndon(query, vo.getStartTime(), vo.getEndTime(), (List) workstations.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList()));
|
}
|
|
private AndonStatisticalCardVO groupCard(AndonStatisticsSearchVO vo) {
|
List<Long> ids = vo.getIds();
|
if (Func.isEmpty(ids)) {
|
return new AndonStatisticalCardVO();
|
}
|
List<Workstation> workstations = this.workstationService.listWorkStationByGroup(ids);
|
if (Func.isEmpty(workstations)) {
|
return new AndonStatisticalCardVO();
|
}
|
return getRecords(workstations, vo);
|
}
|
|
private AndonStatisticalCardVO workstationCard(AndonStatisticsSearchVO vo) {
|
List<Long> ids = vo.getIds();
|
if (Func.isEmpty(ids)) {
|
return new AndonStatisticalCardVO();
|
}
|
List<Workstation> workstations = this.workstationService.listByIds(ids);
|
if (Func.isEmpty(workstations)) {
|
return new AndonStatisticalCardVO();
|
}
|
return getRecords(workstations, vo);
|
}
|
|
private AndonStatisticalCardVO getRecords(List<Workstation> workstations, AndonStatisticsSearchVO vo) {
|
return this.recordService.queryCard((List) workstations.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList()), vo.getStartTime(), vo.getEndTime());
|
}
|
}
|