| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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.IService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.util.StringUtil; |
| | | 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.MdcTorqueConfig; |
| | | import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | import org.jeecg.modules.mdc.service.IMdcTorqueConfigService; |
| | | import org.jeecg.modules.quartz.entity.QuartzJob; |
| | | 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.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.lang.reflect.Array; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @Description: 扭矩配置管理 |
| | |
| | | * @Date: 2023-06-29 |
| | | */ |
| | | @Service |
| | | public class MdcTorqueConfigServiceImpl extends ServiceImpl<MdcTorqueConfigMapper, MdcTorqueConfig> implements IMdcTorqueConfigService{ |
| | | public class MdcTorqueConfigServiceImpl extends ServiceImpl<MdcTorqueConfigMapper, MdcTorqueConfig> implements IMdcTorqueConfigService { |
| | | |
| | | @Autowired |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | | @Override |
| | | public MdcTorqueConfig queryById(String id) { |
| | |
| | | |
| | | @Override |
| | | public Boolean addTorque(MdcTorqueConfig mdcTorqueConfig) { |
| | | return this.save(mdcTorqueConfig); |
| | | boolean result = false; |
| | | String[] equipmentIds = mdcTorqueConfig.getEquipmentIds().split(","); |
| | | for (String equipmentId : equipmentIds) { |
| | | MdcEquipment mdcEquipment = mdcEquipmentService.findEquipmentNameByEquipmentId(equipmentId); |
| | | MdcTorqueConfig torqueConfig = new MdcTorqueConfig(); |
| | | torqueConfig.setEquipmentId(equipmentId); |
| | | torqueConfig.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | torqueConfig.setTorqueDate(mdcTorqueConfig.getTorqueDate()); |
| | | torqueConfig.setTorqueValue(mdcTorqueConfig.getTorqueValue()); |
| | | torqueConfig.setNotes(mdcTorqueConfig.getNotes()); |
| | | boolean b = super.save(torqueConfig); |
| | | if (b) { |
| | | result = true; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<MdcTorqueConfig> findSpindleRunningCurve(float torqueValue, String equipmentId) { |
| | | return this.baseMapper.findSpindleRunningCurve(torqueValue,equipmentId); |
| | | return this.baseMapper.findSpindleRunningCurve(torqueValue, equipmentId); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<MdcTorqueConfig> queryPageList(Page page, HttpServletRequest req) { |
| | | QueryWrapper<MdcTorqueConfig> queryWrapper=new QueryWrapper(); |
| | | //检查请求体中是否有设备编号字段,存在则返回true |
| | | if (req.getParameterMap().containsKey("equipmentId")){ |
| | | //获取设备编号的值,不为空则添加到查询 |
| | | String equipmentId=req.getParameterMap().get("equipmentId")[0]; |
| | | queryWrapper.eq(StringUtils.isNotBlank(equipmentId),"equipment_id",equipmentId); |
| | | public IPage<MdcTorqueConfig> pageList(String userId, Page page, HttpServletRequest req, MdcTorqueConfig mdcTorqueConfig) { |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcTorqueConfig.getParentId()) && StringUtils.isEmpty(mdcTorqueConfig.getEquipmentId())) { |
| | | if ("2".equals(mdcTorqueConfig.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcTorqueConfig.getParentId()); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcTorqueConfig.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcTorqueConfig.getEquipmentId())) { |
| | | //单台设备信息 |
| | | mdcTorqueConfig.setMdcSectionIds(Collections.singletonList(mdcTorqueConfig.getEquipmentId())); |
| | | } else { |
| | | //查询用户所拥有的所有设备信息 |
| | | if ("2".equals(mdcTorqueConfig.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | return this.page(page,queryWrapper); |
| | | if (mdcTorqueConfig.getMdcSectionIds() == null || mdcTorqueConfig.getMdcSectionIds().isEmpty()) { |
| | | mdcTorqueConfig.setMdcSectionIds(equipmentIds); |
| | | } |
| | | if (mdcTorqueConfig.getMdcSectionIds() == null || mdcTorqueConfig.getMdcSectionIds().isEmpty()) { |
| | | return null; |
| | | } |
| | | return this.baseMapper.pageList(page, mdcTorqueConfig); |
| | | } |
| | | |
| | | /** |
| | | * 导出 |
| | | * |
| | | * @param userId |
| | | * @param mdcTorqueConfig |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ModelAndView exportXls(String userId, MdcTorqueConfig mdcTorqueConfig) { |
| | | // Step.1 组装查询条件 |
| | | LambdaQueryWrapper<MdcTorqueConfig> queryWrapper = new LambdaQueryWrapper<>(); |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcTorqueConfig.getParentId()) && StringUtils.isEmpty(mdcTorqueConfig.getEquipmentId())) { |
| | | if ("2".equals(mdcTorqueConfig.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcTorqueConfig.getParentId()); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcTorqueConfig.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcTorqueConfig.getEquipmentId())) { |
| | | //单台设备信息 |
| | | mdcTorqueConfig.setMdcSectionIds(Collections.singletonList(mdcTorqueConfig.getEquipmentId())); |
| | | } else { |
| | | //查询用户所拥有的所有设备信息 |
| | | if ("2".equals(mdcTorqueConfig.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | if (mdcTorqueConfig.getMdcSectionIds() == null || mdcTorqueConfig.getMdcSectionIds().isEmpty()) { |
| | | mdcTorqueConfig.setMdcSectionIds(equipmentIds); |
| | | } |
| | | if (mdcTorqueConfig.getMdcSectionIds() == null || mdcTorqueConfig.getMdcSectionIds().isEmpty()) { |
| | | return null; |
| | | } else { |
| | | queryWrapper.in(MdcTorqueConfig::getEquipmentId, mdcTorqueConfig.getMdcSectionIds()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcTorqueConfig.getEquipmentId())) { |
| | | queryWrapper.like(MdcTorqueConfig::getEquipmentId, mdcTorqueConfig.getEquipmentId()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcTorqueConfig.getEquipmentName())) { |
| | | queryWrapper.like(MdcTorqueConfig::getEquipmentId, mdcTorqueConfig.getEquipmentId()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcTorqueConfig.getStartTime()) && StringUtils.isNotEmpty(mdcTorqueConfig.getEndTime())) { |
| | | queryWrapper.between(MdcTorqueConfig::getTorqueDate, mdcTorqueConfig.getStartTime(), mdcTorqueConfig.getEndTime()); |
| | | } |
| | | queryWrapper.orderByAsc(MdcTorqueConfig::getTorqueDate); |
| | | // Step.2 AutoPoi 导出Excel |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | List<MdcTorqueConfig> mdcTorqueConfigs = this.baseMapper.selectList(queryWrapper); |
| | | // 导出文件名称 |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, "扭矩配置列表"); |
| | | mv.addObject(NormalExcelConstants.CLASS, MdcTorqueConfig.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, mdcTorqueConfigs); |
| | | return mv; |
| | | } |
| | | } |