mysteel_chemical_index.go 21 KB

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