mysteel_chemical_index.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. // GetMysteelChemicalIndexDataByCode 通过钢联化工指标code获取所有数据列表
  288. func GetMysteelChemicalIndexDataByCode(indexCode string) (items []*MysteelChemicalData, err error) {
  289. sql := ` SELECT * FROM (
  290. SELECT DISTINCT a.index_code,a.value,a.data_time FROM base_from_mysteel_chemical_data AS a WHERE index_code=?
  291. ORDER BY data_time DESC
  292. )AS t
  293. GROUP BY t.data_time
  294. ORDER BY t.data_time DESC `
  295. o := orm.NewOrmUsingDB("data")
  296. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  297. return
  298. }
  299. // MoveBaseFromMysteelChemicalIndex 移动钢联化工指标分类
  300. func MoveBaseFromMysteelChemicalIndex(chartInfoId, classifyId int) (err error) {
  301. o := orm.NewOrmUsingDB("data")
  302. sql := ` UPDATE base_from_mysteel_chemical_index
  303. SET
  304. base_from_mysteel_chemical_classify_id = ?
  305. WHERE base_from_mysteel_chemical_index_id = ?`
  306. _, err = o.Raw(sql, classifyId, chartInfoId).Exec()
  307. return
  308. }
  309. // UpdateBaseFromMysteelChemicalIndexByClassifyId 根据指标id更新排序
  310. func UpdateBaseFromMysteelChemicalIndexByClassifyId(classifyId, nowSort, prevIndexInfoId int, updateSort string) (err error) {
  311. o := orm.NewOrmUsingDB("data")
  312. sql := ` update base_from_mysteel_chemical_index set sort = ` + updateSort + ` WHERE base_from_mysteel_chemical_classify_id=? AND `
  313. if prevIndexInfoId > 0 {
  314. sql += ` ( sort > ? or (base_from_mysteel_chemical_index_id > ` + fmt.Sprint(prevIndexInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  315. }
  316. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  317. return
  318. }
  319. // GetFirstBaseFromMysteelChemicalIndexByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  320. func GetFirstBaseFromMysteelChemicalIndexByClassifyId(classifyId int) (item *BaseFromMysteelChemicalIndex, err error) {
  321. o := orm.NewOrmUsingDB("data")
  322. 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`
  323. err = o.Raw(sql, classifyId).QueryRow(&item)
  324. return
  325. }
  326. // GetMysteelChemicalIndexCount 根据条件获取钢联化工数据
  327. func GetMysteelChemicalIndexCount(condition string, pars []interface{}) (count int, err error) {
  328. o := orm.NewOrmUsingDB("data")
  329. sql := ` SELECT COUNT(1) AS count FROM base_from_mysteel_chemical_index WHERE 1=1 `
  330. if condition != "" {
  331. sql += condition
  332. }
  333. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC `
  334. err = o.Raw(sql, pars).QueryRow(&count)
  335. return
  336. }
  337. // GetMysteelChemicalIndexList 根据分类id获取钢联化工频度数据列表
  338. func GetMysteelChemicalIndexList(condition string, pars []interface{}, startSize, pageSize int, orderDesc string) (items []*BaseFromMysteelChemicalIndex, err error) {
  339. o := orm.NewOrmUsingDB("data")
  340. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  341. if condition != "" {
  342. sql += condition
  343. }
  344. if orderDesc == `` {
  345. orderDesc = ` ASC `
  346. }
  347. sql += ` ORDER BY base_from_mysteel_chemical_index_id `
  348. sql += orderDesc
  349. sql += ` LIMIT ?,? `
  350. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  351. return
  352. }
  353. // GetMysteelChemicalIndexListGroupByUserId 根据指标id列表、用户分组获取指标信息
  354. func GetMysteelChemicalIndexListGroupByUserId(edbIdList []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  355. num := len(edbIdList)
  356. if num <= 0 {
  357. return
  358. }
  359. o := orm.NewOrmUsingDB("data")
  360. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  361. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  362. return
  363. }
  364. // GetMysteelChemicalIndexListByIndexId
  365. // @Description: 根据指标id列表获取列表信息
  366. // @param edbIdList
  367. // @return items
  368. // @return err
  369. func GetMysteelChemicalIndexListByIndexId(edbIdList []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  370. num := len(edbIdList)
  371. if num <= 0 {
  372. return
  373. }
  374. o := orm.NewOrmUsingDB("data")
  375. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id in (` + utils.GetOrmInReplace(num) + `) `
  376. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  377. return
  378. }
  379. // GetMysteelChemicalIndexListByUserId
  380. // @Description: 根据用户id列表获取列表信息
  381. // @param userIdList
  382. // @return items
  383. // @return err
  384. func GetMysteelChemicalIndexListByUserId(userIdList []int) (items []*BaseFromMysteelChemicalIndex, err error) {
  385. num := len(userIdList)
  386. if num <= 0 {
  387. return
  388. }
  389. o := orm.NewOrmUsingDB("data")
  390. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  391. _, err = o.Raw(sql, userIdList).QueryRows(&items)
  392. return
  393. }
  394. // ModifyMysteelChemicalIndexUserIdByCodeList 根据指标code列表修改创建人
  395. func ModifyMysteelChemicalIndexUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  396. num := len(edbIdList)
  397. if num <= 0 {
  398. return
  399. }
  400. o := orm.NewOrmUsingDB("data")
  401. 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) + `) `
  402. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  403. return
  404. }
  405. // ModifyMysteelChemicalIndexUserIdByOldUserId
  406. // @Description: 根据旧用户id修改新用户id
  407. // @author: Roc
  408. // @datetime 2024-03-25 17:59:08
  409. // @param oldUserId int
  410. // @param userId int
  411. // @param userName string
  412. // @return err error
  413. func ModifyMysteelChemicalIndexUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  414. num := len(oldUserIdList)
  415. if num <= 0 {
  416. return
  417. }
  418. o := orm.NewOrmUsingDB("data")
  419. sql := `UPDATE base_from_mysteel_chemical_index SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  420. _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  421. return
  422. }
  423. // GetMysteelChemicalIndexAdminList 获取所有指标创建人
  424. func GetMysteelChemicalIndexAdminList() (list []int, err error) {
  425. o := orm.NewOrmUsingDB("data")
  426. sql := ` SELECT sys_user_id FROM base_from_mysteel_chemical_index GROUP BY sys_user_id `
  427. _, err = o.Raw(sql).QueryRows(&list)
  428. return
  429. }
  430. type TerminalNum struct {
  431. TerminalCode string `description:"terminal_code"`
  432. Num int `description:"num"`
  433. }
  434. // GetMysteelChemicalGroupTerminalNum 获取钢联化工指标的终端分布
  435. func GetMysteelChemicalGroupTerminalNum() (items []*TerminalNum, err error) {
  436. o := orm.NewOrmUsingDB("data")
  437. sql := ` SELECT terminal_code,count(1) num FROM base_from_mysteel_chemical_index GROUP BY terminal_code ORDER BY num ASC `
  438. _, err = o.Raw(sql).QueryRows(&items)
  439. return
  440. }
  441. // BaseRefreshEdbInfo
  442. // @Description: 刷新配置的基础指标信息结构体
  443. type BaseRefreshEdbInfo struct {
  444. EdbInfoId int
  445. ClassifyId int `description:"钢联化工指标分类id"`
  446. IndexCode string `description:"指标编码"`
  447. IndexName string `description:"指标名称"`
  448. EndDate string `description:"最新日期"`
  449. EndValue string `description:"最新值"`
  450. SysUserId int `description:"创建人id"`
  451. SysUserRealName string `description:"创建人姓名"`
  452. Frequency string `description:"频度"`
  453. IsStop int `description:"是否停更:1:停更,0:未停更"`
  454. TerminalCode string `description:"终端编码"`
  455. RefreshTime string `description:"刷新时间"`
  456. }
  457. // RefreshBaseEdbInfoResp
  458. // @Description: 刷新数据源的数据返回
  459. type RefreshBaseEdbInfoResp struct {
  460. Paging *paging.PagingItem
  461. List []*BaseRefreshEdbInfo
  462. }
  463. // GetMysteelChemicalBaseInfoList
  464. // @Description: 获取钢联化工数据列表
  465. // @author: Roc
  466. // @datetime 2024-01-10 14:28:35
  467. // @param condition string
  468. // @param pars []interface{}
  469. // @param orderBy string
  470. // @param startSize int
  471. // @param pageSize int
  472. // @return total int
  473. // @return items []*BaseRefreshEdbInfo
  474. // @return err error
  475. func GetMysteelChemicalBaseInfoList(condition string, pars []interface{}, orderBy string, startSize, pageSize int) (total int, items []*BaseRefreshEdbInfo, err error) {
  476. o := orm.NewOrmUsingDB("data")
  477. // 数量汇总
  478. totalSql := ` SELECT count(1) FROM base_from_mysteel_chemical_index WHERE 1=1 `
  479. if condition != "" {
  480. totalSql += condition
  481. }
  482. err = o.Raw(totalSql, pars).QueryRow(&total)
  483. if err != nil {
  484. return
  485. }
  486. // 列表数据
  487. 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 `
  488. if condition != "" {
  489. sql += condition
  490. }
  491. if orderBy != "" {
  492. sql += ` ORDER BY ` + orderBy
  493. } else {
  494. sql += ` ORDER BY base_from_mysteel_chemical_index_id ASC `
  495. }
  496. sql += ` LIMIT ?,? `
  497. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  498. return
  499. }
  500. // ModifyMysteelChemicalUpdateStatus
  501. // @Description: 修改钢联化工数据停更状态
  502. // @author: Roc
  503. // @datetime 2024-01-08 16:23:31
  504. // @param edbIdList []int
  505. // @param indexCodeList []string
  506. // @param isStop int
  507. // @return err error
  508. func ModifyMysteelChemicalUpdateStatus(edbIdList []int, indexCodeList []string, isStop int) (err error) {
  509. idNum := len(edbIdList)
  510. if idNum <= 0 {
  511. return
  512. }
  513. o, err := orm.NewOrmUsingDB("data").Begin()
  514. if err != nil {
  515. return
  516. }
  517. defer func() {
  518. if err != nil {
  519. _ = o.Rollback()
  520. return
  521. }
  522. _ = o.Commit()
  523. }()
  524. // 更改数据源的更新状态
  525. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = ? WHERE base_from_mysteel_chemical_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
  526. _, err = o.Raw(sql, isStop, edbIdList).Exec()
  527. if err != nil {
  528. return
  529. }
  530. codeNum := len(indexCodeList)
  531. if codeNum <= 0 {
  532. // 需要通过指标id列表查找code列表
  533. sql := ` SELECT index_code FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
  534. _, err = o.Raw(sql, edbIdList).QueryRows(&indexCodeList)
  535. if err != nil {
  536. return
  537. }
  538. }
  539. codeNum = len(indexCodeList)
  540. // 查出来的编码是空的话,那么就直接返回了
  541. if codeNum <= 0 {
  542. return
  543. }
  544. // 更改指标的更新状态
  545. sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_code IN (` + utils.GetOrmInReplace(codeNum) + `) `
  546. _, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, indexCodeList).Exec()
  547. if err != nil {
  548. return
  549. }
  550. return
  551. }
  552. // ModifyMysteelChemicalUpdateStatusByEdbInfoId
  553. // @Description: 修改单个钢联化工指标停更状态,同时停更依赖于该指标的计算指标
  554. // @author: Roc
  555. // @datetime 2024-01-08 16:23:31
  556. // @param edbIdList []int
  557. // @param indexCodeList []string
  558. // @param isStop int
  559. // @return err error
  560. func ModifyMysteelChemicalUpdateStatusByEdbInfoId(edbInfoId, isStop int, edbCode string, calculateEdbInfoIds []int) (err error) {
  561. o, err := orm.NewOrmUsingDB("data").Begin()
  562. if err != nil {
  563. return
  564. }
  565. defer func() {
  566. if err != nil {
  567. _ = o.Rollback()
  568. return
  569. }
  570. _ = o.Commit()
  571. }()
  572. // 更改数据源的更新状态
  573. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = ? WHERE index_code = ? `
  574. _, err = o.Raw(sql, isStop, edbCode).Exec()
  575. if err != nil {
  576. return
  577. }
  578. // 更改指标的更新状态
  579. sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_info_id=? `
  580. _, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, edbInfoId).Exec()
  581. if err != nil {
  582. return
  583. }
  584. if len(calculateEdbInfoIds) > 0 {
  585. // 批量更新相关联的指标ID
  586. sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  587. _, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
  588. if err != nil {
  589. return
  590. }
  591. }
  592. return
  593. }
  594. func ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbInfoIds []int, isStop int, edbCodes []string, calculateEdbInfoIds []int) (err error) {
  595. o, err := orm.NewOrmUsingDB("data").Begin()
  596. if err != nil {
  597. return
  598. }
  599. defer func() {
  600. if err != nil {
  601. _ = o.Rollback()
  602. return
  603. }
  604. _ = o.Commit()
  605. }()
  606. // 更改数据源的更新状态
  607. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = ? WHERE index_code IN (` + utils.GetOrmInReplace(len(edbCodes)) + `) `
  608. _, err = o.Raw(sql, isStop, edbCodes).Exec()
  609. if err != nil {
  610. return
  611. }
  612. // 更改指标的更新状态
  613. sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
  614. _, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbInfoIds).Exec()
  615. if err != nil {
  616. return
  617. }
  618. if len(calculateEdbInfoIds) > 0 {
  619. // 批量更新相关联的指标ID
  620. sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  621. _, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
  622. if err != nil {
  623. return
  624. }
  625. }
  626. return
  627. }
  628. // GetNotIsSupplierStopIndexByCodeList
  629. // @Description: 获取未被供应商停更的指标
  630. // @author: Roc
  631. // @datetime 2024-08-28 18:15:03
  632. // @param codeList []string
  633. // @param isStop int
  634. // @return items []*BaseFromMysteelChemicalIndex
  635. // @return err error
  636. func GetNotIsSupplierStopIndexByCodeList(codeList []string, isStop int) (items []*BaseFromMysteelChemicalIndex, err error) {
  637. num := len(codeList)
  638. if num <= 0 {
  639. return
  640. }
  641. o := orm.NewOrmUsingDB("data")
  642. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE is_supplier_stop = ? AND index_code in (` + utils.GetOrmInReplace(num) + `) `
  643. _, err = o.Raw(sql, isStop, codeList).QueryRows(&items)
  644. return
  645. }