VerifyContract.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package Contract
  2. import (
  3. "ERP_storage/logs"
  4. "git.baozhida.cn/ERP_libs/lib"
  5. orm2 "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. _ "github.com/astaxie/beego/cache/redis"
  8. "github.com/beego/beego/v2/adapter/orm"
  9. _ "github.com/go-sql-driver/mysql"
  10. )
  11. // 验证合同
  12. type VerifyContract struct {
  13. Id int `orm:"column(ID);size(11);auto;pk"`
  14. T_customer string `orm:"size(256);null"` // 客户名称
  15. T_customer_id string `orm:"size(256);null"` // 客户id
  16. T_start_date string `orm:"size(256);null"` // 起始时间
  17. T_end_date string `orm:"size(256);null"` // 终止时间
  18. T_remark string `orm:"type(text);null"` // 备注
  19. T_State int `orm:"size(2);default(1)"` // 0 删除(伪删除) 1-未签约 2-已作废 3-已签约 4-即将到期
  20. T_sign_times int `orm:"size(2);default(1)"` // 签约次数
  21. CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
  22. UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
  23. }
  24. func (t *VerifyContract) TableName() string {
  25. return "verify_contract" // 数据库名称 // ************** 替换 FormulaList **************
  26. }
  27. type VerifyContractDaoImpl struct {
  28. orm orm.Ormer
  29. }
  30. func NewVerifyContract(orm orm.Ormer) *VerifyContractDaoImpl {
  31. return &VerifyContractDaoImpl{orm: orm}
  32. }
  33. func init() {
  34. //注册模型
  35. orm.RegisterModel(new(VerifyContract))
  36. }
  37. type VerifyContract_R struct {
  38. Id int
  39. T_customer string // 客户名称
  40. T_customer_id string // 客户id
  41. T_start_date string // 起始时间
  42. T_end_date string // 终止时间
  43. T_remark string // 备注
  44. T_State int // 1-未签约 2-已作废 3-已签约 4-即将到期
  45. T_sign_times int // 签约次数
  46. }
  47. func VerifyContractToVerifyContract_R(r VerifyContract) (t VerifyContract_R) {
  48. t.Id = r.Id
  49. t.T_customer = r.T_customer
  50. t.T_customer_id = r.T_customer_id
  51. t.T_start_date = r.T_start_date
  52. t.T_end_date = r.T_end_date
  53. t.T_remark = r.T_remark
  54. t.T_State = r.T_State
  55. t.T_sign_times = r.T_sign_times
  56. return t
  57. }
  58. // 添加
  59. func (dao *VerifyContractDaoImpl) Add_VerifyContract(r VerifyContract) (id int64, err error) {
  60. id, err = dao.orm.Insert(&r)
  61. if err != nil {
  62. logs.Error(lib.FuncName(), err)
  63. }
  64. return id, err
  65. }
  66. // 修改
  67. func (dao *VerifyContractDaoImpl) Update_VerifyContract(m VerifyContract, cols ...string) error {
  68. _, err := dao.orm.Update(&m, cols...)
  69. if err != nil {
  70. logs.Error(lib.FuncName(), err)
  71. return err
  72. }
  73. return nil
  74. }
  75. // 获取 ById
  76. func (dao *VerifyContractDaoImpl) Read_VerifyContract_ByT_customer_id(T_customer_id string) (r VerifyContract, err error) {
  77. qs := dao.orm.QueryTable(new(VerifyContract))
  78. err = qs.Filter("T_customer_id", T_customer_id).Filter("T_State__gt", 0).One(&r)
  79. if err != nil {
  80. logs.Error(lib.FuncName(), err)
  81. }
  82. return
  83. }
  84. // 获取列表
  85. func (dao *VerifyContractDaoImpl) Read_VerifyContract_List(T_name string, T_state, page, page_z int) (r_ []VerifyContract_R, cnt int64) {
  86. // 也可以直接使用 Model 结构体作为表名
  87. qs := dao.orm.QueryTable(new(VerifyContract))
  88. var offset int64
  89. if page <= 1 {
  90. offset = 0
  91. } else {
  92. offset = int64((page - 1) * page_z)
  93. }
  94. // 过滤
  95. cond := orm.NewCondition()
  96. cond = cond.And("T_State__gt", 0)
  97. if T_state > 0 {
  98. cond = cond.And("T_State", T_state)
  99. }
  100. if len(T_name) > 0 {
  101. cond = cond.And("T_customer__icontains", T_name)
  102. }
  103. // 查询
  104. var r []VerifyContract
  105. var err error
  106. if page_z == 9999 {
  107. _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-T_State").All(&r)
  108. } else {
  109. _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-T_State").All(&r)
  110. }
  111. if err != nil {
  112. logs.Error(lib.FuncName(), err)
  113. return
  114. }
  115. cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
  116. if err != nil {
  117. logs.Error(lib.FuncName(), err)
  118. return
  119. }
  120. for _, v := range r {
  121. r_ = append(r_, VerifyContractToVerifyContract_R(v))
  122. }
  123. return r_, cnt
  124. }
  125. // 获取全部
  126. func Read_VerifyContract_All_Map() {
  127. o := orm.NewOrm()
  128. var r []VerifyContract
  129. qs := o.QueryTable(new(VerifyContract))
  130. _, err := qs.All(&r)
  131. if err != nil {
  132. logs.Error(lib.FuncName(), err)
  133. }
  134. for _, v := range r {
  135. Contract_list.Store(v.T_customer_id, v.T_customer)
  136. }
  137. }
  138. func Read_VerifyContract_Get(T_customer_id string) string {
  139. v, ok := Contract_list.Load(T_customer_id)
  140. if ok {
  141. return v.(string)
  142. }
  143. return ""
  144. }