| | |
| | | import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemRespVO; |
| | | import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO; |
| | | import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemStatusUpdateReqVO; |
| | | import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO; |
| | | import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO; |
| | | import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemDO; |
| | | import cn.iocoder.yudao.module.mdm.dal.dataobject.unit.MdmUnitMeasureDO; |
| | | import cn.iocoder.yudao.module.mdm.dal.dataobject.warehouse.MdmWarehouseDO; |
| | | import cn.iocoder.yudao.module.mdm.service.brand.MdmBrandService; |
| | | import cn.iocoder.yudao.module.mdm.service.category.MdmItemCategoryService; |
| | | import cn.iocoder.yudao.module.mdm.service.item.MdmItemBatchConfigService; |
| | | import cn.iocoder.yudao.module.mdm.service.item.MdmItemService; |
| | | import cn.iocoder.yudao.module.mdm.service.unit.MdmUnitMeasureService; |
| | | import cn.iocoder.yudao.module.mdm.service.warehouse.MdmWarehouseService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | |
| | | private MdmItemService itemService; |
| | | |
| | | @Resource |
| | | private MdmItemCategoryService itemCategoryService; |
| | | @Resource |
| | | private MdmUnitMeasureService unitMeasureService; |
| | | @Resource |
| | | private MdmWarehouseService warehouseService; |
| | | @Resource |
| | | private MdmBrandService brandService; |
| | | @Resource |
| | | private MdmItemBatchConfigService itemBatchConfigService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建物料") |
| | |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete-list") |
| | | @Operation(summary = "批量删除物料") |
| | | @Parameter(name = "ids", description = "编号列表", required = true, example = "1,2,3") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:delete')") |
| | | public CommonResult<Boolean> deleteItemList(@RequestParam("ids") List<Long> ids) { |
| | | itemService.deleteItemList(ids); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得物料") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:query')") |
| | | public CommonResult<MdmItemRespVO> getItem(@RequestParam("id") Long id) { |
| | | MdmItemDO item = itemService.getItem(id); |
| | | return success(BeanUtils.toBean(item, MdmItemRespVO.class)); |
| | | MdmItemRespVO resp = BeanUtils.toBean(item, MdmItemRespVO.class); |
| | | if (resp != null) { |
| | | enrichItemRespVO(resp); |
| | | // 填充批次属性配置 |
| | | enrichItemBatchConfig(resp); |
| | | } |
| | | return success(resp); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:query')") |
| | | public CommonResult<PageResult<MdmItemRespVO>> getItemPage(@Valid MdmItemPageReqVO pageReqVO) { |
| | | PageResult<MdmItemDO> pageResult = itemService.getItemPage(pageReqVO); |
| | | // 关联查询分类名称 |
| | | Map<Long, MdmItemCategoryDO> categoryMap = itemCategoryService.getItemCategoryMap( |
| | | convertSet(pageResult.getList(), MdmItemDO::getCategoryId)); |
| | | // 关联查询计量单位名称 |
| | | Map<Long, MdmUnitMeasureDO> unitMap = unitMeasureService.getUnitMeasureMap( |
| | | convertSet(pageResult.getList(), MdmItemDO::getUnitMeasureId)); |
| | | // 转换 |
| | | List<MdmItemRespVO> respList = BeanUtils.toBean(pageResult.getList(), MdmItemRespVO.class); |
| | | // 批量关联查询辅单位名称 |
| | | Set<Long> unitIds = new HashSet<>(); |
| | | respList.forEach(resp -> { |
| | | if (resp.getUnitMeasureId2() != null) unitIds.add(resp.getUnitMeasureId2()); |
| | | if (resp.getUnitMeasureId3() != null) unitIds.add(resp.getUnitMeasureId3()); |
| | | }); |
| | | Map<Long, MdmUnitMeasureDO> auxUnitMap = unitIds.isEmpty() ? |
| | | Collections.emptyMap() : unitMeasureService.getUnitMeasureMap(unitIds); |
| | | // 批量关联查询仓库名称 |
| | | Set<Long> warehouseIds = new HashSet<>(); |
| | | respList.forEach(resp -> { |
| | | if (resp.getWarehouseId() != null) warehouseIds.add(resp.getWarehouseId()); |
| | | }); |
| | | Map<Long, MdmWarehouseDO> warehouseMap = warehouseIds.isEmpty() ? |
| | | Collections.emptyMap() : warehouseService.getWarehouseList(warehouseIds).stream() |
| | | .collect(Collectors.toMap(MdmWarehouseDO::getId, w -> w)); |
| | | // 赋值 |
| | | respList.forEach(resp -> { |
| | | // 分类名称 |
| | | MdmItemCategoryDO category = categoryMap.get(resp.getCategoryId()); |
| | | if (category != null) { |
| | | resp.setCategoryName(category.getName()); |
| | | } |
| | | MdmUnitMeasureDO unit = unitMap.get(resp.getUnitMeasureId()); |
| | | if (unit != null) { |
| | | resp.setUnitMeasureName(unit.getName()); |
| | | } |
| | | MdmUnitMeasureDO auxUnit1 = auxUnitMap.get(resp.getUnitMeasureId2()); |
| | | if (auxUnit1 != null) { |
| | | resp.setUnitMeasureName2(auxUnit1.getName()); |
| | | } |
| | | MdmUnitMeasureDO auxUnit2 = auxUnitMap.get(resp.getUnitMeasureId3()); |
| | | if (auxUnit2 != null) { |
| | | resp.setUnitMeasureName3(auxUnit2.getName()); |
| | | } |
| | | MdmWarehouseDO warehouse = warehouseMap.get(resp.getWarehouseId()); |
| | | if (warehouse != null) { |
| | | resp.setWarehouseName(warehouse.getName()); |
| | | } |
| | | }); |
| | | return success(new PageResult<>(respList, pageResult.getTotal())); |
| | |
| | | return success(BeanUtils.toBean(list, MdmItemRespVO.class)); |
| | | } |
| | | |
| | | /** |
| | | * 填充物料响应 VO 的关联名称(分类、主单位、辅单位、仓库名称) |
| | | */ |
| | | private void enrichItemRespVO(MdmItemRespVO resp) { |
| | | // 分类名称 |
| | | if (resp.getCategoryId() != null) { |
| | | MdmItemCategoryDO category = itemCategoryService.getItemCategory(resp.getCategoryId()); |
| | | if (category != null) { |
| | | resp.setCategoryName(category.getName()); |
| | | } |
| | | } |
| | | // 主单位名称 |
| | | if (resp.getUnitMeasureId() != null) { |
| | | MdmUnitMeasureDO unit = unitMeasureService.getUnitMeasure(resp.getUnitMeasureId()); |
| | | if (unit != null) { |
| | | resp.setUnitMeasureName(unit.getName()); |
| | | } |
| | | } |
| | | // 辅单位1名称 |
| | | if (resp.getUnitMeasureId2() != null) { |
| | | MdmUnitMeasureDO unit2 = unitMeasureService.getUnitMeasure(resp.getUnitMeasureId2()); |
| | | if (unit2 != null) { |
| | | resp.setUnitMeasureName2(unit2.getName()); |
| | | } |
| | | } |
| | | // 辅单位2名称 |
| | | if (resp.getUnitMeasureId3() != null) { |
| | | MdmUnitMeasureDO unit3 = unitMeasureService.getUnitMeasure(resp.getUnitMeasureId3()); |
| | | if (unit3 != null) { |
| | | resp.setUnitMeasureName3(unit3.getName()); |
| | | } |
| | | } |
| | | // 默认仓库名称 |
| | | if (resp.getWarehouseId() != null) { |
| | | MdmWarehouseDO warehouse = warehouseService.getWarehouse(resp.getWarehouseId()); |
| | | if (warehouse != null) { |
| | | resp.setWarehouseName(warehouse.getName()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 填充物料批次属性配置 |
| | | */ |
| | | private void enrichItemBatchConfig(MdmItemRespVO resp) { |
| | | MdmItemBatchConfigDO config = itemBatchConfigService.getItemBatchConfigByItemId(resp.getId()); |
| | | if (config != null) { |
| | | resp.setProduceDateFlag(config.getProduceDateFlag()); |
| | | resp.setExpireDateFlag(config.getExpireDateFlag()); |
| | | resp.setReceiptDateFlag(config.getReceiptDateFlag()); |
| | | resp.setVendorFlag(config.getVendorFlag()); |
| | | resp.setPurchaseOrderCodeFlag(config.getPurchaseOrderCodeFlag()); |
| | | resp.setLotNumberFlag(config.getLotNumberFlag()); |
| | | resp.setQualityStatusFlag(config.getQualityStatusFlag()); |
| | | } |
| | | } |
| | | |
| | | } |