Browse Source

添加库存搜索按库位搜索,且修复库内移动时的bug

lwx_dev
erdanergou 2 years ago
parent
commit
b56a4313a4
  1. 151
      src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java
  2. 11
      src/main/resources/templates/pages/depository/table-stock.html
  3. 11
      target/classes/templates/pages/depository/table-stock.html

151
src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java

@ -14,6 +14,7 @@ import com.dreamchaser.depository_manage.security.pool.RedisPool;
import com.dreamchaser.depository_manage.service.*;
import com.dreamchaser.depository_manage.utils.DateUtil;
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@ -26,6 +27,7 @@ import java.util.concurrent.*;
/**
* @author Dreamchaser
*/
@Slf4j
@Service
public class MaterialServiceImpl implements MaterialService {
@Autowired
@ -301,7 +303,7 @@ public class MaterialServiceImpl implements MaterialService {
}
map.put("state", state);
List<Inventory> list = materialMapper.findInventory(map);
return pack(list);
return pack(list, map.get("placeId"));
}
/**
@ -752,9 +754,20 @@ public class MaterialServiceImpl implements MaterialService {
* @param list DepositoryRecord集合
* @return 包装好的集合
*/
private List<InventoryP> pack(List<Inventory> list) {
private List<InventoryP> pack(List<Inventory> list, Object pid) {
List<InventoryP> result = new ArrayList<>(list.size());
boolean flagForByPlace = false;
int placeId = -1;
if (pid != null) {
try {
placeId = ObjectFormatUtil.toInteger(pid);
if (placeId != 0) {
flagForByPlace = true;
}
} catch (Exception e) {
log.error("查看库存时,库位转换失败");
}
}
for (Inventory inventory : list) {
if (inventory.getPrice() != null) {
inventory.setPrice(inventory.getPrice() / 100);
@ -764,23 +777,91 @@ public class MaterialServiceImpl implements MaterialService {
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
// 获取当前物料所处仓库
Integer depositoryId = inventory.getDepositoryId();
List<PlaceP> placePList = new ArrayList<>();
if (flagForByPlace) {
// 如果是根据库位查询
placePList.add(new PlaceP(placeService.findPlaceById(placeId)));
} else {
// 如果不是
// 获取当前物料所处库位
Integer mid = inventory.getId();
List<PlaceP> placeByMidAndDid = placeService.findPlaceByMidAndDid(mid, depositoryId);
placePList = placeService.findPlaceByMidAndDid(mid, depositoryId);
}
InventoryP m = new InventoryP(inventory);
Map<String, Double> splitInventoryForUnit = new HashMap<>();
splitInventoryForUnit.put(inventory.getUnit(), (double) inventory.getQuantity() / 100);
m.setBaseUnitQuantity((double) inventory.getQuantity() / 100);
// 定义最后展示单位及数目
String unit = inventory.getUnit();
//定义总额
double amounts = 0.0;
boolean flagForInventoryAndPlace = true;
for (PlaceP place :
placePList) {
// 获取当前具体数据
MaterialAndPlace placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialByMidAndPid(place.getId(), m.getId());
if (placeAndMaterialByMidAndPid == null) {
flagForInventoryAndPlace = false;
continue;
} else {
flagForInventoryAndPlace = true;
}
// 获取当前是否存在拆单处理记录
// 获取当前物料对应的所有拆单数目
List<SplitInfo> splitInfoByMid = splitUnitMapper.findSplitInfoByMid(inventory.getMid());
for (SplitInfo splitInfo : splitInfoByMid
) {
// 获取当前拆单单位的总数
double saveQuantity = splitUnitService.findAllInventoryForSplitInfo(-1, placeAndMaterialByMidAndPid, splitInfo.getId(), 0, true);
if (splitInventoryForUnit.containsKey(splitInfo.getNewUnit())) {
// 如果当前存在该拆单类型的记录
// 更新当前类型数据
splitInventoryForUnit.put(splitInfo.getNewUnit(), splitInventoryForUnit.get(splitInfo.getNewUnit()) + saveQuantity);
} else {
// 如果不存在,则新增
splitInventoryForUnit.put(splitInfo.getNewUnit(), saveQuantity);
}
if (inventory.getPrice() == null) {
inventory.setPrice(0.0);
}
int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1);
BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / scale);
double split_price = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
amounts = ObjectFormatUtil.sum(amounts, split_price * saveQuantity);
unit = splitInfo.getNewUnit();
}
}
if (!flagForInventoryAndPlace) {
continue;
}
StringBuilder placeCode = new StringBuilder();
StringBuilder placeKingdeeCode = new StringBuilder();
for (PlaceP placeP : placeByMidAndDid) {
for (PlaceP placeP : placePList) {
placeKingdeeCode.append(placeP.getKingdeecode()).append(" ");
placeCode.append(placeP.getCode()).append(" ");
}
if (depositoryId != null) {
Depository depositoryRecordById = depositoryMapper.findDepositoryById(depositoryId);
String code = depositoryRecordById.getCode();
inventory.setDepositoryCode(code);
m.setDepositoryCode(code);
}
inventory.setPlaceCode(placeCode.toString());
inventory.setPlaceKingdeeCode(placeKingdeeCode.toString());
InventoryP m = new InventoryP(inventory);
m.setPlaceCode(placeCode.toString());
m.setPlaceKingdeeCode(placeKingdeeCode.toString());
Integer warningCount = 0;
if (depositoryId != null) {
m.setDepositoryName(depositoryMapper.findDepositoryNameById(depositoryId));
@ -831,49 +912,7 @@ public class MaterialServiceImpl implements MaterialService {
m.setTypeId(materialTypeByOldId.getOldId());
m.setWarningCount(warningCount);
Map<String, Double> splitInventoryForUnit = new HashMap<>();
splitInventoryForUnit.put(inventory.getUnit(), (double) inventory.getQuantity() / 100);
m.setBaseUnitQuantity((double) inventory.getQuantity() / 100);
// 定义最后展示单位及数目
String unit = inventory.getUnit();
//定义总额
double amounts = 0.0;
for (PlaceP place :
placeByMidAndDid) {
// 获取当前具体数据
MaterialAndPlace placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialByMidAndPid(place.getId(), m.getId());
// 获取当前是否存在拆单处理记录
// 获取当前物料对应的所有拆单数目
List<SplitInfo> splitInfoByMid = splitUnitMapper.findSplitInfoByMid(inventory.getMid());
for (SplitInfo splitInfo : splitInfoByMid
) {
// 获取当前拆单单位的总数
double saveQuantity = splitUnitService.findAllInventoryForSplitInfo(-1, placeAndMaterialByMidAndPid, splitInfo.getId(), 0, true);
if (splitInventoryForUnit.containsKey(splitInfo.getNewUnit())) {
// 如果当前存在该拆单类型的记录
// 更新当前类型数据
splitInventoryForUnit.put(splitInfo.getNewUnit(), splitInventoryForUnit.get(splitInfo.getNewUnit()) + saveQuantity);
} else {
// 如果不存在,则新增
splitInventoryForUnit.put(splitInfo.getNewUnit(), saveQuantity);
}
if (inventory.getPrice() == null) {
inventory.setPrice(0.0);
}
int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1);
BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / scale);
double split_price = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
amounts = ObjectFormatUtil.sum(amounts, split_price * saveQuantity);
unit = splitInfo.getNewUnit();
}
}
// 设置新总额
m.setAmounts(m.getAmounts() + amounts);
// 设置当前各拆单信息对应的库存
@ -976,7 +1015,7 @@ public class MaterialServiceImpl implements MaterialService {
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
}
return pack(materialByDepository);
return pack(materialByDepository, null);
}
@Override
@ -1074,8 +1113,7 @@ public class MaterialServiceImpl implements MaterialService {
}
}
else {
} else {
// 如果要导入的不是默认库位
Map<String, Object> param = new HashMap<>();
param.put("depositoryId", material.getDepositoryId());
@ -1119,8 +1157,7 @@ public class MaterialServiceImpl implements MaterialService {
}
}
return materialMapper.updateInventory(material);
}
else {
} else {
// 用于标志是新插入的物料
map.put("isNew", true);
Double quantity = ObjectFormatUtil.toDouble(map.get("quantity"));
@ -1573,7 +1610,7 @@ public class MaterialServiceImpl implements MaterialService {
// 新增对应关系
Map<String, Object> insertAfter = new HashMap<>();
insertAfter.put("mid", id);
insertAfter.put("quantity", quantity);
insertAfter.put("quantity", (int)(quantity * 100));
insertAfter.put("pid", toPlaceId);
// 添加对应关系
placeService.addMaterialOnPlace(insertAfter);

11
src/main/resources/templates/pages/depository/table-stock.html

@ -97,6 +97,11 @@
</button>
</script>
<script id="changePlace" type="text/html" >
<span style="display: none">{{d.placeKingdeeCode}}</span>
</script>
<script id="materialCode" type="text/html">
<a id="{{d.id}}" onclick="showDetail(this)">{{d.code}}</a>
</script>
@ -206,7 +211,8 @@
{field: 'quantity', width: 200, title: '数量'},
{field: 'depositoryName', width: 200, title: '仓库名称'},
{field: 'depositoryCode', width: 200, title: '仓库编码'},
{title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
// {title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: "placeKingdeeCode", title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: 'warningCount', width: 200, title: '待过期数量', sort: true},
{field: 'price', title: '单价', width: 200, sort: true},
{field: 'amounts', title: '总金额', width: 200, sort: true},
@ -249,11 +255,12 @@
{field: 'brand', width: 200, title: '品牌'},
{field: 'version', width: 200, title: '规格型号'},
{field: 'typeName', width: 200, title: '物料类型'},
{title: '计量单位', width: 200, templet: '#changeUnit', align: "center"},
{field: "unit", title: '计量单位', width: 200, templet: '#changeUnit', align: "center"},
{field: 'quantity', width: 200, title: '数量'},
{field: 'depositoryName', width: 200, title: '仓库名称'},
{field: 'depositoryCode', width: 200, title: '仓库编码'},
{title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: "placeKingdeeCode", title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: 'warningCount', width: 200, title: '待过期数量', sort: true},
{field: 'texture', width: 200, title: '材质',},
{field: 'iremark', width: 200, title: '备注',},

11
target/classes/templates/pages/depository/table-stock.html

@ -97,6 +97,11 @@
</button>
</script>
<script id="changePlace" type="text/html" >
<span style="display: none">{{d.placeKingdeeCode}}</span>
</script>
<script id="materialCode" type="text/html">
<a id="{{d.id}}" onclick="showDetail(this)">{{d.code}}</a>
</script>
@ -206,7 +211,8 @@
{field: 'quantity', width: 200, title: '数量'},
{field: 'depositoryName', width: 200, title: '仓库名称'},
{field: 'depositoryCode', width: 200, title: '仓库编码'},
{title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
// {title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: "placeKingdeeCode", title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: 'warningCount', width: 200, title: '待过期数量', sort: true},
{field: 'price', title: '单价', width: 200, sort: true},
{field: 'amounts', title: '总金额', width: 200, sort: true},
@ -249,11 +255,12 @@
{field: 'brand', width: 200, title: '品牌'},
{field: 'version', width: 200, title: '规格型号'},
{field: 'typeName', width: 200, title: '物料类型'},
{title: '计量单位', width: 200, templet: '#changeUnit', align: "center"},
{field: "unit", title: '计量单位', width: 200, templet: '#changeUnit', align: "center"},
{field: 'quantity', width: 200, title: '数量'},
{field: 'depositoryName', width: 200, title: '仓库名称'},
{field: 'depositoryCode', width: 200, title: '仓库编码'},
{title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: "placeKingdeeCode", title: '所处库位', width: 200, templet: '#changePlace', align: "center"},
{field: 'warningCount', width: 200, title: '待过期数量', sort: true},
{field: 'texture', width: 200, title: '材质',},
{field: 'iremark', width: 200, title: '备注',},

Loading…
Cancel
Save