future_good_chart_info.go 7.7 KB

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