warehouse_process_classify.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. package trade_analysis
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "strings"
  8. "time"
  9. )
  10. // WareHouseProcessClassify 建仓过程分类表
  11. type WareHouseProcessClassify struct {
  12. WareHouseProcessClassifyId int `orm:"column(warehouse_process_classify_id);pk"`
  13. ClassifyName string `description:"分类名称"`
  14. ClassifyNameEn string `description:"英文分类名称"`
  15. ParentId int `description:"父级ID"`
  16. SysUserId int `description:"创建人ID"`
  17. SysUserRealName string `description:"创建人姓名"`
  18. Level int `description:"层级"`
  19. Sort int `description:"排序"`
  20. RootId int `description:"顶级分类ID"`
  21. LevelPath string `description:"层级路径"`
  22. UniqueCode string `description:"唯一编码"`
  23. CreateTime time.Time `description:"创建时间"`
  24. ModifyTime time.Time `description:"修改时间"`
  25. }
  26. func (m *WareHouseProcessClassify) TableName() string {
  27. return "warehouse_process_classify"
  28. }
  29. type WareHouseProcessClassifyCols struct {
  30. PrimaryId string
  31. ClassifyName string
  32. ClassifyNameEn string
  33. ParentId string
  34. SysUserId string
  35. SysUserRealName string
  36. Level string
  37. Sort string
  38. RootId string
  39. LevelPath string
  40. UniqueCode string
  41. CreateTime string
  42. ModifyTime string
  43. }
  44. func (m *WareHouseProcessClassify) Cols() WareHouseProcessClassifyCols {
  45. return WareHouseProcessClassifyCols{
  46. PrimaryId: "warehouse_process_classify_id",
  47. ClassifyName: "classify_name",
  48. ClassifyNameEn: "classify_name_en",
  49. ParentId: "parent_id",
  50. SysUserId: "sys_user_id",
  51. SysUserRealName: "sys_user_real_name",
  52. Level: "level",
  53. Sort: "sort",
  54. RootId: "root_id",
  55. LevelPath: "level_path",
  56. UniqueCode: "unique_code",
  57. CreateTime: "create_time",
  58. ModifyTime: "modify_time",
  59. }
  60. }
  61. func (m *WareHouseProcessClassify) Create() (err error) {
  62. o := orm.NewOrmUsingDB("data")
  63. id, err := o.Insert(m)
  64. if err != nil {
  65. return
  66. }
  67. m.WareHouseProcessClassifyId = int(id)
  68. return
  69. }
  70. func (m *WareHouseProcessClassify) CreateMulti(items []*WareHouseProcessClassify) (err error) {
  71. if len(items) == 0 {
  72. return
  73. }
  74. o := orm.NewOrmUsingDB("data")
  75. _, err = o.InsertMulti(len(items), items)
  76. return
  77. }
  78. func (m *WareHouseProcessClassify) Update(cols []string) (err error) {
  79. o := orm.NewOrmUsingDB("data")
  80. _, err = o.Update(m, cols...)
  81. return
  82. }
  83. func (m *WareHouseProcessClassify) Remove() (err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  86. _, err = o.Raw(sql, m.WareHouseProcessClassifyId).Exec()
  87. return
  88. }
  89. func (m *WareHouseProcessClassify) MultiRemove(ids []int) (err error) {
  90. if len(ids) == 0 {
  91. return
  92. }
  93. o := orm.NewOrmUsingDB("data")
  94. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
  95. _, err = o.Raw(sql, ids).Exec()
  96. return
  97. }
  98. func (m *WareHouseProcessClassify) RemoveByCondition(condition string, pars []interface{}) (err error) {
  99. if condition == "" {
  100. return
  101. }
  102. o := orm.NewOrmUsingDB("data")
  103. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
  104. _, err = o.Raw(sql, pars).Exec()
  105. return
  106. }
  107. func (m *WareHouseProcessClassify) GetItemById(id int) (item *WareHouseProcessClassify, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  110. err = o.Raw(sql, id).QueryRow(&item)
  111. return
  112. }
  113. func (m *WareHouseProcessClassify) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *WareHouseProcessClassify, err error) {
  114. o := orm.NewOrmUsingDB("data")
  115. order := ``
  116. if orderRule != "" {
  117. order = ` ORDER BY ` + orderRule
  118. }
  119. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  120. err = o.Raw(sql, pars).QueryRow(&item)
  121. return
  122. }
  123. func (m *WareHouseProcessClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  124. o := orm.NewOrmUsingDB("data")
  125. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  126. err = o.Raw(sql, pars).QueryRow(&count)
  127. return
  128. }
  129. func (m *WareHouseProcessClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*WareHouseProcessClassify, err error) {
  130. o := orm.NewOrmUsingDB("data")
  131. fields := strings.Join(fieldArr, ",")
  132. if len(fieldArr) == 0 {
  133. fields = `*`
  134. }
  135. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  136. if orderRule != "" {
  137. order = ` ORDER BY ` + orderRule
  138. }
  139. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  140. _, err = o.Raw(sql, pars).QueryRows(&items)
  141. return
  142. }
  143. func (m *WareHouseProcessClassify) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*WareHouseProcessClassify, err error) {
  144. o := orm.NewOrmUsingDB("data")
  145. fields := strings.Join(fieldArr, ",")
  146. if len(fieldArr) == 0 {
  147. fields = `*`
  148. }
  149. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  150. if orderRule != "" {
  151. order = ` ORDER BY ` + orderRule
  152. }
  153. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  154. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  155. return
  156. }
  157. // WareHouseProcessClassifyItem 建仓过程分类信息
  158. type WareHouseProcessClassifyItem struct {
  159. ClassifyId int `description:"分类ID"`
  160. ClassifyName string `description:"分类名称"`
  161. ClassifyNameEn string `description:"英文分类名称"`
  162. ParentId int `description:"父级ID"`
  163. Level int `description:"层级"`
  164. Sort int `description:"排序"`
  165. LevelPath string `description:"层级路径"`
  166. UniqueCode string `description:"唯一编码"`
  167. Children []*WareHouseProcessClassifyItem `description:"子分类"`
  168. }
  169. func (m *WareHouseProcessClassify) Format2Item() (item *WareHouseProcessClassifyItem) {
  170. item = new(WareHouseProcessClassifyItem)
  171. item.ClassifyId = m.WareHouseProcessClassifyId
  172. item.ClassifyName = m.ClassifyName
  173. item.ClassifyNameEn = m.ClassifyNameEn
  174. item.ParentId = m.ParentId
  175. item.Level = m.Level
  176. item.Sort = m.Sort
  177. item.LevelPath = m.LevelPath
  178. item.UniqueCode = m.UniqueCode
  179. item.Children = make([]*WareHouseProcessClassifyItem, 0)
  180. return
  181. }
  182. // ------------------------------------------------ 通用分类 ------------------------------------------------
  183. // GetCommonClassifyCols 通用分类字段映射
  184. func (m *WareHouseProcessClassify) GetCommonClassifyCols() models.CommonClassifyCols {
  185. return models.CommonClassifyCols{
  186. ClassifyId: m.Cols().PrimaryId,
  187. ClassifyName: m.Cols().ClassifyName,
  188. ParentId: m.Cols().ParentId,
  189. Sort: m.Cols().ParentId,
  190. RootId: m.Cols().RootId,
  191. Level: m.Cols().Level,
  192. LevelPath: m.Cols().LevelPath,
  193. CreateTime: m.Cols().CreateTime,
  194. ModifyTime: m.Cols().ModifyTime,
  195. }
  196. }
  197. // GetCommonClassifyById 获取通用分类
  198. func (m *WareHouseProcessClassify) GetCommonClassifyById(classifyId int) (commonClassify *models.CommonClassify, err error) {
  199. item, e := m.GetItemById(classifyId)
  200. if e != nil {
  201. err = e
  202. return
  203. }
  204. commonClassify = new(models.CommonClassify)
  205. commonClassify.ClassifyId = item.WareHouseProcessClassifyId
  206. commonClassify.ClassifyName = item.ClassifyName
  207. commonClassify.ParentId = item.ParentId
  208. commonClassify.RootId = item.RootId
  209. commonClassify.Level = item.Level
  210. commonClassify.LevelPath = item.LevelPath
  211. commonClassify.Sort = item.Sort
  212. commonClassify.CreateTime = item.CreateTime
  213. commonClassify.ModifyTime = item.ModifyTime
  214. return
  215. }
  216. // GetClassifyByParentIdAndName 实现获取分类信息的方法
  217. func (m *WareHouseProcessClassify) GetClassifyByParentIdAndName(parentId int, name string, excludeId int) (*models.CommonClassify, error) {
  218. // 实现获取分类信息的逻辑
  219. return nil, nil
  220. }
  221. // UpdateCommonClassify 实现更新分类信息的方法
  222. func (m *WareHouseProcessClassify) UpdateCommonClassify(classify *models.CommonClassify, updateCols []string) (err error) {
  223. return
  224. }
  225. func (m *WareHouseProcessClassify) UpdateClassifyChildByParentId(classifyIds []int, rootId int, stepLevel int) (err error) {
  226. // o := orm.NewOrmUsingDB("data")
  227. // var pars []interface{}
  228. // pars = append(pars, rootId, levelStep)
  229. // pars = append(pars, classifyIds)
  230. // // 更新相关联的二级分类的parentId,和classify_name_second
  231. // sql := `update edb_classify
  232. //SET root_id = ?, level = level+?
  233. //where classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
  234. // _, err = o.Raw(sql, pars).Exec()
  235. // if err != nil {
  236. // return
  237. // }
  238. return
  239. }
  240. // GetClassifySortMaxByParentId 实现获取分类排序的方法
  241. func (m *WareHouseProcessClassify) GetClassifySortMaxByParentId(parentId int) (sortMax int, err error) {
  242. // o := orm.NewOrmUsingDB("data")
  243. // sql := `SELECT Max(sort) AS sort FROM edb_classify WHERE parent_id=? AND classify_type=? `
  244. // err = o.Raw(sql, parentId, classifyType).QueryRow(&sort)
  245. // return
  246. return
  247. }
  248. func (m *WareHouseProcessClassify) GetFirstClassifyByParentId(parentId int) (item *models.CommonClassify, err error) {
  249. //o := orm.NewOrmUsingDB("data")
  250. //sql := ` SELECT * FROM edb_classify WHERE parent_id=? order by sort asc,classify_id asc limit 1`
  251. //err = o.Raw(sql, parentId).QueryRow(&item)
  252. return
  253. }
  254. // SetClassifySortByParentId 实现设置分类排序的方法
  255. func (m *WareHouseProcessClassify) SetClassifySortByParentId(parentId, classifyId, sort int, sortUpdate string) (err error) {
  256. //o := orm.NewOrmUsingDB("data")
  257. //sql := ` update edb_classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? AND classify_type = ? `
  258. //if classifyId > 0 {
  259. // sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  260. //}
  261. //_, err = o.Raw(sql, parentId, nowSort, classifyType).Exec()
  262. return
  263. }
  264. // GetCommonClassifyObjCols 通用分类对象字段映射
  265. func (m *WareHouseProcessClassify) GetCommonClassifyObjCols() models.CommonClassifyObjCols {
  266. // TODO: 完善
  267. return models.CommonClassifyObjCols{
  268. ObjectId: m.Cols().ClassifyName,
  269. ClassifyId: m.Cols().PrimaryId,
  270. Sort: m.Cols().ParentId,
  271. }
  272. }
  273. func (m *WareHouseProcessClassify) GetObjectById(objectId int) (*models.CommonClassifyObj, error) {
  274. // 实现获取分类信息的逻辑
  275. return nil, nil
  276. }
  277. // GetObjectSortMaxByClassifyId 获取分类下最大排序
  278. func (m *WareHouseProcessClassify) GetObjectSortMaxByClassifyId(classifyId int) (sortMax int, err error) {
  279. // o := orm.NewOrmUsingDB("data")
  280. // sql := `SELECT Max(sort) AS sort FROM edb_info WHERE classify_id=? `
  281. // err = o.Raw(sql, classifyId).QueryRow(&sort)
  282. // return
  283. return
  284. }
  285. func (m *WareHouseProcessClassify) GetFirstObjectByClassifyId(classifyId int) (item *models.CommonClassifyObj, err error) {
  286. //o := orm.NewOrmUsingDB("data")
  287. //sql := ` SELECT * FROM edb_info WHERE classify_id=? order by sort asc,edb_info_id asc limit 1`
  288. //err = o.Raw(sql, classifyId).QueryRow(&item)
  289. return
  290. }
  291. func (m *WareHouseProcessClassify) SetObjectSortByClassifyId(classifyId, sort, prevObjectId int, sortUpdate string) (err error) {
  292. //o := orm.NewOrmUsingDB("data")
  293. //sql := ` update edb_info set sort = ` + updateSort + ` WHERE classify_id=?`
  294. //if prevEdbInfoId > 0 {
  295. // sql += ` AND ( sort > ? or ( edb_info_id > ` + fmt.Sprint(prevEdbInfoId) + ` and sort=` + fmt.Sprint(nowSort) + ` )) `
  296. //} else {
  297. // sql += ` AND ( sort > ? )`
  298. //}
  299. //_, err = o.Raw(sql, classifyId, nowSort).Exec()
  300. return
  301. }
  302. // UpdateCommonClassifyObj 更新通用分类对象
  303. func (m *WareHouseProcessClassify) UpdateCommonClassifyObj(object *models.CommonClassifyObj, updateCols []string) (err error) {
  304. return
  305. }
  306. // ------------------------------------------------ 通用分类 ------------------------------------------------