operationDataPuller.dos 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. module fundit::operationDataPuller
  2. use fundit::sqlUtilities
  3. /*
  4. * 取所有一级策略
  5. *
  6. */
  7. def get_strategy_list() {
  8. s_query = "SELECT strategy_id, strategy, rasie_type AS raise_type FROM mfdb.d_strategy WHERE isvalid = 1";
  9. conn = connect_mysql()
  10. t = odbc::query(conn, s_query)
  11. conn.close()
  12. return t
  13. }
  14. /*
  15. * 取所有二级策略
  16. *
  17. */
  18. def get_substrategy_list() {
  19. s_query = "SELECT substrategy_id, substrategy, raise_type FROM mfdb.d_substrategy WHERE isvalid = 1";
  20. conn = connect_mysql()
  21. t = odbc::query(conn, s_query)
  22. conn.close()
  23. return t
  24. }
  25. /*
  26. * 取有效基金基本信息
  27. *
  28. * Example: get_fund_info("'HF000004KN','HF00018WXG'");
  29. * get_fund_info(null);
  30. *
  31. */
  32. def get_fund_info(fund_ids) {
  33. s_entity_ids = ids_to_string(fund_ids);
  34. s_entity_sql = iif(s_entity_ids == NULL, '', " AND fi.fund_id IN (" + s_entity_ids + ")");
  35. s_query = "SELECT fi.fund_id, fi.inception_date, fi.primary_benchmark_id AS benchmark_id, IFNULL(fi.initial_unit_value, 1) AS ini_value, fs.strategy, fs.substrategy, fi.raise_type, fi.p_fund_id
  36. FROM mfdb.fund_information fi
  37. INNER JOIN mfdb.fund_strategy fs ON fi.fund_id = fs.fund_id
  38. WHERE fs.isvalid = 1
  39. AND fi.isvalid = 1" +
  40. s_entity_sql + "
  41. ORDER BY fi.fund_id"
  42. conn = connect_mysql()
  43. t = odbc::query(conn, s_query)
  44. conn.close()
  45. return t
  46. }
  47. /*
  48. * 取有效指数基本信息
  49. *
  50. * Example: get_index_info("'IN00000008','IN000002GE'");
  51. * get_index_info(null);
  52. *
  53. */
  54. def get_index_info(index_ids) {
  55. s_entity_ids = ids_to_string(index_ids);
  56. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND fi.index_id IN (" + s_entity_ids + ")");
  57. s_query = "SELECT fi.index_id, fi.inception_date, NULL AS benchmark_id, IFNULL(fi.index_initial_value, 1) AS ini_value, fi.index_code, fi.index_type_id
  58. FROM mfdb.indexes_profile fi
  59. WHERE fi.isvalid = 1" +
  60. s_entity_sql + "
  61. ORDER BY fi.index_id";
  62. conn = connect_mysql();
  63. t = odbc::query(conn, s_query);
  64. conn.close();
  65. return t;
  66. }
  67. /*
  68. * 取组合有效信息
  69. *
  70. * NOTE: portfolio 的 strategy 统一为公募混合基金102, sub_strategy 用 sub_type (哪里维护的?)
  71. *
  72. * Example: get_portfolio_info('166002,166114');
  73. * get_portfolio_info(NULL);
  74. *
  75. */
  76. def get_portfolio_info(portfolio_ids) {
  77. s_entity_ids = ids_to_string(portfolio_ids);
  78. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND cpm.id IN (" + s_entity_ids + ")");
  79. s_query = "SELECT cpm.id AS portfolio_id, cpm.userid, cpm.customer_id, cpm.inception_date, 1 AS ini_value,
  80. cpm.portfolio_source, cpm.portfolio_type, 102 AS strategy, sub_type AS substrategy, u.org_id
  81. FROM pfdb.`pf_customer_portfolio_map` cpm
  82. INNER JOIN pfdb.cm_user u ON cpm.userid = u.userid
  83. WHERE cpm.isvalid = 1
  84. AND u.isvalid = 1" +
  85. s_entity_sql + "
  86. ORDER BY cpm.id"
  87. conn = connect_mysql()
  88. t = odbc::query(conn, s_query)
  89. conn.close()
  90. return t
  91. }
  92. /*
  93. * 取私有基金有效信息
  94. *
  95. * Example: get_cus_fund_info(['CF0000005V','CF000000CE']);
  96. * get_cus_fund_info(NULL);
  97. *
  98. */
  99. def get_cus_fund_info(fund_ids) {
  100. s_entity_ids = ids_to_string(fund_ids);
  101. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND fi.fund_id IN (" + s_entity_ids + ")");
  102. s_query = "SELECT fi.fund_id, fi.userid, fi.inception_date, IFNULL(fi.primary_benchmark_id, 'IN00000008') AS benchmark_id,
  103. IFNULL(initial_unit_value, 1) AS ini_value, raise_type, strategy, substrategy
  104. FROM pfdb.pf_cus_fund_information fi
  105. INNER JOIN pfdb.cm_user u ON fi.userid = u.userid
  106. WHERE fi.isvalid = 1
  107. AND u.isvalid = 1" +
  108. s_entity_sql + "
  109. ORDER BY fi.fund_id"
  110. conn = connect_mysql()
  111. t = odbc::query(conn, s_query)
  112. conn.close()
  113. return t
  114. }
  115. /*
  116. * 取因子有效信息
  117. *
  118. * Example: get_factor_info(['FA00000VNB','FA00000VMJ']);
  119. * get_factor_info(NULL);
  120. *
  121. */
  122. def get_factor_info(factor_ids) {
  123. s_entity_ids = ids_to_string(factor_ids);
  124. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND fi.factor_id IN (" + s_entity_ids + ")");
  125. s_query = "SELECT fi.factor_id, fi.factor_type, fi.inception_date, NULL AS benchmark_id, IFNULL(initial_value, 1) AS ini_value
  126. FROM pfdb.cm_factor_information fi
  127. WHERE fi.isvalid = 1 " +
  128. s_entity_sql + "
  129. ORDER BY fi.factor_id"
  130. conn = connect_mysql()
  131. t = odbc::query(conn, s_query)
  132. conn.close()
  133. return t
  134. }
  135. /*
  136. * 取基金经理有效信息
  137. *
  138. * NOTE: Will return multiple records per company!
  139. *
  140. * Example: get_personnel_info(['PL000000AN', 'PL000001GH']);
  141. */
  142. def get_personnel_info(personnel_ids) {
  143. s_entity_ids = ids_to_string(personnel_ids);
  144. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND pi.personnel_id IN (" + s_entity_ids + ")");
  145. s_query = "SELECT pi.personnel_id AS manager_id, fi.raise_type, fs.strategy,
  146. MIN(map.management_start_date) AS inception_date,
  147. CASE fs.strategy WHEN 1 THEN 'IN00000008'
  148. WHEN 2 THEN 'IN00000008'
  149. WHEN 3 THEN 'IN0000008S'
  150. WHEN 4 THEN 'IN00000008'
  151. WHEN 5 THEN 'IN00000008'
  152. WHEN 6 THEN 'IN00000077'
  153. WHEN 7 THEN 'FA00000VNB'
  154. WHEN 8 THEN 'FA00000VNB'
  155. WHEN 101 THEN 'IN00000008'
  156. WHEN 102 THEN 'FA00000VNB'
  157. WHEN 103 THEN 'IN00000077'
  158. WHEN 104 THEN 'IN0000007G'
  159. WHEN 105 THEN 'IN0000009M'
  160. ELSE 'IN00000008' END AS benchmark_id,
  161. 1 AS ini_value
  162. FROM mfdb.personnel_information pi
  163. INNER JOIN mfdb.fund_manager_mapping map ON pi.personnel_id = map.fund_manager_id
  164. INNER JOIN mfdb.fund_information fi ON map.fund_id = fi.fund_id
  165. INNER JOIN mfdb.fund_strategy fs ON fi.fund_id = fs.fund_id
  166. WHERE pi.isvalid = 1 " +
  167. s_entity_sql + "
  168. AND map.isvalid = 1
  169. AND fi.isvalid = 1
  170. AND fs.isvalid = 1
  171. AND fs.strategy > 0
  172. GROUP BY pi.personnel_id, fi.raise_type, fs.strategy
  173. ORDER BY pi.personnel_id"
  174. conn = connect_mysql()
  175. t = odbc::query(conn, s_query)
  176. conn.close()
  177. return t
  178. }
  179. /*
  180. * 取基金经理简版信息 (curve_type + 全strategy)
  181. *
  182. * NOTE: 仿照 MySQL 的设定,curve_type: 1-私募, 4-公募, 7-公私募综合; strategy: 0-不分策略
  183. *
  184. * Example: get_personnel_info_for_perf(['PL000000AN', 'PL000001GH']);
  185. */
  186. def get_personnel_info_for_perf(personnel_ids) {
  187. s_entity_ids = ids_to_string(personnel_ids);
  188. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND pi.personnel_id IN (" + s_entity_ids + ")");
  189. s_query = "SELECT * FROM (
  190. SELECT pi.personnel_id AS manager_id,
  191. IF(fi.raise_type = 1, 1, 4) AS curve_type,
  192. 0 AS strategy,
  193. MIN(map.management_start_date) AS inception_date,
  194. 'FA00000VNB' AS benchmark_id,
  195. 1 AS ini_value
  196. FROM mfdb.personnel_information pi
  197. INNER JOIN mfdb.fund_manager_mapping map ON pi.personnel_id = map.fund_manager_id
  198. INNER JOIN mfdb.fund_information fi ON map.fund_id = fi.fund_id
  199. WHERE pi.isvalid = 1 " +
  200. s_entity_sql + "
  201. AND map.isvalid = 1
  202. AND fi.isvalid = 1
  203. GROUP BY pi.personnel_id, fi.raise_type
  204. UNION
  205. SELECT pi.personnel_id AS manager_id,
  206. 7 AS curve_type,
  207. 0 AS strategy,
  208. MIN(map.management_start_date) AS inception_date,
  209. 'FA00000VNB' AS benchmark_id,
  210. 1 AS ini_value
  211. FROM mfdb.personnel_information pi
  212. INNER JOIN mfdb.fund_manager_mapping map ON pi.personnel_id = map.fund_manager_id
  213. INNER JOIN mfdb.fund_information fi ON map.fund_id = fi.fund_id
  214. WHERE pi.isvalid = 1 " +
  215. s_entity_sql + "
  216. AND map.isvalid = 1
  217. AND fi.isvalid = 1
  218. GROUP BY pi.personnel_id) t
  219. ORDER BY manager_id, curve_type, strategy;";
  220. conn = connect_mysql()
  221. t = odbc::query(conn, s_query)
  222. conn.close()
  223. return t
  224. }
  225. /*
  226. * 取基金公司简版信息 (curve_type + 全strategy)
  227. *
  228. * NOTE: 仿照 MySQL 的设定,curve_type: 1-私募, 4-公募, 7-公私募综合; strategy: 0-不分策略
  229. *
  230. * Example: get_company_info_for_perf(['CO0001003W', 'CO00000017']);
  231. */
  232. def get_company_info_for_perf(company_ids) {
  233. s_entity_ids = ids_to_string(company_ids);
  234. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND ci.company_id IN (" + s_entity_ids + ")");
  235. s_query = "SELECT * FROM (
  236. SELECT ci.company_id,
  237. IF(fi.raise_type = 1, 1, 4) AS curve_type,
  238. 0 AS strategy,
  239. MIN(IFNULL(fi.inception_date, ci.establish_date)) AS inception_date,
  240. 'FA00000VNB' AS benchmark_id,
  241. 1 AS ini_value
  242. FROM mfdb.company_information ci
  243. INNER JOIN mfdb.fund_information fi ON ci.company_id = fi.advisor_id
  244. WHERE ci.isvalid = 1 " +
  245. s_entity_sql + "
  246. AND fi.isvalid = 1
  247. GROUP BY ci.company_id, fi.raise_type
  248. UNION
  249. SELECT ci.company_id,
  250. 7 AS curve_type,
  251. 0 AS strategy,
  252. MIN(IFNULL(fi.inception_date, ci.establish_date)) AS inception_date,
  253. 'FA00000VNB' AS benchmark_id,
  254. 1 AS ini_value
  255. FROM mfdb.company_information ci
  256. INNER JOIN mfdb.fund_information fi ON ci.company_id = fi.advisor_id
  257. WHERE ci.isvalid = 1 " +
  258. s_entity_sql + "
  259. AND fi.isvalid = 1
  260. GROUP BY ci.company_id) t
  261. ORDER BY company_id, curve_type, strategy;";
  262. conn = connect_mysql()
  263. t = odbc::query(conn, s_query)
  264. conn.close()
  265. return t
  266. }
  267. /*
  268. * 取基金公司有效信息
  269. *
  270. * NOTE: Will return multiple records per company!
  271. *
  272. * Example: get_company_info(['CO0001003W', 'CO00000017']);
  273. *
  274. */
  275. def get_company_info(company_ids) {
  276. s_entity_ids = ids_to_string(company_ids);
  277. s_entity_sql = iif(s_entity_ids == NULL || s_entity_ids == '', '', " AND ci.company_id IN (" + s_entity_ids + ")");
  278. s_query = "SELECT ci.company_id, fi.raise_type,
  279. fs.strategy,
  280. MIN(IFNULL(fi.inception_date, ci.establish_date)) AS inception_date,
  281. CASE fs.strategy WHEN 1 THEN 'IN00000008'
  282. WHEN 2 THEN 'IN00000008'
  283. WHEN 3 THEN 'IN0000008S'
  284. WHEN 4 THEN 'IN00000008'
  285. WHEN 5 THEN 'IN00000008'
  286. WHEN 6 THEN 'IN00000077'
  287. WHEN 7 THEN 'FA00000VNB'
  288. WHEN 8 THEN 'FA00000VNB'
  289. WHEN 101 THEN 'IN00000008'
  290. WHEN 102 THEN 'FA00000VNB'
  291. WHEN 103 THEN 'IN00000077'
  292. WHEN 104 THEN 'IN0000007G'
  293. WHEN 105 THEN 'IN0000009M'
  294. ELSE 'IN00000008' END AS benchmark_id,
  295. 1 AS ini_value
  296. FROM mfdb.company_information ci
  297. INNER JOIN mfdb.fund_information fi ON ci.company_id = fi.advisor_id
  298. INNER JOIN mfdb.fund_strategy fs ON fi.fund_id = fs.fund_id
  299. WHERE ci.isvalid = 1 " +
  300. s_entity_sql + "
  301. AND fi.isvalid = 1
  302. AND fs.isvalid = 1
  303. AND fs.strategy > 0
  304. GROUP BY ci.company_id, fi.raise_type, fs.strategy
  305. ORDER BY ci.company_id"
  306. conn = connect_mysql()
  307. t = odbc::query(conn, s_query)
  308. conn.close()
  309. return t
  310. }
  311. /*
  312. * 取基金组合基础有效信息
  313. *
  314. * Example: get_entity_info('HF', ['HF000004KN','HF000103EU','HF00018WXG']);
  315. * get_entity_info('PF', '166002,166114');
  316. * get_entity_info('MI', NULL);
  317. */
  318. def get_entity_info(entity_type, entity_ids) {
  319. t = null;
  320. s_entity_ids = ids_to_string(entity_ids);
  321. if(entity_type == 'MF' || entity_type == 'HF') {
  322. t = get_fund_info(s_entity_ids);
  323. t.rename!('fund_id', 'entity_id');
  324. } else if(entity_type == 'PF') {
  325. t = get_portfolio_info(s_entity_ids);
  326. t.rename!('portfolio_id', 'entity_id');
  327. } else if(entity_type IN ['MI', 'FI']) {
  328. t = get_index_info(s_entity_ids);
  329. t.rename!('index_id', 'entity_id');
  330. } else if(entity_type == 'CF') {
  331. t = get_cus_fund_info(s_entity_ids);
  332. t.rename!('fund_id', 'entity_id');
  333. } else if(entity_type == 'FA') {
  334. t = get_factor_info(s_entity_ids);
  335. t.rename!('factor_id', 'entity_id');
  336. } else if(entity_type == 'PL') {
  337. t = get_personnel_info_for_perf(s_entity_ids);
  338. t.rename!('manager_id', 'entity_id');
  339. } else if(entity_type == 'CO') {
  340. t = get_company_info_for_perf(s_entity_ids);
  341. t.rename!('company_id', 'entity_id');
  342. }
  343. return t;
  344. }
  345. /*
  346. * 取某时间段的基金主基准
  347. * NOTE: 目前数据库里只存最新的基准,以后很可能会支持时间序列
  348. *
  349. * Example: get_fund_primary_benchmark("'MF00003PW2', 'MF00003PW1', 'MF00003PXO'", '1990-01', '2024-06');
  350. */
  351. def get_fund_primary_benchmark(fund_ids, month_start, month_end) {
  352. s_query = "SELECT fund_id, primary_benchmark_id AS benchmark_id, inception_date
  353. FROM mfdb.fund_information
  354. WHERE fund_id IN (" + fund_ids + ")
  355. AND isvalid = 1;";
  356. conn = connect_mysql();
  357. t = odbc::query(conn, s_query);
  358. conn.close();
  359. t.addColumn('end_date', MONTH);
  360. m_start = temporalParse(month_start, 'yyyy-MM');
  361. m_end = temporalParse(month_end, 'yyyy-MM');
  362. tb_end_date = table(m_start..m_end AS end_date);
  363. return (SELECT t.fund_id, d.end_date, t.benchmark_id FROM t JOIN tb_end_date d WHERE d.end_date >= t.inception_date.month());
  364. }
  365. /*
  366. * 取某时间段的组合主基准
  367. * NOTE: 目前所有Java指标计算组合默认主基准是FA00000VNB,以后很可能会改
  368. *
  369. * Example: get_portfolio_primary_benchmark("166002,166114", '1990-01', '2024-08');
  370. */
  371. def get_portfolio_primary_benchmark(portfolio_ids, month_start, month_end) {
  372. s_query = "SELECT id AS portfolio_id, 'FA00000VNB' AS benchmark_id, inception_date
  373. FROM pfdb.pf_customer_portfolio_map
  374. WHERE id IN (" + portfolio_ids + ")
  375. AND isvalid = 1;";
  376. conn = connect_mysql();
  377. t = odbc::query(conn, s_query);
  378. conn.close();
  379. t.addColumn('end_date', MONTH);
  380. m_start = temporalParse(month_start, 'yyyy-MM');
  381. m_end = temporalParse(month_end, 'yyyy-MM');
  382. tb_end_date = table(m_start..m_end AS end_date);
  383. return (SELECT t.portfolio_id, d.end_date, t.benchmark_id FROM t JOIN tb_end_date d WHERE d.end_date >= t.inception_date.month());
  384. }
  385. /*
  386. * 取某时间段的基金组合主基准
  387. *
  388. * NOTE: 指数和因子的”主基准”设置为沪深300
  389. *
  390. * Example: get_entity_primary_benchmark('MF', "'MF00003PW2', 'MF00003PW1', 'MF00003PXO'", '1990-01', '2024-06');
  391. * get_entity_primary_benchmark('PF', [166002,166114], '1990-01', '2024-08');
  392. * get_entity_primary_benchmark('MI', ['IN00000008', 'IN0000000M'], '2024-07', '2024-08');
  393. * get_entity_primary_benchmark('FA', ['FA00000VNB', 'FA00000VMJ'], '2024-01', '2024-08');
  394. */
  395. def get_entity_primary_benchmark(entity_type, entity_ids, month_start, month_end) {
  396. t = table(100:0,
  397. ['entity_id', 'end_date', 'benchmark_id'],
  398. [iif(entity_type == 'PF', INT, SYMBOL), MONTH, SYMBOL]);
  399. s_entity_ids = ids_to_string(entity_ids);
  400. if(s_entity_ids == null || s_entity_ids == '') return null;
  401. if(entity_type == 'MF' || entity_type == 'HF') {
  402. t = get_fund_primary_benchmark(s_entity_ids, month_start, month_end);
  403. t.rename!('fund_id', 'entity_id');
  404. } else if(entity_type == 'PF') {
  405. t = get_portfolio_primary_benchmark(s_entity_ids, month_start, month_end);
  406. t.rename!('portfolio_id', 'entity_id');
  407. } else if(entity_type IN ['MI', 'FI', 'FA', 'CI', 'EQ']) {
  408. t = SELECT entity_id, end_date, NULL AS benchmark_id
  409. FROM cj(get_entity_info(entity_type, s_entity_ids), table(temporalParse(month_start, 'yyyy-MM')..temporalParse(month_end, 'yyyy-MM') AS end_date))
  410. WHERE end_date >= iif(inception_date.isNull(), 1990.01M, inception_date.month())
  411. }
  412. return t;
  413. }
  414. /*
  415. * 取某时间段的基金组合BFI基准
  416. *
  417. *
  418. * Example: get_entity_bfi_factors('MF', "'MF00003PW2', 'MF00003PW1', 'MF00003PXO'", 1990.01M, 2024.06M);
  419. * get_entity_bfi_factors('PF', [166002,166114], 1990.01M, 2029.12M, 2024.10.01);
  420. */
  421. def get_entity_bfi_factors(entity_type, entity_ids, month_start, month_end, updatetime=1990.01.01) {
  422. tmp = get_bfi_by_category_group_table_description(entity_type);
  423. s_entity_ids = ids_to_string(entity_ids);
  424. sql_entity_id = '';
  425. if(s_entity_ids != NULL) {
  426. sql_entity_id = " AND " + tmp.sec_id_col[0] + " IN (" + s_entity_ids + ")";
  427. }
  428. s_query = "SELECT " + tmp.sec_id_col[0] + " AS entity_id, end_date, factor_id
  429. FROM " + tmp.table_name[0] + "
  430. WHERE isvalid = 1 " +
  431. sql_entity_id + "
  432. AND end_date >= '" + month_start.temporalFormat('yyyy-MM') + "'
  433. AND end_date <= '" + month_end.temporalFormat('yyyy-MM') + "'
  434. AND updatetime >= '" + updatetime$STRING + "'
  435. ORDER BY " + tmp.sec_id_col[0] + ", end_date, factor_id";
  436. conn = connect_mysql();
  437. t = odbc::query(conn, s_query);
  438. conn.close();
  439. return t;
  440. }
  441. /*
  442. * 取某时间段的基金经理 BFI基准
  443. *
  444. *
  445. * Example: get_mc_bfi_factors('PL', ['PL000000NS', 'PL00000ICF'], 1990.01M, 2024.06M);
  446. *
  447. */
  448. def get_mc_bfi_factors(entity_type, entity_ids, month_start, month_end, updatetime=1990.01.01) {
  449. tmp = get_bfi_by_category_group_table_description(entity_type);
  450. s_entity_ids = ids_to_string(entity_ids);
  451. sql_entity_id = '';
  452. if(s_entity_ids != NULL) {
  453. sql_entity_id = " AND " + tmp.sec_id_col[0] + " IN (" + s_entity_ids + ")";
  454. }
  455. s_query = "SELECT " + tmp.sec_id_col[0] + " AS entity_id, curve_type, strategy, end_date, factor_id
  456. FROM " + tmp.table_name[0] + "
  457. WHERE isvalid = 1 " +
  458. sql_entity_id + "
  459. AND end_date >= '" + month_start.temporalFormat('yyyy-MM') + "'
  460. AND end_date <= '" + month_end.temporalFormat('yyyy-MM') + "'
  461. AND updatetime >= '" + updatetime$STRING + "'
  462. ORDER BY " + tmp.sec_id_col[0] + ", end_date, factor_id";
  463. conn = connect_mysql();
  464. t = odbc::query(conn, s_query);
  465. conn.close();
  466. return t;
  467. }
  468. /*
  469. * 取基金-经理关系表
  470. *
  471. * Example:get_fund_manager_mapping(['MF00003PW1', 'MF00003PW2']);
  472. */
  473. def get_fund_manager_mapping(fund_ids) {
  474. t = null;
  475. s_entity_ids = ids_to_string(fund_ids);
  476. s_query = "SELECT fund_id, fund_manager_id, management_start_date, management_end_date
  477. FROM mfdb.fund_manager_mapping
  478. WHERE fund_id IN (" + s_entity_ids + ")
  479. AND isvalid = 1
  480. ORDER BY fund_id, management_start_date, management_end_date;";
  481. conn = connect_mysql();
  482. t = odbc::query(conn, s_query);
  483. conn.close();
  484. return t;
  485. }