diff --git a/src/main/java/cn/workde/module/drone/coding/controller/BatchesController.java b/src/main/java/cn/workde/module/drone/coding/controller/BatchesController.java index a247214..ce0d10e 100644 --- a/src/main/java/cn/workde/module/drone/coding/controller/BatchesController.java +++ b/src/main/java/cn/workde/module/drone/coding/controller/BatchesController.java @@ -5,9 +5,11 @@ import cn.hutool.core.util.StrUtil; import cn.workde.core.constant.GrapeConst; import cn.workde.core.data.dto.OptionResult; import cn.workde.core.data.dto.Result; +import cn.workde.module.drone.coding.dto.AttributeValueDto; import cn.workde.module.drone.coding.entity.Batches; import cn.workde.module.drone.coding.service.BatchesService; import cn.workde.module.drone.coding.vo.AttributeValueVo; +import cn.workde.module.drone.coding.vo.AttributeValueVo2; import cn.workde.module.drone.coding.vo.BatchesVo; import cn.workde.module.upms.controller._BaseController; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -82,5 +84,23 @@ public class BatchesController extends _BaseController { return batchesService.getBatchesPageList(getPage(), vo); } + @GetMapping("/attributeValueDetail") + @Operation(summary = "获取属性值详情") + @Parameters({ + @Parameter(name = "batchesId", description = "批次ID", required = true) + }) + public Result getAttributeValueDetail(String batchesId) { + if (StrUtil.isBlank(batchesId)) { + return Result.fail("批次ID不能为空"); + } + return batchesService.getAttributeValueDetail(batchesId); + } + + @PostMapping("/editAttributeValueBatch") + @Operation(summary = "批量设置属性值") + public Result editAttributeValueBatch(@RequestBody @Validated AttributeValueVo2 vo) { + return batchesService.editAttributeValueBatch(vo); + } + } diff --git a/src/main/java/cn/workde/module/drone/coding/service/BatchesService.java b/src/main/java/cn/workde/module/drone/coding/service/BatchesService.java index 068ae36..4476d83 100644 --- a/src/main/java/cn/workde/module/drone/coding/service/BatchesService.java +++ b/src/main/java/cn/workde/module/drone/coding/service/BatchesService.java @@ -7,12 +7,11 @@ import cn.hutool.core.util.StrUtil; import cn.workde.core.base.BaseService; import cn.workde.core.data.dto.OptionResult; import cn.workde.core.data.dto.Result; -import cn.workde.module.drone.coding.entity.Attribute; -import cn.workde.module.drone.coding.entity.AttributeClassification; -import cn.workde.module.drone.coding.entity.AttributeValue; -import cn.workde.module.drone.coding.entity.Batches; +import cn.workde.module.drone.coding.dto.AttributeValueDto; +import cn.workde.module.drone.coding.entity.*; import cn.workde.module.drone.coding.mapper.BatchesMapper; import cn.workde.module.drone.coding.vo.AttributeValueVo; +import cn.workde.module.drone.coding.vo.AttributeValueVo2; import cn.workde.module.drone.coding.vo.BatchesVo; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -48,6 +47,10 @@ public class BatchesService extends BaseService { @Lazy private AttributeValueService attributeValueService; + @Resource + @Lazy + private AttributeValueBackupService attributeValueBackupService; + public Result addBatches(BatchesVo vo) { Long count = this.getBaseMapper().selectCount(new QueryWrapper() .lambda() @@ -103,7 +106,104 @@ public class BatchesService extends BaseService { return Result.data(paged); } + public Result getAttributeValueDetail(String batchesId) { + if (StrUtil.isBlank(batchesId)) return Result.fail("批次ID不能为空"); + AttributeValueDto attributeValueDto = new AttributeValueDto(); + // 获取MFC ID + Batches batches = this.getById(batchesId); + if (ObjUtil.isNull(batches)) return Result.fail("批次不存在"); + String mfcId = batches.getMfcId(); + //获取分类 + List attributeClassifications = attributeClassificationService.list( + new QueryWrapper() + .lambda() + .inSql(AttributeClassification::getId, "select distinct attribute_classification_id from dss_drone_coding_attribute_value where mfc_id = '" + mfcId + "'") + ); + if (CollUtil.isNotEmpty(attributeClassifications)) { + List attributeClassificationDtoList = new ArrayList(); + attributeClassifications.forEach(attributeClassification -> { + AttributeValueDto.AttributeClassificationDTO attributeClassificationDTO = new AttributeValueDto.AttributeClassificationDTO(); + attributeClassificationDTO.setAttributeClassificationId(attributeClassification.getId()); + attributeClassificationDTO.setAttributeClassificationName(attributeClassification.getAttributeClassificationName()); + //获取属性值 + List attributeValues = attributeValueService.list( + new QueryWrapper() + .lambda() + .eq(AttributeValue::getMfcId, mfcId) + .eq(AttributeValue::getAttributeClassificationId, attributeClassification.getId()) + ); + if (CollUtil.isNotEmpty(attributeValues)) { + List attributeDtoList = new ArrayList(); + for (AttributeValue attributeValue : attributeValues) { + AttributeValueDto.AttributeDTO attributeDTO = new AttributeValueDto.AttributeDTO(); + // 获取属性具体信息 + Attribute attribute = attributeService.getById(attributeValue.getAttributeId()); + if (ObjUtil.isNotNull(attribute)) { + attributeDTO.setAttributeDescription(attribute.getAttributeDescription()); + attributeDTO.setAttributeName(attribute.getAttributeName()); + attributeDTO.setAttributeRemarks(attribute.getAttributeRemarks()); + attributeDTO.setLocked(attribute.getLocked()); + } else { + continue; + } + attributeDTO.setMfcId(attributeValue.getMfcId()); + attributeDTO.setBatchesId(null); + attributeDTO.setAttributeId(attributeValue.getAttributeId()); + attributeDTO.setAttributeValue(attributeValue.getAttributeValue()); + //不是锁定的属性 看备份表是否有该属性 有则覆盖 + if (!attribute.getLocked()){ + AttributeValueBackup value = attributeValueBackupService.getOne(new QueryWrapper() + .lambda() + .eq(AttributeValueBackup::getBatchesId, batchesId) + .eq(AttributeValueBackup::getAttributeId, attributeValue.getAttributeId()) + .eq(AttributeValueBackup::getAttributeClassificationId, attributeValue.getAttributeClassificationId()) + ); + if (ObjUtil.isNotNull(value)) { + attributeValue.setAttributeValue(value.getAttributeValue()); + } + } + attributeDtoList.add(attributeDTO); + } + attributeClassificationDTO.setAttributeList(attributeDtoList); + } + attributeClassificationDtoList.add(attributeClassificationDTO); + }); + attributeValueDto.setAttributeClassificationList(attributeClassificationDtoList); + } + return Result.data(attributeValueDto); + } + public Result editAttributeValueBatch(AttributeValueVo2 vo) { + ArrayList attributeValues = new ArrayList<>(); + for (AttributeValueVo2.AttributeValueDto attributeValue : vo.getAttributeValueList()) { + // 检查属性是否被锁定 + Attribute attribute = attributeService.getById(attributeValue.getAttributeId()); + if (ObjUtil.isNull(attribute)) { + continue; + } + if (attribute.getLocked()) { + continue; + } + AttributeValueBackup value = attributeValueBackupService.getOne(new QueryWrapper() + .lambda() + .eq(AttributeValueBackup::getBatchesId, attributeValue.getBatchesId()) + .eq(AttributeValueBackup::getAttributeId, attributeValue.getAttributeId()) + .eq(AttributeValueBackup::getAttributeClassificationId, attributeValue.getAttributeClassificationId()) + ); + if (ObjUtil.isNotNull(value)) { + value.setAttributeValue(attributeValue.getAttributeValue()); + }else { + value = new AttributeValueBackup(); + value.setBatchesId(attributeValue.getBatchesId()); + value.setAttributeId(attributeValue.getAttributeId()); + value.setAttributeClassificationId(attributeValue.getAttributeClassificationId()); + value.setAttributeValue(attributeValue.getAttributeValue()); + } + attributeValues.add(value); + } + boolean flag = attributeValueBackupService.saveOrUpdateBatch(attributeValues); + return flag ? Result.success("操作成功") : Result.fail("操作失败"); + } } diff --git a/src/main/java/cn/workde/module/drone/coding/service/MfcService.java b/src/main/java/cn/workde/module/drone/coding/service/MfcService.java index 87a842e..40c8522 100644 --- a/src/main/java/cn/workde/module/drone/coding/service/MfcService.java +++ b/src/main/java/cn/workde/module/drone/coding/service/MfcService.java @@ -275,6 +275,10 @@ public class MfcService extends BaseService { public Result editAttributeValueBatch(AttributeValueVo2 vo) { ArrayList attributeValues = new ArrayList<>(); for (AttributeValueVo2.AttributeValueDto attributeValue : vo.getAttributeValueList()) { + Attribute attribute = attributeService.getById(attributeValue.getAttributeId()); + if (ObjUtil.isNull(attribute)) { + continue; + } AttributeValue value = attributeValueService.getOne(new QueryWrapper() .lambda() .eq(AttributeValue::getMfcId, attributeValue.getMfcId())