diff --git a/src/main/java/com/heai/modules/app/controller/StockOtherOutController.java b/src/main/java/com/heai/modules/app/controller/StockOtherOutController.java new file mode 100644 index 0000000..0e97280 --- /dev/null +++ b/src/main/java/com/heai/modules/app/controller/StockOtherOutController.java @@ -0,0 +1,32 @@ +package com.heai.modules.app.controller; + +import com.heai.common.annotation.RepeatSubmit; +import com.heai.common.utils.R; +import com.heai.modules.app.entity.StockOtherOutSaveParam; +import com.heai.modules.app.service.StockOtherOutService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * PDA 其他出库(独立于 PdaOrder)- rqrq + */ +@RestController +@RequestMapping("/pda/stockOtherOut") +public class StockOtherOutController { + + @Autowired + private StockOtherOutService stockOtherOutService; + + /** + * @Description 保存其他出库 - rqrq + */ + @PostMapping("/save") + @RepeatSubmit + public R save(@RequestBody StockOtherOutSaveParam param) { + stockOtherOutService.saveStockOtherOut(param); + return R.ok("保存成功!"); + } +} diff --git a/src/main/java/com/heai/modules/app/entity/StockOtherOutLineParam.java b/src/main/java/com/heai/modules/app/entity/StockOtherOutLineParam.java new file mode 100644 index 0000000..bdeebfd --- /dev/null +++ b/src/main/java/com/heai/modules/app/entity/StockOtherOutLineParam.java @@ -0,0 +1,70 @@ +package com.heai.modules.app.entity; + +import java.math.BigDecimal; + +/** + * PDA 其他出库明细 - rqrq + */ +public class StockOtherOutLineParam { + + private String site; + + private String warehouseId; + + private String partNo; + + private String batchNo; + + private String locationId; + + /** 出库数量 */ + private BigDecimal qtyOut; + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + public String getWarehouseId() { + return warehouseId; + } + + public void setWarehouseId(String warehouseId) { + this.warehouseId = warehouseId; + } + + public String getPartNo() { + return partNo; + } + + public void setPartNo(String partNo) { + this.partNo = partNo; + } + + public String getBatchNo() { + return batchNo; + } + + public void setBatchNo(String batchNo) { + this.batchNo = batchNo; + } + + public String getLocationId() { + return locationId; + } + + public void setLocationId(String locationId) { + this.locationId = locationId; + } + + public BigDecimal getQtyOut() { + return qtyOut; + } + + public void setQtyOut(BigDecimal qtyOut) { + this.qtyOut = qtyOut; + } +} diff --git a/src/main/java/com/heai/modules/app/entity/StockOtherOutSaveParam.java b/src/main/java/com/heai/modules/app/entity/StockOtherOutSaveParam.java new file mode 100644 index 0000000..569ecb0 --- /dev/null +++ b/src/main/java/com/heai/modules/app/entity/StockOtherOutSaveParam.java @@ -0,0 +1,39 @@ +package com.heai.modules.app.entity; + +import java.util.List; + +/** + * PDA 其他出库保存 - rqrq + */ +public class StockOtherOutSaveParam { + + private String userName; + + private String remark; + + private List lines; + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public List getLines() { + return lines; + } + + public void setLines(List lines) { + this.lines = lines; + } +} diff --git a/src/main/java/com/heai/modules/app/service/StockOtherOutService.java b/src/main/java/com/heai/modules/app/service/StockOtherOutService.java new file mode 100644 index 0000000..9fff3ec --- /dev/null +++ b/src/main/java/com/heai/modules/app/service/StockOtherOutService.java @@ -0,0 +1,15 @@ +package com.heai.modules.app.service; + +import com.heai.modules.app.entity.StockOtherOutSaveParam; + +/** + * PDA 其他出库(库存标签) - rqrq + */ +public interface StockOtherOutService { + + /** + * @Description 生成其他出库主档+明细(专用存储过程)- rqrq + * @param param 入参 + */ + void saveStockOtherOut(StockOtherOutSaveParam param); +} diff --git a/src/main/java/com/heai/modules/app/service/impl/StockOtherOutServiceImpl.java b/src/main/java/com/heai/modules/app/service/impl/StockOtherOutServiceImpl.java new file mode 100644 index 0000000..726a483 --- /dev/null +++ b/src/main/java/com/heai/modules/app/service/impl/StockOtherOutServiceImpl.java @@ -0,0 +1,152 @@ +package com.heai.modules.app.service.impl; + +import com.heai.common.utils.DateUtil; +import com.heai.modules.app.entity.StockOtherOutLineParam; +import com.heai.modules.app.entity.StockOtherOutSaveParam; +import com.heai.modules.app.service.StockOtherOutService; +import com.heai.modules.production.dao.FunctionMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @Description PDA 其他出库:Inventory_Create_TransHeader_other + Inventory_Create_TransDetail_Out_other - rqrq + */ +@Slf4j +@Service +public class StockOtherOutServiceImpl implements StockOtherOutService { + + private static final String TRANS_TYPE_OC = "OC"; + + /** 与现存发料出库明细过程参数顺序一致的空成本与订单引用 - rqrq */ + private static final String COST_GROUP_EMPTY = ""; + private static final String ORDER_REF_EMPTY = ""; + private static final String ALLOW_NEGATIVE_N = "N"; + + /** 主过程要求往来单位占位 - rqrq */ + private static final String PARTNER_ID_STAR = "*"; + + @Autowired + private FunctionMapper functionMapper; + + /** + * @Description 对齐 FunctionServiceImpl#saveSaveTrans,改用其他出库专用存储过程 - rqrq + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void saveStockOtherOut(StockOtherOutSaveParam param) { + if (param == null) { + throw new RuntimeException("参数不能为空"); + } + if (!StringUtils.hasText(param.getUserName())) { + throw new RuntimeException("用户不能为空"); + } + List lines = param.getLines(); + if (lines == null || lines.isEmpty()) { + throw new RuntimeException("没有出库明细"); + } + + StockOtherOutLineParam first = lines.get(0); + if (!StringUtils.hasText(first.getSite())) { + throw new RuntimeException("工厂不能为空"); + } + if (!StringUtils.hasText(first.getWarehouseId())) { + throw new RuntimeException("仓库不能为空"); + } + + final String site0 = trim(first.getSite()); + final String warehouse0 = trim(first.getWarehouseId()); + + for (int i = 0; i < lines.size(); i++) { + StockOtherOutLineParam row = lines.get(i); + if (!StringUtils.hasText(row.getPartNo())) { + throw new RuntimeException("第" + (i + 1) + "行物料编码不能为空"); + } + if (row.getQtyOut() == null || row.getQtyOut().doubleValue() <= 0) { + throw new RuntimeException("第" + (i + 1) + "行出库数量无效"); + } + if (!site0.equals(trim(row.getSite()))) { + throw new RuntimeException("明细工厂必须一致"); + } + if (!warehouse0.equals(trim(row.getWarehouseId()))) { + throw new RuntimeException("明细仓库必须与首张标签仓库一致"); + } + } + + Date transDate; + try { + transDate = DateUtil.getDate(DateUtil.getStringDate(new Date())); + } catch (ParseException e) { + throw new RuntimeException("业务日期解析失败"); + } + + String user = trim(param.getUserName()); + String remark = param.getRemark() != null ? param.getRemark() : ""; + + List headerParams = new ArrayList<>(); + headerParams.add(site0); + headerParams.add(warehouse0); + headerParams.add(TRANS_TYPE_OC); + headerParams.add(transDate); + headerParams.add(user); + headerParams.add(user); + headerParams.add(""); + headerParams.add(PARTNER_ID_STAR); + headerParams.add(remark); + headerParams.add(""); + headerParams.add(""); + + Map map = functionMapper.getProcedure("Inventory_Create_TransHeader_other", headerParams); + if (map == null) { + throw new RuntimeException("主档存储过程无返回"); + } + String resultCode = String.valueOf(map.get("result_code")).trim(); + String transNo = String.valueOf(map.get("result_msg")).trim(); + if (!"200".equals(resultCode)) { + throw new RuntimeException(transNo); + } + if (!StringUtils.hasText(transNo)) { + throw new RuntimeException("未生成出库单号"); + } + + for (int i = 0; i < lines.size(); i++) { + StockOtherOutLineParam row = lines.get(i); + List detailParams = new ArrayList<>(); + detailParams.add(site0); + detailParams.add(transNo); + detailParams.add(i + 1); + detailParams.add(trim(row.getPartNo())); + detailParams.add(row.getBatchNo() != null ? trim(row.getBatchNo()) : ""); + detailParams.add(row.getLocationId() != null ? trim(row.getLocationId()).toUpperCase() : ""); + detailParams.add(row.getQtyOut().doubleValue()); + detailParams.add(COST_GROUP_EMPTY); + detailParams.add(ORDER_REF_EMPTY); + detailParams.add(ORDER_REF_EMPTY); + detailParams.add(ORDER_REF_EMPTY); + detailParams.add(ALLOW_NEGATIVE_N); + + map = functionMapper.getProcedure("Inventory_Create_TransDetail_Out_other", detailParams); + if (map == null) { + throw new RuntimeException("明细存储过程无返回:" + row.getPartNo()); + } + String dCode = String.valueOf(map.get("result_code")).trim(); + if (!"200".equals(dCode)) { + throw new RuntimeException(String.valueOf(map.get("result_msg"))); + } + } + + log.info("其他出库完成 transNo={}, 行数={} - rqrq", transNo, lines.size()); + } + + private static String trim(String s) { + return s == null ? "" : s.trim(); + } +} diff --git a/src/main/resources/static/js/pdaOther/stockOtherOut.js b/src/main/resources/static/js/pdaOther/stockOtherOut.js index 39eee09..24c20ad 100644 --- a/src/main/resources/static/js/pdaOther/stockOtherOut.js +++ b/src/main/resources/static/js/pdaOther/stockOtherOut.js @@ -47,8 +47,9 @@ function changeTableList(){ function changeTable(){ var str = ''; + // rqrq:首张标签写入发料仓库展示,混仓在 getInventoryData 中拦截 if(tableList.length > 0){ - $("#wareHouse").val(tableList[0].warehouseId + "-" + tableList[0].wareHouseName); + $("#wareHouse").val(tableList[0].warehouseId); } for (let i = 0; i < tableList.length; i++) { str += '' + @@ -108,12 +109,10 @@ function queryPart(){ } function getInventoryData(){ - var wareHouse = $("#wareHouse").val(); - if(wareHouse != null && wareHouse != ""){ - if(tableList.length > 0 && tableList[0].warehouseId != partNoData.wareHouseId){ - layer.msg("仓库编码错误!"); - return false - } + // rqrq:首张确定仓库,后续标签仓库必须一致 + if (tableList.length > 0 && tableList[0].warehouseId !== partNoData.wareHouseId) { + layer.msg("仓库与首张标签不一致,不能混仓其他出库!当前应扫仓库:" + tableList[0].warehouseId); + return false; } var jsonData = { site : partNoData.site, @@ -230,9 +229,70 @@ function clearAll(){ changeTable(); } -//下级界面页面跳转 +/** + * rqrq:提交其他出库(Inventory_Create_TransHeader_other + 逐行 Out_other) + */ function saveData(){ - clearAll() + if (!tableList || tableList.length === 0) { + layer.msg("请先扫描并添加出库明细"); + return; + } + var payload = { + userName: userName, + remark: ($("#remark").val() || ""), + lines: tableList.map(function (r) { + return { + site: r.site, + warehouseId: r.warehouseId, + partNo: r.partNo, + batchNo: r.batchNo, + locationId: r.locationId, + qtyOut: parseFloat(r.qtyOut) + }; + }) + }; + if (payload.lines.some(function (x) { return isNaN(x.qtyOut) || x.qtyOut <= 0; })) { + layer.msg("存在无效数量"); + return; + } + var loadIdx = layer.load(1, { shade: [0.2, '#000'] }); + console.log(payload); + + $.ajax({ + url: "/pda/stockOtherOut/save", + contentType: "application/json", + type: "POST", + data: JSON.stringify(payload), + dataType: "JSON", + beforeSend: function (request) { + request.setRequestHeader("token", $.cookie("token")); + }, + success: function (data) { + layer.close(loadIdx); + if (data.code === 0) { + layer.msg(data.msg || "保存成功"); + clearAll(); + } else { + layer.msg(data.msg || "保存失败"); + } + }, + error: function (xhr) { + layer.close(loadIdx); + var msg = "请求失败"; + try { + var json = JSON.parse(xhr.responseText); + if (json && json.msg) { + msg = json.msg; + } + } catch (e) { } + layer.msg(msg); + if (xhr.status === 403) { + layer.alert(msg, function () { + window.location.href = "/login"; + }); + } + } + }); } //初始化下拉框 diff --git a/src/main/resources/templates/pdaOther/stockOtherOut.ftl b/src/main/resources/templates/pdaOther/stockOtherOut.ftl index c9d912a..25893e5 100644 --- a/src/main/resources/templates/pdaOther/stockOtherOut.ftl +++ b/src/main/resources/templates/pdaOther/stockOtherOut.ftl @@ -55,7 +55,6 @@ -