a
This commit is contained in:
129
08.昶东/EastChanger/BaseService.cs
Normal file
129
08.昶东/EastChanger/BaseService.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using HandleUtils;
|
||||
using Kingdee.BOS;
|
||||
using Kingdee.BOS.App.Data;
|
||||
using Kingdee.BOS.Core.DynamicForm;
|
||||
using Kingdee.BOS.Log;
|
||||
using Kingdee.BOS.TCP;
|
||||
using Kingdee.BOS.Util;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace EastChanger
|
||||
{
|
||||
public class BaseService
|
||||
{
|
||||
protected readonly Context _context;
|
||||
protected readonly string _apiName;
|
||||
protected readonly string _apiVersion;
|
||||
protected readonly string _apiUrl;
|
||||
protected readonly string _appKey;
|
||||
protected readonly string _appKeySecret;
|
||||
protected readonly string _moduleCnName;
|
||||
|
||||
public BaseService(Context context, string apiName, string moduleCnName = "海关信息同步")
|
||||
{
|
||||
_context = context;
|
||||
var sql = "SELECT * FROM V_CUSTOMS_API_REQUEST_PARAMETE ";
|
||||
var data = DBUtils.ExecuteDynamicObject(context, $"/*dialect*/{sql}");
|
||||
var info = data[0];
|
||||
|
||||
_apiUrl = info["appUrl"].ToString();
|
||||
_appKey = info["appKey"].ToString();
|
||||
_appKeySecret = info["appKeySecret"].ToString();
|
||||
_apiName = apiName;
|
||||
_apiVersion = "";
|
||||
_moduleCnName = moduleCnName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行数据加密后发送请求
|
||||
/// </summary>
|
||||
/// <param name="dataJson"></param>
|
||||
/// <returns></returns>
|
||||
public string DoSubmit(string dataJson)
|
||||
{
|
||||
//对json字符串进行url编码
|
||||
var requestData = EncryptHelper.UrlEncode(dataJson);
|
||||
var request = new Dictionary<string, object>();
|
||||
request.Add("app_key", _appKey);
|
||||
request.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
request.Add("name", _apiName); //接口名称
|
||||
request.Add("data", requestData);
|
||||
request.Add("version", _apiVersion);
|
||||
|
||||
string sign = SignUtil.BuildSign(request, _appKeySecret);
|
||||
request.Add("sign", sign);
|
||||
|
||||
string bodyData = JsonUtil.Serialize(request);
|
||||
string result = WebHelper.DoPost(_apiUrl, bodyData);
|
||||
// 转换为字符串
|
||||
var timestampStr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
sfj4Class.SaveTxt(dataJson, $"D:/sjf4Class/{timestampStr}.txt", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据账册分类后设置申报信息表头
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected Dictionary<string, Dictionary<string, object>> GetDeclInfos()
|
||||
{
|
||||
var newDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
var ledgerSql = @"SELECT * FROM V_LEDGER_INFO";
|
||||
|
||||
var ledgerInfos = DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{ledgerSql}");
|
||||
var groupList = ledgerInfos.GroupBy(x => x["FBOOKNUM"].ToString()).ToList();
|
||||
//var lInfo = ledgerInfos[0];
|
||||
var resultData = new Dictionary<string, Dictionary<string, object>>();
|
||||
foreach (var item in groupList)
|
||||
{
|
||||
var main = new Dictionary<string, object>();
|
||||
resultData.Add(item.Key, main);
|
||||
var lInfo = item.ToList()[0];
|
||||
main.Add("entCusCode", lInfo["FENTCUSCODE"]);
|
||||
main.Add("entCreditCode", lInfo["FENTCREDITCODE"]);
|
||||
main.Add("entName", lInfo["FENTNAME"]);
|
||||
main.Add("declaEntCusCode", lInfo["FDECLAENTCUSCODE"]);
|
||||
main.Add("declaEntCreditCode", lInfo["FDECLAENTCREDITCODE"]);
|
||||
main.Add("declaEntName", lInfo["FDECLAENTNAME"]);
|
||||
main.Add("customsCode", lInfo["FCUSTOMSCODE"]);
|
||||
main.Add("bookNum", lInfo["FBOOKNUM"]);
|
||||
}
|
||||
|
||||
return resultData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理接口回调信息
|
||||
/// </summary>
|
||||
/// <param name="opResult"></param>
|
||||
/// <param name="itemNo"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="IsSuccessStatus"></param>
|
||||
public void ExecuteOperateResult(IOperationResult opResult, string itemNo, string msg, bool IsSuccessStatus)
|
||||
{
|
||||
if (opResult != null)
|
||||
{
|
||||
opResult.OperateResult.Add(new OperateResult
|
||||
{
|
||||
Name = "同步编号:" + itemNo,
|
||||
Message = msg,
|
||||
SuccessStatus = IsSuccessStatus
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsSuccessStatus)
|
||||
Logger.Info(_moduleCnName, $"同步编号:{itemNo}--{msg}");
|
||||
else
|
||||
Logger.Error(_moduleCnName, "请检查单据状态", new Exception(msg));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user