|
|
|
|
@@ -0,0 +1,120 @@
|
|
|
|
|
package com.xinda.itsm.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.xinda.common.core.domain.entity.SysDictData;
|
|
|
|
|
import com.xinda.common.core.domain.entity.SysUser;
|
|
|
|
|
import com.xinda.common.utils.DateUtils;
|
|
|
|
|
import com.xinda.itsm.domain.InspectionRecord;
|
|
|
|
|
import com.xinda.itsm.domain.RepairOrder;
|
|
|
|
|
import com.xinda.itsm.domain.enums.InspectionRecordStatus;
|
|
|
|
|
import com.xinda.itsm.domain.enums.RepairOrderStatus;
|
|
|
|
|
import com.xinda.itsm.domain.vo.StateCountVo;
|
|
|
|
|
import com.xinda.itsm.mapper.InspectionRecordMapper;
|
|
|
|
|
import com.xinda.itsm.mapper.RepairOrderMapper;
|
|
|
|
|
import com.xinda.itsm.service.ItsmService;
|
|
|
|
|
import com.xinda.system.mapper.SysDictDataMapper;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.xinda.common.utils.SecurityUtils.getLoginUser;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class ItsmServiceImpl implements ItsmService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RepairOrderMapper repairOrderMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private InspectionRecordMapper inspectionRecordMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysDictDataMapper sysDictDataMapper;
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> countRepairAndInspection() {
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
List<StateCountVo> repairCounts = new ArrayList<>();
|
|
|
|
|
List<StateCountVo> inspectionCounts = new ArrayList<>();
|
|
|
|
|
// 登录用户的所有工单
|
|
|
|
|
SysUser user = getLoginUser().getUser();
|
|
|
|
|
RepairOrder repairOrder = new RepairOrder();
|
|
|
|
|
repairOrder.setUserId(user.getUserId());
|
|
|
|
|
List<RepairOrder> repairs = repairOrderMapper.selectRepairOrderList(repairOrder);
|
|
|
|
|
// 登录用户的所有巡检
|
|
|
|
|
InspectionRecord inspectionRecord = new InspectionRecord();
|
|
|
|
|
inspectionRecord.setUserId(user.getUserId().toString());
|
|
|
|
|
List<InspectionRecord> inspections = inspectionRecordMapper.selectInspectionRecordList(inspectionRecord);
|
|
|
|
|
|
|
|
|
|
// 统计所有状态工单的数量
|
|
|
|
|
List<SysDictData> repairStates = sysDictDataMapper.selectDictDataByType("repair_status");
|
|
|
|
|
Map<String, Long> repairCount = repairs.stream().collect(Collectors.groupingBy(RepairOrder::getOrderStatus, Collectors.counting()));
|
|
|
|
|
for (SysDictData dictData : repairStates) {
|
|
|
|
|
Long value = 0L;
|
|
|
|
|
if(repairCount.keySet().contains(dictData.getDictValue())) {
|
|
|
|
|
value = repairCount.remove(dictData.getDictValue());
|
|
|
|
|
}
|
|
|
|
|
if(dictData.getDictValue().equals(RepairOrderStatus.CARRIED_OUT.getCode())) {
|
|
|
|
|
repairCount.put(RepairOrderStatus.CARRIED_OUT.getInfo(), value);
|
|
|
|
|
}
|
|
|
|
|
if(dictData.getDictValue().equals(RepairOrderStatus.IN_PROGRESS.getCode())) {
|
|
|
|
|
repairCount.put(RepairOrderStatus.IN_PROGRESS.getInfo(), value);
|
|
|
|
|
}
|
|
|
|
|
if(dictData.getDictValue().equals(RepairOrderStatus.COMPLETED.getCode())) {
|
|
|
|
|
repairCount.put(RepairOrderStatus.COMPLETED.getInfo(), value);
|
|
|
|
|
}
|
|
|
|
|
if(dictData.getDictValue().equals(RepairOrderStatus.CANCELED.getCode())) {
|
|
|
|
|
repairCount.put(RepairOrderStatus.CANCELED.getInfo(), value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
repairCount.put("total", (long) repairs.size());
|
|
|
|
|
result.put("repairCount", repairCount);
|
|
|
|
|
|
|
|
|
|
// 统计所有状态的巡检数量
|
|
|
|
|
List<SysDictData> inspectionStates = sysDictDataMapper.selectDictDataByType("inspection_record_status");
|
|
|
|
|
Map<String, Long> inspectionCount = inspections.stream().collect(Collectors.groupingBy(InspectionRecord::getInspectionStatus, Collectors.counting()));
|
|
|
|
|
for (SysDictData dictData : inspectionStates) {
|
|
|
|
|
Long value = 0L;
|
|
|
|
|
if(inspectionCount.keySet().contains(dictData.getDictValue())) {
|
|
|
|
|
value = inspectionCount.remove(dictData.getDictValue());
|
|
|
|
|
}
|
|
|
|
|
if(dictData.getDictValue().equals(InspectionRecordStatus.IN_PROGRESS.getCode())) {
|
|
|
|
|
inspectionCount.put(RepairOrderStatus.IN_PROGRESS.getInfo(), value);
|
|
|
|
|
}
|
|
|
|
|
if(dictData.getDictValue().equals(InspectionRecordStatus.COMPLETED.getCode())) {
|
|
|
|
|
inspectionCount.put(RepairOrderStatus.COMPLETED.getInfo(), value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
inspectionCount.put("total", (long) inspections.size());
|
|
|
|
|
result.put("inspectionCount", inspectionCount);
|
|
|
|
|
|
|
|
|
|
Date start = DateUtils.addYears(DateUtils.getNowDate(),-1);
|
|
|
|
|
// 查询近12个月工单数量
|
|
|
|
|
for (int i = 1; i < 13; i++) {
|
|
|
|
|
Date begin = DateUtils.addMonths(start, i);
|
|
|
|
|
Date finish = DateUtils.addMonths(start, i + 1);
|
|
|
|
|
|
|
|
|
|
StateCountVo repairCountVo = new StateCountVo();
|
|
|
|
|
long repairTotal = repairs.stream().filter(r->r.getUpdateTime().after(begin) && r.getUpdateTime().before(finish)).count();
|
|
|
|
|
long repairCompleted = repairs.stream().filter(r->r.getOrderStatus().equals(RepairOrderStatus.COMPLETED.getCode())
|
|
|
|
|
&& r.getUpdateTime().after(begin) && r.getUpdateTime().before(finish)).count();
|
|
|
|
|
repairCountVo.setTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM,begin));
|
|
|
|
|
repairCountVo.setFinished(repairCompleted);
|
|
|
|
|
repairCountVo.setUnfinished(repairTotal-repairCompleted);
|
|
|
|
|
repairCounts.add(repairCountVo);
|
|
|
|
|
|
|
|
|
|
StateCountVo inspectionCountVo = new StateCountVo();
|
|
|
|
|
long inspectionTotal = inspections.stream().filter(r->r.getUpdateTime().after(begin) && r.getUpdateTime().before(finish)).count();
|
|
|
|
|
long inspectionCompleted = inspections.stream().filter(r->r.getInspectionStatus().equals(InspectionRecordStatus.COMPLETED.getCode())
|
|
|
|
|
&& r.getUpdateTime().after(begin) && r.getUpdateTime().before(finish)).count();
|
|
|
|
|
inspectionCountVo.setTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM,begin));
|
|
|
|
|
inspectionCountVo.setFinished(inspectionCompleted);
|
|
|
|
|
inspectionCountVo.setUnfinished(inspectionTotal-inspectionCompleted);
|
|
|
|
|
inspectionCounts.add(inspectionCountVo);
|
|
|
|
|
}
|
|
|
|
|
result.put("repairs",repairCounts);
|
|
|
|
|
result.put("inspections", inspectionCounts);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|