“linengliang”
2023-12-13 98acd3249e64f5366f0dc145f0b896a8f9a0183a
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/StreamController.java
@@ -13,8 +13,8 @@
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.eam.entity.Equipment;
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.eam.entity.*;
import org.jeecg.modules.eam.service.*;
import org.jeecg.modules.eam.vo.ButtonVo;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.service.*;
@@ -28,15 +28,11 @@
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.entity.StreamOperation;
import org.jeecg.modules.eam.entity.ABCAssessment;
import org.jeecg.modules.eam.entity.Stream;
import org.jeecg.modules.eam.service.IStreamService;
import org.jeecg.modules.eam.service.IStreamOperationService;
import org.jeecg.modules.eam.service.IABCAssessmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
@@ -93,6 +89,23 @@
    @Autowired
    private IEamEquipmentService equipmentService;
    @Autowired
    private IdentityService sysIdentityService;
    @Autowired
    private IEquipmentMaintenancePlanDetailService planDetailService;
    @Autowired
    private IEquipmentMaintenancePlanService planService;
    @Autowired
    private IMaintenanceStandardService maintenanceStandardService;
    @Autowired
    private IEquipmentUpdateInfoService updateInfoService;
@@ -583,12 +596,82 @@
          List<SysDictItem> nodes = sysDictItemService.selectItemsByMainId(streamNode.getId());
          if(buttonVo.getNodeSort()+1==nodes.size()){
             List<ABCAssessment> abcAssessments = aBCAssessmentService.selectByMainId(buttonVo.getStreamId());
            EquipmentMaintenancePlan plan = new EquipmentMaintenancePlan();
            UUID uuid = UUID.randomUUID();
            long mostSignificantBits = uuid.getMostSignificantBits();
            long leastSignificantBits = uuid.getLeastSignificantBits();
            // 将最高位和最低位取出,然后合并为一个long类型的值
            long combinedBits = mostSignificantBits ^ leastSignificantBits;
            // 将合并后的long值转换为16进制字符串
            String hexString = Long.toHexString(combinedBits);
            String planNum = sysIdentityService.getNumByTypeAndLength("",4);
            plan.setId(hexString);
            plan.setNum(planNum);
            plan.setType("3");
            plan.setStatus("created");
                plan.setCreateReason("因ABC标识从B或C变更为A而导致下次三保时间过期,就这些设备生成的临时保养计划");
            List<EquipmentMaintenancePlanDetail> details = new ArrayList<>();
             for(ABCAssessment abcAssessment:abcAssessments){
               Equipment equipment = equipmentService.getById(abcAssessment.getEquipmentId());
               String oldStandard = equipment.getEquipmentImportanceId();
               String newStandard = abcAssessment.getFinalStandard();
               LocalDate currentDate = LocalDate.now();
               // 将当前日期加一天
               LocalDate nextDay = currentDate.plusDays(1);
               LocalDate nextMonth = currentDate.plusMonths(1);
               // 将LocalDate转换为Date
               Date currentDateAsDate = Date.from(currentDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
               Date nextDayAsDate =Date.from(nextDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
               Date nextMonthAsDate = Date.from(nextMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
               Date needingDate = equipment.getNextThirdMaintenanceTime();
               Boolean a = StringUtils.isNotBlank(oldStandard);
               Boolean b = oldStandard.equals("B")||oldStandard.equals("C");
               Boolean c = newStandard.equals("A");
               Boolean d = ObjectUtils.isNotNull(needingDate)&&needingDate.compareTo(currentDateAsDate)<0;
               if(a&&b&&c&&d){
                  EquipmentMaintenancePlanDetail equipmentMaintenancePlanDetail = new EquipmentMaintenancePlanDetail();
                  equipmentMaintenancePlanDetail.setPlanId(hexString);
                  equipmentMaintenancePlanDetail.setEquipmentId(equipment.getId());
                  equipmentMaintenancePlanDetail.setPlanStartTime(nextDayAsDate);
                  equipmentMaintenancePlanDetail.setPlanEndTime(nextMonthAsDate);
                  MaintenanceStandard maintenanceStandard = maintenanceStandardService.getOne(new QueryWrapper<MaintenanceStandard>()
                        .eq("equipment_id",equipment.getId())
                        .eq("maintenance_type","3")
                        .eq("version_status","2")
                        .eq("del_flag",0),false);
                  if(ObjectUtils.isNotNull(maintenanceStandard)){
                     equipmentMaintenancePlanDetail.setStandardId(maintenanceStandard.getId());
                     details.add(equipmentMaintenancePlanDetail);
                  }
               }
               equipment.setEquipmentImportanceId(abcAssessment.getFinalStandard());
               equipment.setStandardA(abcAssessment.getStandardA());
               equipment.setStandardB(abcAssessment.getStandardB());
               equipment.setStandardC(abcAssessment.getStandardC());
               equipment.setStandardD(abcAssessment.getStandardD());
               equipment.setStandardE(abcAssessment.getStandardE());
               equipment.setStandardF(abcAssessment.getStandardF());
               equipmentService.updateById(equipment);
               EquipmentUpdateInfo equipmentUpdateInfo = new EquipmentUpdateInfo();
               equipmentUpdateInfo.setOldAbcTag(oldStandard);
               equipmentUpdateInfo.setNewAbcTag(newStandard);
               equipmentUpdateInfo.setEquipmentId(equipment.getId());
               equipmentUpdateInfo.setUpdatePerson(user.getId());
               equipmentUpdateInfo.setUpdateType("ABC");
               equipmentUpdateInfo.setUpdateDate(currentDateAsDate);
               updateInfoService.save(equipmentUpdateInfo);
            }
             if(details.size()>0){
                planService.save(plan);
                planDetailService.saveBatch(details);
            }
         }
         SysDictItem nextStreamNodeItem = sysDictItemService.getOne(new QueryWrapper<SysDictItem>().eq("dict_id",streamNode.getId()).eq("sort_order",buttonVo.getNodeSort()+1),false);
         return getResult(buttonVo, user, streamOperations, nextStreamNodeItem);
      }