package Contract import ( "ERP_storage/logs" "git.baozhida.cn/ERP_libs/lib" orm2 "github.com/beego/beego/v2/client/orm" "time" _ "github.com/astaxie/beego/cache/redis" "github.com/beego/beego/v2/adapter/orm" _ "github.com/go-sql-driver/mysql" ) // 验证合同 type VerifyContract struct { Id int `orm:"column(ID);size(11);auto;pk"` T_customer string `orm:"size(256);null"` // 客户名称 T_customer_id string `orm:"size(256);null"` // 客户id T_start_date string `orm:"size(256);null"` // 起始时间 T_end_date string `orm:"size(256);null"` // 终止时间 T_remark string `orm:"type(text);null"` // 备注 T_State int `orm:"size(2);default(1)"` // 0 删除(伪删除) 1-未签约 2-已作废 3-已签约 4-即将到期 T_sign_times int `orm:"size(2);default(1)"` // 签约次数 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 *VerifyContract) TableName() string { return "verify_contract" // 数据库名称 // ************** 替换 FormulaList ************** } type VerifyContractDaoImpl struct { orm orm.Ormer } func NewVerifyContract(orm orm.Ormer) *VerifyContractDaoImpl { return &VerifyContractDaoImpl{orm: orm} } func init() { //注册模型 orm.RegisterModel(new(VerifyContract)) } type VerifyContract_R struct { Id int T_customer string // 客户名称 T_customer_id string // 客户id T_start_date string // 起始时间 T_end_date string // 终止时间 T_remark string // 备注 T_State int // 1-未签约 2-已作废 3-已签约 4-即将到期 T_sign_times int // 签约次数 } func VerifyContractToVerifyContract_R(r VerifyContract) (t VerifyContract_R) { t.Id = r.Id t.T_customer = r.T_customer t.T_customer_id = r.T_customer_id t.T_start_date = r.T_start_date t.T_end_date = r.T_end_date t.T_remark = r.T_remark t.T_State = r.T_State t.T_sign_times = r.T_sign_times return t } // 添加 func (dao *VerifyContractDaoImpl) Add_VerifyContract(r VerifyContract) (id int64, err error) { id, err = dao.orm.Insert(&r) if err != nil { logs.Error(lib.FuncName(), err) } return id, err } // 修改 func (dao *VerifyContractDaoImpl) Update_VerifyContract(m VerifyContract, cols ...string) error { _, err := dao.orm.Update(&m, cols...) if err != nil { logs.Error(lib.FuncName(), err) return err } return nil } // 获取 ById func (dao *VerifyContractDaoImpl) Read_VerifyContract_ByT_customer_id(T_customer_id string) (r VerifyContract, err error) { qs := dao.orm.QueryTable(new(VerifyContract)) err = qs.Filter("T_customer_id", T_customer_id).Filter("T_State__gt", 0).One(&r) if err != nil { logs.Error(lib.FuncName(), err) } return } // 获取列表 func (dao *VerifyContractDaoImpl) Read_VerifyContract_List(T_name string, T_state, page, page_z int) (r_ []VerifyContract_R, cnt int64) { // 也可以直接使用 Model 结构体作为表名 qs := dao.orm.QueryTable(new(VerifyContract)) var offset int64 if page <= 1 { offset = 0 } else { offset = int64((page - 1) * page_z) } // 过滤 cond := orm.NewCondition() cond = cond.And("T_State__gt", 0) if T_state > 0 { cond = cond.And("T_State", T_state) } if len(T_name) > 0 { cond = cond.And("T_customer__icontains", T_name) } // 查询 var r []VerifyContract var err error if page_z == 9999 { _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-T_State").All(&r) } else { _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-T_State").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_, VerifyContractToVerifyContract_R(v)) } return r_, cnt } // 获取全部 func Read_VerifyContract_All_Map() { o := orm.NewOrm() var r []VerifyContract qs := o.QueryTable(new(VerifyContract)) _, err := qs.All(&r) if err != nil { logs.Error(lib.FuncName(), err) } for _, v := range r { Contract_list.Store(v.T_customer_id, v.T_customer) } } func Read_VerifyContract_Get(T_customer_id string) string { v, ok := Contract_list.Load(T_customer_id) if ok { return v.(string) } return "" }