This commit is contained in:
parent
9f0ac9b075
commit
79d6ec9a5d
@ -0,0 +1,82 @@
|
||||
package tech.riemann.ims.controller.platform.material;
|
||||
|
||||
import club.zhcs.lina.starter.exception.BizException;
|
||||
import club.zhcs.lina.utils.enums.Codebook;
|
||||
import club.zhcs.lina.utils.enums.ICodeBook;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tech.riemann.ims.dto.response.TypeTree;
|
||||
import tech.riemann.ims.entity.material.Type;
|
||||
import tech.riemann.ims.service.material.ITypeService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author mayong
|
||||
* @since 2025/3/2 14:14
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Tag(name = "Type", description = "物料类型管理")
|
||||
@RequiredArgsConstructor
|
||||
public class TypeController {
|
||||
|
||||
private final ITypeService typeService;
|
||||
|
||||
@GetMapping("areas")
|
||||
@Operation(summary = "查询类型")
|
||||
public List<Type> areas(
|
||||
@Parameter(description = "搜索关键词") @RequestParam(required = false, defaultValue = "") String key) {
|
||||
boolean hasLike = Strings.isNotBlank(key);
|
||||
key = String.format("%%%s%%", key);
|
||||
return typeService.list(
|
||||
Wrappers.<Type>lambdaQuery()
|
||||
.like(hasLike, Type::getName, key));
|
||||
}
|
||||
|
||||
@PostMapping("area")
|
||||
@Operation(summary = "增加/更新地区")
|
||||
public Type addAndModify(@Validated @Parameter(description = "类型") @RequestBody Type area) {
|
||||
if (area.getId() == null) {
|
||||
typeService.save(area);
|
||||
} else {
|
||||
typeService.updateById(area);
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
@DeleteMapping("area/{id}")
|
||||
@Operation(summary = "删除类型")
|
||||
public void deleteArea(@Parameter(description = "id", required = true) @PathVariable long id) {
|
||||
if (!typeService.removeById(id)) {
|
||||
throw BizException.create("删除失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("area/levels")
|
||||
@Operation(summary = "级别")
|
||||
public List<Codebook> levels() {
|
||||
return Arrays.stream(Type.Level.values()).map(ICodeBook::build).toList();
|
||||
}
|
||||
|
||||
@GetMapping("area/trees")
|
||||
@Operation(summary = "类型树")
|
||||
public List<TypeTree> trees() {
|
||||
List<Type> all = typeService.list();
|
||||
List<TypeTree> data = all.stream().map(area -> TypeTree.builder()
|
||||
.value(area.getNo())
|
||||
.label(area.getName())
|
||||
.parentNo(area.getParentNo())
|
||||
.build())
|
||||
.toList();
|
||||
return TypeTree.buildTree(data, null);
|
||||
}
|
||||
}
|
36
src/main/java/tech/riemann/ims/dto/response/TypeTree.java
Normal file
36
src/main/java/tech/riemann/ims/dto/response/TypeTree.java
Normal file
@ -0,0 +1,36 @@
|
||||
package tech.riemann.ims.dto.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author mayong
|
||||
* @since 2025/1/18 19:20
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TypeTree {
|
||||
@Schema(description = "类型编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String value;
|
||||
@Schema(description = "类型名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String label;
|
||||
private String parentNo;
|
||||
private List<TypeTree> children;
|
||||
|
||||
|
||||
public static List<TypeTree> buildTree(List<TypeTree> data, String root) {
|
||||
return data.stream()
|
||||
.filter(t -> Objects.equals(t.getParentNo(), root))
|
||||
.peek(t -> t.setChildren(buildTree(data, t.getValue()))).
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
}
|
90
src/main/java/tech/riemann/ims/entity/material/Type.java
Normal file
90
src/main/java/tech/riemann/ims/entity/material/Type.java
Normal file
@ -0,0 +1,90 @@
|
||||
package tech.riemann.ims.entity.material;
|
||||
|
||||
import club.zhcs.lina.utils.enums.Codebook;
|
||||
import club.zhcs.lina.utils.enums.ICodeBook;
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.json.JsonField;
|
||||
import tech.riemann.ims.entity.IdBaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* @author mayong
|
||||
* @since 2025/3/2 14:07
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@FieldNameConstants
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName("t_material")
|
||||
@Table("t_material")
|
||||
@Comment("物料")
|
||||
@Schema(name = "Material", description = "物料")
|
||||
public class Type extends IdBaseEntity {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "类型编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@TableField("a_no")
|
||||
@Column("a_no")
|
||||
@Comment("类型编码")
|
||||
@ColDefine(notNull = true, width = 10, precision = 0)
|
||||
private String no;
|
||||
|
||||
@Schema(description = "类型名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@TableField("a_name")
|
||||
@Column("a_name")
|
||||
@Comment("类型名称")
|
||||
@ColDefine(notNull = true, width = 255, precision = 0)
|
||||
private String name;
|
||||
|
||||
@Schema(description = "类型级别", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@TableField("a_level")
|
||||
@Column("a_level")
|
||||
@Comment("类型级别")
|
||||
@ColDefine(notNull = true, width = 10, precision = 0)
|
||||
private Level level;
|
||||
|
||||
@Schema(description = "上级类型编码", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@TableField("a_parent_no")
|
||||
@Column("a_parent_no")
|
||||
@Comment("上级类型编码")
|
||||
@ColDefine(notNull = false, width = 10, precision = 0)
|
||||
private String parentNo;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Level implements ICodeBook {
|
||||
ONE("town", "一级"),
|
||||
TWO("village", "二级"),
|
||||
;
|
||||
|
||||
@EnumValue
|
||||
final String code;
|
||||
final String description;
|
||||
}
|
||||
|
||||
@JsonGetter
|
||||
@JsonField
|
||||
public Codebook getLevelInfo() {
|
||||
return level == null ? null : level.build();
|
||||
}
|
||||
|
||||
public void setLevelInfo(Codebook areaLevel) {
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package tech.riemann.ims.mapper.material;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import tech.riemann.ims.entity.material.Type;
|
||||
|
||||
/**
|
||||
* @author mayong
|
||||
* @since 2024/11/27 15:42
|
||||
*/
|
||||
public interface TypeMapper extends BaseMapper<Type> {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package tech.riemann.ims.service.material;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nutz.spring.boot.service.interfaces.IdNameEntityService;
|
||||
import tech.riemann.ims.entity.material.Type;
|
||||
|
||||
/**
|
||||
* @author mayong
|
||||
* @since 2024/11/27 15:40
|
||||
*/
|
||||
public interface ITypeService extends IService<Type>, IdNameEntityService<Type> {
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package tech.riemann.ims.service.material.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tech.riemann.ims.entity.material.Type;
|
||||
import tech.riemann.ims.mapper.material.TypeMapper;
|
||||
import tech.riemann.ims.service.material.ITypeService;
|
||||
|
||||
/**
|
||||
* @author mayong
|
||||
* @since 2024/11/27 15:41
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements ITypeService {
|
||||
private final Dao dao;
|
||||
|
||||
@Override
|
||||
public Dao dao() {
|
||||
return dao;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user