This commit is contained in:
lijiaqi 2024-09-11 10:52:41 +08:00
parent 5c2a59c66f
commit 4a13408dbe
9 changed files with 251 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import cn.workde.core.constant.GrapeConst;
import cn.workde.core.data.dto.OptionResult; import cn.workde.core.data.dto.OptionResult;
import cn.workde.core.data.dto.Result; import cn.workde.core.data.dto.Result;
import cn.workde.module.drone.coding.dto.AttributeValueDto; import cn.workde.module.drone.coding.dto.AttributeValueDto;
import cn.workde.module.drone.coding.dto.BatchesDto;
import cn.workde.module.drone.coding.entity.Batches; import cn.workde.module.drone.coding.entity.Batches;
import cn.workde.module.drone.coding.service.BatchesService; import cn.workde.module.drone.coding.service.BatchesService;
import cn.workde.module.drone.coding.vo.AttributeValueVo; import cn.workde.module.drone.coding.vo.AttributeValueVo;
@ -70,7 +71,7 @@ public class BatchesController extends _BaseController {
@Parameters({ @Parameters({
@Parameter(name = "batchId", description = "批次ID", required = true) @Parameter(name = "batchId", description = "批次ID", required = true)
}) })
public Result<Batches> detail(String batchId) { public Result<BatchesDto> detail(String batchId) {
return batchesService.getBatchesDetail(batchId); return batchesService.getBatchesDetail(batchId);
} }
@ -80,10 +81,16 @@ public class BatchesController extends _BaseController {
@Parameter(name = "current", description = "当前页", required = true), @Parameter(name = "current", description = "当前页", required = true),
@Parameter(name = "size", description = "每页数量", required = true) @Parameter(name = "size", description = "每页数量", required = true)
}) })
public Result<Page<Batches>> page(@ParameterObject BatchesVo vo) { public Result<Page<BatchesDto>> page(@ParameterObject BatchesVo vo) {
return batchesService.getBatchesPageList(getPage(), vo); return batchesService.getBatchesPageList(getPage(), vo);
} }
@GetMapping("/list")
@Operation(summary = "获取批次列表")
public Result<List<BatchesDto>> list() {
return batchesService.getBatchesList();
}
@GetMapping("/attributeValueDetail") @GetMapping("/attributeValueDetail")
@Operation(summary = "获取属性值详情") @Operation(summary = "获取属性值详情")
@Parameters({ @Parameters({

View File

@ -3,12 +3,23 @@ package cn.workde.module.drone.coding.controller;
import cn.workde.core.constant.GrapeConst; import cn.workde.core.constant.GrapeConst;
import cn.workde.core.data.dto.Result;
import cn.workde.module.drone.coding.entity.Rule;
import cn.workde.module.drone.coding.service.RuleService; import cn.workde.module.drone.coding.service.RuleService;
import cn.workde.module.drone.coding.vo.RuleVo;
import cn.workde.module.upms.controller._BaseController; import cn.workde.module.upms.controller._BaseController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 规则管理表(Rule)表控制层 * 规则管理表(Rule)表控制层
* *
@ -25,6 +36,55 @@ public class RuleController extends _BaseController {
@Resource @Resource
private RuleService ruleService; private RuleService ruleService;
@PostMapping("/add")
@Operation(summary = "增加")
public Result addRule(@RequestBody @Validated RuleVo vo) {
return ruleService.addRule(vo);
}
@PutMapping("/edit/{ruleId}")
@Operation(summary = "编辑")
@Parameters({
@Parameter(name = "ruleId", description = "规则ID", required = true)
})
public Result editRule(@RequestBody @Validated RuleVo vo, @PathVariable String ruleId) {
return ruleService.editRule(ruleId, vo);
}
@DeleteMapping("/delete/{ruleId}")
@Operation(summary = "删除")
@Parameters({
@Parameter(name = "ruleId", description = "规则ID", required = true)
})
public Result deleteRule(@PathVariable String ruleId) {
return ruleService.deleteRule(ruleId);
}
@GetMapping("/detail")
@Operation(summary = "详情")
@Parameters({
@Parameter(name = "ruleId", description = "规则ID", required = true)
})
public Result<Rule> detail(String ruleId) {
return ruleService.getRuleDetail(ruleId);
}
@GetMapping("/list")
@Operation(summary = "列表查询")
public Result<List<Rule>> list() {
return ruleService.getRuleList();
}
@GetMapping("/page")
@Operation(summary = "分页查询")
@Parameters({
@Parameter(name = "current", description = "当前页", required = true),
@Parameter(name = "size", description = "每页数量", required = true)
})
public Result<Page<Rule>> page(@ParameterObject RuleVo vo) {
return ruleService.getRulePageList(getPage(), vo);
}
} }

View File

@ -0,0 +1,19 @@
package cn.workde.module.drone.coding.dto;
import cn.workde.module.drone.coding.entity.Batches;
import cn.workde.module.drone.coding.entity.Mfc;
import cn.workde.module.drone.coding.entity.Rule;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class BatchesDto extends Batches {
@Schema(description = "MFC")
private Mfc mfc;
@Schema(description = "规则")
private Rule rule;
}

View File

@ -8,11 +8,13 @@ import cn.workde.core.base.BaseService;
import cn.workde.core.data.dto.OptionResult; import cn.workde.core.data.dto.OptionResult;
import cn.workde.core.data.dto.Result; import cn.workde.core.data.dto.Result;
import cn.workde.module.drone.coding.dto.AttributeValueDto; import cn.workde.module.drone.coding.dto.AttributeValueDto;
import cn.workde.module.drone.coding.dto.BatchesDto;
import cn.workde.module.drone.coding.entity.*; import cn.workde.module.drone.coding.entity.*;
import cn.workde.module.drone.coding.mapper.BatchesMapper; import cn.workde.module.drone.coding.mapper.BatchesMapper;
import cn.workde.module.drone.coding.vo.AttributeValueVo; import cn.workde.module.drone.coding.vo.AttributeValueVo;
import cn.workde.module.drone.coding.vo.AttributeValueVo2; import cn.workde.module.drone.coding.vo.AttributeValueVo2;
import cn.workde.module.drone.coding.vo.BatchesVo; import cn.workde.module.drone.coding.vo.BatchesVo;
import cn.workde.module.drone.coding.wrapper.BatchesWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -76,7 +78,8 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
if (ObjUtil.isNull(obj)) { if (ObjUtil.isNull(obj)) {
return Result.fail("数据不存在"); return Result.fail("数据不存在");
} }
BeanUtil.copyProperties(vo, obj); obj.setBatchesName(vo.getBatchesName());
obj.setBatchesDescription(vo.getBatchesDescription());
return this.saveOrUpdate(obj) ? Result.success("操作成功") : Result.fail("操作失败"); return this.saveOrUpdate(obj) ? Result.success("操作成功") : Result.fail("操作失败");
} }
@ -87,15 +90,15 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
return this.removeById(id) ? Result.success("操作成功") : Result.fail("操作失败"); return this.removeById(id) ? Result.success("操作成功") : Result.fail("操作失败");
} }
public Result<Batches> getBatchesDetail(String id) { public Result<BatchesDto> getBatchesDetail(String id) {
Batches obj = this.getById(id); Batches obj = this.getById(id);
if (ObjUtil.isNull(obj)) { if (ObjUtil.isNull(obj)) {
return Result.fail("数据不存在"); return Result.fail("数据不存在");
} }
return Result.data(obj); return Result.data(BatchesWrapper.INSTANCE.toDto(obj));
} }
public Result<Page<Batches>> getBatchesPageList(Page page, BatchesVo vo) { public Result<Page<BatchesDto>> getBatchesPageList(Page page, BatchesVo vo) {
Page paged = this.page(page, new QueryWrapper<Batches>() Page paged = this.page(page, new QueryWrapper<Batches>()
.lambda() .lambda()
.like(StrUtil.isNotBlank(vo.getBatchesCode()), Batches::getBatchesCode, vo.getBatchesCode()) .like(StrUtil.isNotBlank(vo.getBatchesCode()), Batches::getBatchesCode, vo.getBatchesCode())
@ -103,7 +106,12 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
.like(StrUtil.isNotBlank(vo.getBatchesDescription()), Batches::getBatchesDescription, vo.getBatchesDescription()) .like(StrUtil.isNotBlank(vo.getBatchesDescription()), Batches::getBatchesDescription, vo.getBatchesDescription())
.eq(StrUtil.isNotBlank(vo.getMfcId()), Batches::getMfcId, vo.getMfcId()) .eq(StrUtil.isNotBlank(vo.getMfcId()), Batches::getMfcId, vo.getMfcId())
); );
return Result.data(paged); return Result.data(BatchesWrapper.INSTANCE.toDto(paged));
}
public Result<List<BatchesDto>> getBatchesList() {
List<Batches> list = this.list(new QueryWrapper<Batches>());
return Result.data(BatchesWrapper.INSTANCE.toDto(list));
} }
public Result<AttributeValueDto> getAttributeValueDetail(String batchesId) { public Result<AttributeValueDto> getAttributeValueDetail(String batchesId) {

View File

@ -87,7 +87,8 @@ public class MfcService extends BaseService<MfcMapper, Mfc> {
if (ObjUtil.isNull(obj)) { if (ObjUtil.isNull(obj)) {
return Result.fail("数据不存在"); return Result.fail("数据不存在");
} }
BeanUtil.copyProperties(vo, obj); obj.setMfcName(vo.getMfcName());
obj.setMfcDescription(vo.getMfcDescription());
return this.saveOrUpdate(obj) ? Result.success("操作成功") : Result.fail("操作失败"); return this.saveOrUpdate(obj) ? Result.success("操作成功") : Result.fail("操作失败");
} }

View File

@ -1,12 +1,20 @@
package cn.workde.module.drone.coding.service; 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.base.BaseService;
import com.baomidou.mybatisplus.extension.service.IService; import cn.workde.core.data.dto.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.workde.module.drone.coding.mapper.RuleMapper;
import cn.workde.module.drone.coding.entity.Rule; import cn.workde.module.drone.coding.entity.Rule;
import cn.workde.module.drone.coding.mapper.RuleMapper;
import cn.workde.module.drone.coding.vo.RuleVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* 规则管理表(Rule)表服务实现类 * 规则管理表(Rule)表服务实现类
* *
@ -16,5 +24,93 @@ import org.springframework.stereotype.Service;
@Service("ruleService") @Service("ruleService")
public class RuleService extends BaseService<RuleMapper, Rule> { public class RuleService extends BaseService<RuleMapper, Rule> {
private final List<String> codeList = CollUtil.newArrayList("001", "002", "003");
private String check(String id, RuleVo vo) {
vo.setRuleCode(StrUtil.trim(vo.getRuleCode()));
//判断编码唯一性
long count = this.count(new QueryWrapper<Rule>()
.lambda()
.eq(Rule::getRuleCode, vo.getRuleCode())
.ne(StrUtil.isNotBlank(id), Rule::getId, id)
);
if (count > 0) {
return "规则编码已存在";
}
//判断名称唯一性
count = this.count(new QueryWrapper<Rule>()
.lambda()
.eq(Rule::getRuleName, vo.getRuleName())
.ne(StrUtil.isNotBlank(id), Rule::getId, id)
);
if (count > 0) {
return "规则名称已存在";
}
return "";
}
public Result addRule(RuleVo vo) {
String check = check(null, vo);
if (StrUtil.isNotBlank(check)) {
return Result.fail(check);
}
Rule rule = BeanUtil.copyProperties(vo, Rule.class);
return this.saveOrUpdate(rule) ? Result.success("操作成功") : Result.fail("操作失败");
}
public Result editRule(String id, RuleVo vo) {
String check = check(id, vo);
if (StrUtil.isNotBlank(check)) {
return Result.fail(check);
}
Rule rule = getById(id);
if (ObjUtil.isNull(rule)) {
return Result.fail("数据不存在");
}
if (!codeList.contains(rule.getRuleCode())) {
rule.setRuleCode(vo.getRuleCode());
}
rule.setRuleDescription(vo.getRuleDescription());
return this.saveOrUpdate(rule) ? Result.success("操作成功") : Result.fail("操作失败");
}
public Result deleteRule(String id) {
Rule rule = getById(id);
if (ObjUtil.isNull(rule)) {
return Result.fail("数据不存在");
}
if (codeList.contains(rule.getRuleCode())) {
return Result.fail("内置规则,不允许删除");
}
return this.removeById(id) ? Result.success("操作成功") : Result.fail("操作失败");
}
public Result<Rule> getRuleDetail(String id) {
Rule obj = this.getById(id);
if (ObjUtil.isNull(obj)) {
return Result.fail("数据不存在");
}
return Result.data(obj);
}
public Result<Page<Rule>> getRulePageList(Page page, RuleVo vo) {
Page<Rule> paged = this.page(page, new QueryWrapper<Rule>()
.lambda()
.like(StrUtil.isNotBlank(vo.getRuleCode()), Rule::getRuleCode, vo.getRuleCode())
.like(StrUtil.isNotBlank(vo.getRuleName()), Rule::getRuleName, vo.getRuleName())
.like(StrUtil.isNotBlank(vo.getRuleDescription()), Rule::getRuleDescription, vo.getRuleDescription())
);
return Result.data(paged);
}
public Result<List<Rule>> getRuleList() {
List<Rule> list = this.list(new QueryWrapper<Rule>()
);
return Result.data(list);
}
} }

View File

@ -23,8 +23,8 @@ public class BatchesVo {
@NotBlank(message = "请选择所属MFC") @NotBlank(message = "请选择所属MFC")
private String mfcId; private String mfcId;
// @Schema(description = "规则ID") @Schema(description = "规则ID")
// @NotBlank(message = "请选择规则") @NotBlank(message = "请选择规则")
// private String ruleId; private String ruleId;
} }

View File

@ -0,0 +1,19 @@
package cn.workde.module.drone.coding.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
public class RuleVo {
@Schema(description = "规则编码")
@NotBlank(message = "规则编码不能为空")
private String ruleCode;
@Schema(description = "规则名称")
@NotBlank(message = "规则名称不能为空")
private String ruleName;
@Schema(description = "规则描述")
private String ruleDescription;
}

View File

@ -0,0 +1,27 @@
package cn.workde.module.drone.coding.wrapper;
import cn.workde.core.base.BaseWrapper;
import cn.workde.core.util.SpringUtil;
import cn.workde.module.drone.coding.dto.BatchesDto;
import cn.workde.module.drone.coding.entity.Batches;
import cn.workde.module.drone.coding.service.MfcService;
import cn.workde.module.drone.coding.service.RuleService;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
@Mapper
public interface BatchesWrapper extends BaseWrapper<Batches, BatchesDto> {
BatchesWrapper INSTANCE = Mappers.getMapper(BatchesWrapper.class);
@AfterMapping
default void setOtherField(@Param("obj") Batches obj, @MappingTarget @Param("dto") BatchesDto dto) {
MfcService mfcService = SpringUtil.getBean(MfcService.class);
dto.setMfc(mfcService.getById(obj.getMfcId()));
RuleService ruleService = SpringUtil.getBean(RuleService.class);
dto.setRule(ruleService.getById(obj.getRuleId()));
}
}