yaozc2021
2024-11-22 0799f543beca64dd1c6007e18cb8d8388b2fc391
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java
@@ -15,37 +15,6 @@
*/
package me.zhengjie.modules.project.service.impl;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.constant.Constant;
@@ -58,26 +27,39 @@
import me.zhengjie.modules.project.service.dto.ProjectCostQueryCriteria;
import me.zhengjie.modules.project.service.mapstruct.ProjectCostMapper;
import me.zhengjie.modules.system.domain.SysConfigHoliday;
import me.zhengjie.modules.system.domain.SysLevel;
import me.zhengjie.modules.system.domain.SysUserLevelInsurance;
import me.zhengjie.modules.system.domain.SysUserLevelWage;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
import me.zhengjie.modules.system.repository.SysLevelRepository;
import me.zhengjie.modules.system.repository.SysUserLevelInsuranceRepository;
import me.zhengjie.modules.system.repository.SysUserLevelWageRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.RoleSmallDto;
import me.zhengjie.modules.system.service.dto.SysRosteringDto;
import me.zhengjie.modules.system.service.dto.UserDto;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.treatment.domain.UserInsurance;
import me.zhengjie.modules.treatment.domain.UserLevelWage;
import me.zhengjie.modules.treatment.repository.UserInsuranceRepository;
import me.zhengjie.modules.treatment.repository.UserLevelWageRepository;
import me.zhengjie.utils.*;
import me.zhengjie.utils.enums.DataScopeEnum;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @website https://eladmin.vip
@@ -93,8 +75,8 @@
    private final ProjectCostMapper projectCostMapper;
    private final ProjectRepository projectRepository;
    private final UserRepository userRepository;
    private final SysUserLevelWageRepository sysUserLevelWageRepository;
    private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository;
    private final UserLevelWageRepository sysUserLevelWageRepository;
    private final UserInsuranceRepository sysUserLevelInsuranceRepository;
    private final SysConfigHolidayRepository sysConfigHolidayRepository;
    private final UserService userService;
    private final RoleService roleService;
@@ -189,87 +171,125 @@
        }
    }
    @Override
    public BigDecimal calcUserCostByDate(Long userId, Timestamp enterProjectTime, Timestamp exitProjectTime, Map<String, Double> costHoursMap) {
        // 工资
        BigDecimal wageCost = BigDecimal.valueOf(0);
        // 工作天数
        LocalDateTime enterProject = enterProjectTime.toLocalDateTime();
        LocalDateTime exitProject = exitProjectTime.toLocalDateTime();
        // 通过id获取用户级别工资
        List<SysUserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findByUserId(userId)
              .stream().filter(sysUserLevelWage -> !((sysUserLevelWage.getEndDate() != null && sysUserLevelWage.getEndDate().before(enterProjectTime)) || sysUserLevelWage.getStartDate().after(exitProjectTime)))
              .collect(Collectors.toList());
        // 通过id获取用户级别保险
        List<SysUserLevelInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(userId)
              .stream().filter(sysUserLevelInsurance -> !((sysUserLevelInsurance.getEndDate() != null && sysUserLevelInsurance.getEndDate().before(enterProjectTime)) || sysUserLevelInsurance.getStartDate().after(exitProjectTime)))
              .collect(Collectors.toList());
//    @Override
//    public BigDecimal calcUserCostByDate(Long userId, Timestamp enterProjectTime, Timestamp exitProjectTime, Map<String, Double> costHoursMap) {
//        // 工资
//        BigDecimal wageCost = BigDecimal.valueOf(0);
//        // 工作天数
//        LocalDateTime enterProject = enterProjectTime.toLocalDateTime();
//        LocalDateTime exitProject = exitProjectTime.toLocalDateTime();
//
////        // 通过id获取用户级别工资
////        List<UserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findUserLevelWageByUserId(userId)
////              .stream().filter(sysUserLevelWage -> !((sysUserLevelWage.getYearMonth().getEndDate() != null && sysUserLevelWage.getEndDate().before(enterProjectTime)) || sysUserLevelWage.getStartDate().after(exitProjectTime)))
////              .collect(Collectors.toList());
////        // 通过id获取用户级别保险
////        List<SysUserLevelInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(userId)
////              .stream().filter(sysUserLevelInsurance -> !((sysUserLevelInsurance.getEndDate() != null && sysUserLevelInsurance.getEndDate().before(enterProjectTime)) || sysUserLevelInsurance.getStartDate().after(exitProjectTime)))
////              .collect(Collectors.toList());
//
//        List<UserLevelWage> userLevelWages = sysUserLevelWageRepository.findUserLevelWageByUserId(userId);
//        UserInsurance userInsurance = sysUserLevelInsuranceRepository.findbyUserIdAndDate(userId, enterProject.format(DateTimeFormatter.ofPattern("yyyy-MM")));
//
//        // 判断是否有用户级别工资
//        if(sysUserLevelWages.size() <= 0){
//        if(userLevelWages.size() == 0){
//            throw new BadRequestException("此用户暂无级别工资");
//        }
//        UserLevelWage userLevelWage = userLevelWages.get(0);
//        // 判断是否有用户级别保险
//        if(sysUserLevelInsurances.size() <= 0){
//        if(userInsurance == null){
//            throw new BadRequestException("此用户暂无级别保险");
//        }
//
////       Map<Long, Double> sysUserLevelWageHoursMap = new HashMap<Long, Double>();
////       for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) {
////          sysUserLevelWageHoursMap.put(sysUserLevelWage.getId(), 0.0);
////       }
////
////       Map<Long, Double> sysUserLevelInsuranceHoursMap = new HashMap<Long, Double>();
////       for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) {
////          sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getId(), 0.0);
////       }
//
////        for (LocalDate currentLocalDate = enterProject.toLocalDate();
////              currentLocalDate.isBefore(exitProject.toLocalDate()) || currentLocalDate.isEqual(exitProject.toLocalDate());
////              currentLocalDate = currentLocalDate.plusDays(1)) {
////
////           String dateStr = currentLocalDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
////           if (!costHoursMap.containsKey(dateStr)) {
////              continue;
////           }
////
////           Date currentDate = Date.from(currentLocalDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
////
////           Double costHours = costHoursMap.get(dateStr);
////
////           for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) {
////              if (sysUserLevelWage.getEndDate() == null || sysUserLevelWage.getEndDate().after(currentDate) || sysUserLevelWage.getEndDate().equals(currentDate)) {
////                 sysUserLevelWageHoursMap.put(sysUserLevelWage.getId(), costHours + sysUserLevelWageHoursMap.get(sysUserLevelWage.getId()));
////                 break;
////              }
////           }
////
////           for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) {
////              if (sysUserLevelInsurance.getEndDate() == null || sysUserLevelInsurance.getEndDate().after(currentDate) || sysUserLevelInsurance.getEndDate().equals(currentDate)) {
////                 sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getId(), costHours + sysUserLevelInsuranceHoursMap.get(sysUserLevelInsurance.getId()));
////                 break;
////              }
////           }
////        }
//
//        for (Entry<Long, Double> entry : sysUserLevelWageHoursMap.entrySet()) {
//           SysUserLevelWage sysLevel = sysUserLevelWageRepository.findById(entry.getKey()).orElseGet(SysUserLevelWage::new);
//           wageCost = wageCost.add(sysLevel.getLevelWage().multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));
//        }
//
//        for (Entry<Long, Double> entry : sysUserLevelInsuranceHoursMap.entrySet()) {
//           SysUserLevelInsurance sysLevel = sysUserLevelInsuranceRepository.findById(entry.getKey()).orElseGet(SysUserLevelInsurance::new);
//
//            BigDecimal accumulationRadix = sysLevel.getAccumulationRadix().multiply(BigDecimal.valueOf(sysLevel.getAccumulationCompanyProportion() / 100));
//            BigDecimal pensionRadix = sysLevel.getPensionRadix().multiply(BigDecimal.valueOf(sysLevel.getPensionCompanyProportion() / 100));
//            BigDecimal medicalRadix = sysLevel.getMedicalRadix().multiply(BigDecimal.valueOf(sysLevel.getMedicalCompanyProportion() / 100));
//            BigDecimal unemploymentRadix = sysLevel.getUnemploymentRadix().multiply(BigDecimal.valueOf(sysLevel.getUnemploymentCompanyProportion() / 100));
//            BigDecimal maternityRadix = sysLevel.getMaternityRadix().multiply(BigDecimal.valueOf(sysLevel.getMaternityCompanyProportion() / 100));
//            BigDecimal industrialInjuryRadix = sysLevel.getIndustrialInjuryRadix().multiply(BigDecimal.valueOf(sysLevel.getIndustrialInjuryCompanyProportion() / 100));
//
//            wageCost = wageCost.add(accumulationRadix.add(pensionRadix).add(medicalRadix).add(unemploymentRadix).add(maternityRadix).add(industrialInjuryRadix).multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));
//        }
//
//        return wageCost;
//    }
       Map<Long, Double> sysUserLevelWageHoursMap = new HashMap<Long, Double>();
       for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) {
          sysUserLevelWageHoursMap.put(sysUserLevelWage.getId(), 0.0);
    @Override
    public BigDecimal calcUserCostByHours(Long userId, Double timeTotalCost) {
        // 工资
        BigDecimal wageCost = BigDecimal.valueOf(0);
        // 通过id获取用户级别工资
        List<UserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findUserLevelWageByUserId(userId);
        if (sysUserLevelWages.size() == 0) {
            return BigDecimal.ZERO;
        }
        // 通过id获取用户级别保险
        List<UserInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(userId);
        if (sysUserLevelInsurances.size() == 0) {
            return BigDecimal.ZERO;
       }
       Map<Long, Double> sysUserLevelInsuranceHoursMap = new HashMap<Long, Double>();
       for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) {
          sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getId(), 0.0);
       }
        // 工资
        UserLevelWage sysUserLevelWage = sysUserLevelWages.get(sysUserLevelWages.size() - 1);
        wageCost = wageCost.add(sysUserLevelWage.getBasicWage().add(sysUserLevelWage.getRankWage()).add(sysUserLevelWage.getPerformanceWage()).multiply(BigDecimal.valueOf(timeTotalCost)).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));
        for (LocalDate currentLocalDate = enterProject.toLocalDate();
              currentLocalDate.isBefore(exitProject.toLocalDate()) || currentLocalDate.isEqual(exitProject.toLocalDate());
              currentLocalDate = currentLocalDate.plusDays(1)) {
        // 五险一金
        UserInsurance sysUserLevelInsurance = sysUserLevelInsurances.get(sysUserLevelInsurances.size() - 1);
        BigDecimal accumulationRadix = sysUserLevelInsurance.getAccumulationFund().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getAccumulationFundCompany() / 100));
        BigDecimal pensionRadix = sysUserLevelInsurance.getRetirementInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getRetirementInsuranceCompany() / 100));
        BigDecimal medicalRadix = sysUserLevelInsurance.getMedicalInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getMedicalInsuranceCompany() / 100));
        BigDecimal unemploymentRadix = sysUserLevelInsurance.getUnemploymentInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getUnemploymentInsuranceCompany() / 100));
        BigDecimal maternityRadix = sysUserLevelInsurance.getBirthInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getBirthInsuranceCompany() / 100));
        BigDecimal industrialInjuryRadix = sysUserLevelInsurance.getEmploymentInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getEmploymentInsuranceCompany() / 100));
           String dateStr = currentLocalDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
           if (!costHoursMap.containsKey(dateStr)) {
              continue;
           }
           Date currentDate = Date.from(currentLocalDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
           Double costHours = costHoursMap.get(dateStr);
           for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) {
              if (sysUserLevelWage.getEndDate() == null || sysUserLevelWage.getEndDate().after(currentDate) || sysUserLevelWage.getEndDate().equals(currentDate)) {
                 sysUserLevelWageHoursMap.put(sysUserLevelWage.getId(), costHours + sysUserLevelWageHoursMap.get(sysUserLevelWage.getId()));
                 break;
              }
           }
           for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) {
              if (sysUserLevelInsurance.getEndDate() == null || sysUserLevelInsurance.getEndDate().after(currentDate) || sysUserLevelInsurance.getEndDate().equals(currentDate)) {
                 sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getId(), costHours + sysUserLevelInsuranceHoursMap.get(sysUserLevelInsurance.getId()));
                 break;
              }
           }
        }
        for (Entry<Long, Double> entry : sysUserLevelWageHoursMap.entrySet()) {
           SysUserLevelWage sysLevel = sysUserLevelWageRepository.findById(entry.getKey()).orElseGet(SysUserLevelWage::new);
           wageCost = wageCost.add(sysLevel.getLevelWage().multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));
        }
        for (Entry<Long, Double> entry : sysUserLevelInsuranceHoursMap.entrySet()) {
           SysUserLevelInsurance sysLevel = sysUserLevelInsuranceRepository.findById(entry.getKey()).orElseGet(SysUserLevelInsurance::new);
            BigDecimal accumulationRadix = sysLevel.getAccumulationRadix().multiply(BigDecimal.valueOf(sysLevel.getAccumulationCompanyProportion() / 100));
            BigDecimal pensionRadix = sysLevel.getPensionRadix().multiply(BigDecimal.valueOf(sysLevel.getPensionCompanyProportion() / 100));
            BigDecimal medicalRadix = sysLevel.getMedicalRadix().multiply(BigDecimal.valueOf(sysLevel.getMedicalCompanyProportion() / 100));
            BigDecimal unemploymentRadix = sysLevel.getUnemploymentRadix().multiply(BigDecimal.valueOf(sysLevel.getUnemploymentCompanyProportion() / 100));
            BigDecimal maternityRadix = sysLevel.getMaternityRadix().multiply(BigDecimal.valueOf(sysLevel.getMaternityCompanyProportion() / 100));
            BigDecimal industrialInjuryRadix = sysLevel.getIndustrialInjuryRadix().multiply(BigDecimal.valueOf(sysLevel.getIndustrialInjuryCompanyProportion() / 100));
            wageCost = wageCost.add(accumulationRadix.add(pensionRadix).add(medicalRadix).add(unemploymentRadix).add(maternityRadix).add(industrialInjuryRadix).multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));
        }
        wageCost = wageCost.add(accumulationRadix.add(pensionRadix).add(medicalRadix).add(unemploymentRadix).add(maternityRadix).add(industrialInjuryRadix).multiply(BigDecimal.valueOf(timeTotalCost)).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));
        return wageCost;
    }
@@ -301,7 +321,7 @@
           if ("".equals(dateType)) {
              dateType = currentLocalDate.getDayOfWeek() == DayOfWeek.SATURDAY || currentLocalDate.getDayOfWeek() == DayOfWeek.SUNDAY ? Constant.DATE_TYPE_WEEKEND : Constant.DATE_TYPE_WEEKDAY;
           }
           if (Constant.DATE_TYPE_WEEKEND.equals(dateType) || Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType)) {
           if (Constant.DATE_TYPE_WEEKEND.equals(dateType) || Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType) || Constant.DATE_TYPE_HOLIDAYS.equals(dateType)) {
              continue;
           }
@@ -311,25 +331,25 @@
                 if (exitProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0) {
                    exitProject = exitProject.with(sysRostering.getLunchStartTime());
                 }
                 costHours = costHours + sysRostering.getWorkStartTime().until(exitProject.toLocalTime(), ChronoUnit.HOURS);
                 costHours = costHours + BigDecimal.valueOf(sysRostering.getWorkStartTime().until(exitProject.toLocalTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
              } else if (exitProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) > 0 && exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) {
                 costHours = costHours + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS) + sysRostering.getLunchEndTime().until(exitProject.toLocalTime(), ChronoUnit.HOURS);
                 costHours = costHours + BigDecimal.valueOf(sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES) + sysRostering.getLunchEndTime().until(exitProject.toLocalTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
              } else if (exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) >= 0) {
                 costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
                 costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
              }
           } else if (currentLocalDate.isEqual(enterProject.toLocalDate())) {
              if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) <= 0) {
                 costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
                 costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
              } else if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) <= 0) {
                 costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + enterProject.toLocalTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
                 costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + enterProject.toLocalTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
              } else if (enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) {
                 if (enterProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) < 0) {
                    enterProject = enterProject.with(sysRostering.getLunchEndTime());
                 }
                 costHours = costHours + enterProject.toLocalTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS);
                 costHours = costHours + BigDecimal.valueOf(enterProject.toLocalTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
              }
           } else {
              costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
              costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
           }
        }
        return costHours;
@@ -352,21 +372,25 @@
        // 通过id获取用户信息
        UserDto user = userService.findById(criteria.getUserId());
        // 通过id获取用户级别工资
        Optional<SysUserLevelWage> sysUserLevelWageOpl = sysUserLevelWageRepository.findByUserId(criteria.getUserId())
              .stream().filter(sysUserLevelWage -> !((sysUserLevelWage.getEndDate() != null && sysUserLevelWage.getEndDate().before(startDate)) || sysUserLevelWage.getStartDate().after(endDate)))
              .max((o1, o2) -> o1.getStartDate().compareTo(o2.getStartDate()));
        // 通过id获取用户级别保险
        Optional<SysUserLevelInsurance> sysUserLevelInsuranceOpl = sysUserLevelInsuranceRepository.findByUserId(criteria.getUserId())
              .stream().filter(sysUserLevelInsurance -> !((sysUserLevelInsurance.getEndDate() != null && sysUserLevelInsurance.getEndDate().before(startDate)) || sysUserLevelInsurance.getStartDate().after(endDate)))
              .max((o1, o2) -> o1.getStartDate().compareTo(o2.getStartDate()));
//        // 通过id获取用户级别工资
//        Optional<SysUserLevelWage> sysUserLevelWageOpl = sysUserLevelWageRepository.findByUserId(criteria.getUserId())
//              .stream().filter(sysUserLevelWage -> !((sysUserLevelWage.getEndDate() != null && sysUserLevelWage.getEndDate().before(startDate)) || sysUserLevelWage.getStartDate().after(endDate)))
//              .max((o1, o2) -> o1.getStartDate().compareTo(o2.getStartDate()));
//        // 通过id获取用户级别保险
//        Optional<SysUserLevelInsurance> sysUserLevelInsuranceOpl = sysUserLevelInsuranceRepository.findByUserId(criteria.getUserId())
//              .stream().filter(sysUserLevelInsurance -> !((sysUserLevelInsurance.getEndDate() != null && sysUserLevelInsurance.getEndDate().before(startDate)) || sysUserLevelInsurance.getStartDate().after(endDate)))
//              .max((o1, o2) -> o1.getStartDate().compareTo(o2.getStartDate()));
        List<UserLevelWage> userLevelWageList = sysUserLevelWageRepository.findUserLevelWageByUserId(criteria.getUserId());
        List<UserInsurance> userInsurances = sysUserLevelInsuranceRepository.findByUserId(criteria.getUserId());
        // 判断是否有用户级别工资
        if (!sysUserLevelWageOpl.isPresent()) {
        if (userLevelWageList.size() == 0) {
            throw new BadRequestException("此用户暂无级别工资");
        }
        // 判断是否有用户级别保险
        if (!sysUserLevelInsuranceOpl.isPresent()) {
        if (userInsurances.size() == 0) {
            throw new BadRequestException("此用户暂无级别保险");
        }
@@ -387,7 +411,7 @@
               if ("".equals(dateType)) {
                  dateType = currentLocalDate.getDayOfWeek() == DayOfWeek.SATURDAY || currentLocalDate.getDayOfWeek() == DayOfWeek.SUNDAY ? Constant.DATE_TYPE_WEEKEND : Constant.DATE_TYPE_WEEKDAY;
               }
               if (Constant.DATE_TYPE_WEEKEND.equals(dateType) || Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType)) {
               if (Constant.DATE_TYPE_WEEKEND.equals(dateType) || Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType) || Constant.DATE_TYPE_HOLIDAYS.equals(dateType)) {
                  continue;
               }
@@ -397,25 +421,25 @@
                     if (exitProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0) {
                        exitProject = exitProject.with(sysRostering.getLunchStartTime());
                     }
                     costHours = costHours + sysRostering.getWorkStartTime().until(exitProject.toLocalTime(), ChronoUnit.HOURS);
                     costHours = costHours + BigDecimal.valueOf(sysRostering.getWorkStartTime().until(exitProject.toLocalTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
                  } else if (exitProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) > 0 && exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) {
                     costHours = costHours + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS) + sysRostering.getLunchEndTime().until(exitProject.toLocalTime(), ChronoUnit.HOURS);
                     costHours = costHours + BigDecimal.valueOf(sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES) + sysRostering.getLunchEndTime().until(exitProject.toLocalTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
                  } else if (exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) >= 0) {
                     costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
                     costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
                  }
               } else if (currentLocalDate.isEqual(enterProject.toLocalDate())) {
                  if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) <= 0) {
                     costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
                     costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
                  } else if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) <= 0) {
                     costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + enterProject.toLocalTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
                     costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + enterProject.toLocalTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
                  } else if (enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) {
                     if (enterProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) < 0) {
                        enterProject = enterProject.with(sysRostering.getLunchEndTime());
                     }
                     costHours = costHours + enterProject.toLocalTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS);
                     costHours = costHours + BigDecimal.valueOf(enterProject.toLocalTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
                  }
               } else {
                  costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS);
                  costHours = costHours + BigDecimal.valueOf(sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.MINUTES) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.MINUTES)).divide(BigDecimal.valueOf(60), 2, BigDecimal.ROUND_CEILING).doubleValue();
               }
            }
        } else {
@@ -426,18 +450,22 @@
        projectCost.setInvolvementHours(BigDecimal.valueOf(costHours));
        // 用户级别工资成本
       SysLevel sysLevelWage = sysLevelRepository.findById(sysUserLevelWageOpl.get().getLevelId()).orElseGet(SysLevel::new);
       wageCost = wageCost.add(sysLevelWage.getLevelWage().multiply(BigDecimal.valueOf(costHours)).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));
       wageCost = wageCost.add(userLevelWageList.get(0).getBasicWage())
                .add(userLevelWageList.get(0).getRankWage())
                .add(userLevelWageList.get(0).getPerformanceWage())
                .multiply(BigDecimal.valueOf(costHours))
                .divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING);
       // 用户级别保险成本
       SysLevel sysLevelInsurance = sysLevelRepository.findById(sysUserLevelInsuranceOpl.get().getLevelId()).orElseGet(SysLevel::new);
        UserInsurance sysLevelInsurance = userInsurances.stream().max(Comparator.comparing(UserInsurance::getYearMonth)).orElseGet(UserInsurance::new);
        BigDecimal accumulationRadix = sysLevelInsurance.getAccumulationRadix().multiply(BigDecimal.valueOf(sysLevelInsurance.getAccumulationCompanyProportion() / 100));
        BigDecimal pensionRadix = sysLevelInsurance.getPensionRadix().multiply(BigDecimal.valueOf(sysLevelInsurance.getPensionCompanyProportion() / 100));
        BigDecimal medicalRadix = sysLevelInsurance.getMedicalRadix().multiply(BigDecimal.valueOf(sysLevelInsurance.getMedicalCompanyProportion() / 100));
        BigDecimal unemploymentRadix = sysLevelInsurance.getUnemploymentRadix().multiply(BigDecimal.valueOf(sysLevelInsurance.getUnemploymentCompanyProportion() / 100));
        BigDecimal maternityRadix = sysLevelInsurance.getMaternityRadix().multiply(BigDecimal.valueOf(sysLevelInsurance.getMaternityCompanyProportion() / 100));
        BigDecimal industrialInjuryRadix = sysLevelInsurance.getIndustrialInjuryRadix().multiply(BigDecimal.valueOf(sysLevelInsurance.getIndustrialInjuryCompanyProportion() / 100));
        BigDecimal accumulationRadix = sysLevelInsurance.getAccumulationFund().multiply(BigDecimal.valueOf(sysLevelInsurance.getAccumulationFundCompany() / 100));
        BigDecimal pensionRadix = sysLevelInsurance.getRetirementInsurance().multiply(BigDecimal.valueOf(sysLevelInsurance.getRetirementInsuranceCompany() / 100));
        BigDecimal medicalRadix = sysLevelInsurance.getMedicalInsurance().multiply(BigDecimal.valueOf(sysLevelInsurance.getMedicalInsuranceCompany() / 100));
        BigDecimal unemploymentRadix = sysLevelInsurance.getUnemploymentInsurance().multiply(BigDecimal.valueOf(sysLevelInsurance.getUnemploymentInsuranceCompany() / 100));
        BigDecimal maternityRadix = sysLevelInsurance.getBirthInsurance().multiply(BigDecimal.valueOf(sysLevelInsurance.getBirthInsuranceCompany() / 100));
        BigDecimal industrialInjuryRadix = sysLevelInsurance.getEmploymentInsurance().multiply(BigDecimal.valueOf(sysLevelInsurance.getEmploymentInsuranceCompany() / 100));
        wageCost = wageCost.add(accumulationRadix.add(pensionRadix).add(medicalRadix).add(unemploymentRadix).add(maternityRadix).add(industrialInjuryRadix).multiply(BigDecimal.valueOf(costHours)).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING));