From ab5d57055cf4c9943468baaa8934e0e9aa943894 Mon Sep 17 00:00:00 2001
From: 이민희 <mhlee@maprex.co.kr>
Date: 수, 08 12월 2021 17:02:49 +0900
Subject: [PATCH] - url 컬럼 추가 * DB 초기화 필요 - 대시보드 담당부서 별로 수정

---
 src/main/resources/mybatis/query-template/project-template.xml        |   25 +++++++-----
 src/main/webapp/scripts/components/utils/autoComplete.controller.js   |    3 +
 src/main/java/kr/wisestone/owl/service/impl/WidgetServiceImpl.java    |   16 ++++++-
 src/main/resources/migration/V1_12__Alter_Table.sql                   |    4 ++
 src/main/webapp/scripts/app/issue/issueModifyDepartment.controller.js |    3 +
 src/main/resources/mybatis/query-template/issue-template.xml          |    2 
 src/main/java/kr/wisestone/owl/mapper/WidgetMapper.java               |    4 ++
 src/main/resources/mybatis/query-template/widget-template.xml         |   61 ++++++++++++++++++++++++++----
 8 files changed, 94 insertions(+), 24 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/mapper/WidgetMapper.java b/src/main/java/kr/wisestone/owl/mapper/WidgetMapper.java
index fad95ab..3cf73ff 100644
--- a/src/main/java/kr/wisestone/owl/mapper/WidgetMapper.java
+++ b/src/main/java/kr/wisestone/owl/mapper/WidgetMapper.java
@@ -102,4 +102,8 @@
     List<Map<String, Object>> findProjectMemberIssueByDepartment(WidgetCondition widgetCondition);
 
     List<Map<String, Object>> findMyAssigneeIssueByDepartment(WidgetCondition makeWidgetCondition);
+
+    List<Map<String, Object>> findByStandIssueTypeOfDepartment(WidgetCondition widgetCondition);
+
+    List<Map<String, Object>> findByStandIssueStatusOfDepartment(WidgetCondition widgetCondition);
 }
diff --git a/src/main/java/kr/wisestone/owl/service/impl/WidgetServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/WidgetServiceImpl.java
index 250a93e..3a7cdc3 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/WidgetServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/WidgetServiceImpl.java
@@ -782,10 +782,15 @@
         }
 
         List<Map<String, Object>> results = Lists.newArrayList();
+        User user = this.webAppUtil.getLoginUserObject();
 
         if (widgetCondition.getProjectIds().size() > 0) {
             SetMeAndDownProjectIds(widgetCondition.getProjectIds(), widgetCondition);
-            results = this.widgetMapper.findByStandIssueStatus(widgetCondition);
+            if (this.userWorkspaceService.checkWorkspaceManager(user)) {
+                results = this.widgetMapper.findByStandIssueStatus(widgetCondition);
+            }else {
+                results = this.widgetMapper.findByStandIssueStatusOfDepartment(widgetCondition);
+            }
         }
 
         for (Map<String, Object> result : results) {
@@ -809,10 +814,15 @@
     public void findByStandIssueType(Map<String, Object> resJsonData, WidgetCondition widgetCondition, Boolean getWidgetCondition) {
         //  �쐞�젽 寃��깋 議곌굔�쓣 �뼸�뼱�빞 �븷 �긽�솴�씪 �븣 - �솕硫댁뿉�꽌 �꺆�쓣 �닃�윭 �뜲�씠�꽣瑜� �옱�슂泥��뻽�쓣 �븣 �쐞�젽 寃��깋 議곌굔�쓣 留뚮뱾怨� �쟾泥� �봽濡쒖젥�듃 �젙蹂대�� 由ы꽩�븳�떎.
         Map<String, Object> results = this.makeWidgetConditionAllProject(widgetCondition, getWidgetCondition);
-
+        User user = this.webAppUtil.getLoginUserObject();
         if (widgetCondition.getProjectId() != null) {
             SetMeAndDownProjectIds(widgetCondition.getProjectIds(), widgetCondition);
-            List<Map<String, Object>> issueTypeIssues = this.widgetMapper.findByStandIssueType(widgetCondition);
+            List<Map<String, Object>> issueTypeIssues = Lists.newArrayList();
+            if (this.userWorkspaceService.checkWorkspaceManager(user)) {
+                issueTypeIssues = this.widgetMapper.findByStandIssueType(widgetCondition);
+            } else {
+                issueTypeIssues = this.widgetMapper.findByStandIssueTypeOfDepartment(widgetCondition);
+            }
             //  �씠�뒋 �젙蹂�
             results.put("issues", issueTypeIssues);
         } else {
diff --git a/src/main/resources/migration/V1_12__Alter_Table.sql b/src/main/resources/migration/V1_12__Alter_Table.sql
index cbce5f8..1cc7e95 100644
--- a/src/main/resources/migration/V1_12__Alter_Table.sql
+++ b/src/main/resources/migration/V1_12__Alter_Table.sql
@@ -5,3 +5,7 @@
 ALTER TABLE `company_field` ADD COLUMN  `url` VARCHAR(255) NULL;
 ALTER TABLE `isp_field` ADD COLUMN  `url` VARCHAR(255) NULL;
 ALTER TABLE `hosting_field` ADD COLUMN  `url` VARCHAR(255) NULL;
+
+ALTER TABLE `issue_company` ADD COLUMN  `url` VARCHAR(255) NULL;
+ALTER TABLE `issue_isp` ADD COLUMN  `url` VARCHAR(255) NULL;
+ALTER TABLE `issue_hosting` ADD COLUMN  `url` VARCHAR(255) NULL;
diff --git a/src/main/resources/mybatis/query-template/issue-template.xml b/src/main/resources/mybatis/query-template/issue-template.xml
index 55d1396..b0352e2 100644
--- a/src/main/resources/mybatis/query-template/issue-template.xml
+++ b/src/main/resources/mybatis/query-template/issue-template.xml
@@ -241,7 +241,7 @@
         INNER JOIN priority priority FORCE INDEX(PRIMARY) ON issue.priority_id = priority.id
         INNER JOIN severity severity FORCE INDEX(PRIMARY) ON issue.severity_id = severity.id
         INNER JOIN issue_department isd ON isd.issue_id = issue.id
-        INNER JOIN department d ON d.id = isd.department_id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         LEFT OUTER JOIN issue_custom_field_value issue_custom FORCE INDEX(issueIdIndex) ON issue.id = issue_custom.issue_id
         LEFT OUTER JOIN (SELECT issue_id, COUNT(id) as attachedFileCount FROM attached_file GROUP BY issue_id)
         temp_attached_file on (temp_attached_file.issue_id = issue.id)
diff --git a/src/main/resources/mybatis/query-template/project-template.xml b/src/main/resources/mybatis/query-template/project-template.xml
index 0c14c0a..e2d6b13 100644
--- a/src/main/resources/mybatis/query-template/project-template.xml
+++ b/src/main/resources/mybatis/query-template/project-template.xml
@@ -74,11 +74,10 @@
         project p
         INNER JOIN project_role pr on p.id = pr.project_id
         INNER JOIN project_role_department prd on prd.project_role_id = pr.id
-        INNER JOIN department d on d.id = prd.department_id
+        INNER JOIN user_department ud on ud.department_id = prd.department_id
         INNER JOIN workspace ws on ws.id = p.workspace_id
         LEFT JOIN project_closure pc ON p.id = pc.project_id
         WHERE if (pc.parent_project_id > -1, pc.parent_project_id, -1) = -1
-        AND prd.department_id = d.id
         <if test="name != '' and name != null">
             AND p.name like CONCAT('%',#{name},'%')
         </if>
@@ -89,9 +88,6 @@
                     #{item}
                 </foreach>
             </when>
-            <otherwise>
-                AND 1 != 1
-            </otherwise>
         </choose>
 
         <choose>
@@ -178,14 +174,23 @@
         project p
         INNER JOIN project_role pr on p.id = pr.project_id
         INNER JOIN project_role_department prd on prd.project_role_id = pr.id
-        INNER JOIN department d on d.id = prd.department_id
+        INNER JOIN user_department ud on ud.department_id = prd.department_id
         INNER JOIN workspace ws on ws.id = p.workspace_id
         LEFT JOIN project_closure pc on p.id = pc.project_id
-        WHERE prd.department_id = d.id
+        WHERE prd.department_id = ud.id
         AND if (pc.parent_project_id > -1, pc.parent_project_id, -1) = -1
         <if test="name != '' and name != null">
             AND p.name like CONCAT('%',#{name},'%')
         </if>
+
+        <choose>
+            <when test="myDepartmentIds.size != 0">
+                AND prd.department_id IN
+                <foreach collection="myDepartmentIds" item="item" index="index" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </when>
+        </choose>
 
         <choose>
             <when test="roleTypes.size != 0">
@@ -466,9 +471,9 @@
         project p
         INNER JOIN project_role pr on p.id = pr.project_id
         INNER JOIN project_role_department prd on prd.project_role_id = pr.id
-        INNER JOIN department d on d.id = prd.department_id
+        INNER JOIN user_department ud on ud.department_id = prd.department_id
         LEFT JOIN project_closure pc ON p.id = pc.project_id
-        WHERE prd.department_id = d.id
+        WHERE prd.department_id = ud.department_id
         AND if (pc.parent_project_id > -1, pc.parent_project_id, -1) = -1
         AND p.workspace_id = #{workspaceId}
         <if test="name != '' and name != null">
@@ -511,7 +516,7 @@
             project p
                 INNER JOIN project_role pr on p.id = pr.project_id
                 INNER JOIN project_role_department prd on prd.project_role_id = pr.id
-                INNER JOIN department d on d.id = prd.department_id
+                INNER JOIN user_department ud on ud.department_id = prd.department_id
         WHERE 1=1
           AND p.id = #{id}
     </select>
diff --git a/src/main/resources/mybatis/query-template/widget-template.xml b/src/main/resources/mybatis/query-template/widget-template.xml
index f7fedc1..22cd788 100644
--- a/src/main/resources/mybatis/query-template/widget-template.xml
+++ b/src/main/resources/mybatis/query-template/widget-template.xml
@@ -29,7 +29,7 @@
         SELECT
         COUNT(i.id) FROM issue i
         INNER JOIN issue_department isd ON isd.issue_id = i.id
-        INNER JOIN department d ON d.id = isd.department_id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         WHERE EXISTS(SELECT 1 FROM issue_status iss WHERE iss.issue_status_type != 'CLOSE' AND i.issue_status_id =
         iss.id)
         <choose>
@@ -73,7 +73,7 @@
         SELECT
         COUNT(i.id) FROM issue i
         INNER JOIN issue_department isd ON isd.issue_id = i.id
-        INNER JOIN department d ON d.id = isd.department_id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         where exists(select 1 from issue_status iss where iss.id = i.issue_status_id and iss.issue_status_type != 'CLOSE')
         <choose>
             <when test="meAndDownProjectIds != null and meAndDownProjectIds.size != 0">
@@ -153,7 +153,7 @@
         SELECT
         COUNT(i.id) FROM issue i
         INNER JOIN issue_department isd ON isd.issue_id = i.id
-        INNER JOIN department d ON d.id = isd.department_id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         WHERE EXISTS(SELECT 1 FROM issue_department isd WHERE isd.issue_id = i.id
         <choose>
             <when test="myDepartmentIds.size != 0">
@@ -199,7 +199,7 @@
         select
         count(i.id) as todayCount from issue i
         INNER JOIN issue_department isd ON isd.issue_id = i.id
-        INNER JOIN department d ON d.id = isd.department_id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         where
         i.register_id = #{loginUserId}
         <choose>
@@ -308,7 +308,7 @@
         count(*) as issueCount from issue i
         inner join issue_status iss on iss.id = i.issue_status_id
         INNER JOIN issue_department isd ON isd.issue_id = i.id
-        INNER JOIN department d ON d.id = isd.department_id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         where iss.issue_status_type = 'CLOSE'
         <choose>
             <when test="meAndDownProjectIds != null and meAndDownProjectIds.size != 0">
@@ -535,7 +535,9 @@
             parameterType="kr.wisestone.owl.web.condition.WidgetCondition">
         select
         count(i.id) as todayCount from issue i where
-        exists(select 1 from issue_department isd where isd.issue_id = i.id
+        exists(select 1 from issue_department isd
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
+        where isd.issue_id = i.id
         <choose>
             <when test="myDepartmentIds.size != 0">
                 AND isd.department_id IN
@@ -684,6 +686,7 @@
         replace(SUBSTRING(i.register_date, 1, 10), "-", ".") as registerDate
         from issue i
         inner join issue_department isd on isd.issue_id = i.id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         inner join issue_status iss on iss.id = i.issue_status_id
         inner join project p on p.id = i.project_id
         WHERE 1=1
@@ -1001,6 +1004,35 @@
         group by p.id
     </select>
 
+    <select id="findByStandIssueStatusOfDepartment" resultType="java.util.HashMap"
+            parameterType="kr.wisestone.owl.web.condition.WidgetCondition">
+        select
+        <choose>
+            <when test="issueStatuses.size != 0">
+                <foreach collection="issueStatuses" item="item" index="index" separator="," open="" close="">
+                    count(case when i.issue_status_id = #{item.id} then 1 end) as #{item.name}
+                </foreach>
+            </when>
+        </choose>
+        ,p.id,
+        p.name as projectName
+        from issue i
+        inner join project p on p.id = i.project_id
+        inner join issue_status iss on iss.id = i.issue_status_id
+        INNER JOIN issue_department isd ON isd.issue_id = i.id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
+        where 1=1
+        <choose>
+            <when test="meAndDownProjectIds != null and meAndDownProjectIds.size != 0">
+                AND i.project_id IN
+                <foreach collection="meAndDownProjectIds" item="item" index="index" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </when>
+        </choose>
+        group by p.id
+    </select>
+
     <!--    9踰� �쐞�젽 �걹 -->
 
     <!--    11踰� �쐞�젽 �떆�옉 -->
@@ -1085,6 +1117,7 @@
         from
         department d
         inner join project_role_department prd on prd.department_id = d.id
+        INNER JOIN user_department ud ON ud.department_id = prd.department_id
         inner join project_role pr on pr.id = prd.project_role_id
         inner join project p on p.id = pr.project_id
         WHERE
@@ -1243,8 +1276,18 @@
 
     <select id="findByStandIssueType" resultType="java.util.HashMap"
             parameterType="kr.wisestone.owl.web.condition.WidgetCondition">
-        SELECT issue_type.name as name, COUNT(issue.id) as issueCount FROM issue issue
-        INNER JOIN issue_type issue_type ON issue.issue_type_id = issue_type.id
+        SELECT issue_type.name as name, COUNT(issue.id) as issueCount FROM issue
+        INNER JOIN issue_type ON issue.issue_type_id = issue_type.id
+        WHERE issue.project_id = #{projectId}
+        GROUP BY issue_type.name
+    </select>
+
+    <select id="findByStandIssueTypeOfDepartment" resultType="java.util.HashMap"
+            parameterType="kr.wisestone.owl.web.condition.WidgetCondition">
+        SELECT issue_type.name as name, COUNT(issue.id) as issueCount FROM issue
+        INNER JOIN issue_type ON issue.issue_type_id = issue_type.id
+        INNER JOIN issue_department isd ON isd.issue_id = issue.id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         WHERE issue.project_id = #{projectId}
         GROUP BY issue_type.name
     </select>
@@ -1289,6 +1332,7 @@
         INNER JOIN severity s ON s.id = i.severity_id
         INNER JOIN issue_status iss ON iss.id = i.issue_status_id
         INNER JOIN issue_department isd on isd.issue_id = i.id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         WHERE w.id = #{workspaceId}
         AND iss.issue_status_type != 'CLOSE'
         <choose>
@@ -1363,6 +1407,7 @@
         INNER JOIN severity s ON s.id = i.severity_id
         INNER JOIN issue_status iss ON iss.id = i.issue_status_id
         INNER JOIN issue_department isd on isd.issue_id = i.id
+        INNER JOIN user_department ud ON ud.department_id = isd.department_id
         WHERE w.id = #{workspaceId}
         AND s.id = #{severityId}
         AND iss.issue_status_type != 'CLOSE'
diff --git a/src/main/webapp/scripts/app/issue/issueModifyDepartment.controller.js b/src/main/webapp/scripts/app/issue/issueModifyDepartment.controller.js
index 85a1aa0..9185985 100644
--- a/src/main/webapp/scripts/app/issue/issueModifyDepartment.controller.js
+++ b/src/main/webapp/scripts/app/issue/issueModifyDepartment.controller.js
@@ -26,7 +26,8 @@
                 $scope.vm = {
                     form : {
                         departments : [],     //  �떞�떦遺��꽌
-                        projects : []
+                        projects : [],
+                        issueTypeId : ""
                     },
                     departmentName : "",  //  遺��꽌 寃��깋
                     autoCompletePage : {
diff --git a/src/main/webapp/scripts/components/utils/autoComplete.controller.js b/src/main/webapp/scripts/components/utils/autoComplete.controller.js
index ddc1e12..866a530 100644
--- a/src/main/webapp/scripts/components/utils/autoComplete.controller.js
+++ b/src/main/webapp/scripts/components/utils/autoComplete.controller.js
@@ -312,7 +312,8 @@
 
                 function getIssueDepartmentList(query, excludeList, page, callBack) {
                     var conditions = {
-                        issueTypeId : $scope.vm.form.issueTypeId,
+                        //issueTypeId : $scope.vm.form.issueTypeId,
+                        issueTypeId : $rootScope.currentDetailIssueId,
                         departmentName : query,
                         userId : $rootScope.user.id,
                         projectId : (function () {

--
Gitblit v1.8.0