api_bbs_w_comment.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package route
  2. import (
  3. "database/sql"
  4. "log"
  5. "opennamu/route/tool"
  6. "strconv"
  7. jsoniter "github.com/json-iterator/go"
  8. )
  9. func Api_bbs_w_comment(call_arg []string) string {
  10. var json = jsoniter.ConfigCompatibleWithStandardLibrary
  11. other_set := map[string]string{}
  12. json.Unmarshal([]byte(call_arg[0]), &other_set)
  13. db := tool.DB_connect()
  14. defer db.Close()
  15. if other_set["tool"] == "length" {
  16. stmt, err := db.Prepare(tool.DB_change("select count(*) from bbs_data where set_name = 'comment_date' and set_id = ? order by set_code + 0 desc"))
  17. if err != nil {
  18. log.Fatal(err)
  19. }
  20. defer stmt.Close()
  21. var comment_length string
  22. bbs_and_post_num := other_set["bbs_num"] + "-" + other_set["post_num"]
  23. err = stmt.QueryRow(bbs_and_post_num).Scan(&comment_length)
  24. if err != nil {
  25. if err == sql.ErrNoRows {
  26. comment_length = "0"
  27. } else {
  28. log.Fatal(err)
  29. }
  30. }
  31. stmt, err = db.Prepare(tool.DB_change("select count(*) from bbs_data where set_name = 'comment_date' and set_id like ? order by set_code + 0 desc"))
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  35. defer stmt.Close()
  36. var reply_length string
  37. err = stmt.QueryRow(bbs_and_post_num + "-%").Scan(&reply_length)
  38. if err != nil {
  39. if err == sql.ErrNoRows {
  40. reply_length = "0"
  41. } else {
  42. log.Fatal(err)
  43. }
  44. }
  45. comment_length_int, _ := strconv.Atoi(comment_length)
  46. reply_length_int, _ := strconv.Atoi(reply_length)
  47. length_int := comment_length_int + reply_length_int
  48. length_str := strconv.Itoa(length_int)
  49. data_list := map[string]string{
  50. "comment": comment_length,
  51. "reply": reply_length,
  52. "data": length_str,
  53. }
  54. json_data, _ := json.Marshal(data_list)
  55. return string(json_data)
  56. } else {
  57. return "{}"
  58. }
  59. }