package com.qianwen.smartman.modules.andon.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.constant.ExcelConstant;
|
import com.qianwen.smartman.common.utils.AbstractSqlAdapter;
|
import com.qianwen.smartman.common.utils.Lambda;
|
import com.qianwen.smartman.common.utils.TimeUtils;
|
import com.qianwen.core.excel.util.ExcelUtil;
|
import com.qianwen.core.mp.support.Condition;
|
import com.qianwen.core.mp.support.Query;
|
import com.qianwen.core.oss.model.BladeFile;
|
import com.qianwen.core.tool.utils.DateUtil;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.andon.convert.AndonRecordConvert;
|
import com.qianwen.smartman.modules.andon.entity.AndonRecord;
|
import com.qianwen.smartman.modules.andon.entity.AndonRecordReason;
|
import com.qianwen.smartman.modules.andon.enums.AndonStatusEnum;
|
import com.qianwen.smartman.modules.andon.excel.AndonCallRecordExport;
|
import com.qianwen.smartman.modules.andon.service.IAndonCallRecordService;
|
import com.qianwen.smartman.modules.andon.service.IAndonRecordReasonService;
|
import com.qianwen.smartman.modules.andon.service.IAndonRecordService;
|
import com.qianwen.smartman.modules.andon.vo.AndonCallRecordResVO;
|
import com.qianwen.smartman.modules.andon.vo.AndonCallRecordSearchVO;
|
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.multipart.MultipartFile;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/andon/service/impl/AndonCallRecordServiceImpl.class */
|
public class AndonCallRecordServiceImpl implements IAndonCallRecordService {
|
private final IAndonRecordService recordService;
|
|
private final IAndonRecordReasonService reasonService;
|
|
private final OssBuilder ossBuilder;
|
|
public AndonCallRecordServiceImpl(IAndonRecordService recordService, IAndonRecordReasonService reasonService, OssBuilder ossBuilder) {
|
this.recordService = recordService;
|
this.reasonService = reasonService;
|
this.ossBuilder = ossBuilder;
|
}
|
|
|
@Override // org.springblade.modules.andon.service.IAndonCallRecordService
|
public IPage<AndonCallRecordResVO> pageQueryRecord(Query query, AndonCallRecordSearchVO vo) {
|
QueryWrapper<AndonRecord> wrapper = getWrapper(vo);
|
IPage<AndonRecord> page = this.recordService.page(Condition.getPage(query), wrapper);
|
List<AndonRecord> records = page.getRecords();
|
Map<Long, List<AndonRecordReason>> recordReasonMap = (Map<Long, List<AndonRecordReason>>)this.reasonService.list().stream().collect(Collectors.groupingBy(AndonRecordReason::getRecordId));
|
List<AndonCallRecordResVO> vos = (List<AndonCallRecordResVO>)records.stream().map(c -> convert(c, recordReasonMap)).collect(Collectors.toList());
|
Page<AndonCallRecordResVO> page1 = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
page1.setRecords(vos);
|
return page1;
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonCallRecordService
|
public BladeFile exportRecord(AndonCallRecordSearchVO vo) {
|
List<AndonRecord> records = this.recordService.list(getWrapper(vo));
|
Map<Long, List<AndonRecordReason>> recordReasonMap = (Map<Long, List<AndonRecordReason>>)this.reasonService.list().stream().collect(Collectors.groupingBy(AndonRecordReason::getRecordId));
|
List<AndonCallRecordExport> exports = (List<AndonCallRecordExport>)records.stream().map(c -> convertExport(c, recordReasonMap)).collect(Collectors.toList());
|
String fileName = String.format("%s-%s.xlsx", new Object[] { "安灯确认记录", DateUtil.time() });
|
String sheetName = "安灯确认记录";
|
MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, sheetName, exports, AndonCallRecordExport.class);
|
return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
|
}
|
|
private AndonCallRecordExport convertExport(AndonRecord record, Map<Long, List<AndonRecordReason>> recordReasonMap) {
|
long callTotalTime;
|
AndonCallRecordExport export = AndonRecordConvert.INSTANCE.convertExport(record);
|
export.setCallTime(DateUtil.formatDateTime(record.getCallTime()));
|
if (Func.notNull(record.getResponseTime())) {
|
export.setResponseTime(DateUtil.formatDateTime(record.getResponseTime()));
|
}
|
if (Func.notNull(record.getEndTime())) {
|
export.setEndTime(DateUtil.formatDateTime(record.getEndTime()));
|
}
|
Integer curStatus = record.getCurStatus();
|
Date now = DateUtil.now();
|
if (AndonStatusEnum.COMPLETE.getStatus().equals(curStatus)) {
|
callTotalTime = DateUtil.between(record.getEndTime(), record.getCallTime()).getSeconds();
|
} else {
|
callTotalTime = DateUtil.between(now, record.getCallTime()).getSeconds();
|
}
|
export.setCallTotalTime(TimeUtils.getUseTime(callTotalTime));
|
Long handTotalTime = null;
|
if (AndonStatusEnum.COMPLETE.getStatus().equals(curStatus)) {
|
handTotalTime = Long.valueOf(DateUtil.between(record.getEndTime(), record.getResponseTime()).getSeconds());
|
} else if (AndonStatusEnum.ALREADY_RECEIVED.getStatus().equals(curStatus)) {
|
handTotalTime = Long.valueOf(DateUtil.between(now, record.getResponseTime()).getSeconds());
|
}
|
export.setHandTotalTime(handTotalTime == null ? "-" : TimeUtils.getUseTime(handTotalTime.longValue()));
|
if (Func.notNull(record.getResponseTime())) {
|
export.setResponseTotalTime(TimeUtils.getUseTime(DateUtil.between(record.getResponseTime(), record.getCallTime()).getSeconds()));
|
}
|
Optional.ofNullable(recordReasonMap.get(record.getId())).ifPresent(rs -> {
|
String reasonCode = (String) rs.stream().map((v0) -> {
|
return v0.getReasonCode();
|
}).collect(Collectors.joining(","));
|
export.setReasonCode(reasonCode);
|
String reasonName = (String) rs.stream().map((v0) -> {
|
return v0.getReasonName();
|
}).collect(Collectors.joining(","));
|
export.setReasonName(reasonName);
|
});
|
return export;
|
}
|
|
private QueryWrapper<AndonRecord> getWrapper(AndonCallRecordSearchVO vo) {
|
QueryWrapper<AndonRecord> queryWrapper = (QueryWrapper<AndonRecord>) (((Wrappers.<AndonRecord>query()
|
.eq(Lambda.getName(AndonRecord::getCurStatus), AndonStatusEnum.COMPLETE.getStatus())
|
.in(Func.isNotEmpty(vo.getWorkstationIds()), Lambda.getName(AndonRecord::getWorkstationId),
|
vo.getWorkstationIds()))
|
.in(Func.isNotEmpty(vo.getTypeIds()), Lambda.getName(AndonRecord::getTypeId), vo.getTypeIds()))
|
.in(Func.isNotEmpty(vo.getHandEmpIds()), Lambda.getName(AndonRecord::getHandEmpId), vo.getHandEmpIds()))
|
.in(Func.isNotEmpty(vo.getCallEmpIds()), Lambda.getName(AndonRecord::getCallEmpId), vo.getCallEmpIds());
|
return AbstractSqlAdapter
|
.dateBetweenAdapter(queryWrapper,
|
(Func.notNull(vo.getStartCallTime()) && Func.notNull(vo.getEndCallTime())),
|
Lambda.getName(AndonRecord::getCallTime), vo.getStartCallTime(), vo.getEndCallTime())
|
.orderByDesc(Lambda.getName(AndonRecord::getEndTime))
|
.orderByAsc(Lambda.getName(AndonRecord::getTypeCode));
|
}
|
|
private AndonCallRecordResVO convert(AndonRecord record, Map<Long, List<AndonRecordReason>> recordReasonMap) {
|
long callTotalTime;
|
AndonCallRecordResVO vo = AndonRecordConvert.INSTANCE.convertCall(record);
|
Integer curStatus = record.getCurStatus();
|
Date now = DateUtil.now();
|
if (AndonStatusEnum.COMPLETE.getStatus().equals(curStatus)) {
|
callTotalTime = DateUtil.between(record.getEndTime(), record.getCallTime()).getSeconds();
|
} else {
|
callTotalTime = DateUtil.between(now, record.getCallTime()).getSeconds();
|
}
|
vo.setCallTotalTime(Integer.valueOf(Math.abs(Math.toIntExact(callTotalTime))));
|
Long handTotalTime = null;
|
if (AndonStatusEnum.COMPLETE.getStatus().equals(curStatus)) {
|
handTotalTime = Long.valueOf(DateUtil.between(record.getEndTime(), record.getResponseTime()).getSeconds());
|
} else if (AndonStatusEnum.ALREADY_RECEIVED.getStatus().equals(curStatus)) {
|
handTotalTime = Long.valueOf(DateUtil.between(now, record.getResponseTime()).getSeconds());
|
}
|
vo.setHandTotalTime((handTotalTime == null) ? null : Integer.valueOf(Math.abs(Math.toIntExact(handTotalTime.longValue()))));
|
if (Func.notNull(record.getResponseTime()))
|
vo.setResponseTotalTime(Integer.valueOf(Math.abs(Math.toIntExact(DateUtil.between(record.getResponseTime(), record.getCallTime()).getSeconds()))));
|
Optional.ofNullable(recordReasonMap.get(record.getId()))
|
.ifPresent(rs -> {
|
String reasonCode = rs.stream().map(AndonRecordReason::getReasonCode).collect(Collectors.joining(","));
|
vo.setReasonCode(reasonCode);
|
String reasonName = rs.stream().map(AndonRecordReason::getReasonName).collect(Collectors.joining(","));
|
vo.setReasonName(reasonName);
|
});
|
return vo;
|
}
|
}
|