132 lines
4.9 KiB
C#
132 lines
4.9 KiB
C#
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;
|
|
protected readonly string _moduleName;
|
|
|
|
public BaseService(Context context, int apiNoId)
|
|
{
|
|
_context = context;
|
|
var sql = $"SELECT * FROM V_CUSTOMS_API_REQUEST_PARAMETE WHERE Id = {apiNoId}";
|
|
var data = DBUtils.ExecuteDynamicObject(context, $"/*dialect*/{sql}");
|
|
var info = data[0];
|
|
|
|
_moduleCnName = info["ModuleCnName"].ToString();
|
|
_moduleName = info["ModuleName"].ToString();
|
|
_apiVersion = info["apiVersion"].ToString();
|
|
_apiName = info["apiName"].ToString();
|
|
_apiUrl = info["appUrl"].ToString();
|
|
_appKey = info["appKey"].ToString();
|
|
_appKeySecret = info["appKeySecret"].ToString();
|
|
}
|
|
|
|
/// <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 virtual 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));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|