前提:该机构录入的都是和该机构有关的数据,机构下的funmental(idcard唯一)和creditinfo(funmentalid唯一)不能重复所以推出以下结论:
1.根据userid(机构)=》allfunmental 和 allInfo
2.标示唯一 funmetal以idcard allinfo以funmentalid,所以做出对应的字典allfdic allinfodic
3.if(allfdic.containskey(idcard))取出该数据 funmental,为字典重新赋值(在保存之前就重新赋值因为是引用类型,反之info也一样),然后标记为脏数据,如果不存在则new 出一个funmental,加入字典不管 三七二十一给他们赋值,最后saveorupdate funmental

4.info表的保存
creditinfo=null;
if(allinfodic.containskey(funmetalid))从字典取出该数据,然后重新赋值(引用类型结论和前面的一样),如果字典里没有加入字典,
然后为creditinfo.funmentalid=funmental.id 之后不管三七二十一saveorupdate

private void Import()
{
QueryInfo info=new QueryInfo("SysDict");
info.AddParam("TypeCode","SECTOR_TYPE");
List<SysDict> IndustryDic = Holworth.Utility.Utility.ListToT<SysDict>(Dao.FindList(info)).ToList();
var dics = (from s in IndustryDic select s).ToDictionary(x => x.Name);
StringBuilder sbError = new StringBuilder();
if (string.IsNullOrEmpty(fileup.FileName))
{
ScriptHelper.MessageBox(false, "不能上传空文件。", 0);
return;
}
string excelName = fileup.FileName;
string fileName = Server.MapPath("~/upload/" + excelName);
this.fileup.SaveAs(fileName);
List<CcrPersonalFundamental> fundamentals = new List<CcrPersonalFundamental>();
List<CcrPersonalCreditInfo> creditInfos=new List<CcrPersonalCreditInfo>();
string sql = "begin\n" ;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds = ExcelHelper.ReadExcelAllSheets(fileName, 0, false);
dt = ds.Tables[0];
QueryInfo allfunInfo = new QueryInfo("CcrPersonalFundamental");
allfunInfo.AddParam("UserId", int.Parse(CurrentUser.UserId));
var allf =
Holworth.Utility.Utility.ListToT<CcrPersonalFundamental>(
Dao.FindList(allfunInfo)).ToList();
var allfDic = (from s in allf select s).ToDictionary(x => x.IdCard);

// info dic
QueryInfo allCreditInfoDic = new QueryInfo("CcrPersonalCreditInfo");
allCreditInfoDic.AddParam("UserId", int.Parse(CurrentUser.UserId));
var allInfo =
Holworth.Utility.Utility.ListToT<CcrPersonalCreditInfo>(
Dao.FindList(allCreditInfoDic)).ToList();
var allInfoDic = (from s in allInfo select s).ToDictionary(x => x.FundamentalId);

//
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow row = dt.Rows[i];
var idcard = row[0].ToString().Trim().ToUpper().Trim();
var findf = false;
CcrPersonalFundamental fundamental = null;
if (allfDic.ContainsKey(idcard))
{
findf = true;
fundamental = allfDic[idcard];
fundamental.State.MarkDirty();

}
else
{
fundamental = new CcrPersonalFundamental();
findf = false;
fundamental.State.MarkNew();

}

CcrPersonalCreditInfo creditInfo=null;
fundamental.IdCard = idcard;
fundamental.Marriage = row[7].ToString().Trim();
fundamental.PersonalName = row[1].ToString().Trim();

fundamental.Address = row[8].ToString().Trim();
fundamental.MobilePhone = row[2].ToString().Trim();
fundamental.Industry = dics[row[9].ToString().Trim()].Code;

fundamental.Sex = row[3].ToString().Trim();
fundamental.CompanySize = row[10].ToString().Trim();
fundamental.Birthday = DateTime.Parse(row[4].ToString().Trim());

fundamental.Position = row[11].ToString().Trim();
fundamental.Education = row[5].ToString().Trim();
fundamental.MonthlyIncome =row[12].ToString().Trim();
fundamental.School = row[6].ToString().Trim();
fundamental.UserId = int.Parse(CurrentUser.UserId);
//通过判断身份证IdCard和机构账号UserId判断是否新纪录,新纪录插入,旧记录更新,还要判断信息是否完整
//QueryInfo histroyFundamentalInfo=new QueryInfo();
//histroyFundamentalInfo.QueryObject = "CcrPersonalFundamental";
//histroyFundamentalInfo.AddParam("UserId",int.Parse(CurrentUser.UserId));
//histroyFundamentalInfo.AddParam("IdCard",fundamental.IdCard);

// List<CcrPersonalFundamental> historyFundamentalList = Holworth.Utility.Utility.ListToT<CcrPersonalFundamental>(Dao.FindList(histroyFundamentalInfo)).ToList();
//如果已经存在这个机构下的身份证,则更新改数据

Dao.SaveOrUpdate(fundamental);
//CcrPersonalFundamental importFundamental=Dao.SaveOrUpdate(fundamental) as CcrPersonalFundamental;
if (!findf)
{
allfDic.Add(idcard, fundamental);
}
else
{
allfDic[idcard] = fundamental;
}
//通过上一步的身份证IdCard和机构账号UserId查询出funmentalId,再根据当前的UserId,判断这个funmetal是否存在如果存在判断info表里的userid和funmetalid是否已经存在更新,不存在新增

var findC = false;
if (allInfoDic.ContainsKey(fundamental.Id))
{
findC = true;
creditInfo = allInfoDic[fundamental.Id];

creditInfo.State.MarkDirty();

}
else
{
creditInfo = new CcrPersonalCreditInfo();
findC = false;
creditInfo.State.MarkNew();
}

creditInfo.PresentResidenceSince = row[23].ToString().Trim();
creditInfo.AccountStatus = row[14].ToString().Trim();
creditInfo.Propety = row[24].ToString().Trim();
creditInfo.DurationInMonth =row[15].ToString().Trim();
creditInfo.AgeInYear =row[25].ToString().Trim();
creditInfo.CreditHistory = row[13].ToString().Trim();
creditInfo.OtherInstallmentPlans =row[26].ToString().Trim();
creditInfo.Purpose = row[16].ToString().Trim();
creditInfo.Hounsing = row[27].ToString().Trim();
creditInfo.CreditAmount =row[17].ToString().Trim();
creditInfo.NumberOfCreditcard =row[28].ToString().Trim();
creditInfo.SavingsAccount = row[18].ToString().Trim();
creditInfo.Job =row[29].ToString().Trim();
creditInfo.PresentEmploymentSince = row[19].ToString().Trim();
creditInfo.NumberOfPeopleSupport = row[30].ToString().Trim();
creditInfo.DisposableIncome = row[20].ToString().Trim();
creditInfo.Telphone = row[31].ToString().Trim();
creditInfo.PersonalStatusAndSex =row[21].ToString().Trim();
creditInfo.ForeignWorkder = row[32].ToString().Trim();
creditInfo.OtherGuarantor = row[22].ToString().Trim();
creditInfo.UserId = int.Parse(CurrentUser.UserId);
creditInfo.CreditRate = row[33].ToString().Trim();
creditInfo.Usage = "train";

if ( !findC)
{
creditInfo.FundamentalId = fundamental.Id;
}

var obj = Dao.SaveOrUpdate(creditInfo);
if (!findC)
{
allInfoDic.Add(creditInfo.FundamentalId,creditInfo);
}

}

System.IO.File.Delete(fileName);

//记录日志 成功几条 失败几条
Contract.Domain.EtlLog log = new EtlLog();
log.TableName = "ccr_personal_fundamental,ccr_personal_credit_info";
log.CreateUname = CurrentUser.UserName;
log.Status = "插入成功";
log.FileName = fileName;
log.Remark = string.Format("共导入{0}条", creditInfos.Count);
if (dt.Rows.Count -1- creditInfos.Count > 0)
log.Remark += string.Format("失败{0}条因为{1}", dt.Rows.Count - 1 - creditInfos.Count, sbError.ToString() + "\n");
log.CreateDate = DateTime.Now;
log.State.MarkNew();
Dao.SaveOrUpdate(log);
Page.ClientScript.RegisterClientScriptBlock(JSUtil.CurrentPage.GetType(), Util.NewGuid(), @"<script>$.messager.alert('操作提示', '导入成功', 'info', function () {
artDialog.open.origin.JDataGrid.GridSearch();
artDialog.close();
});</script>");

}

excel判断新增使用字典作为页面级数据库,减少io的更多相关文章

  1. js 获取当前焦点所在的元素、给元素和input控件添加键盘监听事件、添加页面级的键盘监听事件

    页面级的键盘监听事件 document.onkeydown = function (event) { var e = event || window.event || arguments.callee ...

  2. 不同浏览器对document.documentElement和document.body的scrollheight ,scrollTop,clientHeight以及判断滚动条是否滚动到页面最底部 【转载】

    前段时间学习怎么写一个瀑布流的时候,就接触到document.documentElement和document.body的区别,然后今天查资料的时候看到这篇博客,遂转载记录在此. 两种特殊的文档属性可 ...

  3. 利用HTML5判断用户是否正在浏览页面技巧

    现在,HTML5里页面可见性接口就提供给了程序员一个方法,让他们使用visibilitychange页面事件来判断当前页面可见性的状态,并针对性的执行某些任务.同时还有新的document.hidde ...

  4. js判断用户是否离开当前页面

    简介 VisibilityChange 事件:用于判断用户是否离开当前页面 Code // 页面的 visibility 属性可能返回三种状态 // prerender,visible 和 hidde ...

  5. DataGridView使用技巧三:不显示最下面的新行、判断新增行

    一.DataGridView不显示下面的新行 通常DataGridView的最下面一行是用户新追加的行(行头显示*).如果不想让用户新追加行即不想显示该新行,可以将DataGridView对象的All ...

  6. excel判断单元格包含指定内容的函数用=IF(COUNTIF(A1,"*内容*"),"0","1")

    前面我们聊过怎样将Excel包含某字符的单元格填充颜色,这边我们用另外一种方法来实现:excel判断单元格包含指定内容的函数 选中需要显示结果的单元格,假设我们要判断第一行第一列的单元格A1是否含有“ ...

  7. js判断滚动条是否已到页面最底部或顶部实例

    原文 本文实例讲述了js判断滚动条是否已到页面最底部或顶部的方法.分享给大家供大家参考.具体分析如下: 我们经常会看到很多的网站一个返回顶部效果就是当我们滚动条到指定位置时返回顶部出来了,否则就自动隐 ...

  8. 数据库SQL优化大总结之 百万级数据库优化方案(转载)

    网上关于SQL优化的教程很多,但是比较杂乱.近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充. 这篇文章我花费了大量的时间查找资料.修改.排版,希望大家阅读之后,感觉 ...

  9. mysql 百万级数据库优化方案

    https://blog.csdn.net/Kaitiren/article/details/80307828 一.百万级数据库优化方案 1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 wher ...

随机推荐

  1. linux(8)

    第十九单元 nfs服务 ===============服务端 介绍: NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于198 ...

  2. [Java]基础.端口

    Map<String,String[]> map = request.getParameterMap(); BeanUtils.populate(user,map);  // 遍历 use ...

  3. error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

    编译出现如下错误: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such ...

  4. Go - reflection

    Go 语言也有反射的机制,通过这种机制可以大大提高程序的灵活性. reflect包中的 TypeOf 与 ValueOf 方法 首先,当我们想要使用反射技术的时候,我们需要先引用 reflect 包. ...

  5. Sqoop修改sqoop元信息实现job的增量导入

    最简单方式是按主键增量导入:http://blog.csdn.net/ggz631047367/article/details/50185319 以下方法只做存档 需求:redis缓存的数据隔段时间往 ...

  6. CentOS7.6安装PM2(Npm方式全局安装)

    安装前提: 1. node环境 2. npm 安装开始: 第一步:全局安装,npm install -g pm2 第二步: 保存当前进程状态,pm2 save 第三步: 生成开机自启动服务,pm2 s ...

  7. Keil MDK 和 IAR 两款ARM开发工具区别比较

    首先要说明,没有那款开发工具是万能的,也没有那款工具在所有方面都具有绝对优势.对于Keil MDK-ARM和IAR两款工具择,可以根据自己的习惯来选择,而不应该在使用其中的一款时贬低另外一款,或者总是 ...

  8. oringin 画图

    oringin做图输出矢量图方法: 右击图区,选择copy page 在Word文档中直接粘贴即可 oringin做图调整图边距: tool->option->page->margi ...

  9. 关于Android的margin(当前视图与周围视图的距离)和padding(当前视图与内部内容的距离)

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  10. Unable to save settings: Failed to save settings. Please restart IntelliJ IDEA

    找到原先备份的项目,把 .idea 文件夹重新覆盖,解决问题.