chart_edb_mapping.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. package data_manage
  2. import (
  3. sql2 "database/sql"
  4. "eta_gn/eta_api/global"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. )
  12. type ChartEdbMapping struct {
  13. ChartEdbMappingId int `orm:"column(chart_edb_mapping_id);pk" gorm:"primaryKey" `
  14. ChartInfoId int `description:"图表id"`
  15. EdbInfoId int `description:"指标id"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"修改时间"`
  18. UniqueCode string `description:"唯一编码"`
  19. MaxData float64 `description:"上限"`
  20. MinData float64 `description:"下限"`
  21. IsOrder bool `description:"true:正序,false:逆序"`
  22. IsAxis int `description:"true:左轴,false:右轴"`
  23. EdbInfoType int `description:"true:标准指标,false:领先指标"`
  24. LeadValue int `description:"领先值"`
  25. LeadUnit string `description:"领先单位"`
  26. ChartStyle string `description:"图表类型"`
  27. ChartColor string `description:"颜色"`
  28. PredictChartColor string `description:"预测数据的颜色"`
  29. ChartWidth float64 `description:"线条大小"`
  30. Source int `description:"1:ETA图库;2:商品价格曲线"`
  31. EdbAliasName string `description:"中文别名"`
  32. IsConvert int `description:"是否数据转换 0不转 1转"`
  33. ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  34. ConvertValue float64 `description:"数据转换值"`
  35. ConvertUnit string `description:"数据转换单位"`
  36. ConvertEnUnit string `description:"数据转换单位"`
  37. }
  38. func AddChartEdbMapping(items []*ChartEdbMapping) (err error) {
  39. err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error
  40. return
  41. }
  42. func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  43. o := global.DmSQL["data"]
  44. sql := ` SELECT a.*,b.source_name,b.source,b.sub_source,b.classify_id,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,
  45. b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.edb_type,b.is_join_permission,
  46. a.is_convert, a.convert_type, a.convert_value, a.convert_unit, a.convert_en_unit
  47. FROM chart_edb_mapping AS a
  48. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  49. WHERE chart_info_id=?
  50. ORDER BY chart_edb_mapping_id ASC `
  51. err = o.Raw(sql, chartInfoId).Scan(&list).Error
  52. if err != nil {
  53. return
  54. }
  55. // 日期格式转换
  56. for _, v := range list {
  57. v.ConvertToResp()
  58. }
  59. return
  60. }
  61. func GetChartMappingList(chartInfoId int) (list []*ChartEdbMapping, err error) {
  62. o := global.DmSQL["data"]
  63. sql := ` SELECT a.*
  64. FROM chart_edb_mapping AS a
  65. WHERE chart_info_id=?
  66. ORDER BY chart_edb_mapping_id ASC `
  67. err = o.Raw(sql, chartInfoId).Scan(&list).Error
  68. return
  69. }
  70. func GetChartEdbMappingListByChartInfoIds(chartInfoIds string) (list []*ChartEdbInfoMapping, err error) {
  71. o := global.DmSQL["data"]
  72. sql := ` SELECT a.*,b.source_name,b.source,b.sub_source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.edb_type,b.classify_id,b.is_join_permission
  73. FROM chart_edb_mapping AS a
  74. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  75. WHERE chart_info_id in (` + chartInfoIds + `)
  76. ORDER BY chart_edb_mapping_id ASC `
  77. err = o.Raw(sql).Scan(&list).Error
  78. if err != nil {
  79. return
  80. }
  81. // 日期格式转换
  82. for _, v := range list {
  83. v.ConvertToResp()
  84. }
  85. return
  86. }
  87. func GetChartEdbMappingListByChartInfoIdList(chartInfoIdList []int) (list []*ChartEdbInfoMapping, err error) {
  88. if len(chartInfoIdList) <= 0 {
  89. return
  90. }
  91. o := global.DmSQL["data"]
  92. sql := ` SELECT a.*,b.source_name,b.source,b.sub_source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.edb_type,b.classify_id,b.is_join_permission
  93. FROM chart_edb_mapping AS a
  94. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  95. WHERE chart_info_id in (?)
  96. ORDER BY chart_edb_mapping_id ASC `
  97. err = o.Raw(sql, chartInfoIdList).Scan(&list).Error
  98. if err != nil {
  99. return
  100. }
  101. // 日期格式转换
  102. for _, v := range list {
  103. v.ConvertToResp()
  104. }
  105. return
  106. }
  107. func GetChartEdbMappingListByEdbInfoId(edbInfoStr string) (list []*ChartEdbInfoMapping, err error) {
  108. o := global.DmSQL["data"]
  109. sql := ` SELECT edb_info_id,source_name,source,sub_source,edb_code,edb_name,edb_name_en,frequency,unit,unit_en,start_date,end_date,modify_time,latest_date,latest_value,unique_code,edb_info_type AS edb_info_category_type,max_value,min_value,edb_type,classify_id,is_join_permission
  110. FROM edb_info
  111. WHERE edb_info_id IN(` + edbInfoStr + `)
  112. ORDER BY FIELD(edb_info_id,` + edbInfoStr + `)
  113. `
  114. err = o.Raw(sql).Scan(&list).Error
  115. if err != nil {
  116. return
  117. }
  118. // 日期格式转换
  119. for _, v := range list {
  120. v.ConvertToResp()
  121. }
  122. return
  123. }
  124. // GetChartEdbMappingListByEdbInfoIdList 根据指标id列表获取关联关系
  125. func GetChartEdbMappingListByEdbInfoIdList(edbIdList []int) (list []*ChartEdbInfoMapping, err error) {
  126. num := len(edbIdList)
  127. if num <= 0 {
  128. return
  129. }
  130. edbIdArr := make([]string, 0)
  131. for _, v := range edbIdList {
  132. edbIdArr = append(edbIdArr, strconv.Itoa(v))
  133. }
  134. edbIdStr := strings.Join(edbIdArr, ",")
  135. o := global.DmSQL["data"]
  136. sql := ` SELECT edb_info_id,source_name,source,sub_source,edb_code,edb_name,edb_name_en,frequency,unit,unit_en,start_date,end_date,modify_time,latest_date,latest_value,unique_code,edb_info_type AS edb_info_category_type,max_value,min_value,edb_type,classify_id,is_join_permission
  137. FROM edb_info
  138. WHERE edb_info_id IN(` + edbIdStr + `)
  139. ORDER BY FIELD(edb_info_id,` + edbIdStr + `) `
  140. err = o.Raw(sql).Find(&list).Error
  141. if err != nil {
  142. return
  143. }
  144. // 日期格式转换
  145. for _, v := range list {
  146. v.ConvertToResp()
  147. }
  148. return
  149. }
  150. // GetChartEdbMappingListByIdList 通过图表id列表获取
  151. func GetChartEdbMappingListByIdList(chartInfoIdList []int) (list []*ChartEdbInfoMapping, err error) {
  152. num := len(chartInfoIdList)
  153. if num <= 0 {
  154. return
  155. }
  156. o := global.DmSQL["data"]
  157. sql := ` SELECT a.*,b.source_name,b.source,b.sub_source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type,b.edb_type AS edb_info_category_type,b.classify_id,b.is_join_permission
  158. FROM chart_edb_mapping AS a
  159. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  160. WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `)
  161. ORDER BY chart_edb_mapping_id ASC `
  162. err = o.Raw(sql, chartInfoIdList).Scan(&list).Error
  163. if err != nil {
  164. return
  165. }
  166. // 日期格式转换
  167. for _, v := range list {
  168. v.ConvertToResp()
  169. }
  170. return
  171. }
  172. // RelationEdbInfoListResp 关联指标列表数据返回
  173. type RelationEdbInfoListResp struct {
  174. Paging *paging.PagingItem
  175. List []*ChartEdbInfoMapping
  176. }
  177. func GetRelationEdbInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*ChartEdbInfoMapping, err error) {
  178. o := global.DmSQL["data"]
  179. sql := ` SELECT a.* FROM edb_info AS a
  180. JOIN edb_info_calculate_mapping AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
  181. if condition != "" {
  182. sql += condition
  183. }
  184. //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  185. sql += " ORDER BY a.create_time DESC LIMIT ?,? "
  186. pars = append(pars, startSize)
  187. pars = append(pars, pageSize)
  188. err = o.Raw(sql, pars...).Scan(&item).Error
  189. return
  190. }
  191. func GetRelationEdbInfoListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  192. o := global.DmSQL["data"]
  193. sql := ` SELECT COUNT(1) AS count FROM edb_info AS a
  194. JOIN edb_info_calculate_mapping AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
  195. if condition != "" {
  196. sql += condition
  197. }
  198. err = o.Raw(sql, pars...).Scan(&count).Error
  199. return
  200. }
  201. // GetEtaEdbChartEdbMapping 商品曲线图查询对应的普通指标
  202. func GetEtaEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  203. o := global.DmSQL["data"]
  204. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  205. sql := ` SELECT ` + aField + `,b.source_name,b.source,b.sub_source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.classify_id,b.is_join_permission
  206. FROM chart_edb_mapping AS a
  207. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  208. WHERE a.chart_info_id=? AND a.source = ?
  209. ORDER BY chart_edb_mapping_id ASC `
  210. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).Scan(&item).Error
  211. if err != nil {
  212. return
  213. }
  214. // 日期格式转换
  215. item.ConvertToResp()
  216. return
  217. }
  218. // GetEtaEdbChartEdbMappingList 商品曲线图查询对应的普通指标
  219. func GetEtaEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  220. o := global.DmSQL["data"]
  221. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  222. sql := ` SELECT ` + aField + `,b.source_name,b.source,b.sub_source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.classify_id,b.is_join_permission
  223. FROM chart_edb_mapping AS a
  224. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  225. WHERE a.chart_info_id=? AND a.source = ?
  226. ORDER BY chart_edb_mapping_id ASC `
  227. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).Scan(&items).Error
  228. if err != nil {
  229. return
  230. }
  231. // 日期格式转换
  232. for _, v := range items {
  233. v.ConvertToResp()
  234. }
  235. return
  236. }
  237. // GetFutureGoodEdbChartEdbMapping 商品曲线图查询对应的商品指标
  238. func GetFutureGoodEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  239. o := global.DmSQL["data"]
  240. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  241. sql := ` SELECT ` + aField + `,b.future_good_edb_info_id,b.future_good_edb_code as edb_code,b.future_good_edb_name as edb_name,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value
  242. FROM chart_edb_mapping AS a
  243. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  244. WHERE a.chart_info_id=? AND a.source = ?
  245. ORDER BY chart_edb_mapping_id ASC `
  246. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).Scan(&item).Error
  247. if err != nil {
  248. return
  249. }
  250. // 日期格式转换
  251. item.ConvertToResp()
  252. return
  253. }
  254. // GetFutureGoodEdbChartEdbMappingList 商品曲线图查询对应的商品指标
  255. func GetFutureGoodEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  256. o := global.DmSQL["data"]
  257. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  258. sql := ` SELECT ` + aField + `,b.future_good_edb_info_id,b.future_good_edb_code as edb_code,b.future_good_edb_name as edb_name,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value
  259. FROM chart_edb_mapping AS a
  260. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  261. WHERE a.chart_info_id=? AND a.source = ?
  262. ORDER BY chart_edb_mapping_id ASC `
  263. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).Scan(&items).Error
  264. if err != nil {
  265. return
  266. }
  267. // 日期格式转换
  268. for _, v := range items {
  269. v.ConvertToResp()
  270. }
  271. return
  272. }
  273. // GetChartEdbMappingListV2 根据图表id获取指标信息,不连表查询指标表
  274. func GetChartEdbMappingListV2(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  275. o := global.DmSQL["data"]
  276. sql := ` SELECT a.* FROM chart_edb_mapping AS a
  277. WHERE chart_info_id=?
  278. ORDER BY chart_edb_mapping_id ASC `
  279. err = o.Raw(sql, chartInfoId).Scan(&list).Error
  280. if err != nil {
  281. return
  282. }
  283. // 日期格式转换
  284. for _, v := range list {
  285. v.ConvertToResp()
  286. }
  287. return
  288. }
  289. // GetChartEdbMappingByEdbInfoId 根据指标id获取edb_mapping
  290. func GetChartEdbMappingByEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
  291. o := global.DmSQL["data"]
  292. sql := ` SELECT edb_info_id,source_name,classify_id,source,sub_source,edb_code,edb_name,edb_name_en,frequency,unit,unit_en,start_date,end_date,modify_time,latest_date,latest_value,unique_code,edb_info_type AS edb_info_category_type,edb_type,max_value,min_value,is_join_permission
  293. FROM edb_info
  294. WHERE edb_info_id = ? `
  295. err = o.Raw(sql, edbInfoId).First(&item).Error
  296. if err != nil {
  297. return
  298. }
  299. // 日期格式转换
  300. item.ConvertToResp()
  301. return
  302. }
  303. // GetEdbMappingListByEdbInfoId 根据指标id获取edb_mapping
  304. func GetEdbMappingListByEdbInfoId(edbInfoId int) (list []*ChartEdbInfoMapping, err error) {
  305. o := global.DmSQL["data"]
  306. sql := ` SELECT * FROM chart_edb_mapping
  307. WHERE edb_info_id = ? `
  308. err = o.Raw(sql, edbInfoId).Scan(&list).Error
  309. if err != nil {
  310. return
  311. }
  312. // 日期格式转换
  313. for _, v := range list {
  314. v.ConvertToResp()
  315. }
  316. return
  317. }
  318. // GetChartEdbMappingByFutureGoodEdbInfoId 根据指标id获取edb_mapping
  319. func GetChartEdbMappingByFutureGoodEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
  320. o := global.DmSQL["data"]
  321. sql := ` SELECT future_good_edb_info_id as edb_info_id,future_good_edb_code as edb_code,b.future_good_edb_name as edb_name,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.region_type
  322. FROM future_good_edb_info b
  323. WHERE future_good_edb_info_id = ? limit 1 `
  324. err = o.Raw(sql, edbInfoId).Scan(&item).Error
  325. if err != nil {
  326. return
  327. }
  328. // 日期格式转换
  329. item.ConvertToResp()
  330. return
  331. }
  332. // ModifyChartEdbMapping
  333. // @Description: 修改图表的关系表
  334. // @author: Roc
  335. // @datetime 2023-12-11 17:23:32
  336. // @param chartInfoId int
  337. // @param edbInfoList []*EdbInfo
  338. // @return err error
  339. func ModifyChartEdbMapping(chartInfoId int, edbInfoList []*EdbInfo) (err error) {
  340. o := global.DmSQL["data"].Begin()
  341. defer func() {
  342. if err != nil {
  343. fmt.Println("AddCalculateHcz,Err:" + err.Error())
  344. _ = o.Rollback()
  345. } else {
  346. _ = o.Commit()
  347. }
  348. }()
  349. list := make([]*ChartEdbMapping, 0)
  350. sql := ` SELECT a.*
  351. FROM chart_edb_mapping AS a
  352. WHERE chart_info_id=?
  353. ORDER BY chart_edb_mapping_id ASC `
  354. err = o.Raw(sql, chartInfoId).Scan(&list).Error
  355. if err != nil {
  356. return
  357. }
  358. mappingIdMap := make(map[int]*ChartEdbMapping)
  359. removeMapping := make(map[int]int)
  360. for _, v := range list {
  361. mappingIdMap[v.EdbInfoId] = v
  362. removeMapping[v.EdbInfoId] = v.ChartEdbMappingId
  363. }
  364. addList := make([]*ChartEdbMapping, 0)
  365. for _, v := range edbInfoList {
  366. _, ok := mappingIdMap[v.EdbInfoId]
  367. // 存在该指标关系就不处理了
  368. if ok {
  369. delete(removeMapping, v.EdbInfoId)
  370. continue
  371. }
  372. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  373. // 不存在就添加
  374. addList = append(addList, &ChartEdbMapping{
  375. //ChartEdbMappingId: 0,
  376. ChartInfoId: chartInfoId,
  377. EdbInfoId: v.EdbInfoId,
  378. CreateTime: time.Now(),
  379. ModifyTime: time.Now(),
  380. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + fmt.Sprint(chartInfoId) + "_" + fmt.Sprint(v.EdbInfoId) + "_" + timestamp),
  381. MaxData: v.MaxValue,
  382. MinData: v.MinValue,
  383. EdbInfoType: v.EdbInfoType,
  384. Source: v.Source,
  385. })
  386. }
  387. // 需要添加的话,那就添加吧
  388. if len(addList) > 0 {
  389. err = o.CreateInBatches(addList, utils.MultiAddNum).Error
  390. if err != nil {
  391. return
  392. }
  393. }
  394. // 移除不必要的mapping
  395. if len(removeMapping) > 0 {
  396. removeIdList := make([]string, 0) //需要移除的日期
  397. for _, v := range removeMapping {
  398. removeIdList = append(removeIdList, fmt.Sprint(v))
  399. }
  400. removeIdStr := strings.Join(removeIdList, `","`)
  401. removeIdStr = `"` + removeIdStr + `"`
  402. //如果拼接指标变更了,那么需要删除所有的指标数据
  403. sql := fmt.Sprintf(` DELETE FROM chart_edb_mapping WHERE chart_edb_mapping_id in (%s) `, removeIdStr)
  404. err = o.Exec(sql).Error
  405. if err != nil {
  406. err = fmt.Errorf("移除不必要的mapping失败,Err:" + err.Error())
  407. return
  408. }
  409. }
  410. return
  411. }
  412. func GetRelationEdbInfoListMappingByCondition(condition string, pars []interface{}) (item []*ChartEdbInfoMapping, err error) {
  413. o := global.DmSQL["data"]
  414. sql := ` SELECT a.* FROM edb_info AS a
  415. JOIN edb_info_calculate_mapping AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
  416. if condition != "" {
  417. sql += condition
  418. }
  419. err = o.Raw(sql, pars...).Scan(&item).Error
  420. return
  421. }
  422. // GetCountRelationChartEdbInfoListMappingByCondition
  423. // @Description: 根据条件获取关联图数量
  424. // @author: Roc
  425. // @datetime 2024-12-26 10:13:47
  426. // @param condition string
  427. // @param pars []interface{}
  428. // @return total int
  429. // @return err error
  430. func GetCountRelationChartEdbInfoListMappingByCondition(condition string, pars []interface{}) (total int, err error) {
  431. o := global.DmSQL["data"]
  432. sql := ` SELECT COUNT(1) total FROM chart_edb_mapping AS a
  433. JOIN chart_info AS b on a.chart_info_id = b.chart_info_id WHERE 1=1 `
  434. if condition != "" {
  435. sql += condition
  436. }
  437. var totalNull sql2.NullInt64
  438. err = o.Raw(sql, pars...).Scan(&totalNull).Error
  439. if err != nil {
  440. return
  441. }
  442. total = int(totalNull.Int64)
  443. return
  444. }
  445. // GetUserIdListRelationChartEdbInfoListMappingByCondition
  446. // @Description: 根据条件获取关联图的用户id列表
  447. // @author: Roc
  448. // @datetime 2024-12-26 10:13:47
  449. // @param condition string
  450. // @param pars []interface{}
  451. // @return total int
  452. // @return err error
  453. func GetUserIdListRelationChartEdbInfoListMappingByCondition(condition string, pars []interface{}) (userIdList []int, err error) {
  454. o := global.DmSQL["data"]
  455. sql := ` SELECT b.sys_user_id FROM chart_edb_mapping AS a
  456. JOIN chart_info AS b on a.chart_info_id = b.chart_info_id WHERE 1=1 `
  457. if condition != "" {
  458. sql += condition
  459. }
  460. sql += ` GROUP BY b.sys_user_id `
  461. err = o.Raw(sql, pars...).Scan(&userIdList).Error
  462. return
  463. }