edb_info_calculate.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type EdbInfoCalculateSaveReq struct {
  9. EdbName string `description:"指标名称"`
  10. Frequency string `description:"频率"`
  11. Unit string `description:"单位"`
  12. ClassifyId int `description:"分类id"`
  13. CalculateFormula string `description:"计算公式"`
  14. Calendar string `description:"公历/农历"`
  15. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  16. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  17. Extra string `description:"指标的额外配置"`
  18. EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
  19. }
  20. type EdbInfoFromTag struct {
  21. EdbInfoId int `description:"指标id"`
  22. FromTag string `description:"指标对应标签"`
  23. MoveValue int `description:"移动的值"`
  24. }
  25. type EdbInfoCalculate struct {
  26. EdbInfoCalculateId int `gorm:"primaryKey" `
  27. EdbInfoId int `description:"指标id"`
  28. EdbCode string `description:"指标编码"`
  29. FromEdbInfoId int `description:"计算指标id"`
  30. FromEdbCode string `description:"计算指标编码"`
  31. FromEdbName string `description:"计算指标名称"`
  32. FromSource int `description:"计算指标来源"`
  33. FromSourceName string `description:"计算指标来源名称"`
  34. FromTag string `description:"来源指标标签"`
  35. Sort int `description:"计算指标名称排序"`
  36. CreateTime time.Time `description:"创建时间"`
  37. ModifyTime time.Time `description:"修改时间"`
  38. }
  39. type FromEdbInfoData struct {
  40. EdbInfoId int `description:"指标id"`
  41. EdbName string `description:"指标名称"`
  42. DataList []*EdbInfoSearchData
  43. }
  44. type EdbInfoCalculateDetail struct {
  45. EdbInfoCalculateId int `orm:"column(edb_info_calculate_id);pk" gorm:"primaryKey" `
  46. EdbInfoId int `description:"指标id"`
  47. EdbCode string `description:"指标编码"`
  48. FromEdbInfoId int `description:"计算指标id"`
  49. FromEdbCode string `description:"计算指标编码"`
  50. FromEdbName string `description:"计算指标名称"`
  51. FromEdbNameEn string `description:"计算指标名称"`
  52. FromSource int `description:"计算指标来源"`
  53. FromSourceName string `description:"计算指标来源名称"`
  54. FromTag string `description:"来源指标标签"`
  55. MoveValue int `description:"移动的值,小于0是提前,0是不变,大于0是滞后"`
  56. Sort int `description:"计算指标名称排序"`
  57. CreateTime string `description:"创建时间"`
  58. ModifyTime string `description:"修改时间"`
  59. StartDate string `description:"开始日期"`
  60. EndDate string `description:"结束日期"`
  61. LatestDate string `description:"实际的结束日期"`
  62. LatestValue float64 `description:"最近实际数据的值"`
  63. EndValue float64 `description:"结束日期的值(可能是插入值)"`
  64. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  65. Frequency string `description:"频率"`
  66. Unit string `description:"单位"`
  67. ClassifyId int `description:"分类id"`
  68. }
  69. func GetEdbInfoCalculateDetail(edbInfoId, source int) (list []*EdbInfoCalculateDetail, err error) {
  70. sql := ` SELECT a.edb_info_calculate_mapping_id,a.edb_info_id,a.source,a.source_name,a.edb_code,a.from_edb_info_id,a.from_edb_code,a.from_source,a.from_source_name,a.sort,a.create_time,a.modify_time,a.from_tag,a.move_value,b.edb_name as from_edb_name,b.edb_name_en as from_edb_name_en,b.start_date,b.end_date,b.latest_date,b.latest_value,b.edb_type, b.frequency, b.unit, b.classify_id FROM edb_info_calculate_mapping AS a
  71. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  72. WHERE a.edb_info_id=? ORDER BY sort ASC `
  73. err = global.DmSQL["data"].Raw(sql, edbInfoId).Scan(&list).Error
  74. if err != nil {
  75. return
  76. }
  77. for _, v := range list {
  78. v.ConvertToResp()
  79. }
  80. return
  81. }
  82. type CalculateDetailResp struct {
  83. EdbInfoDetail *EdbInfoFullClassify
  84. CalculateList []*EdbInfoCalculateDetail
  85. }
  86. type EdbInfoCalculateEditReq struct {
  87. EdbInfoId int `description:"指标id"`
  88. EdbName string `description:"指标名称"`
  89. Frequency string `description:"频率"`
  90. Unit string `description:"单位"`
  91. ClassifyId int `description:"分类id"`
  92. CalculateFormula string `description:"计算公式"`
  93. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  94. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  95. Extra string `description:"指标的额外配置"`
  96. EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
  97. }
  98. type EdbInfoBase struct {
  99. EdbInfoId int `description:"指标id"`
  100. EdbName string `description:"指标名称"`
  101. EdbNameEn string `description:"英文指标名称"`
  102. Frequency string `description:"频度"`
  103. Unit string `description:"单位"`
  104. UnitEn string `description:"英文单位"`
  105. ClassifyId int `description:"分类id"`
  106. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  107. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  108. }
  109. type CalculateEdbInfoItem struct {
  110. EdbInfoId int `description:"指标id"`
  111. EdbName string `description:"指标名称"`
  112. Frequency string `description:"频度"`
  113. Unit string `description:"单位"`
  114. ClassifyId int `description:"分类id"`
  115. CalculateId string `description:"当前请求时,单个计算的唯一标识"`
  116. FromEdbInfoId int `description:"计算来源指标id"`
  117. }
  118. type EdbInfoCalculateBatchSaveMultiReq struct {
  119. List []CalculateEdbInfoItem
  120. Formula string `description:"N值/移动天数"`
  121. FromEdbInfoId int `description:"计算来源指标id"`
  122. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:变频"`
  123. CalculateFormula string `description:"计算公式"`
  124. EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
  125. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  126. MoveFrequency string `description:"移动频度:天/周/月/季/年"`
  127. Extra string `description:"指标的额外配置"`
  128. Calendar string `description:"公历/农历"`
  129. }
  130. type EdbInfoCalculateBatchSaveReq struct {
  131. EdbInfoId int `description:"指标id"`
  132. EdbName string `description:"指标名称"`
  133. Frequency string `description:"频度"`
  134. Unit string `description:"单位"`
  135. ClassifyId int `description:"分类id"`
  136. Formula string `description:"N值/移动天数"`
  137. FromEdbInfoId int `description:"计算来源指标id"`
  138. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:变频"`
  139. CalculateFormula string `description:"计算公式"`
  140. EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
  141. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  142. MoveFrequency string `description:"移动频度:天/周/月/季/年"`
  143. Extra string `description:"指标的额外配置"`
  144. Calendar string `description:"公历/农历"`
  145. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  146. }
  147. type EdbInfoCalculateBatchEditReq struct {
  148. EdbName string `description:"指标名称"`
  149. Frequency string `description:"频度"`
  150. Unit string `description:"单位"`
  151. ClassifyId int `description:"分类id"`
  152. Formula string `description:"N值"`
  153. EdbInfoId int `description:"编辑指标id"`
  154. FromEdbInfoId int `description:"计算来源指标id"`
  155. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:变频"`
  156. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  157. MoveFrequency string `description:"移动频度:天/周/月/季/年"`
  158. Calendar string `description:"公历/农历"`
  159. Extra string `description:"指标的额外配置"`
  160. EdbInfoIdArr []EdbInfoFromTag
  161. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  162. }
  163. type EdbInfoCalculateBatchSaveReqByEdbLib struct {
  164. AdminId int `description:"添加人id"`
  165. AdminName string `description:"添加人名称"`
  166. EdbInfoId int `description:"指标id"`
  167. EdbName string `description:"指标名称"`
  168. Frequency string `description:"频度"`
  169. Unit string `description:"单位"`
  170. ClassifyId int `description:"分类id"`
  171. Formula string `description:"N值/移动天数"`
  172. FromEdbInfoId int `description:"计算来源指标id"`
  173. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:变频"`
  174. CalculateFormula string `description:"计算公式"`
  175. EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
  176. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  177. MoveFrequency string `description:"移动频度:天/周/月/季/年"`
  178. Calendar string `description:"公历/农历"`
  179. Data interface{} `description:"数据列"`
  180. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  181. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  182. Extra string `description:"指标的额外配置"`
  183. }
  184. type EdbInfoCalculateBatchEditReqByEdbLib struct {
  185. EdbName string `description:"指标名称"`
  186. Frequency string `description:"频度"`
  187. Unit string `description:"单位"`
  188. ClassifyId int `description:"分类id"`
  189. AdminId int `description:"操作人id"`
  190. AdminName string `description:"操作人姓名"`
  191. Formula string `description:"N值"`
  192. EdbInfoId int `description:"编辑指标id"`
  193. FromEdbInfoId int `description:"计算来源指标id"`
  194. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:变频"`
  195. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  196. MoveFrequency string `description:"移动频度:天/周/月/季/年"`
  197. Calendar string `description:"公历/农历"`
  198. EdbInfoIdArr []EdbInfoFromTag
  199. Data interface{} `description:"数据列"`
  200. Extra string `description:"指标的额外配置"`
  201. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  202. CalculateFormula string `description:"计算公式"`
  203. }
  204. func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfo, err error) {
  205. sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  206. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  207. WHERE a.edb_info_id=? ORDER BY sort ASC `
  208. err = global.DmSQL["data"].Raw(sql, edbInfoId).Find(&list).Error
  209. return
  210. }
  211. type CalculateItems struct {
  212. EdbInfoId int
  213. DataMap map[string]float64
  214. }
  215. type SaveAdjustEdbInfoReq struct {
  216. AdminId int `description:"添加人id"`
  217. AdminName string `description:"添加人名称"`
  218. EdbInfoId int `description:"指标id"`
  219. FromEdbInfoId int `description:"来源指标id"`
  220. EdbName string `description:"指标名称"`
  221. Frequency string `description:"频度"`
  222. Unit string `description:"单位"`
  223. ClassifyId int `description:"分类id"`
  224. DataList []SaveAdjustEdbDataReq `description:"指标对应的数据值"`
  225. }
  226. type SaveAdjustEdbDataReq struct {
  227. Date string `description:"数据日期"`
  228. Value float64 `description:"数据值"`
  229. }
  230. type BatchEdbInfoCalculateBatchSaveReq struct {
  231. AdminId int `description:"添加人id"`
  232. AdminName string `description:"添加人名称"`
  233. EdbList []*CalculateEdbInfoItem //需要批量计算的指标列表
  234. Formula string `description:"N值/移动天数"`
  235. Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,12:环比值,13:环差值,14:升频"`
  236. CalculateFormula string `description:"计算公式"`
  237. EdbInfoIdArr []EdbInfoFromTag `description:"关联指标列表"`
  238. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  239. MoveFrequency string `description:"移动频度:天/周/月/季/年"`
  240. Calendar string `description:"公历/农历"`
  241. Data interface{} `description:"数据"`
  242. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  243. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  244. Extra string `description:"指标的额外配置"`
  245. }
  246. type BatchEdbInfoCalculateBatchSaveResp struct {
  247. Fail []BatchEdbInfoCalculateBatchSaveFailResp `description:"添加失败的指标"`
  248. Success []BatchEdbInfoCalculateBatchSaveSuccessResp `description:"添加成功的指标"`
  249. }
  250. type BatchEdbInfoCalculateBatchSaveFailResp struct {
  251. CalculateId string `description:"当前请求时,单个计算的唯一标识"`
  252. Msg string `description:"用户提示信息"`
  253. ErrMsg string `description:"错误信息,内部查看"`
  254. }
  255. type BatchEdbInfoCalculateBatchSaveSuccessResp struct {
  256. ClassifyId int `description:"分类id"`
  257. CalculateId string `description:"当前请求时,单个计算的唯一标识"`
  258. EdbInfoId int `description:"指标ID"`
  259. UniqueCode string `description:"指标唯一编码"`
  260. }
  261. type CalculateMultiChoiceReq struct {
  262. ClassifyIds string `description:"分类ID, 用英文逗号拼接"`
  263. Frequency string `description:"频度"`
  264. SysUserIds string `description:"创建人ID,用英文逗号拼接"`
  265. Keyword string `description:"关键字"`
  266. SelectAll bool `description:"是否全选"`
  267. EdbInfoIds string `description:"指标Id, 用英文逗号拼接"`
  268. }
  269. type CalculateMultiChoiceResp struct {
  270. SearchItem []EdbInfoBase `description:"查询结果"`
  271. }
  272. type CalculateMultiEdbSearchResp struct {
  273. SearchItem []CalculateMultiEdbSearchItem `description:"查询结果"`
  274. Paging *paging.PagingItem
  275. }
  276. type CalculateMultiEdbSearchItem struct {
  277. EdbInfoId int `description:"指标id"`
  278. EdbName string `description:"指标名称"`
  279. EdbNameEn string `description:"英文指标名称"`
  280. Frequency string `description:"频度"`
  281. Unit string `description:"单位"`
  282. UnitEn string `description:"英文单位"`
  283. ClassifyId int `description:"分类id"`
  284. SysUserId int
  285. SysUserRealName string
  286. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  287. EndDate string `description:"终止日期"`
  288. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  289. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  290. }
  291. type BaseStepCalculateReq struct {
  292. DataList []*EdbInfoSearchData
  293. Calculates []FactorEdbSeriesCalculatePars
  294. }
  295. func (m *EdbInfoCalculateDetail) ConvertToResp() {
  296. m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
  297. m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
  298. m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
  299. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  300. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  301. return
  302. }