‘linchangsheng’ 3 maanden geleden
bovenliggende
commit
ccc29e8f90

+ 15 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/policy/PolicyOrderLogic.java

@@ -34,6 +34,7 @@ import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
@@ -311,6 +312,9 @@ public class PolicyOrderLogic {
                 if (policyOrderup.getStartTime().after(policyOrderup.getEndTime()))
                     throw new RemoteServiceException(policyOrder.getWorkerIdcard()+"开始时间不能大于结束时间");
 
+                if (!this.areInSameMonth(policyOrderup.getStartTime(),policyOrderup.getEndTime()))
+                    throw new RemoteServiceException(policyOrder.getWorkerIdcard()+"工伤险的有效时间必须在同一个月内");
+
 
                 if (new Date().after(policyOrderup.getStartTime()) && new Date().before(policyOrderup.getEndTime()))
                     policyOrderup.setPolicyOrderStatus("BZZ");
@@ -384,6 +388,17 @@ public class PolicyOrderLogic {
         }
     }
 
+    public boolean areInSameMonth(Date date1, Date date2) {
+        Calendar cal1 = Calendar.getInstance();
+        Calendar cal2 = Calendar.getInstance();
+
+        cal1.setTime(date1);
+        cal2.setTime(date2);
+
+        return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
+                cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
+    }
+
     @Transactional(rollbackFor = Exception.class)
     public void importEm(List<Object> objects) {
 

+ 16 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/policy/WorkerManagerLogic.java

@@ -33,6 +33,7 @@ import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -949,6 +950,10 @@ public class WorkerManagerLogic {
                 if (workerPolicy.getStartTime().after(workerPolicy.getEndTime()))
                     throw new RemoteServiceException(workerPolicy.getWorkerName()+"工伤开始时间不能大于结束时间");
 
+                if (!this.areInSameMonth(workerPolicy.getStartTime(),workerPolicy.getEndTime()))
+                    throw new RemoteServiceException(workerPolicy.getWorkerName()+"工伤险的有效时间必须在同一个月内");
+
+
                 if (workerPolicy.getEndTime().after(new Date()) && workerPolicy.getStartTime().before(new Date())) {
                     workerPolicy.setStatus("BZZ");
                 }else {
@@ -1004,6 +1009,17 @@ public class WorkerManagerLogic {
 
 }
 
+    public boolean areInSameMonth(Date date1, Date date2) {
+        Calendar cal1 = Calendar.getInstance();
+        Calendar cal2 = Calendar.getInstance();
+
+        cal1.setTime(date1);
+        cal2.setTime(date2);
+
+        return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
+                cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
+    }
+
     public WorkerUserCount countWorker( ) {