dataset.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  1. <?php
  2. class dataset
  3. {
  4. /**
  5. * Database connection.
  6. *
  7. * @var object
  8. * @access public
  9. */
  10. public $dao;
  11. /**
  12. * Config.
  13. *
  14. * @var object
  15. * @access public
  16. */
  17. public $config;
  18. /**
  19. * User vision.
  20. *
  21. * @var string
  22. * @access public
  23. */
  24. public $vision;
  25. /**
  26. * __construct.
  27. *
  28. * @param DAO $dao
  29. * @access public
  30. * @return void
  31. */
  32. public function __construct($dao, $config, $vision = 'rnd')
  33. {
  34. $this->dao = $dao;
  35. $this->config = $config;
  36. $this->vision = $vision;
  37. }
  38. /**
  39. * append where condition of vision.
  40. *
  41. * @param PDOStatement $query
  42. * @param string $table
  43. * @access public
  44. * @return PDOStatement
  45. */
  46. public function defaultWhere($query, $table)
  47. {
  48. $visions = explode(',', $this->vision);
  49. $wheres = array();
  50. foreach($visions as $vision) $wheres[] = "{$table}.vision LIKE '%{$vision}%'";
  51. $where = implode(' OR ', $wheres);
  52. return $query->andWhere($where, true)
  53. ->orWhere("{$table}.vision IS NULL")->markRight(1);
  54. }
  55. /**
  56. * 获取所有的项目集。
  57. * Get all program list.
  58. *
  59. * @param string $fieldList
  60. * @access public
  61. * @return PDOStatement
  62. */
  63. public function getPrograms($fieldList)
  64. {
  65. $stmt = $this->dao->select($fieldList)
  66. ->from(TABLE_PROJECT)->alias('t1')
  67. ->where('type')->eq('program')
  68. ->andWhere('deleted')->eq('0');
  69. return $this->defaultWhere($stmt, 't1');
  70. }
  71. /**
  72. * 获取所有的顶级项目集。
  73. * Get top program list.
  74. *
  75. * @param string $fieldList
  76. * @access public
  77. * @return PDOStatement
  78. */
  79. public function getTopPrograms($fieldList)
  80. {
  81. $stmt = $this->dao->select($fieldList)
  82. ->from(TABLE_PROJECT)->alias('t1')
  83. ->where('type')->eq('program')
  84. ->andWhere('grade')->eq('1')
  85. ->andWhere('deleted')->eq('0');
  86. return $this->defaultWhere($stmt, 't1');
  87. }
  88. /**
  89. * Get all projects.
  90. * 获取所有项目。
  91. *
  92. * @param string $fieldList
  93. * @access public
  94. * @return PDOStatement
  95. */
  96. public function getAllProjects($fieldList)
  97. {
  98. $stmt = $this->dao->select($fieldList)->from(TABLE_PROJECT)->alias('t1')
  99. ->where('deleted')->eq(0)
  100. ->andWhere('type')->eq('project');
  101. return $this->defaultWhere($stmt, 't1');
  102. }
  103. /**
  104. * 获取执行数据。
  105. * Get executions.
  106. *
  107. * @param string $fieldList
  108. * @access public
  109. * @return PDOStatement
  110. */
  111. public function getExecutions($fieldList)
  112. {
  113. $stmt = $this->dao->select($fieldList)->from(TABLE_PROJECT)->alias('t1')
  114. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
  115. ->where('t1.deleted')->eq(0)
  116. ->andWhere('t2.deleted')->eq(0)
  117. ->andWhere('t1.type')->in('sprint,stage,kanban')
  118. ->andWhere('t1.multiple')->eq('1')
  119. ->andWhere('t2.type')->eq('project');
  120. return $this->defaultWhere($stmt, 't1');
  121. }
  122. /**
  123. * 获取发布数据。
  124. * Get release list.
  125. *
  126. * @param string $fieldList
  127. * @access public
  128. * @return PDOStatement
  129. */
  130. public function getReleases($fieldList)
  131. {
  132. $dbType = $this->config->metricDB->type;
  133. $stmt = $this->dao->select($fieldList)
  134. ->from(TABLE_RELEASE)->alias('t1')
  135. ->beginIF($dbType == 'mysql' || $dbType == 'duckdb')->leftJoin(TABLE_PROJECT)->alias('t2')->on("CONCAT(',', t2.id, ',') LIKE CONCAT('%,', t1.project, ',%')")->fi()
  136. ->beginIF($dbType == 'sqlite')->leftJoin(TABLE_PROJECT)->alias('t2')->on("(',' || t2.id || ',') LIKE ('%' || t1.project || '%')")->fi()
  137. ->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t1.product=t3.id')
  138. ->where('t1.deleted')->eq(0)
  139. ->andWhere('t3.deleted')->eq(0);
  140. return $this->defaultWhere($stmt, 't2');
  141. }
  142. /**
  143. * 按产品获取发布数据。
  144. * Get release list according to product.
  145. *
  146. * @param string $fieldList
  147. * @access public
  148. * @return PDOStatement
  149. */
  150. public function getProductReleases($fieldList)
  151. {
  152. $stmt = $this->dao->select($fieldList)
  153. ->from(TABLE_RELEASE)->alias('t1')
  154. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  155. ->where('t1.deleted')->eq(0)
  156. ->andWhere('t2.deleted')->eq(0)
  157. ->andWhere('t2.shadow')->eq(0);
  158. return $this->defaultWhere($stmt, 't2');
  159. }
  160. /**
  161. * 获取所有发布数据。
  162. * Get all release data.
  163. *
  164. * @param string $fieldList
  165. * @access public
  166. * @return PDOStatement
  167. */
  168. public function getAllReleases($fieldList)
  169. {
  170. return $this->dao->select($fieldList)->from(TABLE_RELEASE)->alias('t1')->where('deleted')->eq(0);
  171. }
  172. /**
  173. * 获取产品计划数据。
  174. * Get plan list, without shadow product's data.
  175. *
  176. * @param string $fieldList
  177. * @access public
  178. * @return PDOStatement
  179. */
  180. public function getPlans($fieldList)
  181. {
  182. $stmt = $this->dao->select($fieldList)
  183. ->from(TABLE_PRODUCTPLAN)->alias('t1')
  184. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  185. ->where('t1.deleted')->eq(0)
  186. ->andWhere('t2.deleted')->eq(0)
  187. ->andWhere('t2.shadow')->eq(0);
  188. return $this->defaultWhere($stmt, 't2');
  189. }
  190. /**
  191. * 获取产品计划数据,包括项目型项目的计划。
  192. * Get plan list include shadow product data.
  193. *
  194. * @param string $fieldList
  195. * @access public
  196. * @return PDOStatement
  197. */
  198. public function getAllPlans($fieldList)
  199. {
  200. $stmt = $this->dao->select($fieldList)
  201. ->from(TABLE_PRODUCTPLAN)->alias('t1')
  202. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  203. ->where('t1.deleted')->eq(0)
  204. ->andWhere('t2.deleted')->eq(0);
  205. return $this->defaultWhere($stmt, 't2');
  206. }
  207. /**
  208. * 获取bug数据。
  209. * Get product bug list.
  210. *
  211. * @param string $fieldList
  212. * @access public
  213. * @return PDOStatement
  214. */
  215. public function getBugs($fieldList)
  216. {
  217. $longlife = $this->dao->select('value')
  218. ->from(TABLE_CONFIG)
  219. ->where('module')->eq('bug')
  220. ->andWhere('key')->eq('longlife')
  221. ->fetch('value');
  222. if(!$longlife) $longlife = 7;
  223. $stmt = $this->dao->select("$fieldList, $longlife as longlife")
  224. ->from(TABLE_BUG)->alias('t1')
  225. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  226. ->where('t1.deleted')->eq(0)
  227. ->andWhere('t2.deleted')->eq(0)
  228. ->andWhere('t2.shadow')->eq(0);
  229. return $this->defaultWhere($stmt, 't2');
  230. }
  231. /**
  232. * 获取执行bug数据。
  233. * Get execution product bug list.
  234. *
  235. * @param string $fieldList
  236. * @access public
  237. * @return PDOStatement
  238. */
  239. public function getExecutionBugs($fieldList)
  240. {
  241. $stmt = $this->dao->select($fieldList)
  242. ->from(TABLE_BUG)->alias('t1')
  243. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  244. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t1.execution=t3.id')
  245. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t1.project=t4.id')
  246. ->where('t1.deleted')->eq(0)
  247. ->andWhere('t2.shadow')->eq(0)
  248. ->andWhere('t3.deleted')->eq(0)
  249. ->andWhere('t3.type')->in('sprint,stage,kanban')
  250. ->andWhere('t4.deleted')->eq(0);
  251. return $this->defaultWhere($stmt, 't2');
  252. }
  253. /**
  254. * 获取所有bug数据。
  255. * Get all bug list.
  256. *
  257. * @param string $fieldList
  258. * @access public
  259. * @return PDOStatement
  260. */
  261. public function getAllBugs($fieldList)
  262. {
  263. $stmt = $this->dao->select($fieldList)
  264. ->from(TABLE_BUG)->alias('t1')
  265. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  266. ->where('t1.deleted')->eq(0)
  267. ->andWhere('t2.deleted')->eq(0);
  268. return $this->defaultWhere($stmt, 't2');
  269. }
  270. /**
  271. * 获取项目bug数据。
  272. * Get project bug list.
  273. *
  274. * @param string $fieldList
  275. * @access public
  276. * @return PDOStatement
  277. */
  278. public function getProjectBugs($fieldList)
  279. {
  280. $stmt = $this->dao->select($fieldList)->from(TABLE_BUG)->alias('t1')
  281. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  282. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t1.project=t3.id')
  283. ->where('t1.deleted')->eq(0)
  284. ->andWhere('t2.deleted')->eq(0)
  285. ->andWhere('t3.deleted')->eq(0);
  286. return $this->defaultWhere($stmt, 't3');
  287. }
  288. /**
  289. * 获取反馈数据。
  290. * Get feedback list.
  291. *
  292. * @param string $fieldList
  293. * @access public
  294. * @return PDOStatement
  295. */
  296. public function getFeedbacks($fieldList)
  297. {
  298. $stmt = $this->dao->select($fieldList)->from(TABLE_FEEDBACK)->alias('t1')
  299. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  300. ->where('t1.deleted')->eq(0)
  301. ->andWhere('t2.deleted')->eq(0)
  302. ->andWhere('t2.shadow')->eq(0);
  303. return $this->defaultWhere($stmt, 't2');
  304. }
  305. /**
  306. * 获取所有反馈数据。
  307. * Get all feedback list.
  308. *
  309. * @param string $fieldList
  310. * @access public
  311. * @return PDOStatement
  312. */
  313. public function getAllFeedbacks($fieldList)
  314. {
  315. $stmt = $this->dao->select($fieldList)->from(TABLE_FEEDBACK)->alias('t1')
  316. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  317. ->where('t1.deleted')->eq(0)
  318. ->andWhere('t2.deleted')->eq(0);
  319. return $this->defaultWhere($stmt, 't2');
  320. }
  321. /**
  322. * 获取需求数据。
  323. * Get story list.
  324. *
  325. * @param string $fieldList
  326. * @access public
  327. * @return PDOStatement
  328. */
  329. public function getStories($fieldList)
  330. {
  331. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  332. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  333. ->where('t1.deleted')->eq(0)
  334. ->andWhere('t2.deleted')->eq(0)
  335. ->andWhere('t2.shadow')->eq(0);
  336. return $this->defaultWhere($stmt, 't1');
  337. }
  338. /**
  339. * 获取所有需求数据,不区分类型。
  340. * Get all story list.
  341. *
  342. * @param string $fieldList
  343. * @access public
  344. * @return PDOStatement
  345. */
  346. public function getAllStories($fieldList)
  347. {
  348. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  349. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  350. ->where('t1.deleted')->eq(0)
  351. ->andWhere('t2.deleted')->eq(0);
  352. return $this->defaultWhere($stmt, 't1');
  353. }
  354. /**
  355. * 获取执行的研发需求数据。
  356. * Get story list, with execution and type is story.
  357. *
  358. * @param string $fieldList
  359. * @access public
  360. * @return PDOStatement
  361. */
  362. public function getDevStoriesWithExecution($fieldList)
  363. {
  364. $stmt = $this->dao->select($fieldList)
  365. ->from(TABLE_STORY)->alias('t1')
  366. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  367. ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t1.id=t3.story')
  368. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t3.project=t4.id')
  369. ->leftJoin(TABLE_PROJECT)->alias('t5')->on('t4.project=t5.id')
  370. ->where('t1.deleted')->eq(0)
  371. ->andWhere('t2.deleted')->eq(0)
  372. ->andWhere('t1.type')->eq('story')
  373. ->andWhere('t4.deleted')->eq(0)
  374. ->andWhere('t4.type')->in('sprint,stage,kanban')
  375. ->andWhere('t5.deleted')->eq(0);
  376. return $this->defaultWhere($stmt, 't1');
  377. }
  378. /**
  379. * 获取执行的研发需求数据,以执行为主表。
  380. * Get execution story list, story type is story.
  381. *
  382. * @param string $fieldList
  383. * @access public
  384. * @return PDOStatement
  385. */
  386. public function getExecutionDevStories($fieldList)
  387. {
  388. $stmt = $this->dao->select($fieldList)
  389. ->from(TABLE_PROJECT)->alias('t1')
  390. ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t1.id=t3.project')
  391. ->leftJoin(TABLE_STORY)->alias('t4')->on('t3.story=t4.id')
  392. ->leftJoin(TABLE_PROJECT)->alias('t5')->on('t1.project=t5.id')
  393. ->leftJoin(TABLE_ACTION)->alias('t6')->on('t3.story=t6.objectID')
  394. ->where('t1.type')->in('sprint,stage,kanban')
  395. ->andWhere('t6.objectType')->eq('story')
  396. ->andWhere('t1.deleted')->eq(0)
  397. ->andWhere('t4.type')->eq('story')
  398. ->andWhere('t4.deleted')->eq(0)
  399. ->andWhere('t5.deleted')->eq(0);
  400. return $this->defaultWhere($stmt, 't1');
  401. }
  402. /**
  403. * 获取执行的所有需求数据。
  404. * Get story list, with execution story.
  405. *
  406. * @param string $fieldList
  407. * @access public
  408. * @return PDOStatement
  409. */
  410. public function getAllStoriesWithExecution($fieldList)
  411. {
  412. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  413. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  414. ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t1.id=t3.story')
  415. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t3.project=t4.id')
  416. ->leftJoin(TABLE_PROJECT)->alias('t5')->on('t4.project=t5.id')
  417. ->where('t1.deleted')->eq(0)
  418. ->andWhere('t2.deleted')->eq(0)
  419. ->andWhere('t4.deleted')->eq(0) // 已删除的执行
  420. ->andWhere('t4.type')->in('sprint,stage,kanban')
  421. ->andWhere('t5.deleted')->eq(0); // 已删除的项目
  422. return $this->defaultWhere($stmt, 't1');
  423. }
  424. /**
  425. * 获取项目的研发需求数据。
  426. * Get story list, with project and type is story.
  427. *
  428. * @param string $fieldList
  429. * @access public
  430. * @return PDOStatement
  431. */
  432. public function getDevStoriesWithProject($fieldList)
  433. {
  434. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  435. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  436. ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t1.id=t3.story')
  437. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t3.project=t4.id')
  438. ->where('t1.deleted')->eq('0')
  439. ->andWhere('t2.deleted')->eq('0')
  440. ->andWhere('t1.type')->eq('story')
  441. ->andWhere('t4.deleted')->eq('0')
  442. ->andWhere('t1.isParent')->eq('0')
  443. ->andWhere('t4.type')->eq('project');
  444. return $this->defaultWhere($stmt, 't1');
  445. }
  446. /**
  447. * 获取项目的业务需求数据。
  448. * Get epic list with project.
  449. *
  450. * @param string $fieldList
  451. * @access public
  452. * @return PDOStatement
  453. */
  454. public function getEpicWithProject($fieldList)
  455. {
  456. $stmt = $this->dao->select($fieldList)
  457. ->from(TABLE_STORY)->alias('t1')
  458. ->leftJoin(TABLE_PROJECTSTORY)->alias('t2')->on('t1.id=t2.story')
  459. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project=t3.id')
  460. ->where('t1.deleted')->eq(0)
  461. ->andWhere('t3.deleted')->eq(0)
  462. ->andWhere('t1.type')->eq('epic')
  463. ->andWhere('t3.type')->eq('project');
  464. return $this->defaultWhere($stmt, 't1');
  465. }
  466. /**
  467. * 获取项目的所有需求数据。
  468. * Get story list, with project story.
  469. *
  470. * @param string $fieldList
  471. * @access public
  472. * @return PDOStatement
  473. */
  474. public function getAllStoriesWithProject($fieldList)
  475. {
  476. $stmt = $this->dao->select($fieldList)
  477. ->from(TABLE_STORY)->alias('t1')
  478. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  479. ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t1.id=t3.story')
  480. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t3.project=t4.id')
  481. ->where('t1.deleted')->eq(0)
  482. ->andWhere('t2.deleted')->eq(0)
  483. ->andWhere('t4.deleted')->eq(0)
  484. ->andWhere('t4.type')->eq('project');
  485. return $this->defaultWhere($stmt, 't1');
  486. }
  487. /**
  488. * 获取研发需求数据,过滤影子产品。
  489. * Get story list, filter shadow product.
  490. *
  491. * @param string $fieldList
  492. * @access public
  493. * @return PDOStatement
  494. */
  495. public function getDevStories($fieldList)
  496. {
  497. if(strpos($fieldList, '`t3`.') === false)
  498. {
  499. $stmt = $this->dao->select($fieldList)
  500. ->from(TABLE_STORY)->alias('t1')
  501. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  502. ->where('t1.deleted')->eq('0')
  503. ->andWhere('t2.deleted')->eq('0')
  504. ->andWhere('t1.type')->eq('story')
  505. ->andWhere('t1.isParent')->eq('0')
  506. ->andWhere('t2.shadow')->eq('0');
  507. return $this->defaultWhere($stmt, 't1');
  508. }
  509. $dbType = $this->config->metricDB->type;
  510. if($dbType == 'duckdb')
  511. {
  512. $table = "(SELECT `story`, COUNT(`id`) AS `case_count` FROM " . TABLE_CASE . " GROUP BY `story`)";
  513. }
  514. else
  515. {
  516. $table = 'tmp_case_getDevStories';
  517. $this->dao->exec("DROP TABLE IF EXISTS `{$table}`");
  518. $this->dao->exec("CREATE TABLE `{$table}` AS SELECT `story`, COUNT(`id`) AS `case_count` FROM " . TABLE_CASE . 'GROUP BY `story`');
  519. $this->dao->exec("CREATE INDEX `story` ON `{$table}` (`story`)");
  520. }
  521. $stmt = $this->dao->select($fieldList)
  522. ->from(TABLE_STORY)->alias('t1')
  523. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  524. ->leftJoin("`{$table}`")->alias('t3')->on('t1.id=t3.story')
  525. ->where('t1.deleted')->eq('0')
  526. ->andWhere('t2.deleted')->eq('0')
  527. ->andWhere('t1.type')->eq('story')
  528. ->andWhere('t1.isParent')->eq('0')
  529. ->andWhere('t2.shadow')->eq('0');
  530. return $this->defaultWhere($stmt, 't1');
  531. }
  532. /**
  533. * 获取所有研发需求数据,不过滤影子产品。
  534. * Get all story list, don't filter shadow product.
  535. *
  536. * @param string $fieldList
  537. * @access public
  538. * @return PDOStatement
  539. */
  540. public function getAllDevStories($fieldList)
  541. {
  542. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  543. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  544. ->where('t1.deleted')->eq('0')
  545. ->andWhere('t2.deleted')->eq('0')
  546. ->andWhere('t1.type')->eq('story')
  547. ->andWhere('t1.isParent')->eq('0');
  548. return $this->defaultWhere($stmt, 't1');
  549. }
  550. public function getAllDevStoriesWithLinkBug($fieldList)
  551. {
  552. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  553. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  554. ->leftJoin(TABLE_RELATION)->alias('t3')->on("t1.id = t3.AID and t3.AType = 'story' and t3.BType = 'bug'")
  555. ->leftJoin(TABLE_BUG)->alias('t4')->on("t3.BType = 'bug' and t3.BID = t4.id")
  556. ->where('t1.deleted')->eq('0')
  557. ->andWhere('t2.deleted')->eq('0')
  558. ->andWhere('t1.type')->eq('story')
  559. ->andWhere('t1.isParent')->eq('0');
  560. $stmt = $this->defaultWhere($stmt, 't1');
  561. return $stmt->groupBy('t1.id');
  562. }
  563. /**
  564. * 获取所有研发需求数据,包含父需求,不过滤影子产品。
  565. * Get all story list with parent, don't filter shadow product.
  566. *
  567. * @param string $fieldList
  568. * @access public
  569. * @return PDOStatement
  570. */
  571. public function getAllDevStoriesWithParent($fieldList)
  572. {
  573. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  574. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  575. ->where('t1.deleted')->eq('0')
  576. ->andWhere('t2.deleted')->eq('0')
  577. ->andWhere('t1.type')->eq('story');
  578. return $this->defaultWhere($stmt, 't1');
  579. }
  580. /**
  581. * 获取所有业务需求数据,不过滤影子产品。
  582. * Get all epics, don't filter shadow product.
  583. *
  584. * @param string $fieldList
  585. * @access public
  586. * @return PDOStatement
  587. */
  588. public function getAllEpics($fieldList)
  589. {
  590. $stmt = $this->dao->select($fieldList)
  591. ->from(TABLE_STORY)->alias('t1')
  592. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  593. ->where('t1.deleted')->eq(0)
  594. ->andWhere('t2.deleted')->eq(0)
  595. ->andWhere('t1.type')->eq('epic');
  596. return $this->defaultWhere($stmt, 't1');
  597. }
  598. /**
  599. * 获取项目的用户需求数据。
  600. * Get requirement list, with project and type is requirement.
  601. *
  602. * @param string $fieldList
  603. * @access public
  604. * @return PDOStatement
  605. */
  606. public function getRequirementsWithProject($fieldList)
  607. {
  608. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  609. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  610. ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t1.id=t3.story')
  611. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t3.project=t4.id')
  612. ->where('t1.deleted')->eq('0')
  613. ->andWhere('t2.deleted')->eq('0')
  614. ->andWhere('t1.type')->eq('requirement')
  615. ->andWhere('t4.deleted')->eq('0')
  616. ->andWhere('t4.type')->eq('project');
  617. return $this->defaultWhere($stmt, 't1');
  618. }
  619. /**
  620. * 获取所有用户需求数据,不过滤影子产品。
  621. * Get all requirements, don't filter shadow product.
  622. *
  623. * @param string $fieldList
  624. * @access public
  625. * @return PDOStatement
  626. */
  627. public function getAllRequirements($fieldList)
  628. {
  629. $stmt = $this->dao->select($fieldList)
  630. ->from(TABLE_STORY)->alias('t1')
  631. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  632. ->where('t1.deleted')->eq(0)
  633. ->andWhere('t2.deleted')->eq(0)
  634. ->andWhere('t1.type')->eq('requirement');
  635. return $this->defaultWhere($stmt, 't1');
  636. }
  637. /**
  638. * 获取已交付的需求数据。
  639. * Get delivered story list.
  640. *
  641. * @param string $fieldList
  642. * @access public
  643. * @return PDOStatement
  644. */
  645. public function getDeliveredStories($fieldList)
  646. {
  647. $stmt = $this->dao->select($fieldList)->from(TABLE_STORY)->alias('t1')
  648. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  649. ->where('t1.deleted')->eq(0)
  650. ->andWhere('t2.deleted')->eq(0)
  651. ->andWhere('t2.shadow')->eq(0)
  652. ->andWhere('t1.stage', true)->eq('released')
  653. ->orWhere('t1.closedReason')->eq('done')
  654. ->markRight(1);
  655. return $this->defaultWhere($stmt, 't1')->groupBy('t1.product');
  656. }
  657. /**
  658. * 获取用例数据。
  659. * Get case list.
  660. *
  661. * @param string $fieldList
  662. * @access public
  663. * @return PDOStatement
  664. */
  665. public function getCases($fieldList)
  666. {
  667. $stmt = $this->dao->select($fieldList)->from(TABLE_CASE)->alias('t1')
  668. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  669. ->where('t1.deleted')->eq(0)
  670. ->andWhere('t2.deleted')->eq(0)
  671. ->andWhere('t2.shadow')->eq(0);
  672. return $this->defaultWhere($stmt, 't2');
  673. }
  674. /**
  675. * 获取执行下的用例步骤数据。
  676. * Get case steps data with execution.
  677. *
  678. * @param string $fieldList
  679. * @access public
  680. * @return PDOStatement
  681. */
  682. public function getExecutionCasesSteps($fieldList)
  683. {
  684. $stmt = $this->dao->select($fieldList)->from(TABLE_CASESTEP)->alias('t1')
  685. ->leftJoin(TABLE_PROJECTCASE)->alias('t2')->on('t1.case = t2.case')
  686. ->leftJoin(TABLE_CASE)->alias('t3')->on('t2.case = t3.id and t1.version = t3.version')
  687. ->leftJoin(TABLE_PROJECT)->alias('t5')->on('t5.id = t2.project')
  688. ->leftJoin(TABLE_PROJECT)->alias('t6')->on('t6.id = t5.project')
  689. ->where('t3.deleted')->eq('0')
  690. ->andWhere('t5.deleted')->eq('0')
  691. ->andWhere('t6.deleted')->eq('0')
  692. ->andWhere('t5.type')->in('sprint,kanban,stage');
  693. return $this->defaultWhere($stmt, 't5');
  694. }
  695. /**
  696. * 获取执行下的用例数据。
  697. * Get case list under execution.
  698. *
  699. * @param string $fieldList
  700. * @access public
  701. * @return PDOStatement
  702. */
  703. public function getExecutionCases($fieldList)
  704. {
  705. $stmt = $this->dao->select($fieldList)->from(TABLE_PROJECTCASE)->alias('t1')
  706. ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
  707. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t4.id = t1.project')
  708. ->leftJoin(TABLE_PROJECT)->alias('t5')->on('t5.id = t4.project')
  709. ->where('t4.deleted')->eq('0')
  710. ->andWhere('t2.deleted')->eq('0')
  711. ->andWhere('t5.deleted')->eq('0')
  712. ->andWhere('t4.type')->in('sprint,kanban,stage');
  713. return $this->defaultWhere($stmt, 't4');
  714. }
  715. /**
  716. * 获取所有用例数据。
  717. * Get all case list.
  718. *
  719. * @param string $fieldList
  720. * @access public
  721. * @return PDOStatement
  722. */
  723. public function getAllCases($fieldList)
  724. {
  725. $stmt = $this->dao->select($fieldList)->from(TABLE_CASE)->alias('t1')
  726. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  727. ->where('t1.deleted')->eq(0)
  728. ->andWhere('t2.deleted')->eq(0);
  729. return $this->defaultWhere($stmt, 't2');
  730. }
  731. /**
  732. * 获取关联用例的研发需求数据。
  733. * Get story list with case.
  734. *
  735. * @param string $fieldList
  736. * @access public
  737. * @return PDOStatement
  738. */
  739. public function getCasesWithStory($fieldList)
  740. {
  741. $stmt = $this->dao->select($fieldList)
  742. ->from(TABLE_CASE)->alias('t0')
  743. ->leftJoin(TABLE_PROJECTSTORY)->alias('t1')->on('t1.story=t0.story')
  744. ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story=t2.id')
  745. ->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t1.product=t3.id')
  746. ->where('t2.deleted')->eq('0')
  747. ->andWhere('t3.deleted')->eq('0');
  748. return $this->defaultWhere($stmt, 't2');
  749. }
  750. /**
  751. * 获取产品数据。
  752. * Get product list.
  753. *
  754. * @param string $fieldList
  755. * @access public
  756. * @return PDOStatement
  757. */
  758. public function getProducts($fieldList)
  759. {
  760. $stmt = $this->dao->select($fieldList)
  761. ->from(TABLE_PRODUCT)->alias('t1')
  762. ->where('t1.deleted')->eq(0)
  763. ->andWhere('t1.shadow')->eq(0);
  764. return $this->defaultWhere($stmt, 't1');
  765. }
  766. /**
  767. * 获取任务数据,包括团队成员。
  768. * Get all tasks data with team.
  769. *
  770. * @param string $fieldList
  771. * @access public
  772. * @return PDOStatement
  773. */
  774. public function getTasksWithTeam($fieldList)
  775. {
  776. $stmt = $this->dao->select($fieldList)->from(TABLE_TASK)->alias('t1')
  777. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution=t2.id')
  778. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project=t3.id')
  779. ->leftJoin(TABLE_TASKTEAM)->alias('t4')->on("t1.id=t4.task and t1.mode='multi'")
  780. ->where('t2.type')->in('sprint,kanban,stage')
  781. ->andWhere('t1.deleted')->eq('0')
  782. ->andWhere('t2.deleted')->eq('0')
  783. ->andWhere('t3.deleted')->eq('0');
  784. return $this->defaultWhere($stmt, 't1');
  785. }
  786. /**
  787. * 获取任务数据。
  788. * Get all tasks.
  789. *
  790. * @param string $fieldList
  791. * @access public
  792. * @return PDOStatement
  793. */
  794. public function getTasks($fieldList)
  795. {
  796. $stmt = $this->dao->select($fieldList)->from(TABLE_TASK)->alias('t1')
  797. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution=t2.id')
  798. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project=t3.id')
  799. ->where('t2.type')->in('sprint,kanban,stage')
  800. ->andWhere('t1.deleted')->eq('0')
  801. ->andWhere('t2.deleted')->eq('0')
  802. ->andWhere('t3.deleted')->eq('0');
  803. return $this->defaultWhere($stmt, 't1');
  804. }
  805. public function getTasksWithBuildInfo($fieldList)
  806. {
  807. $stmt = $this->dao->select($fieldList)->from(TABLE_TASK)->alias('t1')
  808. ->leftJoin(TABLE_BUG)->alias('t2')->on('t1.fromBug = t2.id')
  809. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t1.execution=t3.id')
  810. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t3.project=t4.id')
  811. ->leftJoin(TABLE_BUILD)->alias('t5')->on('t5.execution=t3.id')
  812. ->where('t3.type')->in('sprint,stage,kanban')
  813. ->andWhere('t1.deleted')->eq('0')
  814. ->andWhere('t3.deleted')->eq('0')
  815. ->andWhere('t4.deleted')->eq('0')
  816. ->andWhere('t1.fromBug')->ne(0)
  817. ->andWhere('t1.isParent')->eq('0');
  818. return $this->defaultWhere($stmt, 't1');
  819. }
  820. /**
  821. * 获取产品线数据。
  822. * Get product lines.
  823. *
  824. * @param string $fieldList
  825. * @access public
  826. * @return PDOStatement
  827. */
  828. public function getLines($fieldList)
  829. {
  830. return $this->dao->select($fieldList)->from(TABLE_MODULE)->alias('t1')
  831. ->where('t1.deleted')->eq(0)
  832. ->andWhere('t1.type')->eq('line');
  833. }
  834. /**
  835. * 获取用户数据。
  836. * Get users.
  837. *
  838. * @param string $fieldList
  839. * @access public
  840. * @return PDOStatement
  841. */
  842. public function getUsers($fieldList)
  843. {
  844. return $this->dao->select($fieldList)->from(TABLE_USER)->alias('t1')
  845. ->where('t1.deleted')->eq('0');
  846. }
  847. /**
  848. * 获取文档数据。
  849. * Get docs.
  850. *
  851. * @param string $fieldList
  852. * @access public
  853. * @return PDOStatement
  854. */
  855. public function getDocs($fieldList)
  856. {
  857. $stmt = $this->dao->select($fieldList)->from(TABLE_DOC)->alias('t1')
  858. ->where('t1.deleted')->eq('0');
  859. return $this->defaultWhere($stmt, 't1');
  860. }
  861. /**
  862. * 获取风险数据。
  863. * Get risks.
  864. *
  865. * @param string $fieldList
  866. * @access public
  867. * @return PDOStatement
  868. */
  869. public function getRisks($fieldList)
  870. {
  871. $stmt = $this->dao->select($fieldList)->from(TABLE_RISK)->alias('t1')
  872. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
  873. ->where('t1.deleted')->eq('0')
  874. ->andWhere('t2.deleted')->eq('0')
  875. ->andWhere('t2.type')->eq('project');
  876. return $this->defaultWhere($stmt, 't2');
  877. }
  878. /**
  879. * 获取评审意见数据。
  880. * Get reviewissues.
  881. *
  882. * @param string $fieldList
  883. * @access public
  884. * @return PDOStatement
  885. */
  886. public function getReviewissues($fieldList)
  887. {
  888. $stmt = $this->dao->select($fieldList)->from(TABLE_REVIEWISSUE)->alias('t1')
  889. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
  890. ->where('t1.deleted')->eq('0')
  891. ->andWhere('t2.deleted')->eq('0')
  892. ->andWhere('t2.type')->eq('project');
  893. return $this->defaultWhere($stmt, 't2');
  894. }
  895. /**
  896. * 获取问题数据。
  897. * Get issues.
  898. *
  899. * @param string $fieldList
  900. * @access public
  901. * @return PDOStatement
  902. */
  903. public function getIssues($fieldList)
  904. {
  905. $stmt = $this->dao->select($fieldList)->from(TABLE_ISSUE)->alias('t1')
  906. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
  907. ->where('t1.deleted')->eq('0')
  908. ->andWhere('t2.deleted')->eq('0')
  909. ->andWhere('t2.type')->eq('project');
  910. return $this->defaultWhere($stmt, 't2');
  911. }
  912. /**
  913. * 获取制品库数量。
  914. * Get artifact repo count.
  915. *
  916. * @param string $fieldList
  917. * @access public
  918. * @return PDOStatement
  919. */
  920. public function getArtifactRepos($fieldList)
  921. {
  922. return $this->dao->select($fieldList)->from(TABLE_ARTIFACTREPO)
  923. ->where('deleted')->eq('0');
  924. }
  925. /**
  926. * 获取代码库数量。
  927. * Get repos count.
  928. *
  929. * @param string $fieldList
  930. * @access public
  931. * @return PDOStatement
  932. */
  933. public function getRepos($fieldList)
  934. {
  935. return $this->dao->select($fieldList)->from(TABLE_REPO)
  936. ->where('deleted')->eq('0');
  937. }
  938. /**
  939. * 获取上线计划数据。
  940. * Get deployment data.
  941. *
  942. * @param string $fieldList
  943. * @access public
  944. * @return PDOStatement
  945. */
  946. public function getDeployment($fieldList)
  947. {
  948. return $this->dao->select($fieldList)->from(TABLE_DEPLOY)
  949. ->where('deleted')->eq('0');
  950. }
  951. /**
  952. * 获取流水线数据。
  953. * Get pipeline.
  954. *
  955. * @param string $fieldList
  956. * @access public
  957. * @return PDOStatement
  958. */
  959. public function getPipeline($fieldList)
  960. {
  961. return $this->dao->select($fieldList)->from(TABLE_JOB)->alias('t1')
  962. ->where('t1.deleted')->eq('0');
  963. }
  964. /**
  965. * 获取流水线执行数据。
  966. * Get compile.
  967. *
  968. * @param string $fieldList
  969. * @access public
  970. * @return PDOStatement
  971. */
  972. public function getCompile($fieldList)
  973. {
  974. return $this->dao->select($fieldList)->from(TABLE_COMPILE)->alias('t1')
  975. ->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job = t2.id')
  976. ->where('t1.deleted')->eq('0')
  977. ->andWhere('t2.deleted')->eq('0');
  978. }
  979. /**
  980. * 统计代码库问题信息。
  981. * Get repo issues.
  982. *
  983. * @param string $fieldList
  984. * @access public
  985. * @return PDOStatement
  986. */
  987. public function getRepoIssues($fieldList)
  988. {
  989. return $this->dao->select($fieldList)->from(TABLE_BUG)->alias('t1')
  990. ->leftJoin(TABLE_REPO)->alias('t2')->on('t1.repo = t2.id')
  991. ->where('t1.repo')->gt(0)
  992. ->andWhere('t1.deleted')->eq('0')
  993. ->andWhere('t2.deleted')->eq('0');
  994. }
  995. /**
  996. * 统计执行节点信息。
  997. * Get za nodes.
  998. *
  999. * @param string $fieldList
  1000. * @access public
  1001. * @return PDOStatement
  1002. */
  1003. public function getZaNodes($fieldList)
  1004. {
  1005. return $this->dao->select($fieldList)->from(TABLE_ZAHOST)->alias('t1')
  1006. ->leftJoin(TABLE_IMAGE)->alias('t2')->on('t2.id = t1.image')
  1007. ->where('t1.deleted')->eq(0)
  1008. ->andWhere("t1.type = 'node'");
  1009. }
  1010. /**
  1011. * 统计合并请求信息。
  1012. * Get merge requests.
  1013. *
  1014. * @param string $fieldList
  1015. * @access public
  1016. * @return PDOStatement
  1017. */
  1018. public function getMRs($fieldList)
  1019. {
  1020. return $this->dao->select($fieldList)->from(TABLE_MR)->alias('t1')
  1021. ->leftJoin(TABLE_REPO)->alias('t2')->on('t1.repoID = t2.id')
  1022. ->where('t1.deleted')->eq('0')
  1023. ->andWhere('t2.deleted')->eq('0')
  1024. ->andWhere('t1.isFlow')->eq('0');
  1025. }
  1026. /**
  1027. * 统计团队成员信息。
  1028. * Get team members.
  1029. *
  1030. * @param string $fieldList
  1031. * @access public
  1032. * @return PDOStatement
  1033. */
  1034. public function getTeamMembers($fieldList)
  1035. {
  1036. $stmt = $this->dao->select($fieldList)
  1037. ->from(TABLE_TEAM)->alias('t1')
  1038. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t2.id=t1.root')
  1039. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t3.id=t2.project')
  1040. ->leftJoin(TABLE_USER)->alias('t4')->on('t1.account=t4.account')
  1041. ->where('t1.type')->eq('execution')
  1042. ->andWhere('t2.deleted')->eq(0)
  1043. ->andWhere('t3.deleted')->eq(0)
  1044. ->andWhere('t4.deleted')->eq(0);
  1045. return $this->defaultWhere($stmt, 't3');
  1046. }
  1047. /**
  1048. * 统计日志信息。
  1049. * Get effort.
  1050. *
  1051. * @param string $fieldList
  1052. * @access public
  1053. * @return PDOStatement
  1054. */
  1055. public function getEfforts($fieldList)
  1056. {
  1057. $defaultHours = $this->dao->select('value')
  1058. ->from(TABLE_CONFIG)
  1059. ->where('module')->eq('execution')
  1060. ->andWhere('key')->eq('defaultWorkhours')
  1061. ->fetch('value');
  1062. if(empty($defaultHours)) $defaultHours = 7;
  1063. return $this->dao->select("$fieldList, $defaultHours as defaultHours")
  1064. ->from(TABLE_EFFORT)->alias('t1')
  1065. ->where('t1.deleted')->eq('0');
  1066. }
  1067. /**
  1068. * 统计项目日志信息。
  1069. * Get project effort.
  1070. *
  1071. * @param string $fieldList
  1072. * @access public
  1073. * @return PDOStatement
  1074. */
  1075. public function getProjectEfforts($fieldList)
  1076. {
  1077. $defaultHours = $this->dao->select('value')
  1078. ->from(TABLE_CONFIG)
  1079. ->where('module')->eq('execution')
  1080. ->andWhere('key')->eq('defaultWorkhours')
  1081. ->fetch('value');
  1082. if(empty($defaultHours)) $defaultHours = 7;
  1083. $stmt = $this->dao->select("$fieldList, $defaultHours as defaultHours")
  1084. ->from(TABLE_EFFORT)->alias('t1')
  1085. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
  1086. ->where('t1.deleted')->eq('0')
  1087. ->andWhere('t2.deleted')->eq('0')
  1088. ->andWhere('t2.type')->eq('project');
  1089. return $this->defaultWhere($stmt, 't2');
  1090. }
  1091. /**
  1092. * 统计瀑布项目任务信息。
  1093. * Get waterfall tasks.
  1094. *
  1095. * @param string $fieldList
  1096. * @access public
  1097. * @return PDOStatement
  1098. */
  1099. public function getWaterfallTasks($fieldList)
  1100. {
  1101. $stmt = $this->dao->select($fieldList)->from(TABLE_TASK)->alias('t1')
  1102. ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.execution = t2.id')
  1103. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project = t3.id')
  1104. ->where('t1.isParent')->eq(0)
  1105. ->andWhere('t1.deleted')->eq('0')
  1106. ->andWhere('t1.status')->ne('cancel')
  1107. ->andWhere('t2.deleted')->eq('0')
  1108. ->andWhere('t3.type')->eq('project')
  1109. ->andWhere('t3.model')->in('waterfall,waterfallplus');
  1110. return $this->defaultWhere($stmt, 't3');
  1111. }
  1112. public function getWaterfallEfforts($fieldList)
  1113. {
  1114. $stmt = $this->dao->select($fieldList)->from(TABLE_EFFORT)->alias('t1')
  1115. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
  1116. ->where('t1.deleted')->eq('0')
  1117. ->andWhere('t2.deleted')->eq('0')
  1118. ->andWhere('t2.model')->eq('waterfall')
  1119. ->andWhere('t2.type')->eq('project');
  1120. return $this->defaultWhere($stmt, 't2');
  1121. }
  1122. /**
  1123. * 统计测试用例结果信息。
  1124. * Get test results.
  1125. *
  1126. * @param string $fieldList
  1127. * @access public
  1128. * @return PDOStatement
  1129. */
  1130. public function getTestresults($fieldList)
  1131. {
  1132. $stmt = $this->dao->select($fieldList)
  1133. ->from(TABLE_TESTRESULT)->alias('t1')
  1134. ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.`case`=t2.id')
  1135. ->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t2.product=t3.id')
  1136. ->where('t2.deleted')->eq('0')
  1137. ->andWhere('t3.deleted')->eq('0');
  1138. return $this->defaultWhere($stmt, 't3');
  1139. }
  1140. /**
  1141. * 统计研发需求评审信息。
  1142. *
  1143. * @param string $fieldList
  1144. * @access public
  1145. * @return PDOStatement
  1146. */
  1147. public function getDevStoriesWithReview($fieldList)
  1148. {
  1149. $stmt = $this->dao->select($fieldList)
  1150. ->from(TABLE_STORYREVIEW)->alias('t1')
  1151. ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story=t2.id')
  1152. ->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t2.product=t3.id')
  1153. ->where('t2.deleted')->eq(0)
  1154. ->andWhere('t3.deleted')->eq(0)
  1155. ->andWhere('t2.type')->eq('story');
  1156. return $this->defaultWhere($stmt, 't3');
  1157. }
  1158. public function getProjectTasks($fieldList)
  1159. {
  1160. $defaultHours = $this->dao->select('value')
  1161. ->from(TABLE_CONFIG)
  1162. ->where('module')->eq('execution')
  1163. ->andWhere('key')->eq('defaultWorkhours')
  1164. ->fetch('value');
  1165. if(empty($defaultHours)) $defaultHours = 7;
  1166. if(strpos($fieldList, '`t2`.') === false)
  1167. {
  1168. $stmt = $this->dao->select("$fieldList, $defaultHours AS defaultHours")
  1169. ->from(TABLE_PROJECT)->alias('t1')
  1170. ->where('t1.type')->eq('project')
  1171. ->andWhere('t1.deleted')->eq('0');
  1172. return $this->defaultWhere($stmt, 't1');
  1173. }
  1174. $task = $this->dao->select('SUM(t1.consumed) AS consumed, t1.project')
  1175. ->from(TABLE_TASK)->alias('t1')
  1176. ->where('t1.deleted')->eq('0')
  1177. ->andWhere('t1.isParent')->eq('0');
  1178. $query = $this->defaultWhere($task, 't1')->groupBy('t1.project')->get();
  1179. $dbType = $this->config->metricDB->type;
  1180. if($dbType == 'duckdb')
  1181. {
  1182. $table = "($query)";
  1183. }
  1184. else
  1185. {
  1186. $table = 'tmp_task_getProjectTasks';
  1187. $this->dao->exec("DROP TABLE IF EXISTS `{$table}`");
  1188. $this->dao->exec("CREATE TABLE `{$table}` AS {$query}");
  1189. $this->dao->exec("CREATE INDEX `project` ON `{$table}` (`project`)");
  1190. }
  1191. $stmt = $this->dao->select("$fieldList, $defaultHours AS defaultHours")
  1192. ->from(TABLE_PROJECT)->alias('t1')
  1193. ->leftJoin($table)->alias('t2')->on('t1.id = t2.project')
  1194. ->where('t1.type')->eq('project')
  1195. ->andWhere('t1.deleted')->eq('0');
  1196. return $this->defaultWhere($stmt, 't1');
  1197. }
  1198. public function getTestRuns($fieldList)
  1199. {
  1200. return $this->dao->select($fieldList)
  1201. ->from(TABLE_TESTRUN)->alias('t1')
  1202. ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.`case` = t2.id')
  1203. ->leftJoin(TABLE_TESTTASK)->alias('t3')->on('t1.task = t3.id')
  1204. ->where('t3.deleted')->eq(0)
  1205. ->andWhere('t2.deleted')->eq(0);
  1206. }
  1207. /**
  1208. * 获取工单数据。
  1209. * Get Tickets.
  1210. *
  1211. * @param string $fieldList
  1212. * @access public
  1213. * @return PDOStatement
  1214. */
  1215. public function getAllTickets($fieldList)
  1216. {
  1217. $stmt = $this->dao->select($fieldList)->from(TABLE_TICKET)->alias('t1')
  1218. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  1219. ->where('t1.deleted')->eq('0')
  1220. ->andWhere('t2.deleted')->eq('0');
  1221. return $this->defaultWhere($stmt, 't2');
  1222. }
  1223. /**
  1224. * 获取工单数据,过滤影子产品下的工单。
  1225. * Get Tickets without shadow product.
  1226. *
  1227. * @param string $fieldList
  1228. * @access public
  1229. * @return PDOStatement
  1230. */
  1231. public function getTickets($fieldList)
  1232. {
  1233. $stmt = $this->dao->select($fieldList)->from(TABLE_TICKET)->alias('t1')
  1234. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  1235. ->where('t1.deleted')->eq('0')
  1236. ->andWhere('t2.deleted')->eq('0')
  1237. ->andWhere('t2.shadow')->eq('0');
  1238. return $this->defaultWhere($stmt, 't2');
  1239. }
  1240. /**
  1241. * 获取需求池中的需求数据。
  1242. * Get demands.
  1243. *
  1244. * @param string $fieldList
  1245. * @access public
  1246. * @return PDOStatement
  1247. */
  1248. public function getDemands($fieldList)
  1249. {
  1250. return $this->dao->select($fieldList)->from(TABLE_DEMAND)
  1251. ->where('deleted')->eq('0')
  1252. ->andWhere("vision LIKE '%or%'");
  1253. }
  1254. /**
  1255. * 获取质量保证计划和不符合项的编号和指派人。
  1256. * Get id and assigned of auditplan and nc.
  1257. *
  1258. * @param string $fieldList
  1259. * @access public
  1260. * @return PDOStatement
  1261. */
  1262. public function getQAs($fieldList)
  1263. {
  1264. $fieldList = 't1.id, t1.assignedTo, t2.vision';
  1265. $auditplanTable = $this->config->objectTables['auditplan'];
  1266. $ncTable = $this->config->objectTables['nc'];
  1267. $userTable = $this->config->objectTables['user'];
  1268. $projectTable = $this->config->objectTables['project'];
  1269. $auditplan = $this->dao->select($fieldList)
  1270. ->from(TABLE_AUDITPLAN)->alias('t1')
  1271. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
  1272. ->leftJoin(TABLE_USER)->alias('t3')->on('t1.assignedTo = t3.account')
  1273. ->where('t1.status')->eq('wait')
  1274. ->andWhere('t2.type')->eq('project')
  1275. ->andWhere('t1.deleted')->eq('0')
  1276. ->andWhere('t2.deleted')->eq('0')
  1277. ->andWhere('t3.deleted')->eq('0')->get();
  1278. $nc = $this->dao->select($fieldList)
  1279. ->from(TABLE_NC)->alias('t1')
  1280. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
  1281. ->leftJoin(TABLE_USER)->alias('t3')->on('t1.assignedTo = t3.account')
  1282. ->where('t1.status')->eq('active')
  1283. ->andWhere('t2.type')->eq('project')
  1284. ->andWhere('t1.deleted')->eq('0')
  1285. ->andWhere('t2.deleted')->eq('0')
  1286. ->andWhere('t3.deleted')->eq('0')->get();
  1287. $sql = "$auditplan UNION ALL $nc";
  1288. $stmt = $this->dao->select('*')->from("($sql) tt")->where('1=1');
  1289. $stmt = $this->defaultWhere($stmt, 'tt');
  1290. return $stmt;
  1291. }
  1292. /**
  1293. * 获取代码库提交数量。
  1294. * Get repo commits.
  1295. *
  1296. * @param string $fieldList
  1297. * @access public
  1298. * @return PDOStatement
  1299. */
  1300. public function getRepoCommits($fieldList)
  1301. {
  1302. return $this->dao->select($fieldList)->from(TABLE_REPO)->alias('t1')
  1303. ->leftJoin(TABLE_REPOHISTORY)->alias('t2')->on('t2.repo=t1.id')
  1304. ->leftJoin(TABLE_PIPELINE)->alias('t3')->on('t3.id=t1.serviceHost')
  1305. ->where('t1.deleted')->eq(0);
  1306. }
  1307. /**
  1308. * 获取应用信息。
  1309. * Get applications.
  1310. *
  1311. * @param string $fieldList
  1312. * @access public
  1313. * @return PDOStatement
  1314. */
  1315. public function getApplications($fieldList)
  1316. {
  1317. $count = (int)$this->dao->select('COUNT(1) AS count')->from(TABLE_INSTANCE)
  1318. ->where('deleted')->eq(0)
  1319. ->fetch('count');
  1320. return $this->dao->select("COUNT(1) AS count, {$count} as instanceCount")->from(TABLE_PIPELINE)
  1321. ->where('deleted')->eq(0);
  1322. }
  1323. /**
  1324. * 获取主机信息。
  1325. * Get hosts.
  1326. *
  1327. * @param string $fieldList
  1328. * @access public
  1329. * @return void
  1330. */
  1331. public function getHosts($fieldList)
  1332. {
  1333. return $this->dao->select($fieldList)->from(TABLE_HOST)->where('deleted')->eq(0);
  1334. }
  1335. /**
  1336. * 获取DevOps环境信息。
  1337. * Get devops env.
  1338. *
  1339. * @param string $fieldList
  1340. * @access public
  1341. * @return void
  1342. */
  1343. public function getDevOpsEnv($fieldList)
  1344. {
  1345. return $this->dao->select($fieldList)->from(TABLE_ENV)->where('deleted')->eq(0);
  1346. }
  1347. }