Browse Source

盘点优化

master
常熟吴彦祖 6 months ago
parent
commit
5478605ca0
  1. 24
      src/main/java/com/gaotao/modules/check/controller/PhysicalInventoryController.java
  2. 21
      src/main/java/com/gaotao/modules/check/mapper/PhysicalInventoryMapper.java
  3. 16
      src/main/java/com/gaotao/modules/check/service/PhysicalInventoryService.java
  4. 161
      src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java
  5. 18
      src/main/resources/mapper/check/PhysicalInventoryMapper.xml

24
src/main/java/com/gaotao/modules/check/controller/PhysicalInventoryController.java

@ -112,6 +112,30 @@ public class PhysicalInventoryController {
return R.ok().put("result", result); return R.ok().put("result", result);
} }
/**
* @Description 一键添加物料 - 根据物料号精确查询所有标签并添加到盘点单 - rqrq
* @param query 包含sitecountNosearchPartNousername
* @return R
* @author rqrq
*/
@PostMapping("/quickAddMaterialByPartNo")
public R quickAddMaterialByPartNo(@RequestBody CountHeaderData query) {
int result = physicalInventoryService.quickAddMaterialByPartNo(query);
return R.ok().put("result", result);
}
/**
* @Description 一键删除物料 - 根据物料号删除盘点单中该物料的所有标签 - rqrq
* @param query 包含sitecountNosearchPartNo
* @return R
* @author rqrq
*/
@PostMapping("/deleteMaterialByPartNo")
public R deleteMaterialByPartNo(@RequestBody CountHeaderData query) {
int result = physicalInventoryService.deleteMaterialByPartNo(query);
return R.ok().put("result", result);
}
/** /**
* @Description 下达盘点单 - rqrq * @Description 下达盘点单 - rqrq
* @param query 包含sitecountNousername * @param query 包含sitecountNousername

21
src/main/java/com/gaotao/modules/check/mapper/PhysicalInventoryMapper.java

@ -497,7 +497,7 @@ public interface PhysicalInventoryMapper extends BaseMapper<CountHeader> {
*/ */
int deleteCountLabel(@Param("site") String site, @Param("countNo") String countNo); int deleteCountLabel(@Param("site") String site, @Param("countNo") String countNo);
/**
/**
* @Description 删除盘点栈板子表 - rqrq * @Description 删除盘点栈板子表 - rqrq
* @param site 工厂编码 * @param site 工厂编码
* @param countNo 盘点单号 * @param countNo 盘点单号
@ -506,6 +506,25 @@ public interface PhysicalInventoryMapper extends BaseMapper<CountHeader> {
*/ */
int deleteCountPallet(@Param("site") String site, @Param("countNo") String countNo); int deleteCountPallet(@Param("site") String site, @Param("countNo") String countNo);
/**
* @Description 根据物料号删除盘点标签 - rqrq
* @param site 工厂编码
* @param countNo 盘点单号
* @param partNo 物料号
* @return int 删除数量
* @author rqrq
*/
int deleteCountLabelByPartNo(@Param("site") String site, @Param("countNo") String countNo, @Param("partNo") String partNo);
/**
* @Description 清理没有标签的栈板记录 - rqrq
* @param site 工厂编码
* @param countNo 盘点单号
* @return int 删除数量
* @author rqrq
*/
int deleteEmptyCountPallets(@Param("site") String site, @Param("countNo") String countNo);
// ==================== 推送WCS相关 ==================== // ==================== 推送WCS相关 ====================
/** /**

16
src/main/java/com/gaotao/modules/check/service/PhysicalInventoryService.java

@ -74,6 +74,22 @@ public interface PhysicalInventoryService {
*/ */
int addMaterialToCount(CountHeaderData query); int addMaterialToCount(CountHeaderData query);
/**
* @Description 一键添加物料 - 根据物料号精确查询所有标签并添加到盘点单 - rqrq
* @param query 包含sitecountNosearchPartNousername
* @return int 新增标签数量
* @author rqrq
*/
int quickAddMaterialByPartNo(CountHeaderData query);
/**
* @Description 一键删除物料 - 根据物料号删除盘点单中该物料的所有标签 - rqrq
* @param query 包含sitecountNosearchPartNo
* @return int 删除标签数量
* @author rqrq
*/
int deleteMaterialByPartNo(CountHeaderData query);
/** /**
* @Description 下达盘点单 - rqrq * @Description 下达盘点单 - rqrq
* @param query 包含sitecountNousername * @param query 包含sitecountNousername

161
src/main/java/com/gaotao/modules/check/service/impl/PhysicalInventoryServiceImpl.java

@ -554,6 +554,167 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM
return countLabels.size(); return countLabels.size();
} }
@Override
@Transactional(rollbackFor = Exception.class)
public int quickAddMaterialByPartNo(CountHeaderData query) {
log.info("quickAddMaterialByPartNo 开始,site: {}, countNo: {}, partNo: {}",
query.getSite(), query.getCountNo(), query.getSearchPartNo());
// 1. 参数校验 - rqrq
if (!StringUtils.hasText(query.getSite())) {
throw new RuntimeException("工厂编码不能为空");
}
if (!StringUtils.hasText(query.getCountNo())) {
throw new RuntimeException("盘点单号不能为空");
}
if (!StringUtils.hasText(query.getSearchPartNo())) {
throw new RuntimeException("物料号不能为空");
}
// 2. 校验盘点单状态 - rqrq
CountHeaderData header = getCountHeaderByNo(query.getSite(), query.getCountNo());
if (header == null) {
throw new RuntimeException("盘点单不存在");
}
if (!CountHeader.STATUS_DRAFT.equals(header.getStatus())) {
throw new RuntimeException("只有草稿状态的盘点单才能添加物料");
}
if (!CountHeader.COUNT_TYPE_MANUAL.equals(header.getCountType())) {
throw new RuntimeException("只有手工盘点单才能添加物料");
}
// 3. 获取当前盘点单已有的标签用于去重- rqrq
CountLabelData labelQuery = new CountLabelData();
labelQuery.setSite(query.getSite());
labelQuery.setCountNo(query.getCountNo());
List<CountLabelData> existingLabels = baseMapper.searchCountLabelList(labelQuery);
Set<String> existingUnitIds = existingLabels.stream()
.map(CountLabelData::getUnitId)
.collect(Collectors.toSet());
// 4. 根据物料号精确查询所有标签在立库中的- rqrq
CountMaterialSummary labelQueryParam = new CountMaterialSummary();
labelQueryParam.setSite(query.getSite());
labelQueryParam.setSearchPartNo(query.getSearchPartNo()); // 精确匹配
List<CountLabelInfo> allLabels = baseMapper.queryLabelsByMaterial(labelQueryParam);
// 5. 过滤出未在盘点单中的标签 - rqrq
List<CountLabelInfo> newLabels = allLabels.stream()
.filter(label -> query.getSearchPartNo().equals(label.getPartNo())) // 精确匹配物料号
.filter(label -> !existingUnitIds.contains(label.getUnitId()))
.collect(Collectors.toList());
if (newLabels.isEmpty()) {
throw new RuntimeException("没有找到新的可添加标签(物料号: " + query.getSearchPartNo() + ")");
}
// 6. 收集涉及的栈板 - rqrq
Set<String> newPallets = new LinkedHashSet<>();
for (CountLabelInfo label : newLabels) {
if (label.getPalletId() != null) {
newPallets.add(label.getPalletId());
}
}
log.info("新增标签数: {},涉及托盘数: {}", newLabels.size(), newPallets.size());
// 7. 创建盘点标签子表 - rqrq
List<CountLabel> countLabels = new ArrayList<>();
for (CountLabelInfo labelInfo : newLabels) {
CountLabel countLabel = createCountLabel(query.getSite(), query.getCountNo(), labelInfo,
CountLabel.LABEL_TYPE_ASSIGNED, query.getUsername());
countLabels.add(countLabel);
}
if (!countLabels.isEmpty()) {
baseMapper.batchInsertCountLabel(countLabels);
}
// 8. 创建/更新盘点栈板子表 - rqrq
Integer maxSeqNo = baseMapper.getMaxSeqNo(query.getSite(), query.getCountNo());
int seqNo = (maxSeqNo == null ? 0 : maxSeqNo) + 1;
List<CountPallet> countPallets = new ArrayList<>();
for (String palletId : newPallets) {
int exists = baseMapper.checkCountPalletExists(query.getSite(), query.getCountNo(), palletId);
if (exists == 0) {
int labelCount = (int) countLabels.stream()
.filter(l -> palletId.equals(l.getPalletId()))
.count();
Integer locationZ = 1;
CountLabelInfo firstLabel = newLabels.stream()
.filter(l -> palletId.equals(l.getPalletId()))
.findFirst()
.orElse(null);
if (firstLabel != null && firstLabel.getLocationZ() != null) {
locationZ = firstLabel.getLocationZ().intValue();
}
CountPallet countPallet = new CountPallet();
countPallet.setSite(query.getSite());
countPallet.setCountNo(query.getCountNo());
countPallet.setSeqNo(seqNo++);
countPallet.setPalletId(palletId);
countPallet.setCountFlag(CountPallet.COUNT_FLAG_NO);
countPallet.setLabelCount(labelCount);
countPallet.setCheckedCount(0);
countPallet.setLocationZ(locationZ);
countPallet.setCreatedBy(query.getUsername());
countPallets.add(countPallet);
}
}
if (!countPallets.isEmpty()) {
baseMapper.batchInsertCountPallet(countPallets);
}
log.info("quickAddMaterialByPartNo 结束,新增标签数: {}", countLabels.size());
return countLabels.size();
}
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteMaterialByPartNo(CountHeaderData query) {
log.info("deleteMaterialByPartNo 开始,site: {}, countNo: {}, partNo: {}",
query.getSite(), query.getCountNo(), query.getSearchPartNo());
// 1. 参数校验 - rqrq
if (!StringUtils.hasText(query.getSite())) {
throw new RuntimeException("工厂编码不能为空");
}
if (!StringUtils.hasText(query.getCountNo())) {
throw new RuntimeException("盘点单号不能为空");
}
if (!StringUtils.hasText(query.getSearchPartNo())) {
throw new RuntimeException("物料号不能为空");
}
// 2. 校验盘点单状态 - rqrq
CountHeaderData header = getCountHeaderByNo(query.getSite(), query.getCountNo());
if (header == null) {
throw new RuntimeException("盘点单不存在");
}
if (!CountHeader.STATUS_DRAFT.equals(header.getStatus())) {
throw new RuntimeException("只有草稿状态的盘点单才能删除物料");
}
if (!CountHeader.COUNT_TYPE_MANUAL.equals(header.getCountType())) {
throw new RuntimeException("只有手工盘点单才能删除物料");
}
// 3. 删除该物料的所有标签 - rqrq
int deleteCount = baseMapper.deleteCountLabelByPartNo(query.getSite(), query.getCountNo(), query.getSearchPartNo());
log.info("已删除标签数: {}", deleteCount);
// 4. 清理没有标签的栈板 - rqrq
int cleanedPallets = baseMapper.deleteEmptyCountPallets(query.getSite(), query.getCountNo());
log.info("已清理空栈板数: {}", cleanedPallets);
log.info("deleteMaterialByPartNo 结束,删除标签数: {}", deleteCount);
return deleteCount;
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int releaseCount(CountHeaderData query) { public int releaseCount(CountHeaderData query) {

18
src/main/resources/mapper/check/PhysicalInventoryMapper.xml

@ -810,7 +810,7 @@
LEFT JOIN agv_station s ON p.location_code = s.station_code LEFT JOIN agv_station s ON p.location_code = s.station_code
WHERE h.site = #{query.site} AND p.pallet_id IS NOT NULL and p.wcs_location is not null WHERE h.site = #{query.site} AND p.pallet_id IS NOT NULL and p.wcs_location is not null
<if test="query.searchPartNo != null and query.searchPartNo != ''"> <if test="query.searchPartNo != null and query.searchPartNo != ''">
AND h.part_no LIKE '%' + #{query.searchPartNo} + '%'
AND h.part_no LIKE #{query.searchPartNo}
</if> </if>
<if test="query.searchBatchNo != null and query.searchBatchNo != ''"> <if test="query.searchBatchNo != null and query.searchBatchNo != ''">
AND h.batch_no LIKE '%' + #{query.searchBatchNo} + '%' AND h.batch_no LIKE '%' + #{query.searchBatchNo} + '%'
@ -899,6 +899,22 @@
DELETE FROM count_pallet WHERE site = #{site} AND count_no = #{countNo} DELETE FROM count_pallet WHERE site = #{site} AND count_no = #{countNo}
</delete> </delete>
<!-- rqrq - 根据物料号删除盘点标签 -->
<delete id="deleteCountLabelByPartNo">
DELETE FROM count_label
WHERE site = #{site} AND count_no = #{countNo} AND part_no = #{partNo}
</delete>
<!-- rqrq - 清理没有标签的栈板记录 -->
<delete id="deleteEmptyCountPallets">
DELETE FROM count_pallet
WHERE site = #{site} AND count_no = #{countNo}
AND pallet_id NOT IN (
SELECT DISTINCT pallet_id FROM count_label
WHERE site = #{site} AND count_no = #{countNo}
)
</delete>
<!-- ==================== 推送WCS相关 ==================== --> <!-- ==================== 推送WCS相关 ==================== -->
<!-- rqrq - 查询未推送的栈板列表(按层均匀分布排序)--> <!-- rqrq - 查询未推送的栈板列表(按层均匀分布排序)-->

Loading…
Cancel
Save