辅材盘盈盘亏支持小数
This commit is contained in:
parent
b31a0876a0
commit
3301969c33
@ -6688,7 +6688,7 @@ public class ToSAPServiceImpl {
|
||||
|
||||
/**
|
||||
* 转工单-新
|
||||
* @param materialPackingList
|
||||
* @param mapList
|
||||
* @param mes
|
||||
* @param bwart
|
||||
* @return
|
||||
@ -6769,8 +6769,8 @@ public class ToSAPServiceImpl {
|
||||
}
|
||||
|
||||
System.out.println(mapList);
|
||||
/*log.info("SendTOSAP >>>>" + sendData);
|
||||
String sendDatas = sendData.toJSONString();
|
||||
log.info("SendTOSAP >>>>" + sendData);
|
||||
/*String sendDatas = sendData.toJSONString();
|
||||
String sapreturn = toSAPMessageUtil.sendHttpPost(toSAPMessageUtil.materialChangeLocationUrl, "", sendDatas);
|
||||
org.json.JSONObject receiveJsonObject = new org.json.JSONObject(sapreturn);
|
||||
org.json.JSONObject returnJsonObject = (org.json.JSONObject) receiveJsonObject.get("RETURN");
|
||||
|
@ -335,6 +335,7 @@ public class MaterialReceiveActController {
|
||||
String checkType = auxiliaryOutIn.getCheckType();
|
||||
String user = auxiliaryOutIn.getUser();
|
||||
String nums = auxiliaryOutIn.getNums();
|
||||
BigDecimal numsBigDecimal = new BigDecimal(nums);
|
||||
String siteName = auxiliaryOutIn.getSiteName();
|
||||
String erpFactory = auxiliaryOutIn.getErpFactory();
|
||||
String erpLocation = auxiliaryOutIn.getErpLocation();
|
||||
@ -388,44 +389,32 @@ public class MaterialReceiveActController {
|
||||
if (maps == null || maps.size() <= 0) {
|
||||
return AjaxResult.me().setSuccess(false).setMessage("没有符合条件的数据");
|
||||
}
|
||||
int materialquantity = maps.stream()
|
||||
.mapToInt(map -> {
|
||||
Object qtyObj = map.get("MATERIALQUANTITY");
|
||||
if (qtyObj instanceof Integer) {
|
||||
return (Integer) qtyObj;
|
||||
} else if (qtyObj instanceof Number) {
|
||||
// 如果可能是 Double、Long 等,也可以安全转为 int
|
||||
return ((Number) qtyObj).intValue();
|
||||
} else if (qtyObj != null) {
|
||||
try {
|
||||
return Integer.parseInt(qtyObj.toString());
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
return 0; // 默认值
|
||||
})
|
||||
.sum();
|
||||
if (materialquantity < Integer.parseInt(nums)) {
|
||||
BigDecimal materialquantity = maps.stream()
|
||||
.map(map -> (BigDecimal) map.get("MATERIALQUANTITY"))
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
if (materialquantity.compareTo(numsBigDecimal) < 0) {
|
||||
return AjaxResult.me().setSuccess(false).setMessage("数量不足");
|
||||
}
|
||||
List<LinkedHashMap<String, Object>> linkedHashMaps = pickMaterialQuantities(maps, Integer.parseInt(nums));
|
||||
List<LinkedHashMap<String, Object>> linkedHashMaps = pickMaterialQuantities(maps, numsBigDecimal);
|
||||
return AjaxResult.me().setResultObj(linkedHashMaps);
|
||||
}
|
||||
}
|
||||
|
||||
public List<LinkedHashMap<String, Object>> pickMaterialQuantities(List<LinkedHashMap<String, Object>> maps, int requiredQuantity) {
|
||||
public List<LinkedHashMap<String, Object>> pickMaterialQuantities(List<LinkedHashMap<String, Object>> maps, BigDecimal requiredQuantity) {
|
||||
List<LinkedHashMap <String, Object>> resultList = new ArrayList<>();
|
||||
int remaining = requiredQuantity;
|
||||
BigDecimal remaining = requiredQuantity;
|
||||
|
||||
for (LinkedHashMap<String, Object> item : maps) {
|
||||
// 获取当前记录的数量
|
||||
Integer materialQuantity = Integer.parseInt(item.get("MATERIALQUANTITY").toString());
|
||||
if (materialQuantity == null || materialQuantity <= 0 || remaining <= 0) {
|
||||
continue; // 跳过无效或已满足的情况
|
||||
BigDecimal materialQuantity = (BigDecimal) item.get("MATERIALQUANTITY");
|
||||
if (materialQuantity == null || materialQuantity.compareTo(BigDecimal.ZERO) <= 0
|
||||
|| remaining.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
continue; // 数量无效
|
||||
}
|
||||
|
||||
// 计算可以取多少
|
||||
int take = Math.min(materialQuantity, remaining);
|
||||
BigDecimal take = materialQuantity.min(remaining);
|
||||
|
||||
// 创建新的记录并设置数量
|
||||
LinkedHashMap<String, Object> newItem = new LinkedHashMap<>(item); // 复制原有字段
|
||||
@ -435,10 +424,10 @@ public class MaterialReceiveActController {
|
||||
resultList.add(newItem);
|
||||
|
||||
// 更新剩余数量
|
||||
remaining -= take;
|
||||
remaining = remaining.subtract(take);
|
||||
|
||||
// 如果已经满足需求,退出循环
|
||||
if (remaining == 0) {
|
||||
if (remaining.compareTo(BigDecimal.ZERO) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -518,10 +507,10 @@ public class MaterialReceiveActController {
|
||||
}
|
||||
HashMap<String, Object> hashMap = maps.get(0);
|
||||
// 数据库中数量
|
||||
Integer materialquantity = Integer.parseInt(hashMap.get("MATERIALQUANTITY").toString());
|
||||
BigDecimal materialquantity = (BigDecimal)hashMap.get("MATERIALQUANTITY");
|
||||
// 前端传递数量
|
||||
Integer materialQuantityFont = (int)materialPacking.getMaterialQuantity();
|
||||
if (materialquantity <= materialQuantityFont) {
|
||||
BigDecimal materialQuantityFont = BigDecimal.valueOf(materialPacking.getMaterialQuantity());
|
||||
if (materialquantity.compareTo(materialQuantityFont) <= 0) {
|
||||
updateList.add(materialPacking);
|
||||
} else {
|
||||
// 更新库存数量
|
||||
|
@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -65,6 +66,6 @@ public interface CostCenterDao {
|
||||
List<HashMap<String, Object>> getByMaterialPackingName(String newBoxId);
|
||||
|
||||
void updateQty(@Param("materialPackingName") String materialPackingName,
|
||||
@Param("materialQuantityFont") Integer materialQuantityFont,
|
||||
@Param("materialQuantityFont") BigDecimal materialQuantityFont,
|
||||
@Param("user") String user);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.cim.idm.model.CostCenter;
|
||||
import com.cim.idm.model.MaterialPacking;
|
||||
import com.cim.idm.model.vo.MaterialInfo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -28,5 +29,5 @@ public interface CostCenterService {
|
||||
|
||||
List<HashMap<String, Object>> getByMaterialPackingName(String newBoxId);
|
||||
|
||||
void updateQty(String materialPackingName, Integer materialQuantityFont, String user);
|
||||
void updateQty(String materialPackingName, BigDecimal materialQuantityFont, String user);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
@Service("CostCenterService")
|
||||
@ -171,7 +172,7 @@ public class CostCenterServiceImpl implements CostCenterService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateQty(String materialPackingName, Integer materialQuantityFont, String user) {
|
||||
public void updateQty(String materialPackingName, BigDecimal materialQuantityFont, String user) {
|
||||
costCenterDao.updateQty(materialPackingName, materialQuantityFont, user);
|
||||
}
|
||||
}
|
||||
|
@ -673,7 +673,7 @@ public class MESToWMSServiceImpl implements MESToWMSService {
|
||||
// 组织
|
||||
String WERKS = jsonObject.getString("WERKS");
|
||||
// 仓库
|
||||
String LGORT = jsonObject.getString("LGORT");
|
||||
String LGORT = jsonObject.getString("erpLocation");
|
||||
// 数量
|
||||
String MENGE = jsonObject.getString("MENGE");
|
||||
// 单位
|
||||
@ -683,7 +683,7 @@ public class MESToWMSServiceImpl implements MESToWMSService {
|
||||
// 自定义领料单行号
|
||||
String ZLLITEM = jsonObject.getString("ZLLITEM");
|
||||
// 工单
|
||||
String AUFNR = jsonObject.getString("AUFNR");
|
||||
String AUFNR = jsonObject.getString("toOrder");
|
||||
|
||||
map.put("MATNR", materialSpecname);
|
||||
map.put("WERKS", WERKS);
|
||||
@ -696,8 +696,19 @@ public class MESToWMSServiceImpl implements MESToWMSService {
|
||||
mapList.add(map);
|
||||
}
|
||||
// 出库
|
||||
String undoid = toSAPService.StockOutByOrder_new(mapList, "MES", "262");
|
||||
return AjaxResult.me().setResultObj(null).setSuccess(true).setErrorCode(200).setMessage("执行成功,物料凭证 " + undoid);
|
||||
// String undoidOut = toSAPService.StockOutByOrder_new(mapList, "MES", "262");
|
||||
// 入库
|
||||
String undoidIn = toSAPService.StockOutByOrder_new(mapList, "MES", "261");
|
||||
/*if (StringUtils.isEmpty(undoidIn)) {
|
||||
// 冲销
|
||||
String undo = invoiceService.cancelShipInter(undoidOut, "MES");
|
||||
if (undo == null || undo.isEmpty()) {
|
||||
throw new GlobalException("下发mes失败后冲销失败!");
|
||||
} else {
|
||||
throw new GlobalException("发送到mes失败!");
|
||||
}
|
||||
}*/
|
||||
return AjaxResult.me().setResultObj(null).setSuccess(true).setErrorCode(200).setMessage("执行成功,物料凭证 " + undoidIn);
|
||||
}
|
||||
/**
|
||||
* 接收MES请求工单请求
|
||||
|
Loading…
x
Reference in New Issue
Block a user