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.lang.StringUtils; import org.apache.shiro.SecurityUtils; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.mdc.entity.EquipmentSpindleStatistical; import org.jeecg.modules.mdc.mapper.EquipmentSpindleStatisticalMapper; import org.jeecg.modules.mdc.service.IEquipmentSpindleStatisticalService; import org.jeecg.modules.mdc.service.IMdcEquipmentService; import org.jeecg.modules.mdc.vo.EquipmentSpindleStatisticalVo; 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.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; /** * @Description: 设备负载 * @Author: lius * @Date: 2024-07-16 * @Version: V1.0 */ @Service public class EquipmentSpindleStatisticalServiceImpl extends ServiceImpl implements IEquipmentSpindleStatisticalService { @Resource private IMdcEquipmentService mdcEquipmentService; /** * 分页列表 * * @param userId * @param page * @param equipmentSpindleStatisticalVo * @param req * @return */ @Override public IPage pageList(String userId, Page page, EquipmentSpindleStatisticalVo equipmentSpindleStatisticalVo, HttpServletRequest req) { List equipmentIds = new ArrayList<>(); if (StringUtils.isNotEmpty(equipmentSpindleStatisticalVo.getParentId()) && StringUtils.isEmpty(equipmentSpindleStatisticalVo.getEquipmentId())) { if ("2".equals(equipmentSpindleStatisticalVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, equipmentSpindleStatisticalVo.getParentId()); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, equipmentSpindleStatisticalVo.getParentId()); } } else if (StringUtils.isNotEmpty(equipmentSpindleStatisticalVo.getEquipmentId())) { //单台设备信息 equipmentSpindleStatisticalVo.setEquipmentIdList(Collections.singletonList(equipmentSpindleStatisticalVo.getEquipmentId())); } else { //查询用户拥有的所有设备信息 if ("2".equals(equipmentSpindleStatisticalVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); } } if (equipmentSpindleStatisticalVo.getEquipmentIdList() == null || equipmentSpindleStatisticalVo.getEquipmentIdList().isEmpty()) { equipmentSpindleStatisticalVo.setEquipmentIdList(equipmentIds); } if (equipmentSpindleStatisticalVo.getEquipmentIdList() == null || equipmentSpindleStatisticalVo.getEquipmentIdList().isEmpty()) { return null; } return this.baseMapper.pageList(page, equipmentSpindleStatisticalVo); } /** * 导出 * * @param userId * @param equipmentSpindleStatisticalVo * @return */ @Override public ModelAndView exportXls(String userId, EquipmentSpindleStatisticalVo equipmentSpindleStatisticalVo) { List equipmentIds = new ArrayList<>(); if (StringUtils.isNotEmpty(equipmentSpindleStatisticalVo.getParentId()) && StringUtils.isEmpty(equipmentSpindleStatisticalVo.getEquipmentId())) { if ("2".equals(equipmentSpindleStatisticalVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, equipmentSpindleStatisticalVo.getParentId()); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, equipmentSpindleStatisticalVo.getParentId()); } } else if (StringUtils.isNotEmpty(equipmentSpindleStatisticalVo.getEquipmentId())) { //单台设备信息 equipmentSpindleStatisticalVo.setEquipmentIdList(Collections.singletonList(equipmentSpindleStatisticalVo.getEquipmentId())); } else { //查询用户拥有的所有设备信息 if ("2".equals(equipmentSpindleStatisticalVo.getTypeTree())) { //部门层级 equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); } else { //产线层级 equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); } } if (equipmentSpindleStatisticalVo.getEquipmentIdList() == null || equipmentSpindleStatisticalVo.getEquipmentIdList().isEmpty()) { equipmentSpindleStatisticalVo.setEquipmentIdList(equipmentIds); } if (equipmentSpindleStatisticalVo.getEquipmentIdList() == null || equipmentSpindleStatisticalVo.getEquipmentIdList().isEmpty()) { return null; } // Step.2 AutoPoi 导出Excel ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); List equipmentSpindleStatisticals = this.baseMapper.list(equipmentSpindleStatisticalVo); // 导出文件名称 mv.addObject(NormalExcelConstants.FILE_NAME, "设备负载列表"); mv.addObject(NormalExcelConstants.CLASS, EquipmentSpindleStatistical.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, equipmentSpindleStatisticals); return mv; } /** * 根据设备id获取最新一条数据 * * @param equipmentId * @return */ @Override public Date getMaxDate(String equipmentId) { return this.baseMapper.getMaxDate(equipmentId); } }