index.ashx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <%@ WebHandler Language="C#" Class="index" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.SessionState;
  5. using Curtain.DataAccess;
  6. using DK.XuWei.WebMes;
  7. using System.Data;
  8. using Newtonsoft.Json.Linq;
  9. using System.Collections;
  10. using Curtain.Log;
  11. using System.Collections.Generic;
  12. using Oracle.ManagedDataAccess.Client;
  13. using System.Text.RegularExpressions;
  14. public class index : IHttpHandler
  15. {
  16. //输入参数 【条码】
  17. public string barCode = "";
  18. //输入参数 【入库:in】【撤销入库:cancelin】 入库操作预留
  19. public string wmsAction = "";
  20. string procedure_no;
  21. string procedure_in;
  22. string road_no;
  23. string rack;
  24. string position;
  25. //入库是否成功标识
  26. bool WarehostingFlag;
  27. //入库返回失败提示
  28. public string message = "";
  29. //输出参数
  30. public JObject resultJson = null;
  31. public void ProcessRequest(HttpContext context)
  32. {
  33. context.Response.ContentType = "text/plain";
  34. //输入输出参数初始化
  35. barCode = context.Request["barcode"] is object ? context.Request["barcode"] : "";
  36. wmsAction = context.Request["wmsAction"] is object ? context.Request["wmsAction"] : "";
  37. procedure_no = context.Request["procedure_no"] is object ? context.Request["procedure_no"] : "1_1_1";
  38. if (wmsAction.ToLower() == "in") procedure_in = "1";
  39. if (wmsAction.ToLower() == "cancelin") procedure_in = "-1";
  40. road_no = "0";
  41. rack = "";
  42. position = "";
  43. resultJson = new JObject(
  44. new JProperty("success", true),
  45. new JProperty("message", ""),
  46. new JProperty("goods", new JObject(
  47. new JProperty("GoodsName", ""),
  48. new JProperty("GoodsCode", ""),
  49. new JProperty("GoodsSpecification", ""),
  50. new JProperty("GoodsModel", ""),
  51. new JProperty("GoodsType", ""),
  52. new JProperty("GoodsLineType", ""),
  53. new JProperty("GlazeType", ""),
  54. new JProperty("PlateLimitnum", ""),
  55. new JProperty("Logo", ""),
  56. new JProperty("Buildingno", ""),
  57. new JProperty("GoodsLevelName", ""),
  58. new JProperty("KingdeeCode", "")
  59. )
  60. )
  61. );
  62. using (IDataAccess conn = DataAccess.Create())
  63. {
  64. //开启事务
  65. conn.BeginTransaction();
  66. //获取业务数据,无入库动作才获取产品信息
  67. if (Convert.ToBoolean(resultJson["success"]) == true)
  68. {
  69. if (barCode != "" && wmsAction == "")
  70. {
  71. getGoodsData(conn, barCode);
  72. }
  73. else
  74. {
  75. if (barCode == "")
  76. {
  77. resultJson["success"] = false;
  78. resultJson["message"] = "缺少条码参数!";
  79. }
  80. }
  81. }
  82. //执行 【入库:in】【撤销入库:cancelin】 操作 入库撤销操作预留
  83. if (Convert.ToBoolean(resultJson["success"]) == true)
  84. {
  85. if (wmsAction == "in" || wmsAction == "cancelin")
  86. {
  87. string[] arrayBarcode = barCode.Split(',');
  88. for (int i = 0; i < arrayBarcode.Length; i++)
  89. {
  90. //调用标准计件方法===============================
  91. WCF wcf = new WCF();
  92. wcf.Para.Add(new JProperty("barcode", arrayBarcode[i].ToString()));
  93. wcf.Para.Add(new JProperty("procedure_no", procedure_no));
  94. wcf.Para.Add(new JProperty("road_no", road_no));
  95. wcf.Para.Add(new JProperty("rack", rack));
  96. wcf.Para.Add(new JProperty("position", position));
  97. wcf.Para.Add(new JProperty("procedure_in", procedure_in));
  98. string jsonStr = wcf.Get("/DKService/ExHGS3QR/AddWorkInfoHGS3_QR");
  99. //这个接口很小的机率会带出html标签===============================================
  100. if (jsonStr.IndexOf("<html>") > 0) jsonStr = jsonStr.Substring(0, jsonStr.IndexOf("<html>"));
  101. if (jsonStr.IndexOf("<!DOCTYPEhtml>") > 0) jsonStr = jsonStr.Substring(0, jsonStr.IndexOf("<!DOCTYPEhtml>"));
  102. //xuwei fix 2022-05-28 有时会带出 DOCTYPEhtml标签
  103. jsonStr = jsonStr.Replace("<!DOCTYPEhtml>", "");
  104. jsonStr = jsonStr.Replace("\\u000d\\u000a", "")
  105. .Replace("\\n", "").Replace("\\", "").Replace(" ", "")
  106. .Replace("产品编码:", " 产品编码 ")
  107. .Replace("当前工序:", " 当前工序 ")
  108. .Replace("可到工序:", " 可到工序 ")
  109. .Replace("{\"d\":\"", "")
  110. .Replace("\"}\"}", "\"}")
  111. .Replace("<!DOCTYPEhtml>", "")
  112. ;
  113. Curtain.Log.Logger.Debug(context.Request.UserHostAddress + "\r\n" + context.Request.Url + "\r\n" + jsonStr);
  114. string apiResult = "";
  115. //处理输出结果 OK开头成功 NOK开头失败
  116. JObject json = JObject.Parse(jsonStr);
  117. bool apiStatus = false;
  118. apiStatus = Convert.ToBoolean(json["success"]);
  119. apiResult = jsonStr;
  120. //HttpContext.Current.Response.Write(apiResult);
  121. //记录接口调用日志
  122. Hashtable ht = new Hashtable();
  123. ht.Add("barcode", arrayBarcode[i].ToString());
  124. ht.Add("procedure_no", procedure_no);
  125. ht.Add("road_no", road_no);
  126. ht.Add("rack", rack);
  127. ht.Add("position", position);
  128. ht.Add("procedure_in", procedure_in);
  129. int apiId = Convert.ToInt32(procedure_no.Replace("_", "") + road_no + Math.Abs(Convert.ToInt32(procedure_in)));
  130. arrayBarcode[i] = arrayBarcode[i].Replace("2c%", ",");
  131. int apiBarcodeCount = arrayBarcode[i].Split(',').Length;
  132. string apiUrl = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port.ToString() + "/api/DKService/ExHGS3QR/AddWorkInfoHGS3_QR/?" + JsonClient.ParaToString(ht);
  133. ApiLog.WriteApiLog("立库_扫码", apiUrl, apiStatus, apiResult, apiId, apiBarcodeCount);
  134. //===============================================
  135. if (Convert.ToBoolean(json["success"]) == true)
  136. {
  137. WarehostingFlag = true;
  138. //message += "条码[" + arrayBarcode[i] + "]入库成功,";
  139. doWmsAction(conn, arrayBarcode[i], wmsAction, WarehostingFlag);
  140. }
  141. else
  142. {
  143. if (wmsAction == "in")
  144. {
  145. WarehostingFlag = false;
  146. message += json["message"].ToString() + ",";
  147. doWmsAction(conn, arrayBarcode[i], wmsAction, WarehostingFlag);
  148. }
  149. else if (wmsAction == "cancelin")
  150. {
  151. //resultJson["success"] = false;
  152. //resultJson["message"] = "产品撤销入库失败!";
  153. }
  154. }
  155. }
  156. }
  157. }
  158. //提交事务
  159. if (Convert.ToBoolean(resultJson["success"]) == true)
  160. {
  161. conn.Commit();
  162. }
  163. else
  164. {
  165. conn.Rollback();
  166. }
  167. //输出JSON数据
  168. context.Response.Write(resultJson.ToString());
  169. }
  170. }
  171. //获取业务数据
  172. private void getGoodsData(IDataAccess conn, string barCode)
  173. {
  174. //业务数据读取
  175. DataTable dt = conn.ExecuteDatatable(@"
  176. SELECT
  177. T.BARCODE,
  178. T.GOODSNAME,
  179. T.GOODSCODE,
  180. T.GOODSSPECIFICATION,
  181. T.GOODSMODEL,
  182. T.GOODSTYPENAME,
  183. T.GOODS_LINE_TYPE,
  184. T.DICTIONARYVALUE,
  185. T.PLATELIMITNUM,
  186. T.LOGONAME,
  187. T.BUILDINGNO,
  188. TMGL.GOODSLEVELNAME,
  189. TMGK.KingdeeCode,
  190. T.CREATETIME,
  191. T.GOODSLEVELID
  192. FROM
  193. (
  194. SELECT DISTINCT
  195. TPGD.BARCODE,
  196. TPGD.GOODSNAME,
  197. TPGD.GOODSCODE,
  198. TMG.GOODSSPECIFICATION,
  199. TMG.GOODSMODEL,
  200. TMGT.GOODSTYPENAME,
  201. CASE
  202. TMG.GOODS_LINE_TYPE WHEN 0 THEN
  203. '普通' ELSE '高压'
  204. END AS GOODS_LINE_TYPE,
  205. TMDC.DICTIONARYVALUE,
  206. 1 AS PLATELIMITNUM,
  207. TML.LOGONAME,
  208. (
  209. CASE WHEN TPPC.PROCEDUREID = 35 THEN '重烧' WHEN TPPC.PROCEDUREID != 35 THEN ( CASE WHEN TPG.BUILDINGNO = '1#' THEN '一期' WHEN TPG.BUILDINGNO = '2#' THEN '二期' WHEN TPG.BUILDINGNO = '3#' THEN '三期' END ) END
  210. ) AS BUILDINGNO,
  211. TPPD.GOODSLEVELID,
  212. NULL AS KingdeeCode,
  213. TPPD.CHECKFLAG,
  214. TPGR.CREATETIME
  215. FROM
  216. TP_PM_GROUTINGDAILYDETAIL TPGD
  217. LEFT JOIN TP_PM_GlazetypeRecord TPGR ON TPGR.GROUTINGDAILYDETAILID = TPGD.GROUTINGDAILYDETAILID
  218. LEFT JOIN TP_MST_GOODS TMG ON TPGD.GOODSID = TMG.GOODSID
  219. LEFT JOIN TP_MST_GOODSTYPE TMGT ON TMG.GOODSTYPEID = TMGT.GOODSTYPEID
  220. LEFT JOIN TP_MST_DATADICTIONARY TMDC ON TPGR.NEWGLAZETYPEID = TMDC.DICTIONARYID
  221. LEFT JOIN TP_MST_LOGO TML ON TPGD.LOGOID = TML.LOGOID
  222. LEFT JOIN TP_PC_GROUTINGLINE TPG ON TPGD.GROUTINGLINEID = TPG.GROUTINGLINEID
  223. INNER JOIN TP_PM_PRODUCTIONDATA TPPD ON TPGD.BARCODE = TPPD.BARCODE
  224. LEFT JOIN TP_PC_PROCEDURE TPPC ON TPPD.PROCEDUREID = TPPC.PROCEDUREID
  225. WHERE
  226. ( CASE WHEN
  227. ( SELECT COUNT( * ) FROM TP_PM_PRODUCTIONDATA TPPD LEFT JOIN TP_PC_PROCEDURE TPPC ON TPPD.PROCEDUREID = TPPC.PROCEDUREID WHERE TPPD.PROCEDUREID IN 35 AND TPPD.BARCODE = @BARCODE@ ) = 1 THEN 35
  228. ELSE 13 END
  229. ) = TPPD.PROCEDUREID
  230. AND TPGD.VALUEFLAG = 1
  231. AND TMDC.DICTIONARYTYPE = 'TPC002'
  232. AND TPGD.BARCODE = @BARCODE@
  233. ORDER BY TPGR.CREATETIME DESC) T
  234. LEFT JOIN TP_MST_GOODSKINGDEECODE TMGK ON T.GOODSCODE = TMGK.GOODSCODE
  235. AND T.DICTIONARYVALUE = TMGK.GLAZETYPE
  236. AND T.LOGONAME = TMGK.LOGONAME
  237. LEFT JOIN TP_MST_GOODSLEVEL TMGL ON TMGL.GOODSLEVELID = T.GOODSLEVELID
  238. ORDER BY T.GOODSLEVELID,T.CREATETIME DESC",
  239. new CDAParameter("BARCODE", barCode)
  240. );
  241. if (dt.Rows.Count > 0)
  242. {
  243. resultJson["success"] = true;
  244. resultJson["message"] = "数据读取成功!";
  245. resultJson["goods"]["GoodsName"] = dt.Rows[0]["GOODSNAME"].ToString();
  246. resultJson["goods"]["GoodsCode"] = dt.Rows[0]["GOODSCODE"].ToString();
  247. resultJson["goods"]["GoodsSpecification"] = dt.Rows[0]["GOODSSPECIFICATION"].ToString();
  248. resultJson["goods"]["GoodsModel"] = dt.Rows[0]["GOODSMODEL"].ToString();
  249. resultJson["goods"]["GoodsType"] = dt.Rows[0]["GOODSTYPENAME"].ToString();
  250. resultJson["goods"]["GoodsLineType"] = dt.Rows[0]["GOODS_LINE_TYPE"].ToString();
  251. resultJson["goods"]["GlazeType"] = dt.Rows[0]["DICTIONARYVALUE"].ToString();
  252. resultJson["goods"]["PlateLimitnum"] = dt.Rows[0]["PLATELIMITNUM"].ToString();
  253. resultJson["goods"]["Logo"] = dt.Rows[0]["LOGONAME"].ToString();
  254. resultJson["goods"]["Buildingno"] = dt.Rows[0]["BUILDINGNO"].ToString();
  255. resultJson["goods"]["GoodsLevelName"] = dt.Rows[0]["GOODSLEVELNAME"].ToString();
  256. resultJson["goods"]["KingdeeCode"] = dt.Rows[0]["KingdeeCode"].ToString().Trim();
  257. }
  258. else
  259. {
  260. resultJson["success"] = false;
  261. resultJson["message"] = "条码错误或不存在此产品!";
  262. }
  263. //写日志
  264. ///writeLog(conn);
  265. }
  266. //入库方法
  267. private void doWmsAction(IDataAccess conn, string barCode, string action, bool WarehostingFlag)
  268. {
  269. int Count = 0;
  270. string sql;
  271. CDAParameter[] para;
  272. //入库操作(条码支持多个,用逗号分开)
  273. if (action == "in")
  274. {
  275. //入库操作
  276. #region 入库校验有一个不成功,则全部入库失败
  277. //DataTable dt = conn.ExecuteDatatable(@"SELECT WMSACTION,BARCODE FROM TP_PM_GOODSWHETHERWAREHOUSING WHERE BARCODE = @BARCODE@ AND VALUEFLAG = 1",
  278. // new CDAParameter("BARCODE", arrayBarcode[i].ToString())
  279. // );
  280. ////入库
  281. //if (dt.Rows.Count != 0)
  282. //{
  283. // if (dt.Rows[0]["WMSACTION"].ToString() == "0")
  284. // {
  285. // sql = @"UPDATE TP_PM_GOODSWHETHERWAREHOUSING SET WMSACTION=@WMSACTION@ WHERE BARCODE = @BARCODE@";
  286. // para = new CDAParameter[]{
  287. // new CDAParameter("BARCODE",arrayBarcode[i].ToString()),
  288. // new CDAParameter("WMSACTION",1)
  289. // };
  290. // Count += conn.ExecuteNonQuery(sql, para);
  291. // }
  292. // else
  293. // {
  294. // resultJson["success"] = false;
  295. // resultJson["message"] = "产品入库失败!条码为:" + dt.Rows[0]["BARCODE"] + "的产品已经入库";
  296. // return;
  297. // }
  298. //}
  299. //else
  300. //{
  301. // sql = @"INSERT INTO TP_PM_GOODSWHETHERWAREHOUSING(BARCODE,WMSACTION)VALUES(@BARCODE@,@WMSACTION@)";
  302. // para = new CDAParameter[]{
  303. // new CDAParameter("BARCODE",arrayBarcode[i].ToString()),
  304. // new CDAParameter("WMSACTION",1)
  305. // };
  306. // Count += conn.ExecuteNonQuery(sql, para);
  307. //}
  308. #endregion
  309. #region 失败的不入库 成功的入库
  310. try
  311. {
  312. if (WarehostingFlag == true)
  313. {
  314. sql = @"INSERT INTO TP_PM_GOODSWHETHERWAREHOUSING(BARCODE,WMSACTION)VALUES(@BARCODE@,@WMSACTION@)";
  315. para = new CDAParameter[]{
  316. new CDAParameter("BARCODE",barCode),
  317. new CDAParameter("WMSACTION",1),
  318. };
  319. Count = conn.ExecuteNonQuery(sql, para);
  320. }
  321. if (Count == 1)
  322. {
  323. message += "条码[" + barCode + "]入库成功,";
  324. resultJson["success"] = true;
  325. resultJson["message"] = message;
  326. }
  327. else
  328. {
  329. resultJson["success"] = true;
  330. resultJson["message"] = message;
  331. }
  332. }
  333. catch (Exception)
  334. {
  335. message += "条码[" + barCode + "] 已经入库了,";
  336. resultJson["success"] = true;
  337. resultJson["message"] = message;
  338. return;
  339. }
  340. #endregion
  341. }
  342. //入库撤销操作 预留内容(条码支持多个,用逗号分开)
  343. if (action == "cancelin")
  344. {
  345. //调用计件撤销方法===============================
  346. //DataTable dt = conn.ExecuteDatatable(@"SELECT WMSACTION,BARCODE FROM TP_PM_GOODSWHETHERWAREHOUSING WHERE BARCODE = @BARCODE@ AND VALUEFLAG = 1",
  347. //new CDAParameter("BARCODE", barCode)
  348. //);
  349. //if (dt.Rows.Count != 0)
  350. //{
  351. // if (dt.Rows[0]["WMSACTION"].ToString() == "0")
  352. // {
  353. // resultJson["success"] = false;
  354. // resultJson["message"] = "产品撤销入库失败!条码为:" + dt.Rows[0]["BARCODE"] + "的产品已经撤销入库";
  355. // return;
  356. // }
  357. // sql = @"UPDATE TP_PM_GOODSWHETHERWAREHOUSING SET WMSACTION=@WMSACTION@ WHERE BARCODE = @BARCODE@";
  358. // para = new CDAParameter[]{
  359. // new CDAParameter("BARCODE",barCode),
  360. // new CDAParameter("WMSACTION",0)
  361. // };
  362. // Count += conn.ExecuteNonQuery(sql, para);
  363. //}
  364. //else
  365. //{
  366. // resultJson["success"] = false;
  367. // resultJson["message"] = "产品撤销入库失败!条码不存在";
  368. // return;
  369. //}
  370. }
  371. //if (Count == arrayBarcode.Length)
  372. //{
  373. // if (action == "in")
  374. // {
  375. // resultJson["success"] = true;
  376. // resultJson["message"] = "产品入库成功!";
  377. // }
  378. // else if (action == "cancelin")
  379. // {
  380. // resultJson["success"] = true;
  381. // resultJson["message"] = "产品撤销入库成功!";
  382. // }
  383. //}
  384. //else
  385. //{
  386. // if (action == "in")
  387. // {
  388. // resultJson["success"] = false;
  389. // resultJson["message"] = "产品入库失败!";
  390. // }
  391. // else if (action == "cancelin")
  392. // {
  393. // resultJson["success"] = false;
  394. // resultJson["message"] = "产品撤销入库失败!";
  395. // }
  396. //}
  397. //===============================================
  398. //写日志
  399. //writeLog(conn);
  400. }
  401. //日志记录(访问者IP,访问链接,访问参数,返回结果,访问时间)
  402. //private void writeLog(IDataAccess conn)
  403. //{
  404. // if(Convert.ToBoolean(resultJson["success"]) == true)
  405. // {
  406. // Logger.Info("IP:" + HttpContext.Current.Request.UserHostAddress + " "+"访问链接:"+ HttpContext.Current.Request.UrlReferrer +" "+ " " +
  407. // "条码:" + barCode + " 入库标识:"+ wmsAction +" " +" 输出:" + resultJson.ToString());
  408. // }
  409. // else
  410. // {
  411. // Logger.Info("IP:" + HttpContext.Current.Request.UserHostAddress +"访问链接:"+ HttpContext.Current.Request.UrlReferrer + " " +
  412. // "条码:"+ barCode +" 入库标识:"+ wmsAction +" "+ resultJson["message"] + "输出:" + resultJson.ToString());
  413. // }
  414. //}
  415. public bool IsReusable
  416. {
  417. get
  418. {
  419. return false;
  420. }
  421. }
  422. }