Browse Source

项目月打卡数据新增年月筛选

anderx 2 years ago
parent
commit
24dd473e3e

+ 2 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -399,8 +399,8 @@ public class ProjectTaskController extends BaseController {
 
     @GetMapping("/myDurationMonth")
     @ApiOperation("查询我的月份数据")
-    public AjaxResult myDurationMonth(Long id){
-        return projectStaffRecordService.myDurationMonth(id);
+    public AjaxResult myDurationMonth(Long id,Integer year,Integer month){
+        return projectStaffRecordService.myDurationMonth(id,year,month);
     }
 
     /**

+ 15 - 7
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -201,22 +201,30 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         return Date.from(zdt.toInstant());
     }
 
-    public static String firsDayOfMonth(){
-        LocalDateTime date=LocalDateTime.now();
+    public static String firsDayOfMonth(Integer year,Integer month){
+        LocalDateTime date = null;
+        if (year!=null && month!=null){
+            date=LocalDateTime.of(year,month,1,0,0);
+        }else {
+            date = LocalDateTime.now();
+        }
         date = date.with(TemporalAdjusters.firstDayOfMonth());
 
         return date.format(DateTimeFormatter.ofPattern(YYYY_MM_DD));
     }
 
-    public static String lastDayOfMonth(){
-        LocalDateTime date=LocalDateTime.now();
+    public static String lastDayOfMonth(Integer year,Integer month){
+        LocalDateTime date=null;
+        if (year!=null && month!=null){
+            date=LocalDateTime.of(year,month,1,0,0);
+        }else {
+            date = LocalDateTime.now();
+        }
         date = date.with(TemporalAdjusters.lastDayOfMonth());
         return date.format(DateTimeFormatter.ofPattern(YYYY_MM_DD));
     }
 
-    public static void main(String[] args) {
-        System.out.println(lastDayOfMonth());
-    }
+
 
     public static int getWeeks(String dates) {
         Calendar cal=Calendar.getInstance();

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectStaffRecordService.java

@@ -26,7 +26,7 @@ public interface ProjectStaffRecordService {
 
     AjaxResult updateCheckMaxDuration(ProjectStaffRecord in);
 
-    AjaxResult myDurationMonth(Long id);
+    AjaxResult myDurationMonth(Long id,Integer year,Integer month);
 
     AjaxResult recordDetails(Long id);
 

+ 14 - 12
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectStaffRecordServiceImpl.java

@@ -36,11 +36,11 @@ import javax.servlet.http.HttpServletResponse;
 import javax.validation.Validator;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
@@ -150,14 +150,16 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
     }
 
     @Override
-    public AjaxResult myDurationMonth(Long id) {
+    public AjaxResult myDurationMonth(Long id,Integer year,Integer month) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(id);
         BigDecimal maxDuration= new BigDecimal(loginUser.getUser().getDept().getMaxDuration());
         String  date=DateUtils.getDate();
+        String firsDayOfMonth=DateUtils.firsDayOfMonth(year,month);
+        String lastDayOfMonth=DateUtils.lastDayOfMonth(year,month);
         Long aid=loginUser.getUserId();
-        List<MyMonthDays> myMonthDays = projectStaffRecordMapper.myDurationMonth(id, aid, DateUtils.firsDayOfMonth(), DateUtils.lastDayOfMonth() + " 23:59:59");
-        supplementMyMonthDays(myMonthDays);
+        List<MyMonthDays> myMonthDays = projectStaffRecordMapper.myDurationMonth(id, aid,firsDayOfMonth,lastDayOfMonth  + " 23:59:59");
+        supplementMyMonthDays(myMonthDays,firsDayOfMonth,lastDayOfMonth);
         for (MyMonthDays myMonthDay : myMonthDays) {
             DateUtils.getWeeks(myMonthDay.getDates());
 //            0 =未到时限 1=满工时,2=未打卡,3=未满工时,4=不属于打卡区间
@@ -285,14 +287,16 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         return false;
     }
 
-    private void supplementMyMonthDays(List<MyMonthDays> myMonthDays) {
-        List<Map<String,Object>> monthDays = getMonthDays();
+    private void supplementMyMonthDays(List<MyMonthDays> myMonthDays, String firsDayOfMonth, String lastDayOfMonth) {
+        List<Map<String,Object>> monthDays = getMonthDays(firsDayOfMonth,lastDayOfMonth);
+        List<MyMonthDays> list=new ArrayList<MyMonthDays>();
         for ( Map<String,Object> map : monthDays) {
             boolean flag= true;
             for (MyMonthDays myMonthDay : myMonthDays) {
                 if (map.get("days").equals(myMonthDay.getDates())){
                     flag=false;
                     myMonthDay.setWeek((Integer) map.get("week"));
+                    list.add(myMonthDay);
                     break;
                 }
             }
@@ -302,18 +306,16 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
                 mmd.setWeek((Integer) map.get("week"));
                 mmd.setDuration("0");
                 mmd.setStatus(0);
-                myMonthDays.add(mmd);
+                list.add(mmd);
             }
         }
+        myMonthDays.clear();
+        myMonthDays.addAll(list);
     }
 
-    private static List<Map<String,Object>> getMonthDays() {
-        String firsDayOfMonth = DateUtils.firsDayOfMonth();
-        String lastDayOfMonth = DateUtils.lastDayOfMonth();
+    private static List<Map<String,Object>> getMonthDays(String firsDayOfMonth, String lastDayOfMonth) {
         List<Map<String,Object>> dates=new ArrayList<>();
-
         String str=firsDayOfMonth.substring(0,firsDayOfMonth.lastIndexOf("-"));
-
         for (int i=1; i<32;i++){
             Map<String,Object> map=new HashMap<>();
             String res;