From d0b97b5655a6cac1efbda08dad1d3019ed973923 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期三, 21 五月 2025 12:04:16 +0800 Subject: [PATCH] 设备日志批量导出 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java | 129 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 1 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java index 3acd269..ddb71d0 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java @@ -1,20 +1,31 @@ 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 org.apache.commons.lang.StringUtils; -import org.jeecg.modules.mdc.entity.MdcDownTime; +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.MdcMttrInfo; import org.jeecg.modules.mdc.entity.MdcRepairInfo; import org.jeecg.modules.mdc.mapper.MdcRepairInfoMapper; import org.jeecg.modules.mdc.service.IMdcEquipmentService; +import org.jeecg.modules.mdc.service.IMdcMttrInfoService; import org.jeecg.modules.mdc.service.IMdcRepairInfoService; import org.jeecg.modules.mdc.vo.MdcRepairInfoVo; +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.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; @@ -29,6 +40,9 @@ @Resource private IMdcEquipmentService mdcEquipmentService; + + @Resource + private IMdcMttrInfoService mdcMttrInfoService; /** * 鍒嗛〉鍒楄〃 @@ -93,4 +107,117 @@ this.saveBatch(repairInfoList); return true; } + + /** + * 瀵煎嚭 + * + * @param userId + * @param mdcRepairInfoVo + * @return + */ + @Override + public ModelAndView exportXls(String userId, MdcRepairInfoVo mdcRepairInfoVo) { + LambdaQueryWrapper<MdcRepairInfo> queryWrapper = new LambdaQueryWrapper<>(); + List<String> equipmentIds = new ArrayList<>(); + if (StringUtils.isNotEmpty(mdcRepairInfoVo.getParentId()) && StringUtils.isEmpty(mdcRepairInfoVo.getEquipmentId())) { + if ("2".equals(mdcRepairInfoVo.getTypeTree())) { + //閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcRepairInfoVo.getParentId()); + } else { + //浜х嚎灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcRepairInfoVo.getParentId()); + } + } else if (StringUtils.isNotEmpty(mdcRepairInfoVo.getEquipmentId())) { + //鍗曞彴璁惧淇℃伅 + mdcRepairInfoVo.setEquipmentIdList(Collections.singletonList(mdcRepairInfoVo.getEquipmentId())); + } else { + //鏌ヨ鐢ㄦ埛鎷ユ湁鐨勬墍鏈夎澶囦俊鎭� + if ("2".equals(mdcRepairInfoVo.getTypeTree())) { + //閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); + } else { + //浜х嚎灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); + } + } + + if (mdcRepairInfoVo.getEquipmentIdList() == null || mdcRepairInfoVo.getEquipmentIdList().isEmpty()) { + mdcRepairInfoVo.setEquipmentIdList(equipmentIds); + } + + if (mdcRepairInfoVo.getEquipmentIdList() == null || mdcRepairInfoVo.getEquipmentIdList().isEmpty()) { + return null; + } else { + queryWrapper.in(MdcRepairInfo::getEquipmentId, mdcRepairInfoVo.getEquipmentIdList()); + } + if (StringUtils.isNotEmpty(mdcRepairInfoVo.getEquipmentId())) { + queryWrapper.eq(MdcRepairInfo::getEquipmentId, mdcRepairInfoVo.getEquipmentId()); + } + if (StringUtils.isNotEmpty(mdcRepairInfoVo.getStartTime()) && StringUtils.isNotEmpty(mdcRepairInfoVo.getEndTime())) { + queryWrapper.between(MdcRepairInfo::getTheDate, mdcRepairInfoVo.getStartTime(), mdcRepairInfoVo.getEndTime()); + } + queryWrapper.orderByDesc(MdcRepairInfo::getTheDate).orderByDesc(MdcRepairInfo::getEquipmentId); + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + List<MdcRepairInfo> repairInfos = this.baseMapper.selectList(queryWrapper); + // 瀵煎嚭鏂囦欢鍚嶇О + mv.addObject(NormalExcelConstants.FILE_NAME, "璁惧缁翠慨鏃堕暱鍒楄〃"); + mv.addObject(NormalExcelConstants.CLASS, MdcRepairInfo.class); + 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, repairInfos); + return mv; + } + + /** + * 璁$畻MTTR + * + * @param month + */ + @Override + public void computeMttr(String month) { + /* + 璁惧骞冲潎淇悊鏃堕棿(MTTR) = 鎬荤淮淇椂闂� / 鎬荤淮淇鏁� + */ + List<MdcMttrInfo> mdcMttrInfos = mdcMttrInfoService.list(new LambdaQueryWrapper<MdcMttrInfo>().eq(MdcMttrInfo::getTheDate, month)); + if (mdcMttrInfos != null && !mdcMttrInfos.isEmpty()) { + for (MdcMttrInfo mdcMttrInfo : mdcMttrInfos) { + // 鎬荤淮淇椂闂� + BigDecimal totalRepairLong = this.baseMapper.findTotalRepairLong(month); + mdcMttrInfo.setTotalRepairLong(totalRepairLong); + // 鎬荤淮淇鏁� + Integer totalRepairCount = this.baseMapper.findTotalRepairCount(month); + mdcMttrInfo.setTotalRepairCount(totalRepairCount); + // MTTR + if (mdcMttrInfo.getTotalRepairCount() != 0) { + BigDecimal mttr = mdcMttrInfo.getTotalRepairLong().divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP); + mdcMttrInfo.setMttr(mttr); + } + } + mdcMttrInfoService.updateBatchById(mdcMttrInfos); + } else { + List<MdcEquipment> equipmentList = mdcEquipmentService.list(); + if (equipmentList != null && !equipmentList.isEmpty()) { + List<MdcMttrInfo> mmi = new ArrayList<>(); + for (MdcEquipment mdcEquipment : equipmentList) { + MdcMttrInfo mdcMttrInfo = new MdcMttrInfo(); + mdcMttrInfo.setEquipmentId(mdcEquipment.getEquipmentId()); + mdcMttrInfo.setTheDate(month); + // 鎬荤淮淇椂闂� + BigDecimal totalRepairLong = this.baseMapper.findTotalRepairLong(month); + mdcMttrInfo.setTotalRepairLong(totalRepairLong); + // 鎬荤淮淇鏁� + Integer totalRepairCount = this.baseMapper.findTotalRepairCount(month); + mdcMttrInfo.setTotalRepairCount(totalRepairCount); + // MTTR + if (mdcMttrInfo.getTotalRepairCount() != 0) { + BigDecimal mttr = mdcMttrInfo.getTotalRepairLong().divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP); + mdcMttrInfo.setMttr(mttr); + } + mmi.add(mdcMttrInfo); + } + mdcMttrInfoService.saveBatch(mmi); + } + } + } } -- Gitblit v1.9.3