|
|
@@ -0,0 +1,180 @@
|
|
|
+<%@ WebHandler Language="C#" Class="DKService_ExHGS3QR_AddGroutingData_JM" %>
|
|
|
+
|
|
|
+using System;
|
|
|
+using System.Web;
|
|
|
+using System.Web.SessionState;
|
|
|
+using Curtain.DataAccess;
|
|
|
+using DK.XuWei.WebMes;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using Curtain.Log;
|
|
|
+using System.Collections;
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// 给金马:自动注浆绑码接口
|
|
|
+/// </summary>
|
|
|
+public class DKService_ExHGS3QR_AddGroutingData_JM : IHttpHandler,IReadOnlySessionState
|
|
|
+{
|
|
|
+
|
|
|
+ public void ProcessRequest(HttpContext context)
|
|
|
+ {
|
|
|
+ context.Response.ContentType = "application/json";
|
|
|
+ context.Response.Charset = "UTF-8";
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 读取请求体(支持JSON格式)
|
|
|
+ string requestBody = string.Empty;
|
|
|
+ using (var reader = new System.IO.StreamReader(context.Request.InputStream))
|
|
|
+ {
|
|
|
+ requestBody = reader.ReadToEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析JSON数据
|
|
|
+ JObject jsonData;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ jsonData = JObject.Parse(requestBody);
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ ReturnError(context, "JSON格式错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取DATA节点
|
|
|
+ JObject data = jsonData["DATA"] as JObject;
|
|
|
+ if (data == null)
|
|
|
+ {
|
|
|
+ ReturnError(context, "缺少DATA节点");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证必填字段
|
|
|
+ string[] requiredFields = {
|
|
|
+ "GROUTINGLINECODE",
|
|
|
+ "MOULDCODE",
|
|
|
+ "USERCODE",
|
|
|
+ "GROUTINGDATE",
|
|
|
+ "CREATETIME",
|
|
|
+ "BARCODE"
|
|
|
+ };
|
|
|
+
|
|
|
+ foreach (var field in requiredFields)
|
|
|
+ {
|
|
|
+ if (data[field] == null || string.IsNullOrWhiteSpace(data[field].ToString()))
|
|
|
+ {
|
|
|
+ ReturnError(context, "必填字段"+field+"为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取参数
|
|
|
+ string groutingLineCode = data["GROUTINGLINECODE"].ToString();
|
|
|
+ string mouldCode = data["MOULDCODE"].ToString();
|
|
|
+ string userCode = data["USERCODE"].ToString();
|
|
|
+ string groutingDateStr = data["GROUTINGDATE"].ToString();
|
|
|
+ string createTimeStr = data["CREATETIME"].ToString();
|
|
|
+ string barcode = data["BARCODE"].ToString();
|
|
|
+ string highNum = data.ContainsKey("HIGHNUM")?data["HIGHNUM"].ToString() :"";
|
|
|
+ string tbInfo = data.ContainsKey("TBINFO")?data["TBINFO"].ToString() :"";
|
|
|
+
|
|
|
+ // 解析日期
|
|
|
+ DateTime groutingDate, createTime;
|
|
|
+ if (!DateTime.TryParse(groutingDateStr, out groutingDate))
|
|
|
+ {
|
|
|
+ ReturnError(context, "GROUTINGDATE日期格式错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!DateTime.TryParse(createTimeStr, out createTime))
|
|
|
+ {
|
|
|
+ ReturnError(context, "CREATETIME日期格式错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 以下是业务逻辑处理 ==========
|
|
|
+
|
|
|
+ //调用WCF接口
|
|
|
+ WCF wcf = new WCF();
|
|
|
+ wcf.Para.Add(new JProperty("groutingLineCode", groutingLineCode));
|
|
|
+ wcf.Para.Add(new JProperty("mouldCode", mouldCode));
|
|
|
+ wcf.Para.Add(new JProperty("userCode", userCode));
|
|
|
+ wcf.Para.Add(new JProperty("groutingDateStr", groutingDate));
|
|
|
+ wcf.Para.Add(new JProperty("createTimeStr", createTime));
|
|
|
+ wcf.Para.Add(new JProperty("barcode", barcode));
|
|
|
+ wcf.Para.Add(new JProperty("highNum", highNum));
|
|
|
+ wcf.Para.Add(new JProperty("tbInfo", tbInfo));
|
|
|
+ string jsonStr = wcf.Get("/DKService/ExHGS3QR/AddGroutingData_JM");
|
|
|
+
|
|
|
+ //这个接口很小的机率会带出html标签===============================================
|
|
|
+ if (jsonStr.IndexOf("<html>") > 0) jsonStr = jsonStr.Substring(0, jsonStr.IndexOf("<html>"));
|
|
|
+
|
|
|
+ //xuwei fix 2022-05-28 有时会带出 DOCTYPEhtml标签
|
|
|
+ jsonStr = jsonStr.Trim().Replace("<!DOCTYPEhtml>","");
|
|
|
+
|
|
|
+ jsonStr = jsonStr.Replace("\\u000d\\u000a", "")
|
|
|
+ .Replace("\\n","").Replace("\\","").Replace(" ","")
|
|
|
+ .Replace("产品编码:"," 产品编码 ")
|
|
|
+ .Replace("当前工序:"," 当前工序 ")
|
|
|
+ .Replace("可到工序:"," 可到工序 ")
|
|
|
+ .Replace("{\"d\":\"","")
|
|
|
+ .Replace("\"}\"}","\"}")
|
|
|
+ ;
|
|
|
+
|
|
|
+ Logger.Debug(context.Request.UserHostAddress + "\r\n" + context.Request.Url + "\r\n" +jsonStr);
|
|
|
+
|
|
|
+ string apiResult = "";
|
|
|
+
|
|
|
+ //处理输出结果
|
|
|
+ JObject json = JObject.Parse(jsonStr.Replace("}<!DOCTYPEhtml>","}").ToString());
|
|
|
+ bool apiStatus = false;
|
|
|
+ apiStatus = Convert.ToBoolean(json["success"]);
|
|
|
+ apiResult = jsonStr.Replace("}<!DOCTYPEhtml>", "}").ToString();
|
|
|
+ context.Response.Write(apiResult);
|
|
|
+
|
|
|
+ //记录接口调用日志
|
|
|
+ Hashtable ht = new Hashtable();
|
|
|
+ ht.Add("groutingLineCode", groutingLineCode);
|
|
|
+ ht.Add("mouldCode", mouldCode);
|
|
|
+ ht.Add("userCode", userCode);
|
|
|
+ ht.Add("groutingDateStr", groutingDateStr);
|
|
|
+ ht.Add("barcode", barcode);
|
|
|
+
|
|
|
+ int apiId = 20401;
|
|
|
+ barcode = barcode.Replace("2c%", ",");
|
|
|
+ int apiBarcodeCount = barcode.Split(',').Length;
|
|
|
+ string apiUrl = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port.ToString() + "/api/DKService/ExHGS3QR/AddGroutingData_JM/?" + JsonClient.ParaToString(ht)+
|
|
|
+ "&createTimeStr="+createTimeStr+"&highNum="+highNum+"&tbInfo="+tbInfo;
|
|
|
+ ApiLog.WriteApiLog("金马_自动注浆绑码", apiUrl, apiStatus, apiResult, apiId, apiBarcodeCount);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ // 记录日志
|
|
|
+ Curtain.Log.Logger.Debug(context.Request.UserHostAddress + "\r\n" + context.Request.Url + "\r\n" +ex);
|
|
|
+ ReturnError(context, "系统异常:"+ex.Message);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReturnError(HttpContext context, string message)
|
|
|
+ {
|
|
|
+ var errorResponse = new
|
|
|
+ {
|
|
|
+ Success = false,
|
|
|
+ Message = message,
|
|
|
+ ErrorCode = "400"
|
|
|
+ };
|
|
|
+ context.Response.StatusCode = 400;
|
|
|
+ context.Response.Write(errorResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsReusable
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|