编写获取一个库位接口

This commit is contained in:
刘名喜 2024-12-17 09:39:31 +08:00
parent 2b8219d01e
commit 2e81d77dee
6 changed files with 121 additions and 88 deletions

View File

@ -121,4 +121,6 @@ public interface BaseKnifeMapper {
public Boolean isDuplicateRfid(String rfid);
List<BaseKnife> selectBaseKnifeNotValidList(BaseKnife baseKnifeWrapper);
List<String> selectAreaCodeList();
}

View File

@ -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<WmStorageLocationVo> 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<WmStorageLocation> list = wmStorageLocationService.selectWmStorageLocationList(wmStorageLocation);
ExcelUtil<WmStorageLocation> util = new ExcelUtil<WmStorageLocation>(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));

View File

@ -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);
}

View File

@ -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<WmStorageLocation> selectWmStorageLocationList(WmStorageLocation wmStorageLocation)
{
public List<WmStorageLocation> selectWmStorageLocationList(WmStorageLocation wmStorageLocation) {
return wmStorageLocationMapper.selectWmStorageLocationList(wmStorageLocation);
}
@ -72,16 +78,15 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService
* @return 库区设置
*/
@Override
public List<WmStorageLocationVo> selectWmStorageLocationListVo(WmStorageLocation wmStorageLocation)
{
public List<WmStorageLocationVo> 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<String> selectAreaCodeList = this.baseKnifeMapper.selectAreaCodeList();
// 获取库位列表
WmStorageArea wmStorageAreaQuery = new WmStorageArea();
wmStorageAreaQuery.setLocationId(wmStorageLocationByCode.getLocationId());
if (isBig) wmStorageAreaQuery.setAttr3(1L);
List<WmStorageArea> 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);
}
}

View File

@ -612,4 +612,10 @@
FROM BASE_KNIFE
WHERE RFID = #{value}
</select>
<select id="selectAreaCodeList" resultType="java.lang.String">
SELECT AREA_CODE
FROM BASE_KNIFE
GROUP BY AREA_CODE
</select>
</mapper>

View File

@ -69,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="enableFlag != null and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
and IS_DELETE = 0
</where>
ORDER BY AREA_CODE ASC
</select>
<select id="selectWmStorageAreaListVo" parameterType="AreaVo" resultMap="WmStorageAreaVoResult">