using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Pub_Class; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Web.Http; using WebAPI.Models; using Tea; using AlibabaCloud.SDK.Dingtalkyida_1_0.Models; using AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models; using DingTalk.Api.Request; using DingTalk.Api; using DingTalk.Api.Response; using System.Globalization; using System.Linq; using AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models; using System.Text.RegularExpressions; using System.Net.Http; using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using System.Text; using System.Security.Cryptography; using System.Net.Http.Headers; using System.Web; using Kingdee.BOS.WebApi.Client; namespace WebAPI.Controllers { #region 模型类 #region 服务地址返回类 public class ServerAddressResponse { public string res; public string msg; public ServerAddressResponse_Data data; } public class ServerAddressResponse_Data { public string gofServerAdd; } #endregion #region 验证码返回类 public class VerificationCodeResponse { public string res; public string msg; public VerificationCodeResponse_Data data; } public class VerificationCodeResponse_Data { public string VerificationCode; } #endregion #region Token返回类 public class TokenResponse { public string res; public string msg; public TokenResponse_Data data; } public class TokenResponse_Data { public string key; } #endregion #region 产品档案 #region 物料列表 public class MaterListResponse { public string code; public string msg; public MaterListResponse_Data data; } public class MaterListResponse_Data { public MaterListResponse_Data_Product[] product; public string updateTime; public string totalNumber; public string totalPage; public string pageIndex; } public class MaterListResponse_Data_Product { public string productName; //产品名称 public string productId; //产品ID public string partnum; //产品编号 public string cycleTime; //循环周期 public string spec; //规格型号 public string weight; //产品重量 public string headWeight; //料头重量 public string colorName; //颜色名称 public string comments; // 备注 public string lastUpdateTime; //修改日期 } #endregion #region 物料详细信息 public class MaterDetailResponse { public string code; public string msg; public MaterDetailResponse_Data data; } public class MaterDetailResponse_Data { public MaterDetailResponse_Data_Detail details; public string updateTime; //更新时间 public string totalNumber; public string totalPage; public string pageIndex; } public class MaterDetailResponse_Data_Detail { public string productName; //产品名称 public string partNum; //产品编号 public string weight; //产品重量 public string headWeight; //料头重量 public string cycleTime; //循环周期 public string comments; // 备注 public string materialNo; //材料编号 public string cpNo; //色粉编号 public string cpName; //色粉名称 public string color; //颜色ID public string colorName; //颜色名称 public string unit; //单位 public string partId; //产品ID public string productType; //产品类型 public string processWay; //生产进度统计方式:0:数量 1:时长 public string spec; //规格型号 public string option1; //自定义字段1:用于记录金蝶云 修改时间 } #endregion #region 新增产品信息 public class MaterialResponse { public string code; public string msg; public MaterialResponse_Data data; public string productId; } public class MaterialResponse_Data { public string partId; //产品ID public string productName; //产品名称 public string partNum; //产品编码 public string sepc; //规格型号 public string weight; //产品重量 public string comments; //备注 public string cycleTime; //周期 public string headWeight; //料头重量 public string createDate; //创建日期 public string color; //颜色ID public string colorName; //颜色名称 public string pieceWage; //单价 } public class Material { public string key; //密钥 public string productName; //产品名称 public string partNum; //产品编码 public string sepc; //规格型号 public string weight; //产品重量 public string headWeight; //料头重量 public string cycleTime; //周期 public string flightsPartnum; public string comments; //备注 public string colorName; //颜色名称 public string pieceWage; //单价 public string unit; //单位 public string systemType; //系统类型(IMM:注塑 ,CNC:精加工),不传默认注塑 public string tdDocNo; //工艺路线编号,多个使用,进行分开(CNC) public string progressWay; //生产进度统计方式:0:数量 1:时长(CNC) public string groupId; //分组id public string option1; //自定义字段1:用于记录金蝶云 修改时间 } #endregion #region 编辑产品信息 public class MaterialEditResponse { public string code; public string msg; public MaterialEditReponse_Data data; public string productId; } public class MaterialEditReponse_Data { public string partId; //产品ID public string partNum; //产品编码 public string productName; //产品名称 public string sepc; //规格型号 public string weight; //产品重量 public string comments; //备注 public string cycleTime; //周期 public string headWeight; //料头重量 public string lastUpdateTime; //最后更新时间 public string productType; //产品类型 public string createDate; //创建日期 public string colorName; //颜色名称 public string unit; //单位 public string systemType; //系统类型 } public class MaterialEdit { public string key; //密钥 public string productId; //产品ID public string productName; //产品名称 public string partNum; //产品编码 public string sepc; //规格型号 public string weight; //产品重量 public string headWeight; //料头重量 public string cycleTime; //周期 public string flightsPartnum; public string comments; //备注 public string colorName; //颜色名称 public string pieceWage; //单价 public string unit; //单位 public string systemType; //系统类型(IMM:注塑 ,CNC:精加工),不传默认注塑 public string tdDocNo; //工艺路线编号,多个使用,进行分开(CNC) public string progressWay; //生产进度统计方式:0:数量 1:时长(CNC) public string groupId; //分组id public string option1; //自定义字段1:用于记录金蝶云 修改时间 } #endregion #endregion #region 生产订单 #region 生产订单列表 public class ICMOListResponse { public string code; public string msg; public ICMOListResponse_Data data; } public class ICMOListResponse_Data { public ICMOListResponse_Data_Plan[] plan; public string pageIndex; public string pageCount; } public class ICMOListResponse_Data_Plan { public string planId; //计划单ID public string leave_qty; //剩余数量 public string productName; //产品名称 public string planNumber; //计划单号 public string planQty; //计划数量 public string taskNo; //任务单号 public string materialId; //材料编号 public string materialName; //材料名称 public string cpId; //色粉编号 public string cpName; //色粉名称 public string partId; //产品id public string partNum; //产品编号 public string qty; //数量 public string allotQty; //分配数量 public string planStartDate; //计划开始时间 public string planFinishDate; //计划完成时间 public string comments; //备注 public string createDate; //创建日期 public string spec; //规格型号 public string urgent; //是否紧急 public string partnum; //产品编号 public string cycleTime; //循环周期 } #endregion #region 生产订单详细信息 public class ICMODetailResponse { public string code; public string msg; public ICMODetailResponse_Data[] data; } public class ICMODetailResponse_Data { public string planProductName; //产品名称 public string planNumber; //计划单号 public string planQty; //计划数量 public string planStartTime; //计划开始时间 public string planEndTime; //计划完成时间 public string allottedQty; //分配数量 public string planProductId; //产品id public string finishPercentage; //完成进度 public string colorName; //颜色 public string color; //颜色id public string levQty; //剩余数量 public string planId; //计划单id public string createUserId; //创建人 public string createUserName; //创建人名称 public string customerName; //客户名称 public string comments; //备注 public string productName; //产品名称 public string partNum; //产品编号(partNum或者productId二选一) public string urgent; //是否紧急 1:紧急 public string productRemark; //产品备注 public string option1; //自定义字段1:用于记录金蝶云 修改时间 } #endregion #region 新增生产订单信息 public class ICMOResponse { public string code; public string msg; public ICMOResponse_Data data; } public class ICMOResponse_Data { public string planId; //计划单id public string companyId; //公司的id public string planNo; //计划单号 public string partId; //产品ID public string qty; //计划数量 public string customerName; //客户名称 public string planStartTime; //计划开始时间 public string planFinishDate; //计划完成时间 public string allotQty; //分配数量 public string finishQty; //完成数量 public string comments; //备注 public string createDate; //创建日期 public string createUserId; //创建人 public string createUserName; //创建人名称 public string colorName; //颜色 public string color; //颜色id public string productName; //产品名称 public string partNum; //产品编号 public string status; //状态 public string urgent; //是否紧急 1:紧急 public string option1; //自定义字段1:用于记录金蝶云 修改时间 } public class ICMO { public string key; //密钥 public string planNumber; //计划单号 public string planQty; //计划数量 public string partNum; //产品编号 public string planStartDate; //计划开始时间 public string planEndDate; //计划结束时间 public string comments; //备注 public string customerName; //客户名称 public string colorName; //颜色名称 public string spec; //型号规格 public string cpNo; //色粉编号 public string cpName; //色粉名称 public string materialNo; //材料编号 public string materialName; //材料名称 public string orderNumber; //订单编号 public string option1; //自定义字段1:用于记录金蝶云 修改时间 } #endregion #region 编辑生产订单信息 public class ICMOEditResponse { public string code; public string msg; public ICMOEditReponse_Data data; } public class ICMOEditReponse_Data { public string planId; //计划单id //public string companyId; //公司的id public string planNo; //计划单号 public string partId; //产品ID public string qty; //计划数量 public string customerName; //客户名称 public string planStartTime; //计划开始时间 public string planFinishDate; //计划完成时间 public string allotQty; //分配数量 public string finishQty; //完成数量 public string comments; //备注 public string createDate; //创建日期 public string createUserId; //创建人 public string createUserName; //创建人名称 public string colorName; //颜色 public string color; //颜色id public string productName; //产品名称 public string partNum; //产品编号 public string status; //状态 public string urgent; //是否紧急 1:紧急 public string option1; //自定义字段1:用于记录金蝶云 修改时间 } public class ICMOEdit { public string key; //密钥 public string planId; //计划单ID public string planNumber; //计划单号 public string planQty; //计划数量 public string partNum; //产品编号 public string planStartDate; //计划开始时间 public string planEndDate; //计划结束时间 public string comments; //备注 public string customerName; //客户名称 public string colorName; //颜色名称 public string spec; //型号规格 public string cpNo; //色粉编号 public string cpName; //色粉名称 public string materialNo; //材料编号 public string materialName; //材料名称 public string orderNumber; //订单编号 public string option1; //自定义字段1:用于记录金蝶云 修改时间 } #endregion #endregion #region 生产汇报 #region 已审核的报工记录信息列表 public class ICMOReportListResponse { public string code; public string msg; public List data; } public class ICMOReportListResponse_Data { public List data; public string pageIndex; public string pageCount; } public class ICMOReportListResponse_Data_Data { public string produceReportId; //报工记录id public string machineName; //设备名称 public string macId; //设备id public string productName; //产品名称 public string partId; //产品id public string workTime; //工作时间 public string tour; //班次 public string productNum; //生产数据 public string standardNum; //报合格数量 public string defectiveNum; //次品数量 public string remark; //备注 public string materialId; // public string materialName; //材料名称 public string materialNo; //材料编号 public string producePerson; //生产人员 public string producePersonId; //生产人员id public string producePersonCode; //生产人员code public string planNo; //计划单号 public string taskNo; //任务单号 public string partNum; //产品编号 public string produceRecordId; //生产记录的id public string moldNo; //模具编号 public string reportDate; //报工日期 public string reportUser; //报工人员 public string reportUserCode; //报工人员编码 public string auditUser; //审核人 public string auditUserCode; //审核人员编号 public string auditDate; //审核日期 public string moldName; //模具名称 public string defectiveReasonName; //次品明细信息 public string boxCodes; //箱码 public string tourGroupName; //班组 } #endregion #region 生产汇报详细信息 public class ICMOReportDetailResponse { public string code; public string msg; public List data; } public class ICMOReportDetailResponse_Data { public string produceReportId; //报工记录id public string machineName; //设备名称 public string macId; //设备id public string productName; //产品名称 public string partId; //产品id public string workTime; //工作时间 public string tour; //班次 public string productNum; //生产数据 public string standardNum; //报合格数量 public string defectiveNum; //次品数量 public string stockInputNum; public string remark; //备注 /* public string materialId; */ // public string materialName; //材料名称 public string materialNo; //材料编号 public string producePerson; //生产人员 public string producePersonId; //生产人员id public string producePersonCode; //生产人员code public string planNo; //计划单号 public string taskNo; //任务单号 public string partNum; //产品编号 public string produceRecordId; //生产记录的id public string moldNo; //模具编号 public string reportDate; //报工日期 public string reportUser; //报工人员 public string reportUserCode; //报工人员编码 public string auditUser; //审核人 public string auditUserCode; //审核人员编号 public string auditDate; //审核日期 public string piceWage; //单价 public string moldName; //模具名称 public List defectiveReasonNameList; public List defectiveNumList; public string tourGroupName; //班组 public List boxs; } public class ICMOReportDetailResponse_Data_Box { public string boxCode; //箱码 public string boxActQty; //数量 } #endregion #endregion #endregion #region 小诸葛数据同步 public class XZG_DataSynchronizationController : ApiController { //获取系统参数 Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); public DBUtility.ClsPub.Enum_BillStatus BillStatus; private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; #region 小诸葛数据同步密钥 string APPID = "1f2e019a-ff51-f115-ce59-205606c72853"; string APPPWD = "YYLM01A"; #endregion #region erp数据库名称 string erpDatabaseName = "AIS20210811135644.."; #endregion #region 获取服务地址 public async Task getServerAddressAsync() { //请求地址 string url = "https://js1.gomake.cn/kq_highnet_gof_connect/gof1.0/authorize"; //请求参数 Dictionary queryParams = new Dictionary { {"appid", APPID}, {"ver", "1.0"}, {"seq",DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) + "" } }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 ServerAddressResponse serverAddressResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); //获取对象中的数据 string res = serverAddressResponse.data.gofServerAdd; return res; } #endregion #region 获取验证码 public async Task getVerificationCodeAsync() { //请求地址 string url = await getServerAddressAsync() + "/gof1.0/verify"; //请求参数 Dictionary queryParams = new Dictionary { {"appid", APPID}, {"ver", "1.0"}, {"seq",DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) + "" } }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 VerificationCodeResponse verificationCodeResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); //获取对象中的数据 string res = verificationCodeResponse.data.VerificationCode; return res; } #endregion #region 获取Token public async Task getTokenAsync() { //请求地址 string url = await getServerAddressAsync() + "/gof1.0/key"; string verificationCode = await getVerificationCodeAsync(); //请求参数 Dictionary queryParams = new Dictionary { {"appid", APPID}, {"ver", "1.0"}, {"seq",DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) + "" }, {"pwd", DefinedRequestSendMethod.GetMD5( DefinedRequestSendMethod.GetMD5(verificationCode) + DefinedRequestSendMethod.GetMD5(APPPWD))} }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 TokenResponse tokenResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); //获取对象中的数据 string res = tokenResponse.data.key; return res; } #endregion #region 数据同步 #region 数据同步-汇总全部同步 public async Task dataAnsy() { try { //产品档案同步(erp->小诸葛) await productInfoSyncFromERPToXZG(); //生产订单同步(erp->小诸葛) await icmoInfoSyncFromERPToXZG(); //生产汇报单同步(小诸葛->erp) await icmoReportInfoSyncFromXZGToERP(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "同步成功!"; objJsonResult.data = null; return objJsonResult; } catch(Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "同步失败!" + e.Message; objJsonResult.data = null; return objJsonResult; } } #endregion #endregion #region 产品档案 #region 获取产品列表信息 public async Task getMaterListAsync() { //请求地址 string url = await getServerAddressAsync() + "/v2/GET/getProductAll"; string token = await getTokenAsync(); //请求参数 Dictionary queryParams = new Dictionary { {"key", token}, {"page", "1"}, {"sidx", "lastUpdateTime"}, {"sord", "desc"}, {"systemType","IMM" } }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 MaterListResponse materListResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return materListResponse; } #endregion #region 获取产品详细信息 public async Task getMaterDetailAsync(string url, string key, string partNum) { //请求地址 url = url + "/v2/GET/getProductDetails"; //请求参数 Dictionary queryParams = new Dictionary { {"key", key}, {"partNum",partNum } }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 MaterDetailResponse materDetailResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return materDetailResponse; } #endregion #region 新增产品 public async Task getAddMaterAsync(string url, Material material) { //请求地址 url = url + "/v2/POST/AddProduct"; //POST请求参数 Dictionary queryParams = new Dictionary { {"key", DBUtility.ClsPub.isStrNull(material.key)}, {"productName", DBUtility.ClsPub.isStrNull(material.productName)}, {"partNum",DBUtility.ClsPub.isStrNull(material.partNum)}, {"sepc", DBUtility.ClsPub.isStrNull(material.sepc)}, {"weight", DBUtility.ClsPub.isStrNull(material.weight)}, {"headWeight", DBUtility.ClsPub.isStrNull(material.headWeight)}, {"cycletime", DBUtility.ClsPub.isStrNull(material.cycleTime)}, {"fightsPartnum", DBUtility.ClsPub.isStrNull(material.flightsPartnum)}, {"comments", DBUtility.ClsPub.isStrNull(material.comments)}, {"colorName", DBUtility.ClsPub.isStrNull(material.colorName)}, {"pieceWage", DBUtility.ClsPub.isStrNull(material.pieceWage)}, {"unit", DBUtility.ClsPub.isStrNull(material.unit)}, {"systemType", DBUtility.ClsPub.isStrNull(material.systemType)}, {"tdDocNo", DBUtility.ClsPub.isStrNull(material.tdDocNo)}, {"progressWay", DBUtility.ClsPub.isStrNull(material.progressWay)}, {"groupId", DBUtility.ClsPub.isStrNull(material.groupId)}, {"option1", DBUtility.ClsPub.isStrNull(material.option1)} }; //POST请求Body数据 var postData = new { }; string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData); //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByPOSTRequest(url, queryParams, json); //将字符串转换为对象 MaterialResponse materialResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return materialResponse; } #endregion #region 编辑产品 public async Task getAddMaterEditAsync(string url, MaterialEdit material) { //请求地址 url = url + "/v2/POST/UpdateProduct"; //POST请求参数 Dictionary queryParams = new Dictionary { {"key", DBUtility.ClsPub.isStrNull(material.key)}, {"productId", DBUtility.ClsPub.isStrNull(material.productId)}, {"productName", DBUtility.ClsPub.isStrNull(material.productName)}, {"partNum",DBUtility.ClsPub.isStrNull(material.partNum)}, {"cycletime", DBUtility.ClsPub.isStrNull(material.cycleTime)}, {"sepc", DBUtility.ClsPub.isStrNull(material.sepc)}, {"weight", DBUtility.ClsPub.isStrNull(material.weight)}, {"headWeight", DBUtility.ClsPub.isStrNull(material.headWeight)}, {"fightsPartnum", DBUtility.ClsPub.isStrNull(material.flightsPartnum)}, {"comments", DBUtility.ClsPub.isStrNull(material.comments)}, {"colorName", DBUtility.ClsPub.isStrNull(material.colorName)}, {"unit", DBUtility.ClsPub.isStrNull(material.unit)}, {"systemType", DBUtility.ClsPub.isStrNull(material.systemType)}, {"tdDocNo", DBUtility.ClsPub.isStrNull(material.tdDocNo)}, {"progressWay", DBUtility.ClsPub.isStrNull(material.progressWay)}, {"groupId", DBUtility.ClsPub.isStrNull(material.groupId)}, {"option1", DBUtility.ClsPub.isStrNull(material.option1)} }; //POST请求Body数据 var postData = new { }; string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData); //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByPOSTRequest(url, queryParams, json); //将字符串转换为对象 MaterialEditResponse materialEditResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return materialEditResponse; } #endregion #region 产品档案定时同步_从ERP到小诸葛 public async Task productInfoSyncFromERPToXZG() { try { //请求地址 string url = await getServerAddressAsync(); string token = await getTokenAsync(); //获取金蝶云物料数据 List materials = new List(); string sql = @"select a.FNUMBER HNumber ,l.FNAME HName ,isnull(l.FSPECIFICATION,'') HModel ,'CLD-ERP导入' HRemark ,unit.FNAME HUnitName ,convert(varchar(100),a.FMODIFYDATE,20) HUpdateDate from AIS20210811135644..T_BD_MATERIAL a with(nolock) inner join AIS20210811135644..T_BD_MATERIAL_L l with(nolock) on a.FMATERIALID=l.FMATERIALID inner join AIS20210811135644..T_BD_MATERIALSTOCK s with(nolock) on a.FMATERIALID=s.FMATERIALID inner join AIS20210811135644..T_BD_Unit_L unit with(nolock) on isnull(s.FSTOREUNITID,0) = unit.FUNITID Where l.FLOCALEID=2052 and unit.FLOCALEID = 2052 and a.FFORBIDSTATUS='A' and ( convert(varchar(100),a.FCREATEDATE,23) >= convert(varchar(100),DATEADD(day,-7,getdate()),23) or convert(varchar(100),a.FMODIFYDATE,23) >= convert(varchar(100),DATEADD(day,-7,getdate()),23) )"; DataSet ds = oCN.RunProcReturn(sql, "AIS20210811135644..T_BD_MATERIAL"); if (ds != null && ds.Tables.Count > 0) { for(int i = 0; i < ds.Tables[0].Rows.Count; i++) { Material material = new Material(); material.key = token; material.productName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HName"]); material.partNum = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HNumber"]); material.sepc = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HModel"]); //material.weight = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); //material.headWeight = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); material.cycleTime = "1"; //material.flightsPartnum = ""; material.comments = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HRemark"]); //material.colorName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); //material.pieceWage = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); material.unit = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HUnitName"]); material.systemType = "IMM"; material.tdDocNo = ""; //material.progressWay = "0"; //material.groupId = ""; material.option1 = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HUpdateDate"]); materials.Add(material); } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "金蝶云物料数据获取失败!"; objJsonResult.data = null; } //判断物料列表中的数据是否在小诸葛中已经存在且已经是最新数据。如果小诸葛中不存在则同步到小诸葛。如果小诸葛中存在,则覆盖数据。 string errMsg = ""; List materials_waitSync = new List(); for(int i = 0; i < materials.Count; i++) { string HMaterNumber = materials[i].partNum; MaterDetailResponse materDetailResponse = await getMaterDetailAsync(url, token, HMaterNumber); if (materDetailResponse.code == "1") { if (materDetailResponse.data.details.option1 != materials[i].option1) { MaterialEdit materialEdit = new MaterialEdit(); materialEdit.key = token; materialEdit.productId = materDetailResponse.data.details.partId; materialEdit.productName = DBUtility.ClsPub.isStrNull(materials[i].productName); materialEdit.partNum = DBUtility.ClsPub.isStrNull(materials[i].partNum); materialEdit.sepc = DBUtility.ClsPub.isStrNull(materials[i].sepc); //materialEdit.weight = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); //materialEdit.headWeight = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); materialEdit.cycleTime = "1"; //materialEdit.flightsPartnum = ""; materialEdit.comments = DBUtility.ClsPub.isStrNull(materials[i].comments); //materialEdit.colorName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); //materialEdit.pieceWage = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i][""]); materialEdit.unit = DBUtility.ClsPub.isStrNull(materials[i].unit); materialEdit.systemType = "IMM"; materialEdit.tdDocNo = ""; //materialEdit.progressWay = ""; //materialEdit.groupId = ""; materialEdit.option1 = DBUtility.ClsPub.isStrNull(materials[i].option1); MaterialEditResponse materialEditResponse = await getAddMaterEditAsync(url, materialEdit); if (materialEditResponse.code == "0") { errMsg += "【" + HMaterNumber + "】" + materialEditResponse.msg + ";"; } } } else { MaterialResponse materialResponse = await getAddMaterAsync(url, materials[i]); if (materialResponse.code == "0") { errMsg += "【" + HMaterNumber + "】" + materialResponse.msg + ";"; } } } if (errMsg.Length > 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "同步失败!" + errMsg; objJsonResult.data = null; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "同步成功!" + errMsg; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "同步失败!" + e.Message; objJsonResult.data = null; return objJsonResult; } } #endregion #endregion #region 生产订单 #region 获取生产订单列表信息 public async Task getICMOListAsync() { //请求地址 string url = await getServerAddressAsync() + "/v2/GET/getPlanOrder"; string token = await getTokenAsync(); //请求参数 Dictionary queryParams = new Dictionary { {"key", token}, {"indexPage", "1"}, {"planStartDate", DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}, {"planEndDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 ICMOListResponse icmoListResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return icmoListResponse; } #endregion #region 获取生产订单详细信息 public async Task getICMODetailAsync(string url, string key, string planNum) { //请求地址 url = url + "/v2/GET/getPlanOrderDetail"; //请求参数 Dictionary queryParams = new Dictionary { {"key", key}, {"planNum",planNum } }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 ICMODetailResponse icmoDetailResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return icmoDetailResponse; } #endregion #region 新增生产订单 public async Task getAddICMOAsync(string url, ICMO icmo) { //请求地址 url = url + "/v2/POST/addPlan"; //POST请求参数 Dictionary queryParams = new Dictionary { {"key", DBUtility.ClsPub.isStrNull(icmo.key)}, {"planNumber", DBUtility.ClsPub.isStrNull(icmo.planNumber)}, {"planQty",DBUtility.ClsPub.isStrNull(icmo.planQty)}, {"partNum", DBUtility.ClsPub.isStrNull(icmo.partNum)}, {"planStartDate", DBUtility.ClsPub.isStrNull(icmo.planStartDate)}, {"planEndDate", DBUtility.ClsPub.isStrNull(icmo.planEndDate)}, {"comments", DBUtility.ClsPub.isStrNull(icmo.comments)}, {"customerName", DBUtility.ClsPub.isStrNull(icmo.customerName)}, {"colorName", DBUtility.ClsPub.isStrNull(icmo.colorName)}, {"spec", DBUtility.ClsPub.isStrNull(icmo.spec)}, {"cpNo", DBUtility.ClsPub.isStrNull(icmo.cpNo)}, {"cpName", DBUtility.ClsPub.isStrNull(icmo.cpName)}, {"materialNo", DBUtility.ClsPub.isStrNull(icmo.materialNo)}, {"materialName", DBUtility.ClsPub.isStrNull(icmo.materialName)}, {"orderNumber", DBUtility.ClsPub.isStrNull(icmo.orderNumber)}, {"option1", DBUtility.ClsPub.isStrNull(icmo.option1)} }; //POST请求Body数据 var postData = new { }; string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData); //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByPOSTRequest(url, queryParams, json); //将字符串转换为对象 ICMOResponse icmoResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return icmoResponse; } #endregion #region 编辑生产订单 public async Task getAddICMOEditAsync(string url, ICMOEdit icmo) { //请求地址 url = url + "/v2/POST/updatePlanInfo"; //POST请求参数 Dictionary queryParams = new Dictionary { {"key", DBUtility.ClsPub.isStrNull(icmo.key)}, {"planId", DBUtility.ClsPub.isStrNull(icmo.planId)}, {"planNumber", DBUtility.ClsPub.isStrNull(icmo.planNumber)}, {"planQty",DBUtility.ClsPub.isStrNull(icmo.planQty)}, {"partNum", DBUtility.ClsPub.isStrNull(icmo.partNum)}, {"planStartDate", DBUtility.ClsPub.isStrNull(icmo.planStartDate)}, {"planEndDate", DBUtility.ClsPub.isStrNull(icmo.planEndDate)}, {"comments", DBUtility.ClsPub.isStrNull(icmo.comments)}, {"customerName", DBUtility.ClsPub.isStrNull(icmo.customerName)}, {"colorName", DBUtility.ClsPub.isStrNull(icmo.colorName)}, {"spec", DBUtility.ClsPub.isStrNull(icmo.spec)}, {"cpNo", DBUtility.ClsPub.isStrNull(icmo.cpNo)}, {"cpName", DBUtility.ClsPub.isStrNull(icmo.cpName)}, {"materialNo", DBUtility.ClsPub.isStrNull(icmo.materialNo)}, {"materialName", DBUtility.ClsPub.isStrNull(icmo.materialName)}, {"orderNumber", DBUtility.ClsPub.isStrNull(icmo.orderNumber)}, {"option1", DBUtility.ClsPub.isStrNull(icmo.option1)} }; //POST请求Body数据 var postData = new { }; string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData); //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByPOSTRequest(url, queryParams, json); //将字符串转换为对象 ICMOEditResponse icmoEditResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return icmoEditResponse; } #endregion #region 生产订单定时同步_从ERP到小诸葛 public async Task icmoInfoSyncFromERPToXZG() { try { //请求地址 string url = await getServerAddressAsync(); string token = await getTokenAsync(); //获取金蝶云生产订单数据 List icmos = new List(); string sql = @"select cast(a.FBILLNO as varchar(100)) + '_' + cast(b.FSEQ as varchar(10)) + '_' + cast(b.FENTRYID as varchar(10)) 计划单号 ,cast(b.FQTY as int) 计划数量 ,m.FNUMBER 产品编号 ,convert(varchar(100),b.FPLANSTARTDATE,20) 计划开工日期 ,convert(varchar(100),b.FPLANFINISHDATE,20) 计划完工日期 ,'ERP导入' 备注 ,'' 客户名称 ,'' 颜色 ,isnull(m_l.FSPECIFICATION,'') 型号规格 ,'' 色粉编号 ,'' 色粉名称 ,'' 材料编号 ,'' 材料名称 ,a.FBILLNO 订单编号 ,ISNULL(convert(varchar(100),c.FSTARTDATE ,20),'') 开工日期 ,convert(varchar(100),a.FMODIFYDATE,20) 修改日期 from AIS20210811135644..T_PRD_MO as a inner join AIS20210811135644..T_PRD_MOENTRY as b with(nolock) on a.FID = b.FID inner join AIS20210811135644..T_PRD_MOENTRY_A as c with(nolock) on b.FID = c.FID and b.FEntryID = c.FEntryID inner join AIS20210811135644..T_BD_MATERIAL as m with(nolock) on b.FMATERIALID = m.FMATERIALID inner join AIS20210811135644..T_BD_MATERIAL_L as m_l with(nolock) on m.FMATERIALID=m_l.FMATERIALID where m_l.FLOCALEID=2052 and isnull(a.FAPPROVERID,0)<> 0 --已经审核 and isnull(c.fstatus,0) in (4) --业务状态(1:计划;2:计划确认;3:下达;4:开工;5:完工;6:结案) and ( convert(varchar(100),a.fmodifydate,23) >= convert(varchar(100),dateadd(day,-7,getdate()),23) or convert(varchar(100),c.fstartdate ,23) >= convert(varchar(100),dateadd(day,-7,getdate()),23) ) --and cast(a.FBILLNO as varchar(100)) + '_' + cast(b.FSEQ as varchar(10)) = 'MO000269_1'"; DataSet ds = oCN.RunProcReturn(sql, "AIS20210811135644..T_PRD_MO"); if (ds != null && ds.Tables.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { ICMO icmo = new ICMO(); icmo.key = token; icmo.planNumber = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["计划单号"]); icmo.planQty = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["计划数量"]); icmo.partNum = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["产品编号"]); icmo.planStartDate = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["计划开工日期"]); icmo.planEndDate = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["计划完工日期"]); icmo.comments = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["备注"]); icmo.customerName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["客户名称"]); icmo.colorName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["颜色"]); icmo.spec = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["型号规格"]); icmo.cpNo = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["色粉编号"]); icmo.cpName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["色粉名称"]); icmo.materialNo = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["材料编号"]); icmo.materialName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["材料名称"]); icmo.orderNumber = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["订单编号"]); icmo.option1 = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["修改日期"]); icmos.Add(icmo); } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "金蝶云生产订单数据获取失败!"; objJsonResult.data = null; } //判断生产订单列表中的数据是否在小诸葛中已经存在且已经是最新数据。如果小诸葛中不存在则同步到小诸葛。如果小诸葛中存在,则覆盖数据。 string errMsg = ""; for (int i = 0; i < icmos.Count; i++) { string HPlanNumber = icmos[i].planNumber; ICMODetailResponse icmoDetailResponse = await getICMODetailAsync(url, token, HPlanNumber); if (icmoDetailResponse.code == "1") { if (icmoDetailResponse.data[0].option1 != icmos[i].option1) { ICMOEdit icmoEdit = new ICMOEdit(); icmoEdit.key = token; icmoEdit.planId = icmoDetailResponse.data[0].planId; icmoEdit.planNumber = DBUtility.ClsPub.isStrNull(icmos[i].planNumber); icmoEdit.planQty = DBUtility.ClsPub.isStrNull(icmos[i].planQty); icmoEdit.partNum = DBUtility.ClsPub.isStrNull(icmos[i].partNum); icmoEdit.planStartDate = DBUtility.ClsPub.isStrNull(icmos[i].planStartDate); icmoEdit.planEndDate = DBUtility.ClsPub.isStrNull(icmos[i].planEndDate); icmoEdit.comments = DBUtility.ClsPub.isStrNull(icmos[i].comments); icmoEdit.customerName = DBUtility.ClsPub.isStrNull(icmos[i].customerName); icmoEdit.colorName = DBUtility.ClsPub.isStrNull(icmos[i].colorName); icmoEdit.spec = DBUtility.ClsPub.isStrNull(icmos[i].spec); icmoEdit.cpName = DBUtility.ClsPub.isStrNull(icmos[i].cpName); icmoEdit.materialNo = DBUtility.ClsPub.isStrNull(icmos[i].materialNo); icmoEdit.materialName = DBUtility.ClsPub.isStrNull(icmos[i].materialName); icmoEdit.orderNumber = DBUtility.ClsPub.isStrNull(icmos[i].orderNumber); icmoEdit.option1 = DBUtility.ClsPub.isStrNull(icmos[i].option1); ICMOEditResponse icmoEditResponse = await getAddICMOEditAsync(url, icmoEdit); if (icmoEditResponse.code == "0") { errMsg += "【" + HPlanNumber + "】" + icmoEditResponse.msg + ";"; } } } else { ICMOResponse icmoResponse = await getAddICMOAsync(url, icmos[i]); if (icmoResponse.code == "0") { errMsg += "【" + HPlanNumber + "】" + icmoResponse.msg + ";"; } } } if (errMsg.Length > 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "同步失败!" + errMsg; objJsonResult.data = null; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "同步成功!" + errMsg; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "同步失败!" + e.Message; objJsonResult.data = null; return objJsonResult; } } #endregion #endregion #region 生产汇报 #region 获取已审核的报工记录信息列表信息 public async Task getICMOReportListAsync() { //请求地址 string url = await getServerAddressAsync() + "/v2/GET/getAuditedProduceReportList"; string token = await getTokenAsync(); //请求参数 Dictionary queryParams = new Dictionary { {"key", token}, {"indexPage", "1"}, //{"startDate", DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd")}, //{"endDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, {"sidx", "reportDate"}, {"sord", "desc"}, //{"tour", "白班"}, {"type", "1"}, {"reportStartDate", DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss")}, {"reportEndDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 ICMOReportListResponse icmoReportListResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return icmoReportListResponse; } #endregion #region 获取生产汇报详细信息 public async Task getICMOReportDetailAsync(string url, string key, string reportId) { //请求地址 url = url + "/v2/GET/getProduceRecordReport"; //请求参数 Dictionary queryParams = new Dictionary { {"key", key}, {"reportId",reportId } }; //返回结果 string responseBody = await DefinedRequestSendMethod.GetDataAsyncByGetRequest(url, queryParams); //将字符串转换为对象 ICMOReportDetailResponse icmoReportDetailResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody); return icmoReportDetailResponse; } #endregion #region 生产汇报定时同步_从小诸葛到ERP public async Task icmoReportInfoSyncFromXZGToERP() { string sErrMsg = ""; try { //请求地址 string url = await getServerAddressAsync(); string token = await getTokenAsync(); ICMOReportListResponse iCMOReportListResponse = await getICMOReportListAsync(); List iCMOReportList = new List(); for(int i = 0; i < iCMOReportListResponse.data.Count; i++) { for(int j=0;j< iCMOReportListResponse.data[i].data.Count; j++) { string sql = "select * from AIS20210811135644..T_PRD_MORPT where FBillNo = '" + iCMOReportListResponse.data[i].data[j].produceReportId + "'"; DataSet ds_erp = oCN.RunProcReturn(sql, "AIS20210811135644..T_PRD_MORPT"); if(ds_erp!=null&ds_erp.Tables[0].Rows.Count == 0) { iCMOReportList.Add(iCMOReportListResponse.data[i].data[j]); } } } ////金蝶云生产汇报单:批量同步 //ICMOReportListResponse_Data_Data data = new ICMOReportListResponse_Data_Data(); //data.planNo = "MO000269_1_100483"; //data.reportDate = "2025-04-27 00:00:00"; //data.standardNum = "1"; //data.produceReportId = "1234321"; //iCMOReportList.Add(data); objJsonResult = set_SaveICMOReportBillList(iCMOReportList); //objJsonResult.code = "1"; //objJsonResult.count = 1; //objJsonResult.Message = "同步成功!"; //objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "同步失败!" + e.Message; objJsonResult.data = null; return objJsonResult; } } #endregion #region 生产汇报 批量新增 public json set_SaveICMOReportBillList(List iCMOReportList) { string sErrMsg = ""; string sRemark = ""; string sRemark_errAudit = ""; try { for (int i = 0; i < iCMOReportList.Count; i++) { objJsonResult = set_SaveICMOReportBill(iCMOReportList[i]); if (objJsonResult.code == "1" && objJsonResult.count == 1) { sRemark += objJsonResult.Message; }else if(objJsonResult.code == "1" && objJsonResult.count == 0) { sRemark_errAudit += objJsonResult.Message; } else { sErrMsg += objJsonResult.Message; } } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "【同步并审核成功信息】:" + sRemark + ";【同步成功但审核失败信息】:" + sRemark_errAudit + ";【同步失败信息:】:" + sErrMsg ; //成功! objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "生产汇报单上传失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 生产汇报 新增 public json set_SaveICMOReportBill(ICMOReportListResponse_Data_Data data) { string sErrMsg = ""; //用于记录过程数据,作为日记数据 string sRemark = ""; try { try { #region 从配置文件获取 CLOUD网址、账套信息、登录用户、登录密码 //登录 string HReturn; bool bLogin = false; var loginRet = InvokeHelper.LoginUser(data.reportUser); string dbId = Pub_Class.ClsPub.sCLOUDAcc; //AotuTest117 var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value(); if (isSuccess <= 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = loginRet; objJsonResult.data = null; return objJsonResult; } else { bLogin = true; sRemark = sRemark + " ;获取验证CLOUD账号密码" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); } #endregion #region 判断生产订单状态 是否为 完工 或结案 string[] planNoSplit = data.planNo.Split('_'); string HICMOBillNo = planNoSplit[0]; string HICMOSEQ = planNoSplit[1]; string HICMOEntryID = planNoSplit[2]; string sql_judgeICMOStatus = @"select distinct mo.FBILLNO from AIS20210811135644..T_PRD_MO mo inner join AIS20210811135644..T_PRD_MOENTRY_A a on mo.FID=a.FID where a.FSTATUS in (5,6) and mo.FBILLNO = '" + HICMOBillNo + "' " + "and a.FENTRYID = " + HICMOEntryID; DataSet Ds2; Ds2 = oCN.RunProcReturn(sql_judgeICMOStatus, "AIS20210811135644..T_PRD_MO"); if (Ds2 != null && Ds2.Tables[0].Rows.Count > 0) { sErrMsg = "生产订单【 " + HICMOBillNo + "】业务状态已完工不允许汇报!"; objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; objJsonResult.data = null; return objJsonResult; } #endregion #region 获取金蝶云生成单据json string json = getErpJSON(data); sRemark = sRemark + " ;获取CLOUD单据API递入值" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); #endregion #region 生成金蝶云单据 if (bLogin) { var result = InvokeHelper.Save("PRD_MORPT", json); sRemark = sRemark + " ;生成CLOUD单据" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); //获取金蝶云单据生成返回信息 HReturn = result.ToString(); if (HReturn.Contains("\"IsSuccess\":false") == true) { sErrMsg = "生成生产汇报单失败!" + HReturn; LogService.Write("生成生产汇报单(源单:生产订单)失败!" + HReturn + json); //写入txt文本 objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; //成功! objJsonResult.data = null; return objJsonResult; } else { sRemark = sRemark + json; } } else { sErrMsg = "生成生产汇报单失败!金蝶云登录失败!"; objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; //成功! objJsonResult.data = null; return objJsonResult; } #endregion } catch (Exception e) { sErrMsg = "生成生产汇报单失败!" + e.Message; objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; objJsonResult.data = null; return objJsonResult; } #region 审核单据 try { //提交、审核金蝶云单据 #region 从配置文件获取 CLOUD网址、账套信息、登录用户、登录密码 //登录 string HReturn = ""; bool bLogin = false; var loginRet = InvokeHelper.LoginUser(data.auditUser); string dbId = Pub_Class.ClsPub.sCLOUDAcc; //AotuTest117 var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value(); if (isSuccess <= 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = loginRet; objJsonResult.data = null; return objJsonResult; } else { bLogin = true; sRemark = sRemark + " ;获取验证CLOUD账号密码" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); } #endregion if (bLogin) { ////提交单据 string sJson2 = "{\"CreateOrgId\":0,\"Numbers\":[\"" + data.produceReportId + "\"]}"; var result2 = InvokeHelper.Submit("PRD_MORPT", sJson2); //审核单据 string sJson3 = "{\"CreateOrgId\":0,\"Numbers\":[\"" + data.produceReportId + "\"]}"; var result3 = InvokeHelper.Audit("PRD_MORPT", sJson3); HReturn = result2.ToString() + "," + result3.ToString(); if (HReturn.Contains("\"IsSuccess\":false") == true) { LogService.Write("审核单据失败" + sRemark); sErrMsg = "生成生产汇报单成功,审核单据失败!" + HReturn; objJsonResult.code = "1"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; objJsonResult.data = null; return objJsonResult; } else { LogService.Write("生成并审核生产汇报单(源单:生产订单)成功!" + sRemark); sErrMsg = "生成并审核生产汇报单成功!单据号为:" + data.produceReportId; objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = sErrMsg; objJsonResult.data = null; return objJsonResult; } } else { sErrMsg = "审核生产汇报单失败!金蝶云登录失败!"; objJsonResult.code = "1"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; objJsonResult.data = null; return objJsonResult; } } catch (Exception e) { sErrMsg = "审核生产汇报单失败!" + e.Message; objJsonResult.code = "1"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; objJsonResult.data = null; return objJsonResult; } #endregion }catch(Exception e0) { sErrMsg = "生成生产汇报单失败!" + e0.Message; objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = sErrMsg; objJsonResult.data = null; return objJsonResult; } } #endregion #region 根据获取的报工信息,拼接json语句 public string getErpJSON(ICMOReportListResponse_Data_Data data) { //try //{ //data.planNo = "MO000269_1_100483"; //data.reportDate = "2025-04-27 00:00:00"; //data.standardNum = "1"; //data.produceReportId = "1234321"; // 获取生产汇报的源单信息 string[] planNoSplit = data.planNo.Split('_'); string HICMOBillNo = planNoSplit[0]; string HICMOSEQ = planNoSplit[1]; string HICMOEntryID = planNoSplit[2]; //根据报工信息,获取相关信息 string sql1 = @"select isnull(org1.hnumber,'') FPRDORGIDNumber ,ISNULL(org1.HItemID,0) FPRDORGID ,isnull(moSub.FPRODUCTTYPE,'1') FPRODUCTTYPE ,ISNULL(pr.HNumber,'') FAUXPROPNumber ,ISNULL(unit.HNumber,'') FUNITNumber ,ISNULL(dept.HNumber,'') FWORKSHOPNumber ,isnull(moSub.FMTONO,'') FMTONO ,isnull(moSubA.FCHECKPRODUCT,'false') FCHECKPRODUCT ,isnull(mo.FISENTRUST,'false') FISENTRUST ,isnull(moSub.FPROJECTNO,'') FPROJECTNO ,isnull(mp.FPERUNITSTANDHOUR,0) FSTDMANHOUR ,isnull(mp.FSTDLABORPREPARETIME,0) FHRPREPARETIME ,isnull(mp.FSTDMACHINEPREPARETIME,0) FMACPREPARETIME ,isnull(mo.FID,0) FSRCINTERID ,isnull(moSub.FSEQ,0) FSRCENTRYSEQ ,isnull(mo.FID,0) FMOID ,isnull(moSub.FENTRYID,0) FMOENTRYID ,isnull(unit1.HNumber,'') FBASEUNITID ,isnull(org1.HNumber,'') FSTOCKINORGID ,isnull(moSubA.FINSTOCKOWNERTYPEID,'') FOWNERTYPEID ,isnull(org2.HNumber,'') FOWNERID ,isnull(moSub.FCOSTRATE,0) FCOSTRATE ,isnull('','') FSTOCKID ,isnull(moSubA.FISBACKFLUSH,'false') FISBACKFLUSH ,isnull(moSub.FENTRYID,0) FMOMAINENTRYID ,isnull(moSubA.FQAIP,'') FQAIP ,isnull(moSubA.FREQSRC,'') FREQSRC ,isnull(moSub.FSALEORDERNO,'') FREQBILLNO ,isnull(moSub.FSALEORDERID,0) FREQBILLID ,isnull(moSub.FSALEORDERENTRYSEQ,0) FREQENTRYSEQ ,isnull(moSub.FSALEORDERENTRYID,0) FREQENTRYID ,isnull(moSubA.FINSTOCKTYPE,'1') FINSTOCKTYPE from AIS20210811135644..T_PRD_MO mo with(nolock) left join AIS20210811135644..T_PRD_MOENTRY moSub with(nolock) on mo.FID=moSub.FID left join AIS20210811135644..T_PRD_MOENTRY_A moSubA with(nolock) on moSubA.FID=moSub.FID and moSubA.FENTRYID=moSub.FENTRYID left join Xt_ORGANIZATIONS org1 with(nolock) on mo.FPRDORGID=org1.HItemID --生产组织 left join xt_ORGANIZATIONS org2 with(nolock) on moSubA.FINSTOCKOWNERID=org2.HItemID --入库货主 left join AIS20210811135644..t_BD_MaterialProduce mp with(nolock) on moSub.FMATERIALID=mp.FMATERIALID --物料生产信息 left join Gy_Unit as unit with(nolock) on moSub.FUNITID = unit.HItemID left join Gy_Unit as unit1 with(nolock) on moSub.FBASEUNITID = unit1.HItemID left join Gy_Property pr on moSub.FAUXPROPID = pr.HItemID left join Gy_Department dept on moSub.FWORKSHOPID = dept.HItemID where mo.FBillNo = '" + HICMOBillNo + "' " + " and moSub.FENTRYID = " + HICMOEntryID; DataSet jsonData = oCN.RunProcReturn(sql1, "AIS20210811135644..T_PRD_MO"); if (jsonData == null || jsonData.Tables[0].Rows.Count == 0) { return ""; } string FBillType = "SCHBD01_SYS"; //单据类型 string FPRDORGIDNumber = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FPRDORGIDNumber"]); //生产组织编码 string FPRDORGID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FPRDORGID"]); //生产组织编码 string FAUXPROPNumber = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FAUXPROPNumber"]); //辅助属性 string FIsNew = "false"; //是否新增行 string FPRODUCTTYPE = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FPRODUCTTYPE"]); //产品类型 string FREPORTTYPE = ""; //生产汇报类型 string FUNITNumber = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FUNITNumber"]); //单位编码 string FWORKSHOPNumber = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FWORKSHOPNumber"]); //部门 string FMTONO = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FMTONO"]); //计划跟踪号 string FCHECKPRODUCT = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FCHECKPRODUCT"]); //产品检验 string FISENTRUST = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FISENTRUST"]); //组织委托加工 string FSRCBILLTYPE = "PRD_MO"; //源单类型 string FPROJECTNO = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FPROJECTNO"]); //项目编号 string FSTDMANHOUR = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FSTDMANHOUR"]); //单位标准工时 string FHRPREPARETIME = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FHRPREPARETIME"]); //人员准备工时 string FMACPREPARETIME = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FMACPREPARETIME"]); //机器准备工时 string FSRCINTERID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FSRCINTERID"]); //源单内码 string FSRCENTRYSEQ = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FSRCENTRYSEQ"]); //源单行号 string FMOID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FMOID"]); //生产订单内码 string FMOENTRYID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FMOENTRYID"]); //生产订单分录号 string FBASEUNITID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FBASEUNITID"]); //基本单位 string FSTOCKINORGID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FSTOCKINORGID"]); //入库组织 string FBOMID = ""; //BOM版本 string FOWNERTYPEID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FOWNERTYPEID"]); //货主类型 string FOWNERID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FOWNERID"]); //货主 string FSTOCKID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FSTOCKID"]); //仓库 string FCOSTRATE = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FCOSTRATE"]); //成本权重 string FSNUNITID = ""; //序列号单位 string FISBACKFLUSH = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FISBACKFLUSH"]); //倒冲领料 string FMOMAINENTRYID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FMOMAINENTRYID"]); //生产订单主产品分录 string FQAIP = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FQAIP"]); //紧急放行 string FREQSRC = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FREQSRC"]); //需求来源 string FREQBILLNO = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FREQBILLNO"]); //需求单据 string FREQBILLID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FREQBILLID"]); //需求单据内码 string FREQENTRYSEQ = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FREQENTRYSEQ"]); //需求单据行号 string FREQENTRYID = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FREQENTRYID"]); //需求单据分录内码 string FINSTOCKTYPE = Pub_Class.ClsPub.isStrNull(jsonData.Tables[0].Rows[0]["FINSTOCKTYPE"]); //供下推入库单使用-入库类型 string FEntity_Link_FFlowId = "f6e6eec3-5267-4f02-8593-b633da508a72"; //业务流程图 string FEntity_Link_FFlowLineId = "3"; //推进路线 string FEntity_Link_FRuleId = "PRD_MO2MORPT"; //转换规则 string FEntity_Link_FSTableName = "T_PRD_MOENTRY"; //源单表 string FBFLOWID = "f6e6eec3-5267-4f02-8593-b633da508a72"; //业务流程 //获取生产汇报类型 string sql2 = @"select top(1) FNUMBER FREPORTTYPE from AIS20210811135644..T_PRD_REPORTTYPE with(nolock) Where FUSEORGID = " + FPRDORGID + " and FISDEFREPTYPE=1"; DataSet jsonData2 = oCN.RunProcReturn(sql2, "T_PRD_REPORTTYPE"); if (jsonData2 != null && jsonData2.Tables[0].Rows.Count > 0) { FREPORTTYPE = Pub_Class.ClsPub.isStrNull(jsonData2.Tables[0].Rows[0]["FREPORTTYPE"]); } //最终语句 string json = ""; string sJson_ZYMESFLAG = ""; //生产汇报单同步MES标记 string sJson_MainCustom = ""; //主表自定义字段 string sJson_Date = ""; //单据日期 //sJson_MainCustom = Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["MainCustom"]); //单据日期 sJson_Date = ",\"FDATE\":\"" + data.reportDate + "\""; sJson_ZYMESFLAG = ""; string sJson_Main = "{" + "\"Creator\":\"\"" + ",\"NeedUpDateFields\":[]" + ",\"NeedReturnFields\":[]" + ",\"IsDeleteEntry\":\"True\"" + ",\"SubSystemId\":\"\"" + ",\"IsVerifyBaseDataField\":\"false\"" + ",\"IsEntryBatchFill\":\"false\"" + ",\"ValidateFlag\":\"True\"" + ",\"NumberSearch\":\"True\"" + ",\"InterationFlags\":\"\"" + ",\"Model\": " + "{ " + "\"FBILLNO\":\"" + data.produceReportId + "\"" + //",\"FID\":\"" + oMain.HInterID.ToString() + "\"" + ",\"FBillType\":" + "{" + "\"FNumber\":\"" + FBillType + "\"" + "}" + ",\"FDocumentStatus\":\"\"" + sJson_Date + ",\"FPRDORGID\":" + "{" + "\"FNumber\":\"" + FPRDORGIDNumber + "\"" + "}" + //",\"FWorkshipIdH\":" + // "{" + // "\"FNumber\":\"\"" + // "}" + //",\"FDescription\":\"\"" + sJson_ZYMESFLAG + sJson_MainCustom + ",\"FEntity\": [ "; string sJson_Entry = ""; string sJson_BatchNo = ""; string sJson_StockPlace = ""; string sJson_FProduceDate = ""; //生产日期 string sJson_FExpiryDate = ""; //有效期至 string sJson_EntryCustom = ""; string sJson_FAUXPROPID = ""; string sJson_SubCustom = ""; //子表自定义字段 //子表自定义字段 //sJson_SubCustom = Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["SubCustom"]); ////是否启用批次管理 //if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HISBATCHMANAGE"]) == "1") //{ // sJson_BatchNo = " \"FLOT\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLOT"]) + "\"}, \"FLOT_TEXT\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLOT"]) + "\" , "; //} //else //{ // sJson_BatchNo = ""; //} ////是否启用保质期控制 //if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FISKFPERIOD"]) == "1") //{ // sJson_FProduceDate = " \"FProduceDate\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FProduceDate"]) + "\","; // sJson_FExpiryDate = " \"FExpiryDate\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FExpiryDate"]) + "\","; //} //else //{ // sJson_FProduceDate = ""; // sJson_FExpiryDate = ""; //} //辅助属性 sJson_FAUXPROPID = ", \"FAUXPROPID\":" + "{" + "\"FAUXPROPID__FF100002\":" + "{" + "\"FNumber\":\"" + FAUXPROPNumber + "\"" + "}" + "}"; ////仓位 //if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSTOCKLOCID"]) == "") //{ // sJson_StockPlace = ""; //} //else //{ // sJson_StockPlace = Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSTOCKLOCID"]) + "\"}},"; //} //自定义字段处理 sJson_EntryCustom = ""; sJson_Entry = sJson_Entry + " {" + //"\"FEntryID\":" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HEntryID"]) + "," + " \"FSRCENTRYID\":" + HICMOEntryID + "" + ", \"FIsNew\":" + FIsNew + "" + ", \"FMATERIALID\":" + "{" + "\"FNumber\":\"" + data.partNum + "\"" + "}" + ", \"FPRODUCTTYPE\":\"" + FPRODUCTTYPE + "\"" + ", \"FREPORTTYPE\":" + "{" + "\"FNumber\":\"" + FREPORTTYPE + "\"" + "}" + ", \"FUNITID\":" + "{" + "\"FNumber\":\"" + FUNITNumber + "\"" + "}" + ", \"FWORKSHIPID\":" + "{" + "\"FNumber\":\"" + FWORKSHOPNumber + "\"" + "}" + //", \"FShiftGroupId\":{\"FNumber\":\"\"}" + sJson_BatchNo + //\"FDeptId\":{\"FNumber\":\"\"}, //sJson_StockPlace + //仓位移到下方 ", \"FMTONO\":\"" + FMTONO + "\"" + ", \"FCHECKPRODUCT\":" + FCHECKPRODUCT + "" + ", \"FISENTRUST\":" + FISENTRUST + "" + ", \"FSRCBILLTYPE\":\"" + FSRCBILLTYPE + "\"" + ", \"FMOBILLNO\":\"" + HICMOBillNo + "\"" + //", \"FAUXPROPID\":" + // "{" + // "\"FAUXPROPID__FF100002\":" + // "{" + // "\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FAUXPROPID"]) + "\"" + // "}" + // "}" + sJson_FAUXPROPID + //", \"FHumanQty\":\"0\"" + ", \"FSRCBILLNO\":\"" + HICMOBillNo + "\"" + //", \"FMachineQty\":\"0\"" + //", \"FMaterialUnitID\":" + // "{" + // "\"FNumber\":\"\"" + // "}" + //", \"FStartTime\":\"1900-01-01\"" + //", \"FEndTime\":\"1900-01-01\"" + //", \"FTimeUnitId\":\"\"" + ", \"FMOENTRYSEQ\":" + HICMOSEQ + "" + //", \"FSTANDHOURUNITID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSTANDHOURUNITID"]) + "\"" + ", \"FPROJECTNO\":\"" + FPROJECTNO + "\"" + ", \"FSTDMANHOUR\":" + FSTDMANHOUR + "" + ", \"FHRPREPARETIME\":" + FHRPREPARETIME + "" + //", \"FHrWorkTime\":\"0\"" + ", \"FMACPREPARETIME\":" + FMACPREPARETIME + "" + //",\"FMacWorkTime\":\"0\"" + //",\"FDescriptionE\":\"\"" + ", \"FSRCINTERID\":" + FSRCINTERID + "" + ", \"FSRCENTRYSEQ\":" + FSRCENTRYSEQ + "" + ", \"FMOID\":" + FMOID + "" + ", \"FMOENTRYID\":" + FMOENTRYID + "" + ", \"FBASEUNITID\":" + "{" + "\"FNumber\":\"" + FBASEUNITID + "\"" + "}" + ", \"FSTOCKINORGID\":" + "{" + "\"FNumber\":\"" + FSTOCKINORGID + "\"" + "}" + ", \"FBOMID\":" + "{" + "\"FNumber\":\"" + FBOMID + "\"" + "}" + ", \"FOWNERTYPEID\":\"" + FOWNERTYPEID + "\"" + ", \"FOWNERID\":" + "{" + "\"FNumber\":\"" + FOWNERID + "\"" + "}" + ", \"FSTOCKID\":" + "{" + "\"FNumber\":\"" + FSTOCKID + "\"" + "}" + ", \"FCOSTRATE\":" + FCOSTRATE + "" + ", \"FSNUNITID\":" + "{" + "\"FNumber\":\"" + FSNUNITID + "\"" + "}" + //", \"FSNQty\":" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSNQty"]) + "" + sJson_FProduceDate + sJson_FExpiryDate + ", \"FISBACKFLUSH\":" + FISBACKFLUSH + "" + ", \"FMOMAINENTRYID\":" + FMOMAINENTRYID + "" + ", \"FQAIP\":\"" + FQAIP + "\"" + ", \"FREQSRC\":\"" + FREQSRC + "\"" + ", \"FREQBILLNO\":\"" + FREQBILLNO + "\"" + ", \"FREQBILLID\":" + FREQBILLID + "" + ", \"FREQENTRYSEQ\":" + FREQENTRYSEQ + "" + ", \"FREQENTRYID\":" + FREQENTRYID + "" + ", \"FBASEQUAQTY\":" + data.standardNum + "" + ", \"FQUAQTY\":" + data.standardNum + "" + ", \"FBASEFINISHQTY\":" + data.standardNum + "" + ", \"FFINISHQTY\":" + data.standardNum + "" + ", \"FInStockType\":\"" + FINSTOCKTYPE + "\"" + sJson_StockPlace + sJson_EntryCustom + sJson_SubCustom + //",\"FSerialSubEntity\":" + // "[" + // "{" + // "\"FDetailID\":\"0\"" + // ",\"FQCMaterialId\":" + // "{" + // "\"FNUMBER\":\"\"" + // "}" + // ",\"FInspectResult\":\"\"" + // ",\"FQcAuxPropId\":" + // "{" + // "\"FQCAUXPROPID__FF100002\":" + // "{" + // "\"FNumber\":\"\"" + // "}" + // "}" + // ",\"FQCQty\":\"0\"" + // ",\"FSerialNo\":\"\"" + // ",\"FSerialId\":" + // "{" + // "\"FNUMBER\":\"\"" + // "}" + // ",\"FQCStockInSelQty\":\"0\"" + // ",\"FSerialNote\":\"\"" + // ",\"FBaseQCQty\":\"0\"" + // ",\"FBaseQCStockInSelQty\":\"0\"" + // "}" + // "]" ", \"FEntity_Link\": " + "[" + "{" + " \"FEntity_Link_FFlowId\":\"" + FEntity_Link_FFlowId + "\"" + ", \"FEntity_Link_FFlowLineId\":\"" + FEntity_Link_FFlowLineId + "\"" + ", \"FEntity_Link_FRuleId\":\"" + FEntity_Link_FRuleId + "\"" + ", \"FEntity_Link_FSTableName\":\"" + FEntity_Link_FSTableName + "\"" + ", \"FEntity_Link_FSBillId\":\"" + FMOID + "\"" + ", \"FEntity_Link_FSId\":\"" + FMOENTRYID + "\"" + " }" + " ]" + ", \"FBFLOWID\":" + "{" + "\"FID\":\"" + FBFLOWID + "\"" + "}" + "}"; string sJson_End = " ] }}"; json = sJson_Main + sJson_Entry + sJson_End; return json; //}catch(Exception e) //{ // return e.Message; //} } #endregion #endregion } #endregion } #region HTTP请求类 class DefinedRequestSendMethod { #region Get请求 public static async Task GetDataAsyncByGetRequest(string url, Dictionary queryParams) { //返回字符串 string responseBody = ""; using (HttpClient client = new HttpClient()) { string apiUrl = url + ToQueryString(queryParams); HttpResponseMessage response = await client.GetAsync(apiUrl); response.EnsureSuccessStatusCode(); responseBody = await response.Content.ReadAsStringAsync(); } return responseBody; } #endregion #region POST请求 public static async Task GetDataAsyncByPOSTRequest(string url, Dictionary queryParams, string json) { //返回字符串 string responseBody = ""; using (HttpClient client = new HttpClient()) { //准备链接 url = url + ToQueryString(queryParams); // 准备POST数据 var content = new StringContent(json, Encoding.UTF8, "application/json"); // 发送POST请求 HttpResponseMessage response = await client.PostAsync(url, content); response.EnsureSuccessStatusCode(); responseBody = await response.Content.ReadAsStringAsync(); } return responseBody; } #endregion #region 参数处理 static string ToQueryString(Dictionary parameters) { string paramsStr = ""; foreach (var param in parameters) { if (paramsStr.Length == 0) { paramsStr += param.Key + "=" + param.Value; } else { paramsStr += "&" + param.Key + "=" + param.Value; } } return "?" + paramsStr; //var query = System.Web.HttpUtility.ParseQueryString(string.Empty); //foreach (var param in parameters) //{ // query[param.Key] = param.Value; //} //return "?" + query.ToString(); } #endregion #region MD5加密 public static string GetMD5(string input) { using (MD5 md5 = MD5.Create()) { byte[] inputBytes = Encoding.UTF8.GetBytes(input); byte[] hashBytes = md5.ComputeHash(inputBytes); StringBuilder sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("x2")); // "x2"表示小写的16进制格式 } return sb.ToString(); } } #endregion } #endregion