mysteel_chemical_index.go 28 KB

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