feat: 木箱类型crud
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package cn.code.nl.module.lms.controller.admin.boxtype;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.code.nl.framework.common.pojo.PageParam;
|
||||
import cn.code.nl.framework.common.pojo.PageResult;
|
||||
import cn.code.nl.framework.common.pojo.CommonResult;
|
||||
import cn.code.nl.framework.common.util.object.BeanUtils;
|
||||
import static cn.code.nl.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.code.nl.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.code.nl.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.code.nl.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.code.nl.module.lms.controller.admin.boxtype.vo.*;
|
||||
import cn.code.nl.module.lms.dal.dataobject.boxtype.BoxTypeDO;
|
||||
import cn.code.nl.module.lms.service.boxtype.BoxTypeService;
|
||||
|
||||
@Tag(name = "管理后台 - 木箱类型")
|
||||
@RestController
|
||||
@RequestMapping("/lms/box-type")
|
||||
@Validated
|
||||
public class BoxTypeController {
|
||||
|
||||
@Resource
|
||||
private BoxTypeService boxTypeService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建木箱类型")
|
||||
@PreAuthorize("@ss.hasPermission('lms:box-type:create')")
|
||||
public CommonResult<Long> createBoxType(@Valid @RequestBody BoxTypeSaveReqVO createReqVO) {
|
||||
return success(boxTypeService.createBoxType(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新木箱类型")
|
||||
@PreAuthorize("@ss.hasPermission('lms:box-type:update')")
|
||||
public CommonResult<Boolean> updateBoxType(@Valid @RequestBody BoxTypeSaveReqVO updateReqVO) {
|
||||
boxTypeService.updateBoxType(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除木箱类型")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('lms:box-type:delete')")
|
||||
public CommonResult<Boolean> deleteBoxType(@RequestParam("id") String id) {
|
||||
boxTypeService.deleteBoxType(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除木箱类型")
|
||||
@PreAuthorize("@ss.hasPermission('lms:box-type:delete')")
|
||||
public CommonResult<Boolean> deleteBoxTypeList(@RequestParam("ids") List<String> ids) {
|
||||
boxTypeService.deleteBoxTypeListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得木箱类型")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('lms:box-type:query')")
|
||||
public CommonResult<BoxTypeRespVO> getBoxType(@RequestParam("id") String id) {
|
||||
BoxTypeDO boxType = boxTypeService.getBoxType(id);
|
||||
return success(BeanUtils.toBean(boxType, BoxTypeRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得木箱类型分页")
|
||||
@PreAuthorize("@ss.hasPermission('lms:box-type:query')")
|
||||
public CommonResult<PageResult<BoxTypeRespVO>> getBoxTypePage(@Valid BoxTypePageReqVO pageReqVO) {
|
||||
PageResult<BoxTypeDO> pageResult = boxTypeService.getBoxTypePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, BoxTypeRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出木箱类型 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('lms:box-type:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportBoxTypeExcel(@Valid BoxTypePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<BoxTypeDO> list = boxTypeService.getBoxTypePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "木箱类型.xls", "数据", BoxTypeRespVO.class,
|
||||
BeanUtils.toBean(list, BoxTypeRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.code.nl.module.lms.controller.admin.boxtype.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.code.nl.framework.common.pojo.PageParam;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 木箱类型分页 Request VO")
|
||||
@Data
|
||||
public class BoxTypePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "木箱类型", example = "2")
|
||||
private String boxType;
|
||||
|
||||
@Schema(description = "木箱描述", example = "张三")
|
||||
private String boxName;
|
||||
|
||||
@Schema(description = "是否一次捆扎")
|
||||
private Boolean needLashOne;
|
||||
|
||||
@Schema(description = "是否二次捆扎")
|
||||
private Boolean needLashTwo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.code.nl.module.lms.controller.admin.boxtype.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import cn.idev.excel.annotation.*;
|
||||
import cn.code.nl.framework.excel.core.annotations.DictFormat;
|
||||
import cn.code.nl.framework.excel.core.convert.DictConvert;
|
||||
|
||||
@Schema(description = "管理后台 - 木箱类型 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class BoxTypeRespVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "木箱类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("木箱类型")
|
||||
private String boxType;
|
||||
|
||||
@Schema(description = "木箱描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
@ExcelProperty("木箱描述")
|
||||
private String boxName;
|
||||
|
||||
@Schema(description = "捆扎模版")
|
||||
@ExcelProperty("捆扎模版")
|
||||
private String lashNum;
|
||||
|
||||
@Schema(description = "一次捆扎次数")
|
||||
@ExcelProperty("一次捆扎次数")
|
||||
private Integer lashNumOne;
|
||||
|
||||
@Schema(description = "二次捆扎次数")
|
||||
@ExcelProperty("二次捆扎次数")
|
||||
private Integer lashNumTwo;
|
||||
|
||||
@Schema(description = "是否一次捆扎")
|
||||
@ExcelProperty(value = "是否一次捆扎", converter = DictConvert.class)
|
||||
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Boolean needLashOne;
|
||||
|
||||
@Schema(description = "是否二次捆扎")
|
||||
@ExcelProperty(value = "是否二次捆扎", converter = DictConvert.class)
|
||||
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Boolean needLashTwo;
|
||||
|
||||
@Schema(description = "叉车取货宽度")
|
||||
@ExcelProperty("叉车取货宽度")
|
||||
private BigDecimal expendWidth;
|
||||
|
||||
@Schema(description = "木箱结构")
|
||||
@ExcelProperty("木箱结构")
|
||||
private String boxStructure;
|
||||
|
||||
@Schema(description = "干燥剂数量", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("干燥剂数量")
|
||||
private Integer desiccantNum;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.code.nl.module.lms.controller.admin.boxtype.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 木箱类型新增/修改 Request VO")
|
||||
@Data
|
||||
public class BoxTypeSaveReqVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "木箱类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private String boxType;
|
||||
@Schema(description = "木箱描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private String boxName;
|
||||
|
||||
@Schema(description = "捆扎模版")
|
||||
private String lashNum;
|
||||
|
||||
@Schema(description = "一次捆扎次数")
|
||||
private Integer lashNumOne;
|
||||
|
||||
@Schema(description = "二次捆扎次数")
|
||||
private Integer lashNumTwo;
|
||||
|
||||
@Schema(description = "是否一次捆扎")
|
||||
private Boolean needLashOne;
|
||||
|
||||
@Schema(description = "是否二次捆扎")
|
||||
private Boolean needLashTwo;
|
||||
|
||||
@Schema(description = "叉车取货宽度")
|
||||
private BigDecimal expendWidth;
|
||||
|
||||
@Schema(description = "木箱结构")
|
||||
private String boxStructure;
|
||||
|
||||
@Schema(description = "干燥剂数量", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "干燥剂数量不能为空")
|
||||
private Integer desiccantNum;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package cn.code.nl.module.lms.dal.dataobject.boxtype;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 木箱类型 DO
|
||||
*
|
||||
* @author 诺力管理员
|
||||
*/
|
||||
@TableName("lms_box_type")
|
||||
@KeySequence("lms_box_type_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BoxTypeDO {
|
||||
|
||||
/**
|
||||
* 木箱类型id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 木箱类型
|
||||
*/
|
||||
private String boxType;
|
||||
/**
|
||||
* 木箱描述
|
||||
*/
|
||||
private String boxName;
|
||||
/**
|
||||
* 捆扎模版
|
||||
*/
|
||||
private String lashNum;
|
||||
/**
|
||||
* 一次捆扎次数
|
||||
*/
|
||||
private Integer lashNumOne;
|
||||
/**
|
||||
* 二次捆扎次数
|
||||
*/
|
||||
private Integer lashNumTwo;
|
||||
/**
|
||||
* 是否一次捆扎
|
||||
*
|
||||
* 枚举 {@link TODO infra_boolean_string 对应的类}
|
||||
*/
|
||||
private Boolean needLashOne;
|
||||
/**
|
||||
* 是否二次捆扎
|
||||
*
|
||||
* 枚举 {@link TODO infra_boolean_string 对应的类}
|
||||
*/
|
||||
private Boolean needLashTwo;
|
||||
/**
|
||||
* 叉车取货宽度
|
||||
*/
|
||||
private BigDecimal expendWidth;
|
||||
/**
|
||||
* 木箱结构
|
||||
*/
|
||||
private String boxStructure;
|
||||
/**
|
||||
* 干燥剂数量
|
||||
*/
|
||||
private Integer desiccantNum;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.code.nl.module.lms.dal.mysql.boxtype;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.code.nl.framework.common.pojo.PageResult;
|
||||
import cn.code.nl.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.code.nl.module.lms.dal.dataobject.boxtype.BoxTypeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.code.nl.module.lms.controller.admin.boxtype.vo.*;
|
||||
|
||||
/**
|
||||
* 木箱类型 Mapper
|
||||
*
|
||||
* @author 诺力管理员
|
||||
*/
|
||||
@Mapper
|
||||
public interface BoxTypeMapper extends BaseMapperX<BoxTypeDO> {
|
||||
|
||||
default PageResult<BoxTypeDO> selectPage(BoxTypePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<BoxTypeDO>()
|
||||
.eqIfPresent(BoxTypeDO::getBoxType, reqVO.getBoxType())
|
||||
.likeIfPresent(BoxTypeDO::getBoxName, reqVO.getBoxName())
|
||||
.eqIfPresent(BoxTypeDO::getNeedLashOne, reqVO.getNeedLashOne())
|
||||
.eqIfPresent(BoxTypeDO::getNeedLashTwo, reqVO.getNeedLashTwo())
|
||||
.orderByDesc(BoxTypeDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.code.nl.module.lms.service.boxtype;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import cn.code.nl.module.lms.controller.admin.boxtype.vo.*;
|
||||
import cn.code.nl.module.lms.dal.dataobject.boxtype.BoxTypeDO;
|
||||
import cn.code.nl.framework.common.pojo.PageResult;
|
||||
import cn.code.nl.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 木箱类型 Service 接口
|
||||
*
|
||||
* @author 诺力管理员
|
||||
*/
|
||||
public interface BoxTypeService {
|
||||
|
||||
/**
|
||||
* 创建木箱类型
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createBoxType(@Valid BoxTypeSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新木箱类型
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateBoxType(@Valid BoxTypeSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除木箱类型
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteBoxType(String id);
|
||||
|
||||
/**
|
||||
* 批量删除木箱类型
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteBoxTypeListByIds(List<String> ids);
|
||||
|
||||
/**
|
||||
* 获得木箱类型
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 木箱类型
|
||||
*/
|
||||
BoxTypeDO getBoxType(String id);
|
||||
|
||||
/**
|
||||
* 获得木箱类型分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 木箱类型分页
|
||||
*/
|
||||
PageResult<BoxTypeDO> getBoxTypePage(BoxTypePageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package cn.code.nl.module.lms.service.boxtype;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.code.nl.module.lms.controller.admin.boxtype.vo.*;
|
||||
import cn.code.nl.module.lms.dal.dataobject.boxtype.BoxTypeDO;
|
||||
import cn.code.nl.framework.common.pojo.PageResult;
|
||||
import cn.code.nl.framework.common.pojo.PageParam;
|
||||
import cn.code.nl.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.code.nl.module.lms.dal.mysql.boxtype.BoxTypeMapper;
|
||||
|
||||
import static cn.code.nl.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.code.nl.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.code.nl.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 木箱类型 Service 实现类
|
||||
*
|
||||
* @author 诺力管理员
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class BoxTypeServiceImpl implements BoxTypeService {
|
||||
|
||||
@Resource
|
||||
private BoxTypeMapper boxTypeMapper;
|
||||
|
||||
@Override
|
||||
public Long createBoxType(BoxTypeSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
BoxTypeDO boxType = BeanUtils.toBean(createReqVO, BoxTypeDO.class);
|
||||
boxTypeMapper.insert(boxType);
|
||||
|
||||
// 返回
|
||||
return boxType.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBoxType(BoxTypeSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateBoxTypeExists(String.valueOf(updateReqVO.getId()));
|
||||
// 更新
|
||||
BoxTypeDO updateObj = BeanUtils.toBean(updateReqVO, BoxTypeDO.class);
|
||||
boxTypeMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBoxType(String id) {
|
||||
// 校验存在
|
||||
validateBoxTypeExists(id);
|
||||
// 删除
|
||||
boxTypeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBoxTypeListByIds(List<String> ids) {
|
||||
// 删除
|
||||
boxTypeMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateBoxTypeExists(String id) {
|
||||
if (boxTypeMapper.selectById(id) == null) {
|
||||
throw exception(BOX_TYPE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoxTypeDO getBoxType(String id) {
|
||||
return boxTypeMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<BoxTypeDO> getBoxTypePage(BoxTypePageReqVO pageReqVO) {
|
||||
return boxTypeMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.code.nl.module.lms.dal.mysql.boxtype.BoxTypeMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user