| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mdm.controller.admin.item; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemPageReqVO; |
| | | 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.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.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 jakarta.annotation.Resource; |
| | | 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.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; |
| | | |
| | | @Tag(name = "管çåå° - MDM ç©æä¸»æ°æ®") |
| | | @RestController |
| | | @RequestMapping("/mdm/item") |
| | | @Validated |
| | | public class MdmItemController { |
| | | |
| | | @Resource |
| | | private MdmItemService itemService; |
| | | |
| | | @Resource |
| | | private MdmUnitMeasureService unitMeasureService; |
| | | |
| | | @Resource |
| | | private MdmWarehouseService warehouseService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "åå»ºç©æ") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:create')") |
| | | public CommonResult<Long> createItem(@Valid @RequestBody MdmItemSaveReqVO createReqVO) { |
| | | return success(itemService.createItem(createReqVO)); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @Operation(summary = "æ´æ°ç©æ") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:update')") |
| | | public CommonResult<Boolean> updateItem(@Valid @RequestBody MdmItemSaveReqVO updateReqVO) { |
| | | itemService.updateItem(updateReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @PutMapping("/update-status") |
| | | @Operation(summary = "æ´æ°ç©æç¶æ") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:update')") |
| | | public CommonResult<Boolean> updateItemStatus(@RequestBody MdmItemStatusUpdateReqVO reqVO) { |
| | | itemService.updateItemStatus(reqVO.getId(), reqVO.getStatus()); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "å é¤ç©æ") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true, example = "1") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:delete')") |
| | | public CommonResult<Boolean> deleteItem(@RequestParam("id") Long id) { |
| | | itemService.deleteItem(id); |
| | | 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); |
| | | MdmItemRespVO resp = BeanUtils.toBean(item, MdmItemRespVO.class); |
| | | if (resp != null) { |
| | | enrichItemRespVO(resp); |
| | | } |
| | | return success(resp); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "è·å¾ç©æå页") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:query')") |
| | | public CommonResult<PageResult<MdmItemRespVO>> getItemPage(@Valid MdmItemPageReqVO pageReqVO) { |
| | | PageResult<MdmItemDO> pageResult = itemService.getItemPage(pageReqVO); |
| | | // å
³èæ¥è¯¢è®¡éåä½åç§° |
| | | 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 -> { |
| | | 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())); |
| | | } |
| | | |
| | | @GetMapping("/list-by-ids") |
| | | @Operation(summary = "è·å¾ç©æå表") |
| | | @Parameter(name = "ids", description = "ç¼å·å表", required = true, example = "1,2,3") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:query')") |
| | | public CommonResult<List<MdmItemRespVO>> getItemList(@RequestParam("ids") List<Long> ids) { |
| | | List<MdmItemDO> list = itemService.getItemList(ids); |
| | | return success(BeanUtils.toBean(list, MdmItemRespVO.class)); |
| | | } |
| | | |
| | | /** |
| | | * å¡«å
ç©æååº VO çå
³èåç§°ï¼ä¸»åä½ãè¾
åä½ãä»åºåç§°ï¼ |
| | | */ |
| | | private void enrichItemRespVO(MdmItemRespVO resp) { |
| | | // 主åä½åç§° |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |