mysteel_chemical_index.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/beego/beego/v2/client/orm"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. )
  10. // BaseFromMysteelChemicalIndex 钢联化工指标表
  11. type BaseFromMysteelChemicalIndex struct {
  12. BaseFromMysteelChemicalIndexId int `orm:"column(base_from_mysteel_chemical_index_id);pk"`
  13. BaseFromMysteelChemicalClassifyId int `orm:"column(base_from_mysteel_chemical_classify_id)" description:"钢联化工指标分类id"`
  14. IndexCode string `description:"指标编码"`
  15. IndexName string `description:"指标名称"`
  16. Unit string `description:"单位"`
  17. Source string `description:"数据来源"`
  18. Frequency string `description:"频度"`
  19. StartDate string `description:"开始日期"`
  20. EndDate string `description:"结束日期"`
  21. Describe string `description:"指标描述"`
  22. UpdateWeek string `description:"更新周期"`
  23. UpdateTime string `description:"更新时间1"`
  24. UpdateTime2 string `description:"更新时间2"`
  25. SysUserId int `description:"创建人id"`
  26. SysUserRealName string `description:"创建人姓名"`
  27. ModifyTime time.Time `description:"修改时间"`
  28. CreateTime time.Time `description:"创建时间"`
  29. Sort int `description:"排序字段"`
  30. MergeFilePath string `description:"合并文件"`
  31. TerminalCode string `description:"终端编码"`
  32. IsStop int `description:"是否停更:1:停更,0:未停更"`
  33. EndValue float64 `description:"指标的最新值"`
  34. }
  35. type BaseFromMysteelChemicalIndexItem struct {
  36. BaseFromMysteelChemicalIndexId int64 `orm:"column(base_from_mysteel_chemical_index_id);pk"`
  37. IndexCode string `description:"指标编码"`
  38. IndexName string `description:"指标名称"`
  39. Unit string `description:"单位"`
  40. Frequency string `description:"频度"`
  41. Source int `description:"数据来源"`
  42. StartDate string `description:"开始日期"`
  43. EndDate string `description:"结束日期"`
  44. CreateTime string `description:"创建时间"`
  45. ModifyTime string `description:"修改时间"`
  46. EdbInfoId int `description:"eta指标库的id"`
  47. EdbUniqueCode string `description:"指标库唯一编码"`
  48. EdbClassifyId int `description:"指标库分类ID"`
  49. IsStop int `description:"是否停更:1:停更,0:未停更"`
  50. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  51. }
  52. var BaseFromMysteelChemicalIndexCols = struct {
  53. BaseFromMysteelChemicalIndexId string
  54. IndexCode string
  55. IndexName string
  56. Unit string
  57. Frequency string
  58. Source string
  59. StartDate string
  60. EndDate string
  61. CreateTime string
  62. ModifyTime string
  63. }{
  64. BaseFromMysteelChemicalIndexId: "base_from_mysteel_chemical_index_id",
  65. IndexCode: "index_code",
  66. IndexName: "index_name",
  67. Unit: "unit",
  68. Frequency: "frequency",
  69. Source: "source",
  70. StartDate: "start_date",
  71. EndDate: "end_date",
  72. CreateTime: "create_time",
  73. ModifyTime: "modify_time",
  74. }
  75. // Update 更新钢联化工指标基础信息
  76. func (item *BaseFromMysteelChemicalIndex) Update(cols []string) (err error) {
  77. o := orm.NewOrmUsingDB("data")
  78. _, err = o.Update(item, cols...)
  79. return
  80. }
  81. func (m *BaseFromMysteelChemicalIndex) GeItemsByCondition(condition string, pars []interface{}, limitSize int) (items []*BaseFromMysteelChemicalIndexItem, err error) {
  82. if pars == nil {
  83. pars = make([]interface{}, 0)
  84. }
  85. sql := `select a.*,b.edb_info_id,b.unique_code as edb_unique_code,b.classify_id as edb_classify_id FROM base_from_mysteel_chemical_index AS a LEFT JOIN edb_info b on a.index_code=b.edb_code AND b.source=? WHERE 1=1 `
  86. if condition != "" {
  87. sql += condition
  88. }
  89. sql += ` order by a.base_from_mysteel_chemical_index_id desc `
  90. if limitSize > 0 {
  91. sql += " limit ? "
  92. pars = append(pars, limitSize)
  93. }
  94. o := orm.NewOrmUsingDB("data")
  95. _, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, pars).QueryRows(&items)
  96. return
  97. }
  98. // AddBaseFromMysteelChemicalIndex 添加钢联化工指标
  99. func AddBaseFromMysteelChemicalIndex(item *BaseFromMysteelChemicalIndex) (lastId int64, err error) {
  100. o := orm.NewOrmUsingDB("data")
  101. lastId, err = o.Insert(item)
  102. if err != nil {
  103. return
  104. }
  105. item.BaseFromMysteelChemicalIndexId = int(lastId)
  106. return
  107. }
  108. // AddBaseFromMysteelChemicalIndex 添加钢联化工指标
  109. func BatchAddBaseFromMysteelChemicalIndex(items []*BaseFromMysteelChemicalIndex) (lastId int64, err error) {
  110. o := orm.NewOrmUsingDB("data")
  111. _, err = o.InsertMulti(len(items), items)
  112. return
  113. }
  114. // BaseFromMysteelChemicalData 钢联化工指标数据表
  115. type BaseFromMysteelChemicalData struct {
  116. BaseFromMysteelChemicalDataId int `orm:"column(base_from_mysteel_chemical_data_id);pk"`
  117. BaseFromMysteelChemicalIndexId int `orm:"column(base_from_mysteel_chemical_index_id)" description:"钢联化工指标id"`
  118. IndexCode string `description:"指标编码"`
  119. DataTime time.Time `description:"数据日期"`
  120. Value float64 `description:"数据值"`
  121. ModifyTime time.Time `description:"修改时间"`
  122. CreateTime time.Time `description:"创建时间"`
  123. }
  124. // MysteelChemicalFrequency 钢联化工频度
  125. type MysteelChemicalFrequency struct {
  126. Frequency string `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
  127. }
  128. // GetMysteelChemicalIndexByClassifyId 用于分类展示
  129. func GetMysteelChemicalIndexByClassifyId(classifyId int) (items []*BaseFromMysteelChemicalClassifyItems, err error) {
  130. o := orm.NewOrmUsingDB("data")
  131. sql := ` SELECT base_from_mysteel_chemical_index_id,base_from_mysteel_chemical_classify_id,index_name AS classify_name,
  132. sys_user_id,sys_user_real_name,sort,index_code
  133. FROM base_from_mysteel_chemical_index where base_from_mysteel_chemical_classify_id=? ORDER BY sort asc, create_time ASC `
  134. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  135. return
  136. }
  137. // MysteelChemicalFrequencyByClassifyId 根据分类id获取钢联化工频度数据列表
  138. func MysteelChemicalFrequencyByClassifyId(classifyId int) (items []*MysteelChemicalFrequency, err error) {
  139. o := orm.NewOrmUsingDB("data")
  140. if classifyId == 0 {
  141. sql := ` SELECT frequency FROM base_from_mysteel_chemical_index WHERE frequency != "" GROUP BY frequency ORDER BY frequency ASC `
  142. _, err = o.Raw(sql).QueryRows(&items)
  143. return
  144. } else {
  145. 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 `
  146. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  147. return
  148. }
  149. }
  150. // GetMysteelChemicalFrequency 获取钢联化工频度数据列表
  151. func GetMysteelChemicalFrequency(condition string, pars []interface{}) (items []*MysteelChemicalFrequency, err error) {
  152. o := orm.NewOrmUsingDB("data")
  153. sql := ` SELECT frequency FROM base_from_mysteel_chemical_index WHERE 1=1 AND frequency != "" `
  154. if condition != "" {
  155. sql += condition
  156. }
  157. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  158. _, err = o.Raw(sql, pars).QueryRows(&items)
  159. return
  160. }
  161. // MysteelChemicalList 钢联化工指标列表
  162. type MysteelChemicalList struct {
  163. Id int `orm:"column(base_from_mysteel_chemical_index_id)"`
  164. BaseFromMysteelChemicalClassifyId int `orm:"column(base_from_mysteel_chemical_classify_id)" description:"钢联化工指标分类id"`
  165. ParentClassifyId int `description:"钢联化工指标父级分类id"`
  166. IndexCode string `description:"指标编码"`
  167. IndexName string `description:"指标名称"`
  168. UnitName string `orm:"column(unit)"`
  169. UniqueCode string `description:"唯一编码"`
  170. FrequencyName string `orm:"column(frequency)"`
  171. EdbInfoId int `description:"指标库的id"`
  172. UpdateTime string `orm:"column(modify_time)"`
  173. IsStop int `description:"是否停更:1:停更,0:未停更"`
  174. Paging *paging.PagingItem `description:"分页数据"`
  175. DataList []*MysteelChemicalData
  176. }
  177. // MysteelChemicalData 钢联化工数据列表
  178. type MysteelChemicalData struct {
  179. InputValue string `orm:"column(value)" description:"值"`
  180. DataTime string `orm:"column(data_time)" description:"日期"`
  181. }
  182. // GetMysteelChemicalIndex 根据分类id获取钢联化工频度数据列表
  183. func GetMysteelChemicalIndex(condition string, pars []interface{}) (items []*MysteelChemicalList, err error) {
  184. o := orm.NewOrmUsingDB("data")
  185. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  186. if condition != "" {
  187. sql += condition
  188. }
  189. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC `
  190. _, err = o.Raw(sql, pars).QueryRows(&items)
  191. return
  192. }
  193. // GetMysteelChemicalIndexData 根据指标code获取钢联化工数据列表
  194. func GetMysteelChemicalIndexData(indexCode string, startSize, pageSize int) (items []*MysteelChemicalData, err error) {
  195. sql := ` SELECT * FROM (
  196. SELECT DISTINCT a.index_code,a.value,a.data_time FROM base_from_mysteel_chemical_data AS a WHERE index_code=?
  197. ORDER BY data_time DESC
  198. )AS t
  199. GROUP BY t.data_time
  200. ORDER BY t.data_time DESC LIMIT ?,? `
  201. o := orm.NewOrmUsingDB("data")
  202. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  203. return
  204. }
  205. // GetMysteelChemicalIndexDataCount 根据指标code获取钢联化工数据列表 获取钢联数据总数
  206. func GetMysteelChemicalIndexDataCount(indexCode string) (count int, err error) {
  207. sql := `SELECT COUNT(1) AS count FROM (
  208. SELECT * FROM (
  209. SELECT DISTINCT a.index_code,a.value,a.data_time FROM base_from_mysteel_chemical_data AS a WHERE index_code=?
  210. ORDER BY data_time DESC
  211. )AS t
  212. GROUP BY t.data_time
  213. ORDER BY t.data_time DESC
  214. )AS n `
  215. o := orm.NewOrmUsingDB("data")
  216. err = o.Raw(sql, indexCode).QueryRow(&count)
  217. return
  218. }
  219. // GetBaseFromMysteelChemicalIndexByIndexId 根据指标id获取指标信息
  220. func GetBaseFromMysteelChemicalIndexByIndexId(indexId int) (item *BaseFromMysteelChemicalIndex, err error) {
  221. o := orm.NewOrmUsingDB("data")
  222. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id=? `
  223. err = o.Raw(sql, indexId).QueryRow(&item)
  224. return
  225. }
  226. // GetBaseFromMysteelChemicalIndexByCode 根据指标code获取指标信息
  227. func GetBaseFromMysteelChemicalIndexByCode(indexCode string) (item *BaseFromMysteelChemicalIndex, err error) {
  228. o := orm.NewOrmUsingDB("data")
  229. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_code=? `
  230. err = o.Raw(sql, indexCode).QueryRow(&item)
  231. return
  232. }
  233. // GetBaseFromMysteelChemicalIndexByCodeList 根据指标code获取指标信息
  234. func GetBaseFromMysteelChemicalIndexByCodeList(indexCodeList []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  235. if len(indexCodeList) <= 0 {
  236. return
  237. }
  238. o := orm.NewOrmUsingDB("data")
  239. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_code IN (%s) `
  240. holder := make([]string, 0)
  241. for range indexCodeList {
  242. holder = append(holder, "?")
  243. }
  244. sql = fmt.Sprintf(sql, strings.Join(holder, ","))
  245. _, err = o.Raw(sql, indexCodeList).QueryRows(&items)
  246. return
  247. }
  248. // GetBaseFromMysteelChemicalIndexByClassifyIdAndName 根据分类id和指标名名获取指标信息
  249. func GetBaseFromMysteelChemicalIndexByClassifyIdAndName(classifyId int, chartName string) (item *BaseFromMysteelChemicalIndex, err error) {
  250. o := orm.NewOrmUsingDB("data")
  251. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id = ? and index_name = ? `
  252. err = o.Raw(sql, classifyId, chartName).QueryRow(&item)
  253. return
  254. }
  255. // GetBaseFromMysteelChemicalIndexListByClassifyId 根据指标分类id获取指标列表信息
  256. func GetBaseFromMysteelChemicalIndexListByClassifyId(classifyId int) (items []*BaseFromMysteelChemicalIndex, err error) {
  257. o := orm.NewOrmUsingDB("data")
  258. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id=? `
  259. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  260. return
  261. }
  262. // GetBaseFromMysteelChemicalIndexListByClassifyIdList 根据指标分类id集合获取指标列表信息
  263. func GetBaseFromMysteelChemicalIndexListByClassifyIdList(classifyIdList []int) (items []*BaseFromMysteelChemicalIndex, err error) {
  264. num := len(classifyIdList)
  265. if num <= 0 {
  266. return
  267. }
  268. o := orm.NewOrmUsingDB("data")
  269. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(num) + `) `
  270. _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  271. return
  272. }
  273. // GetBaseFromMysteelChemicalDataMaxCount 获取分类下指标的最大数量
  274. func GetBaseFromMysteelChemicalDataMaxCount(classifyId int) (count int, err error) {
  275. o := orm.NewOrmUsingDB("data")
  276. sql := `SELECT MAX(t.num) AS count FROM (
  277. SELECT COUNT(1) AS num FROM base_from_mysteel_chemical_index AS a
  278. INNER JOIN base_from_mysteel_chemical_data AS b ON a.base_from_mysteel_chemical_index_id=b.base_from_mysteel_chemical_index_id
  279. WHERE a.base_from_mysteel_chemical_classify_id=?
  280. GROUP BY a.base_from_mysteel_chemical_index_id
  281. )AS t `
  282. err = o.Raw(sql, classifyId).QueryRow(&count)
  283. return
  284. }
  285. // GetMysteelChemicalIndexDataByCode 通过钢联化工指标code获取所有数据列表
  286. func GetMysteelChemicalIndexDataByCode(indexCode string) (items []*MysteelChemicalData, err error) {
  287. sql := ` SELECT * FROM (
  288. SELECT DISTINCT a.index_code,a.value,a.data_time FROM base_from_mysteel_chemical_data AS a WHERE index_code=?
  289. ORDER BY data_time DESC
  290. )AS t
  291. GROUP BY t.data_time
  292. ORDER BY t.data_time DESC `
  293. o := orm.NewOrmUsingDB("data")
  294. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  295. return
  296. }
  297. // MoveBaseFromMysteelChemicalIndex 移动钢联化工指标分类
  298. func MoveBaseFromMysteelChemicalIndex(chartInfoId, classifyId int) (err error) {
  299. o := orm.NewOrmUsingDB("data")
  300. sql := ` UPDATE base_from_mysteel_chemical_index
  301. SET
  302. base_from_mysteel_chemical_classify_id = ?
  303. WHERE base_from_mysteel_chemical_index_id = ?`
  304. _, err = o.Raw(sql, classifyId, chartInfoId).Exec()
  305. return
  306. }
  307. // UpdateBaseFromMysteelChemicalIndexByClassifyId 根据指标id更新排序
  308. func UpdateBaseFromMysteelChemicalIndexByClassifyId(classifyId, nowSort, prevIndexInfoId int, updateSort string) (err error) {
  309. o := orm.NewOrmUsingDB("data")
  310. sql := ` update base_from_mysteel_chemical_index set sort = ` + updateSort + ` WHERE base_from_mysteel_chemical_classify_id=? AND `
  311. if prevIndexInfoId > 0 {
  312. sql += ` ( sort > ? or (base_from_mysteel_chemical_index_id > ` + fmt.Sprint(prevIndexInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  313. }
  314. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  315. return
  316. }
  317. // GetFirstBaseFromMysteelChemicalIndexByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  318. func GetFirstBaseFromMysteelChemicalIndexByClassifyId(classifyId int) (item *BaseFromMysteelChemicalIndex, err error) {
  319. o := orm.NewOrmUsingDB("data")
  320. 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`
  321. err = o.Raw(sql, classifyId).QueryRow(&item)
  322. return
  323. }
  324. // GetMysteelChemicalIndexCount 根据条件获取钢联化工数据
  325. func GetMysteelChemicalIndexCount(condition string, pars []interface{}) (count int, err error) {
  326. o := orm.NewOrmUsingDB("data")
  327. sql := ` SELECT COUNT(1) AS count FROM base_from_mysteel_chemical_index WHERE 1=1 `
  328. if condition != "" {
  329. sql += condition
  330. }
  331. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC `
  332. err = o.Raw(sql, pars).QueryRow(&count)
  333. return
  334. }
  335. // GetMysteelChemicalIndexList 根据分类id获取钢联化工频度数据列表
  336. func GetMysteelChemicalIndexList(condition string, pars []interface{}, startSize, pageSize int, orderDesc string) (items []*BaseFromMysteelChemicalIndex, err error) {
  337. o := orm.NewOrmUsingDB("data")
  338. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  339. if condition != "" {
  340. sql += condition
  341. }
  342. if orderDesc == `` {
  343. orderDesc = ` ASC `
  344. }
  345. sql += ` ORDER BY base_from_mysteel_chemical_index_id `
  346. sql += orderDesc
  347. sql += ` LIMIT ?,? `
  348. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  349. return
  350. }
  351. // GetMysteelChemicalIndexListGroupByUserId 根据指标id列表、用户分组获取指标信息
  352. func GetMysteelChemicalIndexListGroupByUserId(edbIdList []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  353. num := len(edbIdList)
  354. if num <= 0 {
  355. return
  356. }
  357. o := orm.NewOrmUsingDB("data")
  358. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  359. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  360. return
  361. }
  362. // GetMysteelChemicalIndexListByIndexId
  363. // @Description: 根据指标id列表获取列表信息
  364. // @param edbIdList
  365. // @return items
  366. // @return err
  367. func GetMysteelChemicalIndexListByIndexId(edbIdList []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  368. num := len(edbIdList)
  369. if num <= 0 {
  370. return
  371. }
  372. o := orm.NewOrmUsingDB("data")
  373. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(num) + `) `
  374. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  375. return
  376. }
  377. // GetMysteelChemicalIndexListByUserId
  378. // @Description: 根据用户id列表获取列表信息
  379. // @param userIdList
  380. // @return items
  381. // @return err
  382. func GetMysteelChemicalIndexListByUserId(userIdList []int) (items []*BaseFromMysteelChemicalIndex, err error) {
  383. num := len(userIdList)
  384. if num <= 0 {
  385. return
  386. }
  387. o := orm.NewOrmUsingDB("data")
  388. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  389. _, err = o.Raw(sql, userIdList).QueryRows(&items)
  390. return
  391. }
  392. // ModifyMysteelChemicalIndexUserIdByCodeList 根据指标code列表修改创建人
  393. func ModifyMysteelChemicalIndexUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  394. num := len(edbIdList)
  395. if num <= 0 {
  396. return
  397. }
  398. o := orm.NewOrmUsingDB("data")
  399. 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) + `) `
  400. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  401. return
  402. }
  403. // ModifyMysteelChemicalIndexUserIdByOldUserId
  404. // @Description: 根据旧用户id修改新用户id
  405. // @author: Roc
  406. // @datetime 2024-03-25 17:59:08
  407. // @param oldUserId int
  408. // @param userId int
  409. // @param userName string
  410. // @return err error
  411. func ModifyMysteelChemicalIndexUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  412. num := len(oldUserIdList)
  413. if num <= 0 {
  414. return
  415. }
  416. o := orm.NewOrmUsingDB("data")
  417. sql := `UPDATE base_from_mysteel_chemical_index SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  418. _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  419. return
  420. }
  421. // GetMysteelChemicalIndexAdminList 获取所有指标创建人
  422. func GetMysteelChemicalIndexAdminList() (list []int, err error) {
  423. o := orm.NewOrmUsingDB("data")
  424. sql := ` SELECT sys_user_id FROM base_from_mysteel_chemical_index GROUP BY sys_user_id `
  425. _, err = o.Raw(sql).QueryRows(&list)
  426. return
  427. }
  428. type TerminalNum struct {
  429. TerminalCode string `description:"terminal_code"`
  430. Num int `description:"num"`
  431. }
  432. // GetMysteelChemicalGroupTerminalNum 获取钢联化工指标的终端分布
  433. func GetMysteelChemicalGroupTerminalNum() (items []*TerminalNum, err error) {
  434. o := orm.NewOrmUsingDB("data")
  435. sql := ` SELECT terminal_code,count(1) num FROM base_from_mysteel_chemical_index GROUP BY terminal_code ORDER BY num ASC `
  436. _, err = o.Raw(sql).QueryRows(&items)
  437. return
  438. }
  439. // BaseRefreshEdbInfo
  440. // @Description: 刷新配置的基础指标信息结构体
  441. type BaseRefreshEdbInfo struct {
  442. EdbInfoId int
  443. ClassifyId int `description:"钢联化工指标分类id"`
  444. IndexCode string `description:"指标编码"`
  445. IndexName string `description:"指标名称"`
  446. EndDate string `description:"最新日期"`
  447. EndValue string `description:"最新值"`
  448. SysUserId int `description:"创建人id"`
  449. SysUserRealName string `description:"创建人姓名"`
  450. Frequency string `description:"频度"`
  451. IsStop int `description:"是否停更:1:停更,0:未停更"`
  452. TerminalCode string `description:"终端编码"`
  453. RefreshTime string `description:"刷新时间"`
  454. }
  455. // RefreshBaseEdbInfoResp
  456. // @Description: 刷新数据源的数据返回
  457. type RefreshBaseEdbInfoResp struct {
  458. Paging *paging.PagingItem
  459. List []*BaseRefreshEdbInfo
  460. }
  461. // GetMysteelChemicalBaseInfoList
  462. // @Description: 获取钢联化工数据列表
  463. // @author: Roc
  464. // @datetime 2024-01-10 14:28:35
  465. // @param condition string
  466. // @param pars []interface{}
  467. // @param orderBy string
  468. // @param startSize int
  469. // @param pageSize int
  470. // @return total int
  471. // @return items []*BaseRefreshEdbInfo
  472. // @return err error
  473. func GetMysteelChemicalBaseInfoList(condition string, pars []interface{}, orderBy string, startSize, pageSize int) (total int, items []*BaseRefreshEdbInfo, err error) {
  474. o := orm.NewOrmUsingDB("data")
  475. // 数量汇总
  476. totalSql := ` SELECT count(1) FROM base_from_mysteel_chemical_index WHERE 1=1 `
  477. if condition != "" {
  478. totalSql += condition
  479. }
  480. err = o.Raw(totalSql, pars).QueryRow(&total)
  481. if err != nil {
  482. return
  483. }
  484. // 列表数据
  485. sql := ` SELECT base_from_mysteel_chemical_index_id as edb_info_id, base_from_mysteel_chemical_classify_id as classify_id,index_code,index_name,end_date,end_value,sys_user_id,sys_user_real_name,frequency,is_stop,terminal_code FROM base_from_mysteel_chemical_index WHERE 1=1 `
  486. if condition != "" {
  487. sql += condition
  488. }
  489. if orderBy != "" {
  490. sql += ` ORDER BY ` + orderBy
  491. } else {
  492. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC `
  493. }
  494. sql += ` LIMIT ?,? `
  495. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  496. return
  497. }
  498. // ModifyMysteelChemicalUpdateStatus
  499. // @Description: 修改钢联化工数据停更状态
  500. // @author: Roc
  501. // @datetime 2024-01-08 16:23:31
  502. // @param edbIdList []int
  503. // @param indexCodeList []string
  504. // @param isStop int
  505. // @return err error
  506. func ModifyMysteelChemicalUpdateStatus(edbIdList []int, indexCodeList []string, isStop int) (err error) {
  507. idNum := len(edbIdList)
  508. if idNum <= 0 {
  509. return
  510. }
  511. o, err := orm.NewOrmUsingDB("data").Begin()
  512. if err != nil {
  513. return
  514. }
  515. defer func() {
  516. if err != nil {
  517. _ = o.Rollback()
  518. return
  519. }
  520. _ = o.Commit()
  521. }()
  522. // 更改数据源的更新状态
  523. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = ? WHERE base_from_mysteel_chemical_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
  524. _, err = o.Raw(sql, isStop, edbIdList).Exec()
  525. if err != nil {
  526. return
  527. }
  528. codeNum := len(indexCodeList)
  529. if codeNum <= 0 {
  530. // 需要通过指标id列表查找code列表
  531. sql := ` SELECT index_code FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
  532. _, err = o.Raw(sql, edbIdList).QueryRows(&indexCodeList)
  533. if err != nil {
  534. return
  535. }
  536. }
  537. codeNum = len(indexCodeList)
  538. // 查出来的编码是空的话,那么就直接返回了
  539. if codeNum <= 0 {
  540. return
  541. }
  542. // 更改指标的更新状态
  543. sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_code IN (` + utils.GetOrmInReplace(codeNum) + `) `
  544. _, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, indexCodeList).Exec()
  545. if err != nil {
  546. return
  547. }
  548. return
  549. }
  550. // ModifyMysteelChemicalUpdateStatusByEdbInfoId
  551. // @Description: 修改单个钢联化工指标停更状态,同时停更依赖于该指标的计算指标
  552. // @author: Roc
  553. // @datetime 2024-01-08 16:23:31
  554. // @param edbIdList []int
  555. // @param indexCodeList []string
  556. // @param isStop int
  557. // @return err error
  558. func ModifyMysteelChemicalUpdateStatusByEdbInfoId(edbInfoId, isStop int, edbCode string, calculateEdbInfoIds []int) (err error) {
  559. o, err := orm.NewOrmUsingDB("data").Begin()
  560. if err != nil {
  561. return
  562. }
  563. defer func() {
  564. if err != nil {
  565. _ = o.Rollback()
  566. return
  567. }
  568. _ = o.Commit()
  569. }()
  570. // 更改数据源的更新状态
  571. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = ? WHERE index_code = ? `
  572. _, err = o.Raw(sql, isStop, edbCode).Exec()
  573. if err != nil {
  574. return
  575. }
  576. // 更改指标的更新状态
  577. sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_info_id=? `
  578. _, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, edbInfoId).Exec()
  579. if err != nil {
  580. return
  581. }
  582. if len(calculateEdbInfoIds) > 0 {
  583. // 批量更新相关联的指标ID
  584. sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  585. _, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
  586. if err != nil {
  587. return
  588. }
  589. }
  590. return
  591. }
  592. func ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbInfoIds []int, isStop int, edbCodes []string, calculateEdbInfoIds []int) (err error) {
  593. o, err := orm.NewOrmUsingDB("data").Begin()
  594. if err != nil {
  595. return
  596. }
  597. defer func() {
  598. if err != nil {
  599. _ = o.Rollback()
  600. return
  601. }
  602. _ = o.Commit()
  603. }()
  604. // 更改数据源的更新状态
  605. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = ? WHERE index_code IN (` + utils.GetOrmInReplace(len(edbCodes)) + `) `
  606. _, err = o.Raw(sql, isStop, edbCodes).Exec()
  607. if err != nil {
  608. return
  609. }
  610. // 更改指标的更新状态
  611. sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
  612. _, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbInfoIds).Exec()
  613. if err != nil {
  614. return
  615. }
  616. if len(calculateEdbInfoIds) > 0 {
  617. // 批量更新相关联的指标ID
  618. sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  619. _, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
  620. if err != nil {
  621. return
  622. }
  623. }
  624. return
  625. }