宜都城投资产数据同步插件 修复一些问题
This commit is contained in:
@@ -33,7 +33,7 @@ public class MyJdbcAgent {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public Object execute(String sqlString, Object param) throws BusinessException, SQLException {
|
||||
public Object executeWithOneParam(String sqlString, Object param) throws BusinessException, SQLException {
|
||||
List params = new ArrayList();
|
||||
params.add(param);
|
||||
return this.execute(sqlString, (List)params);
|
||||
|
||||
@@ -18,6 +18,10 @@ import com.seeyon.apps.src_ydctdatasync.datamap.RefundDataMapMode;
|
||||
import com.seeyon.apps.src_ydctdatasync.datasource.DataSource;
|
||||
import com.seeyon.apps.src_ydctdatasync.utils.StatementQueryUtil;
|
||||
import com.seeyon.apps.src_ydctdatasync.utils.TimeUtils;
|
||||
import com.seeyon.cap4.form.api.FormApi4Cap4;
|
||||
import com.seeyon.cap4.form.bean.FormBean;
|
||||
import com.seeyon.cap4.form.bean.FormFieldBean;
|
||||
import com.seeyon.cap4.form.bean.FormTableBean;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.exceptions.BusinessException;
|
||||
import com.seeyon.ctp.services.ServiceException;
|
||||
@@ -49,7 +53,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
private DataSource myCusDataSource = new DataSource((javax.sql.DataSource)AppContext.getBean("dataSource"));
|
||||
private MyJdbcAgent agent = new MyJdbcAgent(myCusDataSource);
|
||||
private boolean prod;
|
||||
|
||||
private FormApi4Cap4 formApi4Cap4 = null;
|
||||
public boolean isProd() {
|
||||
return prod;
|
||||
}
|
||||
@@ -57,6 +61,13 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
public void setProd(boolean prod) {
|
||||
this.prod = prod;
|
||||
}
|
||||
public FormApi4Cap4 getFormApi4Cap4() {
|
||||
if (this.formApi4Cap4 == null) {
|
||||
this.formApi4Cap4 = (FormApi4Cap4)AppContext.getBean("formApi4Cap4");
|
||||
}
|
||||
|
||||
return this.formApi4Cap4;
|
||||
}
|
||||
|
||||
public FormFactory getFormFactory() {
|
||||
if (formFactory == null) {
|
||||
@@ -147,11 +158,11 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
}
|
||||
}).start();
|
||||
countDownLatch.await();
|
||||
log.info("宜都城投资产数据同步任务结束,耗时:"+ (System.currentTimeMillis() - startTime)+ " ms");
|
||||
} catch (Exception e) {
|
||||
log.error("宜都城投资产数据同步任务执行失败");
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
log.info("宜都城投资产数据同步任务结束,耗时:"+ (System.currentTimeMillis() - startTime)+ " ms");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -178,7 +189,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
convert2StringValue(targetMap),
|
||||
getBizConfigByKey(YdzbdataSyncConstants.contractTable),
|
||||
convert2StringValue(subMap),
|
||||
"WHERE field0003 = ?", (String) targetMap.get("合同编号"));
|
||||
" WHERE field0003 = ?", (String) targetMap.get("合同编号"));
|
||||
}
|
||||
}
|
||||
log.info("合同表数据同步结束");
|
||||
@@ -305,7 +316,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
upsertData(getBizConfigByKey(YdzbdataSyncConstants.zcFormNo),
|
||||
convert2StringValue(targetMap),
|
||||
getBizConfigByKey(YdzbdataSyncConstants.zcTable),
|
||||
"WHERE field0031 = ?",
|
||||
" WHERE field0031 = ?",
|
||||
targetMap.get("资产编号") +"");
|
||||
}
|
||||
}
|
||||
@@ -330,7 +341,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
upsertData(getBizConfigByKey(YdzbdataSyncConstants.zcFormNo),
|
||||
convert2StringValue(targetMap),
|
||||
getBizConfigByKey(YdzbdataSyncConstants.zcTable),
|
||||
"WHERE field0031 = ?",
|
||||
" WHERE field0031 = ?",
|
||||
targetMap.get("资产编号") + "");
|
||||
}
|
||||
}
|
||||
@@ -355,7 +366,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
upsertData(getBizConfigByKey(YdzbdataSyncConstants.zcFormNo),
|
||||
convert2StringValue(targetMap),
|
||||
getBizConfigByKey(YdzbdataSyncConstants.zcTable),
|
||||
"WHERE field0031 = ?",
|
||||
" WHERE field0031 = ?",
|
||||
targetMap.get("资产编号") + "");
|
||||
}
|
||||
}
|
||||
@@ -385,7 +396,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
upsertData(getBizConfigByKey(YdzbdataSyncConstants.zcFormNo),
|
||||
convert2StringValue(targetMap),
|
||||
getBizConfigByKey(YdzbdataSyncConstants.zcTable),
|
||||
"WHERE field0031 = ?",
|
||||
" WHERE field0031 = ?",
|
||||
targetMap.get("资产编号") + "");
|
||||
}
|
||||
}
|
||||
@@ -398,23 +409,30 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
params.add(param);
|
||||
String querySql = "SELECT * FROM " + table + " "+ whereSql +";";
|
||||
Map<String,Object> existData = null;
|
||||
try {
|
||||
List<Map<String,Object>> resList = (List<Map<String, Object>>) agent.execute(querySql,params);
|
||||
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
||||
if(existData != null && existData.size() > 0) {
|
||||
for (String key : targetMap.keySet()) {
|
||||
existData.put(key,targetMap.get(key)+"");
|
||||
Map<String, Object> updateSqlMap = generateUpdateSql(existData, table, whereSql, param);
|
||||
agent.execute((String) updateSqlMap.get("sql"),updateSqlMap.get("params"));
|
||||
List<Map<String, Object>> resList = (List<Map<String, Object>>) agent.execute(querySql, params);
|
||||
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
||||
if (existData != null && existData.size() > 0) {
|
||||
FormBean cap4FormBean = this.getFormApi4Cap4().getFormByFormCode(formNo);
|
||||
Map<String, Object> temp = new HashMap<>();
|
||||
for (FormTableBean tableBean : cap4FormBean.getTableList()) {
|
||||
if (tableBean.getDbTableName().contains("formmain")) {
|
||||
for (String key : targetMap.keySet()) {
|
||||
FormFieldBean fieldBean = tableBean.getFieldMap4Display().get(key);
|
||||
temp.put(fieldBean.getColumnName(), targetMap.get(key));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
FormExport formExport = new FormExport();
|
||||
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
||||
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo,formExport, new String[] {});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (String key : temp.keySet()) {
|
||||
existData.put(key, temp.get(key) + "");
|
||||
}
|
||||
Map<String, Object> updateSqlMap = generateUpdateSql(existData, table, " WHERE ID = ?", param);
|
||||
agent.execute((String) updateSqlMap.get("sql"), (List) updateSqlMap.get("params"));
|
||||
} else {
|
||||
FormExport formExport = new FormExport();
|
||||
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
||||
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo, formExport, new String[]{});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void insertData(String formNo,Map<String, String> targetMap) throws BusinessException, SQLException, ServiceException {
|
||||
@@ -429,27 +447,34 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
params.add(param);
|
||||
String querySql = "SELECT * FROM " + table +" " + whereSql +";";
|
||||
Map<String,Object> existData = null;
|
||||
try {
|
||||
List<Map<String,Object>> resList = (List<Map<String, Object>>) agent.execute(querySql,params);
|
||||
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
||||
if(existData != null && existData.size() > 0) {
|
||||
for (String key : targetMap.keySet()) {
|
||||
existData.put(key,targetMap.get(key)+"");
|
||||
Map<String, Object> updateSqlMap = generateUpdateSql(existData, table, whereSql, param);
|
||||
agent.execute((String) updateSqlMap.get("sql"),updateSqlMap.get("params"));
|
||||
List<Map<String, Object>> resList = (List<Map<String, Object>>) agent.execute(querySql, params);
|
||||
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
||||
if (existData != null && existData.size() > 0) {
|
||||
FormBean cap4FormBean = this.getFormApi4Cap4().getFormByFormCode(formNo);
|
||||
Map<String, Object> temp = new HashMap<>();
|
||||
for (FormTableBean tableBean : cap4FormBean.getTableList()) {
|
||||
if (tableBean.getDbTableName().contains("formmain")) {
|
||||
for (String key : targetMap.keySet()) {
|
||||
FormFieldBean fieldBean = tableBean.getFieldMap4Display().get(key);
|
||||
temp.put(fieldBean.getColumnName(), targetMap.get(key));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
FormExport formExport = new FormExport();
|
||||
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
||||
formExport.setSubordinateForms(FormExportUtil.setSubordinateFormValue(subTableMap));
|
||||
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo,formExport, new String[] {});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
for (String key : temp.keySet()) {
|
||||
existData.put(key, temp.get(key) + "");
|
||||
}
|
||||
Map<String, Object> updateSqlMap = generateUpdateSql(existData, table, " WHERE ID = ?", param);
|
||||
agent.execute((String) updateSqlMap.get("sql"), (List) updateSqlMap.get("params"));
|
||||
} else {
|
||||
FormExport formExport = new FormExport();
|
||||
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
||||
formExport.setSubordinateForms(FormExportUtil.setSubordinateFormValue(subTableMap));
|
||||
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo, formExport, new String[]{});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<String, Object> generateUpdateSql(Map<String, Object> fieldValues, String tableName, String whereClause,String clauseValue) {
|
||||
private Map<String, Object> generateUpdateSql(Map<String, Object> fieldValues, String tableName, String whereClause,Object clauseValue) {
|
||||
if (fieldValues == null || fieldValues.isEmpty()) {
|
||||
throw new IllegalArgumentException("Field values cannot be null or empty");
|
||||
}
|
||||
@@ -464,6 +489,15 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
// Build the SET clause
|
||||
int fieldCount = 0;
|
||||
for (Map.Entry<String, Object> entry : fieldValues.entrySet()) {
|
||||
if(entry.getValue() == null || "".equals(entry.getValue()) || "null".equals(entry.getValue())) {
|
||||
continue;
|
||||
}
|
||||
if(entry.getKey().equals("ID")) {
|
||||
if(whereClause.contains("ID")) {
|
||||
clauseValue = entry.getValue();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (fieldCount > 0) {
|
||||
sqlBuilder.append(", ");
|
||||
}
|
||||
@@ -475,6 +509,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
||||
// Append the WHERE clause
|
||||
sqlBuilder.append(whereClause);
|
||||
// Create result map
|
||||
sqlBuilder.append(";");
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("sql", sqlBuilder.toString());
|
||||
result.put("params", params);
|
||||
|
||||
Reference in New Issue
Block a user