123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- package Illness
- import (
- "FollowUp_Notice/lib"
- "FollowUp_Notice/logs"
- _ "github.com/astaxie/beego/cache/redis"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- _ "github.com/go-sql-driver/mysql"
- "strconv"
- "sync"
- "time"
- )
- // 诊断通知
- type IllnessNotice struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_Illness_id int `orm:"size(256);null"` // 名称
- T_name string `orm:"size(256);null"` // 名称
- T_content string `orm:"size(1024);null"` // 名称
- T_State int `orm:"size(2);default(1)"` // 0 删除(伪删除) 1 正常
- T_template_id string `orm:"size(20);default(0)"` // 短信模版id
- T_template_status string `orm:"size(20);default(0)"` // 赛邮云短信审核状态
- T_template_status_description string `orm:"size(1024);null"` // 赛邮云短信审核描述
- T_template_reject_reson string `orm:"size(1024);null"` // 赛邮云短信审核原因
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
- UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
- }
- func (t *IllnessNotice) TableName() string {
- return "illness_notice"
- }
- var IllnessNotice_list *sync.Map
- func init() {
- //注册模型
- orm.RegisterModel(new(IllnessNotice))
- IllnessNotice_list = new(sync.Map)
- }
- type IllnessNotice_R struct {
- Id int
- T_Illness_id int // 名称
- T_name string // 名称
- T_content string // 名称
- T_State int // 0 删除(伪删除) 1 正常
- T_template_id string // 模版id
- T_template_status string // 赛邮云审核状态 0-未提交审核 1-正在审核 2-审核通过 3-未通过审核
- T_template_status_description string // 赛邮云审核描述
- T_template_reject_reson string // 赛邮云审核原因
- CreateTime string //auto_now_add 第一次保存时才设置时间
- UpdateTime string //auto_now 每次 model 保存时都会对时间自动更新
- }
- func IllnessNoticeToIllnessNotice_R(t IllnessNotice) (r IllnessNotice_R) {
- r.Id = t.Id
- r.T_Illness_id = t.T_Illness_id
- r.T_name = t.T_name
- r.T_content = t.T_content
- r.T_State = t.T_State
- r.T_template_id = t.T_template_id
- r.T_template_status = t.T_template_status
- r.T_template_status_description = t.T_template_status_description
- r.T_template_reject_reson = t.T_template_reject_reson
- r.CreateTime = t.CreateTime.Format("2006-01-02 15:04:05")
- r.UpdateTime = t.UpdateTime.Format("2006-01-02 15:04:05")
- return r
- }
- // 添加
- func Add_IllnessNotice(r IllnessNotice) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Insert(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- return id, err
- }
- // 获取 ById
- func Read_IllnessNotice_ById(Id int) (r IllnessNotice, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(IllnessNotice))
- err = qs.Filter("Id", Id).One(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- return
- }
- // 修改
- func Update_IllnessNotice(m IllnessNotice, cols ...string) error {
- o := orm.NewOrm()
- _, err := o.Update(&m, cols...)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return err
- }
- return nil
- }
- // 删除
- func Delete_IllnessNotice(v IllnessNotice) error {
- o := orm.NewOrm()
- v.T_State = 0
- _, err := o.Update(&v, "T_State")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- return err
- }
- // 获取列表
- func Read_IllnessNotice_List(T_Illness_id int, T_name, T_template_status string, page, page_z int) (r_ []IllnessNotice_R, cnt int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- qs := o.QueryTable(new(IllnessNotice))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- // 过滤
- cond := orm.NewCondition()
- cond = cond.And("T_State", 1)
- if T_Illness_id > 0 {
- cond = cond.And("T_Illness_id", T_Illness_id)
- }
- if len(T_name) > 0 {
- cond = cond.And("T_name__icontains", T_name)
- }
- if len(T_template_status) > 0 {
- cond = cond.And("T_template_status", T_template_status)
- }
- // 查询
- var r []IllnessNotice
- var err error
- if page_z == 9999 {
- _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&r)
- } else {
- _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&r)
- }
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range r {
- r_ = append(r_, IllnessNoticeToIllnessNotice_R(v))
- }
- return r_, cnt
- }
- func Read_IllnessNotice_Count_ByT_uid(T_uid int) (cnt int64) {
- o := orm.NewOrm()
- var count int64
- sql := "SELECT count(*) FROM illness_notice left JOIN illness on illness.ID = illness_notice.t__illness_id " +
- "WHERE t_uid = " + strconv.Itoa(T_uid)
- err := o.Raw(sql).QueryRow(&count)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- return count
- }
- // 获取疾病
- func Read_IllnessNotice_All_Map() {
- o := orm.NewOrm()
- var r []IllnessNotice
- qs := o.QueryTable(new(IllnessNotice))
- _, err := qs.All(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- for _, v := range r {
- IllnessNotice_list.Store(v.Id, v.T_name)
- }
- }
- func Read_IllnessNotice_Get(Id int) string {
- // 有先加入 给全部人发消息
- v, ok := IllnessNotice_list.Load(Id) /*如果确定是真实的,则存在,否则不存在 */
- if ok {
- return v.(string)
- } else {
- return ""
- }
- }
|