StockIn.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package Stock
  2. import (
  3. "ERP_storage/models/Account"
  4. "ERP_storage/models/Basic"
  5. "git.baozhida.cn/ERP_libs/lib"
  6. orm2 "github.com/beego/beego/v2/client/orm"
  7. "time"
  8. "ERP_storage/logs"
  9. _ "github.com/astaxie/beego/cache/redis"
  10. "github.com/beego/beego/v2/adapter/orm"
  11. _ "github.com/go-sql-driver/mysql"
  12. )
  13. // 入库
  14. type StockIn struct {
  15. Id int `orm:"column(ID);size(11);auto;pk"`
  16. T_number string `orm:"size(256);null"` // 入库单号
  17. T_depot_id int `orm:"size(20);null"` // 仓库id
  18. T_date string `orm:"size(256);null"` // 业务日期
  19. T_submit string `orm:"size(256);null"` // 经办人
  20. T_remark string `orm:"type(text);null"` // 备注
  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 *StockIn) TableName() string {
  25. return "stock_in" // 数据库名称 // ************** 替换 FormulaList **************
  26. }
  27. type StockInDaoImpl struct {
  28. orm orm.Ormer
  29. }
  30. func NewStockIn(orm orm.Ormer) *StockInDaoImpl {
  31. return &StockInDaoImpl{orm: orm}
  32. }
  33. func init() {
  34. //注册模型
  35. orm.RegisterModel(new(StockIn))
  36. }
  37. type StockIn_R struct {
  38. Id int
  39. T_number string
  40. T_depot_id int
  41. T_depot_name string
  42. T_date string
  43. T_submit string
  44. T_submit_name string
  45. T_remark string
  46. }
  47. type StockIn_Detail struct {
  48. Id int
  49. T_number string
  50. T_depot_id int
  51. T_depot_name string
  52. T_date string
  53. T_submit string
  54. T_submit_name string
  55. T_remark string
  56. T_Product []StockInProduct_R
  57. }
  58. func StockInToStockIn_R(t StockIn) (r StockIn_R) {
  59. r.Id = t.Id
  60. r.T_number = t.T_number
  61. r.T_depot_id = t.T_depot_id
  62. r.T_depot_name = Basic.Read_Depot_Get(t.T_depot_id)
  63. r.T_date = t.T_date
  64. r.T_submit = t.T_submit
  65. r.T_submit_name = Account.Read_User_T_name_Get(t.T_submit)
  66. r.T_remark = t.T_remark
  67. return r
  68. }
  69. func StockInToStockIn_Detail(t StockIn, productList []StockInProduct_R) (r StockIn_Detail) {
  70. r.Id = t.Id
  71. r.T_number = t.T_number
  72. r.T_depot_id = t.T_depot_id
  73. r.T_depot_name = Basic.Read_Depot_Get(t.T_depot_id)
  74. r.T_date = t.T_date
  75. r.T_submit = t.T_submit
  76. r.T_submit_name = Account.Read_User_T_name_Get(t.T_submit)
  77. r.T_remark = t.T_remark
  78. r.T_Product = productList
  79. return r
  80. }
  81. // 添加
  82. func (dao *StockInDaoImpl) Add_StockIn(r StockIn) (id int64, err error) {
  83. id, err = dao.orm.Insert(&r)
  84. if err != nil {
  85. logs.Error(lib.FuncName(), err)
  86. }
  87. return id, err
  88. }
  89. // 获取 ById
  90. func (dao *StockInDaoImpl) Read_StockIn_ByT_number(T_number string) (r StockIn, err error) {
  91. qs := dao.orm.QueryTable(new(StockIn))
  92. err = qs.Filter("T_number", T_number).One(&r)
  93. if err != nil {
  94. logs.Error(lib.FuncName(), err)
  95. }
  96. return
  97. }
  98. // 修改
  99. func (dao *StockInDaoImpl) Update_StockIn(m StockIn, cols ...string) error {
  100. _, err := dao.orm.Update(&m, cols...)
  101. if err != nil {
  102. logs.Error(lib.FuncName(), err)
  103. return err
  104. }
  105. return nil
  106. }
  107. // 获取列表
  108. func (dao *StockInDaoImpl) Read_StockIn_List(T_depot_id int, T_start_date, T_end_date string, page, page_z int) (r_ []StockIn_R, cnt int64) {
  109. qs := dao.orm.QueryTable(new(StockIn))
  110. var offset int64
  111. if page <= 1 {
  112. offset = 0
  113. } else {
  114. offset = int64((page - 1) * page_z)
  115. }
  116. // 过滤
  117. cond := orm.NewCondition()
  118. if T_depot_id > 0 {
  119. cond = cond.And("T_depot_id", T_depot_id)
  120. }
  121. if len(T_start_date) > 0 {
  122. cond = cond.And("T_date__gte", T_start_date)
  123. }
  124. if len(T_end_date) > 0 {
  125. cond = cond.And("T_date__lte", T_end_date)
  126. }
  127. // 查询
  128. var r []StockIn
  129. _, err := qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&r)
  130. if err != nil {
  131. logs.Error(lib.FuncName(), err)
  132. return
  133. }
  134. cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
  135. if err != nil {
  136. logs.Error(lib.FuncName(), err)
  137. return
  138. }
  139. for _, v := range r {
  140. r_ = append(r_, StockInToStockIn_R(v))
  141. }
  142. return r_, cnt
  143. }