From f84d9e69907cb678150eaa6393fd74cf042fcca4 Mon Sep 17 00:00:00 2001
From: zenglf <18502938215@163.com>
Date: 星期四, 28 九月 2023 14:39:03 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into develop

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcVacationManagementServiceImpl.java |  167 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 140 insertions(+), 27 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcVacationManagementServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcVacationManagementServiceImpl.java
index 75df63e..33fb1af 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcVacationManagementServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcVacationManagementServiceImpl.java
@@ -1,19 +1,35 @@
 package org.jeecg.modules.mdc.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import net.sf.saxon.expr.Component;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.modules.mdc.entity.MdcEquipment;
+import org.jeecg.modules.mdc.entity.MdcStandardProcessDuration;
 import org.jeecg.modules.mdc.entity.MdcVacationManagement;
 import org.jeecg.modules.mdc.mapper.MdcVacationManagementMappper;
 import org.jeecg.modules.mdc.service.IMdcEquipmentService;
 import org.jeecg.modules.mdc.service.IMdcVacationManagementService;
+import org.jeecg.modules.mdc.util.DateUtils;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 
 /**
@@ -34,7 +50,20 @@
 
     @Override
     public Boolean addVacation(MdcVacationManagement mdcVacationManagement) {
-        return this.save(mdcVacationManagement);
+        boolean result = false;
+        String[] equipmentIds = mdcVacationManagement.getEquipmentIds().split(",");
+        for (String equipmentId : equipmentIds) {
+            MdcEquipment mdcEquipment = equipmentService.findEquipmentNameByEquipmentId(equipmentId);
+            MdcVacationManagement vacationManagement = new MdcVacationManagement();
+            BeanUtils.copyProperties(mdcVacationManagement, vacationManagement);
+            vacationManagement.setEquipmentId(mdcEquipment.getEquipmentId());
+            vacationManagement.setEquipmentName(mdcEquipment.getEquipmentName());
+            boolean b = super.save(vacationManagement);
+            if (b) {
+                result = true;
+            }
+        }
+        return result;
     }
 
     @Override
@@ -54,45 +83,129 @@
 
     @Override
     public IPage<MdcVacationManagement> pageList(String userId, Page page, HttpServletRequest req, MdcVacationManagement mdcVacationManagement) {
-        //鏄剧ず鍙屼紤鏃�
-        Date vacationDate=mdcVacationManagement.getVacationDate();
-        String type= mdcVacationManagement.getType();
-        Calendar c=Calendar.getInstance();
-        c.setTime(vacationDate);
-        int day=c.get(Calendar.DAY_OF_WEEK)-1;
-        System.out.println(day);
-        if (day==6||day==7){
-            System.out.println("鍙屼紤鏃�");
-            mdcVacationManagement.setType("鍙屼紤鏃�");
-        }
         //鏌ヨ鐢ㄦ埛鎵�鎷ユ湁鐨勮澶囦俊鎭�
-        List<String> equipmentIds=new ArrayList<>();
-        if (StringUtils.isNotEmpty(mdcVacationManagement.getParentId()) && StringUtils.isEmpty(mdcVacationManagement.getEquipmentId())){
-            if ("2".equals(mdcVacationManagement.getTypeTree())){
+        List<String> equipmentIds = new ArrayList<>();
+        if (StringUtils.isNotEmpty(mdcVacationManagement.getParentId()) && StringUtils.isEmpty(mdcVacationManagement.getEquipmentId())) {
+            if ("2".equals(mdcVacationManagement.getTypeTree())) {
                 //閮ㄩ棬灞傜骇
-                equipmentIds=equipmentService.getEquipmentIdsByDepart(userId,mdcVacationManagement.getParentId());
-            }else {
+                equipmentIds = equipmentService.getEquipmentIdsByDepart(userId, mdcVacationManagement.getParentId());
+            } else {
                 //浜х嚎灞傜骇
-                equipmentIds=equipmentService.getEquipmentIdsProduction(userId,mdcVacationManagement.getParentId());
+                equipmentIds = equipmentService.getEquipmentIdsProduction(userId, mdcVacationManagement.getParentId());
             }
-        }else if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentId())){
+        } else if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentId())) {
             //鍗曞彴璁惧淇℃伅
             mdcVacationManagement.setMdcSectionIds(Collections.singletonList(mdcVacationManagement.getEquipmentId()));
-        }else {
+        } else {
             //鏌ヨ鐢ㄦ埛鎵�鎷ユ湁鐨勮澶囦俊鎭�
-            if ("2".equals(mdcVacationManagement.getTypeTree())){
+            if ("2".equals(mdcVacationManagement.getTypeTree())) {
                 //閮ㄩ棬灞傜骇
-                equipmentIds=equipmentService.getEquipmentIdsByDepart(userId,null);
-            }else {
-                equipmentIds=equipmentService.getEquipmentIdsProduction(userId,null);
+                equipmentIds = equipmentService.getEquipmentIdsByDepart(userId, null);
+            } else {
+                equipmentIds = equipmentService.getEquipmentIdsProduction(userId, null);
             }
         }
-        if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()){
+        if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()) {
             mdcVacationManagement.setMdcSectionIds(equipmentIds);
         }
-        if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()){
+        if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()) {
             return null;
         }
-        return this.baseMapper.pageList(page,mdcVacationManagement);
+        return this.baseMapper.pageList(page, mdcVacationManagement);
+    }
+
+    /**
+     * 鐢熸垚鍙屼紤鏃�
+     */
+    @Override
+    public void generateWeekDays() {
+        MdcVacationManagement mdcVacationManagement = this.baseMapper.selectLastWeekDays();
+        // 鑾峰彇鐢熸垚寮�濮嬫椂闂村拰缁撴潫鏃堕棿
+        LocalDate startDate;
+        LocalDate endDate;
+        if (mdcVacationManagement == null) {
+            startDate = LocalDate.now();
+            endDate = LocalDate.of(DateUtils.getYear(), DateUtils.getMonth(), DateUtils.getDayOfMonth());
+        } else {
+            LocalDate vacationDate = mdcVacationManagement.getVacationDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().plusMonths(1);
+            startDate = vacationDate.with(TemporalAdjusters.firstDayOfMonth());
+            endDate = vacationDate.with(TemporalAdjusters.lastDayOfMonth());
+        }
+        List<MdcVacationManagement> list = new ArrayList<>();
+        // 鑾峰彇寮�濮嬫椂闂村拰缁撴潫鏃堕棿鐨勪腑闂村弻浼戞棩闆嗗悎
+        List<Date> dateList = DateUtils.getWeekDays(startDate, endDate);
+        if (!dateList.isEmpty()) {
+            // 鑾峰彇鎵�鏈夎澶�
+            List<MdcEquipment> equipmentList = equipmentService.list();
+            for (Date date : dateList) {
+                for (MdcEquipment mdcEquipment : equipmentList) {
+                    MdcVacationManagement management = new MdcVacationManagement();
+                    management.setEquipmentId(mdcEquipment.getEquipmentId());
+                    management.setEquipmentName(mdcEquipment.getEquipmentName());
+                    management.setVacationDate(date);
+                    management.setVacationType("鍙屼紤鏃�");
+                    management.setCreateBy("root");
+                    list.add(management);
+                }
+            }
+            super.saveBatch(list);
+        }
+
+    }
+
+    @Override
+    public ModelAndView exportXls(String userId, MdcVacationManagement mdcVacationManagement) {
+        LambdaQueryWrapper<MdcVacationManagement> queryWrapper = new LambdaQueryWrapper<>();
+        //鏌ヨ鐢ㄦ埛鎵�鎷ユ湁鐨勮澶囦俊鎭�
+        List<String> equipmentIds = new ArrayList<>();
+        if (StringUtils.isNotEmpty(mdcVacationManagement.getParentId()) && StringUtils.isEmpty(mdcVacationManagement.getEquipmentId())) {
+            if ("2".equals(mdcVacationManagement.getTypeTree())) {
+                //閮ㄩ棬灞傜骇
+                equipmentIds = equipmentService.getEquipmentIdsByDepart(userId, mdcVacationManagement.getParentId());
+            } else {
+                //浜х嚎灞傜骇
+                equipmentIds = equipmentService.getEquipmentIdsProduction(userId, mdcVacationManagement.getParentId());
+            }
+        } else if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentId())) {
+            //鍗曞彴璁惧淇℃伅
+            mdcVacationManagement.setMdcSectionIds(Collections.singletonList(mdcVacationManagement.getEquipmentId()));
+        } else {
+            //鏌ヨ鐢ㄦ埛鎵�鎷ユ湁鐨勮澶囦俊鎭�
+            if ("2".equals(mdcVacationManagement.getTypeTree())) {
+                //閮ㄩ棬灞傜骇
+                equipmentIds = equipmentService.getEquipmentIdsByDepart(userId, null);
+            } else {
+                equipmentIds = equipmentService.getEquipmentIdsProduction(userId, null);
+            }
+        }
+        if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()) {
+            mdcVacationManagement.setMdcSectionIds(equipmentIds);
+        }
+        if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()) {
+            return null;
+        } else {
+            queryWrapper.in(MdcVacationManagement::getEquipmentId, mdcVacationManagement.getMdcSectionIds());
+        }
+        if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentId())) {
+            queryWrapper.like(MdcVacationManagement::getEquipmentId, mdcVacationManagement.getEquipmentId());
+        }
+        if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentName())) {
+            queryWrapper.like(MdcVacationManagement::getEquipmentName, mdcVacationManagement.getEquipmentName());
+        }
+        if (StringUtils.isNotEmpty(mdcVacationManagement.getStartTime()) && StringUtils.isNotEmpty(mdcVacationManagement.getEndTime())) {
+            queryWrapper.between(MdcVacationManagement::getVacationDate, mdcVacationManagement.getStartTime(), mdcVacationManagement.getEndTime());
+        }
+        queryWrapper.orderByAsc(MdcVacationManagement::getVacationDate);
+        // Step.2 AutoPoi 瀵煎嚭Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<MdcVacationManagement> mdcStandardProcessDurations = this.baseMapper.selectList(queryWrapper);
+        // 瀵煎嚭鏂囦欢鍚嶇О
+        mv.addObject(NormalExcelConstants.FILE_NAME, "鍋囨湡绠$悊鍒楄〃");
+        mv.addObject(NormalExcelConstants.CLASS, MdcVacationManagement.class);
+        //鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("鍋囨湡绠$悊鍒楄〃鏁版嵁", "瀵煎嚭浜�:" + user.getRealname(), "鍋囨湡绠$悊"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, mdcStandardProcessDurations);
+        return mv;
     }
 }

--
Gitblit v1.9.3