|
@@ -1,11 +1,30 @@
|
|
|
package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.sop.business.entity.TBCrm;
|
|
|
+import com.qmth.sop.business.entity.TBCrmDetail;
|
|
|
+import com.qmth.sop.business.entity.TBDing;
|
|
|
import com.qmth.sop.business.entity.TBDingStatistic;
|
|
|
import com.qmth.sop.business.mapper.TBDingStatisticMapper;
|
|
|
-import com.qmth.sop.business.service.TBDingStatisticService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.sop.business.service.*;
|
|
|
+import com.qmth.sop.common.contant.SystemConstant;
|
|
|
+import com.qmth.sop.common.enums.DingDateTypeEnum;
|
|
|
+import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.sop.common.enums.SopRoleTypeEnum;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 考勤提交统计表 服务实现类
|
|
@@ -16,5 +35,111 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TBDingStatisticServiceImpl extends ServiceImpl<TBDingStatisticMapper, TBDingStatistic> implements TBDingStatisticService {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(TBDingStatisticServiceImpl.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TBCrmDetailService tbCrmDetailService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TBDingService tbDingService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TBCrmService tbCrmService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TBUserArchivesAllocationService tbUserArchivesAllocationService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void buildDingStatistic(String sopNo) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void buildDingStatistic() {
|
|
|
+
|
|
|
+ List<TBDing> datasource = tbDingService.list();
|
|
|
+ List<String> sopNoList = datasource.stream().map(TBDing::getSopNo).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ 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("未找到派单信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 违规工时
|
|
|
+ int violationDays = Math.toIntExact(
|
|
|
+ dingList.stream().filter(e -> SystemConstant.isOneNull(e.getSignInTime(), e.getSignOutTime()))
|
|
|
+ .count());
|
|
|
+
|
|
|
+ TBDingStatistic tbDingStatistic = new TBDingStatistic();
|
|
|
+ // TODO: 2024/5/23 新增实体对象-czx
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|