edb_info_calculate.go 18 KB

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