Commit b1f781d44ef06f8e2f9e13f509ebfea077971235

Authored by 游杰
1 parent dbc05588

1.入库单有两条相同物料,那么合并库存

2.优化入库体验
src/main/java/com/huaheng/mobile/receipt/MobileBatchReceiptController.java
... ... @@ -507,7 +507,7 @@ public class MobileBatchReceiptController {
507 507 container.setWarehouseCode(ShiroUtils.getWarehouseCode());
508 508 LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(container);
509 509 container = containerService.getOne(lambdaQueryWrapper);
510   - if(container==null) {
  510 + if(container == null) {
511 511 return AjaxResult.error("容器不存在");
512 512 }
513 513 if (!StringUtils.isNotEmpty(container.getLocationCode())) {
... ... @@ -532,7 +532,7 @@ public class MobileBatchReceiptController {
532 532 }
533 533 //判断托盘是否已经存在任务
534 534 LambdaQueryWrapper<TaskHeader> headerQueryWrapper = Wrappers.lambdaQuery();
535   - headerQueryWrapper.ne(TaskHeader::getStatus, 100)
  535 + headerQueryWrapper.ne(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED.intValue())
536 536 .eq(TaskHeader::getContainerCode, containerCode);
537 537 Integer taskCount = taskHeaderService.count(headerQueryWrapper);
538 538 if (taskCount != null && taskCount.intValue() > 0) {
... ... @@ -543,7 +543,7 @@ public class MobileBatchReceiptController {
543 543 TaskHeader taskHeader = new TaskHeader();
544 544 taskHeader.setWarehouseCode(loc.getWarehouseCode());
545 545 taskHeader.setCompanyCode(companyCode);//货主
546   - if(type == 200) {
  546 + if(type == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT.intValue()) {
547 547 taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHELF);
548 548 taskHeader.setTaskType(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT);
549 549 } else {
... ...
src/main/java/com/huaheng/pc/task/taskHeader/service/TaskHeaderServiceImpl.java
... ... @@ -677,7 +677,7 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
677 677 if (task.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_SHELF) ) {
678 678 //入库任务
679 679 this.completeReceiptTask(task);
680   -// combineInventory(task);
  680 + combineInventory(task);
681 681 }
682 682 if (task.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_PICKING) &&
683 683 (task.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT) || task.getTaskType().equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT))) {
... ... @@ -719,7 +719,7 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
719 719 }
720 720 LambdaQueryWrapper<InventoryHeader> inventoryHeaderErapper = Wrappers.lambdaQuery();
721 721 inventoryHeaderErapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
722   - .eq(InventoryHeader::getLocationCode, task.getFromLocation())
  722 + .eq(InventoryHeader::getLocationCode, task.getToLocation())
723 723 .eq(InventoryHeader::getContainerCode, task.getContainerCode());
724 724 InventoryHeader header = inventoryHeaderService.getOne(inventoryHeaderErapper);
725 725  
... ... @@ -747,12 +747,12 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
747 747 //将未完成的任务数量更新到库存表
748 748 if (DataUtils.getInteger(map.get("status")) < QuantityConstant.TASK_STATUS_COMPLETED) {
749 749  
750   -
751 750 LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
752 751 inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
753   - .eq(InventoryDetail::getLocationCode, task.getFromLocation())
  752 + .eq(InventoryDetail::getLocationCode, task.getToLocation())
754 753 .eq(InventoryDetail::getMaterialCode, DataUtils.getString(map.get("materialCode")))
755   - .eq(InventoryDetail::getContainerCode, DataUtils.getString(map.get("containerCode")));
  754 + .eq(InventoryDetail::getContainerCode, DataUtils.getString(map.get("containerCode")))
  755 + .eq(InventoryDetail::getContainerCode, DataUtils.getString(map.get("batch")));
756 756 InventoryDetail detail = inventoryDetailService.getOne(inventory);
757 757 if (detail == null) {
758 758 //库存明细添加
... ... @@ -892,21 +892,41 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
892 892 return AjaxResult.success("完成入库任务");
893 893 }
894 894  
895   -// private void combineInventory(TaskHeader task) {
896   -// LambdaQueryWrapper<InventoryHeader> inventoryHeaderErapper = Wrappers.lambdaQuery();
897   -// inventoryHeaderErapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
898   -// .eq(InventoryHeader::getLocationCode, task.getFromLocation())
899   -// .eq(InventoryHeader::getContainerCode, task.getContainerCode());
900   -// InventoryHeader header = inventoryHeaderService.getOne(inventoryHeaderErapper);
901   -// if(header != null) {
902   -// LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
903   -// inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
904   -// .eq(InventoryDetail::getLocationCode, task.getFromLocation())
905   -// .eq(InventoryDetail::getMaterialCode, DataUtils.getString(map.get("materialCode")))
906   -// .eq(InventoryDetail::getContainerCode, DataUtils.getString(map.get("containerCode")));
907   -// List<InventoryDetail> detail = inventoryDetailService.list(inventory);
908   -// }
909   -// }
  895 + @Transactional(rollbackFor = Exception.class)
  896 + public void combineInventory(TaskHeader task) {
  897 + LambdaQueryWrapper<InventoryHeader> inventoryHeaderErapper = Wrappers.lambdaQuery();
  898 + inventoryHeaderErapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
  899 + .eq(InventoryHeader::getLocationCode, task.getToLocation())
  900 + .eq(InventoryHeader::getContainerCode, task.getContainerCode());
  901 + InventoryHeader header = inventoryHeaderService.getOne(inventoryHeaderErapper);
  902 + if(header != null) {
  903 + LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
  904 + inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
  905 + .eq(InventoryDetail::getLocationCode, task.getFromLocation())
  906 + .eq(InventoryDetail::getContainerCode, task.getContainerCode());
  907 + List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventory);
  908 + for(int i=0; i < inventoryDetailList.size() -1; i++) {
  909 + for(int j = inventoryDetailList.size() - 1; j > i; j--) {
  910 + if(inventoryDetailList.get(i).getMaterialCode().equals(inventoryDetailList.get(j).getMaterialCode())) {
  911 + BigDecimal totalQty = inventoryDetailList.get(i).getQty().add(inventoryDetailList.get(j).getQty());
  912 + inventoryDetailList.get(i).setQty(totalQty);
  913 + inventoryDetailList.remove(j);
  914 + LambdaQueryWrapper<InventoryDetail> wrapper = Wrappers.lambdaQuery();
  915 + wrapper.eq(InventoryDetail::getId, inventoryDetailList.get(i).getId());
  916 + inventoryDetailService.update(inventoryDetailList.get(i), wrapper);
  917 + }
  918 + }
  919 + }
  920 + BigDecimal totalQty = new BigDecimal(0);
  921 + for(InventoryDetail inventoryDetail : inventoryDetailList) {
  922 + totalQty = totalQty.add(inventoryDetail.getQty());
  923 + }
  924 + header.setTotalQty(totalQty);
  925 + LambdaQueryWrapper<InventoryHeader> wrapper = Wrappers.lambdaQuery();
  926 + wrapper.eq(InventoryHeader::getId, header.getId());
  927 + inventoryHeaderService.update(header, wrapper);
  928 + }
  929 + }
910 930  
911 931 /**
912 932 * 移动端创建入库任务
... ...
src/main/resources/templates/receipt/receiptDetail/add.html
... ... @@ -25,7 +25,7 @@
25 25 </div>
26 26 </div>
27 27 <div class="form-group">
28   - <label class="col-sm-3 control-label">数量:</label>
  28 + <label class="col-sm-3 control-label">数量:</label>
29 29 <div class="col-sm-8">
30 30 <input id="totalQty" name="totalQty" class="form-control" type="text">
31 31 </div>
... ... @@ -134,7 +134,7 @@
134 134 <!--</div>-->
135 135 <div class="form-group">
136 136 <div class="form-control-static col-sm-offset-9">
137   - <button type="submit" class="btn btn-primary" >提交</button>
  137 + <button type="submit" class="btn btn-primary" >提交</button>
138 138 <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
139 139 </div>
140 140 </div>
... ... @@ -160,13 +160,54 @@
160 160 }
161 161 },
162 162 submitHandler: function(form) {
163   - var tableValue = $("#form-receiptDetail-add").serialize();
164   - tableValue = formValueReplace(tableValue, "inventorySts", $("#inventorySts option:selected").val());
165   - tableValue = formValueReplace(tableValue, "qcCheck", $("#qcCheck option:selected").val());
166   - $.operate.save(prefix + "/add", tableValue);
  163 + $.ajax({
  164 + cache : true,
  165 + type : "POST",
  166 + url : prefix + "/add",
  167 + data : {
  168 + "receiptId": $("input[name='receiptId']").val(),
  169 + "receiptCode": $("input[name='receiptCode']").val(),
  170 + "companyId": $("input[name='companyId']").val(),
  171 + "companyCode": $("input[name='companyCode']").val(),
  172 + "sourceLine": $("input[name='sourceLine']").val(),
  173 + // "materialId": $("input[name='materialId']").val(),
  174 + "materialCode": $("input[name='materialCode']").val(),
  175 + "batch": $("input[name='batch']").val(),
  176 + "lot": $("input[name='lot']").val(),
  177 + "project": $("input[name='project']").val(),
  178 + "manufactureDate": $("input[name='manufactureDate']").val(),
  179 + "expirationDate": $("input[name='expirationDate']").val(),
  180 + "inventorySts": $("#inventorySts option:selected").val(),
  181 + "totalQty": $("input[name='totalQty']").val(),
  182 + "price": $("input[name='price']").val(),
  183 + // "userDef1": $("input[name='userDef1']").val(),
  184 + // "userDef2": $("input[name='userDef2']").val(),
  185 + // "userDef3": $("input[name='userDef3']").val()
  186 + },
  187 + async : false,
  188 + error : function(request) {
  189 + $.modal.alertError("请求失败!");
  190 + },
  191 + success : function(data) {
  192 + // $.operate.saveSuccess(data);
  193 + ajaxSuccess(data);
  194 + }
  195 + });
167 196 }
168 197 });
169 198  
  199 + function ajaxSuccess(result) {
  200 + if (result.code == web_status.SUCCESS) {
  201 + $.modal.msgSuccess(result.msg);
  202 + var index = parent.layer.getFrameIndex(window.name);
  203 + parent.layer.close(index);
  204 + window.parent.loadDetail();
  205 + } else {
  206 + $.modal.alertError(result.msg);
  207 + }
  208 + $.modal.closeLoading();
  209 + }
  210 +
170 211 $(function () {
171 212 layui.use('laydate', function() {
172 213 var laydate = layui.laydate;
... ...
src/main/resources/templates/receipt/receiptHeader/add.html
... ... @@ -8,7 +8,7 @@
8 8 <div class="form-group">
9 9 <label class="col-sm-3 control-label">入库类型:</label>
10 10 <div class="col-sm-8">
11   - <select id="receiptType" name="receiptType" class="form-control" th:with="receiptHeaderType=${@receiptTypeService.getType()}">
  11 + <select id="receiptType" name="receiptType" class="form-control" th:with="receiptHeaderType=${@receiptTypeService.getType()}">
12 12 <option th:each="dict : ${receiptHeaderType}" th:text="${dict['name']}" th:value="${dict['code']}"></option>
13 13 </select>
14 14 </div>
... ...