Bläddra i källkod

增加校验人力成本数据是否重复存在的代码

Cyangbin 2 år sedan
förälder
incheckning
776a2e9979

+ 3 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunImplCostDao.java

@@ -7,6 +7,7 @@ import org.springframework.stereotype.Repository;
 
 import javax.transaction.Transactional;
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  * @author kxuan
@@ -20,6 +21,8 @@ public interface ChuanyunImplCostDao extends GalaxisRepository<ChuanyunImplCostD
 
     ChuanyunImplCostDO findByProjectCodeAndWorkGroupAndLocalDate(String projectCode, String workGroup, LocalDateTime localDate);
 
+    List<ChuanyunImplCostDO> findAllByProjectCode(String projectCode);
+
     @Transactional
     void deleteAllByProjectId(String projectId);
 

+ 14 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunMonthLaborCostNewDao.java

@@ -0,0 +1,14 @@
+package com.galaxis.manatee.dao;
+
+import com.galaxis.manatee.capsule.util.GalaxisRepository;
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunMonthLaborCostNewDO;
+import org.springframework.stereotype.Repository;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Repository
+public interface ChuanyunMonthLaborCostNewDao extends GalaxisRepository<ChuanyunMonthLaborCostNewDO,String> {
+
+    List<ChuanyunMonthLaborCostNewDO> findAllByProjectCodeAndLogDateAndDepartment(String projectCode, LocalDateTime dateTime,String dept);
+}

+ 4 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunMonthLaborCostWgDao.java

@@ -18,4 +18,8 @@ public interface ChuanyunMonthLaborCostWgDao extends GalaxisRepository<ChuanyunM
 
     List<ChuanyunMonthLaborCostWgDTO> findAllByProjectCodeAndProjectId(String projectCode, String projectId);
 
+    List<ChuanyunMonthLaborCostWgDTO> findAllByProjectCodeAndProjectIdAndLogDateGreaterThanEqual(String projectCode, String projectId, LocalDateTime date);
+
+    List<ChuanyunMonthLaborCostWgDTO> findAllByProjectCodeAndLogDateLessThan(String projectCode, LocalDateTime date);
+
 }

+ 3 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunReimbursementDao.java

@@ -6,6 +6,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Repository;
 
+import java.time.LocalDateTime;
 import java.util.List;
 
 
@@ -39,5 +40,7 @@ public interface ChuanyunReimbursementDao extends GalaxisRepository<ChuanyunReim
      */
     List<ChuanyunReimbursementDO> findAllByGroupProjectIdAndReimburseUserIdAndStatusIn(String projectId, String userId, List<Integer> status);
 
+    List<ChuanyunReimbursementDO> findAllByGroupProjectIdAndStatusInAndBusinessDateGreaterThanEqual(String projectId, List<Integer> status, LocalDateTime date);
 
+    List<ChuanyunReimbursementDO> findAllByGroupProjectCodeAndStatusInAndBusinessDateLessThan(String projectCode, List<Integer> status, LocalDateTime date);
 }

+ 6 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunSelfWorkHourDao.java

@@ -221,4 +221,10 @@ public interface ChuanyunSelfWorkHourDao extends GalaxisRepository<ChuanyunSelfW
 
     List<ChuanyunSelfWorkHourDO> findAllByProjectIdAndStatusIn(String projectId, List<String> status);
 
+    List<ChuanyunSelfWorkHourDO> findAllByProjectIdAndStatusInAndDayLogDateGreaterThanEqual(String projectId, List<String> status,LocalDateTime date);
+
+    List<ChuanyunSelfWorkHourDO> findAllByProjectCodeAndStatusInAndDayLogDateLessThan(String projectCode, List<String> status,LocalDateTime date);
+
+    List<ChuanyunSelfWorkHourDO> findAllByProjectCodeIsNullAndProjectTypeNotContains(String projectType);
+
 }

+ 9 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ChuanyunMemberHourDO.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.galaxis.manatee.capsule.bo.ChuanyunObject;
 import com.galaxis.manatee.util.ChuanyunLocalDateTimeDeserializer;
 import com.galaxis.manatee.util.ChuanyunLocalDateTimeSerializer;
 import lombok.Data;
@@ -12,6 +13,7 @@ import lombok.EqualsAndHashCode;
 import lombok.extern.slf4j.Slf4j;
 
 import javax.persistence.Entity;
+import javax.persistence.Transient;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 
@@ -49,4 +51,11 @@ public class ChuanyunMemberHourDO extends BasicDO{
 
     @JsonProperty("F0000004")
     private BigDecimal standardWorkHour;
+
+    @JsonProperty("F0000006")
+    private String workHourStatus;
+
+    @JsonProperty("F0000002Object")
+    @Transient
+    private ChuanyunObject userObject;
 }

+ 46 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ChuanyunMonthLaborCostNewDO.java

@@ -0,0 +1,46 @@
+package com.galaxis.manatee.entity.chuanyun.data.object;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.galaxis.manatee.util.ChuanyunLocalDateTimeDeserializer;
+import com.galaxis.manatee.util.ChuanyunLocalDateTimeSerializer;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.extern.slf4j.Slf4j;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Slf4j
+@EqualsAndHashCode
+@Data
+@Entity(name = "CHUANYUN_MONTH_LABORCOST_NEW")
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ChuanyunMonthLaborCostNewDO {
+
+    @Id
+    @GeneratedValue(generator = "idGeneratorChuanyunImplCos")
+    @GenericGenerator(name = "idGeneratorChuanyunImplCos", strategy = "com.galaxis.manatee.capsule.util.GalaxisIdGenerator")
+    private Long id;
+
+    private String projectCode;
+
+    @JsonSerialize(using = ChuanyunLocalDateTimeSerializer.class)
+    @JsonDeserialize(using = ChuanyunLocalDateTimeDeserializer.class)
+    private LocalDateTime logDate;
+
+    private String department;
+
+    private BigDecimal amount;
+
+    @Transient
+    private BigDecimal totalamount;
+
+    private String dataType;
+}

+ 0 - 5
src/main/java/com/galaxis/manatee/entity/chuanyun/dto/ChuanyunLaborCostDTO.java

@@ -3,9 +3,7 @@ package com.galaxis.manatee.entity.chuanyun.dto;
 
 import lombok.Data;
 
-import javax.persistence.Id;
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
 
 @Data
 public class ChuanyunLaborCostDTO {
@@ -15,7 +13,4 @@ public class ChuanyunLaborCostDTO {
 
     private BigDecimal costamount;
 
-    private String workGroupID;
-
-    private String workGroupName;
 }

+ 48 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/dto/ChuanyunMonthLaborCostNewDTO.java

@@ -0,0 +1,48 @@
+package com.galaxis.manatee.entity.chuanyun.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.galaxis.manatee.entity.chuanyun.data.object.BasicDO;
+import com.galaxis.manatee.util.ChuanyunLocalDateTimeDeserializer;
+import com.galaxis.manatee.util.ChuanyunLocalDateTimeSerializer;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.persistence.Transient;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Slf4j
+@EqualsAndHashCode(callSuper = true)
+@Data
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ChuanyunMonthLaborCostNewDTO extends BasicDO {
+
+    /**
+     * 表名
+     */
+    public static final String SCHEMA_CODE ="D001789c42dc40d56a84e84b09609bf44a77205";
+
+    @JsonProperty("F0000005")
+    private String projectCode;
+
+    @JsonSerialize(using = ChuanyunLocalDateTimeSerializer.class)
+    @JsonDeserialize(using = ChuanyunLocalDateTimeDeserializer.class)
+    @JsonProperty("F0000002")
+    private LocalDateTime logDate;
+
+    @JsonProperty("F0000018")
+    private String department;
+
+    @JsonProperty("F0000003")
+    private BigDecimal amount;
+
+    @Transient
+    private BigDecimal totalamount;
+
+    @JsonProperty("F0000004")
+    private String dataType;
+}

+ 148 - 66
src/main/java/com/galaxis/manatee/service/impl/WorkGroupServiceImpl.java

@@ -489,7 +489,9 @@ public class WorkGroupServiceImpl implements WorkGroupService {
                         Map<LocalDate, List<ChuanyunReimbursementDO>> reimbursementMap = new HashMap<>();
                         Map<LocalDate, List<ChuanyunSelfWorkHourDO>> workHoursMap = new HashMap<>();
                         Map<LocalDate, List<ChuanyunMonthLaborCostWgDTO>> laborCostMap = new HashMap<>();
-                        List<ChuanyunReimbursementDO> reimbursements = reimbursementDao.findAllByGroupProjectIdAndStatusIn(chuanyunGroupProjectDO.getObjectId(), List.of(1, 2));
+                        // 通过项目id只查询2022年8月份之后的
+                        LocalDate date = LocalDate.of(2022, 8, 1);
+                        List<ChuanyunReimbursementDO> reimbursements = reimbursementDao.findAllByGroupProjectIdAndStatusInAndBusinessDateGreaterThanEqual(chuanyunGroupProjectDO.getObjectId(), List.of(1, 2), date.atStartOfDay());
                         // 查询用户在该项目的报销单
                         // 报销单按日期分组
                         Map<LocalDate, List<ChuanyunReimbursementDO>> map1 = reimbursements.stream().collect(Collectors.groupingBy(chuanyunReimbursementDO -> {
@@ -512,7 +514,7 @@ public class WorkGroupServiceImpl implements WorkGroupService {
                             }
                         });
 
-                        List<ChuanyunSelfWorkHourDO> workHours = selfWorkHourDao.findAllByProjectIdAndStatusIn(groupProjectObjectId, List.of("1", "2"));
+                        List<ChuanyunSelfWorkHourDO> workHours = selfWorkHourDao.findAllByProjectIdAndStatusInAndDayLogDateGreaterThanEqual(groupProjectObjectId, List.of("1", "2"), date.atStartOfDay());
                         Map<LocalDate, List<ChuanyunSelfWorkHourDO>> map2 = workHours.stream().collect(Collectors.groupingBy(chuanyunSelfWorkHourDO -> {
                             if (!Objects.isNull(chuanyunSelfWorkHourDO.getDayLogDate())) {
                                 return LocalDate.of(chuanyunSelfWorkHourDO.getDayLogDate().getYear(), chuanyunSelfWorkHourDO.getDayLogDate().getMonthValue(), 1);
@@ -532,7 +534,7 @@ public class WorkGroupServiceImpl implements WorkGroupService {
                             }
                         });
 
-                        List<ChuanyunMonthLaborCostWgDTO> laborCostWgs = chuanyunMonthLaborCostWgDao.findAllByProjectCode(groupProjectCode);
+                        List<ChuanyunMonthLaborCostWgDTO> laborCostWgs = chuanyunMonthLaborCostWgDao.findAllByProjectCodeAndProjectIdAndLogDateGreaterThanEqual(groupProjectCode, groupProjectObjectId, date.atStartOfDay());
                         Map<LocalDate, List<ChuanyunMonthLaborCostWgDTO>> map3 = laborCostWgs.stream().collect(Collectors.groupingBy(chuanyunMonthLaborCostWgDTO -> {
                             if (!Objects.isNull(chuanyunMonthLaborCostWgDTO.getLogDate())) {
                                 return LocalDate.of(chuanyunMonthLaborCostWgDTO.getLogDate().getYear(), chuanyunMonthLaborCostWgDTO.getLogDate().getMonthValue(), 1);
@@ -564,82 +566,162 @@ public class WorkGroupServiceImpl implements WorkGroupService {
                             List<ChuanyunReimbursementDO> reimbursementList = reimbursementMap.getOrDefault(localDate, Collections.emptyList());
                             List<ChuanyunSelfWorkHourDO> selfWorkHourList = workHoursMap.getOrDefault(localDate, Collections.emptyList());
                             List<ChuanyunMonthLaborCostWgDTO> laborCostWgList = laborCostMap.getOrDefault(localDate, Collections.emptyList());
-                            if (!localDate.isBefore(LocalDate.of(2022, 8, 1))) {
-                                Map<String, List<ChuanyunReimbursementDO>> workGroupIdReimbursementMap = reimbursementList.stream().collect(Collectors.groupingBy(chuanyunReimbursementDO -> {
-                                    if (Objects.isNull(chuanyunReimbursementDO.getWorkGroupId()) || !StringUtils.hasLength(chuanyunReimbursementDO.getWorkGroupId())) {
-                                        return ChuanYunConstant.DEFAULT_WORK_GROUP;
-                                    } else {
-                                        return chuanyunReimbursementDO.getWorkGroupId();
-                                    }
-                                }));
-                                Map<String, List<ChuanyunSelfWorkHourDO>> workGroupIdSelfWorkHourMap = selfWorkHourList.stream().collect(Collectors.groupingBy(chuanyunSelfWorkHourDO -> {
-                                    if (Objects.isNull(chuanyunSelfWorkHourDO.getWorkGroupId()) || !StringUtils.hasLength(chuanyunSelfWorkHourDO.getWorkGroupId())) {
-                                        return ChuanYunConstant.DEFAULT_WORK_GROUP;
-                                    } else {
-                                        return chuanyunSelfWorkHourDO.getWorkGroupId();
-                                    }
-                                }));
-                                Map<String, List<ChuanyunMonthLaborCostWgDTO>> workGroupIdLaborCostMap = laborCostWgList.stream().collect(Collectors.groupingBy(chuanyunMonthLaborCostWgDTO -> {
-                                    if (Objects.isNull(chuanyunMonthLaborCostWgDTO.getWorkGroupId()) || !StringUtils.hasLength(chuanyunMonthLaborCostWgDTO.getWorkGroupId())) {
-                                        return ChuanYunConstant.DEFAULT_WORK_GROUP;
-                                    } else {
-                                        return chuanyunMonthLaborCostWgDTO.getWorkGroupId();
-                                    }
-                                }));
 
-                                Set<String> workGroup1 = workGroupIdReimbursementMap.keySet();
-                                Set<String> workGroup2 = workGroupIdSelfWorkHourMap.keySet();
-                                Set<String> workGroup3 = workGroupIdLaborCostMap.keySet();
+                            Map<String, List<ChuanyunReimbursementDO>> workGroupIdReimbursementMap = reimbursementList.stream().collect(Collectors.groupingBy(chuanyunReimbursementDO -> {
+                                if (Objects.isNull(chuanyunReimbursementDO.getWorkGroupId()) || !StringUtils.hasLength(chuanyunReimbursementDO.getWorkGroupId())) {
+                                    return ChuanYunConstant.DEFAULT_WORK_GROUP;
+                                } else {
+                                    return chuanyunReimbursementDO.getWorkGroupId();
+                                }
+                            }));
+                            Map<String, List<ChuanyunSelfWorkHourDO>> workGroupIdSelfWorkHourMap = selfWorkHourList.stream().collect(Collectors.groupingBy(chuanyunSelfWorkHourDO -> {
+                                if (Objects.isNull(chuanyunSelfWorkHourDO.getWorkGroupId()) || !StringUtils.hasLength(chuanyunSelfWorkHourDO.getWorkGroupId())) {
+                                    return ChuanYunConstant.DEFAULT_WORK_GROUP;
+                                } else {
+                                    return chuanyunSelfWorkHourDO.getWorkGroupId();
+                                }
+                            }));
+                            Map<String, List<ChuanyunMonthLaborCostWgDTO>> workGroupIdLaborCostMap = laborCostWgList.stream().collect(Collectors.groupingBy(chuanyunMonthLaborCostWgDTO -> {
+                                if (Objects.isNull(chuanyunMonthLaborCostWgDTO.getWorkGroupId()) || !StringUtils.hasLength(chuanyunMonthLaborCostWgDTO.getWorkGroupId())) {
+                                    return ChuanYunConstant.DEFAULT_WORK_GROUP;
+                                } else {
+                                    return chuanyunMonthLaborCostWgDTO.getWorkGroupId();
+                                }
+                            }));
 
+                            Set<String> workGroup1 = workGroupIdReimbursementMap.keySet();
+                            Set<String> workGroup2 = workGroupIdSelfWorkHourMap.keySet();
+                            Set<String> workGroup3 = workGroupIdLaborCostMap.keySet();
 
-                                Set<String> workGroupMergeCollections = CollectionsUtils.mergeStringCollections(workGroup1, workGroup2, workGroup3);
-                                // 避免默认工作与实际工作组数据重复,可能会存在历史数据没有工作组,后面标准化的时候又补充了工作组信息。
-                                workGroupMergeCollections.add(ChuanYunConstant.DEFAULT_WORK_GROUP);
 
-                                workGroupMergeCollections.forEach(workGroupId -> {
-                                    List<ChuanyunReimbursementDO> reimbursementDOList = workGroupIdReimbursementMap.getOrDefault(workGroupId, Collections.emptyList());
-                                    List<ChuanyunSelfWorkHourDO> selfWorkHourDOS = workGroupIdSelfWorkHourMap.getOrDefault(workGroupId, Collections.emptyList());
-                                    List<ChuanyunMonthLaborCostWgDTO> monthLaborCostWgDTOS = workGroupIdLaborCostMap.getOrDefault(workGroupId, Collections.emptyList());
+                            Set<String> workGroupMergeCollections = CollectionsUtils.mergeStringCollections(workGroup1, workGroup2, workGroup3);
+                            // 避免默认工作与实际工作组数据重复,可能会存在历史数据没有工作组,后面标准化的时候又补充了工作组信息。
+                            workGroupMergeCollections.add(ChuanYunConstant.DEFAULT_WORK_GROUP);
 
-                                    BigDecimal totalReimbursement;
-                                    BigDecimal totalManDay;
-                                    BigDecimal totalLaborCost;
+                            workGroupMergeCollections.forEach(workGroupId -> {
+                                List<ChuanyunReimbursementDO> reimbursementDOList = workGroupIdReimbursementMap.getOrDefault(workGroupId, Collections.emptyList());
+                                List<ChuanyunSelfWorkHourDO> selfWorkHourDOS = workGroupIdSelfWorkHourMap.getOrDefault(workGroupId, Collections.emptyList());
+                                List<ChuanyunMonthLaborCostWgDTO> monthLaborCostWgDTOS = workGroupIdLaborCostMap.getOrDefault(workGroupId, Collections.emptyList());
 
-                                    if (reimbursementDOList.isEmpty()) {
-                                        totalReimbursement = new BigDecimal("0.00");
-                                    } else {
-                                        totalReimbursement = reimbursementDOList.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
-                                    }
+                                BigDecimal totalReimbursement;
+                                BigDecimal totalManDay;
+                                BigDecimal totalLaborCost;
 
-                                    if (selfWorkHourDOS.isEmpty()) {
-                                        totalManDay = new BigDecimal("0.00");
-                                    } else {
-                                        BigDecimal totalWorkHours = selfWorkHourDOS.stream().map(ChuanyunSelfWorkHourDO::getStandardWorkHour).reduce(BigDecimal.ZERO, BigDecimal::add);
-                                        totalManDay = totalWorkHours.divide(BigDecimal.valueOf(8), 3, RoundingMode.UP);
-                                    }
+                                if (reimbursementDOList.isEmpty()) {
+                                    totalReimbursement = new BigDecimal("0.00");
+                                } else {
+                                    totalReimbursement = reimbursementDOList.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
+                                }
 
-                                    if (monthLaborCostWgDTOS.isEmpty()) {
-                                        totalLaborCost = new BigDecimal("0.00");
-                                    } else {
-                                        totalLaborCost = monthLaborCostWgDTOS.stream().map(ChuanyunMonthLaborCostWgDTO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-                                    }
+                                if (selfWorkHourDOS.isEmpty()) {
+                                    totalManDay = new BigDecimal("0.00");
+                                } else {
+                                    BigDecimal totalWorkHours = selfWorkHourDOS.stream().map(ChuanyunSelfWorkHourDO::getStandardWorkHour).reduce(BigDecimal.ZERO, BigDecimal::add);
+                                    totalManDay = totalWorkHours.divide(BigDecimal.valueOf(8), 3, RoundingMode.UP);
+                                }
 
-                                    ChuanyunImplCostDO old = implCostDao.findByProjectIdAndProjectCodeAndWorkGroupAndLocalDate(groupProjectObjectId, groupProjectCode, workGroupId, localDate.atStartOfDay());
-                                    checkDataChange(chuanyunGroupProjectDO, groupProjectCode, localDate, workGroupId, totalReimbursement, totalManDay, totalLaborCost, old);
+                                if (monthLaborCostWgDTOS.isEmpty()) {
+                                    totalLaborCost = new BigDecimal("0.00");
+                                } else {
+                                    totalLaborCost = monthLaborCostWgDTOS.stream().map(ChuanyunMonthLaborCostWgDTO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+                                }
 
-                                });
-                            } else {
-                                // 为2022年8月之前的数据,数据汇总到一个组内
-                                BigDecimal totalReimbursement = reimbursementList.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
-                                BigDecimal totalWorkHours = selfWorkHourList.stream().map(ChuanyunSelfWorkHourDO::getStandardWorkHour).reduce(BigDecimal.ZERO, BigDecimal::add);
-                                BigDecimal totalManDay = totalWorkHours.divide(BigDecimal.valueOf(8), 3, RoundingMode.UP);
-                                BigDecimal totalLaborCost = laborCostWgList.stream().map(ChuanyunMonthLaborCostWgDTO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-                                // 统一汇总到默认组内
-                                String workGroupId = ChuanYunConstant.DEFAULT_WORK_GROUP;
-                                ChuanyunImplCostDO old = implCostDao.findByProjectCodeAndWorkGroupAndLocalDate(groupProjectCode, workGroupId, localDate.atStartOfDay());
+                                ChuanyunImplCostDO old = implCostDao.findByProjectIdAndProjectCodeAndWorkGroupAndLocalDate(groupProjectObjectId, groupProjectCode, workGroupId, localDate.atStartOfDay());
                                 checkDataChange(chuanyunGroupProjectDO, groupProjectCode, localDate, workGroupId, totalReimbursement, totalManDay, totalLaborCost, old);
 
+                            });
+
+
+                        });
+
+                        // 处理2022年8月份之前的数据
+                        Map<LocalDate, List<ChuanyunReimbursementDO>> beforeReimbursementMap = new HashMap<>();
+                        Map<LocalDate, List<ChuanyunSelfWorkHourDO>> beforeWorkHoursMap = new HashMap<>();
+                        Map<LocalDate, List<ChuanyunMonthLaborCostWgDTO>> beforeLaborCostMap = new HashMap<>();
+                        List<ChuanyunReimbursementDO> beforeReimbursements = reimbursementDao.findAllByGroupProjectCodeAndStatusInAndBusinessDateLessThan(groupProjectCode, List.of(1, 2), date.atStartOfDay());
+                        // 查询用户在该项目的报销单
+                        // 报销单按日期分组
+                        Map<LocalDate, List<ChuanyunReimbursementDO>> brforeMap1 = beforeReimbursements.stream().collect(Collectors.groupingBy(chuanyunReimbursementDO -> {
+                            if (!Objects.isNull(chuanyunReimbursementDO.getBusinessDate())) {
+                                return LocalDate.of(chuanyunReimbursementDO.getBusinessDate().getYear(), chuanyunReimbursementDO.getBusinessDate().getMonthValue(), 1);
+                            } else {
+                                return LocalDate.of(2015, 1, 1);
+                            }
+                        }));
+
+                        brforeMap1.forEach((localDate, chuanyunReimbursementDOS) -> {
+                            boolean containsKey = beforeReimbursementMap.containsKey(localDate);
+                            if (containsKey) {
+                                // 表示已经存在该key
+                                List<ChuanyunReimbursementDO> reimbursementDOList = beforeReimbursementMap.get(localDate);
+                                reimbursementDOList.addAll(chuanyunReimbursementDOS);
+                                beforeReimbursementMap.put(localDate, reimbursementDOList);
+                            } else {
+                                beforeReimbursementMap.put(localDate, chuanyunReimbursementDOS);
+                            }
+                        });
+
+                        List<ChuanyunSelfWorkHourDO> beforeWorkHours = selfWorkHourDao.findAllByProjectCodeAndStatusInAndDayLogDateLessThan(groupProjectCode, List.of("1", "2"), date.atStartOfDay());
+                        Map<LocalDate, List<ChuanyunSelfWorkHourDO>> beforeMap2 = beforeWorkHours.stream().collect(Collectors.groupingBy(chuanyunSelfWorkHourDO -> {
+                            if (!Objects.isNull(chuanyunSelfWorkHourDO.getDayLogDate())) {
+                                return LocalDate.of(chuanyunSelfWorkHourDO.getDayLogDate().getYear(), chuanyunSelfWorkHourDO.getDayLogDate().getMonthValue(), 1);
+                            } else {
+                                return LocalDate.of(2015, 1, 1);
                             }
+                        }));
+                        beforeMap2.forEach((localDate, chuanyunSelfWorkHourDOS) -> {
+                            boolean containsKey = beforeWorkHoursMap.containsKey(localDate);
+                            if (containsKey) {
+                                // 表示已经存在该key
+                                List<ChuanyunSelfWorkHourDO> selfWorkHours = beforeWorkHoursMap.get(localDate);
+                                selfWorkHours.addAll(chuanyunSelfWorkHourDOS);
+                                beforeWorkHoursMap.put(localDate, selfWorkHours);
+                            } else {
+                                beforeWorkHoursMap.put(localDate, chuanyunSelfWorkHourDOS);
+                            }
+                        });
+
+                        List<ChuanyunMonthLaborCostWgDTO> beforeLaborCostWgs = chuanyunMonthLaborCostWgDao.findAllByProjectCodeAndLogDateLessThan(groupProjectCode, date.atStartOfDay());
+                        Map<LocalDate, List<ChuanyunMonthLaborCostWgDTO>> beforeMap3 = beforeLaborCostWgs.stream().collect(Collectors.groupingBy(chuanyunMonthLaborCostWgDTO -> {
+                            if (!Objects.isNull(chuanyunMonthLaborCostWgDTO.getLogDate())) {
+                                return LocalDate.of(chuanyunMonthLaborCostWgDTO.getLogDate().getYear(), chuanyunMonthLaborCostWgDTO.getLogDate().getMonthValue(), 1);
+                            } else {
+                                return LocalDate.of(2015, 1, 1);
+                            }
+
+                        }));
+                        beforeMap3.forEach((localDate, chuanyunMonthLaborCostWgDTOS) -> {
+                            boolean containsKey = beforeLaborCostMap.containsKey(localDate);
+                            if (containsKey) {
+                                // 表示已经存在该key
+                                List<ChuanyunMonthLaborCostWgDTO> monthLaborCostWgs = beforeLaborCostMap.get(localDate);
+                                monthLaborCostWgs.addAll(chuanyunMonthLaborCostWgDTOS);
+                                beforeLaborCostMap.put(localDate, monthLaborCostWgs);
+                            } else {
+                                beforeLaborCostMap.put(localDate, chuanyunMonthLaborCostWgDTOS);
+                            }
+                        });
+
+                        Set<LocalDate> beforeLocalDates1 = beforeReimbursementMap.keySet();
+                        Set<LocalDate> beforeLocalDates2 = beforeWorkHoursMap.keySet();
+                        Set<LocalDate> beforeLocalDates3 = beforeLaborCostMap.keySet();
+
+                        Set<LocalDate> beforeLocalDateCollections = CollectionsUtils.mergeCollections(beforeLocalDates1, beforeLocalDates2);
+                        Set<LocalDate> beforeMergeCollections = CollectionsUtils.mergeCollections(beforeLocalDateCollections, beforeLocalDates3);
+
+                        // 为2022年8月之前的数据,数据汇总到一个组内
+                        beforeMergeCollections.forEach(localDate -> {
+                            List<ChuanyunReimbursementDO> beforeReimbursementList = beforeReimbursementMap.getOrDefault(localDate, Collections.emptyList());
+                            List<ChuanyunSelfWorkHourDO> beforeWorkHourList = beforeWorkHoursMap.getOrDefault(localDate, Collections.emptyList());
+                            List<ChuanyunMonthLaborCostWgDTO> beforeLaborCostWgList = beforeLaborCostMap.getOrDefault(localDate, Collections.emptyList());
+                            BigDecimal totalReimbursement = beforeReimbursementList.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
+                            BigDecimal totalWorkHours = beforeWorkHourList.stream().map(ChuanyunSelfWorkHourDO::getStandardWorkHour).reduce(BigDecimal.ZERO, BigDecimal::add);
+                            BigDecimal totalManDay = totalWorkHours.divide(BigDecimal.valueOf(8), 3, RoundingMode.UP);
+                            BigDecimal totalLaborCost = beforeLaborCostWgList.stream().map(ChuanyunMonthLaborCostWgDTO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+                            // 统一汇总到默认组内
+                            String workGroupId = ChuanYunConstant.DEFAULT_WORK_GROUP;
+                            ChuanyunImplCostDO old = implCostDao.findByProjectCodeAndWorkGroupAndLocalDate(groupProjectCode, workGroupId, localDate.atStartOfDay());
+                            checkDataChange(chuanyunGroupProjectDO, groupProjectCode, localDate, workGroupId, totalReimbursement, totalManDay, totalLaborCost, old);
 
                         });
 

+ 3 - 3
src/main/java/com/galaxis/manatee/task/ChuanyunScheduledTask.java

@@ -115,7 +115,7 @@ public class ChuanyunScheduledTask {
         parameters.put("size", Integer.toString(size));
 
         while (page<=totalPage){
-            List<ChuanyunMaterialDO> toSave=new ArrayList<>();
+            List<MaterialDTO> toSave=new ArrayList<>();
             //获取U9中的物料数据
             Page<MaterialDTO> result=clawFeign.findMaterialPageable(parameters);
             totalPage=result.getTotalPages();
@@ -126,7 +126,7 @@ public class ChuanyunScheduledTask {
                 if(list.size()==0){
                     ChuanyunMaterialDO chuanyunMaterialDO=ChuanyunMaterialDO.fromMaterialDTO(materialDTO);
                     chuanyunMaterialList.add(chuanyunMaterialDO);
-                    toSave.add(chuanyunMaterialDO);
+                    toSave.add(materialDTO);
                 }
             });
             chuanyunMaterialDao.saveAll(chuanyunMaterialList);
@@ -136,7 +136,7 @@ public class ChuanyunScheduledTask {
             log.info("共"+totalPage+"页,当前第"+page+"页,更新了"+chuanyunMaterialList.size()+"条数据");
             //将更新的的物料信息同步到氚云
             if (chuanyunMaterialList.size()>0){
-                getMaterialFromU9(result.getContent());
+                getMaterialFromU9(toSave);
             }
 
         }

+ 100 - 4
src/main/java/com/galaxis/manatee/task/U9InfoTask.java

@@ -45,12 +45,17 @@ public class U9InfoTask {
     private final ChuanyunOutDepartmentDao chuanyunOutDepartmentDao;
     private final ChuanyunSupplierDao chuanyunSupplierDao;
     private ChuanyunMonthLaborCostWgDao chuanyunMonthLaborCostWgDao;
+    private ChuanyunMonthLaborCostNewDao chuanyunMonthLaborCostNewDao;
 
     @Autowired
     public void setChuanyunMonthLaborCostWgDao(ChuanyunMonthLaborCostWgDao chuanyunMonthLaborCostWgDao) {
         this.chuanyunMonthLaborCostWgDao = chuanyunMonthLaborCostWgDao;
     }
 
+    @Autowired
+    public void setChuanyunMonthLaborCostNewDao(ChuanyunMonthLaborCostNewDao chuanyunMonthLaborCostNewDao) {
+        this.chuanyunMonthLaborCostNewDao = chuanyunMonthLaborCostNewDao;
+    }
 
     public U9InfoTask(ChuanYunManager chuanYunManager, ClawFeign clawFeign, ChuanyunBudgetStatisticsDao chuanyunBudgetStatisticsDao, ChuanyunCompanyDao chuanyunCompanyDao, ChuanyunClientDao chuanyunClientDao, ChuanyunUserDao chuanyunUserDao, ChuanyunOutDepartmentDao chuanyunOutDepartmentDao, ChuanyunSupplierDao chuanyunSupplierDao) {
         this.chuanYunManager = chuanYunManager;
@@ -81,6 +86,11 @@ public class U9InfoTask {
         saveSubLaborCost();
     }
 
+    @Scheduled(cron = "0 0 0 15 * ? *")
+    private void checkLaborCost() {
+        saveDbLaborCost();
+    }
+
     /**
      * 更新项目物料成本
      */
@@ -596,6 +606,85 @@ public class U9InfoTask {
         }
     }
 
+    /**
+     * 新增人力成本
+     */
+    public void saveDbLaborCost() {
+        chuanyunMonthLaborCostNewDao.deleteAllInBatch();
+        log.info("开始更新项目人力成本");
+        var objectMapper = new ObjectMapper();
+        var page = 1;
+        var size = 50;
+        var flag = true;
+        while (flag) {
+            Map<String, String> map = new HashMap<>(1);
+            map.put("page", String.valueOf(page));
+            map.put("size", String.valueOf(size));
+            //获取物料成本
+            //@TODO这个方法找不到实现,代码可能未提交
+            PageDTO<ChuanyunLaborCostDTO> pageInfo = clawFeign.findChuanyunLaborCost(map);
+            if (page <= pageInfo.getTotalPages()) {
+                page += 1;
+            } else {
+                flag = false;
+                break;
+            }
+            List<ChuanyunLaborCostDTO> list = pageInfo.getContent();
+            List<ChuanyunMonthLaborCostNewDO> saveDbList = new ArrayList<>();
+            list.forEach(chuanyunLaborCostDTO -> {
+                if (chuanyunLaborCostDTO != null) {
+                    ChuanyunMonthLaborCostNewDO monthLaborCostDO = new ChuanyunMonthLaborCostNewDO();
+                    monthLaborCostDO.setProjectCode(chuanyunLaborCostDTO.getChuanyunLaborCostPrimaryKey().getProjectcode());
+                    monthLaborCostDO.setLogDate(chuanyunLaborCostDTO.getChuanyunLaborCostPrimaryKey().getPeriod());
+                    monthLaborCostDO.setDepartment(chuanyunLaborCostDTO.getChuanyunLaborCostPrimaryKey().getDepartment());
+                    monthLaborCostDO.setAmount(chuanyunLaborCostDTO.getCostamount());
+                    monthLaborCostDO.setDataType("U9");
+                    saveDbList.add(monthLaborCostDO);
+                }
+            });
+            chuanyunMonthLaborCostNewDao.saveAll(saveDbList);
+        }
+        this.delChuanyunRepeatWorkHour();
+    }
+
+    private void delChuanyunRepeatWorkHour() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        List<String> errorObjectIdList = new ArrayList<>();
+        var start = 0;
+        var pageSize = 200;
+        var flag = true;
+        while (flag) {
+            try {
+                //从氚云查询数据
+                var filter = Filter.instance(start, start + pageSize, true);
+                var chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunMonthLaborCostNewDTO.SCHEMA_CODE, filter);
+                if (chuanyunFindAllResponse.getReturnData() == null) {
+                    flag = false;
+                    continue;
+                }
+                if (chuanyunFindAllResponse.getReturnData().getTotalCount() >= start + pageSize) {
+                    start += pageSize;
+                } else {
+                    flag = false;
+                }
+                //转化为POJO
+                List<ChuanyunMonthLaborCostNewDTO> result = objectMapper.convertValue(chuanyunFindAllResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
+                });
+                result.forEach(chuanyunMonthLaborCostDO -> {
+                    List<ChuanyunMonthLaborCostNewDO> monthLaborCostNewDOList = chuanyunMonthLaborCostNewDao.findAllByProjectCodeAndLogDateAndDepartment(chuanyunMonthLaborCostDO.getProjectCode(), chuanyunMonthLaborCostDO.getLogDate(), chuanyunMonthLaborCostDO.getDepartment());
+                    if (monthLaborCostNewDOList.isEmpty()) {
+                        log.info("查询到异常的数据:{}", chuanyunMonthLaborCostDO);
+                        errorObjectIdList.add(chuanyunMonthLaborCostDO.getObjectId());
+                    }
+                });
+            } catch (Exception e) {
+                log.error(e.getMessage());
+                e.printStackTrace();
+            }
+        }
+        errorObjectIdList.forEach(objectId -> chuanYunManager.delete(ChuanyunMonthLaborCostNewDTO.SCHEMA_CODE, objectId));
+    }
+
     public void saveLaborCostWgTest() {
         saveDbLaborCostWg();
     }
@@ -608,7 +697,7 @@ public class U9InfoTask {
         chuanyunMonthLaborCostWgDao.deleteAllInBatch();
         log.info("开始保存项目工作组人力成本");
         var page = 1;
-        var size = 100;
+        var size = 50;
         var flag = true;
         while (flag) {
             Map<String, String> map = new HashMap<>(1);
@@ -623,6 +712,9 @@ public class U9InfoTask {
                 break;
             }
             List<ChuanyunLaborCostWgDTO> list = pageInfo.getList();
+
+            ArrayList<ChuanyunMonthLaborCostWgDTO> laborCostWgDTOS = new ArrayList<>();
+
             list.forEach(laborCostWgDTO -> {
                 if (!Objects.isNull(laborCostWgDTO)) {
                     // 保存至数据库
@@ -632,7 +724,9 @@ public class U9InfoTask {
                     String department = laborCostWgDTO.getDepartment();
                     String workGroupId = laborCostWgDTO.getWorkgroupid();
                     // @fixme 避免默认工作组相同项目号相同时间相同部门数据相互影响,所以直接删除全表数据,重新全部保存。
-                    SaveMonthLaborCostWg(laborCostWgDTO, projectCode, time, workGroupId, department);
+                    ChuanyunMonthLaborCostWgDTO chuanyunMonthLaborCostWgDTO = toMonthLaborCostWg(laborCostWgDTO, projectCode, time, workGroupId, department);
+                    laborCostWgDTOS.add(chuanyunMonthLaborCostWgDTO);
+
 //                    List<ChuanyunMonthLaborCostWgDTO> laborCostWg = chuanyunMonthLaborCostWgDao.findAllByProjectCodeAndLogDateAndWorkGroupIdAndDepartment(projectCode, time, workGroupId, department);
 //
 //                    if (laborCostWg.isEmpty()) {
@@ -658,11 +752,12 @@ public class U9InfoTask {
                 }
 
             });
+            chuanyunMonthLaborCostWgDao.saveAll(laborCostWgDTOS);
         }
         log.info("工作组人力成本保存至数据库完成");
     }
 
-    private void SaveMonthLaborCostWg(ChuanyunLaborCostWgDTO laborCostWgDTO, String projectCode, LocalDateTime time, String workGroupId, String department) {
+    private ChuanyunMonthLaborCostWgDTO toMonthLaborCostWg(ChuanyunLaborCostWgDTO laborCostWgDTO, String projectCode, LocalDateTime time, String workGroupId, String department) {
         ChuanyunMonthLaborCostWgDTO monthLaborCostWgDTO = new ChuanyunMonthLaborCostWgDTO();
         monthLaborCostWgDTO.setProjectCode(projectCode);
         monthLaborCostWgDTO.setProjectId(laborCostWgDTO.getProjectid());
@@ -672,7 +767,8 @@ public class U9InfoTask {
         monthLaborCostWgDTO.setLogDate(time);
         monthLaborCostWgDTO.setDepartment(department);
         monthLaborCostWgDTO.setDataType("U9");
-        chuanyunMonthLaborCostWgDao.save(monthLaborCostWgDTO);
+        return monthLaborCostWgDTO;
+
     }
 
     /**

+ 3 - 3
src/main/resources/application.yml

@@ -50,11 +50,11 @@ spring:
         size: 500
       thread-name-prefix: scheduled-task-
   datasource:
-    url: jdbc:mysql://10.1.6.49:3306/manatee?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
+    url: jdbc:mysql://223.76.209.65:3306/manatee?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
     username: root
-    password: root
+    password: j$%rW-GRu$H#pj%V2M-B
     hikari:
-      maximum-pool-size: 128
+      maximum-pool-size: 16
   jpa:
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
     hibernate: