mysteel_chemical_index.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/utils"
  7. "time"
  8. )
  9. // BaseFromMysteelChemicalIndex 钢联化工指标表
  10. type BaseFromMysteelChemicalIndex struct {
  11. BaseFromMysteelChemicalIndexId int `orm:"column(base_from_mysteel_chemical_index_id);pk"`
  12. BaseFromMysteelChemicalClassifyId int `orm:"column(base_from_mysteel_chemical_classify_id)" description:"钢联化工指标分类id"`
  13. IndexCode string `description:"指标编码"`
  14. IndexName string `description:"指标名称"`
  15. Unit string `description:"单位"`
  16. Source string `description:"数据来源"`
  17. Frequency string `description:"频度"`
  18. StartDate string `description:"开始日期"`
  19. EndDate string `description:"结束日期"`
  20. Describe string `description:"指标描述"`
  21. UpdateWeek string `description:"更新周期"`
  22. UpdateTime string `description:"更新时间1"`
  23. UpdateTime2 string `description:"更新时间2"`
  24. SysUserId int `description:"创建人id"`
  25. SysUserRealName string `description:"创建人姓名"`
  26. ModifyTime time.Time `description:"修改时间"`
  27. CreateTime time.Time `description:"创建时间"`
  28. Sort int `description:"排序字段"`
  29. MergeFilePath string `description:"合并文件"`
  30. }
  31. // Update 更新钢联化工指标基础信息
  32. func (item *BaseFromMysteelChemicalIndex) Update(cols []string) (err error) {
  33. o := orm.NewOrmUsingDB("data")
  34. _, err = o.Update(item, cols...)
  35. return
  36. }
  37. // AddBaseFromMysteelChemicalIndex 添加钢联化工指标
  38. func AddBaseFromMysteelChemicalIndex(item *BaseFromMysteelChemicalIndex) (lastId int64, err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. lastId, err = o.Insert(item)
  41. return
  42. }
  43. // BaseFromMysteelChemicalData 钢联化工指标数据表
  44. type BaseFromMysteelChemicalData struct {
  45. BaseFromMysteelChemicalDataId int `orm:"column(base_from_mysteel_chemical_data_id);pk"`
  46. BaseFromMysteelChemicalIndexId int `orm:"column(base_from_mysteel_chemical_index_id)" description:"钢联化工指标id"`
  47. IndexCode string `description:"指标编码"`
  48. DataTime time.Time `description:"数据日期"`
  49. Value float64 `description:"数据值"`
  50. ModifyTime time.Time `description:"修改时间"`
  51. CreateTime time.Time `description:"创建时间"`
  52. }
  53. // MysteelChemicalFrequency 钢联化工频度
  54. type MysteelChemicalFrequency struct {
  55. Frequency string `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
  56. }
  57. // GetMysteelChemicalIndexAll 用于分类展示
  58. func GetMysteelChemicalIndexAll() (items []*BaseFromMysteelChemicalClassifyItems, err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. sql := ` SELECT base_from_mysteel_chemical_index_id,base_from_mysteel_chemical_classify_id,index_name AS classify_name,
  61. sys_user_id,sys_user_real_name,sort
  62. FROM base_from_mysteel_chemical_index ORDER BY sort asc, create_time ASC `
  63. _, err = o.Raw(sql).QueryRows(&items)
  64. return
  65. }
  66. // MysteelChemicalFrequencyByClassifyId 根据分类id获取钢联化工频度数据列表
  67. func MysteelChemicalFrequencyByClassifyId(classifyId int) (items []*MysteelChemicalFrequency, err error) {
  68. o := orm.NewOrmUsingDB("data")
  69. if classifyId == 0 {
  70. sql := ` SELECT frequency FROM base_from_mysteel_chemical_index WHERE frequency != "" GROUP BY frequency ORDER BY frequency ASC `
  71. _, err = o.Raw(sql).QueryRows(&items)
  72. return
  73. } else {
  74. sql := ` SELECT frequency FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id = ? AND frequency != "" GROUP BY frequency ORDER BY frequency ASC `
  75. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  76. return
  77. }
  78. }
  79. // GetMysteelChemicalFrequency 获取钢联化工频度数据列表
  80. func GetMysteelChemicalFrequency(condition string, pars []interface{}) (items []*MysteelChemicalFrequency, err error) {
  81. o := orm.NewOrmUsingDB("data")
  82. sql := ` SELECT frequency FROM base_from_mysteel_chemical_index WHERE 1=1 AND frequency != "" `
  83. if condition != "" {
  84. sql += condition
  85. }
  86. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  87. _, err = o.Raw(sql, pars).QueryRows(&items)
  88. return
  89. }
  90. // MysteelChemicalList 钢联化工指标列表
  91. type MysteelChemicalList struct {
  92. Id int `orm:"column(base_from_mysteel_chemical_index_id)"`
  93. BaseFromMysteelChemicalClassifyId int `orm:"column(base_from_mysteel_chemical_classify_id)" description:"钢联化工指标分类id"`
  94. IndexCode string `description:"指标编码"`
  95. IndexName string `description:"指标名称"`
  96. UnitName string `orm:"column(unit)"`
  97. UniqueCode string `description:"唯一编码"`
  98. FrequencyName string `orm:"column(frequency)"`
  99. UpdateTime string `orm:"column(modify_time)"`
  100. Paging *paging.PagingItem `description:"分页数据"`
  101. DataList []*MysteelChemicalData
  102. }
  103. // MysteelChemicalData 钢联化工数据列表
  104. type MysteelChemicalData struct {
  105. InputValue string `orm:"column(value)" description:"值"`
  106. DataTime string `orm:"column(data_time)" description:"日期"`
  107. }
  108. // GetMysteelChemicalIndex 根据分类id获取钢联化工频度数据列表
  109. func GetMysteelChemicalIndex(condition string, pars []interface{}) (items []*MysteelChemicalList, err error) {
  110. o := orm.NewOrmUsingDB("data")
  111. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  112. if condition != "" {
  113. sql += condition
  114. }
  115. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC `
  116. _, err = o.Raw(sql, pars).QueryRows(&items)
  117. return
  118. }
  119. // GetMysteelChemicalIndexData 根据指标code获取钢联化工数据列表
  120. func GetMysteelChemicalIndexData(indexCode string, startSize, pageSize int) (items []*MysteelChemicalData, err error) {
  121. sql := ` SELECT * FROM (
  122. SELECT DISTINCT a.index_code,a.value,a.data_time FROM base_from_mysteel_chemical_data AS a WHERE index_code=?
  123. ORDER BY data_time DESC
  124. )AS t
  125. GROUP BY t.data_time
  126. ORDER BY t.data_time DESC LIMIT ?,? `
  127. o := orm.NewOrmUsingDB("data")
  128. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  129. return
  130. }
  131. // GetMysteelChemicalIndexDataCount 根据指标code获取钢联化工数据列表 获取钢联数据总数
  132. func GetMysteelChemicalIndexDataCount(indexCode string) (count int, err error) {
  133. sql := `SELECT COUNT(1) AS count FROM (
  134. SELECT * FROM (
  135. SELECT DISTINCT a.index_code,a.value,a.data_time FROM base_from_mysteel_chemical_data AS a WHERE index_code=?
  136. ORDER BY data_time DESC
  137. )AS t
  138. GROUP BY t.data_time
  139. ORDER BY t.data_time DESC
  140. )AS n `
  141. o := orm.NewOrmUsingDB("data")
  142. err = o.Raw(sql, indexCode).QueryRow(&count)
  143. return
  144. }
  145. // GetBaseFromMysteelChemicalIndexByIndexId 根据指标id获取指标信息
  146. func GetBaseFromMysteelChemicalIndexByIndexId(indexId int) (item *BaseFromMysteelChemicalIndex, err error) {
  147. o := orm.NewOrmUsingDB("data")
  148. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id=? `
  149. err = o.Raw(sql, indexId).QueryRow(&item)
  150. return
  151. }
  152. // GetBaseFromMysteelChemicalIndexByCode 根据指标code获取指标信息
  153. func GetBaseFromMysteelChemicalIndexByCode(indexCode string) (item *BaseFromMysteelChemicalIndex, err error) {
  154. o := orm.NewOrmUsingDB("data")
  155. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_code=? `
  156. err = o.Raw(sql, indexCode).QueryRow(&item)
  157. return
  158. }
  159. // GetBaseFromMysteelChemicalIndexByClassifyIdAndName 根据分类id和指标名名获取指标信息
  160. func GetBaseFromMysteelChemicalIndexByClassifyIdAndName(classifyId int, chartName string) (item *BaseFromMysteelChemicalIndex, err error) {
  161. o := orm.NewOrmUsingDB("data")
  162. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id = ? and index_name = ? `
  163. err = o.Raw(sql, classifyId, chartName).QueryRow(&item)
  164. return
  165. }
  166. // GetBaseFromMysteelChemicalIndexListByClassifyId 根据指标分类id获取指标列表信息
  167. func GetBaseFromMysteelChemicalIndexListByClassifyId(classifyId int) (items []*BaseFromMysteelChemicalIndex, err error) {
  168. o := orm.NewOrmUsingDB("data")
  169. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id=? `
  170. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  171. return
  172. }
  173. // GetBaseFromMysteelChemicalIndexListByClassifyIdList 根据指标分类id集合获取指标列表信息
  174. func GetBaseFromMysteelChemicalIndexListByClassifyIdList(classifyIdList []int) (items []*BaseFromMysteelChemicalIndex, err error) {
  175. num := len(classifyIdList)
  176. if num <= 0 {
  177. return
  178. }
  179. o := orm.NewOrmUsingDB("data")
  180. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(num) + `) `
  181. _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  182. return
  183. }
  184. // GetBaseFromMysteelChemicalDataMaxCount 获取分类下指标的最大数量
  185. func GetBaseFromMysteelChemicalDataMaxCount(classifyId int) (count int, err error) {
  186. o := orm.NewOrmUsingDB("data")
  187. sql := `SELECT MAX(t.num) AS count FROM (
  188. SELECT COUNT(1) AS num FROM base_from_mysteel_chemical_index AS a
  189. INNER JOIN base_from_mysteel_chemical_data AS b ON a.base_from_mysteel_chemical_index_id=b.base_from_mysteel_chemical_index_id
  190. WHERE a.base_from_mysteel_chemical_classify_id=?
  191. GROUP BY a.base_from_mysteel_chemical_index_id
  192. )AS t `
  193. err = o.Raw(sql, classifyId).QueryRow(&count)
  194. return
  195. }
  196. // GetMysteelChemicalIndexDataByCode 通过钢联化工指标code获取所有数据列表
  197. func GetMysteelChemicalIndexDataByCode(indexCode string) (items []*MysteelChemicalData, err error) {
  198. sql := ` SELECT * FROM (
  199. SELECT DISTINCT a.index_code,a.value,a.data_time FROM base_from_mysteel_chemical_data AS a WHERE index_code=?
  200. ORDER BY data_time DESC
  201. )AS t
  202. GROUP BY t.data_time
  203. ORDER BY t.data_time DESC `
  204. o := orm.NewOrmUsingDB("data")
  205. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  206. return
  207. }
  208. // MoveBaseFromMysteelChemicalIndex 移动钢联化工指标分类
  209. func MoveBaseFromMysteelChemicalIndex(chartInfoId, classifyId int) (err error) {
  210. o := orm.NewOrmUsingDB("data")
  211. sql := ` UPDATE base_from_mysteel_chemical_index
  212. SET
  213. base_from_mysteel_chemical_classify_id = ?
  214. WHERE base_from_mysteel_chemical_index_id = ?`
  215. _, err = o.Raw(sql, classifyId, chartInfoId).Exec()
  216. return
  217. }
  218. // UpdateBaseFromMysteelChemicalIndexByClassifyId 根据指标id更新排序
  219. func UpdateBaseFromMysteelChemicalIndexByClassifyId(classifyId, nowSort, prevIndexInfoId int, updateSort string) (err error) {
  220. o := orm.NewOrmUsingDB("data")
  221. sql := ` update base_from_mysteel_chemical_index set sort = ` + updateSort + ` WHERE base_from_mysteel_chemical_classify_id=? AND `
  222. if prevIndexInfoId > 0 {
  223. sql += ` ( sort > ? or (base_from_mysteel_chemical_index_id > ` + fmt.Sprint(prevIndexInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  224. }
  225. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  226. return
  227. }
  228. // GetFirstBaseFromMysteelChemicalIndexByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  229. func GetFirstBaseFromMysteelChemicalIndexByClassifyId(classifyId int) (item *BaseFromMysteelChemicalIndex, err error) {
  230. o := orm.NewOrmUsingDB("data")
  231. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id=? order by sort asc,base_from_mysteel_chemical_index_id asc limit 1`
  232. err = o.Raw(sql, classifyId).QueryRow(&item)
  233. return
  234. }
  235. // GetMysteelChemicalIndexCount 根据条件获取钢联化工数据
  236. func GetMysteelChemicalIndexCount(condition string, pars []interface{}) (count int, err error) {
  237. o := orm.NewOrmUsingDB("data")
  238. sql := ` SELECT COUNT(1) AS count FROM base_from_mysteel_chemical_index WHERE 1=1 `
  239. if condition != "" {
  240. sql += condition
  241. }
  242. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC `
  243. err = o.Raw(sql, pars).QueryRow(&count)
  244. return
  245. }
  246. // GetMysteelChemicalIndexList 根据分类id获取钢联化工频度数据列表
  247. func GetMysteelChemicalIndexList(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromMysteelChemicalIndex, err error) {
  248. o := orm.NewOrmUsingDB("data")
  249. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  250. if condition != "" {
  251. sql += condition
  252. }
  253. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC LIMIT ?,? `
  254. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  255. return
  256. }
  257. // GetMysteelChemicalIndexListGroupByUserId 根据指标id列表、用户分组获取指标信息
  258. func GetMysteelChemicalIndexListGroupByUserId(edbIdList []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  259. num := len(edbIdList)
  260. if num <= 0 {
  261. return
  262. }
  263. o := orm.NewOrmUsingDB("data")
  264. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  265. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  266. return
  267. }
  268. // ModifyMysteelChemicalIndexUserIdByCodeList 根据指标code列表修改创建人
  269. func ModifyMysteelChemicalIndexUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  270. num := len(edbIdList)
  271. if num <= 0 {
  272. return
  273. }
  274. o := orm.NewOrmUsingDB("data")
  275. sql := `UPDATE base_from_mysteel_chemical_index SET sys_user_id=?,sys_user_real_name=? WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(num) + `) `
  276. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  277. return
  278. }