|
|
@@ -20,46 +20,52 @@ public class yxb extends Controller {
|
|
|
|
|
|
@API(title = "营销宝数据同步查询", apiversion = R.ID2026030512342901.v1.class)
|
|
|
public String getdata() throws YosException {
|
|
|
- String lastrequestdata = content.getStringValue("lastrequestdata");//上次请求的时间
|
|
|
HashMap<String, YxbResult> resultData = new HashMap<>();//数据更新对象
|
|
|
|
|
|
- Rows yxb_datasyncRows;
|
|
|
- if (lastrequestdata.isEmpty()) {
|
|
|
- yxb_datasyncRows = dbConnect.runSqlQuery("select ownertable,ownerid from yxb_datasync");
|
|
|
- } else {
|
|
|
- yxb_datasyncRows = dbConnect.runSqlQuery("select ownertable,ownerid from yxb_datasync where changedate>'" + lastrequestdata + "'");
|
|
|
+ long yxb_datasyncid = 0;
|
|
|
+ Rows maxyxb_datasync = dbConnect.runSqlQuery("select max(yxb_datasyncid)as yxb_datasyncid from yxb_datasync");
|
|
|
+ if (maxyxb_datasync.isNotEmpty()) {
|
|
|
+ yxb_datasyncid = maxyxb_datasync.get(0).getLong("yxb_datasyncid");
|
|
|
}
|
|
|
- RowsMap rowsMap = yxb_datasyncRows.toRowsMap("ownertable");
|
|
|
+
|
|
|
+ RowsMap rowsMap = dbConnect.runSqlQuery("select ownertable,ownerid from yxb_datasync where yxb_datasyncid<=" + yxb_datasyncid + " group by ownertable,ownerid").toRowsMap("ownertable");
|
|
|
for (String tablename : rowsMap.keySet()) {
|
|
|
String uniquecolumnname = getuniquecolumnname(tablename);
|
|
|
+
|
|
|
+ Rows datasyncRows = rowsMap.get(tablename);
|
|
|
+ ArrayList<String> idlist = datasyncRows.toArrayList("ownerid");//当前表的所有待更新数据ID
|
|
|
QuerySQL querySQL;
|
|
|
- ArrayList<String> idlist = rowsMap.get(tablename).toArrayList("ownerid");//当前表的所有待更新数据ID
|
|
|
if (tablename.equalsIgnoreCase("sys_userrole")) {
|
|
|
//如果是账号角色授权表,则单独处理
|
|
|
querySQL = SQLFactory.createQuerySQL(this, tablename, "userid").setTableAlias("t1");
|
|
|
querySQL.addJoinTable(JOINTYPE.inner, "sys_role", "t2", "t1.roleid=t2.roleid", "rolename", "remarks");
|
|
|
querySQL.setWhere(uniquecolumnname, idlist);
|
|
|
+ querySQL.setDistinct(true);
|
|
|
+ } else if (tablename.equalsIgnoreCase("sys_users")) {
|
|
|
+ querySQL = SQLFactory.createQuerySQL(this, tablename, "userid", "accountno", "name", "status", "phonenumber");
|
|
|
+ querySQL.setWhere("accountno!='admin'");
|
|
|
} else {
|
|
|
querySQL = SQLFactory.createQuerySQL(this, tablename);
|
|
|
querySQL.setWhere(uniquecolumnname, idlist);
|
|
|
}
|
|
|
- Rows datarows = querySQL.query();//查询出所有的待同步的数据
|
|
|
+ Rows datarows = querySQL.query();
|
|
|
+ //查询出所有的待同步的数据
|
|
|
idlist.removeAll(datarows.toArrayList(uniquecolumnname));//排除存在的数据id,即为已经删除的数据的数据ID
|
|
|
- resultData.put(tablename, new YxbResult(datarows, idlist));
|
|
|
+ resultData.put(tablename, new YxbResult(datarows, idlist, yxb_datasyncid));
|
|
|
}
|
|
|
return getSucReturnObject().setData(JSONObject.from(resultData)).toString();
|
|
|
}
|
|
|
|
|
|
@API(title = "营销宝数据同步确认", apiversion = R.ID2026030513573201.v1.class)
|
|
|
public String getdatareback() throws YosException {
|
|
|
- String lastrequestdata = content.getStringValue("lastrequestdata");//上次请求的时间
|
|
|
+ long yxb_datasyncid = content.getLongValue("yxb_datasyncid");
|
|
|
String tablename = content.getStringValue("tablename");
|
|
|
JSONArray ids = content.getJSONArray("ids");
|
|
|
if (!ids.isEmpty()) {
|
|
|
DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "yxb_datasync");
|
|
|
deleteSQL.setWhere("ownertable", tablename);
|
|
|
deleteSQL.setWhere("ownerid", ids);
|
|
|
- deleteSQL.setWhere("changedate", Op.LTE, lastrequestdata);//将该时间之前的记录全部删除
|
|
|
+ deleteSQL.setWhere("changedate", Op.LTE, yxb_datasyncid);//将该ID之前的记录全部删除
|
|
|
deleteSQL.delete();
|
|
|
}
|
|
|
return getSucReturnObject().toString();
|
|
|
@@ -70,10 +76,12 @@ public class yxb extends Controller {
|
|
|
class YxbResult {
|
|
|
public Rows dataRows;
|
|
|
public ArrayList<String> deleteIDs;
|
|
|
+ public long yxb_datasyncid;
|
|
|
|
|
|
- public YxbResult(Rows dataRows, ArrayList<String> deleteIDs) {
|
|
|
+ public YxbResult(Rows dataRows, ArrayList<String> deleteIDs, long yxb_datasyncid) {
|
|
|
this.dataRows = dataRows;
|
|
|
this.deleteIDs = deleteIDs;
|
|
|
+ this.yxb_datasyncid = yxb_datasyncid;
|
|
|
}
|
|
|
}
|
|
|
}
|