From bbfc6a9a5b3a899c7405d06454d315d8c283e23f Mon Sep 17 00:00:00 2001 From: yb <1113799@qq.com> Date: 星期四, 04 九月 2025 15:12:46 +0800 Subject: [PATCH] 倍率统计导出 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentMagnificationServiceImpl.java | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 252 insertions(+), 0 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentMagnificationServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentMagnificationServiceImpl.java new file mode 100644 index 0000000..a2ade91 --- /dev/null +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentMagnificationServiceImpl.java @@ -0,0 +1,252 @@ +package org.jeecg.modules.mdc.service.impl; + +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.lang3.StringUtils; +import org.apache.shiro.SecurityUtils; +import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.modules.mdc.dto.MdcEquipmentMagnificationDto; +import org.jeecg.modules.mdc.entity.*; +import org.jeecg.modules.mdc.mapper.MdcEquipmentMagnificationMapper; +import org.jeecg.modules.mdc.service.*; +import org.jeecg.modules.mdc.util.DateUtils; +import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo; +import org.jeecg.modules.mdc.vo.MdcEquipmentMagnificationVo; +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.util.*; + +@Service +public class MdcEquipmentMagnificationServiceImpl extends ServiceImpl<MdcEquipmentMagnificationMapper, MdcEquipmentMagnification> implements IMdcEquipmentMagnificationService { + + @Resource + private IEquipmentService equipmentService; + @Resource + private IMdcDriveTypeParamConfigService mdcDriveTypeParamConfigService; + @Resource + private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService; + @Resource + private IMdcEquipmentService mdcEquipmentService; + + private static String spindlebeilv = "涓昏酱鍊嶇巼"; + private static String feedbeilv = "杩涚粰鍊嶇巼"; + @Override + public void savesEquipmentMagnifications() { + List<MdcEquipmentMagnification> magnifications = new ArrayList<>(); + //涓昏酱鍊嶇巼 + //杩涚粰鍊嶇巼 + /* Equipment e = equipmentService.getById("12345678"); + List<Equipment> equipmentList = new ArrayList<>(); + equipmentList.add(e);*/ + List<Equipment> equipmentList = equipmentService.list(); + Map<String,List<MdcDriveTypeParamConfig>> map = new HashMap<>(); + Date now = DateUtils.plusTime(DateUtils.getNow(), -1); + for (Equipment equipment : equipmentList) { + Date start = null; + //鏌ヨ鏈�鍚庝竴鏉¤褰� + MdcEquipmentMagnification mdcMagnification = super.baseMapper.getMaxStaticsData(equipment.getEquipmentid()); + if (mdcMagnification == null) { + start = DateUtils.plusTime(DateUtils.getNow(), -5); + } else { + if (now.toString().equals(start.toString())) { + continue; + } + start = DateUtils.toDate(mdcMagnification.getTheDate(),DateUtils.STR_DATE ); + } + List<String> dates = DateUtils.getDatesStringList(start,now); + List<MdcDriveTypeParamConfig> list = new ArrayList<>(); + if (!map.containsKey(equipment.getDrivetype())) { + MdcDriveTypeParamConfig config1 = mdcDriveTypeParamConfigService.getEnglishName(spindlebeilv,equipment.getDrivetype()); + MdcDriveTypeParamConfig config2 = mdcDriveTypeParamConfigService.getEnglishName(feedbeilv,equipment.getDrivetype()); + if (config1 != null) { + list.add(config1); + } + if (config2 != null ) { + list.add(config2); + } + if (list == null || list.size() == 0) { + for (String date : dates) { + MdcEquipmentMagnification info = new MdcEquipmentMagnification(); + info.setEquipmentId(equipment.getEquipmentid()); + info.setTheDate(date); + info.setSpindlebeilv(new BigDecimal(0)); + info.setFeedbeilv(new BigDecimal(0)); + magnifications.add(info); + } + continue; + } else { + map.put(equipment.getDrivetype(), list); + } + + } else { + list = map.get(equipment.getDrivetype()); + } + //寰幆鏃堕棿 + //鏌ヨ瀛楁 MAP 淇濆瓨 + for (String date : dates) { + MdcEquipmentMagnification magnification = selectMagnification(equipment.getEquipmentid(),date,equipment.getDrivetype(), list); + magnifications.add(magnification); + } + } + if (!magnifications.isEmpty() && magnifications.size() > 0) { + saveBatch(magnifications); + } + //鏁版嵁淇濆瓨 + return; + } + + @Override + public IPage<MdcEquipmentMagnification> pageList(String userId, MdcEquipmentMagnificationVo magnificationVo, Integer pageNo, Integer pageSize, HttpServletRequest req) { + IPage<MdcEquipmentMagnification> pageData = new Page<>(pageNo, pageSize); + List<String> equipmentIds = new ArrayList<>(); + if (StringUtils.isNotEmpty(magnificationVo.getParentId()) && StringUtils.isEmpty(magnificationVo.getEquipmentId())) { + if ("2".equals(magnificationVo.getTypeTree())) { + // 閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, magnificationVo.getParentId()); + } else { + // 浜х嚎灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, magnificationVo.getParentId()); + } + } else if (StringUtils.isNotEmpty(magnificationVo.getEquipmentId())) { + // 鍗曞彴璁惧淇℃伅 + magnificationVo.setEquipmentIdList(Collections.singletonList(magnificationVo.getEquipmentId())); + } else { + // 鏌ヨ鐢ㄦ埛鎷ユ湁鐨勬墍鏈夎澶囦俊鎭� + if ("2".equals(magnificationVo.getTypeTree())) { + //閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); + } else { + //浜х嚎灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); + } + } + if (magnificationVo.getEquipmentIdList() == null || magnificationVo.getEquipmentIdList().isEmpty()) { + magnificationVo.setEquipmentIdList(equipmentIds); + } + if (magnificationVo.getEquipmentIdList() == null || magnificationVo.getEquipmentIdList().isEmpty()) { + return null; + } + return this.baseMapper.pageList(pageData, magnificationVo); + } + + @Override + public ModelAndView exportXls(String userId, MdcEquipmentMagnificationVo magnificationVo) { + List<String> equipmentIds = new ArrayList<>(); + if (StringUtils.isNotEmpty(magnificationVo.getParentId()) && StringUtils.isEmpty(magnificationVo.getEquipmentId())) { + if ("2".equals(magnificationVo.getTypeTree())) { + // 閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, magnificationVo.getParentId()); + } else { + // 浜х嚎灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, magnificationVo.getParentId()); + } + } else if (StringUtils.isNotEmpty(magnificationVo.getEquipmentId())) { + // 鍗曞彴璁惧淇℃伅 + magnificationVo.setEquipmentIdList(Collections.singletonList(magnificationVo.getEquipmentId())); + } else { + // 鏌ヨ鐢ㄦ埛鎷ユ湁鐨勬墍鏈夎澶囦俊鎭� + if ("2".equals(magnificationVo.getTypeTree())) { + //閮ㄩ棬灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); + } else { + //浜х嚎灞傜骇 + equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); + } + } + if (magnificationVo.getEquipmentIdList() == null || magnificationVo.getEquipmentIdList().isEmpty()) { + magnificationVo.setEquipmentIdList(equipmentIds); + } + if (magnificationVo.getEquipmentIdList() == null || magnificationVo.getEquipmentIdList().isEmpty()) { + return null; + } + List<MdcEquipmentMagnificationDto> magnificationDtos = super.baseMapper.list(magnificationVo); + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + // 瀵煎嚭鏂囦欢鍚嶇О + mv.addObject(NormalExcelConstants.FILE_NAME, "鍊嶇巼鎶ヨ〃"); + mv.addObject(NormalExcelConstants.CLASS, MdcDownTime.class); + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("鍊嶇巼鎶ヨ〃", "瀵煎嚭浜�:" + user.getRealname(), "鍊嶇巼鎶ヨ〃")); + mv.addObject(NormalExcelConstants.DATA_LIST, magnificationDtos); + return mv; + } + + private MdcEquipmentMagnification selectMagnification(String equipmentId,String date,String drivetype,List<MdcDriveTypeParamConfig> list) { + Date startTime = DateUtils.plusTime(DateUtils.getShortDate(date), 0); + Date endTime = DateUtils.plusTime(DateUtils.getShortDate(date), 1); + List<MdcEquipmentRunningSection> sectionList = mdcEquipmentRunningSectionService.selectRunningData(equipmentId,startTime,endTime); + if (sectionList.isEmpty() || sectionList.size() < 1) { + MdcEquipmentMagnification info = new MdcEquipmentMagnification(); + info.setEquipmentId(equipmentId); + info.setTheDate(date); + info.setSpindlebeilv(new BigDecimal(0)); + info.setFeedbeilv(new BigDecimal(0)); + return info; + } else { + + //闇�瑕佹椂闂存埅鍙� + if (sectionList.get(0).getStartTime().before(startTime)) { + sectionList.get(0).setStartTime(startTime); + } + if (sectionList.size() > 1) { + if (sectionList.get(sectionList.size() - 1).getEndTime().after(endTime)) { + sectionList.get(sectionList.size() - 1).setEndTime(endTime); + } + } else { + if (sectionList.get(0).getEndTime().after(endTime)) { + sectionList.get(0).setEndTime(endTime); + } + } + MdcEquipmentMagnification info = new MdcEquipmentMagnification(); + for (MdcDriveTypeParamConfig config : list) { + info.setTheDate(date); + info.setEquipmentId(equipmentId); + BigDecimal bigDecimal = new BigDecimal(0); + int numberSizeList = 0; + for (MdcEquipmentRunningSection section : sectionList) { + List<Object> objects = super.baseMapper.getEquipmentSequenceNumber(drivetype+ "_" + equipmentId,section.getStartTime(), + section.getEndTime(),config.getEnglishName()); + BigDecimal s = objNumberList(objects); + bigDecimal = bigDecimal.add(s); + numberSizeList += objects.size(); + } + if (config.getChineseName().equals(spindlebeilv)) { + info.setSpindlebeilvValue(bigDecimal); + info.setSpindlebeilvNumber(numberSizeList); + if (bigDecimal.compareTo(BigDecimal.ZERO) >0 && new BigDecimal(numberSizeList).compareTo(BigDecimal.ZERO) > 0) { + info.setSpindlebeilv(bigDecimal.divide(new BigDecimal(numberSizeList))); + } + } + if (config.getChineseName().equals(feedbeilv)) { + info.setFeedbeilvValue(bigDecimal); + info.setFeedbeilvNumber(numberSizeList); + if (bigDecimal.compareTo(BigDecimal.ZERO) >0 && new BigDecimal(numberSizeList).compareTo(BigDecimal.ZERO) > 0) { + info.setFeedbeilv(bigDecimal.divide(new BigDecimal(numberSizeList))); + } + } + } + return info; + } + } + + private BigDecimal objNumberList(List<Object> objects) { + if (objects == null || objects.size() == 0) { + return new BigDecimal(0); + } else { + BigDecimal bigDecimal = new BigDecimal(0); + for (Object object : objects) { + if (object != null && object.toString().length() > 0) { + bigDecimal = bigDecimal.add(new BigDecimal(object.toString())); + } + } + return bigDecimal; + } + } +} -- Gitblit v1.9.3