|
@@ -2,7 +2,9 @@ package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.qmth.sop.business.bean.dto.UserDto;
|
|
import com.qmth.sop.business.entity.TBCrm;
|
|
import com.qmth.sop.business.entity.TBCrm;
|
|
import com.qmth.sop.business.entity.TBCrmDetail;
|
|
import com.qmth.sop.business.entity.TBCrmDetail;
|
|
import com.qmth.sop.business.entity.TBDing;
|
|
import com.qmth.sop.business.entity.TBDing;
|
|
@@ -12,15 +14,19 @@ import com.qmth.sop.business.service.*;
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
import com.qmth.sop.common.enums.DingDateTypeEnum;
|
|
import com.qmth.sop.common.enums.DingDateTypeEnum;
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.sop.common.enums.RoleTypeEnum;
|
|
import com.qmth.sop.common.enums.SopRoleTypeEnum;
|
|
import com.qmth.sop.common.enums.SopRoleTypeEnum;
|
|
-import io.swagger.models.auth.In;
|
|
|
|
|
|
+import com.qmth.sop.common.util.DateDisposeUtils;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -35,6 +41,7 @@ import java.util.stream.Collectors;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class TBDingStatisticServiceImpl extends ServiceImpl<TBDingStatisticMapper, TBDingStatistic> implements TBDingStatisticService {
|
|
public class TBDingStatisticServiceImpl extends ServiceImpl<TBDingStatisticMapper, TBDingStatistic> implements TBDingStatisticService {
|
|
|
|
+
|
|
private final static Logger log = LoggerFactory.getLogger(TBDingStatisticServiceImpl.class);
|
|
private final static Logger log = LoggerFactory.getLogger(TBDingStatisticServiceImpl.class);
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
@@ -47,99 +54,169 @@ public class TBDingStatisticServiceImpl extends ServiceImpl<TBDingStatisticMappe
|
|
private TBCrmService tbCrmService;
|
|
private TBCrmService tbCrmService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- private SysUserService sysUserService;
|
|
|
|
|
|
+ private SysUserRoleService sysUserRoleService;
|
|
|
|
|
|
- @Resource
|
|
|
|
- private TBUserArchivesAllocationService tbUserArchivesAllocationService;
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public TBDingStatistic findBySopNoAndUserArchivesId(String sopNo, Long userArchivesId) {
|
|
|
|
+ return this.getOne(new QueryWrapper<TBDingStatistic>().lambda().eq(TBDingStatistic::getSopNo, sopNo).eq(TBDingStatistic::getUserArchivesId, userArchivesId).last(SystemConstant.LIMIT1));
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ @Transactional
|
|
@Override
|
|
@Override
|
|
public void buildDingStatistic(String sopNo) {
|
|
public void buildDingStatistic(String sopNo) {
|
|
-
|
|
|
|
|
|
+ List<RoleTypeEnum> roleTypeList = new ArrayList<>();
|
|
|
|
+ roleTypeList.add(RoleTypeEnum.ADMIN);
|
|
|
|
+ List<UserDto> userDtoList = sysUserRoleService.userListByRoleType(roleTypeList);
|
|
|
|
+ if (CollectionUtils.isEmpty(userDtoList)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("缺少系统管理员用户");
|
|
|
|
+ }
|
|
|
|
+ // 统计前一天的数据
|
|
|
|
+ Long currentEarliestTime = DateDisposeUtils.getEarliestTime(System.currentTimeMillis());
|
|
|
|
+ List<TBDing> datasource = tbDingService.list(new QueryWrapper<TBDing>().lambda().eq(TBDing::getSopNo, sopNo)).stream().filter(e -> {
|
|
|
|
+ if (Objects.nonNull(e.getSignInTime()) && Objects.nonNull(e.getSignOutTime())) {
|
|
|
|
+ return e.getSignInTime() < currentEarliestTime && e.getSignOutTime() < currentEarliestTime;
|
|
|
|
+ } else if (Objects.isNull(e.getSignInTime())) {
|
|
|
|
+ return e.getSignOutTime() < currentEarliestTime;
|
|
|
|
+ } else if (Objects.isNull(e.getSignOutTime())) {
|
|
|
|
+ return e.getSignInTime() < currentEarliestTime;
|
|
|
|
+ } else {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ this.buildDingStatisticBySop(sopNo, datasource, userDtoList.get(0).getId());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional
|
|
@Override
|
|
@Override
|
|
public void buildDingStatistic() {
|
|
public void buildDingStatistic() {
|
|
-
|
|
|
|
- List<TBDing> datasource = tbDingService.list();
|
|
|
|
|
|
+ Long currentEarliestTime = DateDisposeUtils.getEarliestTime(System.currentTimeMillis());
|
|
|
|
+
|
|
|
|
+ // 统计前一天的数据
|
|
|
|
+ List<TBDing> datasource = tbDingService.list().stream().filter(e -> {
|
|
|
|
+ if (Objects.nonNull(e.getSignInTime()) && Objects.nonNull(e.getSignOutTime())) {
|
|
|
|
+ return e.getSignInTime() < currentEarliestTime && e.getSignOutTime() < currentEarliestTime;
|
|
|
|
+ } else if (Objects.isNull(e.getSignInTime())) {
|
|
|
|
+ return e.getSignOutTime() < currentEarliestTime;
|
|
|
|
+ } else if (Objects.isNull(e.getSignOutTime())) {
|
|
|
|
+ return e.getSignInTime() < currentEarliestTime;
|
|
|
|
+ } else {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }).collect(Collectors.toList());
|
|
List<String> sopNoList = datasource.stream().map(TBDing::getSopNo).distinct().collect(Collectors.toList());
|
|
List<String> sopNoList = datasource.stream().map(TBDing::getSopNo).distinct().collect(Collectors.toList());
|
|
-
|
|
|
|
|
|
+ List<RoleTypeEnum> roleTypeList = new ArrayList<>();
|
|
|
|
+ roleTypeList.add(RoleTypeEnum.ADMIN);
|
|
|
|
+ List<UserDto> userDtoList = sysUserRoleService.userListByRoleType(roleTypeList);
|
|
|
|
+ if (CollectionUtils.isEmpty(userDtoList)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("缺少系统管理员用户");
|
|
|
|
+ }
|
|
for (String sopNo : sopNoList) {
|
|
for (String sopNo : sopNoList) {
|
|
- TBCrmDetail tbCrmDetail = tbCrmDetailService.findBySopNo(sopNo);
|
|
|
|
- if (Objects.isNull(tbCrmDetail)){
|
|
|
|
- log.error(String.format("sopNo[%s]未找到派单详情信息",sopNo));
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到派单详情信息");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String crmNo = tbCrmDetail.getCrmNo();
|
|
|
|
- TBCrm tbCrm = tbCrmService.findByCrmNo(crmNo);
|
|
|
|
- if (Objects.isNull(tbCrm)){
|
|
|
|
- log.error(String.format("crmNo[%s]未找到派单信息",crmNo));
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到派单信息");
|
|
|
|
- }
|
|
|
|
|
|
+ List<TBDing> sopDingInfo = datasource.stream().filter(e -> e.getSopNo().equals(sopNo)).collect(Collectors.toList());
|
|
|
|
+ this.buildDingStatisticBySop(sopNo, sopDingInfo, userDtoList.get(0).getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public void buildDingStatisticBySop(String sopNo, List<TBDing> datasource, Long requestUserId) {
|
|
|
|
+ List<TBDingStatistic> tbDingStatisticList = new ArrayList<>();
|
|
|
|
+ TBCrmDetail tbCrmDetail = tbCrmDetailService.findBySopNo(sopNo);
|
|
|
|
+ if (Objects.isNull(tbCrmDetail)) {
|
|
|
|
+ log.error(String.format("sopNo[%s]未找到派单详情信息", sopNo));
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未找到派单详情信息");
|
|
|
|
+ }
|
|
|
|
|
|
- Long serviceUnitId = tbCrm.getServiceId();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- Long scanStartTime = tbCrmDetail.getScanStartTime();
|
|
|
|
- Long scanEndTime = tbCrmDetail.getScanEndTime();
|
|
|
|
- Long markPaperStartTime = tbCrmDetail.getMarkPaperStartTime();
|
|
|
|
- Long markPaperEndTime = tbCrmDetail.getMarkPaperEndTime();
|
|
|
|
- // 该sop计划有效的日期
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- List<Long> userArchivesIdList = datasource.stream().filter(e -> Objects.equals(sopNo, e.getSopNo())).map(TBDing::getUserArchivesId).distinct().collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- for (Long archivesId : userArchivesIdList) {
|
|
|
|
- // 打卡数据集合
|
|
|
|
- List<TBDing> dingList = datasource.stream()
|
|
|
|
- .filter(e -> Objects.equals(sopNo, e.getSopNo()) && Objects.equals(archivesId, e.getUserArchivesId())).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- // 非异常打卡(打卡时间在计划时间范围内 以及 缺少签到或签退的)
|
|
|
|
- List<TBDing> effectDingList = dingList.stream().filter(e -> !e.getDingException()).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- List<SopRoleTypeEnum> sopRoleTypeList = dingList.stream().flatMap(e -> {
|
|
|
|
- String sopRoleTypeStr = e.getSopRoleType();
|
|
|
|
- List<SopRoleTypeEnum> list = JSONArray.parseArray(sopRoleTypeStr, SopRoleTypeEnum.class);
|
|
|
|
- return list.stream();
|
|
|
|
- }).distinct().collect(Collectors.toList());
|
|
|
|
- String sopRoleType = JSON.toJSONString(sopRoleTypeList);
|
|
|
|
-
|
|
|
|
- // 根据非异常打卡数据统计
|
|
|
|
- int actualDays = 0;
|
|
|
|
- int weekDays = 0;
|
|
|
|
- int weekends = 0;
|
|
|
|
- int legalHolidays = 0;
|
|
|
|
- BigDecimal workHours = BigDecimal.ZERO;
|
|
|
|
- BigDecimal var = new BigDecimal(3600000);
|
|
|
|
- for (TBDing effectDing : effectDingList) {
|
|
|
|
- if (!SystemConstant.isOneNull(effectDing.getSignInTime(), effectDing.getSignOutTime())){
|
|
|
|
- // 有效天数
|
|
|
|
- actualDays ++;
|
|
|
|
- DingDateTypeEnum dateType = effectDing.getDateType();
|
|
|
|
- switch (dateType){
|
|
|
|
- case WEEKEND:
|
|
|
|
- weekends ++;
|
|
|
|
- break;
|
|
|
|
- case LEGAL_HOLIDAYS:
|
|
|
|
- legalHolidays ++;
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- weekDays ++;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- // 累计工时
|
|
|
|
- workHours = workHours.add(new BigDecimal(effectDing.getSignOutTime() - effectDing.getSignInTime()).divide(var, 1,
|
|
|
|
- RoundingMode.HALF_UP));
|
|
|
|
|
|
+ String crmNo = tbCrmDetail.getCrmNo();
|
|
|
|
+ TBCrm tbCrm = tbCrmService.findByCrmNo(crmNo);
|
|
|
|
+ if (Objects.isNull(tbCrm)) {
|
|
|
|
+ log.error(String.format("crmNo[%s]未找到派单信息", crmNo));
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未找到派单信息");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long serviceUnitId = tbCrm.getServiceId();
|
|
|
|
+
|
|
|
|
+ Long scanStartTime = tbCrmDetail.getScanStartTime();
|
|
|
|
+ Long scanEndTime = tbCrmDetail.getScanEndTime();
|
|
|
|
+ Long markPaperStartTime = tbCrmDetail.getMarkPaperStartTime();
|
|
|
|
+ Long markPaperEndTime = tbCrmDetail.getMarkPaperEndTime();
|
|
|
|
+ // 该sop计划有效的日期
|
|
|
|
+
|
|
|
|
+ List<Long> userArchivesIdList = datasource.stream().filter(e -> Objects.equals(sopNo, e.getSopNo())).map(TBDing::getUserArchivesId).distinct().collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ for (Long userArchivesId : userArchivesIdList) {
|
|
|
|
+ // 打卡数据集合
|
|
|
|
+ List<TBDing> dingList = datasource.stream()
|
|
|
|
+ .filter(e -> Objects.equals(sopNo, e.getSopNo()) && Objects.equals(userArchivesId, e.getUserArchivesId())).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 非异常打卡(打卡时间在计划时间范围内 以及 缺少签到或签退的)
|
|
|
|
+ List<TBDing> effectDingList = dingList.stream().filter(e -> !e.getDingException()).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ List<SopRoleTypeEnum> sopRoleTypeList = dingList.stream().flatMap(e -> {
|
|
|
|
+ String sopRoleTypeStr = e.getSopRoleType();
|
|
|
|
+ List<SopRoleTypeEnum> list = JSONArray.parseArray(sopRoleTypeStr, SopRoleTypeEnum.class);
|
|
|
|
+ return list.stream();
|
|
|
|
+ }).distinct().collect(Collectors.toList());
|
|
|
|
+ String sopRoleType = JSON.toJSONString(sopRoleTypeList);
|
|
|
|
+
|
|
|
|
+ // 根据非异常打卡数据统计
|
|
|
|
+ int actualDays = 0;
|
|
|
|
+ int weekDays = 0;
|
|
|
|
+ int weekends = 0;
|
|
|
|
+ int legalHolidays = 0;
|
|
|
|
+ BigDecimal workHours = BigDecimal.ZERO;
|
|
|
|
+ BigDecimal var = new BigDecimal(3600000);
|
|
|
|
+ for (TBDing effectDing : effectDingList) {
|
|
|
|
+ if (!SystemConstant.isOneNull(effectDing.getSignInTime(), effectDing.getSignOutTime())) {
|
|
|
|
+ // 有效天数
|
|
|
|
+ actualDays++;
|
|
|
|
+ DingDateTypeEnum dateType = effectDing.getDateType();
|
|
|
|
+ switch (dateType) {
|
|
|
|
+ case WEEKEND:
|
|
|
|
+ weekends++;
|
|
|
|
+ break;
|
|
|
|
+ case LEGAL_HOLIDAYS:
|
|
|
|
+ legalHolidays++;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ weekDays++;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
+ // 累计工时
|
|
|
|
+ workHours = workHours.add(
|
|
|
|
+ new BigDecimal(effectDing.getSignOutTime() - effectDing.getSignInTime()).divide(var, 1,
|
|
|
|
+ RoundingMode.HALF_UP));
|
|
}
|
|
}
|
|
- // 违规工时
|
|
|
|
- int violationDays = Math.toIntExact(
|
|
|
|
- dingList.stream().filter(e -> SystemConstant.isOneNull(e.getSignInTime(), e.getSignOutTime()))
|
|
|
|
- .count());
|
|
|
|
-
|
|
|
|
- TBDingStatistic tbDingStatistic = new TBDingStatistic();
|
|
|
|
- // TODO: 2024/5/23 新增实体对象-czx
|
|
|
|
}
|
|
}
|
|
|
|
+ // 违规工时
|
|
|
|
+ int violationDays = Math.toIntExact(
|
|
|
|
+ dingList.stream().filter(e -> SystemConstant.isOneNull(e.getSignInTime(), e.getSignOutTime()))
|
|
|
|
+ .count());
|
|
|
|
+
|
|
|
|
+ TBDingStatistic tbDingStatistic;
|
|
|
|
+ tbDingStatistic = this.findBySopNoAndUserArchivesId(sopNo, userArchivesId);
|
|
|
|
+ if (Objects.isNull(tbDingStatistic)) {
|
|
|
|
+ tbDingStatistic = new TBDingStatistic();
|
|
|
|
+ tbDingStatistic.insertInfo(requestUserId);
|
|
|
|
+ } else {
|
|
|
|
+ tbDingStatistic.updateInfo(requestUserId);
|
|
|
|
+ }
|
|
|
|
+ tbDingStatistic.setServiceId(serviceUnitId);
|
|
|
|
+ tbDingStatistic.setSopNo(sopNo);
|
|
|
|
+ tbDingStatistic.setCrmNo(crmNo);
|
|
|
|
+ tbDingStatistic.setUserArchivesId(userArchivesId);
|
|
|
|
+ tbDingStatistic.setScanStartTime(scanStartTime);
|
|
|
|
+ tbDingStatistic.setScanEndTime(scanEndTime);
|
|
|
|
+ tbDingStatistic.setMarkPaperStartTime(markPaperStartTime);
|
|
|
|
+ tbDingStatistic.setMarkPaperEndTime(markPaperEndTime);
|
|
|
|
+ tbDingStatistic.setSopRoleType(sopRoleType);
|
|
|
|
+ tbDingStatistic.setActualDays(actualDays);
|
|
|
|
+ tbDingStatistic.setWeekdays(weekDays);
|
|
|
|
+ tbDingStatistic.setWeekends(weekends);
|
|
|
|
+ tbDingStatistic.setLegalHolidays(legalHolidays);
|
|
|
|
+ tbDingStatistic.setWorkHours(workHours);
|
|
|
|
+ tbDingStatistic.setViolationDays(violationDays);
|
|
|
|
+ tbDingStatisticList.add(tbDingStatistic);
|
|
}
|
|
}
|
|
|
|
+ this.saveOrUpdateBatch(tbDingStatisticList);
|
|
}
|
|
}
|
|
}
|
|
}
|