|
|
@@ -0,0 +1,436 @@
|
|
|
+/*******************************************************************************
|
|
|
+ * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
|
|
|
+ * 类的信息:
|
|
|
+ * 1.程序名称:SmartDeviceService.cs
|
|
|
+ * 2.功能描述:接收智能设备请求
|
|
|
+ * 编辑履历:
|
|
|
+ * 作者 日期 版本 修改内容
|
|
|
+ * 陈晓野 2018/10/25 1.00 新建
|
|
|
+ * 徐伟 2020/07/30 2.00 重组结构优化代码
|
|
|
+ *******************************************************************************/
|
|
|
+
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+using System.Data;
|
|
|
+using System.ServiceModel;
|
|
|
+using System.ServiceModel.Activation;
|
|
|
+
|
|
|
+using Curtain.DataAccess;
|
|
|
+
|
|
|
+using Dongke.IBOSS.PRD.Basics.BaseResources;
|
|
|
+using Dongke.IBOSS.PRD.Basics.DataAccess;
|
|
|
+using Dongke.IBOSS.PRD.Basics.Library;
|
|
|
+using Dongke.IBOSS.PRD.Service.DataModels;
|
|
|
+using Dongke.IBOSS.PRD.Service.PDAModuleLogic;
|
|
|
+using Dongke.IBOSS.PRD.Service.PMModuleLogic;
|
|
|
+using Dongke.IBOSS.PRD.Service.SmartDeviceService;
|
|
|
+using Dongke.IBOSS.PRD.WCF.DataModels;
|
|
|
+
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+
|
|
|
+using Oracle.ManagedDataAccess.Client;
|
|
|
+
|
|
|
+namespace Dongke.IBOSS.PRD.WCF.ExHGS3QRS
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 智能设备对接服务
|
|
|
+ /// </summary>
|
|
|
+ [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
|
|
|
+ [ServiceBehavior(ConfigurationName = "ExHGS3QR",
|
|
|
+ InstanceContextMode = InstanceContextMode.PerCall,
|
|
|
+ ConcurrencyMode = ConcurrencyMode.Multiple,
|
|
|
+ UseSynchronizationContext = false)]
|
|
|
+ public class ExHGS3QR : IExHGS3QR
|
|
|
+ {
|
|
|
+ #region 恒洁三水三车间对接金马扫码
|
|
|
+ public string AddWorkInfoHGS3_QR_TEST(string barcode, string procedure_no, int road_no, double weight)
|
|
|
+ {
|
|
|
+ return "{\"success\":true,\"message\":\"产品库位调度成功!\"}";
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 恒洁三水三车间对接金马扫码
|
|
|
+ /// TP_SYS_SMARTDEVICEPOINT
|
|
|
+ /// 工序号 工序名 道口号
|
|
|
+ /// 3_3_1 预干区(入) 1-8
|
|
|
+ /// 3_3_2 烘干区(入) 1-8
|
|
|
+ /// 3_3_3 干坏区(入)
|
|
|
+ /// 3_2_1 毛坯区(入)
|
|
|
+ /// 3_2_2 精坯库(入)
|
|
|
+ /// 3_2_3 釉坯库(入)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="barcode">条码,多个条码以逗号分隔</param>
|
|
|
+ /// <param name="procedure_no">工序号</param>
|
|
|
+ /// <param name="road_no">道口号</param>
|
|
|
+ /// <param name="rack">货架号</param>
|
|
|
+ /// <param name="position">区域号</param>
|
|
|
+ /// <param name="procedure_in">工序计件</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public string AddWorkInfoHGS3_QR(
|
|
|
+ string barcode,
|
|
|
+ string procedure_no,
|
|
|
+ string road_no,
|
|
|
+ string rack,
|
|
|
+ string position,
|
|
|
+ int procedure_in = 1)
|
|
|
+ {
|
|
|
+ //修正参数,去掉多余的特殊字符
|
|
|
+ barcode = barCodeFix(barcode);
|
|
|
+ road_no = roadNoFix(road_no);
|
|
|
+
|
|
|
+ //返回JSON数据格式
|
|
|
+ JObject returnMessage = new JObject(
|
|
|
+ new JProperty("success", true),
|
|
|
+ new JProperty("message", "产品库位调度成功!"),
|
|
|
+ new JProperty("barcode", barcode)
|
|
|
+ );
|
|
|
+
|
|
|
+ string inputCode = $" barcode:{barcode} procedure_no:{procedure_no} road_no:{road_no} rack:{rack} position:{position} procedure_in:{procedure_in}";
|
|
|
+ string[] barCodes = barcode.Split(',');
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ #region 必须:读取设备对接点配置信息 TP_SYS_SMARTDEVICEPOINT
|
|
|
+ DataTable smartDevicePoint = getSmartDevicePoint(procedure_no, road_no);
|
|
|
+ if (smartDevicePoint.Rows.Count == 0)
|
|
|
+ {
|
|
|
+ OutputLog.TraceLog(LogPriority.Warning,
|
|
|
+ this.ToString(),
|
|
|
+ System.Reflection.MethodBase.GetCurrentMethod().Name,
|
|
|
+ inputCode + "设备对接工序点未配置",
|
|
|
+ LocalPath.LogExePath + "SmartDevice\\");
|
|
|
+ returnMessage["success"] = false;
|
|
|
+ returnMessage["message"] = "设备对接工序点未配置";
|
|
|
+ return returnMessage.ToString();
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 通用:procedure_in = 0 验证处理,支持多条码
|
|
|
+ if (procedure_in == 0)
|
|
|
+ {
|
|
|
+ string msg = "";
|
|
|
+ //标准验证是否可到达,支持多条码
|
|
|
+ msg = checkBarcode(Convert.ToInt32(smartDevicePoint.Rows[0]["PROCEDUREID"]), barCodes);
|
|
|
+ if (msg != "")
|
|
|
+ {
|
|
|
+ returnMessage["success"] = false;
|
|
|
+ returnMessage["message"] = msg;
|
|
|
+ return returnMessage.ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ returnMessage["success"] = true;
|
|
|
+ returnMessage["message"] = "产品库位调度验证成功!";
|
|
|
+ return returnMessage.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 通用:procedure_in = 1 计件处理,支持多条码
|
|
|
+ if (procedure_in == 1)
|
|
|
+ {
|
|
|
+ DataTable addWorkPiece = doAddWorkPiece(barCodes, smartDevicePoint);
|
|
|
+ string out_msg = addWorkPiece?.Rows[0]["out_errMsg"].ToString();
|
|
|
+ if (!string.IsNullOrWhiteSpace(out_msg))
|
|
|
+ {
|
|
|
+ OutputLog.TraceLog(LogPriority.Warning,
|
|
|
+ this.ToString(),
|
|
|
+ System.Reflection.MethodBase.GetCurrentMethod().Name,
|
|
|
+ inputCode + JsonHelper.ToJson(addWorkPiece),
|
|
|
+ LocalPath.LogExePath + "SmartDevice\\");
|
|
|
+ returnMessage["success"] = false;
|
|
|
+ returnMessage["message"] = out_msg;
|
|
|
+ return returnMessage.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ //返回正常结果
|
|
|
+ return returnMessage.ToString();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OutputLog.TraceLog(LogPriority.Error,
|
|
|
+ this.ToString(),
|
|
|
+ System.Reflection.MethodBase.GetCurrentMethod().Name,
|
|
|
+ inputCode + ex.ToString(),
|
|
|
+ LocalPath.LogExePath);
|
|
|
+ returnMessage["success"] = false;
|
|
|
+ returnMessage["message"] = "MES系统异常";
|
|
|
+ return returnMessage.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 通用私有方法
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 修正barcode,去掉barcode中的特殊字符 xuwei 2020-07-13
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="barCode"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private string barCodeFix(string barCode)
|
|
|
+ {
|
|
|
+ return barCode
|
|
|
+ .Replace("%0a", "")
|
|
|
+ .Replace("%0d", "")
|
|
|
+ .Replace("\n", "")
|
|
|
+ .Replace("\r", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 修正road_no值,为0时更新为1 xuwei 2020-07-13
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="road_no"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private string roadNoFix(string road_no)
|
|
|
+ {
|
|
|
+ if (road_no == "0")
|
|
|
+ return "1";
|
|
|
+ else
|
|
|
+ return road_no;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取产品注浆信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="barCode"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private Hashtable getGroutingDailyDetail(string barCode)
|
|
|
+ {
|
|
|
+ Hashtable ht = new Hashtable();
|
|
|
+ DataTable gdata = SmartDeviceLogic.GetGroutingdailydetail(barCode);
|
|
|
+ if (gdata.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ //产品等级 GOODSLEVELTYPEID
|
|
|
+ //1良品 2返工 3废品 4正品 5副品 6重烧 7次品 8损坯 9干补
|
|
|
+ //10丢失 11撤销装车 12撤销入窑 13不合格 14不合格(返) 15复检
|
|
|
+ string level = gdata.Rows[0]["goodsleveltypeid"].ToString();
|
|
|
+ switch (Convert.ToInt32(gdata.Rows[0]["goodsleveltypeid"]))
|
|
|
+ {
|
|
|
+ case 4:
|
|
|
+ case 5:
|
|
|
+ case 15:
|
|
|
+ level = "1";
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ level = "2";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //2020-08-03 默认值改为1
|
|
|
+ level = "1";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ //条码
|
|
|
+ ht["barcode"] = barCode;
|
|
|
+ //产品编码
|
|
|
+ ht["goodscode"] = gdata.Rows[0]["goodscode"];
|
|
|
+ //产品分级
|
|
|
+ ht["goodsleveltypeid"] = gdata.Rows[0]["goodsleveltypeid"];
|
|
|
+ //SKU码
|
|
|
+ ht["materialcode"] = gdata.Rows[0]["materialcode"];
|
|
|
+ //结果
|
|
|
+ ht["level"] = level;
|
|
|
+ //智能
|
|
|
+ ht["zhineng"] = (gdata.Rows[0]["goodstypeid"].ToString() == "18" || gdata.Rows[0]["goodstypeid"].ToString() == "19") ? "1" : "2";
|
|
|
+ //高压
|
|
|
+ ht["gaoya"] = (gdata.Rows[0]["goods_line_type"].ToString() == "1") ? "1" : "2";
|
|
|
+ //成型线号 xuwei add 2021-1-12
|
|
|
+ //ht["lineno"] = gdata.Rows[0]["GROUTINGLINENAME"];
|
|
|
+ ht["lineno"] = gdata.Rows[0]["GROUTINGLINECODE"];
|
|
|
+ }
|
|
|
+
|
|
|
+ return ht;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 验证条码是否可到达
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="conn"></param>
|
|
|
+ /// <param name="procedureId"></param>
|
|
|
+ /// <param name="barCode"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private string checkBarcode(int procedureId, string[] barCodes)
|
|
|
+ {
|
|
|
+ IDBConnection conn = ClsDbFactory.CreateDBConnection(Basics.DataAccess.DataBaseType.ORACLE, DataManager.ConnectionString);
|
|
|
+ string msg = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ conn.Open();
|
|
|
+ for (int i = 0; i < barCodes.Length; i++)
|
|
|
+ {
|
|
|
+ // 工序可以多次扫码,条码所在工序与验证工序一致时,直接通过
|
|
|
+ /*
|
|
|
+ string sql = "select t.flowprocedureid from tp_pm_inproduction t where t.barcode = :in_barcode";
|
|
|
+ OracleParameter[] para1 = new OracleParameter[]{
|
|
|
+ new OracleParameter(":in_barcode",OracleDbType.Varchar2,barCodes[i],ParameterDirection.Input),
|
|
|
+ };
|
|
|
+ string pid = conn.GetSqlResultToStr(sql, para1);
|
|
|
+ if (pid == procedureId + "")
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ OracleParameter[] para = new OracleParameter[]{
|
|
|
+ new OracleParameter("in_procedureid",OracleDbType.Int32,procedureId,ParameterDirection.Input),
|
|
|
+ new OracleParameter("in_barcode",OracleDbType.Varchar2,barCodes[i],ParameterDirection.Input),
|
|
|
+ new OracleParameter("out_errMsg",OracleDbType.Varchar2,2000,"",ParameterDirection.Output),
|
|
|
+ new OracleParameter("out_goodsID",OracleDbType.Int32,ParameterDirection.Output),
|
|
|
+ new OracleParameter("out_goodsCode",OracleDbType.Varchar2,50,"",ParameterDirection.Output),
|
|
|
+ new OracleParameter("out_goodsName",OracleDbType.Varchar2,50,"",ParameterDirection.Output),
|
|
|
+ new OracleParameter("out_groutingUserCode",OracleDbType.NVarchar2,50,null,ParameterDirection.Output),
|
|
|
+ new OracleParameter("out_errMsg_Status",OracleDbType.Varchar2,50,"",ParameterDirection.Output),
|
|
|
+ };
|
|
|
+ conn.ExecStoredProcedure("PRO_PM_CheckBarcode", para);
|
|
|
+ msg += para[2].Value.ToString().Replace("\\n\\r", "").Replace("null", "");
|
|
|
+ }
|
|
|
+ //conn.Close();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ throw ex;
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ conn.Close();
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取设备对接点配置数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="conn"></param>
|
|
|
+ /// <param name="procedureNo"></param>
|
|
|
+ /// <param name="roadNo"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private DataTable getSmartDevicePoint(string procedureNo, string roadNo)
|
|
|
+ {
|
|
|
+ using (IDataAccess conn = DataAccess.Create())
|
|
|
+ {
|
|
|
+ DataTable dt = conn.ExecuteDatatable(@"
|
|
|
+ SELECT
|
|
|
+ SDP.PROCEDUREID,
|
|
|
+ SDP.USERID,
|
|
|
+ U.USERCODE,
|
|
|
+ U.USERNAME
|
|
|
+ FROM
|
|
|
+ TP_SYS_SMARTDEVICEPOINT SDP
|
|
|
+ LEFT JOIN TP_MST_USER U ON U.USERID = SDP.USERID
|
|
|
+ WHERE
|
|
|
+ SDP.POINTCODE = @POINTCODE@
|
|
|
+ AND SDP.ROADNO = @ROADNO@
|
|
|
+ ",
|
|
|
+ new CDAParameter("POINTCODE", procedureNo),
|
|
|
+ new CDAParameter("ROADNO", roadNo)
|
|
|
+ );
|
|
|
+ return dt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通用计件方法
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="barCodes"></param>
|
|
|
+ /// <param name="smartDevicePoint"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private DataTable doAddWorkPiece(string[] barCodes, DataTable smartDevicePoint)
|
|
|
+ {
|
|
|
+ int procedureID = 0;
|
|
|
+ int.TryParse(smartDevicePoint.Rows[0]["ProcedureID"] + "", out procedureID);
|
|
|
+
|
|
|
+ if (procedureID > 0)
|
|
|
+ {
|
|
|
+ //初始条码信息
|
|
|
+ DataTable barcodeTable = new DataTable();
|
|
|
+ barcodeTable.Columns.Add("LogoID");
|
|
|
+ barcodeTable.Columns.Add("BarCode");
|
|
|
+ barcodeTable.Columns.Add("Remarks");
|
|
|
+ barcodeTable.Columns.Add("UserID");
|
|
|
+ barcodeTable.Columns.Add("UserCode");
|
|
|
+ barcodeTable.Columns.Add("UserName");
|
|
|
+ barcodeTable.Columns.Add("GroutingUserCode");
|
|
|
+
|
|
|
+ //初始化用户信息
|
|
|
+ SUserInfo sUserInfo = new SUserInfo();
|
|
|
+ sUserInfo.AccountID = 1;
|
|
|
+ sUserInfo.AccountCode = "dongke";
|
|
|
+ sUserInfo.UserID = Convert.ToInt32(smartDevicePoint.Rows[0]["UserID"]);
|
|
|
+ sUserInfo.UserCode = smartDevicePoint.Rows[0]["UserCode"].ToString();
|
|
|
+
|
|
|
+ // 工序可以多次扫码,条码所在工序与验证工序一致时,直接通过
|
|
|
+ using (IDataAccess conn = DataAccess.Create())
|
|
|
+ {
|
|
|
+ string sql = "select t.flowprocedureid from tp_pm_inproduction t where t.barcode = @barcode@";
|
|
|
+ //支持多条码
|
|
|
+ for (int i = 0; i < barCodes.Length; i++)
|
|
|
+ {
|
|
|
+ //条码为空的不计件 xuwei add 2022-04-13
|
|
|
+ if (barCodes[i].ToString() == "" || barCodes[i].ToString() == "0")
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //相同工序的不调用
|
|
|
+ string pid = conn.ExecuteScalar(sql, new CDAParameter("barcode", barCodes[i])) + "";
|
|
|
+ if (pid == procedureID + "")
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //验证不通过的不调用 xuwei add 2022-04-13
|
|
|
+ string[] temp = new string[1];
|
|
|
+ temp[0] = barCodes[i];
|
|
|
+ string msg = checkBarcode(procedureID, temp);
|
|
|
+ if (msg != "")
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //重复条码不要加进去,处在首节点会报错
|
|
|
+ barcodeTable.PrimaryKey = new DataColumn[] { barcodeTable.Columns["BarCode"] };
|
|
|
+ if (barcodeTable.Rows.Contains(barCodes[i]))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //记录可以计件的条码
|
|
|
+ DataRow dr = barcodeTable.NewRow();
|
|
|
+ dr["BarCode"] = barCodes[i];
|
|
|
+ dr["UserID"] = Convert.ToInt32(smartDevicePoint.Rows[0]["UserID"]);
|
|
|
+ dr["UserCode"] = smartDevicePoint.Rows[0]["UserCode"] + "";
|
|
|
+ dr["UserName"] = smartDevicePoint.Rows[0]["UserName"] + "";
|
|
|
+
|
|
|
+ //fly add 2022-05-10 交坯节点必须有这个参数
|
|
|
+ dr["GroutingUserCode"] = conn.ExecuteScalar(@"
|
|
|
+ SELECT
|
|
|
+ P.USERCODE
|
|
|
+ FROM
|
|
|
+ TP_PM_GROUTINGDAILYDETAIL P
|
|
|
+ WHERE
|
|
|
+ P.BARCODE = @barcode@
|
|
|
+ AND P.VALUEFLAG = '1'
|
|
|
+ ",
|
|
|
+ new CDAParameter("barcode", barCodes[i])
|
|
|
+ );
|
|
|
+
|
|
|
+ barcodeTable.Rows.Add(dr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (barcodeTable.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ //调用通用计件方法
|
|
|
+ ProcedureEntity procedureInfo = null;
|
|
|
+ return PMModuleLogicDAL.AddWorkPiece(procedureID, barcodeTable, sUserInfo, out procedureInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|