future_good_chart_info.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "time"
  7. )
  8. // EditFutureGoodChartEnInfoAndEdbEnInfo 更改商品价格曲线英文信息
  9. func EditFutureGoodChartEnInfoAndEdbEnInfo(chartInfoId int, chartNameEn string, edbInfoId int, edbNameEn, edbUnitEn string) (err error) {
  10. to := global.DmSQL["data"].Begin()
  11. defer func() {
  12. if err != nil {
  13. _ = to.Rollback()
  14. } else {
  15. _ = to.Commit()
  16. }
  17. }()
  18. sql := ` UPDATE chart_info
  19. SET
  20. chart_name_en =?,
  21. modify_time = NOW()
  22. WHERE chart_info_id = ?`
  23. err = to.Exec(sql, chartNameEn, chartInfoId).Error
  24. if err != nil {
  25. fmt.Println("UPDATE chart_info Err:", err.Error())
  26. return err
  27. }
  28. var count int
  29. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = 1 `
  30. err = to.Raw(csql, chartInfoId, edbInfoId).Scan(&count).Error
  31. if err != nil {
  32. fmt.Println("QueryRow Err:", err.Error())
  33. return err
  34. }
  35. if count > 0 {
  36. msql := ` UPDATE edb_info
  37. SET edb_name_en = ?,
  38. unit_en = ?,
  39. modify_time = NOW()
  40. WHERE edb_info_id = ? `
  41. err = to.Exec(msql, edbNameEn, edbUnitEn, edbInfoId).Error
  42. if err != nil {
  43. fmt.Println("edb_info Err:" + err.Error())
  44. return err
  45. }
  46. }
  47. return
  48. }
  49. type EditFutureGoodChartInfoBaseReq struct {
  50. ChartInfoId int `description:"图表ID"`
  51. ChartName string `description:"图表名称(根据当前语言版本不同而不同)"`
  52. /* EdbName string `description:"指标名称(根据当前语言版本不同而不同)"`
  53. Unit string `description:"指标单位(根据当前语言版本不同而不同)"`*/
  54. ProfitName string `description:"利润名称(根据当前语言版本不同而不同)"`
  55. FutureGoodName string `description:"期货合约名称(根据当前语言版本不同而不同)"`
  56. ChartEdbInfoList []*EditChartInfoEdbBaseItem `description:"指标及配置信息"`
  57. XDataList []string `description:"商品价格曲线的X轴数据"`
  58. }
  59. // EditBaseFutureGoodChartInfoAndEdbEnInfo
  60. // @Description: 编辑期货商品基础的图表信息及指标信息
  61. // @author: Roc
  62. // @datetime 2024-04-23 13:58:23
  63. // @param chartInfo ChartInfo
  64. // @param chartName string
  65. // @param edbInfoId int
  66. // @param edbName string
  67. // @param edbUnit string
  68. // @param lang string
  69. // @return err error
  70. func EditBaseFutureGoodChartInfoAndEdbEnInfo(chartInfo *ChartInfo, req *EditFutureGoodChartInfoBaseReq, lang string) (err error) {
  71. to := global.DmSQL["data"].Begin()
  72. defer func() {
  73. if err != nil {
  74. _ = to.Rollback()
  75. } else {
  76. _ = to.Commit()
  77. }
  78. }()
  79. // 修改图表信息
  80. updateChartCols := make([]string, 0)
  81. switch lang {
  82. case utils.EnLangVersion:
  83. chartInfo.ChartNameEn = req.ChartName
  84. updateChartCols = append(updateChartCols, "ChartNameEn")
  85. default:
  86. chartInfo.ChartName = req.ChartName
  87. updateChartCols = append(updateChartCols, "ChartName")
  88. }
  89. chartInfo.ModifyTime = time.Now()
  90. updateChartCols = append(updateChartCols, "ModifyTime", "BarConfig")
  91. err = to.Select(updateChartCols).Updates(chartInfo).Error
  92. if err != nil {
  93. fmt.Println("UPDATE chart_info Err:", err.Error())
  94. return err
  95. }
  96. for _, v := range req.ChartEdbInfoList {
  97. msql := ` UPDATE edb_info SET modify_time = NOW() `
  98. pars := make([]interface{}, 0)
  99. switch lang {
  100. case utils.EnLangVersion:
  101. if v.EdbName != `` {
  102. msql += ` ,edb_name_en = ? `
  103. pars = append(pars, v.EdbName)
  104. }
  105. if v.Unit != `` {
  106. msql += ` ,unit_en = ? `
  107. pars = append(pars, v.Unit)
  108. }
  109. default:
  110. if v.EdbName != `` {
  111. msql += ` ,edb_name = ? `
  112. pars = append(pars, v.EdbName)
  113. }
  114. if v.Unit != `` {
  115. msql += ` ,unit = ? `
  116. pars = append(pars, v.Unit)
  117. }
  118. }
  119. msql += ` WHERE edb_info_id = ? `
  120. pars = append(pars, v.EdbInfoId)
  121. err = to.Exec(msql, pars...).Error
  122. if err != nil {
  123. fmt.Println("edb_info Err:" + err.Error())
  124. return err
  125. }
  126. }
  127. return
  128. }
  129. // EditFutureGoodProfitChartEnInfoAndEdbEnInfo 更改商品利润曲线英文信息
  130. func EditFutureGoodProfitChartEnInfoAndEdbEnInfo(chartInfoId int, chartNameEn string, edbInfoId int, edbNameEn, edbUnitEn, profitNameEn string) (err error) {
  131. to := global.DmSQL["data"].Begin()
  132. defer func() {
  133. if err != nil {
  134. _ = to.Rollback()
  135. } else {
  136. _ = to.Commit()
  137. }
  138. }()
  139. sql := ` UPDATE chart_info
  140. SET chart_name_en =?,modify_time = NOW()
  141. WHERE chart_info_id = ?`
  142. err = to.Exec(sql, chartNameEn, chartInfoId).Error
  143. if err != nil {
  144. fmt.Println("UPDATE chart_info Err:", err.Error())
  145. return
  146. }
  147. // 更改指标英文信息
  148. sql = ` UPDATE edb_info
  149. SET edb_name_en = ?,unit_en = ?,modify_time = NOW()
  150. WHERE edb_info_id = ? `
  151. err = to.Exec(sql, edbNameEn, edbUnitEn, edbInfoId).Error
  152. if err != nil {
  153. fmt.Println("edb_info Err:" + err.Error())
  154. return
  155. }
  156. // 更改指标英文信息
  157. sql = ` UPDATE chart_info_future_good_profit
  158. SET profit_name_en = ?,modify_time = NOW()
  159. WHERE chart_info_id = ? `
  160. err = to.Exec(sql, profitNameEn, chartInfoId).Error
  161. if err != nil {
  162. fmt.Println("chart_info_future_good_profit Err:" + err.Error())
  163. return
  164. }
  165. return
  166. }
  167. // EditBaseFutureGoodProfitChartInfoAndEdbEnInfo
  168. // @Description: 更改商品利润曲线基础信息
  169. // @author: Roc
  170. // @datetime 2024-04-23 14:36:45
  171. // @param chartInfo *ChartInfo
  172. // @param chartName string
  173. // @param edbInfoId int
  174. // @param edbName string
  175. // @param edbUnit string
  176. // @param profitName string
  177. // @param lang string
  178. // @return err error
  179. func EditBaseFutureGoodProfitChartInfoAndEdbEnInfo(chartInfo *ChartInfo, req *EditFutureGoodChartInfoBaseReq, lang string) (err error) {
  180. to := global.DmSQL["data"].Begin()
  181. defer func() {
  182. if err != nil {
  183. _ = to.Rollback()
  184. } else {
  185. _ = to.Commit()
  186. }
  187. }()
  188. // 修改图表信息
  189. updateChartCols := make([]string, 0)
  190. switch lang {
  191. case utils.EnLangVersion:
  192. chartInfo.ChartNameEn = req.ChartName
  193. updateChartCols = append(updateChartCols, "ChartNameEn")
  194. default:
  195. chartInfo.ChartName = req.ChartName
  196. updateChartCols = append(updateChartCols, "ChartName")
  197. }
  198. chartInfo.ModifyTime = time.Now()
  199. updateChartCols = append(updateChartCols, "ModifyTime", "ExtraConfig")
  200. err = to.Select(updateChartCols).Updates(chartInfo).Error
  201. if err != nil {
  202. fmt.Println("UPDATE chart_info Err:", err.Error())
  203. return err
  204. }
  205. var sql string
  206. // 更改指标英文信息
  207. for _, v := range req.ChartEdbInfoList {
  208. msql := ` UPDATE edb_info SET modify_time = NOW() `
  209. pars := make([]interface{}, 0)
  210. switch lang {
  211. case utils.EnLangVersion:
  212. if v.EdbName != `` {
  213. msql += ` ,edb_name_en = ? `
  214. pars = append(pars, v.EdbName)
  215. }
  216. if v.Unit != `` {
  217. msql += ` ,unit_en = ? `
  218. pars = append(pars, v.Unit)
  219. }
  220. default:
  221. if v.EdbName != `` {
  222. msql += ` ,edb_name = ? `
  223. pars = append(pars, v.EdbName)
  224. }
  225. if v.Unit != `` {
  226. msql += ` ,unit = ? `
  227. pars = append(pars, v.Unit)
  228. }
  229. }
  230. msql += ` WHERE edb_info_id = ? `
  231. pars = append(pars, v.EdbInfoId)
  232. err = to.Exec(msql, pars...).Error
  233. if err != nil {
  234. fmt.Println("edb_info Err:" + err.Error())
  235. return err
  236. }
  237. }
  238. // 更改指标英文信息
  239. switch lang {
  240. case utils.EnLangVersion:
  241. sql = ` UPDATE chart_info_future_good_profit SET profit_name_en = ?,modify_time = NOW() WHERE chart_info_id = ? `
  242. default:
  243. sql = ` UPDATE chart_info_future_good_profit SET profit_name = ?,modify_time = NOW() WHERE chart_info_id = ? `
  244. }
  245. err = to.Exec(sql, req.ProfitName, chartInfo.ChartInfoId).Error
  246. if err != nil {
  247. fmt.Println("chart_info_future_good_profit Err:" + err.Error())
  248. return
  249. }
  250. return
  251. }