From 4156a5baafda2f44244eedcee842ef95bc2513ca Mon Sep 17 00:00:00 2001
From: 赵士淞 <zhaoss@yhzhg.cn>
Date: Mon, 26 Dec 2022 07:59:18 +0000
Subject: [PATCH] 用户级别保险

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java |   63 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
index 222f801..0cbec2d 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -21,11 +21,13 @@
 import me.zhengjie.modules.security.service.OnlineUserService;
 import me.zhengjie.modules.security.service.UserCacheManager;
 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.exception.EntityExistException;
 import me.zhengjie.exception.EntityNotFoundException;
 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.UserService;
@@ -67,6 +69,7 @@
     private final UserLoginMapper userLoginMapper;
     private final SysLevelRepository sysLevelRepository;
     private final SysUserLevelWageRepository sysUserLevelWageRepository;
+    private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository;
 
     @Override
     public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
@@ -314,6 +317,8 @@
         if (oldLevelId == null) {
             // 创建用户级别工资
             createSysUserLevelWage(userId, newLevelId);
+            // 创建用户级别保险
+            createSysUserLevelInsurance(userId, newLevelId);
         } else if (oldLevelId != newLevelId) {
             // 旧用户级别工资
             SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId);
@@ -342,6 +347,33 @@
             }
             // 创建用户级别工资
             createSysUserLevelWage(userId, newLevelId);
+            // 旧用户级别保险
+            SysUserLevelInsurance oldSysUserLevelInsurance = sysUserLevelInsuranceRepository.findLastByUserId(userId);
+            // 判断旧用户级别保险是否为空
+            if (oldSysUserLevelInsurance != null && oldSysUserLevelInsurance.getId() != null) {
+                // 旧日期字符串
+                String oldDateString = oldSysUserLevelInsurance.getStartDate().toString().substring(0,10);
+                // 获取当前日期
+                Date nowDate = new Date();
+                // 创建Calendar实例
+                Calendar nowCalendar = Calendar.getInstance();
+                // 设置当前时间
+                nowCalendar.setTime(nowDate);
+                // 新日期字符串
+                String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,10);
+                // 判断新、旧日期字符串
+                if (oldDateString.equals(nowDateString)) {
+                    throw new BadRequestException("每天只能调整一次级别,请明日再试!");
+                }
+                // 设置前一天时间
+                nowCalendar.add(Calendar.DATE, -1);
+                // 旧用户级别保险
+                oldSysUserLevelInsurance.setEndDate(new Timestamp(nowCalendar.getTime().getTime()));
+                // 保存
+                sysUserLevelInsuranceRepository.save(oldSysUserLevelInsurance);
+            }
+            // 创建用户级别保险
+            createSysUserLevelInsurance(userId, newLevelId);
         } else {
 
         }
@@ -368,4 +400,35 @@
         // 保存
         sysUserLevelWageRepository.save(sysUserLevelWage);
     }
+
+    // 创建用户级别保险
+    private void createSysUserLevelInsurance(Long userId, Long levelId) {
+        // 级别
+        SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new);
+        // 用户级别工资
+        SysUserLevelInsurance sysUserLevelInsurance = new SysUserLevelInsurance();
+        sysUserLevelInsurance.setUserId(userId);
+        sysUserLevelInsurance.setLevelId(levelId);
+        sysUserLevelInsurance.setStartDate(new Timestamp(new Date().getTime()));
+        sysUserLevelInsurance.setAccumulationRadix(sysLevel.getAccumulationRadix());
+        sysUserLevelInsurance.setAccumulationPersonalProportion(sysLevel.getAccumulationPersonalProportion());
+        sysUserLevelInsurance.setAccumulationCompanyProportion(sysLevel.getAccumulationCompanyProportion());
+        sysUserLevelInsurance.setPensionRadix(sysLevel.getPensionRadix());
+        sysUserLevelInsurance.setPensionPersonalProportion(sysLevel.getPensionPersonalProportion());
+        sysUserLevelInsurance.setPensionCompanyProportion(sysLevel.getPensionCompanyProportion());
+        sysUserLevelInsurance.setMedicalRadix(sysLevel.getMedicalRadix());
+        sysUserLevelInsurance.setMedicalPersonalProportion(sysLevel.getMedicalPersonalProportion());
+        sysUserLevelInsurance.setMedicalCompanyProportion(sysLevel.getMedicalCompanyProportion());
+        sysUserLevelInsurance.setUnemploymentRadix(sysLevel.getUnemploymentRadix());
+        sysUserLevelInsurance.setUnemploymentPersonalProportion(sysLevel.getUnemploymentPersonalProportion());
+        sysUserLevelInsurance.setUnemploymentCompanyProportion(sysLevel.getUnemploymentCompanyProportion());
+        sysUserLevelInsurance.setMaternityRadix(sysLevel.getMaternityRadix());
+        sysUserLevelInsurance.setMaternityPersonalProportion(sysLevel.getMaternityPersonalProportion());
+        sysUserLevelInsurance.setMaternityCompanyProportion(sysLevel.getMaternityCompanyProportion());
+        sysUserLevelInsurance.setIndustrialInjuryRadix(sysLevel.getIndustrialInjuryRadix());
+        sysUserLevelInsurance.setIndustrialInjuryPersonalProportion(sysLevel.getIndustrialInjuryPersonalProportion());
+        sysUserLevelInsurance.setIndustrialInjuryCompanyProportion(sysLevel.getIndustrialInjuryCompanyProportion());
+        // 保存
+        sysUserLevelInsuranceRepository.save(sysUserLevelInsurance);
+    }
 }

--
Gitblit v1.9.3