宜都城投资产数据同步插件 修复一些问题
This commit is contained in:
@@ -33,7 +33,7 @@ public class MyJdbcAgent {
|
|||||||
this.dataSource = dataSource;
|
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();
|
List params = new ArrayList();
|
||||||
params.add(param);
|
params.add(param);
|
||||||
return this.execute(sqlString, (List)params);
|
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.datasource.DataSource;
|
||||||
import com.seeyon.apps.src_ydctdatasync.utils.StatementQueryUtil;
|
import com.seeyon.apps.src_ydctdatasync.utils.StatementQueryUtil;
|
||||||
import com.seeyon.apps.src_ydctdatasync.utils.TimeUtils;
|
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.AppContext;
|
||||||
import com.seeyon.ctp.common.exceptions.BusinessException;
|
import com.seeyon.ctp.common.exceptions.BusinessException;
|
||||||
import com.seeyon.ctp.services.ServiceException;
|
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 DataSource myCusDataSource = new DataSource((javax.sql.DataSource)AppContext.getBean("dataSource"));
|
||||||
private MyJdbcAgent agent = new MyJdbcAgent(myCusDataSource);
|
private MyJdbcAgent agent = new MyJdbcAgent(myCusDataSource);
|
||||||
private boolean prod;
|
private boolean prod;
|
||||||
|
private FormApi4Cap4 formApi4Cap4 = null;
|
||||||
public boolean isProd() {
|
public boolean isProd() {
|
||||||
return prod;
|
return prod;
|
||||||
}
|
}
|
||||||
@@ -57,6 +61,13 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
|||||||
public void setProd(boolean prod) {
|
public void setProd(boolean prod) {
|
||||||
this.prod = prod;
|
this.prod = prod;
|
||||||
}
|
}
|
||||||
|
public FormApi4Cap4 getFormApi4Cap4() {
|
||||||
|
if (this.formApi4Cap4 == null) {
|
||||||
|
this.formApi4Cap4 = (FormApi4Cap4)AppContext.getBean("formApi4Cap4");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.formApi4Cap4;
|
||||||
|
}
|
||||||
|
|
||||||
public FormFactory getFormFactory() {
|
public FormFactory getFormFactory() {
|
||||||
if (formFactory == null) {
|
if (formFactory == null) {
|
||||||
@@ -147,11 +158,11 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
|||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
countDownLatch.await();
|
countDownLatch.await();
|
||||||
|
log.info("宜都城投资产数据同步任务结束,耗时:"+ (System.currentTimeMillis() - startTime)+ " ms");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("宜都城投资产数据同步任务执行失败");
|
log.error("宜都城投资产数据同步任务执行失败");
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
log.info("宜都城投资产数据同步任务结束,耗时:"+ (System.currentTimeMillis() - startTime)+ " ms");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,23 +409,30 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
|||||||
params.add(param);
|
params.add(param);
|
||||||
String querySql = "SELECT * FROM " + table + " "+ whereSql +";";
|
String querySql = "SELECT * FROM " + table + " "+ whereSql +";";
|
||||||
Map<String,Object> existData = null;
|
Map<String,Object> existData = null;
|
||||||
try {
|
|
||||||
List<Map<String, Object>> resList = (List<Map<String, Object>>) agent.execute(querySql, params);
|
List<Map<String, Object>> resList = (List<Map<String, Object>>) agent.execute(querySql, params);
|
||||||
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
||||||
if (existData != null && existData.size() > 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()) {
|
for (String key : targetMap.keySet()) {
|
||||||
existData.put(key,targetMap.get(key)+"");
|
FormFieldBean fieldBean = tableBean.getFieldMap4Display().get(key);
|
||||||
Map<String, Object> updateSqlMap = generateUpdateSql(existData, table, whereSql, param);
|
temp.put(fieldBean.getColumnName(), targetMap.get(key));
|
||||||
agent.execute((String) updateSqlMap.get("sql"),updateSqlMap.get("params"));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
} else {
|
||||||
FormExport formExport = new FormExport();
|
FormExport formExport = new FormExport();
|
||||||
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
||||||
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo, formExport, new String[]{});
|
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo, formExport, new String[]{});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertData(String formNo,Map<String, String> targetMap) throws BusinessException, SQLException, ServiceException {
|
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);
|
params.add(param);
|
||||||
String querySql = "SELECT * FROM " + table +" " + whereSql +";";
|
String querySql = "SELECT * FROM " + table +" " + whereSql +";";
|
||||||
Map<String,Object> existData = null;
|
Map<String,Object> existData = null;
|
||||||
try {
|
|
||||||
List<Map<String, Object>> resList = (List<Map<String, Object>>) agent.execute(querySql, params);
|
List<Map<String, Object>> resList = (List<Map<String, Object>>) agent.execute(querySql, params);
|
||||||
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
existData = resList == null || resList.size() == 0 ? null : resList.get(0);
|
||||||
if (existData != null && existData.size() > 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()) {
|
for (String key : targetMap.keySet()) {
|
||||||
existData.put(key,targetMap.get(key)+"");
|
FormFieldBean fieldBean = tableBean.getFieldMap4Display().get(key);
|
||||||
Map<String, Object> updateSqlMap = generateUpdateSql(existData, table, whereSql, param);
|
temp.put(fieldBean.getColumnName(), targetMap.get(key));
|
||||||
agent.execute((String) updateSqlMap.get("sql"),updateSqlMap.get("params"));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
} else {
|
||||||
FormExport formExport = new FormExport();
|
FormExport formExport = new FormExport();
|
||||||
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
formExport.setValues(FormExportUtil.setFormValue(targetMap));
|
||||||
formExport.setSubordinateForms(FormExportUtil.setSubordinateFormValue(subTableMap));
|
formExport.setSubordinateForms(FormExportUtil.setSubordinateFormValue(subTableMap));
|
||||||
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo, formExport, new String[]{});
|
getFormFactory().importBusinessFormData(getBizConfigByKey(YdzbdataSyncConstants.loginName), formNo, formExport, new String[]{});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()) {
|
if (fieldValues == null || fieldValues.isEmpty()) {
|
||||||
throw new IllegalArgumentException("Field values cannot be null or empty");
|
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
|
// Build the SET clause
|
||||||
int fieldCount = 0;
|
int fieldCount = 0;
|
||||||
for (Map.Entry<String, Object> entry : fieldValues.entrySet()) {
|
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) {
|
if (fieldCount > 0) {
|
||||||
sqlBuilder.append(", ");
|
sqlBuilder.append(", ");
|
||||||
}
|
}
|
||||||
@@ -475,6 +509,7 @@ public class YdzbDataSyncQuartz extends AbstractQuartzTask implements Disposable
|
|||||||
// Append the WHERE clause
|
// Append the WHERE clause
|
||||||
sqlBuilder.append(whereClause);
|
sqlBuilder.append(whereClause);
|
||||||
// Create result map
|
// Create result map
|
||||||
|
sqlBuilder.append(";");
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
result.put("sql", sqlBuilder.toString());
|
result.put("sql", sqlBuilder.toString());
|
||||||
result.put("params", params);
|
result.put("params", params);
|
||||||
|
|||||||
Reference in New Issue
Block a user