From 1a2258c4eca2e7514b6096004fa1c3e0036b402b Mon Sep 17 00:00:00 2001
From: qushaowei <qushaowei@163.com>
Date: 星期四, 28 三月 2024 14:04:24 +0800
Subject: [PATCH] Merge branch 'master' of http://117.34.109.166:18448/r/mdc_430 into develop

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentOvertimeServiceImpl.java |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 110 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentOvertimeServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentOvertimeServiceImpl.java
index 06e7f9b..00454ef 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentOvertimeServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentOvertimeServiceImpl.java
@@ -5,14 +5,24 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.mdc.entity.MdcEquipmentOvertime;
 import org.jeecg.modules.mdc.mapper.MdcEquipmentOvertimeMapper;
 import org.jeecg.modules.mdc.service.IMdcEquipmentOvertimeService;
 import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+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.stereotype.Service;
+import org.springframework.web.servlet.ModelAndView;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -63,4 +73,104 @@
         }
         return this.baseMapper.pageList(page, mdcEquipmentOvertime);
     }
+
+    /**
+     * 瀵煎嚭
+     *
+     * @param userId
+     * @param mdcEquipmentOvertime
+     * @return
+     */
+    @Override
+    public ModelAndView exportXls(String userId, MdcEquipmentOvertime mdcEquipmentOvertime) {
+        List<String> equipmentIds = new ArrayList<>();
+        if (StringUtils.isNotEmpty(mdcEquipmentOvertime.getParentId()) && StringUtils.isEmpty(mdcEquipmentOvertime.getEquipmentId())) {
+            if ("2".equals(mdcEquipmentOvertime.getTypeTree())) {
+                //閮ㄩ棬灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcEquipmentOvertime.getParentId());
+            } else {
+                //浜х嚎灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcEquipmentOvertime.getParentId());
+            }
+        } else if (StringUtils.isNotEmpty(mdcEquipmentOvertime.getEquipmentId())) {
+            //鍗曞彴璁惧淇℃伅
+            mdcEquipmentOvertime.setMdcSectionIds(Collections.singletonList(mdcEquipmentOvertime.getEquipmentId()));
+        } else {
+            //鏌ヨ鐢ㄦ埛鎷ユ湁鐨勬墍鏈夎澶囦俊鎭�
+            if ("2".equals(mdcEquipmentOvertime.getTypeTree())) {
+                //閮ㄩ棬灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
+            } else {
+                //浜х嚎灞傜骇
+                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
+            }
+        }
+
+        if (mdcEquipmentOvertime.getMdcSectionIds() == null || mdcEquipmentOvertime.getMdcSectionIds().isEmpty()) {
+            mdcEquipmentOvertime.setMdcSectionIds(equipmentIds);
+        }
+
+        if (mdcEquipmentOvertime.getMdcSectionIds() == null || mdcEquipmentOvertime.getMdcSectionIds().isEmpty()) {
+            return null;
+        }
+        // Step.2 AutoPoi 瀵煎嚭Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<MdcEquipmentOvertime> mdcEquipmentOvertimes = this.baseMapper.list(mdcEquipmentOvertime);
+        // 瀵煎嚭鏂囦欢鍚嶇О
+        mv.addObject(NormalExcelConstants.FILE_NAME, "鍔犵彮绠$悊鍒楄〃");
+        mv.addObject(NormalExcelConstants.CLASS, MdcEquipmentOvertime.class);
+        //鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
+        //update-begin---author:wangshuai ---date:20211227  for锛歔JTC-116]瀵煎嚭浜哄啓姝讳簡------------
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("鍔犵彮绠$悊鍒楄〃鏁版嵁", "瀵煎嚭浜�:" + user.getRealname(), "鍔犵彮绠$悊"));
+        //update-end---author:wangshuai ---date:20211227  for锛歔JTC-116]瀵煎嚭浜哄啓姝讳簡------------
+        mv.addObject(NormalExcelConstants.DATA_LIST, mdcEquipmentOvertimes);
+        return mv;
+    }
+
+    /**
+     * 璁$畻鍔犵彮鏃堕棿锛堝垎閽燂級
+     *
+     * @param equipmentId
+     * @param validDate
+     * @return
+     */
+    @Override
+    public BigDecimal computeOvertime(String equipmentId, String validDate) {
+        List<MdcEquipmentOvertime> list = this.baseMapper.computeOvertime(equipmentId, validDate.replaceAll("-", ""));
+        BigDecimal result = new BigDecimal("0");
+        if (list != null && !list.isEmpty()) {
+            for (MdcEquipmentOvertime equipmentOvertime : list) {
+                result = result.add(equipmentOvertime.getDuration().divide(new BigDecimal("60"), 0, RoundingMode.HALF_UP));
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 娣诲姞
+     *
+     * @param mdcEquipmentOvertime
+     * @return
+     */
+    @Override
+    public boolean addOvertime(MdcEquipmentOvertime mdcEquipmentOvertime) {
+        String[] equipmentIds = mdcEquipmentOvertime.getEquipmentId().split(",");
+        List<MdcEquipmentOvertime> mdcEquipmentOvertimes = new ArrayList<>();
+        // 璁$畻鏃堕暱(绉�)
+        String startTime = mdcEquipmentOvertime.getStartTime();
+        String endTime = mdcEquipmentOvertime.getEndTime();
+        long duration = DateUtils.differentSecond(DateUtils.setTimeForDay(DateUtils.getNow(), startTime), DateUtils.setTimeForDay(DateUtils.getNow(), endTime));
+        for (String equipmentId : equipmentIds) {
+            MdcEquipmentOvertime equipmentOvertime = new MdcEquipmentOvertime();
+            equipmentOvertime.setEquipmentId(equipmentId);
+            equipmentOvertime.setTheDate(mdcEquipmentOvertime.getTheDate());
+            equipmentOvertime.setAutoFlag(CommonConstant.AUTO_FLAG_N);
+            equipmentOvertime.setStartTime(mdcEquipmentOvertime.getStartTime());
+            equipmentOvertime.setEndTime(mdcEquipmentOvertime.getEndTime());
+            equipmentOvertime.setDuration(new BigDecimal(duration));
+            mdcEquipmentOvertimes.add(equipmentOvertime);
+        }
+        return super.saveBatch(mdcEquipmentOvertimes);
+    }
 }

--
Gitblit v1.9.3