You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
237 lines
12 KiB
C#
237 lines
12 KiB
C#
using DS.Module.Core.Enums;
|
|
using DS.WMS.Core.Fee.Entity;
|
|
using DS.WMS.Core.Fee.Method;
|
|
using DS.WMS.Core.QuarztJobs.Dtos;
|
|
using DS.WMS.Core.QuarztJobs.Interface;
|
|
using DS.WMS.Core.QuarztJobs.Other;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using System.Net.Http.Headers;
|
|
|
|
|
|
namespace DS.WMS.Core.QuarztJobs.Method
|
|
{
|
|
/// <summary>
|
|
/// 进项发票相关
|
|
/// </summary>
|
|
public class InInvoiceService : IInInvoiceJobService
|
|
{
|
|
|
|
ISqlSugarClient? db;
|
|
public InInvoiceService(IServiceProvider serviceProvider)
|
|
{
|
|
db = serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 定时获取进项发票数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task GetInInvoiceData()
|
|
{
|
|
|
|
//获取组织机构请求授权列表
|
|
if (db == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var orgauthlist = db.Queryable<SysOrgAuth>().ClearFilter().Where(t => t.Deleted == false && t.Type == "InInvoice").ToList();
|
|
|
|
|
|
|
|
|
|
//遍历授权数据集
|
|
foreach (var item in orgauthlist)
|
|
{
|
|
bool tb = false; //根据此字段判断是否需要同步发票数据到钉钉
|
|
|
|
//组织请求远程接口api数据
|
|
Dictionary<string, string> header = new Dictionary<string, string>();
|
|
header.Add("USER_KEY", item.Key);
|
|
header.Add("USER_SECRET", item.Secret);
|
|
|
|
InInvoicePost model = new InInvoicePost();
|
|
model.kprqks = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"); //往前查24小时的进项发票数据
|
|
model.kprqjs = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
var result = await HttpHellp.PostAsync("http://47.105.115.105:26650/api/XSD/GetInInvoiceDataList", JsonConvert.SerializeObject(model), header);
|
|
|
|
//处理返回结果
|
|
var info = JsonConvert.DeserializeObject<InInvoicePostOutput>(result);
|
|
if (info == null || !info.success)
|
|
continue;
|
|
|
|
if (info != null && info.Data.data != null)
|
|
{
|
|
var dbLink = await db.Queryable<Module.SqlSugar.SysTenantLink>().ClearFilter().Where(t => t.TenantId == item.TenantId).FirstAsync();
|
|
SqlSugarClient? tenantDb = null;
|
|
foreach (var itemdata in info.Data.data)
|
|
{
|
|
//查询租户数据库中是否有当前数据
|
|
tenantDb = new SqlSugarClient(new ConnectionConfig
|
|
{
|
|
ConfigId = dbLink.Id,
|
|
ConnectionString = dbLink.Connection,
|
|
DbType = dbLink.DbType,
|
|
IsAutoCloseConnection = true
|
|
});
|
|
|
|
var ininviceinfo = await tenantDb.Queryable<InInvoice>().Where(x => x.InvoiceNumber == itemdata.fphm).FirstAsync();
|
|
|
|
//数据库中发票数据为空,获取发票详情数据
|
|
if (ininviceinfo == null)
|
|
{
|
|
GetInInvoiceDataInfo gidi = new GetInInvoiceDataInfo();
|
|
gidi.fphm = itemdata.fphm;
|
|
var resultinfo = await HttpHellp.PostAsync("http://47.105.115.105:26650/api/XSD/GetInInvoiceDataInfo", JsonConvert.SerializeObject(gidi), header);
|
|
var Iinfo = JsonConvert.DeserializeObject<InInvoiceDataInfoOutput>(resultinfo);
|
|
if (Iinfo.success == true)
|
|
{
|
|
tb = true;
|
|
|
|
//添加发票数据
|
|
InInvoice inInvoice = new InInvoice();
|
|
inInvoice.InvoicingDate = Iinfo.data.kprq;
|
|
inInvoice.InvoiceTypeCode = Iinfo.data.fplxdm;
|
|
inInvoice.InvoiceNumber = Iinfo.data.fphm;
|
|
inInvoice.TotalAmount = Iinfo.data.hjje;
|
|
inInvoice.TotalTax = Iinfo.data.hjse;
|
|
inInvoice.TotalWithTax = Iinfo.data.jshj;
|
|
inInvoice.InvoiceStatus = Iinfo.data.fpzt;
|
|
inInvoice.Invoicer = Iinfo.data.kpr;
|
|
inInvoice.OriginalInvoiceNumber = Iinfo.data.yfphm;
|
|
inInvoice.BuyerInvoiceName = Iinfo.data.gfkpmc;
|
|
inInvoice.BuyerInvoiceTaxNumber = Iinfo.data.gfkpsh;
|
|
inInvoice.SellerInvoiceName = Iinfo.data.xfkpmc;
|
|
inInvoice.SellerInvoiceTaxNumber = Iinfo.data.xfkpsh;
|
|
inInvoice.IsDetailObtained = Iinfo.data.IsGetDtl;
|
|
inInvoice.SellerIdentificationNumber = Iinfo.data.xfsbh;
|
|
inInvoice.FinalCheckCode = Iinfo.data.final_jym;
|
|
inInvoice.BuyerName = Iinfo.data.gfmc;
|
|
inInvoice.CurrentTime = Iinfo.data.dqsj;
|
|
inInvoice.DeductionAmount = Iinfo.data.kce;
|
|
inInvoice.VehicleInvoiceTypeCode = Iinfo.data.jdfplxdm;
|
|
inInvoice.TaxControlCode = Iinfo.data.skm;
|
|
inInvoice.BuyerTaxNumber = Iinfo.data.ghdwdm;
|
|
inInvoice.PaperInvoiceNumber = Iinfo.data.zzfphm;
|
|
inInvoice.Payee = Iinfo.data.skr;
|
|
inInvoice.ItemFlag = Iinfo.data.qdbz;
|
|
inInvoice.InvoiceUnitCode = Iinfo.data.kpdwdm;
|
|
inInvoice.BuyerBankAccount = Iinfo.data.ghdwyhzh;
|
|
inInvoice.Amount = Iinfo.data.je;
|
|
inInvoice.SellerName = Iinfo.data.xfmc;
|
|
inInvoice.SpecialElements = Iinfo.data.tdys;
|
|
inInvoice.ReimbursementType = ReimbursementTypeEnums.NotSubmitted;
|
|
inInvoice.BuyerBankAccountNumber = Iinfo.data.gfyhzh;
|
|
inInvoice.SpecialElementTypeCode = Iinfo.data.tdyslxDm;
|
|
inInvoice.OperatorCode = Iinfo.data.czydm;
|
|
inInvoice.BuyerAddressPhone = Iinfo.data.ghdwdzdh;
|
|
inInvoice.IsPaperInvoice = Iinfo.data.sfwzzfp;
|
|
inInvoice.InvoiceRequestNumber = Iinfo.data.fpqqlsh;
|
|
inInvoice.TaxAmount = Iinfo.data.se;
|
|
inInvoice.Remarks = Iinfo.data.bz;
|
|
inInvoice.BuyerIdentificationNumber = Iinfo.data.gfsbh;
|
|
inInvoice.BuyerFullName = Iinfo.data.ghdwmc;
|
|
inInvoice.SellerTaxNumber = Iinfo.data.xhdwdm;
|
|
inInvoice.InvoiceCode = Iinfo.data.fpdm;
|
|
inInvoice.SellerAddressPhone = Iinfo.data.xhdwdzdh;
|
|
inInvoice.DetailList = Iinfo.data.zbmx;
|
|
inInvoice.SellerAddressPhoneExtra = Iinfo.data.xddzdh;
|
|
inInvoice.SellerBankAccountNumber = Iinfo.data.xfyhzh;
|
|
inInvoice.Reviewer = Iinfo.data.fhr;
|
|
inInvoice.BuyerAddressPhoneExtra = Iinfo.data.gfdzdh;
|
|
inInvoice.SellerFullName = Iinfo.data.xhdwmc;
|
|
inInvoice.MachineCode = Iinfo.data.jqbh;
|
|
inInvoice.ItemOrServiceName = Iinfo.data.zyspmc;
|
|
inInvoice.SellerBankAccount = Iinfo.data.xhdwyhzh;
|
|
inInvoice.PdfFilePath = Iinfo.data.PDFfile;
|
|
inInvoice.OfdFilePath = Iinfo.data.OFDfile;
|
|
inInvoice.XmlFilePath = Iinfo.data.XMLfile;
|
|
inInvoice.AllFileDownloadPath = Iinfo.data.Allfile;
|
|
inInvoice.OrgId = item.OrgId;
|
|
inInvoice.CreateTime = DateTime.Now;
|
|
var datainv = await tenantDb.Insertable(inInvoice).ExecuteReturnEntityAsync();
|
|
|
|
foreach (var dtl in Iinfo.data.List)
|
|
{
|
|
//添加发票详情数据
|
|
InInvoiceDetail inInvoicedtl = new InInvoiceDetail();
|
|
inInvoicedtl.Id = SnowFlakeSingle.Instance.NextId();
|
|
inInvoicedtl.PId = datainv.Id;
|
|
inInvoicedtl.DetailId = dtl.mxid;
|
|
inInvoicedtl.InvoiceCode = dtl.fpdm;
|
|
inInvoicedtl.InvoiceNumber = dtl.fphm;
|
|
inInvoicedtl.InvoiceDetailLineNumber = dtl.fpmxxh;
|
|
inInvoicedtl.InvoiceLineNature = dtl.fphxz;
|
|
inInvoicedtl.Amount = dtl.je;
|
|
inInvoicedtl.TaxRate = dtl.sl;
|
|
inInvoicedtl.TaxAmount = dtl.se;
|
|
inInvoicedtl.ProductName = dtl.spmc;
|
|
inInvoicedtl.Specification = dtl.ggxh;
|
|
inInvoicedtl.Unit = dtl.dw;
|
|
inInvoicedtl.Quantity = dtl.spsl;
|
|
inInvoicedtl.UnitPrice = dtl.spdj;
|
|
inInvoicedtl.ProductCode = dtl.spbm;
|
|
inInvoicedtl.Version = dtl.bb;
|
|
inInvoicedtl.PreferentialPolicyFlag = dtl.yhzcbs;
|
|
inInvoicedtl.InvoicingDate = dtl.kprq;
|
|
inInvoicedtl.InvoicingUnitCode = dtl.kpdwdm;
|
|
inInvoicedtl.Name = dtl.mc;
|
|
inInvoicedtl.SerialNumber = dtl.xh;
|
|
inInvoicedtl.OrgId = item.OrgId;
|
|
inInvoicedtl.CreateTime = DateTime.Now;
|
|
await tenantDb.Insertable(inInvoicedtl).ExecuteCommandAsync();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (tb)
|
|
{
|
|
try
|
|
{
|
|
#region 同步发票到钉钉审批
|
|
var dingconfig = db.Queryable<SysOrgAuth>().Where(t => t.Type == "DingConfig" && t.OrgId == item.OrgId).First();
|
|
|
|
if (dingconfig != null)
|
|
{
|
|
//获取钉钉密钥
|
|
var token = DingDing.GetDingToken(dingconfig.Key, dingconfig.Secret);
|
|
//获取对应的组织机构的发票列表
|
|
var ininviceList = await tenantDb.Queryable<InInvoice>().Where(x => x.ReimbursementType == ReimbursementTypeEnums.NotSubmitted && x.OrgId == item.OrgId).ToListAsync();
|
|
//将发票信息同步更新到钉钉
|
|
var DingProcess = db.Queryable<SysOrgAuth>().Where(t => t.Type == "DingProcessCode" && t.OrgId == item.OrgId).First();
|
|
|
|
|
|
DingDing.UpDingOAForm(token, DingProcess.Key, ininviceList);
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|