INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`) VALUES ('0','*','*','*','*','moduleName=misc&methodName=cleanCache', '清理缓存文件','zentao', 1, 'normal');

ALTER TABLE `zt_product`
ADD `draftStories` mediumint(8) NOT NULL DEFAULT '0' AFTER `reviewer`,
ADD `activeStories` mediumint(8) NOT NULL DEFAULT '0' AFTER `draftStories`,
ADD `changingStories` mediumint(8) NOT NULL DEFAULT '0' AFTER `activeStories`,
ADD `reviewingStories` mediumint(8) NOT NULL DEFAULT '0' AFTER `changingStories`,
ADD `finishedStories` mediumint NOT NULL DEFAULT '0' AFTER `reviewingStories`,
ADD `closedStories` mediumint(8) NOT NULL DEFAULT '0' AFTER `finishedStories`,
ADD `totalStories` mediumint(8) NOT NULL DEFAULT '0' AFTER `closedStories`,
ADD `unresolvedBugs` mediumint(8) NOT NULL DEFAULT '0' AFTER `totalStories`,
ADD `closedBugs` mediumint(8) NOT NULL DEFAULT '0' AFTER `unresolvedBugs`,
ADD `fixedBugs` mediumint(8) NOT NULL DEFAULT '0' AFTER `closedBugs`,
ADD `totalBugs` mediumint(8) NOT NULL DEFAULT '0' AFTER `fixedBugs`,
ADD `plans` mediumint(8) NOT NULL DEFAULT '0' AFTER `totalBugs`,
ADD `releases` mediumint(8) NOT NULL DEFAULT '0' AFTER `plans`;

UPDATE `zt_pivot` SET `sql` = 'SELECT \n  t1.name AS  \'产品\', \n  IFNULL(t2.name, \'/\') AS \'一级项目集\', \n  IFNULL(t3.name, \'/\') AS \'产品线\', \n  IFNULL(t6.exfixedstorys, 0) AS \'研发完成需求数\', \n  round(IFNULL(t6.exfixedstorysmate, 0),3) AS \'研发完成需求规模数\',\n  IFNULL(t8.storycases, 0) AS \'需求用例数\',\n  round(storycases/exfixedstorysmate,3) AS \'用例密度\',\n  round(IFNULL(t10.casestorys/t6.exfixedstorys,0),3) AS \'用例覆盖率\',\n  IFNULL(t7.bug, 0) AS \'Bug数\',\n  IFNULL(t7.effbugs, 0) AS \'有效Bug数\',\n  IFNULL(t7.pri12bugs, 0) AS \'优先级为1，2的Bug数\',\n  round(bug/exfixedstorysmate,3) AS \'Bug密度\',\n  IFNULL(t7.fixedbugs, 0) AS \'修复Bug数\',\n  round(t7.fixedbugs/bug,3) \'Bug修复率\'\nFROM \n  zt_product AS t1 \n  LEFT JOIN zt_project AS t2 ON t1.program = t2.id AND t2.type = \'program\' AND t2.grade = 1 \n  LEFT JOIN zt_module AS t3 ON t1.line = t3.id AND t3.type = \'line\' \n  LEFT JOIN (\n  SELECT\n  product, \n  count(id) exfixedstorys, \n  sum(estimate) exfixedstorysmate\n  FROM zt_story \n  WHERE deleted = \'0\'  and (stage in (\'developed\',\'testing\',\'verfied\',\'released\') or (status=\'closed\' and closedReason=\'done\'))\n  GROUP BY product) AS t6 ON t1.id = t6.product \n  LEFT JOIN (SELECT product, COUNT(id)  AS bug,\n  SUM(case when  resolution in (\'fixed\',\'postponed\') or status=\'active\' then 1 else 0 end) effbugs, \n  SUM(CASE WHEN  resolution=\'fixed\' then 1 else 0 end) fixedbugs,\n  SUM(CASE WHEN severity in (1,2) then 1 else 0 end) pri12bugs\n  FROM zt_bug WHERE deleted = \'0\' GROUP BY product) AS t7 ON t1.id = t7.product \n  LEFT JOIN (SELECT product, COUNT(id) AS storycases FROM zt_case WHERE deleted=\'0\' GROUP BY product) AS t8 ON t1.id=t8.product\n  LEFT JOIN (\n   select \n   t9.product, \n   count(t9.story) casestorys\n   from(\n     SELECT \n     zt_case.product,zt_case.story \n     FROM zt_case \n     left join zt_story\n     on zt_case.story=zt_story.id\n     WHERE zt_case.deleted=\'0\' and zt_case.story !=\'0\' and zt_story.deleted=\'0\' and  (zt_story.stage in (\'developed\',\'testing\',\'verfied\',\'released\') or (zt_story.status=\'closed\' and zt_story.closedReason=\'done\'))\n     GROUP BY product, story) t9\n     group by product) t10\n     on t1.id=t10.product\nWHERE t1.deleted = \'0\' AND t1.status != \'closed\' AND t1.shadow = \'0\'AND t1.vision = \'rnd\'\nORDER BY t1.order'
WHERE id = 1002;
UPDATE `zt_chart` SET `settings` = '{\"value\": {\"type\": \"agg\", \"field\": \"taskleft\", \"agg\": \"sum\"}, \"title\": {\"type\": \"text\", \"name\": \"\"}, \"type\": \"value\"}'
WHERE id = 10112;

UPDATE `zt_priv` SET `edition`=',biz,max,ipd,' where `module`='feedback' and `method`='toUserStory';

UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id,t3.name as project,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t2.id as bugID,t2.type from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)'
WHERE `sql` = 'select t1.id,t3.name as project,t3.id,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t2.id as bugID,t2.type from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)';
UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id,t4.name as project,IF(t4.multiple=\"1\",t1.name,\"\") as execution,t1.status,t2.number as tasks,round(t2.consumed,2) as consumed,round(t2.`left`,2) as `left`,t3.stories,t2.undone as undoneTask,t3.undone as undoneStory,t2.totalReal from zt_project as t1 \r\nleft join ztv_executionsummary as t2 on t1.id=t2.execution\r\nleft join ztv_projectstories as t3 on t1.id=t3.execution\r\nleft join zt_project as t4 on t4.id=t1.project\r\nwhere t1.deleted=\'0\' and t1.type in (\'sprint\',\'stage\') and if($project=\'\',1,t4.id=$project) and if($execution=\'\',1,t1.id=$execution) and if($status=\'\',1,t1.status=$status)'
WHERE `sql` = 'select t1.id,t4.name as project,t4.id,IF(t4.multiple=\"1\",t1.name,\"\") as execution,t1.status,t2.number as tasks,round(t2.consumed,2) as consumed,round(t2.`left`,2) as `left`,t3.stories,t2.undone as undoneTask,t3.undone as undoneStory,t2.totalReal from zt_project as t1 \r\nleft join ztv_executionsummary as t2 on t1.id=t2.execution\r\nleft join ztv_projectstories as t3 on t1.id=t3.execution\r\nleft join zt_project as t4 on t4.id=t1.project\r\nwhere t1.deleted=\'0\' and t1.type in (\'sprint\',\'stage\') and if($project=\'\',1,t4.id=$project) and if($execution=\'\',1,t1.id=$execution) and if($status=\'\',1,t1.status=$status)';
UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id, t5.name as project,IF(t5.multiple=\"1\",t1.name,\"\") as execution,t2.stories,(t2.stories-t2.undone) as doneStory,t3.number,(t3.number-t3.undone) as doneTask,t4.bugs,t4.resolutions, round(t4.bugs/(t2.stories-t2.undone),2) as bugthanstory,round(t4.bugs/(t3.number-t3.undone),2) as bugthantask,t4.seriousBugs from zt_project as t1 \r\nleft join ztv_projectstories as t2 on t1.id=t2.execution\r\nleft join ztv_executionsummary as t3 on t1.id=t3.execution\r\nleft join ztv_projectbugs as t4 on t1.id=t4.execution\r\nleft join zt_project as t5 on t5.id=t1.project\r\nwhere t1.deleted=\'0\' and t1.type in (\'sprint\',\'stage\') and t1.grade=\'1\' and if($project=\'\',1,t5.id=$project) and if($execution=\'\',1,t1.id=$execution)'
WHERE `sql` = 'select t1.id, t5.name as project,t5.id,IF(t5.multiple=\"1\",t1.name,\"\") as execution,t2.stories,(t2.stories-t2.undone) as doneStory,t3.number,(t3.number-t3.undone) as doneTask,t4.bugs,t4.resolutions, round(t4.bugs/(t2.stories-t2.undone),2) as bugthanstory,round(t4.bugs/(t3.number-t3.undone),2) as bugthantask,t4.seriousBugs from zt_project as t1 \r\nleft join ztv_projectstories as t2 on t1.id=t2.execution\r\nleft join ztv_executionsummary as t3 on t1.id=t3.execution\r\nleft join ztv_projectbugs as t4 on t1.id=t4.execution\r\nleft join zt_project as t5 on t5.id=t1.project\r\nwhere t1.deleted=\'0\' and t1.type in (\'sprint\',\'stage\') and t1.grade=\'1\' and if($project=\'\',1,t5.id=$project) and if($execution=\'\',1,t1.id=$execution)';
UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id,t3.name as project,t3.id as projectID,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.assignedTo from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution \r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)'
WHERE `sql` = 'select t1.id,t3.name as project,t3.id,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.assignedTo from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution \r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)';
UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id,t3.name as project,t3.id as projectID,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.resolvedBy from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' and t2.status!=\'active\' and t2.resolvedBy!=\'\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)'
WHERE `sql` = 'select t1.id,t3.name as project,t3.id,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.resolvedBy from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' and t2.status!=\'active\' and t2.resolvedBy!=\'\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)';
UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id,t3.name as project,t3.id as projectID,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.openedBy from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)'
WHERE `sql` = 'select t1.id,t3.name as project,t3.id,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.openedBy from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)';
UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id,t3.name as project,t3.id as projectID,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.status from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' having bugID!=\' \' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)'
WHERE `sql` = 'select t1.id,t3.name as project,t3.id,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.status from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\nwhere t1.deleted=\'0\' and t2.deleted=\'0\' having bugID!=\' \' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)';
UPDATE `zt_pivot` SET `stage` = 'published', `sql` = 'select t1.id,t3.name as project,t3.id as projectID,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.resolution from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\n where t1.deleted=\'0\' and t2.deleted=\'0\' and t2.resolution!=\'\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)'
WHERE `sql` = 'select t1.id,t3.name as project,t3.id,IF(t3.multiple=\"1\",t1.name,\"\") as execution,t1.id as bugID,t2.resolution from zt_project as t1 \r\nleft join zt_bug as t2 on t1.id=t2.execution\r\nleft join zt_project as t3 on t3.id=t1.project\r\n where t1.deleted=\'0\' and t2.deleted=\'0\' and t2.resolution!=\'\' having bugID!=\'\' and if($project=\'\',1,t3.id=$project) and if($execution=\'\',1,t1.id=$execution)';

UPDATE `zt_chart` SET `createdBy` = 'admin' WHERE `id` <= 1110;
