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/MdcNoplanCloseServiceImpl.java | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 105 insertions(+), 3 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcNoplanCloseServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcNoplanCloseServiceImpl.java index bcee671..661dc7c 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcNoplanCloseServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcNoplanCloseServiceImpl.java @@ -6,18 +6,27 @@ 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.system.vo.LoginUser; import org.jeecg.modules.mdc.entity.MdcEquipment; -import org.jeecg.modules.mdc.entity.MdcEquipmentRepair; import org.jeecg.modules.mdc.entity.MdcNoplanClose; import org.jeecg.modules.mdc.mapper.MdcNoplanCloseMapper; import org.jeecg.modules.mdc.service.IMdcEquipmentService; import org.jeecg.modules.mdc.service.IMdcNoplanCloseService; import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.vo.MdcNoplanCloseVo; +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.time.Duration; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -86,8 +95,8 @@ List<MdcNoplanClose> mdcNoplanCloseList = new ArrayList<>(); a: for (String equipmentId : equipmentIds) { - Date startTime = DateUtils.getFormatDate(mdcNoplanCloseVo.getStartTime(), DateUtils.STR_DATE_TIME_SMALL); - Date endTime = DateUtils.getFormatDate(mdcNoplanCloseVo.getEndTime(), DateUtils.STR_DATE_TIME_SMALL); + Date startTime = DateUtils.getFormatDate(mdcNoplanCloseVo.getStartTime(), DateUtils.STR_DATE_TIME_MIN); + Date endTime = DateUtils.getFormatDate(mdcNoplanCloseVo.getEndTime(), DateUtils.STR_DATE_TIME_MIN); MdcEquipment mdcEquipment = mdcEquipmentService.findEquipmentNameByEquipmentId(equipmentId); LambdaQueryWrapper<MdcNoplanClose> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(MdcNoplanClose::getEquipmentId, equipmentId); @@ -243,4 +252,97 @@ } return result; } + + /** + * 瀵煎嚭 + * + * @param userId + * @param mdcNoplanClose + * @return + */ + @Override + public ModelAndView exportXls(String userId, MdcNoplanClose mdcNoplanClose) { + LambdaQueryWrapper<MdcNoplanClose> queryWrapper = new LambdaQueryWrapper<>(); + List<String> equipmentIds = new ArrayList<>(); + if (StringUtils.isNotEmpty(mdcNoplanClose.getParentId()) && StringUtils.isEmpty(mdcNoplanClose.getEquipmentId())) { + if ("2".equals(mdcNoplanClose.getTypeTree())) { + //閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcNoplanClose.getParentId()); + } else { + //浜х嚎灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcNoplanClose.getParentId()); + } + } else if (StringUtils.isNotEmpty(mdcNoplanClose.getEquipmentId())) { + //鍗曞彴璁惧淇℃伅 + mdcNoplanClose.setMdcSectionIds(Collections.singletonList(mdcNoplanClose.getEquipmentId())); + } else { + //鏌ヨ鐢ㄦ埛鎵�鎷ユ湁鐨勬墍鏈夎澶囦俊鎭� + if ("2".equals(mdcNoplanClose.getTypeTree())) { + //閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); + } else { + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); + } + } + if (mdcNoplanClose.getMdcSectionIds() == null || mdcNoplanClose.getMdcSectionIds().isEmpty()) { + mdcNoplanClose.setMdcSectionIds(equipmentIds); + } + if (mdcNoplanClose.getMdcSectionIds() == null || mdcNoplanClose.getMdcSectionIds().isEmpty()) { + return null; + } else { + queryWrapper.in(MdcNoplanClose::getEquipmentId, mdcNoplanClose.getMdcSectionIds()); + } + if (StringUtils.isNotEmpty(mdcNoplanClose.getEquipmentId())) { + queryWrapper.like(MdcNoplanClose::getEquipmentId, mdcNoplanClose.getEquipmentId()); + } + if (StringUtils.isNotEmpty(mdcNoplanClose.getEquipmentName())) { + queryWrapper.like(MdcNoplanClose::getEquipmentName, mdcNoplanClose.getEquipmentName()); + } + if (mdcNoplanClose.getEndTime() != null) { + queryWrapper.le(MdcNoplanClose::getStartTime, mdcNoplanClose.getEndTime()); + } + if (mdcNoplanClose.getStartTime() != null) { + queryWrapper.ge(MdcNoplanClose::getEndTime, mdcNoplanClose.getStartTime()); + } + queryWrapper.orderByAsc(MdcNoplanClose::getStartTime); + // Step.2 AutoPoi 瀵煎嚭Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + List<MdcNoplanClose> mdcNoplanCloses = this.baseMapper.selectList(queryWrapper); + // 瀵煎嚭鏂囦欢鍚嶇О + mv.addObject(NormalExcelConstants.FILE_NAME, "闈炶鍒掑仠鏈虹淮鎶ゅ垪琛�"); + mv.addObject(NormalExcelConstants.CLASS, MdcNoplanClose.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, mdcNoplanCloses); + return mv; + } + + @Override + public BigDecimal findNoplanTimeDuration(String equipmentId, String validDate, String noplanType) { + BigDecimal result = new BigDecimal("0"); + String startDate = DateUtils.format(DateUtils.toDate(validDate + "-01", DateUtils.STR_DATE), DateUtils.STR_DATE) + " 00:00:00"; + Date startTime = DateUtils.toDate(startDate, DateUtils.STR_DATE_TIME_SMALL); + String endDate = DateUtils.format(DateUtils.addMonth(1, DateUtils.toDate(startDate, DateUtils.STR_DATE_TIME_SMALL)), DateUtils.STR_DATE_TIME_SMALL); + Date endTime = DateUtils.toDate(endDate, DateUtils.STR_DATE_TIME_SMALL); + List<MdcNoplanClose> mdcNoplanCloseList = this.baseMapper.findNoplanTimeDuration(equipmentId, noplanType, startDate, endDate); + // 鏃堕棿淇 骞惰绠� + if (mdcNoplanCloseList != null && !mdcNoplanCloseList.isEmpty()) { + for (MdcNoplanClose mdcNoplanClose : mdcNoplanCloseList) { + if (mdcNoplanClose.getStartTime().before(startTime)) { + mdcNoplanClose.setStartTime(startTime); + } + if (mdcNoplanClose.getEndTime().after(endTime)) { + mdcNoplanClose.setEndTime(endTime); + } + LocalDateTime localStartDate = LocalDateTime.ofInstant(mdcNoplanClose.getStartTime().toInstant(), ZoneId.systemDefault()); + LocalDateTime localEndDate = LocalDateTime.ofInstant(mdcNoplanClose.getEndTime().toInstant(), ZoneId.systemDefault()); + int minutes = Math.toIntExact(Duration.between(localStartDate, localEndDate).toMinutes()); + result = result.add(new BigDecimal(minutes)); + } + } + return result; + } } -- Gitblit v1.9.3