|
@@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.pms.dal.mysql.iotmaintenancebom.IotMaintenanceBom
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.maintenance.IotMaintenancePlanMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.redis.BizNoRedisDAO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -42,6 +43,7 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
|
|
|
private BizNoRedisDAO bizNoRedisDAO;
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Long createIotMaintenancePlan(IotMaintenanceSaveVO createReqVO) {
|
|
|
if (ObjectUtil.isEmpty(createReqVO)) {
|
|
|
throw exception(IOT_MAINTENANCE_PLAN_NOT_EXISTS);
|
|
@@ -114,4 +116,36 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
|
|
|
return iotMaintenancePlanMapper.toBeMaintenanceDeviceBOMs();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Long updatePlan(IotMaintenanceSaveVO updateReqVO) {
|
|
|
+ if (ObjectUtil.isEmpty(updateReqVO)) {
|
|
|
+ throw exception(IOT_MAINTENANCE_PLAN_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isEmpty(updateReqVO.getMainPlan())) {
|
|
|
+ throw exception(IOT_MAINTENANCE_PLAN_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ List<IotMaintenanceBomSaveReqVO> deviceBOMs = updateReqVO.getMainPlanBom();
|
|
|
+ if (ObjectUtil.isEmpty(deviceBOMs)) {
|
|
|
+ throw exception(IOT_MAINTENANCE_PLAN_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ // 校验保养计划是否存在
|
|
|
+ IotMaintenancePlanDO existPlan = iotMaintenancePlanMapper.selectById(updateReqVO.getMainPlan().getId());
|
|
|
+ if (ObjectUtil.isEmpty(existPlan)) {
|
|
|
+ throw exception(IOT_MAINTENANCE_PLAN_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ IotMaintenancePlanSaveReqVO mainPlanSaveVO = updateReqVO.getMainPlan();
|
|
|
+ IotMaintenancePlanDO iotMaintenancePlan = BeanUtils.toBean(mainPlanSaveVO, IotMaintenancePlanDO.class);
|
|
|
+ iotMaintenancePlanMapper.updateById(iotMaintenancePlan);
|
|
|
+ // 保养计划明细 先删除再新增
|
|
|
+ iotMaintenanceBomMapper.deleteByPlanId(existPlan.getId());
|
|
|
+ List<IotMaintenanceBomDO> maintenanceBOMs = new ArrayList<>();
|
|
|
+ maintenanceBOMs = convertList(deviceBOMs, bom -> BeanUtils.toBean(bom, IotMaintenanceBomDO.class, item -> item
|
|
|
+ .setPlanId(iotMaintenancePlan.getId())
|
|
|
+ .setId(null)
|
|
|
+ .setDeviceCategoryId(bom.getAssetClass())));
|
|
|
+ iotMaintenanceBomMapper.insertBatch(maintenanceBOMs);
|
|
|
+ return iotMaintenancePlan.getId();
|
|
|
+ }
|
|
|
+
|
|
|
}
|