StockInProduct.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. "strconv"
  8. "time"
  9. "ERP_storage/logs"
  10. _ "github.com/astaxie/beego/cache/redis"
  11. "github.com/beego/beego/v2/adapter/orm"
  12. _ "github.com/go-sql-driver/mysql"
  13. )
  14. // 入库产品mingxi
  15. type StockInProduct struct {
  16. Id int `orm:"column(ID);size(11);auto;pk"`
  17. T_number string `orm:"size(256);null"` // 入库单号
  18. T_depot_id int `orm:"size(20);null"` // 仓库id
  19. T_product_id int `orm:"size(20);null"` // 产品id
  20. T_num int `orm:"size(20);null"` // 入库数量
  21. T_date string `orm:"size(256);null"` // 业务日期
  22. T_relation_sn string `orm:"type(text);null"` // 关联sn,20220101,20230202,
  23. CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
  24. UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
  25. }
  26. // 入库列表
  27. type StockInProductList struct {
  28. Id int
  29. T_number string // StockIn - 入库单号
  30. T_depot_id int // StockIn - 仓库id
  31. T_depot_name string // StockIn - 仓库名称
  32. T_date string // StockIn - 业务日期
  33. T_submit string // StockIn - 经办人
  34. T_submit_name string // StockIn - 经办人名称
  35. T_remark string // StockIn - 备注
  36. T_num int // 入库数量
  37. T_relation_sn string // 关联sn,20220101,20230202
  38. T_device_list []string // sn关联列表
  39. // ---------产品信息-----------
  40. T_product_id int
  41. T_product_name string
  42. T_product_class_name string
  43. T_product_model string
  44. T_product_spec string
  45. T_product_relation_sn int
  46. T_product_img string
  47. }
  48. func (t *StockInProduct) TableName() string {
  49. return "stock_in_product" // 数据库名称 // ************** 替换 FormulaList **************
  50. }
  51. type StockInProductDaoImpl struct {
  52. orm orm.Ormer
  53. }
  54. func NewStockInProduct(orm orm.Ormer) *StockInProductDaoImpl {
  55. return &StockInProductDaoImpl{orm: orm}
  56. }
  57. func init() {
  58. //注册模型
  59. orm.RegisterModel(new(StockInProduct))
  60. }
  61. type StockInProduct_R struct {
  62. Id int
  63. T_number string // 入库单号
  64. T_depot_id int // 仓库id
  65. T_num int // 入库数量
  66. T_date string // 日期
  67. //T_relation_sn string // 关联sn,20220101,20230202,
  68. T_device_list []string // sn关联列表
  69. // ---------产品信息-----------
  70. T_product_id int
  71. T_product_name string
  72. T_product_class_name string
  73. T_product_model string
  74. T_product_spec string
  75. T_product_relation_sn int
  76. T_product_img string
  77. }
  78. func StockInProductToStockInProduct_R(t StockInProduct) (r StockInProduct_R) {
  79. r.Id = t.Id
  80. r.T_number = t.T_number
  81. r.T_depot_id = t.T_depot_id
  82. r.T_num = t.T_num
  83. r.T_date = t.T_date
  84. //r.T_relation_sn = t.T_relation_sn
  85. r.T_device_list = lib.SplitString(t.T_relation_sn, ",")
  86. r.T_product_id = t.T_product_id
  87. product, _ := Basic.Read_Product_ById(t.T_product_id)
  88. r.T_product_name = product.T_name
  89. r.T_product_class_name = Basic.Read_ProductClass_Get(product.T_class)
  90. r.T_product_model = product.T_model
  91. r.T_product_spec = product.T_spec
  92. r.T_product_relation_sn = product.T_relation_sn
  93. r.T_product_img = product.T_img
  94. return r
  95. }
  96. func StockInProductListToStockInProductList(t StockInProductList) (r StockInProductList) {
  97. r.Id = t.Id
  98. r.T_number = t.T_number
  99. r.T_depot_id = t.T_depot_id
  100. r.T_depot_name = Basic.Read_Depot_Get(t.T_depot_id)
  101. r.T_num = t.T_num
  102. r.T_date = t.T_date
  103. r.T_submit = t.T_submit
  104. r.T_submit_name = Account.Read_User_T_name_Get(t.T_submit)
  105. r.T_remark = t.T_remark
  106. r.T_num = t.T_num
  107. r.T_relation_sn = t.T_relation_sn
  108. r.T_device_list = lib.SplitString(t.T_relation_sn, ",")
  109. r.T_product_id = t.T_product_id
  110. product, _ := Basic.Read_Product_ById(t.T_product_id)
  111. r.T_product_name = product.T_name
  112. r.T_product_class_name = Basic.Read_ProductClass_Get(product.T_class)
  113. r.T_product_model = product.T_model
  114. r.T_product_spec = product.T_spec
  115. r.T_product_relation_sn = product.T_relation_sn
  116. r.T_product_img = product.T_img
  117. return r
  118. }
  119. // 添加
  120. func (dao *StockInProductDaoImpl) Add_StockInProduct(r StockInProduct) (id int64, err error) {
  121. id, err = dao.orm.Insert(&r)
  122. if err != nil {
  123. logs.Error(lib.FuncName(), err)
  124. }
  125. return id, err
  126. }
  127. // 通过入库编号查询入库产品列表
  128. func (dao *StockInProductDaoImpl) Read_StockInProduct_List_ByT_number(T_number string) (r []StockInProduct) {
  129. qs := dao.orm.QueryTable(new(StockInProduct))
  130. _, err := qs.Filter("T_number", T_number).All(&r)
  131. if err != nil {
  132. logs.Error(lib.FuncName(), err)
  133. }
  134. return
  135. }
  136. // 修改
  137. func (dao *StockInProductDaoImpl) Update_StockInProduct(m StockInProduct, cols ...string) error {
  138. _, err := dao.orm.Update(&m, cols...)
  139. if err != nil {
  140. logs.Error(lib.FuncName(), err)
  141. return err
  142. }
  143. return nil
  144. }
  145. // 根据库存id、产品id、月份获取本月出库总数量
  146. func (dao *StockInProductDaoImpl) Read_StockIn_Total(T_depot_id, T_product_id int, T_date string) int {
  147. sql := "SELECT SUM(t_num) FROM stock_in_product WHERE t_depot_id = " + strconv.Itoa(T_depot_id) + " AND t_product_id = " + strconv.Itoa(T_product_id) + " AND t_date like '" + T_date + "%'"
  148. var pl_lists orm2.ParamsList
  149. _, err := dao.orm.Raw(sql).ValuesFlat(&pl_lists)
  150. if err != nil {
  151. logs.Error(lib.FuncName(), err)
  152. return 0
  153. }
  154. if pl_lists[0] == nil {
  155. return 0
  156. }
  157. key, _ := strconv.Atoi(pl_lists[0].(string))
  158. return key
  159. }