Browse Source

完成拆单出库功能

lwx_dev
erdanergou 3 years ago
parent
commit
1004c1f68c
  1. 9
      src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java
  2. 22
      src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java
  3. 46
      src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java
  4. 8
      src/main/resources/templates/pages/scanQrCode/ScanBarOrQrCodeOut.html
  5. 20
      src/test/java/com/dreamchaser/depository_manage/TestForOther.java

9
src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java

@ -399,6 +399,7 @@ public class DepositoryRecordController {
insert.put("applyRemark", map.get("applyRemark" + temp));
insert.put("code", map.get("code"));
insert.put("placeId", map.get("placeId"));
insert.put("unit",map.get("unit"+temp));
// 获取主订单编号
insert.put("parentId", id);
// 插入子订单
@ -607,14 +608,14 @@ public class DepositoryRecordController {
// 获取子订单信息
ApplicationOutRecordMin applicationOutRecordMin = applicationOutMinByParentId.get(j);
// 获取出库物料信息
Material materialById = materialService.findMaterialById(applicationOutRecordMin.getMid());
Inventory inventory = materialService.findInventoryById(applicationOutRecordMin.getMid());
// 获取出库物料仓库信息
Depository depository = depositoryService.findDepositoryById(applicationOutRecordMin.getDepositoryId());
mname.append(materialById.getMname()).append(",");
mcode.append(materialById.getCode()).append(",");
mname.append(inventory.getMname()).append(",");
mcode.append(inventory.getCode()).append(",");
depositoryName.append(depository.getDname()).append(",");
sumQuantity += applicationOutRecordMin.getQuantity();
sumPrice += (materialById.getPrice() * applicationOutRecordMin.getQuantity());
sumPrice += (inventory.getPrice() * applicationOutRecordMin.getQuantity());
}
list.get(i).setMcode(mcode.toString());
list.get(i).setMname(mname.toString());

22
src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java

@ -900,7 +900,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
// 用于获取对应的拆单记录
Map<String, Object> paramForSplitInfo = new HashMap<>();
paramForSplitInfo.put("mid", inventory.getMid());
paramForSplitInfo.put("newUnit", record.getUnit());
paramForSplitInfo.put("newUnit", unit);
// 获取对应拆单记录
SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo);
@ -973,7 +973,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
// 如果当前拆单没有父级
if (surplus < splitInfoById.getQuantity()) {
if (surplus <= splitInfoById.getQuantity()) {
// 如果当前未处理的数量小于当前拆单库存数量
@ -1242,14 +1242,24 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
if (splitInventoryForSplitInfo.getSaveQuantity() * parentScale >= nowQuantity) {
// 如果当前库存拆单记录的库存可以满足需要
// 计算当前拆单库存具体减少的数量
int realSaveQuantity = (int) Math.ceil(nowQuantity / (double) parentScale);
// 设置当前拆单库存
splitInventoryForSplitInfo.setSaveQuantity(splitInventoryForSplitInfo.getSaveQuantity() - nowQuantity);
splitInventoryForSplitInfo.setSaveQuantity(splitInventoryForSplitInfo.getSaveQuantity() - realSaveQuantity);
// 设置当前拆单出库库存数
splitInventoryForSplitInfo.setOutQuantity(splitInventoryForSplitInfo.getOutQuantity() + nowQuantity);
splitInventoryForSplitInfo.setOutQuantity(splitInventoryForSplitInfo.getOutQuantity() + realSaveQuantity);
// 修改库存记录
splitUnitMapper.updateSplitInventory(splitInventoryForSplitInfo);
// 获取对应子类
SplitInfo splitInfoByParentId = splitUnitMapper.findSplitInfoByParentId(splitInfo.getId());
if (splitInfoByParentId != null) {
paramForSplitInventory.put("sid", splitInfoByParentId.getId());
// 获取对应子类的库存
SplitInventory splitInventoryBySplitInfoByParentId = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory);
splitInventoryBySplitInfoByParentId.setSaveQuantity(realSaveQuantity * parentScale - nowQuantity);
splitUnitMapper.updateSplitInventory(splitInventoryBySplitInfoByParentId);
}
restResponse.setStatus(200);
restResponse.setData("");
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功"));
@ -1428,7 +1438,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
inventory.setQuantity(inventory.getQuantity() - surplus_redundant);
// 设置当前总额
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
if(Integer.compare(inventory.getQuantity(),0) != 0) {
if (Integer.compare(inventory.getQuantity(), 0) != 0) {
// 设置当前单价
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity());
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

46
src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java

@ -176,7 +176,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
map.put("realQuantity", quantity.toString());
if (splitInfoForUnit.getParentId() != null) {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfoForUnit.getParentId());
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, inventory.getId(), map, quantity.intValue());
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, inventory.getId(), map, quantity.intValue(),splitInfoForUnit);
} else {
Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1);
@ -210,13 +210,13 @@ public class SplitUnitServiceImpl implements SplitUnitService {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(parentId);
if (inventory != null) {
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), inventory.getId(), map, quantity.intValue());
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), inventory.getId(), map, quantity.intValue(),splitInfoForUnit);
} else {
Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1);
map.put("price", price.toString());
result += depositoryRecordService.applicationInPlace(map);
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), ObjectFormatUtil.toInteger(map.get("newInMid")), map, quantity.intValue());
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), ObjectFormatUtil.toInteger(map.get("newInMid")), map, quantity.intValue(),splitInfoForUnit);
}
} else {
Double price = Double.parseDouble((String) map.get("price"));
@ -262,7 +262,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
if (parentId != null) {
// 获取父级
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfoForUnit.getParentId());
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, ObjectFormatUtil.toInteger(map.get("newInMid")), map, quantity.intValue());
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, ObjectFormatUtil.toInteger(map.get("newInMid")), map, quantity.intValue(),splitInfoForUnit);
}
}
@ -283,17 +283,19 @@ public class SplitUnitServiceImpl implements SplitUnitService {
*/
public int findSplitInfoScaleQuantity(SplitInfo splitInfo, Integer parentSplitInfoId) {
int quantity = 1; // 定义进制
quantity *= splitInfo.getQuantity();
if(parentSplitInfoId != null && Integer.compare(-1,parentSplitInfoId) != 0){
if (parentSplitInfoId != null && Integer.compare(-1, parentSplitInfoId) != 0) {
// 如果待查询的父级不是顶级
if(Integer.compare(splitInfo.getId(),parentSplitInfoId) == 0){
if (Integer.compare(splitInfo.getParentId(), parentSplitInfoId) == 0) {
// 如果当前拆单记录是目标拆单单位
quantity *= splitInfo.getQuantity();
return quantity;
}else{
} else {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoScaleQuantity(splitInfoById,parentSplitInfoId);
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);
}
}else {
} else {
quantity *= splitInfo.getQuantity();
if (splitInfo.getParentId() != null) {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);
@ -457,9 +459,8 @@ public class SplitUnitServiceImpl implements SplitUnitService {
* @param map 入库条件
* @param inQuantity 最终入库数量
*/
private void updateSplitInfoSaveQuantity(SplitInfo splitInfo, int quantity, int iid, Map<String, Object> map, int inQuantity) {
private void updateSplitInfoSaveQuantity(SplitInfo splitInfo, int quantity, int iid, Map<String, Object> map, int inQuantity,SplitInfo baseSplitInfo) {
int result = 0;
// 获取当前拆单记录的父级拆单记录
Integer parentId = splitInfo.getParentId();
@ -475,14 +476,14 @@ public class SplitUnitServiceImpl implements SplitUnitService {
int scale = splitInfo.getQuantity();
// 计算处理数量(下取整)
int disposeQuantity = (int) Math.round(Math.floor(quantity / scale));
int disposeQuantity = (int) Math.round(Math.floor(quantity / (double)scale));
// 最终存储到拆单处理的数量
double saveQuantity = quantity - disposeQuantity * scale;
if (splitInventory != null) {
// 如果拆单库存处理记录不为空
if (splitInventory.getSaveQuantity() + saveQuantity > splitInfo.getQuantity()) {
if (splitInventory.getSaveQuantity() + saveQuantity >= splitInfo.getQuantity()) {
// 当前库存拆单记录与新入库的数目大于预设的进制
@ -505,25 +506,26 @@ public class SplitUnitServiceImpl implements SplitUnitService {
// 获取具体父级
SplitInfo splitInfoForParent = splitUnitMapper.findSplitInfoById(parentId);
updateSplitInfoSaveQuantity(splitInfoForParent, disposeQuantity, splitInventory.getIid(), map, inQuantity);
updateSplitInfoSaveQuantity(splitInfoForParent, disposeQuantity, splitInventory.getIid(), map, inQuantity,baseSplitInfo);
} else {
// 如果为空
Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoScaleQuantity(splitInfo, -1);
price = price * findSplitInfoScaleQuantity(baseSplitInfo, -1);
map.put("price", price.toString());
map.put("quantity", String.valueOf(disposeQuantity));
map.put("realQuantity", String.valueOf(inQuantity));
depositoryRecordService.applicationInPlace(map);
}
} else {
}
else {
// 当前库存拆单记录与新入库的数目不大于预设的进制
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() + disposeQuantity);
splitInventory.setInQuantity(splitInventory.getInQuantity() + disposeQuantity);
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() + (int)saveQuantity);
splitInventory.setInQuantity(splitInventory.getInQuantity() + (int)saveQuantity);
splitUnitMapper.updateSplitInventory(splitInventory);
Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoScaleQuantity(splitInfo, -1);
price = price * findSplitInfoScaleQuantity(baseSplitInfo, -1);
map.put("price", price.toString());
map.put("quantity", "0");
map.put("realQuantity", String.valueOf(inQuantity));
@ -554,10 +556,10 @@ public class SplitUnitServiceImpl implements SplitUnitService {
// 获取当前拆单记录的父级
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(parentId);
updateSplitInfoSaveQuantity(parentSplitInfo, quantity_scale, iid, map, inQuantity);
updateSplitInfoSaveQuantity(parentSplitInfo, quantity_scale, iid, map, inQuantity,baseSplitInfo);
} else {
Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoScaleQuantity(splitInfo, -1);
price = price * findSplitInfoScaleQuantity(baseSplitInfo, -1);
map.put("price", price.toString());
map.put("quantity", String.valueOf(quantity_scale));
map.put("realQuantity", String.valueOf(inQuantity));

8
src/main/resources/templates/pages/scanQrCode/ScanBarOrQrCodeOut.html

@ -310,10 +310,10 @@
maxmin: true,
shadeClose: true,
area: ['50%', '50%'],
content: '/ScanBarOrQrCodeOut_selectMaterial?pid=' + place.id+'&mcode='+mcode+'&depositoryId='+place.did,
content: '/ScanBarOrQrCodeOut_selectMaterial?pid=' + place.id + '&mcode=' + mcode + '&depositoryId=' + place.did,
end: function () {
let flagForSelect = layui.$("#flagForSelect").val();
if(flagForSelect === 'true'){
if (flagForSelect === 'true') {
var param = {};
param.id = id;
param.placeId = place.id;
@ -397,10 +397,10 @@
maxmin: true,
shadeClose: true,
area: ['50%', '50%'],
content: '/ScanBarOrQrCodeOut_selectMaterial?pid=' + 0+'&mcode='+mcode+'&depositoryId='+depository.id,
content: '/ScanBarOrQrCodeOut_selectMaterial?pid=' + 0 + '&mcode=' + mcode + '&depositoryId=' + depository.id,
end: function () {
let flagForSelect = layui.$("#flagForSelect").val();
if(flagForSelect === 'true'){
if (flagForSelect === 'true') {
var param = {};
param.id = id;
param.qrCode = qrCode;

20
src/test/java/com/dreamchaser/depository_manage/TestForOther.java

@ -36,31 +36,35 @@ public class TestForOther {
@Test
public void Test() throws IOException {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(7);
double splitInfoScaleQuantity = findSplitInfoScaleQuantity(splitInfoById, 7);
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(4);
double splitInfoScaleQuantity = findSplitInfoScaleQuantity(splitInfoById, null);
System.out.println(splitInfoScaleQuantity);
}
/**
* 用于计算当前拆单单位与目标拆单单位之间的进率
*
* @param splitInfo 待查询拆单记录
* @param parentSplitInfoId 目标拆单单位
* @return
*/
public int findSplitInfoScaleQuantity(SplitInfo splitInfo, Integer parentSplitInfoId) {
int quantity = 1; // 定义进制
quantity *= splitInfo.getQuantity();
if(parentSplitInfoId != null && Integer.compare(-1,parentSplitInfoId) != 0){
if (parentSplitInfoId != null && Integer.compare(-1, parentSplitInfoId) != 0) {
// 如果待查询的父级不是顶级
if(Integer.compare(splitInfo.getId(),parentSplitInfoId) == 0){
if (Integer.compare(splitInfo.getParentId(), parentSplitInfoId) == 0) {
// 如果当前拆单记录是目标拆单单位
quantity *= splitInfo.getQuantity();
return quantity;
}else{
} else {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoScaleQuantity(splitInfoById,parentSplitInfoId);
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);
}
}else {
} else {
quantity *= splitInfo.getQuantity();
if (splitInfo.getParentId() != null) {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);

Loading…
Cancel
Save