| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | 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.constant.DataBaseConstant; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | import org.jeecg.modules.eam.constant.*; |
| | | import org.jeecg.modules.eam.dto.EamReportRepairDto; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.mapper.EamReportRepairMapper; |
| | | import org.jeecg.modules.eam.request.EamReportRepairQuery; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentExtendService; |
| | | import org.jeecg.modules.eam.service.IEamReportRepairService; |
| | | import org.jeecg.modules.eam.request.EamReportRepairRequest; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.system.entity.SysAnnouncementSend; |
| | | import org.jeecg.modules.system.service.IBaseFactoryService; |
| | | import org.jeecg.modules.system.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | 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.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 故障报修 |
| | |
| | | @Resource |
| | | private IEamEquipmentExtendService eamEquipmentExtendService; |
| | | |
| | | @Autowired |
| | | private IBaseFactoryUserService baseFactoryUserService; |
| | | @Autowired |
| | | private IBaseFactoryService baseFactoryService; |
| | | @Autowired |
| | | private IEamReportProductHazardsService iEamReportProductHazardsService; |
| | | @Autowired |
| | | private IEamReportAccidentsRegisterService iEamReportAccidentsRegisterService; |
| | | @Autowired |
| | | @Lazy |
| | | private IEamRepairOrderService iEamRepairOrderService; |
| | | @Autowired |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | /** |
| | | * 分页列表 |
| | | * |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<EamReportRepair> pageList(Page<EamReportRepair> page, EamReportRepairQuery query) { |
| | | QueryWrapper<EamReportRepair> queryWrapper = new QueryWrapper<>(); |
| | | public IPage<EamReportRepairDto> pageList(Page<EamReportRepairDto> page, EamReportRepairQuery query) { |
| | | QueryWrapper<EamReportRepairDto> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据车间过滤设备 |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId()); |
| | | //没有选择设备,根据中心过滤设备 |
| | | List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId())); |
| | | if (!CollectionUtils.isEmpty(baseFactoryUserList)) { |
| | | Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); |
| | | Set<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("e.factory_org_code", factoryCode); |
| | | } else { |
| | | return page; |
| | | } |
| | | } |
| | | //查询条件过滤 |
| | | if (query != null) { |
| | |
| | | entity.setFaultStartTime(new Date()); |
| | | entity.setBreakdownFlag(CommonConstant.DEFAULT_0); |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | entity.setFaultName("周保执行报修处理"); |
| | | entity.setFaultDescription(sb.toString()); |
| | | entity.setFaultType(CommonConstant.DEFAULT_1); |
| | | entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); |
| | | this.baseMapper.insert(entity); |
| | | //更新设备维修状态 |
| | | eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name()); |
| | |
| | | entity.setFaultStartTime(new Date()); |
| | | entity.setBreakdownFlag(CommonConstant.DEFAULT_0); |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | entity.setFaultName("点检执行报修处理"); |
| | | entity.setFaultDescription(sb.toString()); |
| | | entity.setFaultType(CommonConstant.DEFAULT_1); |
| | | entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); |
| | | this.baseMapper.insert(entity); |
| | | //更新设备维修状态 |
| | | eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name()); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair") |
| | | public EamReportRepair add(EamReportRepair eamReportRepair) { |
| | | eamReportRepair.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); |
| | | public EamReportRepair add(EamReportRepairRequest eamReportRepairRequest) { |
| | | EamReportRepair eamReportRepair = new EamReportRepair(); |
| | | BeanUtils.copyProperties(eamReportRepairRequest, eamReportRepair); |
| | | eamReportRepair.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | // 附件处理 |
| | | if (eamReportRepair.getImageFilesResult() != null) { |
| | | List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult(); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(imageFilesResult); |
| | | eamReportRepair.setImageFiles(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | return null; |
| | | } |
| | | } |
| | | eamReportRepair.setReportStatus(EamRepairOrderRepairStatusEnum.PENDING_REPAIR.name()); |
| | | this.baseMapper.insert(eamReportRepair); |
| | | if(StrUtil.isNotEmpty(eamReportRepair.getIsProcessed())&&("1").equals(eamReportRepair.getIsProcessed())){ |
| | | //添加产品安全隐患确认 |
| | | EamReportProductHazards eamReportProductHazards=new EamReportProductHazards(); |
| | | eamReportProductHazards.setEquipmentId(eamReportRepair.getEquipmentId()); |
| | | eamReportProductHazards.setReportId(eamReportRepair.getId()); |
| | | iEamReportProductHazardsService.save(eamReportProductHazards); |
| | | } |
| | | if (StrUtil.isNotEmpty(eamReportRepair.getIsAccidentsRegister())&&("1").equals(eamReportRepair.getIsAccidentsRegister())) { |
| | | //添加设备事故登记表 |
| | | EamReportAccidentsRegister eamReportAccidentsRegister = new EamReportAccidentsRegister(); |
| | | BeanUtils.copyProperties(eamReportRepairRequest, eamReportAccidentsRegister); |
| | | eamReportAccidentsRegister.setReportId(eamReportRepair.getId()); |
| | | eamReportAccidentsRegister.setDelFlag(CommonConstant.DEFAULT_0); |
| | | iEamReportAccidentsRegisterService.save(eamReportAccidentsRegister); |
| | | } |
| | | //生成维修工单,可能会有领取操作 |
| | | EamRepairOrder eamRepairOrder=new EamRepairOrder(); |
| | | BeanUtils.copyProperties(eamReportRepairRequest, eamRepairOrder); |
| | | String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.REPAIR_ORDER_CODE_RULE); |
| | | eamRepairOrder.setRepairCode(codeSeq); |
| | | eamRepairOrder.setId(null); |
| | | eamRepairOrder.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | eamRepairOrder.setReportId(eamReportRepair.getId()); |
| | | eamRepairOrder.setRepairStatus(EamRepairOrderRepairStatusEnum.PENDING_REPAIR.name()); |
| | | iEamRepairOrderService.save(eamRepairOrder); |
| | | //更新设备维修状态 |
| | | eamEquipmentExtendService.updateEquipmentRepairStatus(eamReportRepair.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name()); |
| | | return eamReportRepair; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean edit(EamReportRepair eamReportRepair) { |
| | | // 附件处理 |
| | | if (eamReportRepair.getImageFilesResult() != null) { |
| | | List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult(); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(imageFilesResult); |
| | | eamReportRepair.setImageFiles(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | return false; |
| | | public boolean edit(EamReportRepairDto eamReportRepairDto) { |
| | | LambdaUpdateWrapper<EamReportRepair> updateWrapper = new UpdateWrapper().lambda(); |
| | | EamReportRepair eamReportRepair=new EamReportRepair(); |
| | | BeanUtils.copyProperties(eamReportRepairDto, eamReportRepair); |
| | | if(StrUtil.isNotEmpty(eamReportRepairDto.getIsProcessed())){ |
| | | //todo 缺少对应流程判断 |
| | | if ("0".equals(eamReportRepairDto.getIsProcessed())) { |
| | | updateWrapper.set(EamReportRepair::getBatchNumber,null); |
| | | updateWrapper.set(EamReportRepair::getProcessingPart,null); |
| | | updateWrapper.set(EamReportRepair::getQuantity, null); |
| | | } |
| | | } else { |
| | | eamReportRepair.setImageFiles(null); |
| | | //直接删除再添加 |
| | | iEamReportProductHazardsService.remove(new QueryWrapper<EamReportProductHazards>().eq("report_id",eamReportRepairDto.getId()) |
| | | .eq("equipment_id",eamReportRepairDto.getEquipmentId())); |
| | | //添加产品安全隐患确认 |
| | | EamReportProductHazards eamReportProductHazards=new EamReportProductHazards(); |
| | | eamReportProductHazards.setEquipmentId(eamReportRepairDto.getEquipmentId()); |
| | | eamReportProductHazards.setReportId(eamReportRepairDto.getId()); |
| | | eamReportProductHazards.setId(null); |
| | | iEamReportProductHazardsService.save(eamReportProductHazards); |
| | | } |
| | | this.baseMapper.updateById(eamReportRepair); |
| | | if (StrUtil.isNotEmpty(eamReportRepairDto.getIsAccidentsRegister())) { |
| | | //todo 缺少对应流程判断 |
| | | if ("0".equals(eamReportRepairDto.getIsAccidentsRegister())) { |
| | | updateWrapper.set(EamReportRepair::getScrapPartNumber,null); |
| | | updateWrapper.set(EamReportRepair::getScrapPartValue, null); |
| | | updateWrapper.set(EamReportRepair::getScrapPartQuantity, null); |
| | | } |
| | | //直接删除再添加 |
| | | iEamReportAccidentsRegisterService.remove(new QueryWrapper<EamReportAccidentsRegister>() |
| | | .eq("report_id",eamReportRepairDto.getId()).eq("equipment_id",eamReportRepairDto.getEquipmentId())); |
| | | //添加设备事故登记表 |
| | | EamReportAccidentsRegister eamReportAccidentsRegister = new EamReportAccidentsRegister(); |
| | | BeanUtils.copyProperties(eamReportRepairDto, eamReportAccidentsRegister); |
| | | eamReportAccidentsRegister.setReportId(eamReportRepairDto.getId()); |
| | | eamReportAccidentsRegister.setDelFlag(CommonConstant.DEFAULT_0); |
| | | eamReportAccidentsRegister.setId(null); |
| | | iEamReportAccidentsRegisterService.save(eamReportAccidentsRegister); |
| | | } |
| | | updateWrapper.eq(EamReportRepair::getId,eamReportRepairDto.getId()); |
| | | this.update(eamReportRepair,updateWrapper); |
| | | return true; |
| | | } |
| | | |
| | |
| | | entity.setFaultStartTime(new Date()); |
| | | entity.setBreakdownFlag(CommonConstant.DEFAULT_0); |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | entity.setFaultName("二保执行报修处理"); |
| | | entity.setFaultDescription(sb.toString()); |
| | | entity.setFaultType(CommonConstant.DEFAULT_1); |
| | | entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); |
| | | this.baseMapper.insert(entity); |
| | | //更新设备维修状态 |
| | | eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name()); |
| | |
| | | entity.setFaultStartTime(new Date()); |
| | | entity.setBreakdownFlag(CommonConstant.DEFAULT_0); |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | entity.setFaultName("三保执行报修处理"); |
| | | entity.setFaultDescription(sb.toString()); |
| | | entity.setFaultType(CommonConstant.DEFAULT_1); |
| | | entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); |
| | | this.baseMapper.insert(entity); |
| | | //更新设备维修状态 |
| | | eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name()); |