Browse Source

采购入库物料属性不存在则默认创建

master
han\hanst 2 months ago
parent
commit
9552fff5a4
  1. 10
      src/main/java/com/gaotao/modules/factory/controller/PartAttributeController.java
  2. 61
      src/main/java/com/gaotao/modules/po/service/impl/PoServiceImpl.java
  3. 57
      src/main/java/com/gaotao/modules/production/service/impl/ProductionInboundServiceImpl.java
  4. 7
      src/main/resources/mapper/automatedWarehouse/AgvTaskMapper.xml

10
src/main/java/com/gaotao/modules/factory/controller/PartAttributeController.java

@ -30,7 +30,7 @@ public class PartAttributeController extends AbstractController {
if (queryDto.getSite() == null || queryDto.getSite().trim().isEmpty()) {
queryDto.setSite(getUser().getSite());
}
PageUtils page = partAttributeService.getPartAttributeList(queryDto);
return R.ok().put("page", page);
}
@ -53,7 +53,7 @@ public class PartAttributeController extends AbstractController {
if (partAttribute.getSite() == null || partAttribute.getSite().trim().isEmpty()) {
partAttribute.setSite(getUser().getSite());
}
return partAttributeService.savePartAttribute(partAttribute);
}
@ -66,7 +66,7 @@ public class PartAttributeController extends AbstractController {
if (partAttribute.getSite() == null || partAttribute.getSite().trim().isEmpty()) {
partAttribute.setSite(getUser().getSite());
}
return partAttributeService.updatePartAttribute(partAttribute);
}
@ -74,8 +74,8 @@ public class PartAttributeController extends AbstractController {
* 删除料件属性
*/
@PostMapping("/delete")
public R delete(@RequestParam String site, @RequestParam String partNo) {
return partAttributeService.deletePartAttribute(site, partNo);
public R delete(@RequestBody PartAttribute partAttribute) {
return partAttributeService.deletePartAttribute(partAttribute.getSite(), partAttribute.getPartNo());
}
/**

61
src/main/java/com/gaotao/modules/po/service/impl/PoServiceImpl.java

@ -1,12 +1,15 @@
package com.gaotao.modules.po.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gaotao.common.exception.XJException;
import com.gaotao.common.utils.*;
import com.gaotao.modules.factory.dao.AccessSiteMapper;
import com.gaotao.modules.factory.dao.PartAttributeMapper;
import com.gaotao.modules.factory.entity.PartAttribute;
import com.gaotao.modules.factory.entity.Site;
import lombok.extern.slf4j.Slf4j;
@ -77,6 +80,8 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
private com.gaotao.modules.handlingunit.service.HandlingUnitIdLogService handlingUnitIdLogService;
@Autowired
private LocationService locationService;
@Autowired
private PartAttributeMapper partAttributeMapper;
@Value("${custom.ifs-url}")
private String ifsUrl;
@ -226,6 +231,8 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
if ("N".equals(inData.getNeedCheck())) {
genInventoryStock(inData, transHeader, receiptDetail);
}
// 处理料件属性创建或更新
handlePartAttribute(inData);
// 同步到IFS
syncToIFS(inData);
/* Map<String, Object> weiwaiMap = isWeiwai(inData);
@ -789,6 +796,60 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
return poReceiptDetail;
}
/**
* 处理料件属性PartAttribute
* <p><b>业务规则</b></p>
* <ul>
* <li>如果料件属性不存在则新建默认值进立库=Y常用料=Y机械臂抓取=Y高度=传入值</li>
* <li>如果料件属性已存在且传入了高度则只更新高度</li>
* </ul>
*
* @param inData 采购入库数据
*/
private void handlePartAttribute(TransDetailDto inData) {
try {
String site = inData.getSite();
String partNo = inData.getPartNo();
BigDecimal height = inData.getHeight();
log.info("开始处理料件属性,site: {}, partNo: {}, height: {}", site, partNo, height);
// 检查料件属性是否已存在
PartAttribute existing = partAttributeMapper.getPartAttributeByKey(site, partNo);
if (existing == null) {
// 不存在则新建设置默认值
PartAttribute partAttribute = new PartAttribute();
partAttribute.setSite(site);
partAttribute.setPartNo(partNo);
partAttribute.setIsInWh("Y"); // 默认进立库
partAttribute.setIsCommonlyUsed("Y"); // 默认常用料
partAttribute.setIsRobotPick("Y"); // 默认机械臂抓取
partAttribute.setHeight(height != null ? height : BigDecimal.ZERO); // 高度不能为空默认0
partAttributeMapper.insert(partAttribute);
log.info("料件属性创建成功,site: {}, partNo: {}, height: {}", site, partNo, height);
} else {
// 已存在且传入了高度则只更新高度
if (height != null) {
// 使用 UpdateWrapper 按照联合主键site + partNo更新
LambdaUpdateWrapper<PartAttribute> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PartAttribute::getSite, site)
.eq(PartAttribute::getPartNo, partNo)
.set(PartAttribute::getHeight, height);
partAttributeMapper.update(null, updateWrapper);
log.info("料件属性高度更新成功,site: {}, partNo: {}, 新高度: {}", site, partNo, height);
} else {
log.debug("料件属性已存在且未传入高度,跳过更新,site: {}, partNo: {}", site, partNo);
}
}
} catch (Exception e) {
// 不抛出异常避免影响主流程
log.error("处理料件属性失败,site: {}, partNo: {}, 错误: {}",
inData.getSite(), inData.getPartNo(), e.getMessage(), e);
}
}
@Override
public List<Map<String, Object>> getPoReceiveRecords(String poNumber, String site, String warehouseId) {
return poReceiptDetailService.getPoReceiveRecords(poNumber, site, warehouseId);

57
src/main/java/com/gaotao/modules/production/service/impl/ProductionInboundServiceImpl.java

@ -1,5 +1,6 @@
package com.gaotao.modules.production.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -9,6 +10,8 @@ import com.gaotao.common.utils.HttpUtils;
import com.gaotao.common.utils.IfsErrorMessageUtils;
import com.gaotao.modules.api.entity.IfsShopOrder;
import com.gaotao.modules.api.service.IfsApiService;
import com.gaotao.modules.factory.dao.PartAttributeMapper;
import com.gaotao.modules.factory.entity.PartAttribute;
import com.gaotao.modules.notify.entity.vo.ShopOrderMaterialVo;
import com.gaotao.modules.handlingunit.entity.HandlingUnit;
import com.gaotao.modules.handlingunit.entity.HandlingUnitDetail;
@ -86,6 +89,9 @@ public class ProductionInboundServiceImpl implements ProductionInboundService {
@Autowired
private LocationService locationService;
@Autowired
private PartAttributeMapper partAttributeMapper;
@Autowired
private IfsApiService ifsApiService;
@ -644,7 +650,8 @@ public class ProductionInboundServiceImpl implements ProductionInboundService {
// 6. 生成库存
genInventoryStock(transDetailDto, transHeader);
log.info("生成库存成功");
// 处理料件属性创建或更新
handlePartAttribute(dto);
// 7. 调用IFS接口ManualReceiveShopOrder
callIfsManualReceiveShopOrder(dto, transNo);
log.info("=== 生产订单入库完成 === 事务号: {}, 创建HU数量: {}", transNo, unitIds.size());
@ -660,6 +667,46 @@ public class ProductionInboundServiceImpl implements ProductionInboundService {
}
}
private void handlePartAttribute(ShopOrderInboundDto inData) {
try {
String site = inData.getSite();
String partNo = inData.getPartNo();
BigDecimal height = BigDecimal.valueOf(inData.getHeight()!= null ? inData.getHeight() : 0);
log.info("开始处理料件属性,site: {}, partNo: {}, height: {}", site, partNo, height);
// 检查料件属性是否已存在
PartAttribute existing = partAttributeMapper.getPartAttributeByKey(site, partNo);
if (existing == null) {
// 不存在则新建设置默认值
PartAttribute partAttribute = new PartAttribute();
partAttribute.setSite(site);
partAttribute.setPartNo(partNo);
partAttribute.setIsInWh("Y"); // 默认进立库
partAttribute.setIsCommonlyUsed("Y"); // 默认常用料
partAttribute.setIsRobotPick("Y"); // 默认机械臂抓取
partAttribute.setHeight(height); // 高度不能为空默认0
partAttributeMapper.insert(partAttribute);
log.info("料件属性创建成功,site: {}, partNo: {}, height: {}", site, partNo, height);
} else {
// 已存在且传入了高度则只更新高度
// 使用 UpdateWrapper 按照联合主键site + partNo更新
LambdaUpdateWrapper<PartAttribute> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PartAttribute::getSite, site)
.eq(PartAttribute::getPartNo, partNo)
.set(PartAttribute::getHeight, height);
partAttributeMapper.update(null, updateWrapper);
log.info("料件属性高度更新成功,site: {}, partNo: {}, 新高度: {}", site, partNo, height);
}
} catch (Exception e) {
// 不抛出异常避免影响主流程
log.error("处理料件属性失败,site: {}, partNo: {}, 错误: {}",
inData.getSite(), inData.getPartNo(), e.getMessage(), e);
}
}
/**
* @Author System
* @Description 创建Handling Unit
@ -753,12 +800,12 @@ public class ProductionInboundServiceImpl implements ProductionInboundService {
handlingUnit.setOriginalQty(BigDecimal.valueOf(huInfo.getPerQty()));
handlingUnit.setReceiveDate(new Date());
handlingUnit.setWdr(dto.getWdr()!=null ? dto.getWdr() : "*");
// 设置高度
if (dto.getHeight() != null && dto.getHeight() > 0) {
handlingUnit.setHeight(BigDecimal.valueOf(dto.getHeight()));
}
// 保存HandlingUnit主记录并检查返回值
boolean saveResult = handlingUnitService.save(handlingUnit);
if (!saveResult) {
@ -771,7 +818,7 @@ public class ProductionInboundServiceImpl implements ProductionInboundService {
);
throw new XJException("标签保存失败(save返回false): " + unitId);
}
// 立即验证是否保存成功防止保存失败但业务继续执行
HandlingUnit savedUnit = handlingUnitService.getById(unitId);
if (savedUnit == null) {
@ -785,7 +832,7 @@ public class ProductionInboundServiceImpl implements ProductionInboundService {
);
throw new XJException("标签保存失败(验证未通过): " + unitId);
}
// 更新日志为成功
handlingUnitIdLogService.logUnitIdGeneration(
unitId, inData.getSite(), "PRODUCTION_INBOUND", dto.getOrderNo(),

7
src/main/resources/mapper/automatedWarehouse/AgvTaskMapper.xml

@ -57,6 +57,9 @@
<if test="data.agvCode != null and data.agvCode != ''">
AND agv_code = #{data.agvCode}
</if>
<if test="data.toLocation != null and data.toLocation != ''">
AND to_location = #{data.toLocation}
</if>
<if test="data.palletId != null and data.palletId != ''">
AND pallet_id LIKE CONCAT('%', #{data.palletId}, '%')
</if>
@ -134,7 +137,7 @@
WHERE status IN ('已创建','待下发', '未下发', 'PENDING', 'CREATED')
AND from_location IS NOT NULL
AND to_location IS NOT NULL
ORDER BY
ORDER BY
CASE WHEN priority IS NULL THEN 0 ELSE priority END DESC,
created_time ASC
</select>
@ -220,7 +223,7 @@
<!-- 更新任务状态为已下发 -->
<update id="updateTaskStatusToDispatched">
UPDATE wms_transport_task
SET
SET
status = '已下发',
wms_send_time = GETDATE(),
updated_time = GETDATE()

Loading…
Cancel
Save