|
|
|
@ -129,9 +129,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
Double amounts = (quantity * price * 100); |
|
|
|
// 获取平均价格
|
|
|
|
double avgPrice = 0.0; |
|
|
|
if(quantity != 0){ |
|
|
|
avgPrice = (amounts) / ( quantity); |
|
|
|
}else{ |
|
|
|
if (quantity != 0) { |
|
|
|
avgPrice = (amounts) / (quantity); |
|
|
|
} else { |
|
|
|
avgPrice = price * 100; |
|
|
|
} |
|
|
|
|
|
|
|
@ -171,9 +171,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
map.put("newInMid", newMid); |
|
|
|
|
|
|
|
// 如果包含realQuantity则代表是入库的拆单单位
|
|
|
|
if(map.containsKey("realQuantity")){ |
|
|
|
if (map.containsKey("realQuantity")) { |
|
|
|
// 将入库数量修改为realQuantity
|
|
|
|
map.put("quantity",map.get("realQuantity")); |
|
|
|
map.put("quantity", map.get("realQuantity")); |
|
|
|
} |
|
|
|
return depositoryRecordMapper.insertApplicationInRecord(map); |
|
|
|
} |
|
|
|
@ -541,8 +541,8 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
Integer mid = ObjectFormatUtil.toInteger(map.get("mid")); |
|
|
|
Material materialById = materialMapper.findMaterialById(mid); |
|
|
|
String unit = (String) map.get("unit"); |
|
|
|
if("-1".equals(unit)){ |
|
|
|
map.put("unit",materialById.getUnit()); |
|
|
|
if ("-1".equals(unit)) { |
|
|
|
map.put("unit", materialById.getUnit()); |
|
|
|
} |
|
|
|
if (placeById.getMax() - placeById.getQuantity() > quantity) { |
|
|
|
// 如果当前库位还能存放
|
|
|
|
@ -773,7 +773,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 获取出库申请时的单位
|
|
|
|
String unit = applicationOutMinById.getUnit(); |
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = null; |
|
|
|
if("-1".equals(unit)) { |
|
|
|
if ("-1".equals(unit)) { |
|
|
|
|
|
|
|
// 如果是按基础单位出库
|
|
|
|
|
|
|
|
@ -801,8 +801,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "当前位置未发现该物料")); |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
} |
|
|
|
else { // 如果是默认库位
|
|
|
|
} else { // 如果是默认库位
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", inventory.getId()); |
|
|
|
params.put("pid", 0); |
|
|
|
@ -845,8 +844,6 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是库存转移订单
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
if (record.getIstransfer() == 1) { |
|
|
|
@ -860,7 +857,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
|
|
|
|
// 进行子订单的相关处理
|
|
|
|
updateApplicationMinOutInfo(id,applicationOutMinById,record,trueOut,userByPort,placeId,userAgent); |
|
|
|
updateApplicationMinOutInfo(id, applicationOutMinById, record, trueOut, userByPort, placeId, userAgent); |
|
|
|
|
|
|
|
// 更新入库批次中的物料数量
|
|
|
|
new Thread(new Runnable() { |
|
|
|
@ -887,30 +884,45 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
} |
|
|
|
} |
|
|
|
}).start(); |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
} else { |
|
|
|
// 如果是拆单后的单位
|
|
|
|
|
|
|
|
// 获取拆单库存处理记录
|
|
|
|
SplitInventory splitInventory = splitUnitMapper.findSplitInventoryByIid(inventory.getId()); |
|
|
|
if(splitInventory != null) { |
|
|
|
|
|
|
|
// 用于获取对应的拆单记录
|
|
|
|
Map<String, Object> paramForSplitInfo = new HashMap<>(); |
|
|
|
paramForSplitInfo.put("mid", inventory.getMid()); |
|
|
|
paramForSplitInfo.put("newUnit", record.getUnit()); |
|
|
|
// 获取对应拆单记录
|
|
|
|
SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); |
|
|
|
|
|
|
|
// 获取当前拆单库存
|
|
|
|
Map<String, Object> paramForSplitInventory = new HashMap<>(); |
|
|
|
paramForSplitInventory.put("sid", splitInfo.getId()); |
|
|
|
paramForSplitInventory.put("iid", inventory.getId()); |
|
|
|
SplitInventory splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
|
|
|
|
|
|
|
|
if (splitInventory != null) { |
|
|
|
// 如果拆单库存处理记录存在
|
|
|
|
|
|
|
|
if (splitInventory.getSaveQuantity() >= trueOut) { |
|
|
|
// 如果当前待处理树可以满足需求
|
|
|
|
|
|
|
|
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - trueOut); |
|
|
|
|
|
|
|
// 设置当前拆单后的出库数量
|
|
|
|
if (splitInventory.getOutQuantity() != null) { |
|
|
|
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + trueOut); |
|
|
|
} else { |
|
|
|
splitInventory.setOutQuantity(trueOut); |
|
|
|
} |
|
|
|
|
|
|
|
// 修改库存处理记录
|
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
|
|
|
|
// 进行子订单的相关处理
|
|
|
|
@ -926,100 +938,111 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 如果不能满足需求
|
|
|
|
|
|
|
|
// 获取对应的拆单记录
|
|
|
|
SplitInfo splitInfo = splitUnitMapper.findSplitInfoById(splitInventory.getSid()); |
|
|
|
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInventory.getSid()); |
|
|
|
|
|
|
|
// 获取剩余不足的数量
|
|
|
|
int surplus = trueOut - splitInventory.getSaveQuantity(); |
|
|
|
if (surplus < splitInfo.getQuantity()) { |
|
|
|
// 如果剩余不足的数量小于拆单单位对应的数量
|
|
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", inventory.getId()); |
|
|
|
params.put("pid", placeId); |
|
|
|
if (surplus < splitInfoById.getQuantity()) { |
|
|
|
|
|
|
|
// 获取当前物料在库位中的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
if (splitInfoById.getParentId() != null) { |
|
|
|
// 如果当前拆单没有父级
|
|
|
|
|
|
|
|
if (placeAndMaterialByMidAndPid != null) { |
|
|
|
// 如果当前库位存在该物料
|
|
|
|
if (placeAndMaterialByMidAndPid.getQuantity() < 1) { |
|
|
|
// 如果当前库存中的物料库存不足以出库
|
|
|
|
flag = false; |
|
|
|
// 如果剩余不足的数量小于拆单单位对应的数量
|
|
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", inventory.getId()); |
|
|
|
params.put("pid", placeId); |
|
|
|
|
|
|
|
// 获取当前物料在库位中的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
|
|
|
|
if (placeAndMaterialByMidAndPid != null) { |
|
|
|
// 如果当前库位存在该物料
|
|
|
|
if (placeAndMaterialByMidAndPid.getQuantity() < 1) { |
|
|
|
// 如果当前库存中的物料库存不足以出库
|
|
|
|
flag = false; |
|
|
|
} |
|
|
|
} else { |
|
|
|
restResponse.setStatus(566); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "当前位置未发现该物料")); |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
} else { |
|
|
|
restResponse.setStatus(566); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "当前位置未发现该物料")); |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
|
|
|
|
// 如果物料数量可以出库并且库位数量充足
|
|
|
|
if (inventory.getQuantity() >= 1 && flag) { |
|
|
|
// 如果物料数量可以出库并且库位数量充足
|
|
|
|
if (inventory.getQuantity() >= 1 && flag) { |
|
|
|
|
|
|
|
// 令库存-1
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - 1); |
|
|
|
// 令库存-1
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - 1); |
|
|
|
|
|
|
|
// 重新计算总额
|
|
|
|
inventory.setAmounts(inventory.getQuantity() * inventory.getPrice()); |
|
|
|
// 重新计算总额
|
|
|
|
inventory.setAmounts(inventory.getQuantity() * inventory.getPrice()); |
|
|
|
|
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = new BigDecimal(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = new BigDecimal(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
|
|
|
|
// 修改库存记录
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
// 修改库存记录
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
|
|
|
|
|
|
|
|
// 修改当前库位存放物料的数量
|
|
|
|
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - 1); |
|
|
|
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid); |
|
|
|
// 修改当前库位存放物料的数量
|
|
|
|
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - 1); |
|
|
|
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid); |
|
|
|
|
|
|
|
// 修改库位数量
|
|
|
|
Place placeById = placeMapper.findPlaceById(placeId); |
|
|
|
placeById.setQuantity(placeById.getQuantity() - 1); |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
// 修改库位数量
|
|
|
|
Place placeById = placeMapper.findPlaceById(placeId); |
|
|
|
placeById.setQuantity(placeById.getQuantity() - 1); |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
|
|
|
|
|
|
|
|
// 如果是库存转移订单
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
if (record.getIstransfer() == 1) { |
|
|
|
map.put("quantity", "1"); |
|
|
|
map.put("applicantId", record.getApplicantId()); |
|
|
|
map.put("minRecordId", applicationOutMinById.getId()); // 出库订单编号
|
|
|
|
transferMaterial(map); |
|
|
|
} |
|
|
|
// 如果是库存转移订单
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
if (record.getIstransfer() == 1) { |
|
|
|
map.put("quantity", "1"); |
|
|
|
map.put("applicantId", record.getApplicantId()); |
|
|
|
map.put("minRecordId", applicationOutMinById.getId()); // 出库订单编号
|
|
|
|
transferMaterial(map); |
|
|
|
} |
|
|
|
|
|
|
|
// 设置剩余拆单库存处理数量
|
|
|
|
splitInventory.setSaveQuantity(splitInfo.getQuantity() + splitInventory.getSaveQuantity() - trueOut); |
|
|
|
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + trueOut); |
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
// 设置剩余拆单库存处理数量
|
|
|
|
splitInventory.setSaveQuantity(splitInfoById.getQuantity() + splitInventory.getSaveQuantity() - trueOut); |
|
|
|
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + trueOut); |
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
|
|
|
|
updateApplicationMinOutInfo(id, applicationOutMinById, record, trueOut, userByPort, placeId, userAgent); |
|
|
|
|
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
|
|
|
|
} else { |
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//如果有父级
|
|
|
|
|
|
|
|
updateApplicationMinOutInfo(id, applicationOutMinById, record, trueOut, userByPort, placeId, userAgent); |
|
|
|
|
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
|
|
|
|
} else { |
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果大于
|
|
|
|
|
|
|
|
// 获取库存重要减少的数量
|
|
|
|
int surplus_redundant = surplus / splitInfo.getQuantity(); |
|
|
|
int surplus_redundant = surplus / splitInfoById.getQuantity(); |
|
|
|
// 获取拆单库存处理中要处理数量
|
|
|
|
int saveQuantity = surplus - surplus_redundant * splitInfo.getQuantity(); |
|
|
|
int saveQuantity = surplus - surplus_redundant * splitInfoById.getQuantity(); |
|
|
|
|
|
|
|
if (saveQuantity > splitInventory.getSaveQuantity()) { |
|
|
|
// 如果要处理的数量大于剩余数量
|
|
|
|
|
|
|
|
// 获取一个数量
|
|
|
|
surplus_redundant += 1; |
|
|
|
splitInventory.setSaveQuantity(splitInfo.getQuantity() + splitInventory.getSaveQuantity() - saveQuantity); |
|
|
|
splitInventory.setSaveQuantity(splitInfoById.getQuantity() + splitInventory.getSaveQuantity() - saveQuantity); |
|
|
|
} else { |
|
|
|
// 如果不大于
|
|
|
|
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - saveQuantity); |
|
|
|
@ -1095,17 +1118,11 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
|
|
|
|
} else { |
|
|
|
// 如果拆单库存处理记录不存在
|
|
|
|
|
|
|
|
// 用于获取对应的拆单记录
|
|
|
|
Map<String,Object> paramForSplitInfo = new HashMap<>(); |
|
|
|
paramForSplitInfo.put("mid",inventory.getMid()); |
|
|
|
paramForSplitInfo.put("newUnit",record.getUnit()); |
|
|
|
// 获取对应拆单记录
|
|
|
|
SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); |
|
|
|
if(inventory.getQuantity() * splitInfo.getQuantity() > trueOut){ |
|
|
|
if (inventory.getQuantity() * splitInfo.getQuantity() > trueOut) { |
|
|
|
// 如果当前库存数量满足要求
|
|
|
|
|
|
|
|
// 获取当前出库的具体数目
|
|
|
|
@ -1138,12 +1155,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
|
|
|
|
// 添加拆单库存处理记录
|
|
|
|
Map<String,Object> insertSplitInventory = new HashMap<>(); |
|
|
|
insertSplitInventory.put("sid",splitInfo.getId()); |
|
|
|
insertSplitInventory.put("iid",inventory.getId()); |
|
|
|
insertSplitInventory.put("outQuantity",trueOut); |
|
|
|
insertSplitInventory.put("inQuantity",0); |
|
|
|
insertSplitInventory.put("saveQuantity",splitInfo.getQuantity() - residue_realQuantity); |
|
|
|
Map<String, Object> insertSplitInventory = new HashMap<>(); |
|
|
|
insertSplitInventory.put("sid", splitInfo.getId()); |
|
|
|
insertSplitInventory.put("iid", inventory.getId()); |
|
|
|
insertSplitInventory.put("outQuantity", trueOut); |
|
|
|
insertSplitInventory.put("inQuantity", 0); |
|
|
|
insertSplitInventory.put("saveQuantity", splitInfo.getQuantity() - residue_realQuantity); |
|
|
|
splitUnitMapper.addSplitInventory(insertSplitInventory); |
|
|
|
|
|
|
|
|
|
|
|
@ -1163,7 +1180,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
} else { |
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
@ -1174,19 +1191,38 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于有父级拆单记录的出库处理 |
|
|
|
* @param splitInfo 当前拆单记录 |
|
|
|
* @param inventory 当前库存记录 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
RestResponse updateSplitInventoryInfo(SplitInfo splitInfo,Inventory inventory){ |
|
|
|
// 获取当前拆单的父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
|
|
|
//
|
|
|
|
Map<String,Object> paramForSplitInventory = new HashMap<>(); |
|
|
|
paramForSplitInventory.put("sid",splitInfo.getId()); |
|
|
|
paramForSplitInventory.put("iid",inventory.getId()); |
|
|
|
splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于完成出库时的相关处理操作 |
|
|
|
* @param id 子订单id |
|
|
|
* |
|
|
|
* @param id 子订单id |
|
|
|
* @param applicationOutMinById 待处理的子订单 |
|
|
|
* @param record 子订单对应的主订单 |
|
|
|
* @param trueOut 实际出库数量 |
|
|
|
* @param userByPort 当前登录用户 |
|
|
|
* @param placeId 出库库位id |
|
|
|
* @param userAgent user-agent |
|
|
|
* @param record 子订单对应的主订单 |
|
|
|
* @param trueOut 实际出库数量 |
|
|
|
* @param userByPort 当前登录用户 |
|
|
|
* @param placeId 出库库位id |
|
|
|
* @param userAgent user-agent |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
void updateApplicationMinOutInfo(Integer id, ApplicationOutRecordMin applicationOutMinById, ApplicationOutRecordP record, Integer trueOut, UserByPort userByPort, Integer placeId, String userAgent){ |
|
|
|
void updateApplicationMinOutInfo(Integer id, ApplicationOutRecordMin applicationOutMinById, ApplicationOutRecordP record, Integer trueOut, UserByPort userByPort, Integer placeId, String userAgent) { |
|
|
|
String redisMinRecordKey = "minRecord:" + id; // 设置redis中子订单键值
|
|
|
|
// 修改redis中本子订单状态
|
|
|
|
// redisTemplate.opsForHash().put(redisMinRecordKey,"state","2");
|
|
|
|
@ -1678,8 +1714,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
qyWxOperationService.sendMessageForOtherUserByCard(ObjectFormatUtil.toInteger(id), s, userAgent, 1); |
|
|
|
} |
|
|
|
}).start(); |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
String result = ""; |
|
|
|
// 开启线程更改其他用户卡片模板样式
|
|
|
|
String simpleTime = DateUtil.getSimpleTime(new Date()); |
|
|
|
|