|
|
@@ -0,0 +1,308 @@
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.jeesite.common.lang.DateUtils;
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.modules.mes.entity.MesMaterial;
|
|
|
+import com.jeesite.modules.mes.resp.CommonResp;
|
|
|
+import com.jeesite.modules.mes.service.MesMaterialService;
|
|
|
+import com.jeesite.modules.mes.util.U9cAuthUtil;
|
|
|
+import com.jeesite.modules.utils.DateLocalUtils;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import com.jeesite.common.config.Global;
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
+import com.jeesite.modules.mes.entity.MesMaterialRk;
|
|
|
+import com.jeesite.modules.mes.service.MesMaterialRkService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 采购入库单Controller
|
|
|
+ * @author sxl
|
|
|
+ * @version 2026-06-23
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesMaterialRk")
|
|
|
+public class MesMaterialRkController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesMaterialRkService mesMaterialRkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesMaterialService mesMaterialService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据
|
|
|
+ */
|
|
|
+ @ModelAttribute
|
|
|
+ public MesMaterialRk get(String id, boolean isNewRecord) {
|
|
|
+ return mesMaterialRkService.get(id, isNewRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialRk:view")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(MesMaterialRk mesMaterialRk, Model model) {
|
|
|
+ model.addAttribute("mesMaterialRk", mesMaterialRk);
|
|
|
+ return "modules/mes/mesMaterialRkList";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询列表数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialRk:view")
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
+ @ResponseBody
|
|
|
+ public Page<MesMaterialRk> listData(MesMaterialRk mesMaterialRk, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ mesMaterialRk.setPage(new Page<>(request, response));
|
|
|
+ Page<MesMaterialRk> page = mesMaterialRkService.findPage(mesMaterialRk);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看编辑表单
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialRk:view")
|
|
|
+ @RequestMapping(value = "form")
|
|
|
+ public String form(MesMaterialRk mesMaterialRk, Model model) {
|
|
|
+ model.addAttribute("mesMaterialRk", mesMaterialRk);
|
|
|
+ return "modules/mes/mesMaterialRkForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialRk:edit")
|
|
|
+ @PostMapping(value = "save")
|
|
|
+ @ResponseBody
|
|
|
+ public String save(@Validated MesMaterialRk mesMaterialRk) {
|
|
|
+ mesMaterialRkService.save(mesMaterialRk);
|
|
|
+ return renderResult(Global.TRUE, text("保存采购入库单成功!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 停用数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialRk:edit")
|
|
|
+ @RequestMapping(value = "disable")
|
|
|
+ @ResponseBody
|
|
|
+ public String disable(MesMaterialRk mesMaterialRk) {
|
|
|
+ mesMaterialRk.setStatus(MesMaterialRk.STATUS_DISABLE);
|
|
|
+ mesMaterialRkService.updateStatus(mesMaterialRk);
|
|
|
+ return renderResult(Global.TRUE, text("停用采购入库单成功"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启用数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialRk:edit")
|
|
|
+ @RequestMapping(value = "enable")
|
|
|
+ @ResponseBody
|
|
|
+ public String enable(MesMaterialRk mesMaterialRk) {
|
|
|
+ mesMaterialRk.setStatus(MesMaterialRk.STATUS_NORMAL);
|
|
|
+ mesMaterialRkService.updateStatus(mesMaterialRk);
|
|
|
+ return renderResult(Global.TRUE, text("启用采购入库单成功"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialRk:edit")
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
+ @ResponseBody
|
|
|
+ public String delete(MesMaterialRk mesMaterialRk) {
|
|
|
+ mesMaterialRkService.delete(mesMaterialRk);
|
|
|
+ return renderResult(Global.TRUE, text("删除采购入库单成功!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析来料编码
|
|
|
+ * 格式:ERP代码,采购订单号,采购订单行号,料号,生产日期,生产批次,批次数量
|
|
|
+ * 样例:S-00015,LJR-PO2606030001,10,D3503-000001,20260608,26060001,1000
|
|
|
+ */
|
|
|
+// @RequiresPermissions("mes:mesMaterialRk:api")
|
|
|
+ @RequestMapping(value = "jxCode")
|
|
|
+ @ResponseBody
|
|
|
+ public CommonResp jxCode(HttpServletRequest req) {
|
|
|
+ String materialCode = req.getParameter("materialCode");
|
|
|
+ CommonResp<Map<String, Object>> resp = new CommonResp<>();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(materialCode)) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("来料码不能为空!");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] parts = materialCode.split(",", -1);
|
|
|
+ if (parts.length != 7) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("二维码规则不正确!");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ String docTypeCode = parts[0].trim();
|
|
|
+ String srcDocNo = parts[1].trim();
|
|
|
+ String srcDocLineNoStr = parts[2].trim();
|
|
|
+ String erpSn = parts[3].trim();
|
|
|
+ String produceDateStr = parts[4].trim();
|
|
|
+ String lotCode = parts[5].trim();
|
|
|
+ String qtyStr = parts[6].trim();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(docTypeCode) || StringUtils.isBlank(srcDocNo) || StringUtils.isBlank(srcDocLineNoStr)
|
|
|
+ || StringUtils.isBlank(erpSn) || StringUtils.isBlank(produceDateStr) || StringUtils.isBlank(lotCode)
|
|
|
+ || StringUtils.isBlank(qtyStr)) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("二维码规则不正确!");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long srcDocLineNo;
|
|
|
+ Long pcQty;
|
|
|
+ try {
|
|
|
+ srcDocLineNo = Long.valueOf(srcDocLineNoStr);
|
|
|
+ pcQty = Long.valueOf(qtyStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("二维码规则不正确!");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ String produceDate;
|
|
|
+ try {
|
|
|
+ produceDate = DateLocalUtils.getCurrentDate2(produceDateStr);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("二维码规则不正确!");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+// MesMaterial mesMaterial = new MesMaterial();
|
|
|
+// mesMaterial.setErpSn(erpSn);
|
|
|
+// MesMaterial material = mesMaterialService.findInfo(mesMaterial);
|
|
|
+// if (material == null) {
|
|
|
+// resp.setResult(Global.FALSE);
|
|
|
+// resp.setMessage("物料不存在!");
|
|
|
+// return resp;
|
|
|
+// }
|
|
|
+
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
+// data.put("materialCode", materialCode); // 来料码
|
|
|
+// data.put("docTypeCode", docTypeCode); // ERP代码/单据类型编码
|
|
|
+ data.put("srcDocNo", srcDocNo); // 采购订单号
|
|
|
+ data.put("srcDocLineNo", srcDocLineNo); // 采购订单行号
|
|
|
+ data.put("docLineNo", srcDocLineNo); // 行号
|
|
|
+// data.put("erpSn", erpSn); // 料号/ERP编码
|
|
|
+ data.put("produceDate", produceDate); // 生产日期
|
|
|
+ data.put("lotCode", lotCode); // 生产批次/批号
|
|
|
+ data.put("pcQty", pcQty); // 批次数量
|
|
|
+
|
|
|
+ resp.setData(data);
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
+ resp.setMessage("解析成功");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步数据到 ERP
|
|
|
+ */
|
|
|
+// @RequiresPermissions("mes:mesMaterialRk:api")
|
|
|
+ @RequestMapping(value = "mesToErp")
|
|
|
+ @ResponseBody
|
|
|
+ public String mesToErp(MesMaterialRk mesMaterialRk) {
|
|
|
+ if (StringUtils.isNotBlank(mesMaterialRk.getId())) {
|
|
|
+ mesMaterialRk = mesMaterialRkService.get(mesMaterialRk);
|
|
|
+ }
|
|
|
+ if (mesMaterialRk == null) {
|
|
|
+ return renderResult(Global.FALSE, text("采购入库单不存在!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String requestJson = buildCreateRcvJson(mesMaterialRk);
|
|
|
+ JSONObject response = U9cAuthUtil.createRCV(requestJson);
|
|
|
+ if (response == null) {
|
|
|
+ return renderResult(Global.FALSE, text("同步ERP失败!"));
|
|
|
+ }
|
|
|
+ if (!Boolean.TRUE.equals(response.getBoolean("Success"))) {
|
|
|
+ String msg = response.getString("ResMsg");
|
|
|
+ return renderResult(Global.FALSE, text(StringUtils.isNotBlank(msg) ? msg : "同步ERP失败!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray dataList = response.getJSONArray("Data");
|
|
|
+ if (dataList == null || dataList.isEmpty()) {
|
|
|
+ return renderResult(Global.FALSE, text("同步ERP失败:返回数据为空!"));
|
|
|
+ }
|
|
|
+ JSONObject data = dataList.getJSONObject(0);
|
|
|
+ if (data == null || !Boolean.TRUE.equals(data.getBoolean("IsSucceed"))) {
|
|
|
+ String errorMsg = data != null ? data.getString("ErrorMsg") : null;
|
|
|
+ return renderResult(Global.FALSE, text(StringUtils.isNotBlank(errorMsg) ? errorMsg : "同步ERP失败!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String code = data.getString("Code");
|
|
|
+ String docId = data.getString("ID");
|
|
|
+ StringBuilder successMsg = new StringBuilder(text("同步ERP成功!"));
|
|
|
+ if (StringUtils.isNotBlank(code)) {
|
|
|
+ successMsg.append(" ").append(code);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(docId)) {
|
|
|
+ successMsg.append(" (").append(docId).append(")");
|
|
|
+ }
|
|
|
+ return renderResult(Global.TRUE, successMsg.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造 CreateRCV 接口请求 JSON
|
|
|
+ */
|
|
|
+ private String buildCreateRcvJson(MesMaterialRk mesMaterialRk) {
|
|
|
+ JSONObject root = new JSONObject(true);
|
|
|
+ root.put("OtherID", StringUtils.defaultIfBlank(mesMaterialRk.getOtherId(), ""));
|
|
|
+ root.put("DocTypeCode", StringUtils.defaultIfBlank(mesMaterialRk.getDocTypeCode(), ""));
|
|
|
+ root.put("BusinessDate", formatRkDate(mesMaterialRk.getBusineseDate()));
|
|
|
+ root.put("ConfirmDate", formatRkDate(mesMaterialRk.getConfirmDate()));
|
|
|
+
|
|
|
+ JSONObject line = new JSONObject(true);
|
|
|
+ line.put("OtherID", StringUtils.defaultIfBlank(mesMaterialRk.getOtherId(), ""));
|
|
|
+ line.put("DocLineNo", mesMaterialRk.getDocLineNo());
|
|
|
+ line.put("SrcDocNo", StringUtils.defaultIfBlank(mesMaterialRk.getSrcDocNo(), ""));
|
|
|
+ line.put("SrcDocLineNo", mesMaterialRk.getSrcDocLineNo());
|
|
|
+ line.put("LotCode", StringUtils.defaultIfBlank(mesMaterialRk.getLotCode(), ""));
|
|
|
+ line.put("Qty", mesMaterialRk.getQty());
|
|
|
+ line.put("RtnDeductQty", mesMaterialRk.getRtnDeductQty());
|
|
|
+ line.put("RtnFillQty", mesMaterialRk.getRtnFillQty());
|
|
|
+
|
|
|
+ JSONArray lineDtos = new JSONArray();
|
|
|
+ lineDtos.add(line);
|
|
|
+ root.put("LineDtos", lineDtos);
|
|
|
+
|
|
|
+ JSONArray requestArray = new JSONArray();
|
|
|
+ requestArray.add(root);
|
|
|
+ return requestArray.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String formatRkDate(Date date) {
|
|
|
+ if (date == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return DateUtils.formatDate(date, "yyyy-MM-dd");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|