178 lines
7.9 KiB
C#
178 lines
7.9 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
|
|
namespace WebApi
|
|
{
|
|
public class AnalysisMsg
|
|
{
|
|
/// <summary>
|
|
/// UUID生成
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string UuidUtil()
|
|
{
|
|
string result = Guid.NewGuid().ToString();
|
|
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 人员基础数据下发(OK)
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static string product(string url, [FromBody] JObject jobj)
|
|
{
|
|
var result = new msgResHeader();
|
|
result.Code = "200";
|
|
result.Message = "";
|
|
|
|
string errorMessage = "";
|
|
string parentID = "";
|
|
int AID = -1;
|
|
|
|
if (jobj == null)
|
|
{
|
|
result.Message = "参数格式不正确!";
|
|
result.Code = "500";
|
|
string retString1 = JsonConvert.SerializeObject(result);
|
|
MyLog4Net.MyLogHelper.Info("装配信息res:", retString1);
|
|
return retString1;
|
|
}
|
|
int isError = 0;
|
|
string str = jobj.ToString();
|
|
try
|
|
{
|
|
//存储日志
|
|
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
|
//Event_MOM_Log_Insert,@创建时间,@内容
|
|
var param1 = new SqlParameter[] {
|
|
new SqlParameter("@接口地址",url),
|
|
new SqlParameter("@接口类型",2), // 1. 主动调用接口 2. 被调用接口
|
|
new SqlParameter("@请求内容",str),
|
|
new SqlParameter("@请求时间",CreateTime)
|
|
};
|
|
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_请求记录", ConnectionString, ref param1, out DataTable dt, out errorMessage);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
AID = Convert.ToInt32(dt.Rows[0]["AID"]);
|
|
}
|
|
// 解析订单内容,存储数据库,根据实际业务来写
|
|
IPC_product productDataList = JsonConvert.DeserializeObject<IPC_product>(str);
|
|
List<IPC_product_AssemblyInformation> product_AssemblyInformation = productDataList.AssemblyInformation;
|
|
|
|
|
|
foreach (var personnelBaseData in personnelBaseDataList)
|
|
{
|
|
var parsingParam = new SqlParameter[] {
|
|
new SqlParameter("@所属公司",personnelBaseData.company),
|
|
new SqlParameter("@所属工厂",personnelBaseData.facility),
|
|
new SqlParameter("@所属部门",personnelBaseData.department),
|
|
new SqlParameter("@人员编号",personnelBaseData.employeeNo),
|
|
new SqlParameter("@人员名称",personnelBaseData.employeeName),
|
|
new SqlParameter("@电话",personnelBaseData.phone),
|
|
new SqlParameter("@邮箱",personnelBaseData.mail),
|
|
new SqlParameter("@班组",personnelBaseData.shift)
|
|
};
|
|
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_接收_人员基础数据_增加", Program.ConnectionString, ref parsingParam, out DataTable parsingDt, out errorMessage);
|
|
if (errorMessage != "")
|
|
{
|
|
isError = 1;
|
|
}
|
|
if (parsingDt.Rows.Count > 0)
|
|
{
|
|
if (Convert.ToInt32(parsingDt.Rows[0]["result"]) == 1)
|
|
{
|
|
parentID = personnelBaseData.employeeNo;
|
|
// 权限工位
|
|
List<PersonnelBaseWorkStationData> workStationList = personnelBaseData.workStationList;
|
|
if (workStationList != null)
|
|
{
|
|
foreach (PersonnelBaseWorkStationData item in workStationList)
|
|
{
|
|
var parsingParam2 = new SqlParameter[] {
|
|
new SqlParameter("@人员编号",parentID),
|
|
new SqlParameter("@产线编号",item.productionLineNo),
|
|
new SqlParameter("@工位编号",item.workStation),
|
|
};
|
|
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_接收_人员基础数据_权限工位_增加", Program.ConnectionString, ref parsingParam2, out DataTable parsingDt2, out errorMessage);
|
|
if (errorMessage != "")
|
|
{
|
|
isError = 1;
|
|
}
|
|
}
|
|
}
|
|
// 技能
|
|
List<PersonnelBaseSkillListData> skillList = personnelBaseData.skillList;
|
|
if (skillList != null)
|
|
{
|
|
foreach (PersonnelBaseSkillListData item in skillList)
|
|
{
|
|
var parsingParam2 = new SqlParameter[] {
|
|
new SqlParameter("@人员编号",parentID),
|
|
new SqlParameter("@技能编号",item.skillNo),
|
|
new SqlParameter("@技能名称",item.skillName),
|
|
};
|
|
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_接收_人员基础数据_技能_增加", Program.ConnectionString, ref parsingParam2, out DataTable parsingDt2, out errorMessage);
|
|
if (errorMessage != "")
|
|
{
|
|
isError = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 返回响应结果
|
|
// 包头
|
|
if (errorMessage != "")
|
|
{
|
|
isError = 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
isError = 1;
|
|
}
|
|
}
|
|
}
|
|
if (isError == 1)
|
|
{
|
|
result.msg = "存储过程调用失败!";
|
|
result.code = "501";
|
|
result.returnData = "ERROR";
|
|
}
|
|
|
|
//响应结果
|
|
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
|
var resParam = new SqlParameter[] {
|
|
new SqlParameter("@AID",AID),
|
|
new SqlParameter("@响应时间",CreateTime),
|
|
new SqlParameter("@响应内容",JsonConvert.SerializeObject(result))
|
|
};
|
|
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_响应记录", Program.ConnectionString, ref resParam, out errorMessage);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
AID = Convert.ToInt32(dt.Rows[0]["AID"]);
|
|
}
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
result.code = "501";
|
|
result.msg = err.Message;
|
|
result.returnData = "ERROR";
|
|
}
|
|
|
|
string retString = JsonConvert.SerializeObject(result);
|
|
MyLog4Net.MyLogHelper.Info("人员基础数据下发res:", retString);
|
|
return retString;
|
|
}
|
|
|
|
}
|
|
}
|