mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
✨ ERP:完成 stock 仓库信息的实现
This commit is contained in:
parent
a36ae0c469
commit
b7654eafea
@ -9,6 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
*/
|
||||
public interface ErrorCodeConstants {
|
||||
|
||||
// ========== ERP 仓库 1-030-400-000 ==========
|
||||
ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在");
|
||||
|
||||
// ========== ERP 产品 1-030-500-000 ==========
|
||||
ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");
|
||||
|
||||
|
@ -0,0 +1,106 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehouseRespVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
|
||||
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 jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - ERP 仓库")
|
||||
@RestController
|
||||
@RequestMapping("/erp/warehouse")
|
||||
@Validated
|
||||
public class ErpWarehouseController {
|
||||
|
||||
@Resource
|
||||
private ErpWarehouseService warehouseService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建仓库")
|
||||
@PreAuthorize("@ss.hasPermission('erp:warehouse:create')")
|
||||
public CommonResult<Long> createWarehouse(@Valid @RequestBody ErpWarehouseSaveReqVO createReqVO) {
|
||||
return success(warehouseService.createWarehouse(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新仓库")
|
||||
@PreAuthorize("@ss.hasPermission('erp:warehouse:update')")
|
||||
public CommonResult<Boolean> updateWarehouse(@Valid @RequestBody ErpWarehouseSaveReqVO updateReqVO) {
|
||||
warehouseService.updateWarehouse(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-default-status")
|
||||
@Operation(summary = "更新仓库默认状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "编号", required = true),
|
||||
@Parameter(name = "status", description = "状态", required = true)
|
||||
})
|
||||
public CommonResult<Boolean> updateWarehouseDefaultStatus(@RequestParam("id") Long id,
|
||||
@RequestParam("defaultStatus") Boolean defaultStatus) {
|
||||
warehouseService.updateWarehouseDefaultStatus(id, defaultStatus);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除仓库")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:warehouse:delete')")
|
||||
public CommonResult<Boolean> deleteWarehouse(@RequestParam("id") Long id) {
|
||||
warehouseService.deleteWarehouse(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得仓库")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:warehouse:query')")
|
||||
public CommonResult<ErpWarehouseRespVO> getWarehouse(@RequestParam("id") Long id) {
|
||||
ErpWarehouseDO warehouse = warehouseService.getWarehouse(id);
|
||||
return success(BeanUtils.toBean(warehouse, ErpWarehouseRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得仓库分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:warehouse:query')")
|
||||
public CommonResult<PageResult<ErpWarehouseRespVO>> getWarehousePage(@Valid ErpWarehousePageReqVO pageReqVO) {
|
||||
PageResult<ErpWarehouseDO> pageResult = warehouseService.getWarehousePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ErpWarehouseRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出仓库 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:warehouse:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportWarehouseExcel(@Valid ErpWarehousePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ErpWarehouseDO> list = warehouseService.getWarehousePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "仓库.xls", "数据", ErpWarehouseRespVO.class,
|
||||
BeanUtils.toBean(list, ErpWarehouseRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 仓库分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ErpWarehousePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "仓库名称", example = "李四")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "开启状态", example = "1")
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 仓库 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ErpWarehouseRespVO {
|
||||
|
||||
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11614")
|
||||
@ExcelProperty("仓库编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@ExcelProperty("仓库名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "仓库地址", example = "上海陆家嘴")
|
||||
@ExcelProperty("仓库地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@ExcelProperty("排序")
|
||||
private Long sort;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "负责人", example = "芋头")
|
||||
@ExcelProperty("负责人")
|
||||
private String principal;
|
||||
|
||||
@Schema(description = "仓储费,单位:元", example = "13973")
|
||||
@ExcelProperty("仓储费,单位:元")
|
||||
private BigDecimal warehousePrice;
|
||||
|
||||
@Schema(description = "搬运费,单位:元", example = "9903")
|
||||
@ExcelProperty("搬运费,单位:元")
|
||||
private BigDecimal truckagePrice;
|
||||
|
||||
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "开启状态", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.COMMON_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "是否默认", example = "1")
|
||||
@ExcelProperty("是否默认")
|
||||
private Boolean defaultStatus;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 仓库新增/修改 Request VO")
|
||||
@Data
|
||||
public class ErpWarehouseSaveReqVO {
|
||||
|
||||
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11614")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@NotEmpty(message = "仓库名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "仓库地址", example = "上海陆家嘴")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@NotNull(message = "排序不能为空")
|
||||
private Long sort;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "负责人", example = "芋头")
|
||||
private String principal;
|
||||
|
||||
@Schema(description = "仓储费,单位:元", example = "13973")
|
||||
private BigDecimal warehousePrice;
|
||||
|
||||
@Schema(description = "搬运费,单位:元", example = "9903")
|
||||
private BigDecimal truckagePrice;
|
||||
|
||||
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "开启状态不能为空")
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* ERP 仓库 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("erp_warehouse")
|
||||
@KeySequence("erp_warehouse_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpWarehouseDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 仓库编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 仓库名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 仓库地址
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Long sort;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 负责人
|
||||
*/
|
||||
private String principal;
|
||||
/**
|
||||
* 仓储费,单位:元
|
||||
*/
|
||||
private BigDecimal warehousePrice;
|
||||
/**
|
||||
* 搬运费,单位:元
|
||||
*/
|
||||
private BigDecimal truckagePrice;
|
||||
/**
|
||||
* 开启状态
|
||||
*
|
||||
* 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 是否默认
|
||||
*/
|
||||
private Boolean defaultStatus;
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* ERP 仓库 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpWarehouseMapper extends BaseMapperX<ErpWarehouseDO> {
|
||||
|
||||
default PageResult<ErpWarehouseDO> selectPage(ErpWarehousePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ErpWarehouseDO>()
|
||||
.likeIfPresent(ErpWarehouseDO::getName, reqVO.getName())
|
||||
.eqIfPresent(ErpWarehouseDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(ErpWarehouseDO::getId));
|
||||
}
|
||||
|
||||
default ErpWarehouseDO selectByDefaultStatus() {
|
||||
return selectOne(ErpWarehouseDO::getDefaultStatus, true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* ERP 仓库 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ErpWarehouseService {
|
||||
|
||||
/**
|
||||
* 创建仓库
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createWarehouse(@Valid ErpWarehouseSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新ERP 仓库
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateWarehouse(@Valid ErpWarehouseSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新仓库默认状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param defaultStatus 默认状态
|
||||
*/
|
||||
void updateWarehouseDefaultStatus(Long id, Boolean defaultStatus);
|
||||
|
||||
/**
|
||||
* 删除仓库
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteWarehouse(Long id);
|
||||
|
||||
/**
|
||||
* 获得仓库
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 仓库
|
||||
*/
|
||||
ErpWarehouseDO getWarehouse(Long id);
|
||||
|
||||
/**
|
||||
* 获得仓库分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 仓库分页
|
||||
*/
|
||||
PageResult<ErpWarehouseDO> getWarehousePage(ErpWarehousePageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* ERP 仓库 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ErpWarehouseServiceImpl implements ErpWarehouseService {
|
||||
|
||||
@Resource
|
||||
private ErpWarehouseMapper warehouseMapper;
|
||||
|
||||
@Override
|
||||
public Long createWarehouse(ErpWarehouseSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ErpWarehouseDO warehouse = BeanUtils.toBean(createReqVO, ErpWarehouseDO.class);
|
||||
warehouseMapper.insert(warehouse);
|
||||
// 返回
|
||||
return warehouse.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWarehouse(ErpWarehouseSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateWarehouseExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ErpWarehouseDO updateObj = BeanUtils.toBean(updateReqVO, ErpWarehouseDO.class);
|
||||
warehouseMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateWarehouseDefaultStatus(Long id, Boolean defaultStatus) {
|
||||
// 1. 校验存在
|
||||
validateWarehouseExists(id);
|
||||
|
||||
// 2.1 如果开启,则需要关闭所有其它的默认
|
||||
if (defaultStatus) {
|
||||
ErpWarehouseDO warehouse = warehouseMapper.selectByDefaultStatus();
|
||||
if (warehouse != null) {
|
||||
warehouseMapper.updateById(new ErpWarehouseDO().setId(warehouse.getId()).setDefaultStatus(false));
|
||||
}
|
||||
}
|
||||
// 2.2 更新对应的默认状态
|
||||
warehouseMapper.updateById(new ErpWarehouseDO().setId(id).setDefaultStatus(defaultStatus));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWarehouse(Long id) {
|
||||
// 校验存在
|
||||
validateWarehouseExists(id);
|
||||
// 删除
|
||||
warehouseMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateWarehouseExists(Long id) {
|
||||
if (warehouseMapper.selectById(id) == null) {
|
||||
throw exception(WAREHOUSE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpWarehouseDO getWarehouse(Long id) {
|
||||
return warehouseMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpWarehouseDO> getWarehousePage(ErpWarehousePageReqVO pageReqVO) {
|
||||
return warehouseMapper.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.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -0,0 +1,126 @@
|
||||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehouseSaveReqVO;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link ErpWarehouseServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(ErpWarehouseServiceImpl.class)
|
||||
public class ErpWarehouseServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ErpWarehouseServiceImpl warehouseService;
|
||||
|
||||
@Resource
|
||||
private ErpWarehouseMapper warehouseMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateWarehouse_success() {
|
||||
// 准备参数
|
||||
ErpWarehouseSaveReqVO createReqVO = randomPojo(ErpWarehouseSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long warehouseId = warehouseService.createWarehouse(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(warehouseId);
|
||||
// 校验记录的属性是否正确
|
||||
ErpWarehouseDO warehouse = warehouseMapper.selectById(warehouseId);
|
||||
assertPojoEquals(createReqVO, warehouse, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWarehouse_success() {
|
||||
// mock 数据
|
||||
ErpWarehouseDO dbWarehouse = randomPojo(ErpWarehouseDO.class);
|
||||
warehouseMapper.insert(dbWarehouse);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
ErpWarehouseSaveReqVO updateReqVO = randomPojo(ErpWarehouseSaveReqVO.class, o -> {
|
||||
o.setId(dbWarehouse.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
warehouseService.updateWarehouse(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
ErpWarehouseDO warehouse = warehouseMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, warehouse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWarehouse_notExists() {
|
||||
// 准备参数
|
||||
ErpWarehouseSaveReqVO updateReqVO = randomPojo(ErpWarehouseSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> warehouseService.updateWarehouse(updateReqVO), WAREHOUSE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteWarehouse_success() {
|
||||
// mock 数据
|
||||
ErpWarehouseDO dbWarehouse = randomPojo(ErpWarehouseDO.class);
|
||||
warehouseMapper.insert(dbWarehouse);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbWarehouse.getId();
|
||||
|
||||
// 调用
|
||||
warehouseService.deleteWarehouse(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(warehouseMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteWarehouse_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> warehouseService.deleteWarehouse(id), WAREHOUSE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetWarehousePage() {
|
||||
// mock 数据
|
||||
ErpWarehouseDO dbWarehouse = randomPojo(ErpWarehouseDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setStatus(null);
|
||||
});
|
||||
warehouseMapper.insert(dbWarehouse);
|
||||
// 测试 name 不匹配
|
||||
warehouseMapper.insert(cloneIgnoreId(dbWarehouse, o -> o.setName(null)));
|
||||
// 测试 status 不匹配
|
||||
warehouseMapper.insert(cloneIgnoreId(dbWarehouse, o -> o.setStatus(null)));
|
||||
// 准备参数
|
||||
ErpWarehousePageReqVO reqVO = new ErpWarehousePageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setStatus(null);
|
||||
|
||||
// 调用
|
||||
PageResult<ErpWarehouseDO> pageResult = warehouseService.getWarehousePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbWarehouse, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user