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.apache.shiro.SecurityUtils; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.mdc.entity.MdcDownTime; import org.jeecg.modules.mdc.entity.MdcOeeInfo; import org.jeecg.modules.mdc.mapper.MdcDownTimeMapper; import org.jeecg.modules.mdc.service.IMdcDownTimeService; import org.jeecg.modules.mdc.service.IMdcEquipmentService; import org.jeecg.modules.mdc.vo.MdcDownTimeVo; 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.util.ArrayList; import java.util.Collections; import java.util.List; /** * @Description: 设备故障停机时长表 * @Author: Lius * @Date: 2025-01-22 */ @Service public class MdcDownTimeServiceImpl extends ServiceImpl implements IMdcDownTimeService { @Resource private IMdcEquipmentService mdcEquipmentService; @Override public IPage pageList(String userId, Page page, MdcDownTimeVo mdcDownTimeVo, HttpServletRequest req) { List equipmentIds = new ArrayList<>(); if (StringUtils.isNotEmpty(mdcDownTimeVo.getParentId()) && StringUtils.isEmpty(mdcDownTimeVo.getEquipmentId())) { if ("2".equals(mdcDownTimeVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcDownTimeVo.getParentId()); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcDownTimeVo.getParentId()); } } else if (StringUtils.isNotEmpty(mdcDownTimeVo.getEquipmentId())) { //单台设备信息 mdcDownTimeVo.setEquipmentIdList(Collections.singletonList(mdcDownTimeVo.getEquipmentId())); } else { //查询用户拥有的所有设备信息 if ("2".equals(mdcDownTimeVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); } } if (mdcDownTimeVo.getEquipmentIdList() == null || mdcDownTimeVo.getEquipmentIdList().isEmpty()) { mdcDownTimeVo.setEquipmentIdList(equipmentIds); } if (mdcDownTimeVo.getEquipmentIdList() == null || mdcDownTimeVo.getEquipmentIdList().isEmpty()) { return null; } return this.baseMapper.pageList(page, mdcDownTimeVo); } /** * 添加 * * @param mdcDownTimeVo * @return */ @Override public boolean addDownTime(MdcDownTimeVo mdcDownTimeVo) { String[] equipmentIdList = mdcDownTimeVo.getEquipmentIds().split(","); List downTimeList = new ArrayList<>(); for (String equipmentId : equipmentIdList) { MdcDownTime mdcDownTime = new MdcDownTime(); BeanUtils.copyProperties(mdcDownTimeVo, mdcDownTime); mdcDownTime.setEquipmentId(equipmentId); downTimeList.add(mdcDownTime); } this.saveBatch(downTimeList); return true; } /** * 导出 * * @param userId * @param mdcDownTimeVo * @return */ @Override public ModelAndView exportXls(String userId, MdcDownTimeVo mdcDownTimeVo) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); List equipmentIds = new ArrayList<>(); if (StringUtils.isNotEmpty(mdcDownTimeVo.getParentId()) && StringUtils.isEmpty(mdcDownTimeVo.getEquipmentId())) { if ("2".equals(mdcDownTimeVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcDownTimeVo.getParentId()); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcDownTimeVo.getParentId()); } } else if (StringUtils.isNotEmpty(mdcDownTimeVo.getEquipmentId())) { //单台设备信息 mdcDownTimeVo.setEquipmentIdList(Collections.singletonList(mdcDownTimeVo.getEquipmentId())); } else { //查询用户拥有的所有设备信息 if ("2".equals(mdcDownTimeVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); } } if (mdcDownTimeVo.getEquipmentIdList() == null || mdcDownTimeVo.getEquipmentIdList().isEmpty()) { mdcDownTimeVo.setEquipmentIdList(equipmentIds); } if (mdcDownTimeVo.getEquipmentIdList() == null || mdcDownTimeVo.getEquipmentIdList().isEmpty()) { return null; } else { queryWrapper.in(MdcDownTime::getEquipmentId, mdcDownTimeVo.getEquipmentIdList()); } if (StringUtils.isNotEmpty(mdcDownTimeVo.getEquipmentId())) { queryWrapper.eq(MdcDownTime::getEquipmentId, mdcDownTimeVo.getEquipmentId()); } if (StringUtils.isNotEmpty(mdcDownTimeVo.getStartTime()) && StringUtils.isNotEmpty(mdcDownTimeVo.getEndTime())) { queryWrapper.between(MdcDownTime::getTheDate, mdcDownTimeVo.getStartTime(), mdcDownTimeVo.getEndTime()); } queryWrapper.orderByDesc(MdcDownTime::getTheDate).orderByDesc(MdcDownTime::getEquipmentId); ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); List downTimes = this.baseMapper.selectList(queryWrapper); // 导出文件名称 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(), "设备故障停机时长数据")); //update-end---author:wangshuai ---date:20211227 for:[JTC-116]导出人写死了------------ mv.addObject(NormalExcelConstants.DATA_LIST, downTimes); return mv; } }