|
|
|
@ -15,6 +15,11 @@ using OpenAuth.App.ServiceApp.CompanyManage.Request;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Infrastructure.Helpers;
|
|
|
|
|
using Infrastructure.Utilities;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
|
|
using NPOI.SS.UserModel;
|
|
|
|
|
using NPOI.XSSF.UserModel;
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.App.ServiceApp.CompanyManage
|
|
|
|
|
{
|
|
|
|
@ -204,5 +209,189 @@ namespace OpenAuth.App.ServiceApp.CompanyManage
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 上传企业信息
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上传企业信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="formFiles"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Response<bool> ImportCompanyInfo(IFormFileCollection formFiles)
|
|
|
|
|
{
|
|
|
|
|
IFormFile file = formFiles[0];
|
|
|
|
|
//存储文件到服务器
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
if (file.FileName.IndexOf(".xls") > 0 || file.FileName.IndexOf(".xlsx") > 0)
|
|
|
|
|
{
|
|
|
|
|
//数据库导入
|
|
|
|
|
IWorkbook workbook = null;
|
|
|
|
|
if (file.FileName.IndexOf(".xlsx") > 0)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = file.OpenReadStream())
|
|
|
|
|
{
|
|
|
|
|
workbook = new XSSFWorkbook(stream);//excel的版本2007
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (file.FileName.IndexOf(".xls") > 0)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = file.OpenReadStream())
|
|
|
|
|
{
|
|
|
|
|
workbook = new HSSFWorkbook(stream);//excel的版本2003
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//数据处理
|
|
|
|
|
using (var uow = base.UnitWork.CreateContext())
|
|
|
|
|
{
|
|
|
|
|
//获取sheet
|
|
|
|
|
ISheet sheet;
|
|
|
|
|
sheet = workbook.GetSheetAt(0);
|
|
|
|
|
//处理sheet数据
|
|
|
|
|
string res = "";
|
|
|
|
|
if (sheet != null)
|
|
|
|
|
{
|
|
|
|
|
IRow firstRow = sheet.GetRow(0);
|
|
|
|
|
//获取有效数据行数
|
|
|
|
|
int lastRow = sheet.LastRowNum;
|
|
|
|
|
//int rowCount = 0;
|
|
|
|
|
//具体excel数据解析
|
|
|
|
|
for (int i = 1; i <= lastRow; ++i)
|
|
|
|
|
{
|
|
|
|
|
IRow row = sheet.GetRow(i);
|
|
|
|
|
if (row == null || string.IsNullOrEmpty(row.GetCell(0).ToString())) continue;
|
|
|
|
|
|
|
|
|
|
TaxCompany cy = new TaxCompany();
|
|
|
|
|
cy.Id = Guid.NewGuid().ToString();
|
|
|
|
|
cy.shxydm =row.GetCell(0)?.ToString();
|
|
|
|
|
cy.frdb =row.GetCell(1)?.ToString();
|
|
|
|
|
cy.frsfzh =row.GetCell(2)?.ToString();
|
|
|
|
|
cy.lxfs=row.GetCell(3)?.ToString();
|
|
|
|
|
cy.hy=row.GetCell(4)?.ToString();
|
|
|
|
|
cy.jyzt =row.GetCell(5)?.ToString();
|
|
|
|
|
cy.ydhm =row.GetCell(6)?.ToString();
|
|
|
|
|
cy.ydhh =row.GetCell(7)?.ToString();
|
|
|
|
|
cy.dgyf =row.GetCell(8)?.ToString();
|
|
|
|
|
cy.yrhm =row.GetCell(9)?.ToString();
|
|
|
|
|
cy.yrhh=row.GetCell(10)?.ToString();
|
|
|
|
|
cy.rgyf =row.GetCell(11)?.ToString();
|
|
|
|
|
cy.yqhm =row.GetCell(12)?.ToString();
|
|
|
|
|
cy.yqhh=row.GetCell(13)?.ToString();
|
|
|
|
|
cy.qgyf =row.GetCell(14)?.ToString();
|
|
|
|
|
cy.yshm =row.GetCell(15)?.ToString();
|
|
|
|
|
cy.yshh =row.GetCell(16)?.ToString();
|
|
|
|
|
cy.sgyf =row.GetCell(17)?.ToString();
|
|
|
|
|
cy.dcr=row.GetCell(18)?.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(row.GetCell(19)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
cy.dcrq = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cy.dcrq = Convert.ToDateTime(row.GetCell(19)?.DateCellValue);
|
|
|
|
|
}
|
|
|
|
|
//cy.dcrq=Convert.ToDateTime(row.GetCell(19).ToString());
|
|
|
|
|
cy.clr=row.GetCell(20)?.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(row.GetCell(21)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
cy.clrq = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cy.clrq = Convert.ToDateTime(row.GetCell(21)?.DateCellValue);
|
|
|
|
|
}
|
|
|
|
|
//cy.clrq=Convert.ToDateTime(row.GetCell(21).ToString());
|
|
|
|
|
cy.bz=row.GetCell(22)?.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(row.GetCell(23)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
cy.gdzc=null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cy.gdzc=Convert.ToDecimal(row.GetCell(23)?.ToString());
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(row.GetCell(24)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
cy.xmgxcc = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cy.xmgxcc = Convert.ToDecimal(row.GetCell(24)?.ToString());
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(row.GetCell(25)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
cy.cscy = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cy.cscy = Convert.ToDecimal(row.GetCell(25)?.ToString());
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(row.GetCell(26)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
cy.gdtzze = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cy.gdtzze = Convert.ToDecimal(row.GetCell(26)?.ToString());
|
|
|
|
|
}
|
|
|
|
|
var sfgs = row.GetCell(27)?.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(row.GetCell(27)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
cy.sfgsqy = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (sfgs == "t")
|
|
|
|
|
{
|
|
|
|
|
cy.sfgsqy = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cy.sfgsqy = false;
|
|
|
|
|
}
|
|
|
|
|
//cy.sfgsqy = Convert.ToBoolean(row.GetCell(27).BooleanCellValue);
|
|
|
|
|
}
|
|
|
|
|
cy.syrmc=row.GetCell(28)?.ToString();
|
|
|
|
|
cy.djqdm=row.GetCell(29)?.ToString();
|
|
|
|
|
cy.djqmc=row.GetCell(30)?.ToString();
|
|
|
|
|
cy.djzqdm=row.GetCell(31)?.ToString();
|
|
|
|
|
cy.djzqmc=row.GetCell(32)?.ToString();
|
|
|
|
|
if (uow.TaxCompany.IsAny(u => u.shxydm == cy.shxydm))
|
|
|
|
|
{
|
|
|
|
|
res += "社会信用代码" + cy.shxydm + "已存在,";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uow.TaxCompany.Insert(cy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var flag = uow.Commit();
|
|
|
|
|
|
|
|
|
|
return new Response<bool>
|
|
|
|
|
{
|
|
|
|
|
Result = flag,
|
|
|
|
|
Message = flag == true ? "更新成功 " + res : "更新失败"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Response<bool>
|
|
|
|
|
{
|
|
|
|
|
Result = false,
|
|
|
|
|
Message = "上传文件类型错误,请上传Excel文件"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Response<bool>
|
|
|
|
|
{
|
|
|
|
|
Result = false,
|
|
|
|
|
Message = "文件为空"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|