...

private String tempTab1 = null;

//临时表EcirrWithPPTempTable

public String getTempTable() {
String tempTable = null;
try {
tempTable = "EcirrWithPPTempTable";
String createTableSQL = "create table "
+ tempTable
+ " (" +
"fempName varchar(50),"+//员工姓名
"fempNumber varchar(50),"+//员工编号
"fempEnterDateBefore varchar(50),"+//变更前入职时间
"fempEnterDateAfter varchar(50),"+//变更后入职时间
"fempJoinGroupDateBefore varchar(50),"+//变更前工龄计算起始时间
"fempJoinGroupDateAfter varchar(50),"+//变更后工龄计算起始时间
"flastUpdateTime varchar(50),"+//变更时间
"flastUpdateUserName varchar(50)"//变更人
+ " )";
TempTablePool tablePool = TempTablePool.getInstance(this.ctx);
tempTable = tablePool.createTempTable(createTableSQL);
} catch (Exception e) {
e.printStackTrace();
}
return tempTable;
}

private void getAllInfo(String tempTab12,Map<String, Object> map) {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String longnumber = null;
if (null == map.get("admin")) {
longnumber = "000001";
} else {
longnumber = map.get("admin").toString();
}
try {
StringBuffer sql = new StringBuffer();
sql.append(" SELECT person.FNAME_l2 empName,person.FNUMBER empNumber,ppHis.FENTERDATE empEnterDateBefore,pp.FENTERDATE empEnterDateAfter,ppHis.FJOINGROUPDATE empJoinGroupDateBefore,pp.FJOINGROUPDATE empJoinGroupDateAfter,pp.FLASTUPDATETIME lastUpdateTime,lastU.FNAME_l2 lastUpdateUserName ").append("\r\n");;
sql.append(" FROM T_HR_PERSONPOSITIONHIS pp ").append("\r\n");;
sql.append(" left join T_BD_Person person on pp.FPERSONID=person.FID ").append("\r\n");;
sql.append(" left join T_ORG_POSITION position on position.FID =pp.FPRIMARYPOSITIONID").append("\r\n");;
sql.append(" left join T_ORG_Admin org on org.FID = position.FADMINORGUNITID ").append("\r\n");;
sql.append(" left join T_ORG_ORGFUNCTION fun on fun.FID=org.forgfunctionid ").append("\r\n");;
sql.append(" left join T_PM_User lastU on lastU.FID =pp.FLASTUPDATEUSERID ").append("\r\n");;
sql.append(" left join T_HR_PERSONPOSITIONHIS ppHis on ppHis.FLEFFDT=pp.FEFFDT-1 and ppHis.FPERSONID=pp.FPERSONID ").append("\r\n");;
sql.append(" where org.flongnumber like '"+ longnumber + "%' and FIsSealUp='0' ").append("\r\n");;
// 开始日期
if (null != map.get("startDate")) {
sql.append(" and to_char(pp.FLASTUPDATETIME,'yyyy-MM-dd')>='"+ map.get("startDate") + "' ").append("\r\n");
}
// 结束日期
if (null != map.get("endDate")) {
sql.append(" and to_char(pp.FLASTUPDATETIME,'yyyy-MM-dd') <='"+ map.get("endDate") + "' ").append("\r\n");
}
IRowSet rs = DbUtil.executeQuery(ctx, sql.toString());
while (rs.next()) {
Map<String, String> maps = new HashMap<String, String>();
maps.put("empName", rs.getString("empName"));
maps.put("empNumber", rs.getString("empNumber"));
maps.put("empEnterDateBefore",rs.getDate("empEnterDateBefore")==null?"":sdf.format(rs.getDate("empEnterDateBefore")));
maps.put("empEnterDateAfter", rs.getDate("empEnterDateAfter")==null?"":sdf.format(rs.getDate("empEnterDateAfter")));
maps.put("empJoinGroupDateBefore", rs.getDate("empJoinGroupDateBefore")==null?"":sdf.format(rs.getDate("empJoinGroupDateBefore")));
maps.put("empJoinGroupDateAfter", rs.getDate("empJoinGroupDateAfter")==null?"":sdf.format(rs.getDate("empJoinGroupDateAfter")));
maps.put("lastUpdateTime", rs.getDate("lastUpdateTime")==null?"":sdf.format(rs.getDate("lastUpdateTime")));
maps.put("lastUpdateUserName", rs.getString("lastUpdateUserName"));
list.add(maps);
}
//执行插入数据
insertAllInfo(tempTab1, list);
} catch (BOSException e) {
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

批量执行插入数据

//执行插入数据到tempTable1中
private void insertAllInfo(String tempTab1, List<Map<String, String>> list) {
try {
if (list.size() > 0) {
// 插入临时表
StringBuffer insertSQL = new StringBuffer();
insertSQL.append("INSERT INTO " + tempTab1);
insertSQL.append("(fempName,fempNumber,fempEnterDateBefore,fempEnterDateAfter,fempJoinGroupDateBefore,fempJoinGroupDateAfter,flastUpdateTime,flastUpdateUserName)").append(" VALUES(?,?,?,?,?,?,?,?)");
List<Object> intsertList = new ArrayList<Object>();
// 从map中取出数据放到临时表中
for (Map<String, String> map : list) {
//String number=map.get("longnumber");
Object[] obj = {
map.get("empName"),
map.get("empNumber"),
map.get("empEnterDateBefore"),
map.get("empEnterDateAfter"),
map.get("empJoinGroupDateBefore"),
map.get("empJoinGroupDateAfter"),
map.get("lastUpdateTime"),
map.get("lastUpdateUserName")
};
intsertList.add(obj);
}
DbUtil.executeBatch(ctx, insertSQL.toString(), intsertList);
}
} catch (Exception e) {
e.printStackTrace();
}
}

S-HR之代码创建临时表并插入数据的更多相关文章

  1. 继 S-HR之代码创建临时表并插入数据 完整功能之员工职业信息变更报表

    目的示例1: 制作员工职业信息报表[S-HR系统的报表其实就是列表o.0,醉了] EcirrWithPP.js shr.defineClass("shr.custom.EcirrWithPP ...

  2. sql创建临时表并且插入数据

    if OBJECT_ID('tempdb..#temp') is not null drop table #temp select * into #temp from ( --select * fro ...

  3. SQL Server通过创建临时表遍历更新数据

    前言: 前段时间新项目上线为了赶进度很多模块的功能都没有经过详细的测试导致了生成环境中的数据和实际数据对不上,因此需要自己手写一个数据库脚本来更新下之前的数据.(线上数据库用是SQL Server20 ...

  4. MySQL命令:创建数据库、插入数据

    简介: 学习mysql环境为ubantu,下面记录一些基本的创建数据库和插入数据的口令 打开MySQL 服务并使用 root 登录: --打开 MySQL 服务 sudo service mysql ...

  5. MySQL基础教程——创建数据库并插入数据

    本节将介绍 MySQL 新建数据库,新建表,插入数据以及基本数据类型的相关知识.本节实验将创建一个名为 mysql_shiyan 的数据库,其中有两张表 employee和 department. 1 ...

  6. olacle数据库员工表的创建,及插入数据,添加约束,删除列,查询数据的sql语句

    ---删除原有的员工表drop TABLE employee;---创建员工表CREATE TABLE employee       (       empno NUMBER(4) NOT NULL, ...

  7. 使用SQLiteHelper创建数据库并插入数据

    参考<疯狂android讲义>8.4节P424 1.获取SQLiteDatabase实例有2种方法,一是直接new SQLiteDatabase(),另一种使用SQLiteHelper.一 ...

  8. (大数据工程师学习路径)第四步 SQL基础课程----创建数据库并插入数据

    一.练习内容 1.新建数据库 首先,我们创建一个数据库,给它一个名字,比如“mysql_shiyan”,以后的几次实验也是对mysql_shiyan这个数据库进行操作. 语句格式为“CREATE DA ...

  9. sql Server 创建临时表 嵌套循环 添加数据

    begin --通过销货单与明细,生成安装项目及明细,及判断明细是否拆分生成多条 --delete from sazxm --delete from ssbazrw --获取未生成项目的销货单号 ,) ...

随机推荐

  1. JAVA 学习 IDEA安装及破解

    1.到官网下载安装包 网址:https://www.jetbrains.com/idea/download/#section=windows 选择  “”Ultimate “”这个版本点击“Downl ...

  2. 读书笔记:Information Architecture for the World Wide Web, 3rd Edition 北极熊 简介

    书籍介绍 Information Architecture for the World Wide Web, 3rd Edition<web信息架构:设计大型网站(第三版)> Designi ...

  3. Codeforces Round #324 (Div. 2)C. Marina and Vasya set

                                                          C. Marina and Vasya   Marina loves strings of ...

  4. gitlab的安装和配置

    1 使用omnibus gitlab来安装gitlab 也就是说,将gitlab和它所需要的组件打一个包,即打一个bundle进行安装. 第一步,安装gitlab的源. curl https://pa ...

  5. YTU 2542: 弟弟的作业

    2542: 弟弟的作业 时间限制: 1 Sec  内存限制: 128 MB 提交: 130  解决: 57 题目描述 你的弟弟刚做完了"100以内数的加减法"这部分的作业,请你帮他 ...

  6. python time 时间模块

    time():获取当前系统的时间戳ctime():以人类可读的方式打印当前系统时间sleep():接受一个参数,表示休眠时间 #!/usr/bin/env python #coding:utf8 im ...

  7. JeePlus:API工具

    ylbtech-JeePlus:API工具 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. http://wiki.jeeplus.org/docs/sho ...

  8. 01_c++下jni开发说明

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  9. Mybatis 分页实现

    一.插件 PageHelper(推荐使用) 原理:利用Mybatis的拦截器,截获需要分页的sql语句,在语句后面加分页条件,及获取总记录数等属性. 注意 插件属性类 参考一 参考二 实例: 第一步: ...

  10. bzoj 1673: [Usaco2005 Dec]Scales 天平【dfs】

    真是神奇 根据斐波那契数列,这个a[i]<=c的最大的i<=45,所以直接搜索即可 #include<iostream> #include<cstdio> usin ...