...

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. tesnorflow conv deconv,padding

    1.padding test input = tf.placeholder(tf.float32, shape=(1,2, 2,1)) simpleconv=slim.conv2d(input,1,[ ...

  2. SQLyog软件里无法插入中文(即由默认的latin1改成UTF8编码格式)

    问题详情: 无法插入中文? 解决办法: 需要修改编码格式,由默认的latin1改为utf8. 改成, 成功!

  3. 记录一下收集到的clojure相关的东东

    https://github.com/plexus/chestnut 一个用来调试clojurescript的工具,解决 Clojure, ClojureScript, and CSS的reload问 ...

  4. android 使用AlarmManager定时启动service

    private static AlarmManager am; private static PendingIntent pendingIntent; /** * 使用 AlarmManager 来 ...

  5. Handle/Body pattern(Wrapper pattern)

    Handle Body Pattern 一些设计模式,通过一系列非直接的间接的方式(这种间接的方式,可称其为 handle(把手)),完成接口与实现(实现可称为 body(主体))的分离 Handle ...

  6. Oracle 10g 10.2.0.4的group by BUG |ORA-00979 not a GROUP BY expression|

    乍看 ORA-00979 not a GROUP BY expression 这个提示估计很快能将其定位为SQL语句写得有问题,实际上有可能你遇到了一个Oracle的BUG,这个BUG常见于10.2. ...

  7. html5 画图板

    8个最新炫酷的HTML5动画应用 http://www.php100.com/html/it/qianduan/2015/0107/8281.html 另外一个画板demo http://www.os ...

  8. robotframework - 框架做接口自动化get请求

    1.做get请求之前先安装 Request库,参考github上链接 :https://github.com/bulkan/robotframework-requests/#readme 2.请求&a ...

  9. eclipse mybatis 快速生成工具

    1.首先,得先看看eclipse有没安装mybatis generator插件,如果有的话,请忽略这一步 eclipse在线安装mybatis generator 1.打开eclipse,找到help ...

  10. [CREC2007/CQOI2014]robotic sort

    Description 一个实验室里有n个长短不一的试管.你的任务是编写一段程序,用机器臂把它们按照高度从小到大的顺序排列. 对于高度相同的试管,排序前后的相对位置应保持不变.排序方法如图所示. 排序 ...