From 2e81d77dee01a6b1c5706d6faf8fbab6abe5f678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=90=8D=E5=96=9C?= Date: Tue, 17 Dec 2024 09:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=8E=B7=E5=8F=96=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=BA=93=E4=BD=8D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ktg/mes/md/mapper/BaseKnifeMapper.java | 2 + .../WmStorageLocationController.java | 72 ++++++-------- .../wm/service/IWmStorageLocationService.java | 34 +++++-- .../impl/WmStorageLocationServiceImpl.java | 94 ++++++++++++------- .../resources/mapper/md/BaseKnifeMapper.xml | 6 ++ .../mapper/wm/WmStorageAreaMapper.xml | 1 + 6 files changed, 121 insertions(+), 88 deletions(-) diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java b/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java index 3eba3c4..43bfe59 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java +++ b/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java @@ -121,4 +121,6 @@ public interface BaseKnifeMapper { public Boolean isDuplicateRfid(String rfid); List selectBaseKnifeNotValidList(BaseKnife baseKnifeWrapper); + + List selectAreaCodeList(); } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmStorageLocationController.java b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmStorageLocationController.java index db247ce..06ff161 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmStorageLocationController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmStorageLocationController.java @@ -1,42 +1,34 @@ package com.ktg.mes.wm.controller; -import java.util.List; -import javax.servlet.http.HttpServletResponse; - -import com.ktg.common.constant.UserConstants; -import com.ktg.mes.wm.domain.vo.WmStorageLocationVo; -import com.ktg.mes.wm.service.IWmStorageAreaService; -import com.ktg.mes.wm.utils.WmBarCodeUtil; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.ktg.common.annotation.Log; +import com.ktg.common.constant.UserConstants; import com.ktg.common.core.controller.BaseController; import com.ktg.common.core.domain.AjaxResult; -import com.ktg.common.enums.BusinessType; -import com.ktg.mes.wm.domain.WmStorageLocation; -import com.ktg.mes.wm.service.IWmStorageLocationService; -import com.ktg.common.utils.poi.ExcelUtil; import com.ktg.common.core.page.TableDataInfo; +import com.ktg.common.enums.BusinessType; +import com.ktg.common.utils.poi.ExcelUtil; +import com.ktg.mes.wm.domain.WmStorageLocation; +import com.ktg.mes.wm.domain.vo.WmStorageLocationVo; +import com.ktg.mes.wm.service.IWmStorageAreaService; +import com.ktg.mes.wm.service.IWmStorageLocationService; +import com.ktg.mes.wm.utils.WmBarCodeUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * 库区设置Controller - * + * * @author yinjinlu * @date 2022-05-07 */ @RestController @RequestMapping("/mes/wm/location") -public class WmStorageLocationController extends BaseController -{ +public class WmStorageLocationController extends BaseController { @Autowired private IWmStorageLocationService wmStorageLocationService; @@ -50,8 +42,7 @@ public class WmStorageLocationController extends BaseController * 查询库区设置列表 */ @GetMapping("/list") - public TableDataInfo list(WmStorageLocation wmStorageLocation) - { + public TableDataInfo list(WmStorageLocation wmStorageLocation) { startPage(); List list = wmStorageLocationService.selectWmStorageLocationListVo(wmStorageLocation); return getDataTable(list); @@ -63,8 +54,7 @@ public class WmStorageLocationController extends BaseController @PreAuthorize("@ss.hasPermi('mes:wm:location:export')") @Log(title = "库区设置", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, WmStorageLocation wmStorageLocation) - { + public void export(HttpServletResponse response, WmStorageLocation wmStorageLocation) { List list = wmStorageLocationService.selectWmStorageLocationList(wmStorageLocation); ExcelUtil util = new ExcelUtil(WmStorageLocation.class); util.exportExcel(response, list, "库区设置数据"); @@ -75,8 +65,7 @@ public class WmStorageLocationController extends BaseController */ @PreAuthorize("@ss.hasPermi('mes:wm:location:query')") @GetMapping(value = "/{locationId}") - public AjaxResult getInfo(@PathVariable("locationId") Long locationId) - { + public AjaxResult getInfo(@PathVariable("locationId") Long locationId) { return AjaxResult.success(wmStorageLocationService.selectWmStorageLocationVoByLocationId(locationId)); } @@ -86,16 +75,15 @@ public class WmStorageLocationController extends BaseController @PreAuthorize("@ss.hasPermi('mes:wm:location:add')") @Log(title = "库区设置", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody WmStorageLocation wmStorageLocation) - { - if(UserConstants.NOT_UNIQUE.equals(wmStorageLocationService.checkLocationCodeUnique(wmStorageLocation))){ + public AjaxResult add(@RequestBody WmStorageLocation wmStorageLocation) { + if (UserConstants.NOT_UNIQUE.equals(wmStorageLocationService.checkLocationCodeUnique(wmStorageLocation))) { return AjaxResult.error("库区编码已存在!"); } - if(UserConstants.NOT_UNIQUE.equals(wmStorageLocationService.checkLocationNameUnique(wmStorageLocation))){ + if (UserConstants.NOT_UNIQUE.equals(wmStorageLocationService.checkLocationNameUnique(wmStorageLocation))) { return AjaxResult.error("库区名称已存在!"); } wmStorageLocationService.insertWmStorageLocation(wmStorageLocation); - wmBarCodeUtil.generateBarCode(UserConstants.BARCODE_TYPE_WAREHOUSE,wmStorageLocation.getLocationId(),wmStorageLocation.getLocationCode(),wmStorageLocation.getLocationName()); + wmBarCodeUtil.generateBarCode(UserConstants.BARCODE_TYPE_WAREHOUSE, wmStorageLocation.getLocationId(), wmStorageLocation.getLocationCode(), wmStorageLocation.getLocationName()); return AjaxResult.success(wmStorageLocation.getLocationId()); } @@ -105,8 +93,7 @@ public class WmStorageLocationController extends BaseController @PreAuthorize("@ss.hasPermi('mes:wm:location:edit')") @Log(title = "库区设置", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody WmStorageLocation wmStorageLocation) - { + public AjaxResult edit(@RequestBody WmStorageLocation wmStorageLocation) { return toAjax(wmStorageLocationService.updateWmStorageLocation(wmStorageLocation)); } @@ -116,13 +103,12 @@ public class WmStorageLocationController extends BaseController @PreAuthorize("@ss.hasPermi('mes:wm:location:remove')") @Log(title = "库区设置", businessType = BusinessType.DELETE) @Transactional - @DeleteMapping("/{locationIds}") - public AjaxResult remove(@PathVariable Long[] locationIds) - { + @DeleteMapping("/{locationIds}") + public AjaxResult remove(@PathVariable Long[] locationIds) { //TODO:库区删除之前的逻辑校验 - for (Long locationId: locationIds - ) { + for (Long locationId : locationIds + ) { wmStorageAreaService.deleteByLocationId(locationId); } return toAjax(wmStorageLocationService.deleteWmStorageLocationByLocationIds(locationIds)); diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmStorageLocationService.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmStorageLocationService.java index af5a02d..187585a 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmStorageLocationService.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmStorageLocationService.java @@ -1,20 +1,21 @@ package com.ktg.mes.wm.service; -import java.util.List; +import com.ktg.mes.wm.domain.WmStorageArea; import com.ktg.mes.wm.domain.WmStorageLocation; import com.ktg.mes.wm.domain.vo.WmStorageLocationVo; +import java.util.List; + /** * 库区设置Service接口 - * + * * @author yinjinlu * @date 2022-05-07 */ -public interface IWmStorageLocationService -{ +public interface IWmStorageLocationService { /** * 查询库区设置 - * + * * @param locationId 库区设置主键 * @return 库区设置 */ @@ -31,6 +32,7 @@ public interface IWmStorageLocationService /** * 根据库区编码查询库区 + * * @param locationCode * @return */ @@ -39,7 +41,7 @@ public interface IWmStorageLocationService /** * 查询库区设置列表 - * + * * @param wmStorageLocation 库区设置 * @return 库区设置集合 */ @@ -55,6 +57,7 @@ public interface IWmStorageLocationService /** * 检查库区编码是否唯一 + * * @param wmStorageLocation * @return */ @@ -62,6 +65,7 @@ public interface IWmStorageLocationService /** * 检查库区名称是否唯一 + * * @param wmStorageLocation * @return */ @@ -69,7 +73,7 @@ public interface IWmStorageLocationService /** * 新增库区设置 - * + * * @param wmStorageLocation 库区设置 * @return 结果 */ @@ -77,7 +81,7 @@ public interface IWmStorageLocationService /** * 修改库区设置 - * + * * @param wmStorageLocation 库区设置 * @return 结果 */ @@ -85,7 +89,7 @@ public interface IWmStorageLocationService /** * 批量删除库区设置 - * + * * @param locationIds 需要删除的库区设置主键集合 * @return 结果 */ @@ -93,7 +97,7 @@ public interface IWmStorageLocationService /** * 删除库区设置信息 - * + * * @param locationId 库区设置主键 * @return 结果 */ @@ -101,8 +105,18 @@ public interface IWmStorageLocationService /** * 根据仓库删除对应的库区 + * * @param warehouseId * @return */ public int deleteByWarehouseId(Long warehouseId); + + /** + * 查询一个库位 + * + * @param code 库区编码 + * @param isBig 是否大件 + * @return 库位 + */ + WmStorageArea queryOneAreaByLocationCode(String code, Boolean isBig); } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmStorageLocationServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmStorageLocationServiceImpl.java index 9a25b15..bb9a120 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmStorageLocationServiceImpl.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmStorageLocationServiceImpl.java @@ -1,39 +1,46 @@ package com.ktg.mes.wm.service.impl; -import java.util.List; - import com.ktg.common.constant.UserConstants; import com.ktg.common.utils.DateUtils; import com.ktg.common.utils.StringUtils; +import com.ktg.mes.md.mapper.BaseKnifeMapper; +import com.ktg.mes.wm.domain.WmStorageArea; +import com.ktg.mes.wm.domain.WmStorageLocation; import com.ktg.mes.wm.domain.vo.WmStorageLocationVo; -import org.apache.catalina.User; +import com.ktg.mes.wm.mapper.WmStorageAreaMapper; +import com.ktg.mes.wm.mapper.WmStorageLocationMapper; +import com.ktg.mes.wm.service.IWmStorageLocationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.ktg.mes.wm.mapper.WmStorageLocationMapper; -import com.ktg.mes.wm.domain.WmStorageLocation; -import com.ktg.mes.wm.service.IWmStorageLocationService; + +import java.util.List; +import java.util.stream.Collectors; /** * 库区设置Service业务层处理 - * + * * @author yinjinlu * @date 2022-05-07 */ @Service -public class WmStorageLocationServiceImpl implements IWmStorageLocationService -{ +public class WmStorageLocationServiceImpl implements IWmStorageLocationService { @Autowired private WmStorageLocationMapper wmStorageLocationMapper; + @Autowired + private BaseKnifeMapper baseKnifeMapper; + + @Autowired + private WmStorageAreaMapper wmStorageAreaMapper; + /** * 查询库区设置 - * + * * @param locationId 库区设置主键 * @return 库区设置 */ @Override - public WmStorageLocation selectWmStorageLocationByLocationId(Long locationId) - { + public WmStorageLocation selectWmStorageLocationByLocationId(Long locationId) { return wmStorageLocationMapper.selectWmStorageLocationByLocationId(locationId); } @@ -44,10 +51,10 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService * @return 库区设置 */ @Override - public WmStorageLocationVo selectWmStorageLocationVoByLocationId(Long locationId) - { + public WmStorageLocationVo selectWmStorageLocationVoByLocationId(Long locationId) { return wmStorageLocationMapper.selectWmStorageLocationByVoLocationId(locationId); } + @Override public WmStorageLocation selectWmStorageLocationByLocationCode(String locationCode) { return wmStorageLocationMapper.selectWmStorageLocationByLocationCode(locationCode); @@ -55,13 +62,12 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService /** * 查询库区设置列表 - * + * * @param wmStorageLocation 库区设置 * @return 库区设置 */ @Override - public List selectWmStorageLocationList(WmStorageLocation wmStorageLocation) - { + public List selectWmStorageLocationList(WmStorageLocation wmStorageLocation) { return wmStorageLocationMapper.selectWmStorageLocationList(wmStorageLocation); } @@ -72,16 +78,15 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService * @return 库区设置 */ @Override - public List selectWmStorageLocationListVo(WmStorageLocation wmStorageLocation) - { + public List selectWmStorageLocationListVo(WmStorageLocation wmStorageLocation) { return wmStorageLocationMapper.selectWmStorageLocationListVo(wmStorageLocation); } @Override public String checkLocationCodeUnique(WmStorageLocation wmStorageLocation) { WmStorageLocation location = wmStorageLocationMapper.checkLocationCodeUnique(wmStorageLocation); - Long locationId = wmStorageLocation.getLocationId()==null?-1L:wmStorageLocation.getLocationId(); - if(StringUtils.isNotNull(location) && location.getLocationId().longValue() != locationId.longValue()){ + Long locationId = wmStorageLocation.getLocationId() == null ? -1L : wmStorageLocation.getLocationId(); + if (StringUtils.isNotNull(location) && location.getLocationId().longValue() != locationId.longValue()) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -90,8 +95,8 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService @Override public String checkLocationNameUnique(WmStorageLocation wmStorageLocation) { WmStorageLocation location = wmStorageLocationMapper.checkLocationNameUnique(wmStorageLocation); - Long locationId = wmStorageLocation.getLocationId()==null?-1L:wmStorageLocation.getLocationId(); - if(StringUtils.isNotNull(location) && location.getLocationId().longValue() != locationId.longValue()){ + Long locationId = wmStorageLocation.getLocationId() == null ? -1L : wmStorageLocation.getLocationId(); + if (StringUtils.isNotNull(location) && location.getLocationId().longValue() != locationId.longValue()) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -99,51 +104,47 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService /** * 新增库区设置 - * + * * @param wmStorageLocation 库区设置 * @return 结果 */ @Override - public int insertWmStorageLocation(WmStorageLocation wmStorageLocation) - { + public int insertWmStorageLocation(WmStorageLocation wmStorageLocation) { wmStorageLocation.setCreateTime(DateUtils.getNowDate()); return wmStorageLocationMapper.insertWmStorageLocation(wmStorageLocation); } /** * 修改库区设置 - * + * * @param wmStorageLocation 库区设置 * @return 结果 */ @Override - public int updateWmStorageLocation(WmStorageLocation wmStorageLocation) - { + public int updateWmStorageLocation(WmStorageLocation wmStorageLocation) { wmStorageLocation.setUpdateTime(DateUtils.getNowDate()); return wmStorageLocationMapper.updateWmStorageLocation(wmStorageLocation); } /** * 批量删除库区设置 - * + * * @param locationIds 需要删除的库区设置主键 * @return 结果 */ @Override - public int deleteWmStorageLocationByLocationIds(Long[] locationIds) - { + public int deleteWmStorageLocationByLocationIds(Long[] locationIds) { return wmStorageLocationMapper.deleteWmStorageLocationByLocationIds(locationIds); } /** * 删除库区设置信息 - * + * * @param locationId 库区设置主键 * @return 结果 */ @Override - public int deleteWmStorageLocationByLocationId(Long locationId) - { + public int deleteWmStorageLocationByLocationId(Long locationId) { return wmStorageLocationMapper.deleteWmStorageLocationByLocationId(locationId); } @@ -151,4 +152,27 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService public int deleteByWarehouseId(Long warehouseId) { return wmStorageLocationMapper.deleteByWarehouseId(warehouseId); } + + @Override + public WmStorageArea queryOneAreaByLocationCode(String code, Boolean isBig) { + // 获取库区 + WmStorageLocation wmStorageLocationByCode = this.wmStorageLocationMapper.selectWmStorageLocationByLocationCode(code); + if (wmStorageLocationByCode == null) throw new RuntimeException("自动获取库位失败,该库区不存在"); + + // 获取台账中已经使用的库位编码 + List selectAreaCodeList = this.baseKnifeMapper.selectAreaCodeList(); + + // 获取库位列表 + WmStorageArea wmStorageAreaQuery = new WmStorageArea(); + wmStorageAreaQuery.setLocationId(wmStorageLocationByCode.getLocationId()); + if (isBig) wmStorageAreaQuery.setAttr3(1L); + List wmStorageAreaList = this.wmStorageAreaMapper.selectWmStorageAreaList(wmStorageAreaQuery).stream() + // 过滤掉全部存在物品的库位 + .filter(it -> !selectAreaCodeList.contains(it.getAreaCode())) + .collect(Collectors.toList()); + if (wmStorageAreaList.isEmpty()) throw new RuntimeException("自动获取库位失败,无可用库位"); + + // 返回第一个可用的库位 + return wmStorageAreaList.get(0); + } } diff --git a/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml b/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml index 9bd573d..ad81fce 100644 --- a/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml +++ b/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml @@ -612,4 +612,10 @@ FROM BASE_KNIFE WHERE RFID = #{value} + + \ No newline at end of file diff --git a/ktg-mes/src/main/resources/mapper/wm/WmStorageAreaMapper.xml b/ktg-mes/src/main/resources/mapper/wm/WmStorageAreaMapper.xml index 90b2a73..2dd98a8 100644 --- a/ktg-mes/src/main/resources/mapper/wm/WmStorageAreaMapper.xml +++ b/ktg-mes/src/main/resources/mapper/wm/WmStorageAreaMapper.xml @@ -69,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and enable_flag = #{enableFlag} and IS_DELETE = 0 + ORDER BY AREA_CODE ASC