📄 fawendjtask.java
字号:
package com.zx.gwgl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.TimerTask;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.work.db.DbConnection;
import com.work.db.DbUtil;
import com.work.exception.OurException;
public class FaWenDjTask extends TimerTask {
private static Log log = LogFactory.getLog(FaWenDjTask.class);
/**
* 为了实现发文流程中的数据自动登记;<br>
* 实现思路:首先判断此发文流程是否结束。将发文流程中的数据从zx_fawen表中查询出来,
* 然后插入到表zx_fawendj中去,同时将zx_fawen表中符合条件记录的sfygd设置为1
*
* @return void
*/
public void faWenDj() throws OurException {
String fawenSql = "select printYear,printMonth,printDay ," + // 日期
// 拟稿日期
"bh as fwbh, " + // 发文编号 编号
"zsjg as fwjg ," + // 收文机关 (主送机关、抄送机关合并?)
"zjfs as zwfs," + // 正文份数 主件份数
"fjfs as fjfs," + // 附件份数 附件份数
"fwtitle as wjbt," + // 文件标题 主题 fwtitle
"ngr," + // 拟稿人 拟稿人
"ngdw ," + // 拟稿单位 拟稿单位
"'' as zh," + // 字号 如何获取啊?
"0 as ys," + // 页数 手工录入
"id as fw_id " + // 系统id zx_fawen的id,即流程实例id
"from zx_fawen where sfygd=0";
log.debug(fawenSql);
List srcList = DbUtil.executeQueryList(fawenSql);
if (srcList == null) {
log.info("没有需要归档的发文流程记录。");
return;
}
int LEN = srcList.size(); // 需要登记的收文流程记录数;
List needGdList = new ArrayList();
// =====================判断流程是否结束,然后来决定对哪些记录进行自动登记===========
for (int i = 0; i < LEN; i++) {
HashMap map = (HashMap) srcList.get(i);
String id = (String) map.get("fw_id");
String tempSql = "select step_closedtype from enrol_flow where process_inst_id='"
+ id + "' order by id desc";
List tempList = DbUtil.executeQueryList(tempSql);
if (tempList == null)
break;// 跳出循环
int tempLen = tempList.size();
// Finished
boolean tempFlag = false; // 用来判断此流程过程中是否结束,如果有一条记录包含Finished,那么说明此流程已经结束,可以登记了。
for (int j = 0; j < tempLen; j++) {
if (((String) ((HashMap) tempList.get(j))
.get("step_closedtype")).equals("Finished")) {
tempFlag = true;
break;
}
}
if (tempFlag)
needGdList.add(map);
}
// =================================================
LEN = needGdList.size();
if (LEN < 1) {
log.info("没有需要归档的发文流程记录。");
return;
}
log.debug("归档发文流程的记录数为:" + LEN + "条。");
String djSql = "insert into zx_fawendj "
+ "(rq,fwbh,fwjg,zwfs,fjfs,wjbt,ngr,ngdw,zh,ys,fw_id) values (?,?,?,?,?,?,?,?,?,?,?)";
String sfygdSql = "update zx_fawen set sfygd=1 where id =? "; // 更新发文流程中对应的记录数
String rq = "";
String fwbh = "";
String fwjg = "";
int zwfs = 0;
int fjfs = 0;
String wjbt = "";
String ngr = "";
String ngdw = "";
String zh = "";
int ys = 0;
String sw_id = "";
Connection conn = DbConnection.getConn();
if (conn == null)
throw new OurException("获取数据库连接失败!");
PreparedStatement pst = null;
PreparedStatement pst2 = null;
int result = 0;
int result2 = 0; // 这个sqlserver驱动程序竟然不支持PreparedStatement循环传递参数。
try {
conn.setAutoCommit(false);
pst = conn.prepareStatement(djSql);
pst2 = conn.prepareStatement(sfygdSql);
for (int i = 0; i < LEN; i++) {
HashMap map = (HashMap) needGdList.get(i);
String tempMonth = (String) map.get("printMonth");
if (tempMonth.length() == 1)
tempMonth = "0" + tempMonth;
String tempDay = (String) map.get("printDay");
if (tempDay.length() == 1)
tempDay = "0" + tempDay;
rq = (String) map.get("printYear") + "/" + tempMonth + "/"
+ tempDay;
fwbh = (String) map.get("fwbh");
fwjg = (String) map.get("fwjg");
zwfs = ((Integer) map.get("zwfs")).intValue();
fjfs = ((Integer) map.get("fjfs")).intValue();
wjbt = (String) map.get("wjbt");
ngr = (String) map.get("ngr");
ngdw = (String) map.get("ngdw");
zh = (String) map.get("zh");
ys = ((Integer) map.get("ys")).intValue();
sw_id = (String) map.get("fw_id");
pst.setString(1, rq);
pst.setString(2, fwbh);
pst.setString(3, fwjg);
pst.setInt(4, zwfs);
pst.setInt(5, fjfs);
pst.setString(6, wjbt);
pst.setString(7, ngr);
pst.setString(8, ngdw);
pst.setString(9, zh);
pst.setInt(10, ys);
pst.setString(11, sw_id);
pst2.setString(1, sw_id);
result += pst.executeUpdate();
result2 += pst2.executeUpdate();
// 将已经归档的zx_shouwen中对应的记录设置sfygd为1
}
conn.commit();
log.debug("共" + result + "条发文流程记录登记成功!共" + result2
+ "条发文流程记录设置登记标志成功!");
} catch (SQLException e) {
log.error("出现异常!由于登记了" + result + "记录,更新了" + result2
+ "条记录!所以登记失败!" + "估计是记录数目太多,超出了PreparedStatement的缓存数!");
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
throw new OurException("发文流程自动登记执行失败!请通知管理员!", e);
} finally {
DbUtil.closeStatement(pst2);
DbUtil.closeStatement(pst);
DbUtil.closeConnection(conn);
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
try {
faWenDj();
} catch (OurException e) {
System.out.println(com.work.exception.ExceptionUtil
.getDetailMessage(e));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -