index.ashx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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.GOODSNAME,
  178. T.GOODSCODE,
  179. T.GOODSSPECIFICATION,
  180. T.GOODSMODEL,
  181. T.GOODSTYPENAME,
  182. T.GOODS_LINE_TYPE,
  183. T.DICTIONARYVALUE,
  184. T.PLATELIMITNUM,
  185. T.LOGONAME,
  186. T.BUILDINGNO,
  187. T.GOODSLEVELNAME,
  188. TMGK.KingdeeCode
  189. FROM
  190. (
  191. SELECT DISTINCT
  192. TPGD.GOODSNAME,
  193. TPGD.GOODSCODE,
  194. TMG.GOODSSPECIFICATION,
  195. TMG.GOODSMODEL,
  196. TMGT.GOODSTYPENAME,
  197. CASE
  198. TMG.GOODS_LINE_TYPE
  199. WHEN 0 THEN
  200. '普通' ELSE '高压'
  201. END AS GOODS_LINE_TYPE,
  202. TMDC.DICTIONARYVALUE,
  203. 1 AS PLATELIMITNUM,
  204. TML.LOGONAME,
  205. (
  206. CASE
  207. WHEN TPPC.PROCEDUREID = 35 THEN
  208. '重烧'
  209. WHEN TPPC.PROCEDUREID != 35 THEN
  210. ( CASE WHEN TPG.BUILDINGNO = '1#' THEN '一期' WHEN TPG.BUILDINGNO = '2#' THEN '二期' WHEN TPG.BUILDINGNO = '3#' THEN '三期' END )
  211. END
  212. ) AS BUILDINGNO,
  213. TMGL.GOODSLEVELNAME,
  214. NULL AS KingdeeCode
  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. LEFT JOIN TP_MST_GOODSLEVEL TMGL ON TPGD.GOODSLEVELTYPEID = TMGL.GOODSLEVELTYPEID
  224. LEFT JOIN TP_PM_PRODUCTIONDATA TPPD ON TPGD.BARCODE = TPPD.BARCODE
  225. LEFT JOIN TP_PC_PROCEDURE TPPC ON TPPD.PROCEDUREID = TPPC.PROCEDUREID
  226. WHERE
  227. (
  228. CASE
  229. WHEN(
  230. SELECT
  231. COUNT( * )
  232. FROM
  233. TP_PM_PRODUCTIONDATA TPPD
  234. LEFT JOIN TP_PC_PROCEDURE TPPC ON TPPD.PROCEDUREID = TPPC.PROCEDUREID
  235. WHERE
  236. TPPD.PROCEDUREID = 35
  237. AND TPPD.BARCODE = @BARCODE@
  238. ) = 1 THEN
  239. 35 ELSE TPPD.PROCEDUREID
  240. END
  241. ) = TPPD.PROCEDUREID
  242. AND TPGD.VALUEFLAG = 1
  243. AND TMDC.DICTIONARYTYPE = 'TPC002'
  244. AND TPPD.BARCODE = @BARCODE@
  245. ) T
  246. LEFT JOIN TP_MST_GOODSKINGDEECODE TMGK ON T.GOODSCODE = TMGK.GOODSCODE
  247. AND T.DICTIONARYVALUE = TMGK.GLAZETYPE
  248. AND T.LOGONAME = TMGK.LOGONAME
  249. ",
  250. new CDAParameter("BARCODE", barCode)
  251. );
  252. if (dt.Rows.Count > 0)
  253. {
  254. resultJson["success"] = true;
  255. resultJson["message"] = "数据读取成功!";
  256. resultJson["goods"]["GoodsName"] = dt.Rows[0]["GOODSNAME"].ToString();
  257. resultJson["goods"]["GoodsCode"] = dt.Rows[0]["GOODSCODE"].ToString();
  258. resultJson["goods"]["GoodsSpecification"] = dt.Rows[0]["GOODSSPECIFICATION"].ToString();
  259. resultJson["goods"]["GoodsModel"] = dt.Rows[0]["GOODSMODEL"].ToString();
  260. resultJson["goods"]["GoodsType"] = dt.Rows[0]["GOODSTYPENAME"].ToString();
  261. resultJson["goods"]["GoodsLineType"] = dt.Rows[0]["GOODS_LINE_TYPE"].ToString();
  262. resultJson["goods"]["GlazeType"] = dt.Rows[0]["DICTIONARYVALUE"].ToString();
  263. resultJson["goods"]["PlateLimitnum"] = dt.Rows[0]["PLATELIMITNUM"].ToString();
  264. resultJson["goods"]["Logo"] = dt.Rows[0]["LOGONAME"].ToString();
  265. resultJson["goods"]["Buildingno"] = dt.Rows[0]["BUILDINGNO"].ToString();
  266. resultJson["goods"]["GoodsLevelName"] = dt.Rows[0]["GOODSLEVELNAME"].ToString();
  267. resultJson["goods"]["KingdeeCode"] = dt.Rows[0]["KingdeeCode"].ToString();
  268. }
  269. else
  270. {
  271. resultJson["success"] = false;
  272. resultJson["message"] = "条码错误或不存在此产品!";
  273. }
  274. //写日志
  275. ///writeLog(conn);
  276. }
  277. //入库方法
  278. private void doWmsAction(IDataAccess conn, string barCode, string action, bool WarehostingFlag)
  279. {
  280. int Count = 0;
  281. string sql;
  282. CDAParameter[] para;
  283. //入库操作(条码支持多个,用逗号分开)
  284. if (action == "in")
  285. {
  286. //入库操作
  287. #region 入库校验有一个不成功,则全部入库失败
  288. //DataTable dt = conn.ExecuteDatatable(@"SELECT WMSACTION,BARCODE FROM TP_PM_GOODSWHETHERWAREHOUSING WHERE BARCODE = @BARCODE@ AND VALUEFLAG = 1",
  289. // new CDAParameter("BARCODE", arrayBarcode[i].ToString())
  290. // );
  291. ////入库
  292. //if (dt.Rows.Count != 0)
  293. //{
  294. // if (dt.Rows[0]["WMSACTION"].ToString() == "0")
  295. // {
  296. // sql = @"UPDATE TP_PM_GOODSWHETHERWAREHOUSING SET WMSACTION=@WMSACTION@ WHERE BARCODE = @BARCODE@";
  297. // para = new CDAParameter[]{
  298. // new CDAParameter("BARCODE",arrayBarcode[i].ToString()),
  299. // new CDAParameter("WMSACTION",1)
  300. // };
  301. // Count += conn.ExecuteNonQuery(sql, para);
  302. // }
  303. // else
  304. // {
  305. // resultJson["success"] = false;
  306. // resultJson["message"] = "产品入库失败!条码为:" + dt.Rows[0]["BARCODE"] + "的产品已经入库";
  307. // return;
  308. // }
  309. //}
  310. //else
  311. //{
  312. // sql = @"INSERT INTO TP_PM_GOODSWHETHERWAREHOUSING(BARCODE,WMSACTION)VALUES(@BARCODE@,@WMSACTION@)";
  313. // para = new CDAParameter[]{
  314. // new CDAParameter("BARCODE",arrayBarcode[i].ToString()),
  315. // new CDAParameter("WMSACTION",1)
  316. // };
  317. // Count += conn.ExecuteNonQuery(sql, para);
  318. //}
  319. #endregion
  320. #region 失败的不入库 成功的入库
  321. try
  322. {
  323. if (WarehostingFlag == true)
  324. {
  325. sql = @"INSERT INTO TP_PM_GOODSWHETHERWAREHOUSING(BARCODE,WMSACTION)VALUES(@BARCODE@,@WMSACTION@)";
  326. para = new CDAParameter[]{
  327. new CDAParameter("BARCODE",barCode),
  328. new CDAParameter("WMSACTION",1),
  329. };
  330. Count = conn.ExecuteNonQuery(sql, para);
  331. }
  332. if (Count == 1)
  333. {
  334. message += "条码[" + barCode + "]入库成功,";
  335. resultJson["success"] = true;
  336. resultJson["message"] = message;
  337. }
  338. else
  339. {
  340. resultJson["success"] = true;
  341. resultJson["message"] = message;
  342. }
  343. }
  344. catch (Exception)
  345. {
  346. message += "条码[" + barCode + "] 已经入库了,";
  347. resultJson["success"] = true;
  348. resultJson["message"] = message;
  349. return;
  350. }
  351. #endregion
  352. }
  353. //入库撤销操作 预留内容(条码支持多个,用逗号分开)
  354. if (action == "cancelin")
  355. {
  356. //调用计件撤销方法===============================
  357. //DataTable dt = conn.ExecuteDatatable(@"SELECT WMSACTION,BARCODE FROM TP_PM_GOODSWHETHERWAREHOUSING WHERE BARCODE = @BARCODE@ AND VALUEFLAG = 1",
  358. //new CDAParameter("BARCODE", barCode)
  359. //);
  360. //if (dt.Rows.Count != 0)
  361. //{
  362. // if (dt.Rows[0]["WMSACTION"].ToString() == "0")
  363. // {
  364. // resultJson["success"] = false;
  365. // resultJson["message"] = "产品撤销入库失败!条码为:" + dt.Rows[0]["BARCODE"] + "的产品已经撤销入库";
  366. // return;
  367. // }
  368. // sql = @"UPDATE TP_PM_GOODSWHETHERWAREHOUSING SET WMSACTION=@WMSACTION@ WHERE BARCODE = @BARCODE@";
  369. // para = new CDAParameter[]{
  370. // new CDAParameter("BARCODE",barCode),
  371. // new CDAParameter("WMSACTION",0)
  372. // };
  373. // Count += conn.ExecuteNonQuery(sql, para);
  374. //}
  375. //else
  376. //{
  377. // resultJson["success"] = false;
  378. // resultJson["message"] = "产品撤销入库失败!条码不存在";
  379. // return;
  380. //}
  381. }
  382. //if (Count == arrayBarcode.Length)
  383. //{
  384. // if (action == "in")
  385. // {
  386. // resultJson["success"] = true;
  387. // resultJson["message"] = "产品入库成功!";
  388. // }
  389. // else if (action == "cancelin")
  390. // {
  391. // resultJson["success"] = true;
  392. // resultJson["message"] = "产品撤销入库成功!";
  393. // }
  394. //}
  395. //else
  396. //{
  397. // if (action == "in")
  398. // {
  399. // resultJson["success"] = false;
  400. // resultJson["message"] = "产品入库失败!";
  401. // }
  402. // else if (action == "cancelin")
  403. // {
  404. // resultJson["success"] = false;
  405. // resultJson["message"] = "产品撤销入库失败!";
  406. // }
  407. //}
  408. //===============================================
  409. //写日志
  410. //writeLog(conn);
  411. }
  412. //日志记录(访问者IP,访问链接,访问参数,返回结果,访问时间)
  413. //private void writeLog(IDataAccess conn)
  414. //{
  415. // if(Convert.ToBoolean(resultJson["success"]) == true)
  416. // {
  417. // Logger.Info("IP:" + HttpContext.Current.Request.UserHostAddress + " "+"访问链接:"+ HttpContext.Current.Request.UrlReferrer +" "+ " " +
  418. // "条码:" + barCode + " 入库标识:"+ wmsAction +" " +" 输出:" + resultJson.ToString());
  419. // }
  420. // else
  421. // {
  422. // Logger.Info("IP:" + HttpContext.Current.Request.UserHostAddress +"访问链接:"+ HttpContext.Current.Request.UrlReferrer + " " +
  423. // "条码:"+ barCode +" 入库标识:"+ wmsAction +" "+ resultJson["message"] + "输出:" + resultJson.ToString());
  424. // }
  425. //}
  426. public bool IsReusable
  427. {
  428. get
  429. {
  430. return false;
  431. }
  432. }
  433. }