mysteel_chemical_index.go 24 KB

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