Compare commits

...

2 Commits

Author SHA1 Message Date
王帅
dcb919b97e Merge branch 'main' of http://162.14.99.253:3000/10539622/2025-03-JS-SDK-svr 2025-05-27 20:17:02 +08:00
王帅
b66dac6ecc E库存转化还原 2025-05-27 20:16:47 +08:00
7 changed files with 209 additions and 33 deletions

View File

@ -5981,10 +5981,8 @@ public class ToSAPServiceImpl {
item.put("BWART",moveType);
item.put("MENGE", mm.get("MATERIALQUANTITY"));
item.put("MEINS", mm.get("UNIT"));
if ("413E".equals(moveType)) {
item.put("UMMAT_KDAUF", mm.get("OLDSALESHIPREQUESTNAME"));
item.put("UMMAT_KDPOS", mm.get("OLDSALESHIPREQUESTDETAILNAME"));
}
item.put("UMMAT_KDAUF", mm.get("OLDSALESHIPREQUESTNAME"));
item.put("UMMAT_KDPOS", mm.get("OLDSALESHIPREQUESTDETAILNAME"));
String insmk = "";
// if("NG".equals(pqcResult) ){
// insmk = "3";
@ -5992,21 +5990,12 @@ public class ToSAPServiceImpl {
// String insmk = StringUtils.equals(mm.get("OQARESULTSTATE").toString(),"END")?"":"X";
item.put("INSMK", insmk);
/*if("411E".equals(moveType) || "413E".equals(moveType)) {
if("411E".equals(moveType) || "413E".equals(moveType)) {
item.put("MAT_KDAUF", mm.get("SALESHIPREQUESTNAME")); // 发货销售订单编码
item.put("MAT_KDPOS", mm.get("SALESHIPREQUESTDETAILNAME")); // 发货销售订单项目编码
} else if("413".equals(moveType) || "413E".equals(moveType)) {
item.put("UMMAT_KDAUF", SALESHIPREQUESTNAME); // 发货销售订单编码
item.put("UMMAT_KDPOS", SALESHIPREQUESTDETAILNAME); // 发货销售订单项目编码
}*/
if ("411E".equals(moveType)) {
item.put("MAT_KDAUF", mm.get("OLDSALESHIPREQUESTNAME")); // 发货销售订单编码
item.put("MAT_KDPOS", mm.get("OLDSALESHIPREQUESTDETAILNAME")); // 发货销售订单项目编码
}
if ("413".equals(moveType) || "413E".equals(moveType)) {
item.put("MAT_KDAUF", mm.get("SALESHIPREQUESTNAME")); // 发货销售订单编码
item.put("MAT_KDPOS", mm.get("SALESHIPREQUESTDETAILNAME")); // 发货销售订单项目编码
}
itemData.add(item);

View File

@ -21,6 +21,7 @@ import com.cim.idm.service.CostCenterService;
import com.cim.idm.service.IDeliveryService;
import com.cim.idm.service.IMaterialPackingService;
import com.cim.idm.service.IMaterialShipService;
import com.cim.idm.service.Impl.NoInvoiceManagerServiceImpl;
import com.cim.idm.service.impl.QMSServiceImpl;
import com.cim.idm.service.impl.ToSAPServiceImpl;
import com.cim.idm.utils.AjaxResult;
@ -43,6 +44,7 @@ import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.*;
import com.cim.idm.service.Impl.SDKMaterialPackingServiceImpl;
@ -59,6 +61,10 @@ public class MaterialReceiveActController {
@Resource
private IMaterialPackingService mpService;
@Autowired
NoInvoiceManagerServiceImpl NoInvoiceManagerServiceImpl;
@Autowired
private ToSAPServiceImpl toSAPService;
private static Log log = LogFactory.getLog(MaterialReceiveActController.class);
private EventInfo makeEventInfo;
@ -338,14 +344,14 @@ public class MaterialReceiveActController {
return AjaxResult.me().setSuccess(false).setMessage("物料编号" + materialSpecName + "不存在");
}
if ("盘盈".equals(checkType)) {
String phase = materialInfo.getPhase() != null ? materialInfo.getPhase() : "C";
String width = materialInfo.getWidth();
String materialUnit = materialInfo.getMaterialUnit();
String materialType = materialInfo.getMaterialType();
String descCn = materialInfo.getDescCn();
List<String> boxIds = MaterialPackingServiceImpl.generateBoxID("LabelId", siteName,
"1", DateUtil.now(), "WL", erpFactory);
//470110856|1|C|75mm*1000m|SHBP01JT1202305240009|20230524|11|75
String newBoxId = materialSpecName + "|1|" + phase + "|" + width + "|" + boxIds.get(0) + "|"
String newBoxId = materialSpecName + "|1|" + "|" + width + "|" + boxIds.get(0) + "|"
+ makeDate.replace("-", "").substring(0, 8) + "|" + materialUnit + "|" + nums;
EventInfo makeEventInfo = new EventInfoUtil().makeEventInfo("TrackOutBox", user, "TrackOutBox");
Map<String, Object> bindMap = new HashMap<String, Object>();
@ -360,12 +366,14 @@ public class MaterialReceiveActController {
bindMap.put("stockState", "Created");
bindMap.put("materialPackingName", newBoxId);
bindMap.put("charge", boxIds.get(0));
bindMap.put("materialPackingType", "Box");
bindMap.put("truegg", width);
bindMap.put("unit", materialUnit);
bindMap.put("materialType", materialType);
bindMap.put("createUser", user);
bindMap.put("createTime", DateUtil.now());
CreateInfo createInfo = new CreateInfo();
createInfo.setMaterialPackingName(newBoxId);
createInfo.setMaterialPackingType("Box");
createInfo.setSiteName(auxiliaryOutIn.getSiteName());
createInfo.setUserColumns(bindMap);
MaterialPacking materialPacking = MaterialPackingServiceProxy.getMaterialPackingService().create(
@ -374,11 +382,169 @@ public class MaterialReceiveActController {
return AjaxResult.me().setResultObj(maps);
} else {
// todo
List<HashMap<String, Object>> maps = costCenterService.getMaterialPacking(materialSpecName,siteName,erpFactory,
List<LinkedHashMap<String, Object>> maps = costCenterService.getMaterialPacking(materialSpecName,siteName,erpFactory,
erpLocation, location, nums);
return AjaxResult.me().setResultObj(maps);
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) {
// 如果可能是 DoubleLong 也可以安全转为 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)) {
return AjaxResult.me().setSuccess(false).setMessage("数量不足");
}
List<LinkedHashMap<String, Object>> linkedHashMaps = pickMaterialQuantities(maps, Integer.parseInt(nums));
return AjaxResult.me().setResultObj(linkedHashMaps);
}
}
public List<LinkedHashMap<String, Object>> pickMaterialQuantities(List<LinkedHashMap<String, Object>> maps, int requiredQuantity) {
List<LinkedHashMap <String, Object>> resultList = new ArrayList<>();
int remaining = requiredQuantity;
for (LinkedHashMap<String, Object> item : maps) {
// 获取当前记录的数量
Integer materialQuantity = Integer.parseInt(item.get("MATERIALQUANTITY").toString());
// Integer materialQuantity = (Integer) item.get("MATERIALQUANTITY");
if (materialQuantity == null || materialQuantity <= 0 || remaining <= 0) {
continue; // 跳过无效或已满足的情况
}
// 计算可以取多少
int take = Math.min(materialQuantity, remaining);
// 创建新的记录并设置数量
LinkedHashMap<String, Object> newItem = new LinkedHashMap<>(item); // 复制原有字段
newItem.put("MATERIALQUANTITY", take); // 替换数量
// 添加到结果集
resultList.add(newItem);
// 更新剩余数量
remaining -= take;
// 如果还有剩余但当前记录未完全使用可以在这里做拆分处理可选
if (remaining > 0 && materialQuantity > take) {
// 可以选择修改原列表中的数量如果需要保留原库存信息
// ((HashMap<String, Object>) item).put("materialQuantity", materialQuantity - take);
}
// 如果已经满足需求退出循环
if (remaining == 0) {
break;
}
}
return resultList;
}
/**
* 盘盈入库---pc
* @param in
* @return
* @throws ParseException
*/
@RequestMapping(value = "/QTRCommit", method = RequestMethod.POST)
public AjaxResult QTRCommit(@RequestBody JSONObject in ) throws ParseException {
MaterialReceiveRequest sl = JSON.toJavaObject(in, MaterialReceiveRequest.class);
String commitDateString = sl.getCommitDate();
List<MaterialPacking> boxList = sl.getBoxList();
String user2 = sl.getUser();
String opCode = sl.getOpCode();
String commitDate = commitDateString + " 00:00:00";
String costName = sl.getCostName();
String lifnr = sl.getLifnr();
String qtc = sl.getQtc();
NoInvoiceManagerServiceImpl.QTR(boxList,user2,commitDate,opCode,costName,lifnr,qtc);
return AjaxResult.me().setResultObj(null);
}
/**
* 盘亏出库---pc
* @param in
* @return
*/
@RequestMapping(value = "/QTCCommit", method = RequestMethod.POST)
@Transactional
public AjaxResult QTCCommit(@RequestBody JSONObject in ){
// List<MaterialPacking> object = (List<MaterialPacking>) in.get("boxList");
MaterialReceiveRequest sl = JSON.toJavaObject(in, MaterialReceiveRequest.class);
List<MaterialPacking> boxList = sl.getBoxList();
String siteName = sl.getSiteName();
String user = in.get("user").toString();
String commitDatesString = sl.getCommitDate();
String commitDate = commitDatesString + " 00:00:00";
String opCode = sl.getOpCode();
// 移动类型
String qtc = sl.getQtc();
// 成本中心
String costName = sl.getCostName();
ArrayList<MaterialPackingKey> arrayList = new ArrayList<>();
for(MaterialPacking map : boxList) {
MaterialPackingKey MaterialPackingKey = new MaterialPackingKey("SDK", map.getMaterialPackingName());
arrayList.add(MaterialPackingKey);
}
String undoId = "";
try {
undoId = toSAPService.MaterialScrapStockOut(arrayList,siteName,user,commitDate,opCode,qtc,costName);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.me().setSuccess(false).setMessage(e.toString());
}
if (StringUtils.isEmpty(undoId)) {
return AjaxResult.me().setSuccess(false).setMessage("undoId为空");
}
// 发送过账
EventInfoUtil util = new EventInfoUtil();
String enentName = "报废出库";
if ("Z05".equals(qtc)) {
enentName = "盘亏出库";
}
makeEventInfo = util.makeEventInfo(enentName, user, enentName);
// 更新库存状态
SDKMaterialPackingServiceImpl.SaveUnDoInfo(undoId,commitDate);
List<MaterialPacking> updateList = new ArrayList<>();
for(MaterialPacking materialPacking : boxList) {
List<HashMap<String, Object>> maps = costCenterService.getByMaterialPackingName(materialPacking.getMaterialPackingName());
if (maps == null || maps.size() <= 0) {
// 数据不存在跳过或抛异常
continue;
}
HashMap<String, Object> hashMap = maps.get(0);
// 数据库中数量
Integer materialquantity = Integer.parseInt(hashMap.get("MATERIALQUANTITY").toString());
// 前端传递数量
Integer materialQuantityFont = (int)materialPacking.getMaterialQuantity();
if (materialquantity <= materialQuantityFont) {
updateList.add(materialPacking);
} else {
// 更新库存数量
costCenterService.updateQty(materialPacking.getMaterialPackingName(), materialQuantityFont, user);
}
}
// 更新入库凭证和库存状态
SDKMaterialPackingServiceImpl.updateUndoIdByList(updateList, undoId, makeEventInfo,opCode);
return AjaxResult.me().setResultObj(null);
}
@RequestMapping(value = "/DeleteTrackOutBox", method = RequestMethod.POST)
public AjaxResult DeleteTrackOutBox(@RequestBody JSONObject in ) throws Exception{
// 获取属性

View File

@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -54,12 +55,16 @@ public interface CostCenterDao {
MaterialInfo getMaterialInfo(@Param("materialSpecName") String materialSpecName);
List<HashMap<String, Object>> getMaterialPacking(@Param("materialSpecName") String materialSpecName,
@Param("siteName") String siteName,
@Param("erpFactory") String erpFactory,
@Param("erpLocation") String erpLocation,
@Param("location") String location,
@Param("nums") String nums);
List<LinkedHashMap<String, Object>> getMaterialPacking(@Param("materialSpecName") String materialSpecName,
@Param("siteName") String siteName,
@Param("erpFactory") String erpFactory,
@Param("erpLocation") String erpLocation,
@Param("location") String location,
@Param("nums") String nums);
List<HashMap<String, Object>> getByMaterialPackingName(String newBoxId);
void updateQty(@Param("materialPackingName") String materialPackingName,
@Param("materialQuantityFont") Integer materialQuantityFont,
@Param("user") String user);
}

View File

@ -15,4 +15,5 @@ public class MaterialInfo {
private String phase;
private String width;
private String materialType;
private String descCn;
}

View File

@ -6,6 +6,7 @@ import com.cim.idm.model.MaterialPacking;
import com.cim.idm.model.vo.MaterialInfo;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -23,7 +24,9 @@ public interface CostCenterService {
void editMaterialPackingName(MaterialPacking materialPacking);
MaterialInfo getMaterialInfo(String materialSpecName);
List<HashMap<String, Object>> getMaterialPacking(String materialSpecName, String siteName, String erpFactory, String erpLocation, String location, String nums);
List<LinkedHashMap<String, Object>> getMaterialPacking(String materialSpecName, String siteName, String erpFactory, String erpLocation, String location, String nums);
List<HashMap<String, Object>> getByMaterialPackingName(String newBoxId);
void updateQty(String materialPackingName, Integer materialQuantityFont, String user);
}

View File

@ -22,10 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service("CostCenterService")
@Slf4j
@ -163,7 +160,7 @@ public class CostCenterServiceImpl implements CostCenterService {
}
@Override
public List<HashMap<String, Object>> getMaterialPacking(String materialSpecName, String siteName, String erpFactory, String erpLocation, String location, String nums) {
public List<LinkedHashMap<String, Object>> getMaterialPacking(String materialSpecName, String siteName, String erpFactory, String erpLocation, String location, String nums) {
return costCenterDao.getMaterialPacking(materialSpecName,siteName,erpFactory,
erpLocation, location, nums);
}
@ -172,4 +169,9 @@ public class CostCenterServiceImpl implements CostCenterService {
public List<HashMap<String, Object>> getByMaterialPackingName(String newBoxId) {
return costCenterDao.getByMaterialPackingName(newBoxId);
}
@Override
public void updateQty(String materialPackingName, Integer materialQuantityFont, String user) {
costCenterDao.updateQty(materialPackingName, materialQuantityFont, user);
}
}

View File

@ -55,17 +55,27 @@
select * from MATERIALSPEC where MATERIALSPECNAME = #{materialSpecName}
</select>
<select id="getMaterialPacking" resultType="java.util.HashMap">
<select id="getMaterialPacking" resultType="java.util.LinkedHashMap">
select * from MATERIALPACKING
where MATERIALSPECNAME = #{materialSpecName}
AND SITENAME = #{siteName}
AND ERPFACTORY = #{erpFactory}
AND ERPLOCATION = #{erpLocation}
AND LOCATIONNAME = #{location}
<if test="location != null || location != ''">
AND LOCATIONNAME = #{location}
</if>
AND stockstate = 'Stocked'
order by CREATETIME
</select>
<select id="getByMaterialPackingName" resultType="java.util.HashMap" parameterType="java.lang.String">
select * from MATERIALPACKING
where MATERIALPACKINGNAME = #{newBoxId}
</select>
<update id="updateQty">
update MATERIALPACKING set MATERIALQUANTITY = MATERIALQUANTITY - #{materialQuantityFont},
LASTEVENTTIME = SYSDATE, LASTEVENTUSER = #{user}
where MATERIALPACKINGNAME = #{materialPackingName}
</update>
</mapper>