| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | 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 com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.json.JsonMapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.FileUploadResult; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; |
| | | import org.jeecg.modules.eam.entity.EamMaintenanceStandard; |
| | | import org.jeecg.modules.eam.entity.EamMaintenanceStandardDetail; |
| | | import org.jeecg.modules.eam.mapper.EamMaintenanceStandardMapper; |
| | | import org.jeecg.modules.eam.request.EamMaintenanceStandardRequest; |
| | | import org.jeecg.modules.eam.service.IEamMaintenanceStandardDetailService; |
| | | import org.jeecg.modules.eam.service.IEamMaintenanceStandardService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 保养标准 |
| | |
| | | private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService; |
| | | |
| | | @Override |
| | | public IPage<EamMaintenanceStandard> queryPageList(Page<EamMaintenanceStandard> page, EamMaintenanceStandard eamMaintenanceStandard) { |
| | | LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | StringBuilder sqlSb = new StringBuilder("select 1 from eam_equipment t where t.id = equipment_id and t.equipment_code in ("); |
| | | equipArr.forEach(equipmentCode -> { |
| | | sqlSb.append("'").append(equipmentCode).append("',"); |
| | | }); |
| | | sqlSb.append(")"); |
| | | String sql = sqlSb.toString().replaceAll(",\\)", ")"); |
| | | queryWrapper.exists(sql); |
| | | } else { |
| | | //没有选择设备,根据车间过滤设备 |
| | | queryWrapper.exists("select 1 from eam_equipment e where exists (select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id) and e.id = equipment_id", sysUser.getId()); |
| | | } |
| | | if(eamMaintenanceStandard != null) { |
| | | //编码 模糊查询 |
| | | if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardCode())) { |
| | | queryWrapper.like(EamMaintenanceStandard::getStandardCode, eamMaintenanceStandard.getStandardCode()); |
| | | } |
| | | //名称 模糊查询 |
| | | if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardName())) { |
| | | queryWrapper.like(EamMaintenanceStandard::getStandardName, eamMaintenanceStandard.getStandardName()); |
| | | } |
| | | //设备 |
| | | if(StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentId())) { |
| | | queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, eamMaintenanceStandard.getEquipmentId()); |
| | | } |
| | | //保养分类 |
| | | if(StringUtils.isNotBlank(eamMaintenanceStandard.getMaintenanceCategory())) { |
| | | queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, eamMaintenanceStandard.getMaintenanceCategory()); |
| | | } |
| | | //保养分类 |
| | | if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardStatus())) { |
| | | queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, eamMaintenanceStandard.getStandardStatus()); |
| | | } |
| | | } |
| | | queryWrapper.orderByDesc(EamMaintenanceStandard::getCreateTime); |
| | | return eamMaintenanceStandardMapper.selectPage(page, queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) { |
| | | EamMaintenanceStandard entity = new EamMaintenanceStandard(); |
| | |
| | | entity.setStandardVersion(CommonConstant.OPERATE_TYPE_1); |
| | | //设备处理 |
| | | entity.setEquipmentId(standardRequest.getEquipmentId()); |
| | | //删除标记 |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | //重复性校验 |
| | | //TODO |
| | | EamMaintenanceStandard exist = checkDuplicate(entity.getEquipmentId(), entity.getMaintenanceCategory()); |
| | | if(exist != null){ |
| | | throw new JeecgBootException("设备标准已存在,不能重复添加!"); |
| | | } |
| | | //处理附件 |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getFileList())) { |
| | | FileUploadResult fileUploadResult = standardRequest.getFileList().get(0); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean editMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) { |
| | | return false; |
| | | EamMaintenanceStandard entity = eamMaintenanceStandardMapper.selectById(standardRequest.getId()); |
| | | if(entity == null){ |
| | | throw new JeecgBootException("编辑的数据已删除,请刷新重试!"); |
| | | } |
| | | entity.setStandardName(standardRequest.getStandardName()); |
| | | entity.setMaintenancePeriod(standardRequest.getMaintenancePeriod()); |
| | | entity.setFileCode(standardRequest.getFileCode()); |
| | | //处理附件 |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getFileList())) { |
| | | FileUploadResult fileUploadResult = standardRequest.getFileList().get(0); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(fileUploadResult); |
| | | entity.setReferenceFile(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | log.error("JSON转换失败:" + e.getMessage(), e); |
| | | } |
| | | }else { |
| | | entity.setReferenceFile(null); |
| | | } |
| | | eamMaintenanceStandardMapper.updateById(entity); |
| | | //处理详情 |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { |
| | | List<EamMaintenanceStandardDetail> addList = new ArrayList<>(); |
| | | List<EamMaintenanceStandardDetail> updateList = new ArrayList<>(); |
| | | standardRequest.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setStandardId(entity.getId()); |
| | | if(tableDetail.getId() == null){ |
| | | addList.add(tableDetail); |
| | | }else { |
| | | updateList.add(tableDetail); |
| | | } |
| | | }); |
| | | if(CollectionUtil.isNotEmpty(addList)){ |
| | | eamMaintenanceStandardDetailService.saveBatch(addList); |
| | | } |
| | | if(CollectionUtil.isNotEmpty(updateList)){ |
| | | eamMaintenanceStandardDetailService.updateBatchById(updateList); |
| | | } |
| | | } |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getRemoveDetailList())) { |
| | | List<String> ids = standardRequest.getRemoveDetailList().stream().map(EamMaintenanceStandardDetail::getId).collect(Collectors.toList()); |
| | | eamMaintenanceStandardDetailService.removeBatchByIds(ids); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean upgradeMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) { |
| | | EamMaintenanceStandard entity = eamMaintenanceStandardMapper.selectById(standardRequest.getId()); |
| | | if(entity == null){ |
| | | throw new JeecgBootException("编辑的数据已删除,请刷新重试!"); |
| | | } |
| | | entity.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | //原来的作废 |
| | | eamMaintenanceStandardMapper.updateById(entity); |
| | | |
| | | //新增一个版本 |
| | | EamMaintenanceStandard newEntity = new EamMaintenanceStandard(); |
| | | newEntity.setStandardCode(standardRequest.getStandardCode()); |
| | | newEntity.setStandardName(standardRequest.getStandardName()); |
| | | newEntity.setMaintenanceCategory(standardRequest.getMaintenanceCategory()); |
| | | newEntity.setMaintenancePeriod(standardRequest.getMaintenancePeriod()); |
| | | newEntity.setInitialDate(standardRequest.getInitialDate()); |
| | | newEntity.setFileCode(standardRequest.getFileCode()); |
| | | newEntity.setStandardStatus(MaintenanceStandardStatusEnum.NORMAL.name()); |
| | | //版本递增 |
| | | newEntity.setStandardVersion(entity.getStandardVersion() + 1); |
| | | //设备处理 |
| | | newEntity.setEquipmentId(standardRequest.getEquipmentId()); |
| | | //删除标记 |
| | | newEntity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | //重复性校验 |
| | | EamMaintenanceStandard exist = checkDuplicate(newEntity.getEquipmentId(), newEntity.getMaintenanceCategory()); |
| | | if(exist != null){ |
| | | throw new JeecgBootException("设备标准已存在,不能重复添加!"); |
| | | } |
| | | //处理附件 |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getFileList())) { |
| | | FileUploadResult fileUploadResult = standardRequest.getFileList().get(0); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(fileUploadResult); |
| | | newEntity.setReferenceFile(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | log.error("JSON转换失败:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | eamMaintenanceStandardMapper.insert(newEntity); |
| | | //处理明细数据 |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { |
| | | standardRequest.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setId(null); |
| | | tableDetail.setCreateBy(null); |
| | | tableDetail.setUpdateBy(null); |
| | | tableDetail.setCreateTime(null); |
| | | tableDetail.setUpdateTime(null); |
| | | tableDetail.setStandardId(newEntity.getId()); |
| | | }); |
| | | eamMaintenanceStandardDetailService.saveBatch(standardRequest.getTableDetailList()); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public EamMaintenanceStandard checkDuplicate(String equipmentId, String maintenanceCategory) { |
| | | LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, equipmentId); |
| | | queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory); |
| | | queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.NORMAL.name()); |
| | | queryWrapper.orderByDesc(EamMaintenanceStandard::getStandardVersion); |
| | | |
| | | List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper); |
| | | if(CollectionUtil.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | return list.get(0); |
| | | } |
| | | |
| | | /** |
| | | * 查询标准列表-前端展示该用户拥有的标准 |
| | | * @param keyword 设备编号 |
| | | * @param maintenanceCategory 保养类型 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<EamMaintenanceStandard> queryListBykeywordAndCategory(String keyword, String maintenanceCategory){ |
| | | LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | return eamMaintenanceStandardMapper.queryListBykeywordAndCategory(loginUser.getId(),keyword, maintenanceCategory); |
| | | } |
| | | } |