|
|
@@ -1,15 +1,18 @@
|
|
|
package com.jeesite.modules.mes.web;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
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.util.U9cAuthUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
@@ -17,7 +20,9 @@ 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.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import com.jeesite.common.config.Global;
|
|
|
@@ -29,7 +34,7 @@ import com.jeesite.modules.mes.service.MesProductReportService;
|
|
|
/**
|
|
|
* 完工报告Controller
|
|
|
* @author sxl
|
|
|
- * @version 2026-06-28
|
|
|
+ * @version 2026-07-03
|
|
|
*/
|
|
|
@Controller
|
|
|
@RequestMapping(value = "${adminPath}/mes/mesProductReport")
|
|
|
@@ -37,7 +42,7 @@ public class MesProductReportController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private MesProductReportService mesProductReportService;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 获取数据
|
|
|
*/
|
|
|
@@ -45,7 +50,7 @@ public class MesProductReportController extends BaseController {
|
|
|
public MesProductReport get(String id, boolean isNewRecord) {
|
|
|
return mesProductReportService.get(id, isNewRecord);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 查询列表
|
|
|
*/
|
|
|
@@ -55,7 +60,7 @@ public class MesProductReportController extends BaseController {
|
|
|
model.addAttribute("mesProductReport", mesProductReport);
|
|
|
return "modules/mes/mesProductReportList";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 查询列表数据
|
|
|
*/
|
|
|
@@ -88,7 +93,7 @@ public class MesProductReportController extends BaseController {
|
|
|
mesProductReportService.save(mesProductReport);
|
|
|
return renderResult(Global.TRUE, text("保存完工报告成功!"));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 删除数据
|
|
|
*/
|
|
|
@@ -99,22 +104,19 @@ public class MesProductReportController extends BaseController {
|
|
|
mesProductReportService.delete(mesProductReport);
|
|
|
return renderResult(Global.TRUE, text("删除完工报告成功!"));
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 同步数据到 ERP
|
|
|
*/
|
|
|
@RequiresPermissions("mes:mesProductReport:edit")
|
|
|
- @RequestMapping(value = "mesToErp")
|
|
|
+ @RequestMapping(value = "mesToErp", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
@ResponseBody
|
|
|
- public String mesToErp(MesProductReport mesProductReport) {
|
|
|
- if (StringUtils.isNotBlank(mesProductReport.getId())) {
|
|
|
- MesProductReport exist = mesProductReportService.get(mesProductReport);
|
|
|
- if (exist != null && !exist.getIsNewRecord()) {
|
|
|
- mesProductReport = exist;
|
|
|
- }
|
|
|
+ public String mesToErp(@RequestBody(required = false) String body, HttpServletRequest request) {
|
|
|
+ MesProductReport mesProductReport = resolveMesProductReport(body, request.getParameter("id"));
|
|
|
+ if (mesProductReport == null) {
|
|
|
+ return renderResult(Global.FALSE, text("参数错误!"));
|
|
|
}
|
|
|
- if (mesProductReport == null || mesProductReport.getIsNewRecord()) {
|
|
|
- return renderResult(Global.FALSE, text("完工报告不存在!"));
|
|
|
+ if (mesProductReport.getIsNewRecord()) {
|
|
|
+ mesProductReportService.save(mesProductReport);
|
|
|
}
|
|
|
|
|
|
String requestJson = buildCreateCompleteDocJson(mesProductReport);
|
|
|
@@ -123,26 +125,32 @@ public class MesProductReportController extends BaseController {
|
|
|
return renderResult(Global.FALSE, text("同步ERP失败!"));
|
|
|
}
|
|
|
if (!Boolean.TRUE.equals(response.getBoolean("Success"))) {
|
|
|
- String msg = response.getString("ResMsg");
|
|
|
+ String msg = U9cAuthUtil.getErpErrorMessage(response);
|
|
|
return renderResult(Global.FALSE, text(StringUtils.isNotBlank(msg) ? msg : "同步ERP失败!"));
|
|
|
}
|
|
|
|
|
|
- JSONArray dataList = response.getJSONArray("Data");
|
|
|
+ JSONArray dataList = U9cAuthUtil.getErpDataArray(response);
|
|
|
if (dataList == null || dataList.isEmpty()) {
|
|
|
- return renderResult(Global.FALSE, text("同步ERP失败:返回数据为空!"));
|
|
|
+ String msg = U9cAuthUtil.getErpErrorMessage(response);
|
|
|
+ return renderResult(Global.FALSE, text(StringUtils.isNotBlank(msg) ? msg : "同步ERP失败:返回数据为空!"));
|
|
|
}
|
|
|
JSONObject data = dataList.getJSONObject(0);
|
|
|
if (data == null || !Boolean.TRUE.equals(data.getBoolean("IsSucceed"))) {
|
|
|
- String errorMsg = data != null ? data.getString("ErrorMsg") : null;
|
|
|
+ String errorMsg = U9cAuthUtil.getErpErrorMessage(response);
|
|
|
return renderResult(Global.FALSE, text(StringUtils.isNotBlank(errorMsg) ? errorMsg : "同步ERP失败!"));
|
|
|
}
|
|
|
|
|
|
String code = data.getString("Code");
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ String errorMsg = U9cAuthUtil.getErpErrorMessage(response);
|
|
|
+ return renderResult(Global.FALSE, text(StringUtils.isNotBlank(errorMsg) ? errorMsg : "同步ERP失败:未返回单号!"));
|
|
|
+ }
|
|
|
+ mesProductReport.setDocNo(code);
|
|
|
+ mesProductReportService.update(mesProductReport);
|
|
|
+
|
|
|
String docId = data.getString("ID");
|
|
|
StringBuilder successMsg = new StringBuilder(text("同步ERP成功!"));
|
|
|
- if (StringUtils.isNotBlank(code)) {
|
|
|
- successMsg.append(" ").append(code);
|
|
|
- }
|
|
|
+ successMsg.append(" ").append(code);
|
|
|
if (StringUtils.isNotBlank(docId)) {
|
|
|
successMsg.append(" (").append(docId).append(")");
|
|
|
}
|
|
|
@@ -160,10 +168,11 @@ public class MesProductReportController extends BaseController {
|
|
|
item.put("DocNo", StringUtils.defaultIfBlank(mesProductReport.getDocNo(), ""));
|
|
|
item.put("MODocNo", StringUtils.defaultIfBlank(mesProductReport.getMoDocNo(), ""));
|
|
|
item.put("CompleteDate", formatReportDate(mesProductReport.getCompleteDate()));
|
|
|
- item.put("ActualRcvTime", formatReportDate(mesProductReport.getActualRcvTime()));
|
|
|
item.put("CompleteQty", StringUtils.defaultIfBlank(mesProductReport.getCompleteQty(), ""));
|
|
|
item.put("EligibleQty", StringUtils.defaultIfBlank(mesProductReport.getEligibleQty(), ""));
|
|
|
item.put("ScrapQty", StringUtils.defaultIfBlank(mesProductReport.getScrapQty(), ""));
|
|
|
+ item.put("ScrapReason", StringUtils.defaultIfBlank(mesProductReport.getScrapReason(), ""));
|
|
|
+ item.put("LotCode", StringUtils.defaultIfBlank(mesProductReport.getLotCode(), ""));
|
|
|
|
|
|
JSONArray requestArray = new JSONArray();
|
|
|
requestArray.add(item);
|
|
|
@@ -174,7 +183,88 @@ public class MesProductReportController extends BaseController {
|
|
|
if (date == null) {
|
|
|
return "";
|
|
|
}
|
|
|
- return DateUtils.formatDate(date, "yyyy-MM-dd HH:mm:ss");
|
|
|
+ return DateUtils.formatDate(date, "yyyy-MM-dd");
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
+
|
|
|
+ private MesProductReport resolveMesProductReport(String body, String idParam) {
|
|
|
+ if (StringUtils.isNotBlank(body)) {
|
|
|
+ try {
|
|
|
+ return parseMesProductReportBody(body);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("解析完工报告参数失败", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(idParam)) {
|
|
|
+ MesProductReport exist = mesProductReportService.get(new MesProductReport(idParam));
|
|
|
+ if (exist != null && !exist.getIsNewRecord()) {
|
|
|
+ return exist;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private MesProductReport parseMesProductReportBody(String body) throws ParseException {
|
|
|
+ String json = body.trim();
|
|
|
+ if (json.startsWith("\"") && json.endsWith("\"") && json.length() >= 2) {
|
|
|
+ json = json.substring(1, json.length() - 1);
|
|
|
+ }
|
|
|
+ JSONObject jsonObj = JSON.parseObject(json);
|
|
|
+ if (jsonObj == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ MesProductReport mesProductReport;
|
|
|
+ String id = jsonObj.getString("id");
|
|
|
+ if (StringUtils.isNotBlank(id)) {
|
|
|
+ mesProductReport = mesProductReportService.get(new MesProductReport(id));
|
|
|
+ if (mesProductReport == null || mesProductReport.getIsNewRecord()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mesProductReport = new MesProductReport();
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("otherId")) {
|
|
|
+ mesProductReport.setOtherId(jsonObj.getString("otherId"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("docTypeCode")) {
|
|
|
+ mesProductReport.setDocTypeCode(jsonObj.getString("docTypeCode"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("docNo")) {
|
|
|
+ mesProductReport.setDocNo(jsonObj.getString("docNo"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("moDocNo")) {
|
|
|
+ mesProductReport.setMoDocNo(jsonObj.getString("moDocNo"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("completeQty")) {
|
|
|
+ mesProductReport.setCompleteQty(jsonObj.getString("completeQty"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("eligibleQty")) {
|
|
|
+ mesProductReport.setEligibleQty(jsonObj.getString("eligibleQty"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("scrapQty")) {
|
|
|
+ mesProductReport.setScrapQty(jsonObj.getString("scrapQty"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("scrapReason")) {
|
|
|
+ mesProductReport.setScrapReason(jsonObj.getString("scrapReason"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("lotCode")) {
|
|
|
+ mesProductReport.setLotCode(jsonObj.getString("lotCode"));
|
|
|
+ }
|
|
|
+ if (jsonObj.containsKey("remark")) {
|
|
|
+ mesProductReport.setRemark(jsonObj.getString("remark"));
|
|
|
+ }
|
|
|
+ parseReportDate(jsonObj.getString("businessDate"), mesProductReport::setBusinessDate);
|
|
|
+ parseReportDate(jsonObj.getString("completeDate"), mesProductReport::setCompleteDate);
|
|
|
+ parseReportDate(jsonObj.getString("actualRcvTime"), mesProductReport::setActualRcvTime);
|
|
|
+ return mesProductReport;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void parseReportDate(String dateStr, java.util.function.Consumer<Date> setter) throws ParseException {
|
|
|
+ if (StringUtils.isBlank(dateStr)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String pattern = dateStr.length() > 10 ? "yyyy-MM-dd HH:mm:ss" : "yyyy-MM-dd";
|
|
|
+ setter.accept(new SimpleDateFormat(pattern).parse(dateStr));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|