| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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 {
- HashMap<String, YxbResult> resultData = new HashMap<>();//数据更新对象
- 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 = 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;
- 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");
- } 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, yxb_datasyncid));
- }
- return getSucReturnObject().setData(JSONObject.from(resultData)).toString();
- }
- @API(title = "营销宝数据同步确认", apiversion = R.ID2026030513573201.v1.class)
- public String getdatareback() throws YosException {
- 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("yxb_datasyncid", Op.LTE, yxb_datasyncid);//将该ID之前的记录全部删除
- deleteSQL.delete();
- }
- return getSucReturnObject().toString();
- }
- @Getter
- @Setter
- class YxbResult {
- public Rows dataRows;
- public ArrayList<String> deleteIDs;
- public long yxb_datasyncid;
- public YxbResult(Rows dataRows, ArrayList<String> deleteIDs, long yxb_datasyncid) {
- this.dataRows = dataRows;
- this.deleteIDs = deleteIDs;
- this.yxb_datasyncid = yxb_datasyncid;
- }
- }
- }
|