1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package Account
- import (
- "ERP_user/logs"
- "git.baozhida.cn/ERP_libs/lib"
- "github.com/beego/beego/v2/adapter/orm"
- "sync"
- "time"
- )
- type Dept struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_name string `orm:"size(256);null"` // 部门名称
- T_mid int `orm:"size(256);null"` // Dept.Id T_mid=0 部门 T_mid>0岗位
- T_State int `orm:"size(200);default(1)"` // 0删除 1 正常
- }
- var Dept_list *sync.Map
- func init() {
- //注册模型
- orm.RegisterModel(new(Dept))
- Dept_list = new(sync.Map)
- }
- // 获取全部
- func Read_Dept_All_Map() {
- logs.Println("=========== 初始化部门类型 =========")
- o := orm.NewOrm()
- for true {
- var r []Dept
- qs := o.QueryTable(new(Dept))
- _, err := qs.Filter("T_State", 1).All(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- for _, v := range r {
- Dept_list.Store(v.Id, v.T_name)
- }
- time.Sleep(1 * time.Hour)
- }
- }
- func Read_Dept_Get(Id int) string {
- v, ok := Dept_list.Load(Id)
- if ok {
- return v.(string)
- } else {
- return ""
- }
- }
- func Read_Dept_List() (r []Dept) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Dept))
- _, err := qs.Filter("T_State", 1).Filter("T_mid", 0).All(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r
- }
- return r
- }
- func Read_Post_List(T_dept int) (r []Dept) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(Dept))
- _, err := qs.Filter("T_State", 1).Filter("T_mid", T_dept).All(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r
- }
- return r
- }
|