Dept.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package Account
  2. import (
  3. "ERP_user/logs"
  4. "github.com/beego/beego/v2/adapter/orm"
  5. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  6. "sync"
  7. "time"
  8. )
  9. type Dept struct {
  10. Id int `orm:"column(ID);size(11);auto;pk"`
  11. T_name string `orm:"size(256);null"` // 部门名称
  12. T_mid int `orm:"size(256);null"` // Dept.Id T_mid=0 部门 T_mid>0岗位
  13. T_State int `orm:"size(200);default(1)"` // 0删除 1 正常
  14. }
  15. var Dept_list *sync.Map
  16. func init() {
  17. //注册模型
  18. orm.RegisterModel(new(Dept))
  19. Dept_list = new(sync.Map)
  20. }
  21. // 获取全部
  22. func Read_Dept_All_Map() {
  23. logs.Println("=========== 初始化部门类型 =========")
  24. o := orm.NewOrm()
  25. for true {
  26. var r []Dept
  27. qs := o.QueryTable(new(Dept))
  28. _, err := qs.Filter("T_State", 1).All(&r)
  29. if err != nil {
  30. logs.Error(lib.FuncName(), err)
  31. }
  32. for _, v := range r {
  33. Dept_list.Store(v.Id, v.T_name)
  34. }
  35. time.Sleep(1 * time.Hour)
  36. }
  37. }
  38. func Read_Dept_Get(Id int) string {
  39. v, ok := Dept_list.Load(Id)
  40. if ok {
  41. return v.(string)
  42. } else {
  43. return ""
  44. }
  45. }
  46. func Read_Dept_List() (r []Dept) {
  47. o := orm.NewOrm()
  48. qs := o.QueryTable(new(Dept))
  49. _, err := qs.Filter("T_State", 1).Filter("T_mid", 0).All(&r)
  50. if err != nil {
  51. logs.Error(lib.FuncName(), err)
  52. return r
  53. }
  54. return r
  55. }
  56. func Read_Post_List(T_dept int) (r []Dept) {
  57. o := orm.NewOrm()
  58. qs := o.QueryTable(new(Dept))
  59. _, err := qs.Filter("T_State", 1).Filter("T_mid", T_dept).All(&r)
  60. if err != nil {
  61. logs.Error(lib.FuncName(), err)
  62. return r
  63. }
  64. return r
  65. }