package quartz;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import com.jacal.basic.services.BasicService;
import com.jacal.biz.atp.operatebill.pojo.AtpOpbillModelOptask;
import com.jacal.biz.atp.operatebill.pojo.AtpOpbillOperateItem;
import com.jacal.biz.atp.operatebill.pojo.AtpOpbillOperateTask;
import com.jacal.biz.objects.Constants;
import com.jacal.biz.services.BizUtilServices;
import com.jacal.biz.st.operatebill.pojo.StOpbillOperateTask;
import com.jacal.biz.st.workticket.pojo.StWorkticketMain;
import com.jacal.core.business.BizAgent;
import com.jacal.core.dao.DAO;
import com.jacal.core.pojo.CoreDept;
import com.jacal.core.pojo.CoreOrg;
import com.jacal.core.pojo.CoreUser;
import com.jacal.core.pojo.CoreUserNoFinger;
import com.jacal.core.tools.Log;
import com.jacal.core.tools.StringUtil;
import com.jacal.core.tools.UtilDateTime;
import com.jacal.core.vo.Loginer;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.util.XWorkMap;
import com.txczp.pojo.czp;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.orm.hibernate3.support.ClobStringType;
public class quartzDaoImp {
private DAO dao;
private String oid;
private static String CORE_MODULE = "ATP_OPERATEBILL";// 模块代码
private static Class pojoClass = AtpOpbillOperateTask.class;// 业务对象Class
private static Class operateItemsClass = AtpOpbillOperateItem.class;// 操作项对象Class
private String activityId;
private Loginer loginer;
private String creater;
private Map flowdata = new XWorkMap(String.class);
private boolean isRemoveCache;// 列表是否清空
private String flowstate;// 流程状态
private BasicService bs = (BasicService) BizAgent
.getService(BasicService.class);
private BizUtilServices bizsvc = (BizUtilServices) BizAgent
.getService(BizUtilServices.class);
private JdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate2;
public void synchronous() throws Exception {
System.out.println("定时同步开始");
// input(getListData());
// inputDept();
// inputUser();
// inputTicket();
// inputPiaoLists();
inputCZPs();
System.out.println("定时同步结束");
}
public static final ParameterizedRowMapper<czp> czp = new ParameterizedRowMapper<czp>() {
public czp mapRow(ResultSet rs, int arg1) throws SQLException {
czp c = new czp();
c.setTask(rs.getString("任务"));
c.setContent(rs.getString("内容"));
c.setCzDate(rs.getDate("日期"));
c.setCzTime(rs.getTime("时间"));
c.setCzObject(rs.getString("对象"));
c.setStation(rs.getString("相关厂站"));
c.setCreater(rs.getString("编写人"));
c.setId(rs.getLong("ID"));
return c;
}
};
private Map getParams() {
Map param = new HashMap();
this.getLoginer();
Log.debug("loginer:" + loginer);
param.put(Loginer.LOGININFO_SESSION, loginer);
param.put(Constants.CORE_MODULE, "ATP_CONCRETE_OPERATEBILL");
param.put(Constants.BUSINESS_OBJ, pojoClass);
param.put(Constants.OID, oid);
param.put(Constants.FLOWINFO_ACTIVITYID, activityId);
return param;
}
public void inputCZPs() throws Exception {
String sql = "select * from czp where 备注 is null order by 日期,时间";
List qres = jdbcTemplate.query(sql, czp);
System.out.println("qres.size::" + qres.size());
if (qres.size() > 0) {
CoreUser cu = null;
List cuListnew = dao.find(CoreUser.class, "USERID='wxj'");
if (cuListnew.size() > 0) {
cu = (CoreUser) cuListnew.get(0);
}
Loginer loginercur = new Loginer();
if (cu != null) {
// loginercur=bs.login(cu.getUserid(),cu.getPassword());
loginercur.setUserId(cu.getUserid());
loginercur.setUserName(cu.getUsername());
Log.debug("getUsername:" + cu.getUsername());
loginercur.setUserOid(cu.getOid());
loginercur.setDeptCode(cu.getDept().getDeptcode());
List cdList = dao.find(CoreDept.class, "DEPTCODE="
+ cu.getDept().getDeptcode());
if (cdList.size() > 0)
loginercur.setDeptDesc(((CoreDept) cdList.get(0))
.getDeptdesc());
loginercur.setPassword(cu.getPassword());
loginercur.setOrgCode(cu.getOrg().getOrgcode());
List coList = dao.find(CoreOrg.class, "ORGCODE='"
+ cu.getOrg().getOrgcode() + "'");
if (coList.size() > 0)
loginercur.setOrgName(((CoreOrg) coList.get(0))
.getOrgname());
}
for (int i = 0; i < qres.size(); i++) {
czp pls = (czp) qres.get(i);
String task = pls.getTask();
String creatercur = pls.getCreater();
Date czDate = pls.getCzDate();
Date czTime = pls.getCzTime();
Long id = pls.getId();
String czDatestr = "";
String czTimestr = "";
String czDateTimestr = "";
if (czDate != null)
czDatestr = UtilDateTime.toDateString(czDate,
UtilDateTime.YYYY_MM_DD).substring(0, 10);
else
continue;
if (czTime != null)
czTimestr = UtilDateTime.toDateString(czTime,
UtilDateTime.DEFAULTFORMAT).substring(11, 19);
Log.debug("czTimefULLstr::"
+ UtilDateTime.toDateString(czTime,
UtilDateTime.DEFAULTFORMAT));
czDateTimestr = czDatestr + " " + czTimestr;
Date czDateTime = UtilDateTime.toDateTimeByPattern(
czDateTimestr, UtilDateTime.DEFAULTFORMAT);
Log.debug("czDateTimestr::" + czDateTimestr);
Log.debug("czDateTime::" + czDateTime);
List stootList = dao
.find(
AtpOpbillOperateTask.class,
"OPERATE_TASK='"
+ task
+ "' and to_char(OPERATE_BEGINTIME,'yyyy-MM-dd')='"
+ czDatestr + "'");
if (stootList.size() <= 0) {
AtpOpbillOperateTask aoot = new AtpOpbillOperateTask();
aoot.setBillType("ATP_CONCRETE_OPERATEBILL");
aoot.setRecTime(new Date());
aoot.setOperateTask(task);
aoot.setOperateBegintime(czDateTime);
aoot.setOperateEndtime(czDateTime);
aoot.setOperaterUserId(loginercur.getUserOid());
aoot.setOperaterUserName(loginercur.getUserName());
aoot.setOperaterDeptName(loginercur.getDeptDesc());
Map param = new HashMap();
Log.debug("loginercur:" + loginercur);
param.put(Loginer.LOGININFO_SESSION, loginercur);
param
.put(Constants.CORE_MODULE,
"ATP_CONCRETE_OPERATEBILL");
param.put(Constants.BUSINESS_OBJ, pojoClass);
param.put(Constants.OID, oid);
param.put(Constants.FLOWINFO_ACTIVITYID, activityId);
param.put(Constants.BUSINESS_OBJ, aoot);
Map rs = bizsvc.saveAddBizAndFlow(param);
AtpOpbillOperateItem aooi = new AtpOpbillOperateItem();
aooi.setAtpOpbillOperateTask(aoot);
aooi.setOperateTime(czDateTime);
aooi.setOperateUnit(pls.getStation());
aooi.setOperateContent(pls.getContent());
dao.saveOrUpdate(aooi);
} else {
AtpOpbillOperateTask aoot = (AtpOpbillOperateTask) stootList
.get(0);
aoot.setOperateEndtime(czDateTime);
dao.saveOrUpdate(aoot);
List stooiList = dao
.find(
AtpOpbillOperateItem.class,
"OPERATE_TASK_ID="
+ aoot.getOid()
+ " and to_char(OPERATE_TIME,'yyyy-MM-dd hh24:mi:ss')='"
+ czDateTimestr + "'");
AtpOpbillOperateItem aooi = new AtpOpbillOperateItem();
aooi.setAtpOpbillOperateTask(aoot);
aooi.setOperateTime(czDateTime);
aooi.setOperateUnit(pls.getStation());
aooi.setOperateContent(pls.getContent());
dao.saveOrU