edb_info_calculate.go 18 KB

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