From e818b1d6d438c2bfd3985d1edba1842fcf4af1d3 Mon Sep 17 00:00:00 2001
From: yaozc <unbelievers@yeah.net>
Date: Wed, 18 Jan 2023 01:38:50 +0000
Subject: [PATCH] 项目绩效
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java | 103 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 96 insertions(+), 7 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java
index 94dc076..37cd576 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java
@@ -151,6 +151,95 @@
}
@Override
+ public BigDecimal calcUserCostByDate(Long userId, String enterProjectTime, String exitProjectTime, Map<String, Double> costHoursMap) throws Exception {
+ // 工资
+ BigDecimal wageCost = BigDecimal.valueOf(0);
+ // 工作天数
+ LocalDateTime enterProject = LocalDateTime.parse(enterProjectTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ LocalDateTime exitProject = LocalDateTime.parse(exitProjectTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Date startDate = simpleDateFormat.parse(enterProjectTime);
+ Date endDate = simpleDateFormat.parse(exitProjectTime);
+
+ // 通过id获取用户级别工资
+ List<SysUserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findByUserId(userId)
+ .stream().filter(sysUserLevelWage -> !((sysUserLevelWage.getEndDate() != null && sysUserLevelWage.getEndDate().before(startDate)) || sysUserLevelWage.getStartDate().after(endDate)))
+ .collect(Collectors.toList());
+ // 通过id获取用户级别保险
+ List<SysUserLevelInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(userId)
+ .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("此用户暂无级别保险");
+ }
+
+ 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;
+ }
+
+ @Override
public ProjectCost getCost(ProjectCostQueryCriteria criteria) throws ParseException {
ProjectCost projectCost = new ProjectCost();
// 工资
@@ -186,14 +275,14 @@
List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findByHolidayDateBetween(simpleDateFormat.parse(criteria.getEnterProjectTime()), simpleDateFormat.parse(criteria.getExitProjectTime()));
- Map<Long, Long> sysUserLevelWageHoursMap = new HashMap<Long, Long>();
+ Map<Long, Double> sysUserLevelWageHoursMap = new HashMap<Long, Double>();
for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) {
- sysUserLevelWageHoursMap.put(sysUserLevelWage.getLevelId(), 0L);
+ sysUserLevelWageHoursMap.put(sysUserLevelWage.getLevelId(), 0.0);
}
- Map<Long, Long> sysUserLevelInsuranceHoursMap = new HashMap<Long, Long>();
+ Map<Long, Double> sysUserLevelInsuranceHoursMap = new HashMap<Long, Double>();
for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) {
- sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getLevelId(), 0L);
+ sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getLevelId(), 0.0);
}
for (LocalDate currentLocalDate = enterProject.toLocalDate();
@@ -215,7 +304,7 @@
Date currentDate = Date.from(currentLocalDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
- Long costHours = 0L;
+ Double costHours = 0.0;
SysRosteringDto sysRostering = user.getSysRostering();
if (currentLocalDate.isEqual(enterProject.toLocalDate())) {
@@ -259,12 +348,12 @@
}
}
- for (Entry<Long, Long> entry : sysUserLevelWageHoursMap.entrySet()) {
+ 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));
}
- for (Entry<Long, Long> entry : sysUserLevelInsuranceHoursMap.entrySet()) {
+ for (Entry<Long, Double> entry : sysUserLevelInsuranceHoursMap.entrySet()) {
SysLevel sysLevel = sysLevelRepository.findById(entry.getKey()).orElseGet(SysLevel::new);
BigDecimal accumulationRadix = sysLevel.getAccumulationRadix().multiply(BigDecimal.valueOf(sysLevel.getAccumulationCompanyProportion() / 100));
--
Gitblit v1.9.3