mysteel_chemical_index.go 25 KB

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