一、创建计划任务
二、创建方法实现类
创建一个java类,并命名为synchro_org
import com.gani.api.moka.token;
import com.gani.task.moka.synchro_org;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import weaver.conn.RecordSetDataSource;
import weaver.interfaces.schedule.BaseCronJob;
public class synchro_org extends BaseCronJob {
public void execute() {
RecordSetDataSource rsds = new RecordSetDataSource("HR");
String DepartmentSql = "select department_code,name,parent_code,type,sequence from v_moka_department";
String body = _getDepartmentArrayJson(rsds, DepartmentSql);
token.PutRestful("https://*****", "/api-platform/v1/departments", body, "******");
}
/**读数据库**/
public String _getDepartmentArrayJson(RecordSetDataSource rsds, String DepartmentSql) {
String DepartJson = "";
List<Map<String, Object>> Departmentlist = new ArrayList<>();
if (rsds.executeSql(DepartmentSql)) {
String[] metaData = rsds.getColumnName();
int columnCount = rsds.getColCounts();
while (rsds.next()) {
Map<String, Object> DepartItemMap = new HashMap<>();
for (int i = 0; i < columnCount; i++)
DepartItemMap.put(metaData[i].toLowerCase().toString(), rsds.getString(i + 1).toString());
Departmentlist.add(DepartItemMap);
}
}
DepartJson = String.valueOf(JSONArray.fromObject(Departmentlist));
return DepartJson;
}
}