办公用品信息
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
This commit is contained in:
parent
4b26bb6491
commit
3cc7b76996
@ -40,4 +40,6 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode DRIVER_NOT_EXISTS = new ErrorCode(1_011_014_000, "驾驶员信息不存在");
|
ErrorCode DRIVER_NOT_EXISTS = new ErrorCode(1_011_014_000, "驾驶员信息不存在");
|
||||||
// ========== 项目管理 1_011_015_000 ==========
|
// ========== 项目管理 1_011_015_000 ==========
|
||||||
ErrorCode PROJECT_NOT_EXISTS = new ErrorCode(1_011_015_000, "项目管理不存在");
|
ErrorCode PROJECT_NOT_EXISTS = new ErrorCode(1_011_015_000, "项目管理不存在");
|
||||||
|
// ========== 办公用品信息 1_011_015_000 ==========
|
||||||
|
ErrorCode ITEMS_NOT_EXISTS = new ErrorCode(1_011_015_000,"办公用品管理不存在");
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.items;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import javax.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 javax.validation.constraints.*;
|
||||||
|
import javax.validation.*;
|
||||||
|
import javax.servlet.http.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.items.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.items.ItemsDO;
|
||||||
|
import cn.iocoder.yudao.module.home.service.items.ItemsService;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 办公用品信息")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/home/items")
|
||||||
|
@Validated
|
||||||
|
public class ItemsController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ItemsService itemsService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建办公用品信息")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:items:create')")
|
||||||
|
public CommonResult<Long> createItems(@Valid @RequestBody ItemsSaveReqVO createReqVO) {
|
||||||
|
return success(itemsService.createItems(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新办公用品信息")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:items:update')")
|
||||||
|
public CommonResult<Boolean> updateItems(@Valid @RequestBody ItemsSaveReqVO updateReqVO) {
|
||||||
|
itemsService.updateItems(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除办公用品信息")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:items:delete')")
|
||||||
|
public CommonResult<Boolean> deleteItems(@RequestParam("id") Long id) {
|
||||||
|
itemsService.deleteItems(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得办公用品信息")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:items:query')")
|
||||||
|
public CommonResult<ItemsRespVO> getItems(@RequestParam("id") Long id) {
|
||||||
|
ItemsDO items = itemsService.getItems(id);
|
||||||
|
return success(BeanUtils.toBean(items, ItemsRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得办公用品信息分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:items:query')")
|
||||||
|
public CommonResult<PageResult<ItemsRespVO>> getItemsPage(@Valid ItemsPageReqVO pageReqVO) {
|
||||||
|
PageResult<ItemsDO> pageResult = itemsService.getItemsPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, ItemsRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出办公用品信息 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('home:items:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportItemsExcel(@Valid ItemsPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<ItemsDO> list = itemsService.getItemsPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "办公用品信息.xls", "数据", ItemsRespVO.class,
|
||||||
|
BeanUtils.toBean(list, ItemsRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.items.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 办公用品信息分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class ItemsPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "id", example = "21872")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "物品名字", example = "赵六")
|
||||||
|
private String itemName;
|
||||||
|
|
||||||
|
@Schema(description = "物品分类", example = "8853")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@Schema(description = "物品状态", example = "1")
|
||||||
|
private String itemStatus;
|
||||||
|
|
||||||
|
@Schema(description = "库存数量")
|
||||||
|
private String stockQuantity;
|
||||||
|
|
||||||
|
@Schema(description = "单价", example = "3612")
|
||||||
|
private Integer unitPrice;
|
||||||
|
|
||||||
|
@Schema(description = "入库时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] stockDate;
|
||||||
|
|
||||||
|
@Schema(description = "详细描述", example = "你说的对")
|
||||||
|
private String itemDescription;
|
||||||
|
|
||||||
|
@Schema(description = "单位")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@Schema(description = "备注")
|
||||||
|
private String remarks;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.items.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 办公用品信息 Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class ItemsRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "21872")
|
||||||
|
@ExcelProperty("id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "物品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||||
|
@ExcelProperty("物品名字")
|
||||||
|
private String itemName;
|
||||||
|
|
||||||
|
@Schema(description = "物品分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "8853")
|
||||||
|
@ExcelProperty(value = "物品分类", converter = DictConvert.class)
|
||||||
|
@DictFormat("bgyp_unit") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@Schema(description = "物品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@ExcelProperty(value = "物品状态", converter = DictConvert.class)
|
||||||
|
@DictFormat("driver_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
private String itemStatus;
|
||||||
|
|
||||||
|
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("库存数量")
|
||||||
|
private String stockQuantity;
|
||||||
|
|
||||||
|
@Schema(description = "单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "3612")
|
||||||
|
@ExcelProperty("单价")
|
||||||
|
private Integer unitPrice;
|
||||||
|
|
||||||
|
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("入库时间")
|
||||||
|
private LocalDateTime stockDate;
|
||||||
|
|
||||||
|
@Schema(description = "详细描述", example = "你说的对")
|
||||||
|
@ExcelProperty("详细描述")
|
||||||
|
private String itemDescription;
|
||||||
|
|
||||||
|
@Schema(description = "单位")
|
||||||
|
@ExcelProperty("单位")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@Schema(description = "备注")
|
||||||
|
@ExcelProperty("备注")
|
||||||
|
private String remarks;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.controller.admin.items.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 办公用品信息新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class ItemsSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "21872")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "物品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||||
|
@NotEmpty(message = "物品名字不能为空")
|
||||||
|
private String itemName;
|
||||||
|
|
||||||
|
@Schema(description = "物品分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "8853")
|
||||||
|
@NotNull(message = "物品分类不能为空")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@Schema(description = "物品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotEmpty(message = "物品状态不能为空")
|
||||||
|
private String itemStatus;
|
||||||
|
|
||||||
|
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "库存数量不能为空")
|
||||||
|
private String stockQuantity;
|
||||||
|
|
||||||
|
@Schema(description = "单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "3612")
|
||||||
|
@NotNull(message = "单价不能为空")
|
||||||
|
private Integer unitPrice;
|
||||||
|
|
||||||
|
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "入库时间不能为空")
|
||||||
|
private LocalDateTime stockDate;
|
||||||
|
|
||||||
|
@Schema(description = "详细描述", example = "你说的对")
|
||||||
|
private String itemDescription;
|
||||||
|
|
||||||
|
@Schema(description = "单位")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@Schema(description = "备注")
|
||||||
|
private String remarks;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.dal.dataobject.items;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 办公用品信息 DO
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@TableName("oa_items")
|
||||||
|
@KeySequence("oa_items_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ItemsDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 物品名字
|
||||||
|
*/
|
||||||
|
private String itemName;
|
||||||
|
/**
|
||||||
|
* 物品分类
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO bgyp_unit 对应的类}
|
||||||
|
*/
|
||||||
|
private Integer categoryId;
|
||||||
|
/**
|
||||||
|
* 物品状态
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO driver_status 对应的类}
|
||||||
|
*/
|
||||||
|
private String itemStatus;
|
||||||
|
/**
|
||||||
|
* 库存数量
|
||||||
|
*/
|
||||||
|
private String stockQuantity;
|
||||||
|
/**
|
||||||
|
* 单价
|
||||||
|
*/
|
||||||
|
private Integer unitPrice;
|
||||||
|
/**
|
||||||
|
* 入库时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime stockDate;
|
||||||
|
/**
|
||||||
|
* 详细描述
|
||||||
|
*/
|
||||||
|
private String itemDescription;
|
||||||
|
/**
|
||||||
|
* 单位
|
||||||
|
*/
|
||||||
|
private String unit;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remarks;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.dal.mysql.items;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
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.home.dal.dataobject.items.ItemsDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.items.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 办公用品信息 Mapper
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ItemsMapper extends BaseMapperX<ItemsDO> {
|
||||||
|
|
||||||
|
default PageResult<ItemsDO> selectPage(ItemsPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<ItemsDO>()
|
||||||
|
.eqIfPresent(ItemsDO::getId, reqVO.getId())
|
||||||
|
.likeIfPresent(ItemsDO::getItemName, reqVO.getItemName())
|
||||||
|
.eqIfPresent(ItemsDO::getCategoryId, reqVO.getCategoryId())
|
||||||
|
.eqIfPresent(ItemsDO::getItemStatus, reqVO.getItemStatus())
|
||||||
|
.eqIfPresent(ItemsDO::getStockQuantity, reqVO.getStockQuantity())
|
||||||
|
.eqIfPresent(ItemsDO::getUnitPrice, reqVO.getUnitPrice())
|
||||||
|
.betweenIfPresent(ItemsDO::getStockDate, reqVO.getStockDate())
|
||||||
|
.eqIfPresent(ItemsDO::getItemDescription, reqVO.getItemDescription())
|
||||||
|
.eqIfPresent(ItemsDO::getUnit, reqVO.getUnit())
|
||||||
|
.eqIfPresent(ItemsDO::getRemarks, reqVO.getRemarks())
|
||||||
|
.betweenIfPresent(ItemsDO::getCreateTime, reqVO.getCreateTime())
|
||||||
|
.orderByDesc(ItemsDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.items;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import javax.validation.*;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.items.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.items.ItemsDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 办公用品信息 Service 接口
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
public interface ItemsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建办公用品信息
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createItems(@Valid ItemsSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新办公用品信息
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateItems(@Valid ItemsSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除办公用品信息
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteItems(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得办公用品信息
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 办公用品信息
|
||||||
|
*/
|
||||||
|
ItemsDO getItems(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得办公用品信息分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 办公用品信息分页
|
||||||
|
*/
|
||||||
|
PageResult<ItemsDO> getItemsPage(ItemsPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.items;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.items.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.items.ItemsDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.home.dal.mysql.items.ItemsMapper;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.home.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 办公用品信息 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ItemsServiceImpl implements ItemsService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ItemsMapper itemsMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createItems(ItemsSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
ItemsDO items = BeanUtils.toBean(createReqVO, ItemsDO.class);
|
||||||
|
itemsMapper.insert(items);
|
||||||
|
// 返回
|
||||||
|
return items.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateItems(ItemsSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateItemsExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
ItemsDO updateObj = BeanUtils.toBean(updateReqVO, ItemsDO.class);
|
||||||
|
itemsMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteItems(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateItemsExists(id);
|
||||||
|
// 删除
|
||||||
|
itemsMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateItemsExists(Long id) {
|
||||||
|
if (itemsMapper.selectById(id) == null) {
|
||||||
|
throw exception(ITEMS_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemsDO getItems(Long id) {
|
||||||
|
return itemsMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<ItemsDO> getItemsPage(ItemsPageReqVO pageReqVO) {
|
||||||
|
return itemsMapper.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.home.dal.mysql.items.ItemsMapper">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||||
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||||
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
|
-->
|
||||||
|
|
||||||
|
</mapper>
|
@ -0,0 +1,170 @@
|
|||||||
|
package cn.iocoder.yudao.module.home.service.items;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.home.controller.admin.items.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.dataobject.items.ItemsDO;
|
||||||
|
import cn.iocoder.yudao.module.home.dal.mysql.items.ItemsMapper;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.RandomUtil.*;
|
||||||
|
import static cn.iocoder.yudao.module.home.enums.ErrorCodeConstants.*;
|
||||||
|
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.date.LocalDateTimeUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ItemsServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 君风
|
||||||
|
*/
|
||||||
|
@Import(ItemsServiceImpl.class)
|
||||||
|
public class ItemsServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ItemsServiceImpl itemsService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ItemsMapper itemsMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateItems_success() {
|
||||||
|
// 准备参数
|
||||||
|
ItemsSaveReqVO createReqVO = randomPojo(ItemsSaveReqVO.class).setId(null);
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long itemsId = itemsService.createItems(createReqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(itemsId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
ItemsDO items = itemsMapper.selectById(itemsId);
|
||||||
|
assertPojoEquals(createReqVO, items, "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateItems_success() {
|
||||||
|
// mock 数据
|
||||||
|
ItemsDO dbItems = randomPojo(ItemsDO.class);
|
||||||
|
itemsMapper.insert(dbItems);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
ItemsSaveReqVO updateReqVO = randomPojo(ItemsSaveReqVO.class, o -> {
|
||||||
|
o.setId(dbItems.getId()); // 设置更新的 ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
itemsService.updateItems(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
ItemsDO items = itemsMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(updateReqVO, items);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateItems_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
ItemsSaveReqVO updateReqVO = randomPojo(ItemsSaveReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> itemsService.updateItems(updateReqVO), ITEMS_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteItems_success() {
|
||||||
|
// mock 数据
|
||||||
|
ItemsDO dbItems = randomPojo(ItemsDO.class);
|
||||||
|
itemsMapper.insert(dbItems);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbItems.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
itemsService.deleteItems(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(itemsMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteItems_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> itemsService.deleteItems(id), ITEMS_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||||
|
public void testGetItemsPage() {
|
||||||
|
// mock 数据
|
||||||
|
ItemsDO dbItems = randomPojo(ItemsDO.class, o -> { // 等会查询到
|
||||||
|
o.setId(null);
|
||||||
|
o.setItemName(null);
|
||||||
|
o.setCategoryId(null);
|
||||||
|
o.setItemStatus(null);
|
||||||
|
o.setStockQuantity(null);
|
||||||
|
o.setUnitPrice(null);
|
||||||
|
o.setStockDate(null);
|
||||||
|
o.setItemDescription(null);
|
||||||
|
o.setUnit(null);
|
||||||
|
o.setRemarks(null);
|
||||||
|
o.setCreateTime(null);
|
||||||
|
});
|
||||||
|
itemsMapper.insert(dbItems);
|
||||||
|
// 测试 id 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setId(null)));
|
||||||
|
// 测试 itemName 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setItemName(null)));
|
||||||
|
// 测试 categoryId 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setCategoryId(null)));
|
||||||
|
// 测试 itemStatus 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setItemStatus(null)));
|
||||||
|
// 测试 stockQuantity 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setStockQuantity(null)));
|
||||||
|
// 测试 unitPrice 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setUnitPrice(null)));
|
||||||
|
// 测试 stockDate 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setStockDate(null)));
|
||||||
|
// 测试 itemDescription 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setItemDescription(null)));
|
||||||
|
// 测试 unit 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setUnit(null)));
|
||||||
|
// 测试 remarks 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setRemarks(null)));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
itemsMapper.insert(cloneIgnoreId(dbItems, o -> o.setCreateTime(null)));
|
||||||
|
// 准备参数
|
||||||
|
ItemsPageReqVO reqVO = new ItemsPageReqVO();
|
||||||
|
reqVO.setId(null);
|
||||||
|
reqVO.setItemName(null);
|
||||||
|
reqVO.setCategoryId(null);
|
||||||
|
reqVO.setItemStatus(null);
|
||||||
|
reqVO.setStockQuantity(null);
|
||||||
|
reqVO.setUnitPrice(null);
|
||||||
|
reqVO.setStockDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
reqVO.setItemDescription(null);
|
||||||
|
reqVO.setUnit(null);
|
||||||
|
reqVO.setRemarks(null);
|
||||||
|
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<ItemsDO> pageResult = itemsService.getItemsPage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbItems, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user