| | |
| | | { |
| | | public partial class MES_U9C : IMES_U9C |
| | | { |
| | | public static string U9CAuthLoginUrl { get; set; } = Biz.SysParam["U9CAuthLoginUrl_Test", "U9CUrl"].PARAM_VALUE; // "http://172.16.80.20/U9C/webapi/OAuth2/AuthLogin?"; 测试 |
| | | //public static string U9CAuthLoginUrl { get; set; } = Biz.SysParam["U9CAuthLoginUrl", "U9CUrl"].PARAM_VALUE; //正式 |
| | | public static string U9CAuthLoginUrl { get; set; } = ApiConfig.IsTestServer ? Cache.SysParam["U9CAuthLoginUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["U9CAuthLoginUrl", "U9CUrl"].PARAM_VALUE; // "http://172.16.80.20/U9C/webapi/OAuth2/AuthLogin?"; 测试 |
| | | //public static string U9CAuthLoginUrl { get; set; } = Cache.SysParam["U9CAuthLoginUrl", "U9CUrl"].PARAM_VALUE; //正式 |
| | | public static string secret = "&entcode=02&orgcode=101&clientid=mes&clientsecret=12c8ee7e9bb74ad2a6a0fb3315c8af20"; |
| | | public static string RcvRptDocCreateUrl |
| | | { get; set; } = Biz.SysParam["RcvRptDocCreateUrl_Test", "U9CUrl"].PARAM_VALUE; //"http://172.16.80.20/u9C/webapi/RcvRptDoc/Create"; 测试 |
| | | { get; set; } = ApiConfig.IsTestServer ? Cache.SysParam["RcvRptDocCreateUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["RcvRptDocCreateUrl", "U9CUrl"].PARAM_VALUE; //"http://172.16.80.20/u9C/webapi/RcvRptDoc/Create"; 测试 |
| | | //public static string RcvRptDocCreateUrl |
| | | //{ get; set; } = Biz.SysParam["RcvRptDocCreateUrl", "U9CUrl"].PARAM_VALUE; //正式 |
| | | //{ get; set; } = Cache.SysParam["RcvRptDocCreateUrl", "U9CUrl"].PARAM_VALUE; //正式 |
| | | |
| | | public static string U9CBarcodeCreateUrl |
| | | { get; set; } = ApiConfig.IsTestServer ? Cache.SysParam["U9CBarcodeCreateUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["U9CBarcodeCreateUrl", "U9CUrl"].PARAM_VALUE; |
| | | |
| | | /// <summary> |
| | | /// 入库单接口 |
| | |
| | | var action = new ApiAction<RcvRptDocCreateInput>(); |
| | | try |
| | | { |
| | | //先保存数据 |
| | | bool IsSuccessed = true; |
| | | var db = Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | var s = db.Storageable(input.ErpProdInBths, "U9C_RcvRptDocCreate") |
| | | .WhereColumns(t => new { t.ORDER_NO, t.WORK_ORDER, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | s.AsInsertable.ExecuteCommand(); |
| | | s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败"); |
| | | Logger.Interface.Error(action.Message); |
| | | IsSuccessed = false; |
| | | } |
| | | |
| | | //保存成功,调用U9C接口-测试用 |
| | | //int i = 1; |
| | | //List<BIZ_ERP_PROD_IN_BTH> ErpProdInBths = new List<BIZ_ERP_PROD_IN_BTH>(); |
| | | //foreach (var item in input.RcvRptDocBases.Where(q => q.Status != "Y")) |
| | | //{ |
| | | // var ErpProdInBth = Biz.Db.Queryable<BIZ_ERP_PROD_IN_BTH>().Where(q => q.WORK_ORDER == item.WorkOrder).First(); |
| | | // var ErpProdInBth = input.ErpProdInBths.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault(); |
| | | // item.Status = "Y"; |
| | | // if (!ErpProdInBth.IsNullOrEmpty()) |
| | | // { |
| | | // ErpProdInBth.ORDER_NO = $"XX001-{i}"; |
| | | // ErpProdInBth.ORDER_NO = $"YDRKD24120000{5+i}"; |
| | | // ErpProdInBth.IS_HANDLED = "Y"; |
| | | // ErpProdInBth.HANDLED_DATE = DateTime.Now; |
| | | // ErpProdInBths.Add(ErpProdInBth); |
| | | // } |
| | | // foreach (var p in input.PrintJsons) |
| | | // { |
| | | // var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault(); |
| | | // if (!d.IsNullOrEmpty()) |
| | | // { |
| | | // d.ORDER_NO = $"XX001-{i}"; |
| | | // d.STATUS = "Y"; |
| | | // d.ORDER_NO = $"YDRKD24120000{5 + i}"; |
| | | // d.IS_HANDLED = "Y"; |
| | | // } |
| | | // } |
| | | // i++; |
| | |
| | | //var _db = Biz.Db; |
| | | //var _dbTran = _db.UseTran(() => |
| | | //{ |
| | | // _db.Updateable(ErpProdInBths, "U9C_RcvRptDocCreate").UpdateColumns(x => new { x.ORDER_NO, x.REMARK, x.IS_HANDLED, x.HANDLED_DATE }).ExecuteCommand(); |
| | | // _db.Updateable(input.ErpProdInBths, "U9C_RcvRptDocCreate").UpdateColumns(x => new { x.ORDER_NO, x.REMARK, x.IS_HANDLED, x.HANDLED_DATE, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand(); |
| | | //}); |
| | | //if (!dbTran.IsSuccess) |
| | | //if (!_dbTran.IsSuccess) |
| | | //{ |
| | | // action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败"); |
| | | // action.CatchExceptionWithLog(_dbTran.ErrorException, $"数据处理失败"); |
| | | // Logger.Interface.Error(action.Message); |
| | | // IsSuccessed = false; |
| | | //} |
| | | //input.ErpProdInBths = ErpProdInBths; |
| | | |
| | | //保存成功,调用U9C接口 |
| | | if (IsSuccessed) |
| | | var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode={input.userId}{secret}"); |
| | | if (u9CLoginResult.Success) |
| | | { |
| | | var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode=admin{secret}"); |
| | | if (u9CLoginResult.Success) |
| | | var token = u9CLoginResult.Data; |
| | | Logger.Interface.Info($"U9C登录token: {token}"); |
| | | foreach (var item in input.RcvRptDocBases.Where(q => q.Status != "Y")) |
| | | { |
| | | var token = u9CLoginResult.Data; |
| | | Logger.Interface.Info($"U9C登录token: {token}"); |
| | | List<BIZ_ERP_PROD_IN_BTH> ErpProdInBths = new List<BIZ_ERP_PROD_IN_BTH>(); |
| | | foreach (var item in input.RcvRptDocBases.Where(q => q.Status != "Y")) |
| | | { |
| | | List<RcvRptDocCreateParam> param = new() { |
| | | List<RcvRptDocCreateParam> param = new() { |
| | | new() { |
| | | CompleteList = new(){ |
| | | new CompleteList |
| | |
| | | StorageType = item.StorageType, |
| | | DocState = item.DocState, |
| | | } |
| | | } |
| | | }, |
| | | Remark = "接口生成", |
| | | BusinessDate = DateTime.Now, |
| | | } |
| | | }; |
| | | var response = await HttpHelper.PostAsync(RcvRptDocCreateUrl, JsonConvert.SerializeObject(param), new Dictionary<string, string>() { { "token", token } }); |
| | | var result = JsonConvert.DeserializeObject<U9CResult>(response.Message); |
| | | var ErpProdInBth = Biz.Db.Queryable<BIZ_ERP_PROD_IN_BTH>().Where(q => q.WORK_ORDER == item.WorkOrder).First(); |
| | | if (result != null) |
| | | var response = await HttpHelper.PostAsync(RcvRptDocCreateUrl, JsonConvert.SerializeObject(param), new Dictionary<string, string>() { { "token", token } }); |
| | | var result = JsonConvert.DeserializeObject<U9CResult>(response.Message); |
| | | var ErpProdInBth = input.ErpProdInBths.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault(); |
| | | if (result != null) |
| | | { |
| | | if (result.Success && result.Data[0].m_isSucess) |
| | | { |
| | | if (result.Success && result.Data[0].m_isSucess) |
| | | Logger.Interface.Info($"生成入库单接口提交Json: {JsonConvert.SerializeObject(param)},返回Json: {response.Message}"); |
| | | item.Status = "Y"; |
| | | if (!ErpProdInBth.IsNullOrEmpty()) |
| | | { |
| | | Logger.Interface.Info($"生成入库单接口提交Json: {JsonConvert.SerializeObject(param)},返回Json: {response.Message}"); |
| | | item.Status = "Y"; |
| | | if (!ErpProdInBth.IsNullOrEmpty()) |
| | | { |
| | | ErpProdInBth.ORDER_NO = result.Data[0].m_code; |
| | | ErpProdInBth.IS_HANDLED = "Y"; |
| | | ErpProdInBth.HANDLED_DATE = DateTime.Now; |
| | | ErpProdInBths.Add(ErpProdInBth); |
| | | } |
| | | foreach (var p in input.PrintJsons) |
| | | { |
| | | var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault(); |
| | | if (!d.IsNullOrEmpty()) |
| | | { |
| | | d.ORDER_NO = result.Data[0].m_code; |
| | | } |
| | | } |
| | | Logger.Interface.Info($"生成入库单成功"); |
| | | ErpProdInBth.ORDER_NO = result.Data[0].m_code; |
| | | ErpProdInBth.IS_HANDLED = "Y"; |
| | | ErpProdInBth.HANDLED_DATE = DateTime.Now; |
| | | } |
| | | else |
| | | foreach (var p in input.PrintJsons) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = new($"{action.Message}; {result.Data[0].m_errorMsg}"); |
| | | item.Status = "F"; |
| | | if (!ErpProdInBth.IsNullOrEmpty()) |
| | | var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder && q.IS_HANDLED != "P").FirstOrDefault(); |
| | | if (!d.IsNullOrEmpty()) |
| | | { |
| | | ErpProdInBth.REMARK = result.Data[0].m_errorMsg; |
| | | ErpProdInBth.IS_HANDLED = "F"; |
| | | ErpProdInBth.HANDLED_DATE = DateTime.Now; |
| | | ErpProdInBths.Add(ErpProdInBth); |
| | | d.ORDER_NO = result.Data[0].m_code; |
| | | d.IS_HANDLED = "Y"; |
| | | } |
| | | Logger.Interface.Info($"生成入库单失败:{result.Data[0].m_errorMsg}"); |
| | | } |
| | | Logger.Interface.Info($"生成入库单成功"); |
| | | |
| | | //条码主档 |
| | | BarcodeCreateInput barcodeCreateInput = new() { |
| | | RevDocId = result.Data[0].m_iD, |
| | | userId = input.userId, |
| | | token = token, |
| | | IsLogin = false, |
| | | }; |
| | | U9CBarcodeCreate(barcodeCreateInput); |
| | | } |
| | | else |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = new($"{action.Message}; {result.Data[0].m_errorMsg}"); |
| | | item.Status = "F"; |
| | | if (!ErpProdInBth.IsNullOrEmpty()) |
| | | { |
| | | ErpProdInBth.REMARK = result.Data[0].m_errorMsg; |
| | | ErpProdInBth.IS_HANDLED = "F"; |
| | | ErpProdInBth.HANDLED_DATE = DateTime.Now; |
| | | } |
| | | foreach (var p in input.PrintJsons) |
| | | { |
| | | var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder && q.IS_HANDLED != "P").FirstOrDefault(); |
| | | if (!d.IsNullOrEmpty()) |
| | | { |
| | | d.ORDER_NO = result.Data[0].m_code; |
| | | d.IS_HANDLED = "F"; |
| | | } |
| | | } |
| | | Logger.Interface.Info($"生成入库单失败:{result.Data[0].m_errorMsg}"); |
| | | } |
| | | } |
| | | var _db = Biz.Db; |
| | | var _dbTran = _db.UseTran(() => |
| | | { |
| | | _db.Updateable(ErpProdInBths, "U9C_RcvRptDocCreate").UpdateColumns(x => new { x.ORDER_NO, x.REMARK, x.IS_HANDLED, x.HANDLED_DATE }).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | action.CatchExceptionWithLog(dbTran.ErrorException, $"数据处理失败"); |
| | | Logger.Interface.Error(action.Message); |
| | | IsSuccessed = false; |
| | | } |
| | | input.ErpProdInBths = ErpProdInBths; |
| | | } |
| | | var _db = Biz.Db; |
| | | var _dbTran = _db.UseTran(() => |
| | | { |
| | | _db.Updateable(input.ErpProdInBths, "U9C_RcvRptDocCreate").UpdateColumns(x => new { x.ORDER_NO, x.REMARK, x.IS_HANDLED, x.HANDLED_DATE, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand(); |
| | | }); |
| | | if (!_dbTran.IsSuccess) |
| | | { |
| | | action.CatchExceptionWithLog(_dbTran.ErrorException, $"数据处理失败"); |
| | | Logger.Interface.Error(action.Message); |
| | | } |
| | | } |
| | | input.labels = GetLabels(input.PrintJsons); |
| | | action.Data = input; |
| | | } |
| | | catch (System.Exception ex) |
| | |
| | | Logger.Interface.Info($"/* 入库单接口结束 */\r\n"); //固定写法 |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 入库单条码主档接口 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<BarcodeCreateInput>> U9CBarcodeCreate(BarcodeCreateInput input) |
| | | { |
| | | Logger.Interface.Info($"/**\r\n *进入入库单条码主档接口....\r\n */\r\n"); //固定写法 |
| | | var action = new ApiAction<BarcodeCreateInput>(); |
| | | try |
| | | { |
| | | if (input.IsLogin) |
| | | { |
| | | var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode={input.userId}{secret}"); |
| | | if (u9CLoginResult.Success) |
| | | { |
| | | input.token = u9CLoginResult.Data; |
| | | Logger.Interface.Info($"U9C登录token: {input.token}"); |
| | | } |
| | | } |
| | | List<BarcodeCreateParam> param = new() { |
| | | new() { |
| | | CreateEntityKeys = new(){ |
| | | new CreateEntityKeys |
| | | { |
| | | ID = input.RevDocId, //入库单ID |
| | | EntityType="UFIDA.U9.Complete.RCVRpt.RcvRptDoc" |
| | | } |
| | | }, |
| | | IsCreateHeadBarCode = true, |
| | | BarCodeRuleCode = "DJCPRK01", |
| | | GenerateCount = 1, |
| | | BCQty = 1, |
| | | } |
| | | }; |
| | | var response = await HttpHelper.PostAsync(U9CBarcodeCreateUrl, JsonConvert.SerializeObject(param), new Dictionary<string, string>() { { "token", input.token } }); |
| | | var result = JsonConvert.DeserializeObject<U9CResult>(response.Message); |
| | | if (result != null) |
| | | { |
| | | if (result.Success && result.Data[0].m_isSucess) |
| | | { |
| | | Logger.Interface.Info($"生成入库单条码主档接口提交Json: {JsonConvert.SerializeObject(param)},返回Json: {response.Message}"); |
| | | } |
| | | else |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = new($"{action.Message}; {result.Data[0].m_errorMsg}"); |
| | | Logger.Interface.Info($"生成入库单条码主档失败:{result.Data[0].m_errorMsg}"); |
| | | } |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | action.CatchExceptionWithLog(ex, "生成入库单条码主档异常"); |
| | | } |
| | | Logger.Interface.Info($"/* 入库单条码主档接口结束 */\r\n"); //固定写法 |
| | | return action; |
| | | } |
| | | |
| | | private List<BAS_LABEL_TEMP> GetLabels(List<InStorePrintJson> printJsons) |
| | | { |
| | | List<BAS_LABEL_TEMP> labels = new List<BAS_LABEL_TEMP>(); |
| | | int i = 1; |
| | | int j = 1; |
| | | foreach (var p in printJsons) |
| | | { |
| | | BAS_LABEL_TEMP label = Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == "InstoreTemplate").IncludesAllFirstLayer().First(); |
| | | foreach (var v in p.Items.Where(q => q.IS_HANDLED != "F" && q.IS_HANDLED != "P")) |
| | | { |
| | | foreach (var item in label.Variables) |
| | | { |
| | | if (item.VAR_NAME == "PageNum") |
| | | { |
| | | item.Value = $"第{i}页"; |
| | | } |
| | | if (item.VAR_NAME == "PageSize") |
| | | { |
| | | item.Value = $"共{printJsons.Count}页"; |
| | | } |
| | | if (item.VAR_NAME == "BusinessDate") |
| | | { |
| | | item.Value = DateTime.Now.ToString("yyyy.MM.dd"); |
| | | } |
| | | if (item.VAR_NAME == $"RcvDoc{j}") |
| | | { |
| | | item.Value = v.ORDER_NO; |
| | | } |
| | | if (item.VAR_NAME == $"SoDoc{j}") |
| | | { |
| | | item.Value = v.SALES_ORDER; |
| | | } |
| | | if (item.VAR_NAME == $"MoDoc{j}") |
| | | { |
| | | item.Value = v.WORK_ORDER; |
| | | } |
| | | if (item.VAR_NAME == $"ItemCode{j}") |
| | | { |
| | | item.Value = v.ITEM_CODE; |
| | | } |
| | | if (item.VAR_NAME == $"Description{j}") |
| | | { |
| | | item.Value = v.ITEM_NAME; |
| | | } |
| | | if (item.VAR_NAME == $"BoxQty{j}") |
| | | { |
| | | item.Value = v.CartonQty.ToString(); |
| | | } |
| | | if (item.VAR_NAME == $"InQty{j}") |
| | | { |
| | | item.Value = v.SCAN_QTY.ToString(); |
| | | } |
| | | if (item.VAR_NAME == $"RcvQrCode{j}") |
| | | { |
| | | item.Value = v.ORDER_NO.ToString(); |
| | | } |
| | | if (item.VAR_NAME == $"SapCode{j}") |
| | | { |
| | | item.Value = v.SapCode; |
| | | } |
| | | if (item.VAR_NAME == $"Seq{j}") |
| | | { |
| | | item.Value = j.ToString(); |
| | | } |
| | | } |
| | | j++; |
| | | } |
| | | i++; |
| | | labels.Add(label); |
| | | } |
| | | return labels; |
| | | } |
| | | } |
| | | } |