Browse Source

完成拆单出库功能

lwx_dev
erdanergou 3 years ago
parent
commit
e2d5813057
  1. 138
      src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java
  2. 1
      src/main/resources/templates/pages/material/selectMaterial.html
  3. 77
      src/main/resources/templates/pages/split/split_add.html
  4. 2
      src/main/resources/templates/pages/warehouse/depository_add.html
  5. 5
      src/test/java/com/dreamchaser/depository_manage/TestForOther.java

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

@ -46,33 +46,35 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 用于添加一条拆单记录
*
* @param map 待添加数据
* @return
*/
@Override
public Integer addSplitInfo(Map<String, Object> map) {
// 查询该物料拆单前是否存在该计量单位
Map<String,Object> paramForUnit = new HashMap<>();
Map<String, Object> paramForUnit = new HashMap<>();
// 获取物料id
paramForUnit.put("mid",map.get("mid"));
paramForUnit.put("mid", map.get("mid"));
// 获取拆单前的计量单位
paramForUnit.put("oldUnit",map.get("oldUnit"));
paramForUnit.put("newUnit", map.get("oldUnit"));
// 查询当前要拆单的记录是否已经是拆单过的
SplitInfo splitInfoForUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForUnit);
if(splitInfoForUnit != null){
if (splitInfoForUnit != null) {
// 如果是拆单过
map.put("parentId",splitInfoForUnit.getId());
}else{
map.put("parentId", splitInfoForUnit.getId());
} else {
// 如果没有
map.put("parentId",null);
map.put("parentId", null);
}
// 插入
map.put("state",1);
map.put("state", 1);
return splitUnitMapper.addSplitInfo(map);
}
/**
* 用于添加一条拆单库存处理记录
*
* @param map 待添加数据
* @return
*/
@ -80,15 +82,21 @@ public class SplitUnitServiceImpl implements SplitUnitService {
@Transactional(rollbackFor = Exception.class)
public Integer addSplitInventory(Map<String, Object> map) {
Map<String,Object> paramForSplitInfo = new HashMap<>();
paramForSplitInfo.put("mid",map.get("mid"));
paramForSplitInfo.put("newUnit",map.get("unit"));
Map<String, Object> paramForSplitInfo = new HashMap<>();
paramForSplitInfo.put("mid", map.get("mid"));
paramForSplitInfo.put("newUnit", map.get("unit"));
// 查询当前拆单是否存在
SplitInfo splitInfoForUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo);
// 用于存储最终计算结果
Integer result = 0;
if(splitInfoForUnit != null) {
if (splitInfoForUnit != null) {
// 获取当前进制
// Integer scale = findSplitInfoQuantity(splitInfoForUnit);
Integer scale = findSplitInfoQuantity(splitInfoForUnit);
// 获取当前处理的类型
String type = (String) map.get("type");
@ -100,25 +108,26 @@ public class SplitUnitServiceImpl implements SplitUnitService {
// 定义对应的库存记录
Inventory inventory = null;
// 用于存储拆单库存处理操作的数据
Map<String,Object> paramForInsertSplitInventory = new HashMap<>();
paramForInsertSplitInventory.put("sid",splitInfoForUnit.getId());
if(iid != null){
paramForInsertSplitInventory.put("iid",iid);
Map<String, Object> paramForInsertSplitInventory = new HashMap<>();
paramForInsertSplitInventory.put("sid", splitInfoForUnit.getId());
if (iid != null) {
paramForInsertSplitInventory.put("iid", iid);
// 查询当前库存是否有该拆单的处理记录
splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForInsertSplitInventory);
// 获取对应的库存记录
inventory = materialMapper.findInventoryById(iid);
}
else{
} else {
Map<String, Object> param = new HashMap<>();
param.put("depositoryId", map.get("depositoryId"));
param.put("mid", map.get("mid"));
// 判断该仓库中有无该物物料
List<Inventory> materialByCondition = materialMapper.findInventory(param);
if(materialByCondition.size() > 0){
if (materialByCondition.size() > 0) {
inventory = materialByCondition.get(0);
paramForInsertSplitInventory.put("iid",inventory.getId());
paramForInsertSplitInventory.put("iid", inventory.getId());
// 查询当前库存是否有该拆单的处理记录
splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForInsertSplitInventory);
@ -131,71 +140,89 @@ public class SplitUnitServiceImpl implements SplitUnitService {
// 如果是入库操作
// 计算处理数量(下取整)
int disposeQuantity = (int) Math.round(Math.floor(quantity / splitInfoForUnit.getQuantity()));
int disposeQuantity = (int) Math.round(Math.floor(quantity / scale));
// 最终存储到拆单处理的数量
double saveQuantity = quantity - disposeQuantity * splitInfoForUnit.getQuantity();
if(splitInventory != null){
double saveQuantity = quantity - disposeQuantity * scale;
if (splitInventory != null) {
// 如果有过记录
// 最终存储数量
int realQuantity = (int) Math.round(saveQuantity) + splitInventory.getSaveQuantity();
if(realQuantity > splitInfoForUnit.getQuantity()){
if (realQuantity > scale) {
// 如果当前入库的数量大于拆单规定的进制数量
int quantity_in = realQuantity - (realQuantity / splitInfoForUnit.getQuantity());
disposeQuantity += quantity_in;
realQuantity = realQuantity - quantity_in * splitInfoForUnit.getQuantity();
int quantity_in = realQuantity - (realQuantity / scale);
disposeQuantity += quantity_in;
realQuantity = realQuantity - quantity_in * scale;
}
// 设置当前计量单位的库存
splitInventory.setSaveQuantity(realQuantity);
// 设置当前计量单位的入库数目
if(splitInventory.getInQuantity() != null){
splitInventory.setInQuantity((int) Math.round(splitInventory.getInQuantity() + quantity));
}else{
splitInventory.setInQuantity((int)Math.round(quantity));
if (splitInventory.getInQuantity() != null) {
// 如果当前库存不为空
splitInventory.setInQuantity((int) Math.round(splitInventory.getInQuantity() + quantity));
} else {
splitInventory.setInQuantity((int) Math.round(quantity));
}
splitUnitMapper.updateSplitInventory(splitInventory);
if(disposeQuantity != 0) {
if (disposeQuantity != 0) {
// 用于更改库存的数量
map.put("quantity", String.valueOf(disposeQuantity));
}else{
} else {
map.put("quantity", "0");
}
// 实际入库数量
map.put("realQuantity", quantity.toString());
result += depositoryRecordService.applicationInPlace(map);
}else{
} else {
// 如果没有记录
if(disposeQuantity != 0) {
if (disposeQuantity != 0) {
// 用于更改库存的数量
map.put("quantity", String.valueOf(disposeQuantity));
}
else{
} else {
map.put("quantity", "0");
}
// 实际入库数量
map.put("realQuantity", quantity.toString());
result += depositoryRecordService.applicationInPlace(map);
paramForInsertSplitInventory.put("inQuantity",quantity);
paramForInsertSplitInventory.put("outQuantity",0);
paramForInsertSplitInventory.put("saveQuantity",saveQuantity);
paramForInsertSplitInventory.put("iid",map.get("newInMid"));
paramForInsertSplitInventory.put("inQuantity", quantity);
paramForInsertSplitInventory.put("outQuantity", 0);
paramForInsertSplitInventory.put("saveQuantity", saveQuantity);
paramForInsertSplitInventory.put("iid", map.get("newInMid"));
splitUnitMapper.addSplitInventory(paramForInsertSplitInventory);
}
}
}
return result;
}
/**
* 用于计算当前拆单单位与基础单位之间的进率
*
* @param splitInfo 待查询拆单记录
* @return
*/
private int findSplitInfoQuantity(SplitInfo splitInfo) {
int quantity = 1;
quantity *= splitInfo.getQuantity();
if (splitInfo.getParentId() != null) {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoQuantity(splitInfoById);
} else {
return quantity;
}
}
/**
* 根据条件查询对应拆单详细信息
*
* @param map 查询条件
* @return
*/
@ -211,15 +238,16 @@ public class SplitUnitServiceImpl implements SplitUnitService {
map.put("begin", (page - 1) * size);
}
Object state = 1;
if(map.containsKey("sstate")){
if (map.containsKey("sstate")) {
state = map.get("sstate");
}
map.put("sstate",state);
map.put("sstate", state);
return splitUnitMapper.findSplitInfoPByCondition(map);
}
/**
* 根据条件查询对应拆单数量
*
* @param map 查询条件
* @return
*/
@ -230,6 +258,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 根据主键删除拆单信息软删除
*
* @param id 待删除id
* @return
*/
@ -244,17 +273,17 @@ public class SplitUnitServiceImpl implements SplitUnitService {
for (SplitInventory splitInventory :
splitInventoryList) {
Integer saveQuantity = splitInventory.getSaveQuantity();
if(Integer.compare(saveQuantity,0) != 0){
if (Integer.compare(saveQuantity, 0) != 0) {
// 如果当前记录的剩余库存不为0
flag = false;
break;
}
}
if(flag){
if (flag) {
// 如果可以删除
splitInfo.setState(3);
return splitUnitMapper.updateSplitInfo(splitInfo);
}else{
} else {
// 如果不可以
return -1;
}
@ -262,6 +291,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 根据主键删除拆单信息硬删除
*
* @param id 待删除id
* @return
*/
@ -276,16 +306,16 @@ public class SplitUnitServiceImpl implements SplitUnitService {
for (SplitInventory splitInventory :
splitInventoryList) {
Integer saveQuantity = splitInventory.getSaveQuantity();
if(Integer.compare(saveQuantity,0) != 0){
if (Integer.compare(saveQuantity, 0) != 0) {
// 如果当前记录的剩余库存不为0
flag = false;
break;
}
}
if(flag){
if (flag) {
// 如果可以删除
return splitUnitMapper.delSplitInfoById(splitInfo.getId());
}else{
} else {
// 如果不可以
return -1;
}
@ -293,6 +323,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 根据条件修改拆单信息
*
* @param map 待修改数据
* @return
*/
@ -304,6 +335,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 根据主键id获取拆单信息
*
* @param id 待查询主键
* @return
*/
@ -314,6 +346,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 根据主键id获取拆单详细信息
*
* @param id 待查询主键
* @return
*/
@ -324,6 +357,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 根据物料id查询对应的拆单记录
*
* @param mid 待查询物料id
* @return
*/
@ -335,6 +369,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 通过物料id与拆单前的计量单位获取对应拆单记录
*
* @param map 查询条件
* @return
*/
@ -345,6 +380,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/**
* 根据库存id获取对应拆单库存处理记录
*
* @param Iid 待查询库存id
* @return
*/

1
src/main/resources/templates/pages/material/selectMaterial.html

@ -23,6 +23,7 @@
var tempData = [];
var req = {};
req.mname = mname;
req.type = "1";
var test = tree.render({
elem: '#test2'
, data: []

77
src/main/resources/templates/pages/split/split_add.html

@ -34,10 +34,10 @@
padding-right: 0px;
}
.inputdiv .layui-unselect {
border-style: none;
.layui-form-select{
width: 100%;
}
</style>
<div class="layuimini-container">
<div class="layuimini-main">
@ -119,8 +119,9 @@
<label class="layui-form-label">计量单位:</label>
<div class="layui-input-block">
<input type="text" name="oldUnit" class="layui-input" id="unit" readonly
lay-verify="required"/>
<select id="unit" name="oldUnit">
</select>
</div>
</div>
@ -240,7 +241,7 @@
codeValue.val("");
version.val("");
typeName.val("");
unit.val("");
unit.empty();
return false;
} else if (d.count === 0) {
layer.msg("没有该物品,请确认输入是否正确");
@ -249,7 +250,7 @@
materialName.val("");
version.val("");
typeName.val("");
unit.val("");
unit.empty();
return false;
} else {
var material = d.data[0];
@ -258,7 +259,34 @@
codeValue.val(material.code);
version.val(material.version);
typeName.val(material.typeName);
unit.val(material.unit);
unit.append(new Option(material.unit,material.unit));
var splitInfoList = material["splitInfoList"];
$.each(splitInfoList,function (index,item) {
$("#unit").append(new Option(item.newUnit, item.newUnit));//往下拉菜单里添加元素
});
form.render();
var materialAndBarCodeList = material["materialAndBarCodeList"];
if (materialAndBarCodeList !== null && materialAndBarCodeList.length > 0) {
// 如果有对应的条形码
$("#barCode").remove();
var barCodeSelect = `
<select id="barCode" name= "barCode"></select>`;
$("#barCodeImg").before(barCodeSelect);
form.render();
$.each(materialAndBarCodeList, function (index, item) {
$("#barCode").append(new Option(item.bmcode, item.id));//往下拉菜单里添加元素
});
form.render();
}else{
let children = $("#barCode").parent().children();
if(children.length > 2){
$("#barCode").empty();
$(children[1]).empty();
}
}
}
}
});
@ -301,10 +329,16 @@
}
$("#code").val(code);
$("#version").val(material.version);
$("#unit").val(material.unit);
$("#unit").append(new Option(material.unit,material.unit));
var splitInfoList = material["splitInfoList"];
$.each(splitInfoList,function (index,item) {
$("#unit").append(new Option(item.newUnit, item.newUnit));//往下拉菜单里添加元素
});
form.render();
$("#typeName").val(material.typeName);
var materialAndBarCodeList = material["materialAndBarCodeList"];
if (materialAndBarCodeList.length > 0) {
if (materialAndBarCodeList !== null && materialAndBarCodeList.length > 0) {
// 如果有对应的条形码
$("#barCode").remove();
var barCodeSelect = `
@ -315,6 +349,12 @@
$("#barCode").append(new Option(item.bmcode, item.id));//往下拉菜单里添加元素
});
form.render();
}else{
let children = $("#barCode").parent().children();
if(children.length > 2){
$("#barCode").empty();
$(children[1]).empty();
}
}
}
});
@ -406,7 +446,7 @@
$("#code").val("");
$("#barCode").val("");
$("#version").val("");
$("#unit").val("");
$("#unit").empty();
$("#typeName").val("");
form.render();
@ -414,11 +454,17 @@
$("#mname").val(d.mname);
$("#mid").val( d.mid);
$("#version").val(d.version);
$("#unit").val(d.unit);
$("#unit").empty();
$('#unit').append(new Option(d.unit,d.unit));
var splitInfoList = d["splitInfoList"];
$.each(splitInfoList,function (index,item) {
$("#unit").append(new Option(item.newUnit, item.newUnit));//往下拉菜单里添加元素
});
form.render();
$("#typeName").val(d.typeName);
// 获取物料与条形码的对应关系
var materialAndBarCodeList = d["materialAndBarCodeList"];
if (materialAndBarCodeList.length > 0) {
if (materialAndBarCodeList !== null && materialAndBarCodeList.length > 0) {
// 如果有对应的条形码
$("#barCode").remove();
$(".layui-unselect").remove();
@ -433,8 +479,11 @@
});
form.render();
} else {
$("#barCode").remove();
$(".layui-unselect").remove();
let children = $("#barCode").parent().children();
if(children.length > 2){
$("#barCode").empty();
$(children[1]).empty();
}
}
}

2
src/main/resources/templates/pages/warehouse/depository_add.html

@ -112,7 +112,7 @@
dataType:'json',
contentType: "application/json;charset=utf-8",
success:function(d){
if(data.value != "") {
if(data.value !== "") {
$('#adminorg').empty();
$('#adminorg').append(new Option("请选择部门", ""));
$.each(d.data, function (index, item) {

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

@ -1,8 +1,11 @@
package com.dreamchaser.depository_manage;
import com.dreamchaser.depository_manage.entity.SplitInfo;
import com.dreamchaser.depository_manage.mapper.SplitUnitMapper;
import com.dreamchaser.depository_manage.utils.CreateQrCodeUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import sun.misc.BASE64Decoder;
@ -21,8 +24,10 @@ import java.io.OutputStream;
public class TestForOther {
@Test
public void Test() throws IOException {
}
}

Loading…
Cancel
Save