mysteel_chemical_index.go 28 KB

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