Browse Source

完成库存盘点功能

lwx_dev
erdanergou 3 years ago
parent
commit
ad2dab2d9f
  1. 234
      src/main/java/com/dreamchaser/depository_manage/service/impl/StockTakingServiceImpl.java
  2. 350
      src/main/resources/templates/pages/stockTaking/stockTakingComplete.html

234
src/main/java/com/dreamchaser/depository_manage/service/impl/StockTakingServiceImpl.java

@ -258,7 +258,7 @@ public class StockTakingServiceImpl implements StockTakingService {
Map<String, Object> result = new HashMap<>();
StringBuilder QyWxUid = new StringBuilder();
Integer state = ObjectFormatUtil.toInteger(map.get("state"));
Integer departmentManagerState = ObjectFormatUtil.toInteger(map.get("departmentManagerState"));
Object o = (map.get("mainId"));
Integer res = 0;
if (o == null) {
@ -281,7 +281,7 @@ public class StockTakingServiceImpl implements StockTakingService {
UserByPort userByPort = PageController.FindUserById(ObjectFormatUtil.toInteger(s), userToken);
QyWxUid.append(userByPort.getWorkwechat()).append(",");
}
if (Integer.compare(state, 1) == 0) {
if (Integer.compare(departmentManagerState, 1) == 0) {
// 如果审核通过
stockTakingResult = "通过";
@ -425,8 +425,9 @@ public class StockTakingServiceImpl implements StockTakingService {
}
}
else{
map.put("state",departmentManagerState);
}
// 更新结果
map.put("id", mainId);
String simpleTime = DateUtil.getSimpleTime(new Date());
@ -434,7 +435,7 @@ public class StockTakingServiceImpl implements StockTakingService {
map.put("departmentManager",userToken.getId());
stockTakingMapper.updateStockTaking(map);
// 更新
// 更新其他卡片
String finalStockTakingResult = stockTakingResult;
new Thread(new Runnable() {
@Override
@ -447,9 +448,218 @@ public class StockTakingServiceImpl implements StockTakingService {
}
}).start();
// 抄送盘点调账记录给盘点人员
new Thread(new Runnable() {
@Override
public void run() {
}
}).start();
return result;
}
/**
* 对盘点进行处理
* @param map
* @param userToken
* @return
*/
@Transactional
@Override
public Map<String, Object> completeStockTaking(Map<String, Object> map, UserByPort userToken) {
Map<String, Object> result = new HashMap<>();
StringBuilder QyWxUid = new StringBuilder();
Integer state = ObjectFormatUtil.toInteger(map.get("state"));
Object o = (map.get("mainId"));
Integer res = 0;
if (o == null) {
throw new MyException("缺少必要参数");
}
String stockTakingResult = "驳回";
// 获取主表编号
Integer mainId = ObjectFormatUtil.toInteger(o);
// 获取主单
StockTaking mainRecord = stockTakingMapper.selectStockTakingById(mainId);
// 获取负责人
String departmentManager = mainRecord.getDepartmentManager();
String[] split = departmentManager.split(",");
for (int i = 0; i < split.length; i++) {
String s = split[i];
if("".equals(s)){
continue;
}
UserByPort userByPort = PageController.FindUserById(ObjectFormatUtil.toInteger(s), userToken);
QyWxUid.append(userByPort.getWorkwechat()).append(",");
}
// 如果审核通过
stockTakingResult = "通过";
// 定义错误信息
Map<String, Object> errMsg = new HashMap<>();
// 定义出错单号
List<Long> errIds = new ArrayList<>();
// 定义出错信息
List<String> err = new ArrayList<>();
Integer placeId = mainRecord.getPlaceId();
// 获取库位详情
Place placeById = placeMapper.findPlaceById(placeId);
Integer depositoryId = mainRecord.getDepositoryId();
// 获取仓库详情
Depository depositoryById = depositoryMapper.findDepositoryById(depositoryId);
// 获取所有子单
List<StockTakingChildP> minRecordList = stockTakingMapper.selectStockTakingChildByMainId(mainId);
for (int i = 0; i < minRecordList.size(); i++) {
// 获取子单详情
StockTakingChildP minRecord = minRecordList.get(i);
// 获取盘点的物料详情
// 获取当前盘点结果
String takingResult = minRecord.getTakingResult();
if ("Inventory_normal".equals(takingResult)) {
// 如果盘点结果正常
continue;
}
// 获取盈亏数量
Integer inventory = minRecord.getInventory();
Material materialById = materialMapper.findMaterialById(minRecord.getMid());
Map<String, Object> paramForMaterialAndPlace = new HashMap<>();
paramForMaterialAndPlace.put("mid", materialById.getId());
paramForMaterialAndPlace.put("pid", placeById.getId());
// 获取物料与库位的对应关系
MaterialAndPlace placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(paramForMaterialAndPlace);
// 根据盘点结果重新计算物料的单价
// 数据库中的总额
Double amounts = (materialById.getAmounts() / 100);
Integer newInventory = minRecord.getNewInventory();
Double avgPrice = 0.0;
if (Integer.compare(newInventory, 0) != 0) {
// 如果新的库存不是0
// 新的均价
avgPrice = (amounts / newInventory) * 100;
}
materialById.setPrice(avgPrice);
// 获取当前库位上物料数量
Integer oldQuantity = materialById.getQuantity() - placeAndMaterialByMidAndPid.getQuantity();
materialById.setQuantity(oldQuantity + newInventory);
// 用于计算新的库位数量
Integer newNumberForPlace = 0;
// 用于计算新的库位与物料对应关系的数量
Integer newNumberForMatrialAndPlace = 0;
if ("Inventory_up".equals(takingResult)) {
// 如果盘盈
// 更新当前库位数量
newNumberForPlace = placeById.getQuantity() + inventory;
if (newNumberForPlace < placeById.getMax()) {
// 如果更新后的库位数量没有上溢
// 更新当前库位的数量
placeById.setQuantity(newNumberForPlace);
} else {
// 添加错误信息
errIds.add(minRecord.getId());
err.add("当前库位数量溢出,需要转移");
continue;
}
newNumberForMatrialAndPlace = placeAndMaterialByMidAndPid.getQuantity() + inventory;
// 更新物料与库位对应关系的数量
placeAndMaterialByMidAndPid.setQuantity(newNumberForMatrialAndPlace);
} else {
// 如果盘亏
newNumberForPlace = placeById.getQuantity() - inventory;
if (newNumberForPlace > placeById.getMin()) {
//如果更新后的库位数量没有下溢
// 更新当前库位数量
placeById.setQuantity(newNumberForPlace);
// 更新物料与库位对应关系的数量
newNumberForMatrialAndPlace = placeAndMaterialByMidAndPid.getQuantity() - inventory;
} else {
placeById.setQuantity(0);
newNumberForMatrialAndPlace = 0;
}
placeAndMaterialByMidAndPid.setQuantity(newNumberForMatrialAndPlace);
}
// 更新库位
placeMapper.UpdatePlace(placeById);
// 更新库位与物料的对应关系
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid);
// 更新当前物料信息
materialMapper.updateMaterial(materialById);
if (errIds.size() > 0) {
// 如果有出错的情况
errMsg.put("errIds", errIds);
errMsg.put("errMsg", err);
result.put("errMsg", errMsg);
}
}
// 更新结果
map.put("id", mainId);
String simpleTime = DateUtil.getSimpleTime(new Date());
map.put("completeTime", DateUtil.DateTimeToTimeStamp(simpleTime));
map.put("departmentManager",userToken.getId());
stockTakingMapper.updateStockTaking(map);
// 抄送盘点记录给负责人
new Thread(new Runnable() {
@Override
public void run() {
}
}).start();
return result;
}
/**
* 用于进行盘点结果转移
* @param map
@ -682,16 +892,16 @@ public class StockTakingServiceImpl implements StockTakingService {
Map<String,Object> map = new HashMap<>();
// 获取主表编号
String o = templateCard.getEventKey().split("wms_pass_StockTakingId")[1];
String o = templateCard.getEventKey().split("StockTakingId")[1];
Integer mainId = ObjectFormatUtil.toInteger(o);
// 获取主单
StockTaking mainRecord = stockTakingMapper.selectStockTakingById(mainId);
Integer state = 2;
Integer departmentManagerState = 2;
if ("pass".equals(clickKey)) {
// 如果审核通过
state = 1;
departmentManagerState = 1;
// 定义错误信息
Map<String, Object> errMsg = new HashMap<>();
// 定义出错单号
@ -832,10 +1042,13 @@ public class StockTakingServiceImpl implements StockTakingService {
}
}
else{
map.put("state",departmentManagerState);
}
// 更新结果
map.put("id", mainId);
map.put("state",state);
map.put("departmentManagerState",departmentManagerState);
String simpleTime = DateUtil.getSimpleTime(new Date());
map.put("completeTime", DateUtil.DateTimeToTimeStamp(simpleTime));
map.put("departmentManager",userByPort.getId());
@ -844,6 +1057,9 @@ public class StockTakingServiceImpl implements StockTakingService {
}
public String createTakingCode(String depositoryName) {
String key = "wms_stockTakingNumber";
RLock lock = redissonClient.getLock(key);

350
src/main/resources/templates/pages/stockTaking/stockTakingComplete.html

@ -0,0 +1,350 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>仓库盘点</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="/static/css/public.css" media="all">
<link rel="stylesheet" href="/static/js/lay-module/step-lay/step.css" media="all">
<style>
.inputdiv {
display: flex;
background-color: #fff;
height: 38px;
line-height: 38px;
border: 1px solid rgb(238, 238, 238);
}
.layui-form-label {
padding: 9px 0px;
text-align: left;
}
.layui-input-block {
margin-left: 80px;
}
.layui-form-select {
width: 100%;
border-style: none;
}
</style>
</head>
<body>
<div class="layuimini-container">
<div class="layuimini-main">
<div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto; ">
<div carousel-item style="overflow: inherit">
<div>
<fieldset class="table-search-fieldset">
<legend>库存盘点</legend>
<div class="layui-fluid">
<div class="layui-card">
<form class="layui-form"
style="margin: 0 auto;max-width: 700px;padding-top: 100px; padding-bottom: 200px"
lay-filter="form1" id="form1">
<div class="layui-card-body" id="takingHeader" style="padding-right: 0px">
<div class="layui-form-item">
<label class="layui-form-label">盘点位置:</label>
<div class="layui-input-block">
<input type="text" name="mainId" id="mainId" th:value="${mainRecord.getId()}" style="display:none;">
<input type="text" class="layui-input"
th:value="${mainRecord.getDepositoryName()}"
style="border-style: none"
id="openSonByDepository" readonly
lay-verify="required"/>
<input type="text" name="depositoryId" class="layui-input"
id="depositoryId" th:value="${mainRecord.getDepositoryId()}"
style="display: none" lay-verify="required"/>
<input type="text" name="placeId" class="layui-input" id="placeId"
th:value="${mainRecord.getPlaceId()}"
style="display: none" lay-verify="required"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">负责人:</label>
<div class="layui-input-block">
<input type="text" placeholder="请选择负责人" class="layui-input"
id="departmentManager" readonly
th:value="${mainRecord.getDepartmentManagerName()}"
lay-verify="required"/>
<input type="text" id="departmentManagerId" name="departmentManagerId"
th:value="${mainRecord.getDepartmentManager()}"
class="layui-input" style="display: none" lay-verify="required"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">发起人:</label>
<div class="layui-input-block">
<input type="text" placeholder="请选择负责人" class="layui-input"
id="originatorName" readonly
th:value="${mainRecord.getOriginatorName()}"
lay-verify="required"/>
<input type="text" id="originator" name="departmentManagerId"
th:value="${mainRecord.getOriginator()}"
class="layui-input" style="display: none" lay-verify="required"/>
</div>
</div>
</div>
<fieldset class="table-search-fieldset">
<legend>盘点明细</legend>
<div class="layui-card-body" id="InventoryDetails" style="padding-right: 0px">
<hr>
<div class="layui-collapse" lay-accordion>
<div class="layui-colla-item"
th:each="recordMin,iterStar:${recordChild}">
<h2 class="layui-colla-title"
th:text="${recordMin.getMname()}"></h2>
<div class="layui-colla-content">
<div class="layui-form-item">
<label class="layui-form-label">物料编码:</label>
<div class="layui-input-block" style="margin: 0px;">
<div class="inputdiv">
<input th:attr="name='code' +${recordMin.getId()},id='code'+${recordMin.getId()}"
type="text" placeholder="请填写入物料编码"
th:value="${recordMin.getMcode()}"
class="layui-input" lay-verify="required"
style="border-style: none">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">条形编码:</label>
<div class="layui-input-block" style="margin: 0px;">
<div class="inputdiv">
<select
th:attr="id='barCode'+${recordMin.getId()},name='barCode'+${recordMin.getId()}"
style="border-style: none">
</select>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">物料类型:</label>
<div class="layui-input-block">
<input type="text" placeholder="请选择物料类型"
class="layui-input"
th:value="${recordMin.getTname()}"
th:attr="id='openSonByMateralType'+${recordMin.getId()}"
readonly
lay-verify="required"/>
<input type="text"
th:value="${recordMin.getMtId()}"
th:attr="id='materialTypeId'+${recordMin.getId()},name='typeId'+${recordMin.getId()}"
placeholder="请选择物料类型" class="layui-input"
style="display: none" lay-verify="required"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">材质:</label>
<div class="layui-input-block">
<input type="text" placeholder="请填写材质名称"
class="layui-input"
th:value="${recordMin.getMtexture()}"
th:attr="id='texture'+${recordMin.getId()},name='texture'+${recordMin.getId()}"
/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">规格型号:</label>
<div class="layui-input-block">
<input type="text" placeholder="请填写规格型号"
class="layui-input"
th:value="${recordMin.getMversion()}"
th:attr="id='version'+${recordMin.getId()},name='version'+${recordMin.getId()}"
/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">计量单位:</label>
<div class="layui-input-block">
<input type="text" placeholder="请填写计量单位"
class="layui-input"
th:value="${recordMin.getMunit()}"
th:attr="id='unit'+${recordMin.getId()},name='unit'+${recordMin.getId()}"
/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">库存数量:</label>
<div class="layui-input-block">
<input type="number" class="layui-input" readonly
th:value="${recordMin.getOldInventory()}"
th:attr="id='oldInventory'+${recordMin.getId()},name='oldInventory'+${recordMin.getId()}"
lay-verify="required"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">盘点数量:</label>
<div class="layui-input-block">
<input type="number" class="layui-input"
th:value="${recordMin.getNewInventory()}"
th:attr="id='newInventory'+${recordMin.getId()},name='newInventory'+${recordMin.getId()}"
lay-verify="required"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">盘点结果:</label>
<div class="layui-input-block">
<input type="text" class="layui-input" id="takingResult"
th:value="${recordMin.getTakingResultShow()}"
th:attr="id='takingResult'+${recordMin.getId()},name='takingResult'+${recordMin.getId()}"
lay-verify="required"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">盈亏数量:</label>
<div class="layui-input-block">
<input type="number" class="layui-input" readonly
th:value="${recordMin.getInventory()}"
th:attr="id='inventory'+${recordMin.getId()},name='inventory'+${recordMin.getId()}"
lay-verify="required"/>
</div>
</div>
</div>
</div>
</div>
</div>
</fieldset>
<div id="review">
<div class="layui-form" style="margin: 0 auto;max-width: 900px;padding-top: 40px;">
<div class="layui-form-item">
<label class="layui-form-label">审核备注:</label>
<div class="layui-input-block">
<textarea id="auditOpinion" name="auditOpinion" placeholder="请填写相关原因及申请原因" value="" class="layui-textarea"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="button" class="layui-btn" onclick="review(1)">
&emsp;审核通过&emsp;
</button>
<button type="button" class="layui-btn layui-btn-danger" onclick="review(2)">
&emsp;审核不通过&emsp;
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
function review(data){}
layui.use(['form','step','element'], function () {
var $ = layui.$,
step = layui.step,
element = layui.element,
form = layui.form;
var position=0,states={},number = 2;
states = [ {title: "待审核"}];
// 用于分步表单加载
step.render({
elem: '#stepForm',
filter: 'stepForm',
width: '100%', //设置容器宽度
stepWidth: '750px',
height: '1495px',
position: position,
number:number,
stepItems: states
});
// 用于获取审核结果与审核的单号
review=function (pass) {
let data = {};
data.mainId = $("#mainId").val();
data.auditOpinion = $("#auditOpinion").val();
data.departmentManagerState = pass;
$.ajax({
url:"/stockTaking/review",
type:'post',
dataType:'json',
contentType: "application/json;charset=utf-8",
data:JSON.stringify(data),
beforeSend:function () {
this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
},
success:function(d){
layer.close(this.layerIndex);
if(d.status >= 300){
var errMsg = d.data.errMsg;
// 获取出错的子订单
layer.confirm("当前盘点数量中有溢出情况,需要进行转移", {
btn:["确定"]
},function () { // 继续
layer.open({
type: 2,
title: '转移物料',
skin: 'layui-layer-rim',
maxmin: true,
shadeClose: true, //点击遮罩关闭层
area: ['70%', '70%'],
move: '.layui-layer-title',
fixed: false,
content: '/stockTakingTransfer?minIds='+errMsg.errIds,
end: function (res) {
if(res.status >= 300){
layer.msg("提交失败,联系开发人员解决", {
icon: 5,//成功的表情
time: 500 //1秒关闭(如果不配置,默认是3秒)
}, function(){
window.location = '/StockTakingView?id='+data.mainId;
});
}else{
layer.msg("提交成功", {
icon: 6,//成功的表情
time: 500 //1秒关闭(如果不配置,默认是3秒)
}, function(){
window.location = '/StockTakingView?id='+data.mainId;
});
}
}
});
});
}
else{
layer.msg("提交成功", {
icon: 6,//成功的表情
time: 500 //1秒关闭(如果不配置,默认是3秒)
}, function(){
window.location = '/StockTakingView?id='+data.mainId;
});
}
},
})
};
});
</script>
</body>
</html>
Loading…
Cancel
Save