package restcontroller.system.datacollect; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.data.*; import restcontroller.R; public class datacollect extends Controller { /** * 构造函数 * * @param content */ public datacollect(JSONObject content) throws YosException { super(content); } @API(title = "数据收藏", apiversion = R.ID20240416133702.v1.class) public String isCollect() throws YosException { String ownertable = content.getStringValue("ownertable"); Long ownerid = content.getLongValue("ownerid"); int type = content.getIntValue("type"); QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_datacollect"); querySQL.setSiteid(siteid); querySQL.setWhere("userid", userid); querySQL.setWhere("ownertable", ownertable); querySQL.setWhere("ownerid", ownerid); querySQL.setWhere("type", type); Rows rows = querySQL.query(); if (rows.isNotEmpty()) { DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_datacollect"); deleteSQL.setSiteid(siteid); deleteSQL.setUniqueid(rows.get(0).getLong("sys_datacollectid")); deleteSQL.delete(); } else { InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_datacollect"); insertSQL.setUniqueid(createTableID("sys_datacollect")); insertSQL.setSiteid(siteid); insertSQL.setValue("userid", userid); insertSQL.setValue("ownertable", ownertable); insertSQL.setValue("ownerid", ownerid); insertSQL.setValue("type", type); insertSQL.insert(); } if (ownertable.equals("sat_sharematerial")) { updateSharematerial(ownerid, type); } return getSucReturnObject().toString(); } public void updateSharematerial(Long ownerid, int type) throws YosException { Row row = dbConnect.runSqlQuery(0, "SELECT count(*) count from sys_datacollect WHERE ownertable='sat_sharematerial' and ownerid=" + ownerid + " and type=" + type + " and siteid='" + siteid + "'"); UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial"); updateSQL.setSiteid(siteid); updateSQL.setUniqueid(ownerid); if (type == 1) { updateSQL.setValue("collectcount", row.getLong("count")); } else { updateSQL.setValue("likecount", row.getLong("count")); } updateSQL.update(); } }