datacollect.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package restcontroller.system.datacollect;
  2. import com.alibaba.fastjson.JSONObject;
  3. import common.Controller;
  4. import common.YosException;
  5. import common.annotation.API;
  6. import common.data.*;
  7. import restcontroller.R;
  8. public class datacollect extends Controller {
  9. /**
  10. * 构造函数
  11. *
  12. * @param content
  13. */
  14. public datacollect(JSONObject content) throws YosException {
  15. super(content);
  16. }
  17. @API(title = "数据收藏", apiversion = R.ID20240416133702.v1.class)
  18. public String isCollect() throws YosException {
  19. String ownertable = content.getStringValue("ownertable");
  20. Long ownerid = content.getLongValue("ownerid");
  21. int type = content.getIntValue("type");
  22. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_datacollect");
  23. querySQL.setSiteid(siteid);
  24. querySQL.setWhere("userid", userid);
  25. querySQL.setWhere("ownertable", ownertable);
  26. querySQL.setWhere("ownerid", ownerid);
  27. querySQL.setWhere("type", type);
  28. Rows rows = querySQL.query();
  29. if (rows.isNotEmpty()) {
  30. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_datacollect");
  31. deleteSQL.setSiteid(siteid);
  32. deleteSQL.setUniqueid(rows.get(0).getLong("sys_datacollectid"));
  33. deleteSQL.delete();
  34. } else {
  35. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_datacollect");
  36. insertSQL.setUniqueid(createTableID("sys_datacollect"));
  37. insertSQL.setSiteid(siteid);
  38. insertSQL.setValue("userid", userid);
  39. insertSQL.setValue("ownertable", ownertable);
  40. insertSQL.setValue("ownerid", ownerid);
  41. insertSQL.setValue("type", type);
  42. insertSQL.insert();
  43. }
  44. if (ownertable.equals("sat_sharematerial")) {
  45. updateSharematerial(ownerid, type);
  46. }
  47. return getSucReturnObject().toString();
  48. }
  49. public void updateSharematerial(Long ownerid, int type) throws YosException {
  50. Row row = dbConnect.runSqlQuery(0, "SELECT count(*) count from sys_datacollect WHERE ownertable='sat_sharematerial' and ownerid=" + ownerid + " and type=" + type + " and siteid='" + siteid + "'");
  51. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
  52. updateSQL.setSiteid(siteid);
  53. updateSQL.setUniqueid(ownerid);
  54. if (type == 1) {
  55. updateSQL.setValue("collectcount", row.getLong("count"));
  56. } else {
  57. updateSQL.setValue("likecount", row.getLong("count"));
  58. }
  59. updateSQL.update();
  60. }
  61. }