|
@@ -0,0 +1,79 @@
|
|
|
|
|
+package restcontroller.yxb;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import common.Controller;
|
|
|
|
|
+import common.YosException;
|
|
|
|
|
+import common.annotation.API;
|
|
|
|
|
+import common.data.*;
|
|
|
|
|
+import lombok.Getter;
|
|
|
|
|
+import lombok.Setter;
|
|
|
|
|
+import restcontroller.R;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+
|
|
|
|
|
+public class yxb extends Controller {
|
|
|
|
|
+ public yxb(JSONObject content) throws YosException {
|
|
|
|
|
+ super(content);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @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 + "'");
|
|
|
|
|
+ }
|
|
|
|
|
+ RowsMap rowsMap = yxb_datasyncRows.toRowsMap("ownertable");
|
|
|
|
|
+ for (String tablename : rowsMap.keySet()) {
|
|
|
|
|
+ String uniquecolumnname = getuniquecolumnname(tablename);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ querySQL = SQLFactory.createQuerySQL(this, tablename);
|
|
|
|
|
+ querySQL.setWhere(uniquecolumnname, idlist);
|
|
|
|
|
+ }
|
|
|
|
|
+ Rows datarows = querySQL.query();//查询出所有的待同步的数据
|
|
|
|
|
+ idlist.removeAll(datarows.toArrayList(uniquecolumnname));//排除存在的数据id,即为已经删除的数据的数据ID
|
|
|
|
|
+ resultData.put(tablename, new YxbResult(datarows, idlist));
|
|
|
|
|
+ }
|
|
|
|
|
+ return getSucReturnObject().setData(JSONObject.from(resultData)).toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @API(title = "营销宝数据同步确认", apiversion = R.ID2026030513573201.v1.class)
|
|
|
|
|
+ public String getdatareback() throws YosException {
|
|
|
|
|
+ String lastrequestdata = content.getStringValue("lastrequestdata");//上次请求的时间
|
|
|
|
|
+ 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.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ return getSucReturnObject().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Getter
|
|
|
|
|
+ @Setter
|
|
|
|
|
+ class YxbResult {
|
|
|
|
|
+ public Rows dataRows;
|
|
|
|
|
+ public ArrayList<String> deleteIDs;
|
|
|
|
|
+
|
|
|
|
|
+ public YxbResult(Rows dataRows, ArrayList<String> deleteIDs) {
|
|
|
|
|
+ this.dataRows = dataRows;
|
|
|
|
|
+ this.deleteIDs = deleteIDs;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|