IllnessNotice.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package Illness
  2. import (
  3. "FollowUp_Notice/lib"
  4. "FollowUp_Notice/logs"
  5. _ "github.com/astaxie/beego/cache/redis"
  6. "github.com/beego/beego/v2/adapter/orm"
  7. orm2 "github.com/beego/beego/v2/client/orm"
  8. _ "github.com/go-sql-driver/mysql"
  9. "strconv"
  10. "sync"
  11. "time"
  12. )
  13. // 诊断通知
  14. type IllnessNotice struct {
  15. Id int `orm:"column(ID);size(11);auto;pk"`
  16. T_Illness_id int `orm:"size(256);null"` // 名称
  17. T_name string `orm:"size(256);null"` // 名称
  18. T_content string `orm:"size(1024);null"` // 名称
  19. T_State int `orm:"size(2);default(1)"` // 0 删除(伪删除) 1 正常
  20. T_template_id string `orm:"size(20);default(0)"` // 短信模版id
  21. T_template_status string `orm:"size(20);default(0)"` // 赛邮云短信审核状态
  22. T_template_status_description string `orm:"size(1024);null"` // 赛邮云短信审核描述
  23. T_template_reject_reson string `orm:"size(1024);null"` // 赛邮云短信审核原因
  24. CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
  25. UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
  26. }
  27. func (t *IllnessNotice) TableName() string {
  28. return "illness_notice"
  29. }
  30. var IllnessNotice_list *sync.Map
  31. func init() {
  32. //注册模型
  33. orm.RegisterModel(new(IllnessNotice))
  34. IllnessNotice_list = new(sync.Map)
  35. }
  36. type IllnessNotice_R struct {
  37. Id int
  38. T_Illness_id int // 名称
  39. T_name string // 名称
  40. T_content string // 名称
  41. T_State int // 0 删除(伪删除) 1 正常
  42. T_template_id string // 模版id
  43. T_template_status string // 赛邮云审核状态 0-未提交审核 1-正在审核 2-审核通过 3-未通过审核
  44. T_template_status_description string // 赛邮云审核描述
  45. T_template_reject_reson string // 赛邮云审核原因
  46. CreateTime string //auto_now_add 第一次保存时才设置时间
  47. UpdateTime string //auto_now 每次 model 保存时都会对时间自动更新
  48. }
  49. func IllnessNoticeToIllnessNotice_R(t IllnessNotice) (r IllnessNotice_R) {
  50. r.Id = t.Id
  51. r.T_Illness_id = t.T_Illness_id
  52. r.T_name = t.T_name
  53. r.T_content = t.T_content
  54. r.T_State = t.T_State
  55. r.T_template_id = t.T_template_id
  56. r.T_template_status = t.T_template_status
  57. r.T_template_status_description = t.T_template_status_description
  58. r.T_template_reject_reson = t.T_template_reject_reson
  59. r.CreateTime = t.CreateTime.Format("2006-01-02 15:04:05")
  60. r.UpdateTime = t.UpdateTime.Format("2006-01-02 15:04:05")
  61. return r
  62. }
  63. // 添加
  64. func Add_IllnessNotice(r IllnessNotice) (id int64, err error) {
  65. o := orm.NewOrm()
  66. id, err = o.Insert(&r)
  67. if err != nil {
  68. logs.Error(lib.FuncName(), err)
  69. }
  70. return id, err
  71. }
  72. // 获取 ById
  73. func Read_IllnessNotice_ById(Id int) (r IllnessNotice, err error) {
  74. o := orm.NewOrm()
  75. qs := o.QueryTable(new(IllnessNotice))
  76. err = qs.Filter("Id", Id).One(&r)
  77. if err != nil {
  78. logs.Error(lib.FuncName(), err)
  79. }
  80. return
  81. }
  82. // 修改
  83. func Update_IllnessNotice(m IllnessNotice, cols ...string) error {
  84. o := orm.NewOrm()
  85. _, err := o.Update(&m, cols...)
  86. if err != nil {
  87. logs.Error(lib.FuncName(), err)
  88. return err
  89. }
  90. return nil
  91. }
  92. // 删除
  93. func Delete_IllnessNotice(v IllnessNotice) error {
  94. o := orm.NewOrm()
  95. v.T_State = 0
  96. _, err := o.Update(&v, "T_State")
  97. if err != nil {
  98. logs.Error(lib.FuncName(), err)
  99. }
  100. return err
  101. }
  102. // 获取列表
  103. func Read_IllnessNotice_List(T_Illness_id int, T_name, T_template_status string, page, page_z int) (r_ []IllnessNotice_R, cnt int64) {
  104. o := orm.NewOrm()
  105. // 也可以直接使用 Model 结构体作为表名
  106. qs := o.QueryTable(new(IllnessNotice))
  107. var offset int64
  108. if page <= 1 {
  109. offset = 0
  110. } else {
  111. offset = int64((page - 1) * page_z)
  112. }
  113. // 过滤
  114. cond := orm.NewCondition()
  115. cond = cond.And("T_State", 1)
  116. if T_Illness_id > 0 {
  117. cond = cond.And("T_Illness_id", T_Illness_id)
  118. }
  119. if len(T_name) > 0 {
  120. cond = cond.And("T_name__icontains", T_name)
  121. }
  122. if len(T_template_status) > 0 {
  123. cond = cond.And("T_template_status", T_template_status)
  124. }
  125. // 查询
  126. var r []IllnessNotice
  127. var err error
  128. if page_z == 9999 {
  129. _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&r)
  130. } else {
  131. _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&r)
  132. }
  133. if err != nil {
  134. logs.Error(lib.FuncName(), err)
  135. return
  136. }
  137. cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
  138. if err != nil {
  139. logs.Error(lib.FuncName(), err)
  140. return
  141. }
  142. for _, v := range r {
  143. r_ = append(r_, IllnessNoticeToIllnessNotice_R(v))
  144. }
  145. return r_, cnt
  146. }
  147. func Read_IllnessNotice_Count_ByT_uid(T_uid int) (cnt int64) {
  148. o := orm.NewOrm()
  149. var count int64
  150. sql := "SELECT count(*) FROM illness_notice left JOIN illness on illness.ID = illness_notice.t__illness_id " +
  151. "WHERE t_uid = " + strconv.Itoa(T_uid)
  152. err := o.Raw(sql).QueryRow(&count)
  153. if err != nil {
  154. logs.Error(lib.FuncName(), err)
  155. return
  156. }
  157. return count
  158. }
  159. // 获取疾病
  160. func Read_IllnessNotice_All_Map() {
  161. o := orm.NewOrm()
  162. var r []IllnessNotice
  163. qs := o.QueryTable(new(IllnessNotice))
  164. _, err := qs.All(&r)
  165. if err != nil {
  166. logs.Error(lib.FuncName(), err)
  167. }
  168. for _, v := range r {
  169. IllnessNotice_list.Store(v.Id, v.T_name)
  170. }
  171. }
  172. func Read_IllnessNotice_Get(Id int) string {
  173. // 有先加入 给全部人发消息
  174. v, ok := IllnessNotice_list.Load(Id) /*如果确定是真实的,则存在,否则不存在 */
  175. if ok {
  176. return v.(string)
  177. } else {
  178. return ""
  179. }
  180. }