Browse Source

修改一般用户组合出库功能

lwx_dev
erdanergou 3 years ago
parent
commit
bc535477ef
  1. 125
      src/main/java/com/dreamchaser/depository_manage/controller/GroupController.java
  2. 7
      src/main/java/com/dreamchaser/depository_manage/entity/GroupInfo.java
  3. 2
      src/main/java/com/dreamchaser/depository_manage/service/MaterialService.java
  4. 41
      src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java
  5. 19
      src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java
  6. 78
      src/main/resources/templates/pages/application/application-out.html

125
src/main/java/com/dreamchaser/depository_manage/controller/GroupController.java

@ -95,24 +95,8 @@ public class GroupController {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
// 获取当前部门仓库
List<Depository> depositoryByAdminorg = depositoryService.findDepositoryByAdminorg(userToken.getMaindeparment().toString());
// 查询当前用户管理的仓库
List<RoleAndDepository> depositoryAndRole = roleService.findDepositoryAndRole(userToken.getId());
depositoryAndRole.addAll(roleService.findDepositoryAndRole(userToken.getPosition()));
List<Integer> depositoryIdList = new ArrayList<>();
for (Depository depository : depositoryByAdminorg
) {
depositoryIdList.add(depository.getId());
}
for (RoleAndDepository rad : depositoryAndRole
) {
if (!depositoryIdList.contains(rad.getDepositoryId())) {
depositoryIdList.add(rad.getDepositoryId());
}
}
List<Integer> depositoryIdList = roleService.findDepositoryIdForUserHas(userToken);
String code = map.get("code").toString();
@ -128,17 +112,26 @@ public class GroupController {
// 用于标识当前组合是否可以正常出库
boolean flag = true;
// 定义符合要求的仓库id
List<Integer> satisfyDepositoryIdList = new ArrayList<>();
for (GroupInfo groupInfo : groupByGid) {
// 获取详细信息
Integer infoQuantity = groupInfo.getQuantity();
// 获取该物料的库存
List<Double> inventoryByMidAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList);
Map<Integer, Double> inventoryByGroupInfoAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList);
// 用于标志当前物料库存是否符合要求
boolean flagForQuantity = false;
for (Double quantity : inventoryByMidAndDepository) {
// 获取key 的迭代
for (Integer depositoryId : inventoryByGroupInfoAndDepository.keySet()) {
Double quantity = inventoryByGroupInfoAndDepository.get(depositoryId);
// 如果库存符合要求
if (quantity >= groupInfo.getQuantity()) {
if (quantity >= infoQuantity) {
flagForQuantity = true;
if (!satisfyDepositoryIdList.contains(depositoryId)) {
satisfyDepositoryIdList.add(depositoryId);
}
}
}
if (!flagForQuantity) {
@ -146,6 +139,9 @@ public class GroupController {
flag = false;
errMsg.append(" ").append(groupInfo.getMname()).append(" ");
break;
} else {
List<Depository> depositoryByIds = depositoryService.findDepositoryByIds(satisfyDepositoryIdList);
groupInfo.setSatisfyDepositoryList(depositoryByIds);
}
}
@ -208,7 +204,12 @@ public class GroupController {
* @return
*/
@PostMapping("/findGroupByGname")
public RestResponse findGroupByGname(@RequestBody Map<String, Object> map) {
public RestResponse findGroupByGname(@RequestBody Map<String, Object> map, HttpServletRequest request) {
String token = request.getHeader("user-token");
if (token == null) {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
if (map.containsKey("gname")) {
List<Group> groupOnlyByCondition = groupService.findGroupOnlyByCondition(map);
int size = groupOnlyByCondition.size();
@ -220,6 +221,13 @@ public class GroupController {
// 如果刚好只有一个
// 获取当前组合的所有物料数据
List<GroupInfo> groupByGid = groupService.findGroupByCondition(map);
List<Integer> depositoryIdForUserHas = roleService.findDepositoryIdForUserHas(userToken);
List<Depository> depositoryByIds = depositoryService.findDepositoryByIds(depositoryIdForUserHas);
if (groupByGid != null && groupByGid.size() > 0) {
groupByGid.get(0).setSatisfyDepositoryList(depositoryByIds);
}else{
groupByGid = new ArrayList<>();
}
return new RestResponse(groupByGid, groupByGid.size(), 200);
} else {
@ -373,24 +381,10 @@ public class GroupController {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
// 获取当前部门仓库
List<Depository> depositoryByAdminorg = depositoryService.findDepositoryByAdminorg(userToken.getMaindeparment().toString());
// 查询当前用户管理的仓库
List<RoleAndDepository> depositoryAndRole = roleService.findDepositoryAndRole(userToken.getId());
depositoryAndRole.addAll(roleService.findDepositoryAndRole(userToken.getPosition()));
List<Integer> depositoryIdList = new ArrayList<>();
for (Depository depository : depositoryByAdminorg
) {
depositoryIdList.add(depository.getId());
}
for (RoleAndDepository rad : depositoryAndRole
) {
if (!depositoryIdList.contains(rad.getDepositoryId())) {
depositoryIdList.add(rad.getDepositoryId());
}
}
depositoryIdList = roleService.findDepositoryIdForUserHas(userToken);
// 获取当前组合的所有物料数据
List<GroupInfo> groupByGid = groupService.findGroupByCondition(map);
@ -403,29 +397,42 @@ public class GroupController {
boolean flag = true;
if (!"in".equals(type)) {
// 定义符合要求的仓库id
List<Integer> satisfyDepositoryIdList = new ArrayList<>();
for (GroupInfo groupInfo : groupByGid) {
// 获取详细信息
// 获取该物料的库存
List<Double> inventoryByMidAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList);
Integer infoQuantity = groupInfo.getQuantity();
// 用于标志当前物料库存是否符合要求
boolean flagForQuantity = false;
for (Double quantity : inventoryByMidAndDepository) {
// 如果库存符合要求
if (quantity >= groupInfo.getQuantity()) {
// 获取该物料在各仓库的库存
Map<Integer, Double> inventoryByMidAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList);
// 获取key的迭代器
for (Integer depositoryId : inventoryByMidAndDepository.keySet()) {
Double value = inventoryByMidAndDepository.get(depositoryId);
if (value >= infoQuantity) {
flagForQuantity = true;
satisfyDepositoryIdList.add(depositoryId);
}
}
if (!flagForQuantity) {
// 如果当前不符合
flag = false;
errMsg.append(" ").append(groupInfo.getMname()).append(" ");
break;
} else {
List<Depository> depositoryByIds = depositoryService.findDepositoryByIds(satisfyDepositoryIdList);
groupInfo.setSatisfyDepositoryList(depositoryByIds);
}
}
}
if (flag) {
return new RestResponse(groupByGid);
} else {
return new RestResponse(null, 666, new StatusInfo("不能出库", "当前组合中的" + errMsg + "在仓库中库存不足"));
@ -580,6 +587,7 @@ public class GroupController {
/**
* 入库审核
*
* @param map
* @param request
* @return
@ -613,6 +621,7 @@ public class GroupController {
/**
* 用于获取当前物料在组合中的详细信息
*
* @param map
* @return
*/
@ -777,28 +786,21 @@ public class GroupController {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
// 获取当前部门所拥有的仓库
List<Depository> depositoryByAdminorg = depositoryService.findDepositoryByAdminorg(userToken.getMaindeparment().toString());
// 查询当前用户管理的仓库
List<RoleAndDepository> depositoryAndRole = roleService.findDepositoryAndRole(userToken.getId());
depositoryAndRole.addAll(roleService.findDepositoryAndRole(userToken.getPosition()));
List<Integer> depositoryIdList = new ArrayList<>();
for (Depository depository : depositoryByAdminorg
) {
depositoryIdList.add(depository.getId());
}
for (RoleAndDepository rad : depositoryAndRole
) {
if (!depositoryIdList.contains(rad.getDepositoryId())) {
depositoryIdList.add(rad.getDepositoryId());
}
}
// 获取组合id
Integer gid = ObjectFormatUtil.toInteger(map.get("gid"));
// 获取组合数量
Integer quantity = ObjectFormatUtil.toInteger(map.get("quantity"));
List<Integer> depositoryIdList = new ArrayList<>();
if (map.containsKey("depositoryId")) {
// 获取选择的仓库
Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId"));
depositoryIdList.add(depositoryId);
} else {
depositoryIdList = roleService.findDepositoryIdForUserHas(userToken);
}
Map<String, String> trueForGroup = isTrueForGroup(gid, quantity, depositoryIdList);
Boolean flag = Boolean.valueOf(trueForGroup.get("flag"));
@ -957,7 +959,6 @@ public class GroupController {
}
Map<String, String> isTrueForGroup(Integer gid, Integer quantity, List<Integer> depositoryIdList) {
List<GroupInfo> groupInfoByGid = groupService.findGroupInfoByGid(gid);
boolean flag = true;
@ -971,9 +972,11 @@ public class GroupController {
boolean flagForInventory = false;
// 获取该物料在各仓库的库存
List<Double> inventoryByMidAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList);
for (Double integer : inventoryByMidAndDepository) {
if (integer >= totalQuantity) {
Map<Integer, Double> inventoryByMidAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList);
// 获取key的迭代器
for (Integer depositoryId : inventoryByMidAndDepository.keySet()) {
Double value = inventoryByMidAndDepository.get(depositoryId);
if (value >= totalQuantity) {
flagForInventory = true;
break;
}

7
src/main/java/com/dreamchaser/depository_manage/entity/GroupInfo.java

@ -2,6 +2,8 @@ package com.dreamchaser.depository_manage.entity;
import lombok.Data;
import java.util.List;
/**
* 用于组合信息的封装
*/
@ -104,4 +106,9 @@ public class GroupInfo {
* 用于展示的计量单位
*/
private String showUnit;
/**
* 用于展示符合库存数量的仓库id
*/
private List<Depository> satisfyDepositoryList;
}

2
src/main/java/com/dreamchaser/depository_manage/service/MaterialService.java

@ -157,7 +157,7 @@ public interface MaterialService {
* @param depositoryList 待查询的仓库
* @return
*/
List<Double> findInventoryByGroupInfoAndDepository(GroupInfo groupInfo, List<Integer> depositoryList);
Map<Integer,Double> findInventoryByGroupInfoAndDepository(GroupInfo groupInfo, List<Integer> depositoryList);
/**
* 根据物料id获取其在对应仓库中的库存数

41
src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java

@ -586,6 +586,7 @@ public class GroupServiceImpl implements GroupService {
paramForOut.put("departmenthead", map.get("departmenthead"));
paramForOut.put("applicantId", userToken.getId());
paramForOut.put("createUid", userToken.getId());
// 获取当前提交数
List<String> params = (List<String>) map.get("params");
@ -603,6 +604,14 @@ public class GroupServiceImpl implements GroupService {
// 获取要出库组合的具体信息
List<GroupInfo> groupInfoByGid = groupMapper.findGroupInfoByGid(gid);
// 用于统计出库物料总数
double quantityForTotal = 0;
// 用于统计出库物料金额总数
double priceForTotal = 0;
List<Integer> depositoryIdList = new ArrayList<>();
// 获取当前部门所拥有的仓库
List<Depository> depositoryByAdminorg = depositoryMapper.findDepositoryByAdminorg(userToken.getMaindeparment().toString());
@ -610,7 +619,6 @@ public class GroupServiceImpl implements GroupService {
List<RoleAndDepository> depositoryAndRole = roleMapper.findDepositoryAndRole(userToken.getId());
depositoryAndRole.addAll(roleMapper.findDepositoryAndRole(userToken.getPosition()));
List<Integer> depositoryIdList = new ArrayList<>();
for (Depository depository : depositoryByAdminorg
) {
depositoryIdList.add(depository.getId());
@ -621,11 +629,27 @@ public class GroupServiceImpl implements GroupService {
depositoryIdList.add(rad.getDepositoryId());
}
}
// 用于统计出库物料总数
double quantityForTotal = 0;
// 用于统计出库物料金额总数
double priceForTotal = 0;
// 定义是否选择的仓库(默认没有选择)
boolean flagForSelectDepository = false;
Object depositoryIdForSelect = map.get("depositoryId");
if (depositoryIdForSelect == null || "".equals(depositoryIdForSelect.toString())) {
paramForOut.put("flagForOpenDepository", 1);
map.remove("depositoryId");
} else {
paramForOut.put("flagForOpenDepository", 2);
paramForOut.put("depositoryId", depositoryIdForSelect);
if (depositoryIdList.contains(ObjectFormatUtil.toInteger(depositoryIdForSelect))) {
paramForOut.put("flagForOpenDepository", 1);
flagForSelectDepository = true;
}else{
depositoryIdList = new ArrayList<>();
depositoryIdList.add(ObjectFormatUtil.toInteger(depositoryIdForSelect));
}
}
// 循环遍历当前部门所拥有的仓库
for (Integer depositoryId :
@ -646,7 +670,9 @@ public class GroupServiceImpl implements GroupService {
if (inventory.size() > 0) {
quantityForTotal += quantityForGroup * groupInfo.getQuantity();
priceForTotal += inventory.get(0).getPrice() * 100 * quantityForGroup;
if (!flagForSelectDepository) {
paramForOut.put("depositoryId", depositoryId);
}
break;
}
} else {
@ -663,12 +689,16 @@ public class GroupServiceImpl implements GroupService {
if (inventory.size() > 0) {
quantityForTotal += quantityForGroup * groupInfo.getQuantity();
priceForTotal += inventory.get(0).getPrice() * 100 / scale * quantityForGroup;
if (!flagForSelectDepository) {
paramForOut.put("depositoryId", depositoryId);
}
break;
}
}
}
}
if (map.containsKey("flagForAgency")) {
// 如果开启了代领
paramForOut.put("applicantId", map.get("agencyUid"));
@ -676,7 +706,6 @@ public class GroupServiceImpl implements GroupService {
} else {
paramForOut.put("flagForAgency", 2);
}
paramForOut.put("flagForOpenDepository",1);
paramForOut.put("quantity", quantityForTotal * 100);
paramForOut.put("price", priceForTotal);
paramForOut.put("applicantTime", System.currentTimeMillis());

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

@ -507,9 +507,11 @@ public class MaterialServiceImpl implements MaterialService {
* @return
*/
@Override
public List<Double> findInventoryByGroupInfoAndDepository(GroupInfo groupInfo, List<Integer> depositoryList) {
public Map<Integer, Double> findInventoryByGroupInfoAndDepository(GroupInfo groupInfo, List<Integer> depositoryList) {
// 用于存储各仓库的库存
List<Double> result = new ArrayList<>();
Map<Integer, Double> resultMap = new HashMap<>();
// 获取当前物料在组合中的单位
String unit = groupInfo.getUnit();
@ -521,10 +523,11 @@ public class MaterialServiceImpl implements MaterialService {
for (Integer depositoryId : depositoryList) {
map.put("did", depositoryId);
Inventory inventory = materialMapper.findInventoryByMidAndDid(map);
if (inventory != null) {
result.add((double) inventory.getQuantity() / 100);
resultMap.put(depositoryId, (inventory.getQuantity() / 100.0));
} else {
result.add(0.0);
resultMap.put(depositoryId, 0.0);
}
}
} else {
@ -532,8 +535,6 @@ public class MaterialServiceImpl implements MaterialService {
map.put("newUnit", unit);
// 获取当前拆单单位
SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(map);
// 获取当前拆单单位与基础单位的进制
int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1);
// 用户获取对应拆单库存记录
Map<String, Object> paramForSplitInventory = new HashMap<>();
@ -550,14 +551,12 @@ public class MaterialServiceImpl implements MaterialService {
materialAndPlace.setId(materialAndPlaceForView.getId());
quantity += splitUnitService.findAllInventoryForSplitInfo(-1, materialAndPlace, splitInfo.getId(), 0, true);
}
result.add(quantity);
resultMap.put(depositoryId, quantity);
}
}
return result;
return resultMap;
}
/**

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

@ -298,6 +298,15 @@
required lay-verify="number" placeholder="请填写组合数量"/>
</div>
</div>
<div class="layui-form-item" id="depositoryIdForGroup"
th:style="'display:'+${display}">
<label class="layui-form-label">仓库:</label>
<div class="layui-input-block">
<select name="depositoryId" id="showDepositoryForGroup">
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">备注说明:</label>
<div class="layui-input-block">
@ -765,6 +774,15 @@
<input type="number" name=` + "quantity" + NewIdNumber + ` class="layui-input" id=` + "quantityForGroup" + NewIdNumber + `
required lay-verify="number" onblur="groupQuantityIsTrue(this)" placeholder="请填写组合数量"/>
</div>
</div>
<div class="layui-form-item" id=` + "depositoryIdForGroup" + NewIdNumber + `
style="display:` + depositoryDisplay + `">
<label class="layui-form-label">仓库:</label>
<div class="layui-input-block">
<select name=` + "depositoryId" + NewIdNumber + ` id=` + "showDepositoryForGroup" + NewIdNumber + `>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">备注说明:</label>
@ -1049,9 +1067,21 @@
// 赋值给gname
gnameItem.value = data[0].gname;
gidItem.value = data[0].gid;
let satisfyDepositoryList = data[0].satisfyDepositoryList;
if (depositoryDisplay !== "none") {
var idNumber = gidItem.name.split("gid")[1];
$("#showDepositoryForGroup" + idNumber).empty();
if (satisfyDepositoryList !== null) {
for (let i = 0; i < satisfyDepositoryList.length; i++) {
$("#showDepositoryForGroup" + idNumber).append(new Option(satisfyDepositoryList[i].dname, satisfyDepositoryList[i].id));
}
}
form.render();
}
for (let i = 0; i < data.length; i++) {
CoverpageForGroup(pid, data[i]);
}
element.init();
layer.close(loading2)
}
@ -1249,6 +1279,17 @@
}
// 赋值给gname
gcodeItem.value = data[0].gcode;
let satisfyDepositoryList = data[0].satisfyDepositoryList;
if (depositoryDisplay !== "none") {
var idNumber = gidItem.name.split("gid")[1];
$("#showDepositoryForGroup" + idNumber).empty();
if (satisfyDepositoryList !== null) {
for (let i = 0; i < satisfyDepositoryList.length; i++) {
$("#showDepositoryForGroup" + idNumber).append(new Option(satisfyDepositoryList[i].dname, satisfyDepositoryList[i].id));
}
}
form.render();
}
for (let i = 0; i < data.length; i++) {
CoverpageForGroup(pid, data[i]);
}
@ -1339,6 +1380,17 @@
// 赋值给gname
gidItem.value = data[0].gid;
gcodeItem.value = data[0].gcode;
let satisfyDepositoryList = data[0].satisfyDepositoryList;
if (depositoryDisplay !== "none") {
var idNumber = gidItem.name.split("gid")[1];
$("#showDepositoryForGroup" + idNumber).empty();
if (satisfyDepositoryList !== null) {
for (let i = 0; i < satisfyDepositoryList.length; i++) {
$("#showDepositoryForGroup" + idNumber).append(new Option(satisfyDepositoryList[i].dname, satisfyDepositoryList[i].id));
}
}
form.render();
}
for (let i = 0; i < data.length; i++) {
CoverpageForGroup(pid, data[i]);
}
@ -1348,7 +1400,8 @@
}
}
})
} else {
}
else {
gcodeItem.value = '';
gidItem.value = '';
let childNodes = parent.childNodes;
@ -1357,7 +1410,6 @@
childNodes[i].remove()
}
}
layer.close(loading2);
}
};
@ -1727,6 +1779,9 @@
var req = {};
req.gid = gid;
req.quantity = val;
if (depositoryDisplay !== "none") {
req.depositoryId = $("#showDepositoryForGroup" + id).val();
}
let loading2 = layer.open({type: 3, shade: [0.25, '#000'], icon: 2, speed: 0});
$.ajax({
url: "/group/groupQuantityIsTrue",
@ -1763,18 +1818,24 @@
let unit = "";
let mcode = "";
let depositoryId = "-1";
// 用于标志是否为物料出库(默认为物料)
let flag = true;
if (id.indexOf('unit') !== -1) {
unit = data.value;
} else {
// 获取当前选中的仓库id
} else if (!(id.indexOf('ForGroup'))) {
// 获取当前选中的仓库id是在物料出库下
depositoryId = data.value;
idNum = id.split('showDepository')[1];
unit = $("#unit" + idNum).val();
} else if (id.indexOf("ForGroup")) {
depositoryId = data.value;
idNum = id.split('showDepositoryForGroup')[1];
flag = false;
}
if (flag) {
mcode = $("#code" + idNum).val();
if (mcode === "" || mcode === undefined || mcode === null) {
layer.msg("请输入物料的正确编码!", {icon: 0, time: 500}, function () {
layer.msg("请输入物料的正确编码!", {icon: 0, time: 1000}, function () {
$("#quantity" + idNum).val("")
});
} else {
@ -1811,6 +1872,11 @@
});
}
}
} else {
let elem = {};
elem.id = "quantityForGroup" + idNum;
groupQuantityIsTrue(elem)
}
});

Loading…
Cancel
Save