| | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ProjectCost getCost(ProjectCostQueryCriteria criteria) throws ParseException { |
| | | ProjectCost projectCost = new ProjectCost(); |
| | | // 工资 |
| | | BigDecimal wageCost = BigDecimal.valueOf(0); |
| | | public Double getHours(ProjectCostQueryCriteria criteria) throws ParseException { |
| | | // 工时 |
| | | Double costHours = 0.0; |
| | | |
| | | // 工作天数 |
| | | LocalDateTime enterProject = criteria.getEnterProjectTime().toLocalDateTime(); |
| | | LocalDateTime exitProject = criteria.getExitProjectTime().toLocalDateTime(); |
| | | |
| | | Date startDate = criteria.getEnterProjectTime(); |
| | | Date endDate = criteria.getExitProjectTime(); |
| | | |
| | | |
| | | // 通过id获取用户信息 |
| | | UserDto user = userService.findById(criteria.getUserId()); |
| | | // 通过id获取用户级别工资 |
| | | List<SysUserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findByUserId(criteria.getUserId()) |
| | | .stream().filter(sysUserLevelWage -> !((sysUserLevelWage.getEndDate() != null && sysUserLevelWage.getEndDate().before(startDate)) || sysUserLevelWage.getStartDate().after(endDate))) |
| | | .collect(Collectors.toList()); |
| | | // 通过id获取用户级别保险 |
| | | List<SysUserLevelInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(criteria.getUserId()) |
| | | .stream().filter(sysUserLevelInsurance -> !((sysUserLevelInsurance.getEndDate() != null && sysUserLevelInsurance.getEndDate().before(startDate)) || sysUserLevelInsurance.getStartDate().after(endDate))) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 判断是否有用户级别工资 |
| | | if(sysUserLevelWages.size() <= 0){ |
| | | throw new BadRequestException("此用户暂无级别工资"); |
| | | } |
| | | // 判断是否有用户级别保险 |
| | | if(sysUserLevelInsurances.size() <= 0){ |
| | | throw new BadRequestException("此用户暂无级别保险"); |
| | | } |
| | | |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findByHolidayDateBetween(criteria.getEnterProjectTime(), criteria.getExitProjectTime()); |
| | | |
| | | Map<Long, Double> sysUserLevelWageHoursMap = new HashMap<Long, Double>(); |
| | | for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) { |
| | | sysUserLevelWageHoursMap.put(sysUserLevelWage.getLevelId(), 0.0); |
| | | } |
| | | |
| | | Map<Long, Double> sysUserLevelInsuranceHoursMap = new HashMap<Long, Double>(); |
| | | for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) { |
| | | sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getLevelId(), 0.0); |
| | | } |
| | | |
| | | for (LocalDate currentLocalDate = enterProject.toLocalDate(); |
| | | currentLocalDate.isBefore(exitProject.toLocalDate()) || currentLocalDate.isEqual(exitProject.toLocalDate()); |
| | |
| | | continue; |
| | | } |
| | | |
| | | Date currentDate = Date.from(currentLocalDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); |
| | | |
| | | Double costHours = 0.0; |
| | | SysRosteringDto sysRostering = user.getSysRostering(); |
| | | |
| | | if (currentLocalDate.isEqual(exitProject.toLocalDate())) { |
| | | if (exitProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && exitProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) <= 0) { |
| | | if (exitProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0) { |
| | |
| | | } else { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } |
| | | } |
| | | return costHours; |
| | | } |
| | | |
| | | for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) { |
| | | if (sysUserLevelWage.getEndDate() == null || sysUserLevelWage.getEndDate().after(currentDate) || sysUserLevelWage.getEndDate().equals(currentDate)) { |
| | | sysUserLevelWageHoursMap.put(sysUserLevelWage.getLevelId(), costHours + sysUserLevelWageHoursMap.get(sysUserLevelWage.getLevelId())); |
| | | break; |
| | | } |
| | | } |
| | | @Override |
| | | public ProjectCost getCost(ProjectCostQueryCriteria criteria) throws ParseException { |
| | | ProjectCost projectCost = new ProjectCost(); |
| | | // 工资 |
| | | BigDecimal wageCost = BigDecimal.valueOf(0); |
| | | // 工时 |
| | | Double costHours = 0.0; |
| | | |
| | | for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) { |
| | | if (sysUserLevelInsurance.getEndDate() == null || sysUserLevelInsurance.getEndDate().after(currentDate) || sysUserLevelInsurance.getEndDate().equals(currentDate)) { |
| | | sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getLevelId(), costHours + sysUserLevelInsuranceHoursMap.get(sysUserLevelInsurance.getLevelId())); |
| | | break; |
| | | } |
| | | } |
| | | // 工作天数 |
| | | LocalDateTime enterProject = criteria.getEnterProjectTime().toLocalDateTime(); |
| | | LocalDateTime exitProject = criteria.getExitProjectTime().toLocalDateTime(); |
| | | |
| | | Date startDate = criteria.getEnterProjectTime(); |
| | | Date endDate = criteria.getExitProjectTime(); |
| | | |
| | | // 通过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())); |
| | | |
| | | // 判断是否有用户级别工资 |
| | | if (!sysUserLevelWageOpl.isPresent()) { |
| | | throw new BadRequestException("此用户暂无级别工资"); |
| | | } |
| | | // 判断是否有用户级别保险 |
| | | if (!sysUserLevelInsuranceOpl.isPresent()) { |
| | | throw new BadRequestException("此用户暂无级别保险"); |
| | | } |
| | | |
| | | for (Entry<Long, Double> entry : sysUserLevelWageHoursMap.entrySet()) { |
| | | SysLevel sysLevel = sysLevelRepository.findById(entry.getKey()).orElseGet(SysLevel::new); |
| | | wageCost = wageCost.add(sysLevel.getLevelWage().multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING)); |
| | | if (criteria.getInvolvementHours() == null) { |
| | | // 获取假期数据 |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findByHolidayDateBetween(criteria.getEnterProjectTime(), criteria.getExitProjectTime()); |
| | | |
| | | for (LocalDate currentLocalDate = enterProject.toLocalDate(); |
| | | currentLocalDate.isBefore(exitProject.toLocalDate()) || currentLocalDate.isEqual(exitProject.toLocalDate()); |
| | | currentLocalDate = currentLocalDate.plusDays(1)) { |
| | | String dateType = ""; |
| | | for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayList) { |
| | | if (currentLocalDate.isEqual(sysConfigHoliday.getHolidayDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())) { |
| | | dateType = sysConfigHoliday.getDateType(); |
| | | break; |
| | | } |
| | | } |
| | | 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)) { |
| | | continue; |
| | | } |
| | | |
| | | SysRosteringDto sysRostering = user.getSysRostering(); |
| | | if (currentLocalDate.isEqual(exitProject.toLocalDate())) { |
| | | if (exitProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && exitProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) <= 0) { |
| | | if (exitProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0) { |
| | | exitProject = exitProject.with(sysRostering.getLunchStartTime()); |
| | | } |
| | | costHours = costHours + sysRostering.getWorkStartTime().until(exitProject.toLocalTime(), ChronoUnit.HOURS); |
| | | } 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); |
| | | } else if (exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) >= 0) { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } |
| | | } 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); |
| | | } 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); |
| | | } 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); |
| | | } |
| | | } else { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } |
| | | } |
| | | } else { |
| | | costHours = criteria.getInvolvementHours(); |
| | | } |
| | | |
| | | for (Entry<Long, Double> entry : sysUserLevelInsuranceHoursMap.entrySet()) { |
| | | SysLevel sysLevel = sysLevelRepository.findById(entry.getKey()).orElseGet(SysLevel::new); |
| | | // 参与工时 |
| | | projectCost.setInvolvementHours(BigDecimal.valueOf(costHours)); |
| | | |
| | | 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)); |
| | | // 用户级别工资成本 |
| | | 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(accumulationRadix.add(pensionRadix).add(medicalRadix).add(unemploymentRadix).add(maternityRadix).add(industrialInjuryRadix).multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING)); |
| | | } |
| | | // 用户级别保险成本 |
| | | SysLevel sysLevelInsurance = sysLevelRepository.findById(sysUserLevelInsuranceOpl.get().getLevelId()).orElseGet(SysLevel::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)); |
| | | |
| | | 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)); |
| | | |
| | | projectCost.setProjectCost(wageCost); |
| | | return projectCost; |