|
|
|
@ -10,6 +10,7 @@ import com.gaotao.modules.factory.dao.AccessSiteMapper; |
|
|
|
import com.gaotao.modules.factory.entity.Site; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.Map; |
|
|
|
import com.gaotao.modules.handlingunit.entity.HandlingUnit; |
|
|
|
import com.gaotao.modules.handlingunit.entity.HandlingUnitDetail; |
|
|
|
@ -34,6 +35,7 @@ import jakarta.transaction.Transactional; |
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.data.relational.core.sql.In; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
@ -129,6 +131,19 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen |
|
|
|
@Transactional |
|
|
|
public void saveTrans(TransDetailDto inData) { |
|
|
|
try { |
|
|
|
Map<String, Object> params = Map.of("ifsDBName", ifsDBName, "domainUserID", domainUserID, |
|
|
|
"ifsSiteID", inData.getSite(), |
|
|
|
"ifsPartNo", inData.getPartNo() |
|
|
|
); |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
String jsonBody = objectMapper.writeValueAsString(params); |
|
|
|
String poResponse = HttpUtils.doGetWithBody(ifsUrl+"InventoryPart",jsonBody,null); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
List<Map<String, Object>> poData = mapper.readValue(poResponse, new TypeReference<>() {}); |
|
|
|
Integer shelfLife = null; // 有效期 |
|
|
|
if (poData!=null && !poData.isEmpty()) { |
|
|
|
shelfLife = poData.getFirst().get("shelfLife")!=null?(Integer) poData.getFirst().get("shelfLife"):null; |
|
|
|
} |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String transType = "CRT"; |
|
|
|
// 获取流水号,出错不回滚 |
|
|
|
@ -152,11 +167,11 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen |
|
|
|
if ("Y".equals(inData.getNeedHandlingUnit())) { |
|
|
|
// 创建Handling Unit相关数据 |
|
|
|
for (int i = 0; i < inData.getHandlingUnitList().size(); i++) { |
|
|
|
handlingUnitPart(inData, i, transHeader, currentUser); |
|
|
|
handlingUnitPart(inData, i, transHeader, currentUser,shelfLife); |
|
|
|
} |
|
|
|
} |
|
|
|
// 创建采购接收记录 - 在库存更新之前创建 |
|
|
|
createPoReceiptRecords(inData); |
|
|
|
createPoReceiptRecords(inData,shelfLife); |
|
|
|
// 免检更新库存 待检验的出入库记录状态为待检验 |
|
|
|
if ("N".equals(inData.getNeedCheck())) { |
|
|
|
headerService.save(transHeader); |
|
|
|
@ -185,7 +200,7 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void handlingUnitPart(TransDetailDto inData, int i, TransHeader transHeader, SysUserEntity currentUser) { |
|
|
|
private void handlingUnitPart(TransDetailDto inData, int i, TransHeader transHeader, SysUserEntity currentUser, Integer shelfLife) { |
|
|
|
TransDetailSubDto huInfo = inData.getHandlingUnitList().get(i); |
|
|
|
String subType = "HU"; |
|
|
|
for (int j = 0; j < huInfo.getPerQty(); j++) { |
|
|
|
@ -222,15 +237,22 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen |
|
|
|
handlingUnit.setBatchNo(inData.getBatchNo()); |
|
|
|
handlingUnit.setLocationId(inData.getLocationNo()); |
|
|
|
handlingUnit.setWarehouseId(transHeader.getWarehouseId()); |
|
|
|
// 设置制造日期和自动计算失效日期 |
|
|
|
if (inData.getManufactureDate() != null) { |
|
|
|
handlingUnit.setManufactureDate(inData.getManufactureDate()); |
|
|
|
// 自动计算失效日期 |
|
|
|
Date expiredDate = calculateExpiredDate(inData.getManufactureDate(), inData.getPartNo()); |
|
|
|
handlingUnit.setExpiredDate(expiredDate); |
|
|
|
if (shelfLife==null || shelfLife==0) { |
|
|
|
handlingUnit.setExpiredDate(null); |
|
|
|
} else if (inData.getManufactureDate() != null) { |
|
|
|
// 如果有制造日期,计算失效日期 |
|
|
|
java.util.Calendar calendar = java.util.Calendar.getInstance(); |
|
|
|
calendar.setTime(inData.getManufactureDate()); |
|
|
|
calendar.add(java.util.Calendar.DAY_OF_YEAR, shelfLife); |
|
|
|
handlingUnit.setExpiredDate(calendar.getTime()); |
|
|
|
} else if (inData.getArrivalDate() != null) { |
|
|
|
// 如果制造日期,但有接收日期,尝试用接收日期计算 |
|
|
|
java.util.Calendar calendar = java.util.Calendar.getInstance(); |
|
|
|
calendar.setTime(inData.getArrivalDate()); |
|
|
|
calendar.add(java.util.Calendar.DAY_OF_YEAR, shelfLife); |
|
|
|
handlingUnit.setExpiredDate(calendar.getTime()); |
|
|
|
} |
|
|
|
//handlingUnit.setWdr(inData.getWdr()); |
|
|
|
//handlingUnit.setAvailabilityControlId(inData.getAvailabilityControlId()); |
|
|
|
handlingUnit.setWdr(inData.getWdr()); |
|
|
|
handlingUnit.setStatus("ACTIVE"); |
|
|
|
handlingUnit.setStatusDb("A"); |
|
|
|
handlingUnit.setFreezeFlag("N"); |
|
|
|
@ -523,7 +545,7 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen |
|
|
|
String jsonBody = objectMapper.writeValueAsString(params); |
|
|
|
String ifsResponse = HttpUtils.doPost(ifsUrl+"registerArrival",jsonBody,null); |
|
|
|
log.info("同步接收记录到IFS,PO号: {}", inData.getOrderNo()); |
|
|
|
if ("IFSUpdated".equals(ifsResponse)) { |
|
|
|
if ("IFSUpdated".equals(ifsResponse) || "\"IFSUpdated\"".equals(ifsResponse)) { |
|
|
|
log.info("IFS同步成功,PO号: {}", inData.getOrderNo()); |
|
|
|
} else { |
|
|
|
log.error("IFS同步失败,PO号: {}, 响应: {}", inData.getOrderNo(), ifsResponse); |
|
|
|
@ -543,10 +565,9 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen |
|
|
|
/** |
|
|
|
* 创建采购接收记录 |
|
|
|
*/ |
|
|
|
private void createPoReceiptRecords(TransDetailDto inData) { |
|
|
|
private void createPoReceiptRecords(TransDetailDto inData,Integer shelfLife) { |
|
|
|
try { |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
|
|
|
|
// 生成接收单号 |
|
|
|
TransNoControl receiptNoControl = transNoService.getTransNo(inData.getSite(), "PR", 10); |
|
|
|
String receiptNo = receiptNoControl.getNewTransNo(); |
|
|
|
@ -673,17 +694,53 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen |
|
|
|
if (inData.getManufactureDate() != null) { |
|
|
|
poReceiptDetail.setManuFactureDate(inData.getManufactureDate()); |
|
|
|
} |
|
|
|
|
|
|
|
if (inData.getExpiredDate() != null) { |
|
|
|
poReceiptDetail.setExpiredDate(inData.getExpiredDate()); |
|
|
|
// 失效日期是根据生产日期ManufactureDate+有效期计算,如果生产日期为空,再用接收日期arrivalDate+有效期,如果有效期为空,失效日期就为空 |
|
|
|
if (shelfLife==null || shelfLife==0) { |
|
|
|
poReceiptDetail.setExpiredDate(null); |
|
|
|
} else if (inData.getManufactureDate() != null) { |
|
|
|
// 如果没有失效日期但有制造日期,尝试计算失效日期 |
|
|
|
Date expiredDate = calculateExpiredDate(inData.getManufactureDate(), inData.getPartNo()); |
|
|
|
if (expiredDate != null) { |
|
|
|
poReceiptDetail.setExpiredDate(expiredDate); |
|
|
|
// 如果有制造日期,计算失效日期 |
|
|
|
java.util.Calendar calendar = java.util.Calendar.getInstance(); |
|
|
|
calendar.setTime(inData.getManufactureDate()); |
|
|
|
calendar.add(java.util.Calendar.DAY_OF_YEAR, shelfLife); |
|
|
|
poReceiptDetail.setExpiredDate(calendar.getTime()); |
|
|
|
} else if (inData.getArrivalDate() != null) { |
|
|
|
// 如果制造日期,但有接收日期,尝试用接收日期计算 |
|
|
|
java.util.Calendar calendar = java.util.Calendar.getInstance(); |
|
|
|
calendar.setTime(inData.getArrivalDate()); |
|
|
|
calendar.add(java.util.Calendar.DAY_OF_YEAR, shelfLife); |
|
|
|
poReceiptDetail.setExpiredDate(calendar.getTime()); |
|
|
|
} |
|
|
|
poReceiptDetail.setDeliveryDate(inData.getDeliveryDate()); |
|
|
|
poReceiptDetail.setArrivalDate(inData.getArrivalDate()); |
|
|
|
poReceiptDetail.setSupplierBatchNo(inData.getSupplierBatchNo()); |
|
|
|
poReceiptDetail.setWdr(inData.getWdr() != null ? inData.getWdr() : "*"); |
|
|
|
// width 和length是根据料号判断的,如果料号带尾缀,比如70001234-0250,那么width就是250,如果不带尾缀且单位不是kg,width就是1000 |
|
|
|
String partNo = inData.getPartNo(); |
|
|
|
if (partNo != null && partNo.contains("-")) { |
|
|
|
String[] parts = partNo.split("-"); |
|
|
|
String suffix = parts[parts.length - 1]; |
|
|
|
try { |
|
|
|
int widthVal = Integer.parseInt(suffix); |
|
|
|
poReceiptDetail.setWidth(BigDecimal.valueOf(widthVal)); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
poReceiptDetail.setWidth(BigDecimal.valueOf(1000)); // 默认1000 |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (inData.getPurchaseUOM() != null && !"KG".equalsIgnoreCase(inData.getPurchaseUOM())) { |
|
|
|
poReceiptDetail.setWidth(BigDecimal.valueOf(1000)); |
|
|
|
} else { |
|
|
|
poReceiptDetail.setWidth(BigDecimal.valueOf(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
// length就是数量除以width再乘以1000 |
|
|
|
if (poReceiptDetail.getWidth() != null && poReceiptDetail.getWidth().compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
BigDecimal length = inData.getTransQty() |
|
|
|
.divide(poReceiptDetail.getWidth(), 2, RoundingMode.HALF_UP) |
|
|
|
.multiply(BigDecimal.valueOf(1000)); |
|
|
|
poReceiptDetail.setLength(length); |
|
|
|
} else { |
|
|
|
poReceiptDetail.setLength(BigDecimal.valueOf(0)); |
|
|
|
} |
|
|
|
|
|
|
|
// 备注信息 |
|
|
|
String remarkText = "PO接收自动创建"; |
|
|
|
if ("Y".equals(inData.getNeedCheck())) { |
|
|
|
|