diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/MaterialInventoryController.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/MaterialInventoryController.java index b28ede4..dcdea7a 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/MaterialInventoryController.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/MaterialInventoryController.java @@ -1,56 +1,104 @@ package com.zteits.urbanops.module.garden.controller.admin.materialinventory; -import com.zteits.urbanops.framework.common.pojo.CommonResult; -import com.zteits.urbanops.framework.common.pojo.PageParam; -import com.zteits.urbanops.framework.common.pojo.PageResult; -import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; -import com.zteits.urbanops.module.garden.dal.dataobject.materialinventory.MaterialInventoryDO; -import com.zteits.urbanops.module.garden.service.materialinventory.MaterialInventoryService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.*; import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; +import org.springframework.validation.annotation.Validated; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +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 java.util.List; +import com.zteits.urbanops.framework.common.pojo.PageParam; +import com.zteits.urbanops.framework.common.pojo.PageResult; +import com.zteits.urbanops.framework.common.pojo.CommonResult; +import com.zteits.urbanops.framework.common.util.object.BeanUtils; import static com.zteits.urbanops.framework.common.pojo.CommonResult.success; +import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; + +import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; +import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*; + +import com.zteits.urbanops.module.garden.controller.admin.materialinventory.vo.*; +import com.zteits.urbanops.module.garden.dal.dataobject.materialinventory.MaterialInventoryDO; +import com.zteits.urbanops.module.garden.service.materialinventory.MaterialInventoryService; + @Tag(name = "管理后台 - 物料库存") @RestController -@RequestMapping("/material/inventory") +@RequestMapping("/garden/material-inventory") +@Validated public class MaterialInventoryController { @Resource - private MaterialInventoryService inventoryService; - - @PostMapping("/listForPage") - @Operation(summary = "物料库存-分页查询") - @PreAuthorize("@ss.hasPermission('material:inventory:list')") - public CommonResult> listForPage(@RequestBody MaterialInventoryDO where, - @RequestParam(value = "pageNum", required = false) Integer pageNum, - @RequestParam(value = "pageSize", required = false) Integer pageSize) { - PageParam page = new PageParam(); - page.setPageNo(pageNum == null ? 1 : pageNum); - page.setPageSize(pageSize == null ? 10 : pageSize); - return success(inventoryService.selectPage(page, where)); + private MaterialInventoryService materialInventoryService; + + @PostMapping("/create") + @Operation(summary = "创建物料库存") + @PreAuthorize("@ss.hasPermission('garden:material-inventory:create')") + public CommonResult createMaterialInventory(@Valid @RequestBody MaterialInventorySaveReqVO createReqVO) { + return success(materialInventoryService.createMaterialInventory(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新物料库存") + @PreAuthorize("@ss.hasPermission('garden:material-inventory:update')") + public CommonResult updateMaterialInventory(@Valid @RequestBody MaterialInventorySaveReqVO updateReqVO) { + materialInventoryService.updateMaterialInventory(updateReqVO); + return success(true); } - @GetMapping("/export") - @Operation(summary = "物料库存-导出") - @PreAuthorize("@ss.hasPermission('material:inventory:export')") - public void export(MaterialInventoryDO where, HttpServletResponse response) throws IOException { - List list = inventoryService.selectPage(new PageParam(), where).getList(); - ExcelUtils.write(response, "物料库存.xls", "数据", MaterialInventoryDO.class, list); + @DeleteMapping("/delete") + @Operation(summary = "删除物料库存") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('garden:material-inventory:delete')") + public CommonResult deleteMaterialInventory(@RequestParam("id") Long id) { + materialInventoryService.deleteMaterialInventory(id); + return success(true); } - @GetMapping("/updateByAlermNum") - @Operation(summary = "物料库存-阈值更新") - @PreAuthorize("@ss.hasPermission('material:inventory:export')") - public CommonResult updateInventoryAlermNum(@RequestParam("material_id") Long materialId, - @RequestParam("alerm_num") Long alermNum) { - return success(inventoryService.updateInventoryAlarmNum(materialId, alermNum)); + @DeleteMapping("/delete-list") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除物料库存") + @PreAuthorize("@ss.hasPermission('garden:material-inventory:delete')") + public CommonResult deleteMaterialInventoryList(@RequestParam("ids") List ids) { + materialInventoryService.deleteMaterialInventoryListByIds(ids); + return success(true); } -} + + @GetMapping("/get") + @Operation(summary = "获得物料库存") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('garden:material-inventory:query')") + public CommonResult getMaterialInventory(@RequestParam("id") Long id) { + MaterialInventoryDO materialInventory = materialInventoryService.getMaterialInventory(id); + return success(BeanUtils.toBean(materialInventory, MaterialInventoryRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得物料库存分页") + @PreAuthorize("@ss.hasPermission('garden:material-inventory:query')") + public CommonResult> getMaterialInventoryPage(@Valid MaterialInventoryPageReqVO pageReqVO) { + PageResult pageResult = materialInventoryService.getMaterialInventoryPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, MaterialInventoryRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出物料库存 Excel") + @PreAuthorize("@ss.hasPermission('garden:material-inventory:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportMaterialInventoryExcel(@Valid MaterialInventoryPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = materialInventoryService.getMaterialInventoryPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "物料库存.xls", "数据", MaterialInventoryRespVO.class, + BeanUtils.toBean(list, MaterialInventoryRespVO.class)); + } + +} \ No newline at end of file diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventoryPageReqVO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventoryPageReqVO.java new file mode 100644 index 0000000..88b1fb0 --- /dev/null +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventoryPageReqVO.java @@ -0,0 +1,74 @@ +package com.zteits.urbanops.module.garden.controller.admin.materialinventory.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import com.zteits.urbanops.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static com.zteits.urbanops.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 物料库存分页 Request VO") +@Data +public class MaterialInventoryPageReqVO extends PageParam { + + @Schema(description = "物料ID", example = "29414") + private Long materialId; + + @Schema(description = "物料名称", example = "李四") + private String materialName; + + @Schema(description = "物料类型ID", example = "24853") + private Long materialTypeId; + + @Schema(description = "耗材类型名称", example = "芋艿") + private String materialTypeName; + + @Schema(description = "类别ID", example = "30568") + private Long typeId; + + @Schema(description = "类别名称:药品", example = "芋艿") + private String typeName; + + @Schema(description = "类别明细ID", example = "6252") + private Long typeDetailId; + + @Schema(description = "类别明细", example = "芋艿") + private String typeDetailName; + + @Schema(description = "规格") + private String specifications; + + @Schema(description = "归属单位ID", example = "25626") + private Long belongCompanyId; + + @Schema(description = "归属单位", example = "李四") + private String belongCompanyName; + + @Schema(description = "单位ID", example = "6480") + private Long unitId; + + @Schema(description = "单位", example = "王五") + private String unitName; + + @Schema(description = "当前库存数量") + private Long currentNum; + + @Schema(description = "出库总数量(出库累加)") + private Long outTotalNum; + + @Schema(description = "库存总数量(入库累加)") + private Long inventoryTotalNum; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + + @Schema(description = "库存预警阈值") + private Long inventoryAlermNum; + + @Schema(description = "部门ID", example = "11349") + private Long deptId; + +} \ No newline at end of file diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventoryRespVO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventoryRespVO.java new file mode 100644 index 0000000..c66dffb --- /dev/null +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventoryRespVO.java @@ -0,0 +1,95 @@ +package com.zteits.urbanops.module.garden.controller.admin.materialinventory.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 cn.idev.excel.annotation.*; + +@Schema(description = "管理后台 - 物料库存 Response VO") +@Data +@ExcelIgnoreUnannotated +public class MaterialInventoryRespVO { + + @Schema(description = "库存ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "10980") + @ExcelProperty("库存ID") + private Long inventoryId; + + @Schema(description = "物料ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "29414") + @ExcelProperty("物料ID") + private Long materialId; + + @Schema(description = "物料名称", example = "李四") + @ExcelProperty("物料名称") + private String materialName; + + @Schema(description = "物料类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24853") + @ExcelProperty("物料类型ID") + private Long materialTypeId; + + @Schema(description = "耗材类型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("耗材类型名称") + private String materialTypeName; + + @Schema(description = "类别ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30568") + @ExcelProperty("类别ID") + private Long typeId; + + @Schema(description = "类别名称:药品", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("类别名称:药品") + private String typeName; + + @Schema(description = "类别明细ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "6252") + @ExcelProperty("类别明细ID") + private Long typeDetailId; + + @Schema(description = "类别明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("类别明细") + private String typeDetailName; + + @Schema(description = "规格", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("规格") + private String specifications; + + @Schema(description = "归属单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25626") + @ExcelProperty("归属单位ID") + private Long belongCompanyId; + + @Schema(description = "归属单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @ExcelProperty("归属单位") + private String belongCompanyName; + + @Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "6480") + @ExcelProperty("单位ID") + private Long unitId; + + @Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") + @ExcelProperty("单位") + private String unitName; + + @Schema(description = "当前库存数量", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("当前库存数量") + private Long currentNum; + + @Schema(description = "出库总数量(出库累加)", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("出库总数量(出库累加)") + private Long outTotalNum; + + @Schema(description = "库存总数量(入库累加)", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("库存总数量(入库累加)") + private Long inventoryTotalNum; + + @Schema(description = "创建时间") + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + @Schema(description = "库存预警阈值", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("库存预警阈值") + private Long inventoryAlermNum; + + @Schema(description = "部门ID", example = "11349") + @ExcelProperty("部门ID") + private Long deptId; + +} \ No newline at end of file diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventorySaveReqVO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventorySaveReqVO.java new file mode 100644 index 0000000..e3e8600 --- /dev/null +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventory/vo/MaterialInventorySaveReqVO.java @@ -0,0 +1,85 @@ +package com.zteits.urbanops.module.garden.controller.admin.materialinventory.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import jakarta.validation.constraints.*; + +@Schema(description = "管理后台 - 物料库存新增/修改 Request VO") +@Data +public class MaterialInventorySaveReqVO { + + @Schema(description = "库存ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "10980") + private Long inventoryId; + + @Schema(description = "物料ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "29414") + @NotNull(message = "物料ID不能为空") + private Long materialId; + + @Schema(description = "物料名称", example = "李四") + private String materialName; + + @Schema(description = "物料类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24853") + @NotNull(message = "物料类型ID不能为空") + private Long materialTypeId; + + @Schema(description = "耗材类型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @NotEmpty(message = "耗材类型名称不能为空") + private String materialTypeName; + + @Schema(description = "类别ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30568") + @NotNull(message = "类别ID不能为空") + private Long typeId; + + @Schema(description = "类别名称:药品", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @NotEmpty(message = "类别名称:药品不能为空") + private String typeName; + + @Schema(description = "类别明细ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "6252") + @NotNull(message = "类别明细ID不能为空") + private Long typeDetailId; + + @Schema(description = "类别明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @NotEmpty(message = "类别明细不能为空") + private String typeDetailName; + + @Schema(description = "规格", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "规格不能为空") + private String specifications; + + @Schema(description = "归属单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25626") + @NotNull(message = "归属单位ID不能为空") + private Long belongCompanyId; + + @Schema(description = "归属单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @NotEmpty(message = "归属单位不能为空") + private String belongCompanyName; + + @Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "6480") + @NotNull(message = "单位ID不能为空") + private Long unitId; + + @Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") + @NotEmpty(message = "单位不能为空") + private String unitName; + + @Schema(description = "当前库存数量", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "当前库存数量不能为空") + private Long currentNum; + + @Schema(description = "出库总数量(出库累加)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "出库总数量(出库累加)不能为空") + private Long outTotalNum; + + @Schema(description = "库存总数量(入库累加)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "库存总数量(入库累加)不能为空") + private Long inventoryTotalNum; + + @Schema(description = "库存预警阈值", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "库存预警阈值不能为空") + private Long inventoryAlermNum; + + @Schema(description = "部门ID", example = "11349") + private Long deptId; + +} \ No newline at end of file diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryin/vo/MaterialInventoryInSaveReqVO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryin/vo/MaterialInventoryInSaveReqVO.java index 87e7d12..3f35685 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryin/vo/MaterialInventoryInSaveReqVO.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryin/vo/MaterialInventoryInSaveReqVO.java @@ -15,53 +15,14 @@ public class MaterialInventoryInSaveReqVO { @Schema(description = "入库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "16290") private Long id; - @Schema(description = "入库批次号", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "入库批次号不能为空") - private String inventoryInNo; - @Schema(description = "物料ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "7335") @NotNull(message = "物料ID不能为空") private Long materialId; - @Schema(description = "物料名称", example = "芋艿") - private String materialName; - - @Schema(description = "物料类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "27813") - @NotNull(message = "物料类型ID不能为空") - private Long materialTypeId; - - @Schema(description = "耗材类型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") - @NotEmpty(message = "耗材类型名称不能为空") - private String materialTypeName; - - @Schema(description = "类别ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24913") - @NotNull(message = "类别ID不能为空") - private Long typeId; - - @Schema(description = "类别名称:药品", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") - @NotEmpty(message = "类别名称:药品不能为空") - private String typeName; - - @Schema(description = "类别明细ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "53") - @NotNull(message = "类别明细ID不能为空") - private Long typeDetailId; - - @Schema(description = "类别明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") - @NotEmpty(message = "类别明细不能为空") - private String typeDetailName; - @Schema(description = "规格", requiredMode = Schema.RequiredMode.REQUIRED) @NotEmpty(message = "规格不能为空") private String specifications; - @Schema(description = "归属单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "27639") - @NotNull(message = "归属单位ID不能为空") - private Long belongCompanyId; - - @Schema(description = "归属单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") - @NotEmpty(message = "归属单位不能为空") - private String belongCompanyName; - @Schema(description = "入库数量", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "入库数量不能为空") private Long inInventoryNum; @@ -70,14 +31,6 @@ public class MaterialInventoryInSaveReqVO { @NotNull(message = "单价不能为空") private BigDecimal materialPrice; - @Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11362") - @NotNull(message = "单位ID不能为空") - private Long unitId; - - @Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") - @NotEmpty(message = "单位不能为空") - private String unitName; - @Schema(description = "采购日期", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "采购日期不能为空") private LocalDateTime buyDate; @@ -94,7 +47,4 @@ public class MaterialInventoryInSaveReqVO { @NotEmpty(message = "联系人 电话不能为空") private String contactsPhone; - @Schema(description = "部门ID", example = "18025") - private Long deptId; - -} \ No newline at end of file +} diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryout/vo/MaterialInventoryOutSaveReqVO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryout/vo/MaterialInventoryOutSaveReqVO.java index 52510bb..a92e3f9 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryout/vo/MaterialInventoryOutSaveReqVO.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/materialinventoryout/vo/MaterialInventoryOutSaveReqVO.java @@ -14,10 +14,6 @@ public class MaterialInventoryOutSaveReqVO { @Schema(description = "入库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18713") private Long id; - @Schema(description = "入库批次号", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "入库批次号不能为空") - private String inventoryOutNo; - @Schema(description = "物料ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14541") @NotNull(message = "物料ID不能为空") private Long materialId; @@ -25,67 +21,12 @@ public class MaterialInventoryOutSaveReqVO { @Schema(description = "物料名称", example = "芋艿") private String materialName; - @Schema(description = "物料类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9209") - @NotNull(message = "物料类型ID不能为空") - private Long materialTypeId; - - @Schema(description = "耗材类型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") - @NotEmpty(message = "耗材类型名称不能为空") - private String materialTypeName; - - @Schema(description = "类别ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12624") - @NotNull(message = "类别ID不能为空") - private Long typeId; - - @Schema(description = "类别名称:药品", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotEmpty(message = "类别名称:药品不能为空") - private String typeName; - - @Schema(description = "类别明细ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24611") - @NotNull(message = "类别明细ID不能为空") - private Long typeDetailId; - - @Schema(description = "类别明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") - @NotEmpty(message = "类别明细不能为空") - private String typeDetailName; - - @Schema(description = "规格", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "规格不能为空") - private String specifications; - - @Schema(description = "归属单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17128") - @NotNull(message = "归属单位ID不能为空") - private Long belongCompanyId; - - @Schema(description = "归属单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") - @NotEmpty(message = "归属单位不能为空") - private String belongCompanyName; - @Schema(description = "出库数量", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "出库数量不能为空") private Long outInventoryNum; - @Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1033") - @NotNull(message = "单位ID不能为空") - private Long unitId; - - @Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotEmpty(message = "单位不能为空") - private String unitName; - @Schema(description = "出库日期", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "出库日期不能为空") private LocalDateTime outDate; - @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "你说的对") - @NotEmpty(message = "备注不能为空") - private String remark; - - @Schema(description = "部门ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "22618") - @NotNull(message = "部门ID不能为空") - private Long deptId; - - @Schema(description = "类型: 1:手动出库;2:养护类出库", example = "1") - private Integer type; - -} \ No newline at end of file +} diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/dataobject/materialinventory/MaterialInventoryDO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/dataobject/materialinventory/MaterialInventoryDO.java index eb8909b..06df02e 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/dataobject/materialinventory/MaterialInventoryDO.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/dataobject/materialinventory/MaterialInventoryDO.java @@ -1,32 +1,104 @@ package com.zteits.urbanops.module.garden.dal.dataobject.materialinventory; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; import com.zteits.urbanops.framework.mybatis.core.dataobject.BaseDO; -import lombok.Data; +/** + * 物料库存 DO + * + * @author 超级管理员 + */ @TableName("garden_material_inventory") +@KeySequence("garden_material_inventory_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor public class MaterialInventoryDO extends BaseDO { + + /** + * 库存ID + */ @TableId private Long inventoryId; + /** + * 物料ID + */ private Long materialId; + /** + * 物料名称 + */ private String materialName; + /** + * 物料类型ID + */ private Long materialTypeId; + /** + * 耗材类型名称 + */ private String materialTypeName; + /** + * 类别ID + */ private Long typeId; + /** + * 类别名称:药品 + */ private String typeName; + /** + * 类别明细ID + */ private Long typeDetailId; + /** + * 类别明细 + */ private String typeDetailName; + /** + * 规格 + */ private String specifications; + /** + * 归属单位ID + */ private Long belongCompanyId; + /** + * 归属单位 + */ private String belongCompanyName; + /** + * 单位ID + */ private Long unitId; + /** + * 单位 + */ private String unitName; + /** + * 当前库存数量 + */ private Long currentNum; + /** + * 出库总数量(出库累加) + */ private Long outTotalNum; + /** + * 库存总数量(入库累加) + */ private Long inventoryTotalNum; - private String status; + /** + * 库存预警阈值 + */ private Long inventoryAlermNum; + /** + * 部门ID + */ private Long deptId; -} + + +} \ No newline at end of file diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/materialinventory/MaterialInventoryMapper.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/materialinventory/MaterialInventoryMapper.java index 0df450a..bc6e60b 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/materialinventory/MaterialInventoryMapper.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/materialinventory/MaterialInventoryMapper.java @@ -1,39 +1,44 @@ package com.zteits.urbanops.module.garden.dal.mysql.materialinventory; -import com.zteits.urbanops.framework.mybatis.core.mapper.BaseMapperX; +import java.util.*; + +import com.zteits.urbanops.framework.common.pojo.PageResult; import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX; +import com.zteits.urbanops.framework.mybatis.core.mapper.BaseMapperX; import com.zteits.urbanops.module.garden.dal.dataobject.materialinventory.MaterialInventoryDO; import org.apache.ibatis.annotations.Mapper; +import com.zteits.urbanops.module.garden.controller.admin.materialinventory.vo.*; +/** + * 物料库存 Mapper + * + * @author 超级管理员 + */ @Mapper public interface MaterialInventoryMapper extends BaseMapperX { - default MaterialInventoryDO selectByMaterialId(Long materialId) { - return selectOne(new LambdaQueryWrapperX().eq(MaterialInventoryDO::getMaterialId, materialId)); - } - - default MaterialInventoryDO selectByTypeDetailId(Long typeDetailId, Long companyId) { - return selectOne(new LambdaQueryWrapperX() - .eq(MaterialInventoryDO::getTypeDetailId, typeDetailId) - .eq(MaterialInventoryDO::getBelongCompanyId, companyId)); - } - - default int updateInventoryByMaterialId(Long inventoryId, Long outNum) { - MaterialInventoryDO inv = selectById(inventoryId); - if (inv == null) return 0; - MaterialInventoryDO upd = new MaterialInventoryDO(); - upd.setInventoryId(inventoryId); - upd.setCurrentNum(inv.getCurrentNum() - outNum); - upd.setOutTotalNum(inv.getOutTotalNum() == null ? outNum : inv.getOutTotalNum() + outNum); - return updateById(upd); + default PageResult selectPage(MaterialInventoryPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MaterialInventoryDO::getMaterialId, reqVO.getMaterialId()) + .likeIfPresent(MaterialInventoryDO::getMaterialName, reqVO.getMaterialName()) + .eqIfPresent(MaterialInventoryDO::getMaterialTypeId, reqVO.getMaterialTypeId()) + .likeIfPresent(MaterialInventoryDO::getMaterialTypeName, reqVO.getMaterialTypeName()) + .eqIfPresent(MaterialInventoryDO::getTypeId, reqVO.getTypeId()) + .likeIfPresent(MaterialInventoryDO::getTypeName, reqVO.getTypeName()) + .eqIfPresent(MaterialInventoryDO::getTypeDetailId, reqVO.getTypeDetailId()) + .likeIfPresent(MaterialInventoryDO::getTypeDetailName, reqVO.getTypeDetailName()) + .eqIfPresent(MaterialInventoryDO::getSpecifications, reqVO.getSpecifications()) + .eqIfPresent(MaterialInventoryDO::getBelongCompanyId, reqVO.getBelongCompanyId()) + .likeIfPresent(MaterialInventoryDO::getBelongCompanyName, reqVO.getBelongCompanyName()) + .eqIfPresent(MaterialInventoryDO::getUnitId, reqVO.getUnitId()) + .likeIfPresent(MaterialInventoryDO::getUnitName, reqVO.getUnitName()) + .eqIfPresent(MaterialInventoryDO::getCurrentNum, reqVO.getCurrentNum()) + .eqIfPresent(MaterialInventoryDO::getOutTotalNum, reqVO.getOutTotalNum()) + .eqIfPresent(MaterialInventoryDO::getInventoryTotalNum, reqVO.getInventoryTotalNum()) + .betweenIfPresent(MaterialInventoryDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(MaterialInventoryDO::getInventoryAlermNum, reqVO.getInventoryAlermNum()) + .eqIfPresent(MaterialInventoryDO::getDeptId, reqVO.getDeptId()) + .orderByDesc(MaterialInventoryDO::getMaterialId)); } - default int updateInventoryAlarmNum(Long materialId, Long inventoryAlermNum) { - MaterialInventoryDO inv = selectByMaterialId(materialId); - if (inv == null) return 0; - MaterialInventoryDO upd = new MaterialInventoryDO(); - upd.setInventoryId(inv.getInventoryId()); - upd.setInventoryAlermNum(inventoryAlermNum); - return updateById(upd); - } } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java index f403f9d..34eec00 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java @@ -86,5 +86,5 @@ public interface ErrorCodeConstants { ErrorCode MATERIAL_INVENTORY_IN_NOT_EXISTS = new ErrorCode(1-100-004-004, "物料入库不存在"); ErrorCode MATERIAL_INVENTORY_OUT_NOT_EXISTS = new ErrorCode(1-100-004-005, "物料出库不存在"); - + ErrorCode MATERIAL_INVENTORY_NOT_EXISTS = new ErrorCode(1-100-004-006, "物料库存不存在"); } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryService.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryService.java index c4ab7cd..61f0ba1 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryService.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryService.java @@ -1,10 +1,93 @@ package com.zteits.urbanops.module.garden.service.materialinventory; -import com.zteits.urbanops.framework.common.pojo.PageParam; -import com.zteits.urbanops.framework.common.pojo.PageResult; +import java.util.*; +import jakarta.validation.*; +import com.zteits.urbanops.module.garden.controller.admin.materialinventory.vo.*; import com.zteits.urbanops.module.garden.dal.dataobject.materialinventory.MaterialInventoryDO; +import com.zteits.urbanops.framework.common.pojo.PageResult; +import com.zteits.urbanops.framework.common.pojo.PageParam; +/** + * 物料库存 Service 接口 + * + * @author 超级管理员 + */ public interface MaterialInventoryService { - PageResult selectPage(PageParam pageParam, MaterialInventoryDO where); - Boolean updateInventoryAlarmNum(Long materialId, Long alermNum); + + /** + * 创建物料库存 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createMaterialInventory(@Valid MaterialInventorySaveReqVO createReqVO); + + /** + * 更新物料库存 + * + * @param updateReqVO 更新信息 + */ + void updateMaterialInventory(@Valid MaterialInventorySaveReqVO updateReqVO); + + /** + * 删除物料库存 + * + * @param id 编号 + */ + void deleteMaterialInventory(Long id); + + /** + * 批量删除物料库存 + * + * @param ids 编号 + */ + void deleteMaterialInventoryListByIds(List ids); + + /** + * 获得物料库存 + * + * @param id 编号 + * @return 物料库存 + */ + MaterialInventoryDO getMaterialInventory(Long id); + + /** + * 获得物料库存分页 + * + * @param pageReqVO 分页查询 + * @return 物料库存分页 + */ + PageResult getMaterialInventoryPage(MaterialInventoryPageReqVO pageReqVO); + + + /** + * 新增物料库存 + * + * @param materialInventory 物料库存 + * @return 结果 + */ + public int insertMaterialInventory(MaterialInventoryDO materialInventory); + /** + * 更新物料库存 + * + * @param materialInventory 物料库存 + * @return 结果 + */ + public int updateTdMaterialInventory(MaterialInventoryDO materialInventory); + /** + * @Author wangqian + * @Description 查询物料信息根据 + * @Date 2025/11/28 23:36 + * @Param materialId + */ + MaterialInventoryDO selectTdMaterialInventoryByMaterialId(Long materialId); + + + /** + * 更新出库库库存信息 + * @param inventoryId + * @param outNum 出库数量 + * @return + */ + int updateInVentoryByMaterialId(MaterialInventoryDO materialInventory, Long outNum); } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryServiceImpl.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryServiceImpl.java index ac041f9..518c4a1 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryServiceImpl.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventory/MaterialInventoryServiceImpl.java @@ -1,30 +1,119 @@ package com.zteits.urbanops.module.garden.service.materialinventory; -import com.zteits.urbanops.framework.common.pojo.PageParam; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zteits.urbanops.framework.common.pojo.PageResult; +import com.zteits.urbanops.framework.common.util.object.BeanUtils; +import com.zteits.urbanops.module.garden.controller.admin.materialinventory.vo.MaterialInventoryPageReqVO; +import com.zteits.urbanops.module.garden.controller.admin.materialinventory.vo.MaterialInventorySaveReqVO; import com.zteits.urbanops.module.garden.dal.dataobject.materialinventory.MaterialInventoryDO; import com.zteits.urbanops.module.garden.dal.mysql.materialinventory.MaterialInventoryMapper; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import java.util.List; + +import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; +import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.MATERIAL_INVENTORY_NOT_EXISTS; + +/** + * 物料库存 Service 实现类 + * + * @author 超级管理员 + */ @Service +@Validated public class MaterialInventoryServiceImpl implements MaterialInventoryService { @Resource - private MaterialInventoryMapper mapper; + private MaterialInventoryMapper materialInventoryMapper; + + @Override + public Long createMaterialInventory(MaterialInventorySaveReqVO createReqVO) { + // 插入 + MaterialInventoryDO materialInventory = BeanUtils.toBean(createReqVO, MaterialInventoryDO.class); + materialInventoryMapper.insert(materialInventory); + + // 返回 + return materialInventory.getMaterialId(); + } + + @Override + public void updateMaterialInventory(MaterialInventorySaveReqVO updateReqVO) { + // 校验存在 + validateMaterialInventoryExists(updateReqVO.getMaterialId()); + // 更新 + MaterialInventoryDO updateObj = BeanUtils.toBean(updateReqVO, MaterialInventoryDO.class); + materialInventoryMapper.updateById(updateObj); + } + + @Override + public void deleteMaterialInventory(Long id) { + // 校验存在 + validateMaterialInventoryExists(id); + // 删除 + materialInventoryMapper.deleteById(id); + } + + @Override + public void deleteMaterialInventoryListByIds(List ids) { + // 删除 + materialInventoryMapper.deleteByIds(ids); + } + + + private void validateMaterialInventoryExists(Long id) { + if (materialInventoryMapper.selectById(id) == null) { + throw exception(MATERIAL_INVENTORY_NOT_EXISTS); + } + } + + @Override + public MaterialInventoryDO getMaterialInventory(Long id) { + return materialInventoryMapper.selectById(id); + } + + @Override + public PageResult getMaterialInventoryPage(MaterialInventoryPageReqVO pageReqVO) { + return materialInventoryMapper.selectPage(pageReqVO); + } + + @Override + public int insertMaterialInventory(MaterialInventoryDO materialInventory) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(MaterialInventoryDO::getBelongCompanyId, materialInventory.getBelongCompanyId()); + queryWrapper.eq(MaterialInventoryDO::getTypeDetailId, materialInventory.getTypeDetailId()); + MaterialInventoryDO object = materialInventoryMapper.selectOne(queryWrapper); + if(object != null){ + object.setInventoryTotalNum(object.getInventoryTotalNum()+ materialInventory.getCurrentNum()); + object.setCurrentNum(object.getCurrentNum()+materialInventory.getCurrentNum()); + return materialInventoryMapper.updateById(object); + } else { + return materialInventoryMapper.insert(materialInventory); + } + } + @Override + public int updateTdMaterialInventory(MaterialInventoryDO materialInventory) { + // 校验存在 + validateMaterialInventoryExists(materialInventory.getInventoryId()); + + return materialInventoryMapper.updateById(materialInventory); + } @Override - public PageResult selectPage(PageParam pageParam, MaterialInventoryDO where) { - return mapper.selectPage(pageParam, null, new com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX() - .eqIfPresent(MaterialInventoryDO::getMaterialId, where.getMaterialId()) - .likeIfPresent(MaterialInventoryDO::getMaterialName, where.getMaterialName()) - .eqIfPresent(MaterialInventoryDO::getTypeDetailId, where.getTypeDetailId()) - .eqIfPresent(MaterialInventoryDO::getBelongCompanyId, where.getBelongCompanyId()) - .orderByDesc(MaterialInventoryDO::getUpdateTime)); + public MaterialInventoryDO selectTdMaterialInventoryByMaterialId(Long materialId) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(MaterialInventoryDO::getTypeDetailId, materialId); + return materialInventoryMapper.selectOne(queryWrapper); } @Override - public Boolean updateInventoryAlarmNum(Long materialId, Long alermNum) { - return mapper.updateInventoryAlarmNum(materialId, alermNum) > 0; + public int updateInVentoryByMaterialId(MaterialInventoryDO materialInventory, Long outNum) { + MaterialInventoryDO out = new MaterialInventoryDO(); + out.setInventoryId(materialInventory.getInventoryId()); + out.setOutTotalNum(materialInventory.getInventoryTotalNum() + outNum); + out.setCurrentNum(materialInventory.getCurrentNum() - outNum); + return materialInventoryMapper.updateById(materialInventory); } } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryin/MaterialInventoryInServiceImpl.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryin/MaterialInventoryInServiceImpl.java index beb8895..bedf767 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryin/MaterialInventoryInServiceImpl.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryin/MaterialInventoryInServiceImpl.java @@ -1,6 +1,11 @@ package com.zteits.urbanops.module.garden.service.materialinventoryin; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.RandomUtil; +import com.zteits.urbanops.module.garden.dal.dataobject.material.MaterialDO; +import com.zteits.urbanops.module.garden.dal.dataobject.materialinventory.MaterialInventoryDO; +import com.zteits.urbanops.module.garden.dal.mysql.material.MaterialMapper; +import com.zteits.urbanops.module.garden.service.materialinventory.MaterialInventoryService; import org.springframework.stereotype.Service; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -15,9 +20,13 @@ import com.zteits.urbanops.framework.common.util.object.BeanUtils; import com.zteits.urbanops.module.garden.dal.mysql.materialinventoryin.MaterialInventoryInMapper; +import static com.zteits.urbanops.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; +import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception0; import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.convertList; import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.diffList; +import static com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; +import static com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils.getLoginUserDeptId; import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; /** @@ -32,38 +41,127 @@ public class MaterialInventoryInServiceImpl implements MaterialInventoryInServic @Resource private MaterialInventoryInMapper materialInventoryInMapper; + @Resource + private MaterialMapper materialMapper; + + @Resource + private MaterialInventoryService materialInventoryService; + @Override + @Transactional public Long createMaterialInventoryIn(MaterialInventoryInSaveReqVO createReqVO) { + //参数校验 + MaterialDO material = materialMapper.selectOne(MaterialDO::getMaterialId,createReqVO.getMaterialId()); + if(null == material){ + throw exception0(BAD_REQUEST.getCode(), "无效参数-materialId"); + } + MaterialInventoryInDO in = new MaterialInventoryInDO(); + in.setInventoryInNo(System.currentTimeMillis()+ RandomUtil.randomInt(10, 100000)+""); + in.setMaterialId(createReqVO.getMaterialId()); + in.setMaterialName(material.getMaterialName()); + in.setMaterialTypeId(material.getMaterialTypeId()); + in.setMaterialTypeName(material.getMaterialTypeName()); + in.setTypeId(material.getTypeId()); + in.setTypeName(material.getTypeName()); + in.setTypeDetailId(material.getTypeDetailId()); + in.setTypeDetailName(material.getTypeDetailName()); + in.setSpecifications(material.getSpecifications()); + in.setBelongCompanyId(material.getBelongCompanyId()); + in.setBelongCompanyName(material.getBelongCompanyName()); + in.setInInventoryNum(createReqVO.getInInventoryNum()); + in.setMaterialPrice(createReqVO.getMaterialPrice()); + in.setUnitId(material.getUnitId()); + in.setUnitName(material.getUnitName()); + in.setBuyDate(createReqVO.getBuyDate()); + in.setSupplierName(createReqVO.getSupplierName()); + in.setContactsName(createReqVO.getContactsName()); + in.setContactsPhone(createReqVO.getContactsPhone()); + in.setDeptId(getLoginUserDeptId()); + // 插入 - MaterialInventoryInDO materialInventoryIn = BeanUtils.toBean(createReqVO, MaterialInventoryInDO.class); - materialInventoryInMapper.insert(materialInventoryIn); + //MaterialInventoryInDO materialInventoryIn = BeanUtils.toBean(createReqVO, MaterialInventoryInDO.class); + materialInventoryInMapper.insert(in); + + //更新库存 + MaterialInventoryDO inventory = new MaterialInventoryDO(); + inventory.setMaterialId(in.getMaterialId()); + inventory.setMaterialName(in.getMaterialName()); + inventory.setMaterialTypeId(in.getMaterialTypeId()); + inventory.setMaterialTypeName(in.getMaterialTypeName()); + inventory.setTypeId(material.getTypeId()); + inventory.setTypeName(material.getTypeName()); + inventory.setTypeDetailId(material.getTypeDetailId()); + inventory.setTypeDetailName(material.getTypeDetailName()); + inventory.setSpecifications(in.getSpecifications()); + inventory.setBelongCompanyId(in.getBelongCompanyId()); + inventory.setBelongCompanyName(in.getBelongCompanyName()); + inventory.setUnitId(in.getUnitId()); + inventory.setUnitName(in.getUnitName()); + inventory.setCurrentNum(in.getInInventoryNum()); + inventory.setOutTotalNum(0L); + inventory.setInventoryTotalNum(in.getInInventoryNum()); + inventory.setDeptId(getLoginUserDeptId()); + materialInventoryService.insertMaterialInventory(inventory); // 返回 - return materialInventoryIn.getId(); + return in.getId(); } @Override + @Transactional public void updateMaterialInventoryIn(MaterialInventoryInSaveReqVO updateReqVO) { // 校验存在 validateMaterialInventoryInExists(updateReqVO.getId()); + //查询库存管理参数 + MaterialDO material = materialMapper.selectOne(MaterialDO::getMaterialId,updateReqVO.getMaterialId()); + if(null == material){ + throw exception0(BAD_REQUEST.getCode(), "无效参数-materialId"); + } // 更新 MaterialInventoryInDO updateObj = BeanUtils.toBean(updateReqVO, MaterialInventoryInDO.class); + updateObj.setMaterialName(material.getMaterialName()); + updateObj.setMaterialTypeId(material.getMaterialTypeId()); + updateObj.setMaterialTypeName(material.getMaterialTypeName()); + updateObj.setSpecifications(material.getSpecifications()); + updateObj.setBelongCompanyId(material.getBelongCompanyId()); + updateObj.setBelongCompanyName(material.getBelongCompanyName()); + updateObj.setUnitId(material.getUnitId()); + updateObj.setUnitName(material.getUnitName()); materialInventoryInMapper.updateById(updateObj); } @Override + @Transactional public void deleteMaterialInventoryIn(Long id) { // 校验存在 - validateMaterialInventoryInExists(id); + MaterialInventoryInDO materialInventoryIn = materialInventoryInMapper.selectById(id); + if (null == materialInventoryIn) { + throw exception(MATERIAL_INVENTORY_IN_NOT_EXISTS); + } + MaterialInventoryDO materialInventory = materialInventoryService.selectTdMaterialInventoryByMaterialId(materialInventoryIn.getMaterialId()); + if(null == materialInventory){ + throw exception0(BAD_REQUEST.getCode(),"参数错误"); + } + //库存已使用 + if(materialInventory.getCurrentNum() < materialInventoryIn.getInInventoryNum()){ + throw exception0(BAD_REQUEST.getCode(),"库存已使用"); + } + //入库记录减扣 + MaterialInventoryDO inventory = new MaterialInventoryDO(); + inventory.setInventoryId(materialInventory.getInventoryId()); + inventory.setMaterialId(materialInventory.getMaterialId()); + inventory.setCurrentNum(materialInventory.getCurrentNum() - materialInventoryIn.getInInventoryNum()); + inventory.setInventoryTotalNum(materialInventory.getInventoryTotalNum() - materialInventoryIn.getInInventoryNum()); + materialInventoryService.updateTdMaterialInventory(inventory); // 删除 materialInventoryInMapper.deleteById(id); } @Override - public void deleteMaterialInventoryInListByIds(List ids) { + public void deleteMaterialInventoryInListByIds(List ids) { // 删除 materialInventoryInMapper.deleteByIds(ids); - } + } private void validateMaterialInventoryInExists(Long id) { @@ -82,4 +180,4 @@ public class MaterialInventoryInServiceImpl implements MaterialInventoryInServic return materialInventoryInMapper.selectPage(pageReqVO); } -} \ No newline at end of file +} diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryout/MaterialInventoryOutServiceImpl.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryout/MaterialInventoryOutServiceImpl.java index 4bf635e..4794b2e 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryout/MaterialInventoryOutServiceImpl.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/materialinventoryout/MaterialInventoryOutServiceImpl.java @@ -1,24 +1,25 @@ package com.zteits.urbanops.module.garden.service.materialinventoryout; -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 com.zteits.urbanops.module.garden.controller.admin.materialinventoryout.vo.*; -import com.zteits.urbanops.module.garden.dal.dataobject.materialinventoryout.MaterialInventoryOutDO; import com.zteits.urbanops.framework.common.pojo.PageResult; -import com.zteits.urbanops.framework.common.pojo.PageParam; import com.zteits.urbanops.framework.common.util.object.BeanUtils; - +import com.zteits.urbanops.module.garden.controller.admin.materialinventoryout.vo.MaterialInventoryOutPageReqVO; +import com.zteits.urbanops.module.garden.controller.admin.materialinventoryout.vo.MaterialInventoryOutSaveReqVO; +import com.zteits.urbanops.module.garden.dal.dataobject.material.MaterialDO; +import com.zteits.urbanops.module.garden.dal.dataobject.materialinventory.MaterialInventoryDO; +import com.zteits.urbanops.module.garden.dal.dataobject.materialinventoryout.MaterialInventoryOutDO; +import com.zteits.urbanops.module.garden.dal.mysql.material.MaterialMapper; import com.zteits.urbanops.module.garden.dal.mysql.materialinventoryout.MaterialInventoryOutMapper; +import com.zteits.urbanops.module.garden.service.materialinventory.MaterialInventoryService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; +import static com.zteits.urbanops.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.convertList; -import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.diffList; -import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; +import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception0; +import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.MATERIAL_INVENTORY_OUT_NOT_EXISTS; /** * 物料出库 Service 实现类 @@ -31,15 +32,47 @@ public class MaterialInventoryOutServiceImpl implements MaterialInventoryOutServ @Resource private MaterialInventoryOutMapper materialInventoryOutMapper; + @Resource + private MaterialMapper materialMapper; + @Resource + private MaterialInventoryService materialInventoryService; @Override public Long createMaterialInventoryOut(MaterialInventoryOutSaveReqVO createReqVO) { // 插入 - MaterialInventoryOutDO materialInventoryOut = BeanUtils.toBean(createReqVO, MaterialInventoryOutDO.class); - materialInventoryOutMapper.insert(materialInventoryOut); + MaterialInventoryOutDO out = BeanUtils.toBean(createReqVO, MaterialInventoryOutDO.class); + //参数校验 + MaterialDO material = materialMapper.selectOne(MaterialDO::getMaterialId,createReqVO.getMaterialId()); + if(null == material){ + throw exception0(BAD_REQUEST.getCode(), "无效参数-materialId"); + } + MaterialInventoryDO materialInventory = materialInventoryService.selectTdMaterialInventoryByMaterialId(out.getMaterialId()); + if(null == materialInventory){ + throw exception0(BAD_REQUEST.getCode(),createReqVO.getMaterialName()+"没有库存"); + } + //当前库存不足,无法出库 + if(materialInventory.getCurrentNum() < out.getOutInventoryNum()){ + throw exception0(BAD_REQUEST.getCode(),"当前库存不足,无法出库"); + } + out.setMaterialName(material.getMaterialName()); + out.setMaterialTypeId(material.getMaterialTypeId()); + out.setMaterialTypeName(material.getMaterialTypeName()); + out.setTypeId(material.getTypeId()); + out.setTypeName(material.getTypeName()); + out.setTypeDetailId(material.getTypeDetailId()); + out.setTypeDetailName(material.getTypeDetailName()); + out.setSpecifications(material.getSpecifications()); + out.setBelongCompanyId(material.getBelongCompanyId()); + out.setBelongCompanyName(material.getBelongCompanyName()); + out.setUnitId(material.getUnitId()); + out.setUnitName(material.getUnitName()); + materialInventoryOutMapper.insert(out); + + //更新库存 + materialInventoryService.updateInVentoryByMaterialId(materialInventory, out.getOutInventoryNum()); // 返回 - return materialInventoryOut.getId(); + return out.getId(); } @Override @@ -54,7 +87,30 @@ public class MaterialInventoryOutServiceImpl implements MaterialInventoryOutServ @Override public void deleteMaterialInventoryOut(Long id) { // 校验存在 - validateMaterialInventoryOutExists(id); + MaterialInventoryOutDO materialInventoryOut = materialInventoryOutMapper.selectById(id); + if (null == materialInventoryOut) { + throw exception(MATERIAL_INVENTORY_OUT_NOT_EXISTS); + } + + //查询库存 + MaterialInventoryDO materialInventory = materialInventoryService.selectTdMaterialInventoryByMaterialId(materialInventoryOut.getMaterialId()); + if(null == materialInventory){ + throw exception0(BAD_REQUEST.getCode(),"参数错误"); + } + //库存已使用 + if(materialInventory.getCurrentNum() < materialInventoryOut.getOutInventoryNum()){ + throw exception0(BAD_REQUEST.getCode(),"库存已使用"); + } + + //入库记录减扣 + MaterialInventoryDO inventory = new MaterialInventoryDO(); + inventory.setInventoryId(materialInventory.getInventoryId()); + inventory.setMaterialId(materialInventory.getMaterialId()); + inventory.setCurrentNum(materialInventory.getCurrentNum() + materialInventoryOut.getOutInventoryNum()); + inventory.setInventoryTotalNum(materialInventory.getInventoryTotalNum() + materialInventoryOut.getOutInventoryNum()); + inventory.setOutTotalNum(materialInventory.getOutTotalNum() - materialInventoryOut.getOutInventoryNum()); + materialInventoryService.updateTdMaterialInventory(inventory); + // 删除 materialInventoryOutMapper.deleteById(id); } @@ -82,4 +138,4 @@ public class MaterialInventoryOutServiceImpl implements MaterialInventoryOutServ return materialInventoryOutMapper.selectPage(pageReqVO); } -} \ No newline at end of file +}