| | |
| | | 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.dto.MdcProcessQuantityDto; |
| | | import org.jeecg.modules.mdc.entity.MdcProcessQuantity; |
| | | import org.jeecg.modules.mdc.mapper.MdcProcessQuantityMapper; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | import org.jeecg.modules.mdc.service.IMdcProcessQuantityService; |
| | | import org.jeecg.modules.mdc.vo.MdcProcessQuantityVo; |
| | | 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; |
| | | |
| | | |
| | | /** |
| | |
| | | @Service |
| | | public class MdcProcessQuantityServiceImpl extends ServiceImpl<MdcProcessQuantityMapper, MdcProcessQuantity> implements IMdcProcessQuantityService { |
| | | |
| | | @Resource |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | | * @param userId |
| | | * @param page |
| | | * @param mdcProcessQuantity |
| | | * @param req |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<MdcProcessQuantityDto> pageList(String userId, Page<MdcProcessQuantityDto> page, MdcProcessQuantityVo mdcProcessQuantity, HttpServletRequest req) { |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcProcessQuantity.getParentId()) && StringUtils.isEmpty(mdcProcessQuantity.getEquipmentId())) { |
| | | if ("2".equals(mdcProcessQuantity.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcProcessQuantity.getParentId()); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProcessQuantity.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcProcessQuantity.getEquipmentId())) { |
| | | //单台设备信息 |
| | | mdcProcessQuantity.setMdcSectionIds(Collections.singletonList(mdcProcessQuantity.getEquipmentId())); |
| | | } else { |
| | | //查询用户拥有的所有设备信息 |
| | | if ("2".equals(mdcProcessQuantity.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | |
| | | if (mdcProcessQuantity.getMdcSectionIds() == null || mdcProcessQuantity.getMdcSectionIds().isEmpty()) { |
| | | mdcProcessQuantity.setMdcSectionIds(equipmentIds); |
| | | } |
| | | |
| | | if (mdcProcessQuantity.getMdcSectionIds() == null || mdcProcessQuantity.getMdcSectionIds().isEmpty()) { |
| | | return null; |
| | | } |
| | | return this.baseMapper.pageList(page, mdcProcessQuantity); |
| | | } |
| | | |
| | | /** |
| | | * 导出 |
| | | * |
| | | * @param userId |
| | | * @param mdcProcessQuantity |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ModelAndView exportXls(String userId, MdcProcessQuantityVo mdcProcessQuantity) { |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcProcessQuantity.getParentId()) && StringUtils.isEmpty(mdcProcessQuantity.getEquipmentId())) { |
| | | if ("2".equals(mdcProcessQuantity.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcProcessQuantity.getParentId()); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProcessQuantity.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcProcessQuantity.getEquipmentId())) { |
| | | //单台设备信息 |
| | | mdcProcessQuantity.setMdcSectionIds(Collections.singletonList(mdcProcessQuantity.getEquipmentId())); |
| | | } else { |
| | | //查询用户拥有的所有设备信息 |
| | | if ("2".equals(mdcProcessQuantity.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | if (mdcProcessQuantity.getMdcSectionIds() == null || mdcProcessQuantity.getMdcSectionIds().isEmpty()) { |
| | | mdcProcessQuantity.setMdcSectionIds(equipmentIds); |
| | | } |
| | | if (mdcProcessQuantity.getMdcSectionIds() == null || mdcProcessQuantity.getMdcSectionIds().isEmpty()) { |
| | | return null; |
| | | } |
| | | // Step.2 AutoPoi 导出Excel |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | List<MdcProcessQuantityDto> processQuantityDtos = this.baseMapper.list(mdcProcessQuantity); |
| | | // 导出文件名称 |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, "加工数量列表"); |
| | | mv.addObject(NormalExcelConstants.CLASS, MdcProcessQuantityDto.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, processQuantityDtos); |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * 根据id查询 |
| | | */ |
| | | @Override |
| | | public MdcProcessQuantityDto findById(String id) { |
| | | return this.baseMapper.findById(id); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加数据 |
| | | * |
| | | * @param mdcProcessQuantity |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean addData(MdcProcessQuantity mdcProcessQuantity) { |
| | | boolean result = false; |
| | | String[] equipmentIds = mdcProcessQuantity.getEquipmentIds().split(","); |
| | | for (String equipmentId : equipmentIds) { |
| | | MdcProcessQuantity processQuantity = new MdcProcessQuantity(); |
| | | BeanUtils.copyProperties(mdcProcessQuantity, processQuantity); |
| | | processQuantity.setEquipmentId(equipmentId); |
| | | boolean b = super.save(processQuantity); |
| | | if (b) { |
| | | result = true; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | } |