小揹簍syncProject的備忘
public void syncProject(String updateDate) throws Exception {
String projectNo;
String updateTimeBegin;
String updateTimeEnd;
Date today = new Date();
String toDayStr = DateTimeUtil.format(today, "yyyy-MM-dd");
updateTimeEnd = toDayStr + " 23:59:59";
if (updateDate != null) {
updateTimeBegin = DateTimeUtil.getBeforeDate(updateDate) + " 00:00:00";
} else {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
updateTimeBegin = df.format(calendar.getTime()) + " 00:00:00";
}
String selectSql = "select t1.GCNO," +
" t1.GCName," +
" (SELECT substring(ItemDesc," +
" charIndex('、', ItemDesc) +1," +
" len(ItemDesc) - charIndex('、', ItemDesc))" +
" FROM T_CTFT1" +
" WHERE TableName = 'U_GCTZ'" +
" AND FieldName = 'GCStatus'" +
" and ItemValue = t1.GCStatus) as GCStatus," +
" t1.HTNO," +
" t1.HTNAME," +
" (select ItemDesc from T_CTFT1 where TableName='U_HTTZ' and Itemvalue = T6.Entrust AND FieldName='Entrust') as HtDesc,"+
" t1.PEmail," +
" t1.Company," +
" t1.Dept," +
" t2.u_jobno as xmuser," +
" t3.u_jobno as Assistant," +
" t8.u_jobno as chXMuser," +
" t9.u_jobno as chAssistant," +
" t4.u_jobno as UserSign," +
" t1.CreateDate," +
" t1.UpdateDate," +
" (SELECT" +
" substring(ItemDesc,charIndex('、',ItemDesc)+1,len(ItemDesc)-charIndex('、',ItemDesc))" +
" FROM T_CTFT1 WHERE TableName='U_GCTZ' AND FieldName='JdCom'" +
" and ItemValue = t1.jdCom" +
" ) as jdCom," +
" (" +
" SELECT" +
" substring(ItemDesc,charIndex('、',ItemDesc)+1,len(ItemDesc)-charIndex('、',ItemDesc))" +
" FROM T_CTFT1 WHERE TableName='U_GCTZ' AND FieldName='XmCom'" +
" and ItemValue = t1.xmcom" +
" ) as xmcom," +
" t1.cardName," +
" t1.GCAdr," +
" t1.rpwd, " +
" t1.DocStatus, " +
" t5.total," +
" T6.QDDate, " +
" (case when left(t1.GCNO, 2) = 'GC' then 9999" +
" when PATINDEX('%[^0-9]%', left(t1.GCNO, 2)) = 0 then convert(int,left(t1.GCNO, 2)) " +
" else -1 end) as orderType, " +
" t10.專案負責人 as XMuserCOMBO,t10.專案負責人工號 as XMuserNoCOMBO,t10.專案助理 as AssistantCOMBO,t10.專案助理工號 as AssistantNoCOMBO "
+ " from U_GCTZ t1 "
+ " left join "
+ " OHEM t2 on t1.xmuser=t2.empid "
+ " left join "
+ " OHEM t3 on t1.Assistant=t3.empid "
+ " left join "
+ " OHEM T4 on t1.UserSign=t4.empid "
+ " left join ("
+ " select docentry,sum(isnull(FArea,0) "
+ " ) as total from u_gctz2 group by docentry "
+ " ) t5 on t1.docentry=t5.docentry "
+ " left join U_HTTZ T6 on t1.HTDocEntry = T6.docentry "
+ " left join ( "
+ " select * from U_GCCH gcch where gcch.DocEntry in (select top 1 ch.DocEntry from U_GCCH ch where ch.GCNO = gcch.GCNO order by ch.CreateDate desc) "
+ " ) t7 on t7.GCNO = t1.GCNO "
+ " left join OHEM t8 on t7.xmuser=t8.empid "
+ " left join OHEM t9 on t7.XMAssistant=t9.empid "
+ " left join xt t10 on t10.工程編號 = t1.GCNO "
+ " where t1.GCNO is not null and (t1.GCNO not like 'YF%' and t1.GCNO not like 'GC%') or (t1.GCNO like 'GC%' and t1.hasContact = 'N') ";
/*+ " and (t1.CreateDate >= '" + updateTimeBegin + "'"
+ " and t1.CreateDate <= '" + updateTimeEnd + "') or (t1.UpdateDate >= '" + updateTimeBegin + "'"
+ " and t1.UpdateDate <= '" + updateTimeEnd + "')";*/
List<Map<String, Object>> sapList = sapService.execSQL(selectSql);
if(CollectionUtils.isEmpty(sapList)){
return;
}
/*System.out.println(selectSql);*/
List<Main> mainList = mainService.localPro();
Map<String, Main> mainMap = new HashMap<>();
for (Main main : mainList) {
mainMap.put(main.getNumber(), main);
}
List<Person> personList = localPer();
Map<String, Person> personMap = new HashMap<String, Person>();
for (Person person : personList) {
personMap.put(person.getNumber(), person);
}
List<Organization> organizationList = localOrg();
Map<String, Organization> organizationMap = new HashMap<String, Organization>();
for (Organization organization : organizationList) {
organizationMap.put(organization.getNumber(), organization);
}
try {
for (int i = 0; i < sapList.size(); i++) {
projectNo = (String) sapList.get(i).get("GCNO");
Main model = mainMap.get(projectNo);
if (model != null) {
// 更新專案
setPropertys(model, sapList.get(i));
model.setLastUpdateTime((java.sql.Timestamp)sapList.get(i).get("UpdateDate"));
model.setCreator(ContextUtils.currentUser());
LOGGER.info("Update project which projectNo is :" + projectNo);
mainService.update(model);
} else {
// 新建專案
model = new Main();
setPropertys(model, sapList.get(i));
Calendar cal = Calendar.getInstance();
cal.setTime((java.sql.Timestamp)sapList.get(i).get("CreateDate"));
model.setYear(sapList.get(i).get("CreateDate") == null ? 0 : cal.get(Calendar.YEAR));
model.setCreateTime((java.sql.Timestamp)sapList.get(i).get("CreateDate"));
model.setStatus(StatusEnum.NORMAL);
String rpwd = (String) sapList.get(i).get("rpwd");
model.setMailPwd(rpwd);
LOGGER.info("Add project which projectNo is :" + projectNo);
mainService.addNew(model);
}
//System.out.println(model);
}
//同步t_sys_user的FGSUSERID
getfgsUserId();
} catch (Exception e) {
e.printStackTrace();
}
}