Certificate.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package Certificate
  2. import (
  3. "ColdVerify_local/conf"
  4. "ColdVerify_local/lib"
  5. "ColdVerify_local/logs"
  6. "fmt"
  7. orm2 "github.com/beego/beego/v2/client/orm"
  8. _ "github.com/go-sql-driver/mysql"
  9. "strconv"
  10. )
  11. type Certificate_ struct {
  12. Id int `orm:"column(ID)"`
  13. T_sn string // 编号
  14. T_layout_no string // 布局编号
  15. }
  16. // 获取列表
  17. func Read_Certificate_List(T_task_id, T_sn string, page, page_z int) ([]Certificate_, int64) {
  18. serverOrm := orm2.NewOrmUsingDB(conf.Server_AliasName)
  19. localOrm := orm2.NewOrmUsingDB(conf.Local_AliasName)
  20. pagez := page_z
  21. var offset int
  22. if page <= 1 {
  23. offset = 0
  24. } else {
  25. page -= 1
  26. offset = page * pagez
  27. }
  28. var maps []Certificate_
  29. idList := []string{}
  30. sql := "SELECT t_id FROM z_task_data_" + T_task_id + " GROUP BY t_id"
  31. fmt.Println(sql)
  32. _, err := localOrm.Raw(sql).QueryRows(&idList)
  33. if err != nil {
  34. logs.Error(lib.FuncName(), err)
  35. return maps, 0
  36. }
  37. idListStr := ""
  38. for _, id := range idList {
  39. if idListStr != "" {
  40. idListStr = idListStr + ","
  41. }
  42. idListStr = idListStr + "'" + id + "'"
  43. }
  44. sql_condition := " t__state=1"
  45. if len(idListStr) > 0 {
  46. sql_condition += " AND t_layout_no not in (" + idListStr + ")"
  47. }
  48. if len(T_sn) > 0 {
  49. sql_condition += " AND t_layout_no='" + T_sn + "'"
  50. }
  51. sql = "SELECT count(*) FROM certificate WHERE" + sql_condition
  52. fmt.Println(sql)
  53. var count int64
  54. err = serverOrm.Raw(sql).QueryRow(&count)
  55. if err != nil {
  56. return maps, 0
  57. }
  58. //sql = "SELECT * FROM certificate WHERE t__state=1 AND t_sn not in (" + strings.Join(snList, ",") + ") ORDER BY t_layout_no"
  59. // fixme 冷脸验证线上更新后再部署如下代码
  60. sql = "SELECT ID,t_layout_no FROM certificate WHERE" + sql_condition
  61. if page_z != 9999 {
  62. sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(pagez)
  63. }
  64. fmt.Println(sql)
  65. _, err = serverOrm.Raw(sql).QueryRows(&maps)
  66. if err != nil {
  67. logs.Error(lib.FuncName(), err)
  68. return maps, 0
  69. }
  70. return maps, count
  71. }