This commit is contained in:
lijiaqi 2024-09-09 16:01:08 +08:00
parent 408d262979
commit ea6905fce0
9 changed files with 201 additions and 41 deletions

View File

@ -1,32 +0,0 @@
package cn.workde.module.drone.coding.controller;
import cn.workde.core.constant.GrapeConst;
import cn.workde.module.drone.coding.service.AttributeValueService;
import cn.workde.module.upms.controller._BaseController;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
/**
* 无人机属性数值(AttributeValue)表控制层
*
* @author makejava
* @since 2024-09-06 10:49:54
*/
@Tag(name = "无人机属性数值")
@RestController
@RequestMapping(value = GrapeConst.API + "/attributeValue")
public class AttributeValueController extends _BaseController {
/**
* 服务对象
*/
@Resource
private AttributeValueService attributeValueService;
}

View File

@ -1,11 +1,13 @@
package cn.workde.module.drone.coding.controller;
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.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.BatchesVo;
import cn.workde.module.upms.controller._BaseController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -15,8 +17,11 @@ import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 无人机批次表(Batches)表控制层
*

View File

@ -2,10 +2,14 @@ package cn.workde.module.drone.coding.controller;
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.AttributeClassificationDto;
import cn.workde.module.drone.coding.entity.Mfc;
import cn.workde.module.drone.coding.service.MfcService;
import cn.workde.module.drone.coding.vo.AttributeValueVo;
import cn.workde.module.drone.coding.vo.MfcVo;
import cn.workde.module.upms.controller._BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -89,5 +93,27 @@ public class MfcController extends _BaseController {
public Result<List<Mfc>> list() {
return mfcService.getMfcList();
}
@GetMapping("/attributeOptions")
@Operation(summary = "分类 属性树形 下拉列表")
public Result<List<AttributeClassificationDto>> getAttributeOptions() {
return mfcService.getAttributeOptions();
}
@GetMapping("/attributeByBatchId")
@Operation(summary = "根据MFC ID获取属性ID集合")
public Result<List<String>> getAttributeByBatchId(String mfcId) {
if (StrUtil.isBlank(mfcId)) {
return Result.fail("MFC ID不能为空");
}
return mfcService.getAttributeByBatchId(mfcId);
}
@PostMapping("/editAttribute")
@Operation(summary = "设置属性")
public Result editAttribute(@RequestBody @Validated AttributeValueVo vo) {
return mfcService.editBatchesAttribute(vo);
}
}

View File

@ -0,0 +1,16 @@
package cn.workde.module.drone.coding.dto;
import cn.workde.module.drone.coding.entity.Attribute;
import cn.workde.module.drone.coding.entity.AttributeClassification;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class AttributeClassificationDto extends AttributeClassification {
@Schema(description = "关联属性")
private List<Attribute> attributeList;
}

View File

@ -22,8 +22,8 @@ import java.io.Serializable;
@TableName(value = "dss_drone_coding_attribute_value")
public class AttributeValue extends BaseEntity {
@Schema(description = "批次ID")
private String batchesId;
@Schema(description = "MFC ID")
private String mfcId;
@Schema(description = "属性分类ID")
private String attributeClassificationId;

View File

@ -1,17 +1,28 @@
package cn.workde.module.drone.coding.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
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.mapper.BatchesMapper;
import cn.workde.module.drone.coding.vo.AttributeValueVo;
import cn.workde.module.drone.coding.vo.BatchesVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* 无人机批次表(Batches)表服务实现类
*
@ -21,6 +32,22 @@ import org.springframework.stereotype.Service;
@Service("batchesService")
public class BatchesService extends BaseService<BatchesMapper, Batches> {
@Resource
@Lazy
private MfcService mfcService;
@Resource
@Lazy
private AttributeClassificationService attributeClassificationService;
@Resource
@Lazy
private AttributeService attributeService;
@Resource
@Lazy
private AttributeValueService attributeValueService;
public Result addBatches(BatchesVo vo) {
Long count = this.getBaseMapper().selectCount(new QueryWrapper<Batches>()
.lambda()
@ -71,9 +98,12 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
.like(StrUtil.isNotBlank(vo.getBatchesCode()), Batches::getBatchesCode, vo.getBatchesCode())
.like(StrUtil.isNotBlank(vo.getBatchesName()), Batches::getBatchesName, vo.getBatchesName())
.like(StrUtil.isNotBlank(vo.getBatchesDescription()), Batches::getBatchesDescription, vo.getBatchesDescription())
.eq(StrUtil.isNotBlank(vo.getMfcId()), Batches::getMfcId, vo.getMfcId())
);
return Result.data(paged);
}
}

View File

@ -1,17 +1,26 @@
package cn.workde.module.drone.coding.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.workde.core.base.BaseService;
import cn.workde.core.data.dto.Result;
import cn.workde.module.drone.coding.dto.AttributeClassificationDto;
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.Mfc;
import cn.workde.module.drone.coding.mapper.MfcMapper;
import cn.workde.module.drone.coding.vo.AttributeValueVo;
import cn.workde.module.drone.coding.vo.MfcVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -23,6 +32,19 @@ import java.util.List;
@Service("mfcService")
public class MfcService extends BaseService<MfcMapper, Mfc> {
@Resource
@Lazy
private AttributeClassificationService attributeClassificationService;
@Resource
@Lazy
private AttributeService attributeService;
@Resource
@Lazy
private AttributeValueService attributeValueService;
private String check(String id, MfcVo vo) {
String message = "";
// 校验MFC编号 编号长度必须为4位
@ -96,5 +118,97 @@ public class MfcService extends BaseService<MfcMapper, Mfc> {
List<Mfc> list = this.list();
return Result.data(list);
}
public Result<List<AttributeClassificationDto>> getAttributeOptions() {
//获取所有属性分类
List<AttributeClassification> attributeClassificationList = attributeClassificationService.list();
if (ObjUtil.isNotNull(attributeClassificationList)) {
List<AttributeClassificationDto> attributeClassificationDtoList = new ArrayList<AttributeClassificationDto>();
attributeClassificationList.forEach(attributeClassification -> {
AttributeClassificationDto attributeClassificationDto = new AttributeClassificationDto();
BeanUtil.copyProperties(attributeClassification, attributeClassificationDto);
//获取属性
List<Attribute> attributeList = attributeService.list(new QueryWrapper<Attribute>()
.lambda()
.eq(Attribute::getAttributeClassificationId, attributeClassification.getId())
);
attributeClassificationDto.setAttributeList(attributeList);
attributeClassificationDtoList.add(attributeClassificationDto);
});
return Result.data(attributeClassificationDtoList);
}
return Result.fail("数据不存在");
}
public Result<List<String>> getAttributeByBatchId(String mfcId) {
List<AttributeValue> attributeValueList = attributeValueService.list(
new QueryWrapper<AttributeValue>()
.lambda()
.eq(AttributeValue::getMfcId, mfcId)
);
if (ObjUtil.isNotNull(attributeValueList)) {
List<String> attributeValueListStr = attributeValueList.stream().map(AttributeValue::getAttributeId).toList();
return Result.data(attributeValueListStr);
}
return Result.data(null);
}
public Result editBatchesAttribute(AttributeValueVo vo) {
String mfcId = vo.getMfcId();
List<String> attributeIdList = vo.getAttributeIdList();
// attributeIdList为空的话全部删除
if (CollUtil.isEmpty(attributeIdList)) {
boolean flag = attributeValueService.remove(new QueryWrapper<AttributeValue>()
.lambda()
.eq(AttributeValue::getMfcId, mfcId)
);
return flag ? Result.success("操作成功") : Result.fail("操作失败");
}
List<AttributeValue> attributeValueList = attributeValueService.list(new QueryWrapper<AttributeValue>()
.lambda()
.eq(AttributeValue::getMfcId, mfcId)
);
List<String> addAttributeIdList = new ArrayList<>();
if (CollUtil.isNotEmpty(attributeValueList)) {
// 删除
List<String> attributeValueListStr = attributeValueList.stream().map(AttributeValue::getAttributeId).toList();
//找到数据库attributeValueListStr中不存在于前端传输的attributeIdList的属性
List<String> removeAttributeIdList = attributeValueListStr.stream().filter(attributeId -> !attributeIdList.contains(attributeId)).toList();
boolean flag = attributeValueService.remove(new QueryWrapper<AttributeValue>()
.lambda()
.eq(AttributeValue::getMfcId, mfcId)
.in(AttributeValue::getAttributeId, removeAttributeIdList)
);
if (!flag) return Result.fail("操作失败");
//找到前端传输的attributeIdList中不存在于数据库attributeValueListStr的属性
addAttributeIdList = attributeIdList.stream().filter(attributeId -> !attributeValueListStr.contains(attributeId)).toList();
}
if (CollUtil.isEmpty(addAttributeIdList)) {
addAttributeIdList = attributeIdList;
}
//新增
List<AttributeValue> attributeValueListNew = addAttributeIdList.stream().map(attributeId -> {
AttributeValue attributeValue = new AttributeValue();
attributeValue.setMfcId(mfcId);
Attribute attribute = attributeService.getById(attributeId);
attributeValue.setAttributeClassificationId(ObjUtil.isNotNull(attribute) ? attribute.getAttributeClassificationId() : null);
attributeValue.setAttributeId(attributeId);
return attributeValue;
}).toList();
boolean flag = attributeValueService.saveBatch(attributeValueListNew);
return flag ? Result.success("操作成功") : Result.fail("操作失败");
}
}

View File

@ -9,8 +9,9 @@ import java.util.List;
@Data
public class AttributeValueVo {
@Schema(description = "批次ID")
private String batchesId;
@Schema(description = "MFC ID")
@NotBlank(message = "MFC ID不能为空")
private String mfcId;
@Schema(description = "属性ID集合")
private List<String> attributeIdList;

View File

@ -16,15 +16,15 @@ public class BatchesVo {
private String batchesName;
@Schema(description = "批次描述")
@NotBlank(message = "批次描述不能为空")
// @NotBlank(message = "批次描述不能为空")
private String batchesDescription;
@Schema(description = "所属MFC ID")
@NotBlank(message = "请选择所属MFC")
private String mfcId;
@Schema(description = "规则ID")
@NotBlank(message = "请选择规则")
private String ruleId;
// @Schema(description = "规则ID")
// @NotBlank(message = "请选择规则")
// private String ruleId;
}