Browse Source

编写删除入库记录修改库存记录功能

lwx_dev
erdanergou 3 years ago
parent
commit
626fc42417
  1. 9
      src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java
  2. 4
      src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java
  3. 275
      src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java
  4. 2
      src/main/resources/templates/pages/application/application-out.html
  5. 2
      src/main/resources/templates/pages/application/application-out_back.html
  6. 2
      target/classes/templates/pages/application/application-out.html
  7. 2
      target/classes/templates/pages/application/application-out_back.html

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

@ -966,13 +966,16 @@ public class DepositoryRecordController {
// 删除入库记录
@PostMapping("/deleteApplicationInRecord")
public RestResponse deleteApplicationInRecord(@RequestBody Map<String, Object> map) {
public RestResponse deleteApplicationInRecord(@RequestBody Map<String, Object> map,HttpServletRequest request) {
UserByPort userByPort = (UserByPort) request.getAttribute("userToken");
String header = request.getHeader("user-agent");
String crypt = Md5.crypt(header);
if (map.containsKey("id")) {
Integer id = ObjectFormatUtil.toInteger(map.get("id"));
return CrudUtil.deleteHandle(depositoryRecordService.deleteApplicationInRecordById(id), 1);
return CrudUtil.deleteHandle(depositoryRecordService.deleteApplicationInRecordById(id,userByPort,crypt), 1);
} else if (map.containsKey("ids")) {
List<Integer> ids = (List<Integer>) map.get("ids");
return CrudUtil.deleteHandle(depositoryRecordService.deleteApplicationInRecordByIds(ids), ids.size());
return CrudUtil.deleteHandle(depositoryRecordService.deleteApplicationInRecordByIds(ids,userByPort,crypt), ids.size());
} else {
throw new MyException("所需请求参数缺失!");
}

4
src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java

@ -331,14 +331,14 @@ public interface DepositoryRecordService {
* @return 受影响的行数
* @param id
*/
Integer deleteApplicationInRecordById(Integer id);
Integer deleteApplicationInRecordById(Integer id,UserByPort userToken,String userAgent);
/**
* 根据id集合删除多条入库记录
* @param list id集合
* @return 受影响的行数
*/
Integer deleteApplicationInRecordByIds(List<Integer> list);
Integer deleteApplicationInRecordByIds(List<Integer> list,UserByPort userToken,String userAgent);
/**
* 插入一条出库记录

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

@ -1407,6 +1407,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
return restResponse;
}
/**
* 用于有父级拆单记录的出库处理
*
@ -4047,7 +4048,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
* @return 受影响的行数
*/
@Override
public Integer deleteApplicationInRecordById(Integer id) {
public Integer deleteApplicationInRecordById(Integer id, UserByPort userToken, String userAgent) {
new Thread(new Runnable() {
@Override
public void run() {
}
}).start();
return depositoryRecordMapper.deleteApplicationInRecordById(id);
}
@ -4058,10 +4064,275 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
* @return 受影响的行数
*/
@Override
public Integer deleteApplicationInRecordByIds(List<Integer> list) {
public Integer deleteApplicationInRecordByIds(List<Integer> list, UserByPort userToken, String userAgent) {
return depositoryRecordMapper.deleteApplicationInRecordByIds(list);
}
/**
* 用于修改入库订单错误时的库存数量
*
* @param mid 入库物料
* @param quantity 入库数量
* @param unit 入库单位
* @param placeId 入库库位
* @param depositoryId 入库仓库
*/
void updateInventoryForErrorInRecord(Integer mid, Integer quantity, String unit, Integer placeId, Integer depositoryId) {
// 获取当前入库时的物料
Material material = materialMapper.findMaterialById(mid);
// 如果当前入库时的单位为基础单位
Map<String, Object> paramForMidAndDid = new HashMap<>();
paramForMidAndDid.put("mid", mid);
paramForMidAndDid.put("did", depositoryId);
// 根据入库的物料id与仓库id获取库存记录
Inventory inventory = materialMapper.findInventoryByMidAndDid(paramForMidAndDid);
// 查询当前物料与库位的映射关系
Map<String, Object> paramForMaterialAndPlace = new HashMap<>();
paramForMaterialAndPlace.put("mid", inventory.getId());
paramForMaterialAndPlace.put("pid", placeId);
MaterialAndPlace placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(paramForMaterialAndPlace);
if (unit.equals(material.getUnit())) {
// 如果存在库存记录
// 查询当前入库库位
Place place = placeMapper.findPlaceById(placeId);
if (placeAndMaterialByMidAndPid != null) {
// 修改当前库存记录
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - quantity);
place.setQuantity(place.getQuantity() - quantity);
inventory.setQuantity(inventory.getQuantity() - quantity);
materialMapper.updateInventory(inventory);
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid);
placeMapper.UpdatePlace(place);
}
}
else {
// 如果不是基础单位
Map<String, Object> paramForSplitInfo = new HashMap<>();
paramForSplitInfo.put("newUnit", unit);
paramForSplitInfo.put("mid", mid);
SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo);
if (splitInfo != null) {
// 如果拆单记录存在
if (placeAndMaterialByMidAndPid != null) {
// 如果映射关系存在
Map<String, Object> paramForSplitInventory = new HashMap<>();
paramForSplitInventory.put("sid", splitInfo.getId());
paramForSplitInventory.put("iid", placeAndMaterialByMidAndPid.getId());
// 获取拆单库存记录
SplitInventory splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory);
if (splitInventory != null) {
// 如果拆单库存处理记录存在
if (splitInventory.getSaveQuantity() >= quantity) {
// 如果当前待处理数目可以满足需求
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - quantity);
// 修改库存处理记录
splitUnitMapper.updateSplitInventory(splitInventory);
}
else {
// 如果不能满足需求
// 获取剩余不足的数量
int surplus = quantity - splitInventory.getSaveQuantity();
if (splitInfo.getParentId() != null) {
// 如果当前拆单有父级
// 将当前库存设置为0
splitInventory.setSaveQuantity(0);
// 修改库存数量
splitUnitMapper.updateSplitInventory(splitInventory);
// 获取当前父级拆单记录
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
updateOutSplitInventoryInfo(parentSplitInfo, placeAndMaterialByMidAndPid, quantity, surplus, splitInfo);
}
else {
// 如果当前拆单没有父级
boolean flag = true;
if (surplus <= splitInfo.getQuantity()) {
// 如果当前未处理的数量小于当前拆单库存数量
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;
}
// 如果物料数量可以出库并且库位数量充足
if (inventory.getQuantity() >= 1 && flag) {
// 令库存-1
inventory.setQuantity(inventory.getQuantity() - 1);
// 修改库存记录
materialMapper.updateInventory(inventory);
// 修改当前库位存放物料的数量
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - 1);
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid);
// 修改库位数量
Place placeById = placeMapper.findPlaceById(placeId);
placeById.setQuantity(placeById.getQuantity() - 1);
placeMapper.UpdatePlace(placeById);
// 如果是库存转移订单
// 设置剩余拆单库存处理数量
splitInventory.setSaveQuantity(splitInfo.getQuantity() + splitInventory.getSaveQuantity() - quantity);
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + quantity);
splitUnitMapper.updateSplitInventory(splitInventory);
}
} else {
// 如果大于
// 获取库存重要减少的数量
int surplus_redundant = surplus / splitInfo.getQuantity();
// 获取拆单库存处理中要处理数量
int saveQuantity = surplus - surplus_redundant * splitInfo.getQuantity();
if (saveQuantity > splitInventory.getSaveQuantity()) {
// 如果要处理的数量大于剩余数量
// 获取一个数量
surplus_redundant += 1;
splitInventory.setSaveQuantity(splitInfo.getQuantity() + splitInventory.getSaveQuantity() - saveQuantity);
} else {
// 如果不大于
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - saveQuantity);
}
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + saveQuantity);
Map<String, Object> paramsFor = new HashMap<>();
paramsFor.put("mid", inventory.getId());
paramsFor.put("pid", placeId);
// 获取当前物料在库位中的数量
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(paramsFor);
if (placeAndMaterialByMidAndPid != null) {
// 如果当前库位存在该物料
if (placeAndMaterialByMidAndPid.getQuantity() < surplus_redundant) {
// 如果当前库存中的物料库存不足以出库
flag = false;
}
}
if (inventory.getQuantity() >= surplus_redundant && flag) {
// 如果能够出库
// 令库存-1
inventory.setQuantity(inventory.getQuantity() - surplus_redundant);
// 修改库存记录
materialMapper.updateInventory(inventory);
// 修改当前库位存放物料的数量
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - surplus_redundant);
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid);
// 修改库位数量
Place placeById = placeMapper.findPlaceById(placeId);
placeById.setQuantity(placeById.getQuantity() - surplus_redundant);
placeMapper.UpdatePlace(placeById);
} else {
// restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足"));
}
}
}
}
}
}
else {
// 如果拆单库存处理记录不存在
int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1);
if (inventory.getQuantity() * scale > quantity) {
// 如果当前库存数量满足要求
// 获取当前出库的具体数目
int residue = (int) Math.ceil(quantity / (double) splitInfo.getQuantity());
// 获取剩余数目
int residue_realQuantity = residue * scale - quantity;
// 设置新库存
inventory.setQuantity(inventory.getQuantity() - residue);
//更新库存
materialMapper.updateInventory(inventory);
// 更新对应库位的库存
// 修改当前库位存放物料的数量
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - residue);
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid);
// 修改库位数量
Place placeById = placeMapper.findPlaceById(placeId);
placeById.setQuantity(placeById.getQuantity() - residue);
placeMapper.UpdatePlace(placeById);
// 插入拆单记录
Map<String, Object> insertForSplitInventory = new HashMap<>();
insertForSplitInventory.put("mid", inventory.getMid());
insertForSplitInventory.put("mcode", inventory.getCode());
insertForSplitInventory.put("quantity", residue_realQuantity);
insertForSplitInventory.put("unit", unit);
insertForSplitInventory.put("depositoryId", depositoryId);
insertForSplitInventory.put("placeId", placeAndMaterialByMidAndPid.getPid());
insertForSplitInventory.put("type", "in");
splitUnitService.addSplitInventory(insertForSplitInventory);
Integer new_id = ObjectFormatUtil.toInteger(insertForSplitInventory.get("newInMid"));
depositoryRecordMapper.deleteApplicationInRecordById(new_id);
}
}
}
}
}
}
/**
* 对查出来的记录进行包装包装成前端需要的数据
*

2
src/main/resources/templates/pages/application/application-out.html

@ -1468,7 +1468,7 @@
success: function (res) {
var flag = res.data;
if (!flag) { // 如果当前数目不合适
layer.msg("当前物料数量不足", {icon: 0, time: 500}, function () {
layer.msg("当前单个仓库中物料数量不足", {icon: 0, time: 500}, function () {
$("#quantity" + id).val("");
});

2
src/main/resources/templates/pages/application/application-out_back.html

@ -378,7 +378,7 @@
success: function (res) {
var flag = res.data;
if (!flag) { // 如果当前数目不合适
layer.msg("当前物料数量不足", {icon: 0, time: 500}, function () {
layer.msg("当前单仓库中物料数量不足", {icon: 0, time: 500}, function () {
$("#quantity").val("");
});

2
target/classes/templates/pages/application/application-out.html

@ -1468,7 +1468,7 @@
success: function (res) {
var flag = res.data;
if (!flag) { // 如果当前数目不合适
layer.msg("当前物料数量不足", {icon: 0, time: 500}, function () {
layer.msg("当前单个仓库中物料数量不足", {icon: 0, time: 500}, function () {
$("#quantity" + id).val("");
});

2
target/classes/templates/pages/application/application-out_back.html

@ -378,7 +378,7 @@
success: function (res) {
var flag = res.data;
if (!flag) { // 如果当前数目不合适
layer.msg("当前物料数量不足", {icon: 0, time: 500}, function () {
layer.msg("当前单仓库中物料数量不足", {icon: 0, time: 500}, function () {
$("#quantity").val("");
});

Loading…
Cancel
Save