Browse Source

上级领导页面:首页顶部四个方框数据抓取

wangggziwen 9 months ago
parent
commit
f42e4f3ebe

+ 71 - 25
rc-admin/src/main/java/com/ruoyi/web/controller/rc/TAuditController.java

@@ -12,6 +12,7 @@ import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.rc.domain.*;
+import com.ruoyi.rc.mapper.TAuditMapper;
 import com.ruoyi.rc.service.*;
 import com.ruoyi.system.service.ISysDeptService;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -65,16 +66,49 @@ public class TAuditController extends BaseController
     @Autowired
     private ITOpenItemService itOpenItemService;
 
+    @Autowired
+    private TAuditMapper tAuditMapper;
+
+    /**
+     * 上级领导页面:查询首页顶部四个方框数据
+     */
+    @GetMapping("/homeData")
+    public AjaxResult getHomeData() {
+        HashMap map = new HashMap();
+
+        // 当前登录用户所在部门最近一次审计记录
+        TAudit audit = new TAudit();
+        audit.setDeptId(getLoginUser().getDeptId().toString());
+        TAudit latest = tAuditService.selectTAuditLatest(audit);
+        if (latest != null) {
+            Long auditId = latest.getId();
+
+            int homeData1 = tAuditMapper.selectHomeData1();
+            BigDecimal homeData2 = tAuditMapper.selectHomeData2();
+            int homeData3 = tAuditMapper.selectHomeData3(auditId);
+            int homeData4 = tAuditMapper.selectHomeData4(auditId);
+
+            map.put("homeData1", homeData1);
+            map.put("homeData2", homeData2);
+            map.put("homeData3", homeData3);
+            map.put("homeData4", homeData4);
+
+            return AjaxResult.success(map);
+        } else {
+            return AjaxResult.success();
+        }
+    }
+
     /**
-     * 查询首页柱状图数据
+     * 普通员工页面:查询首页柱状图数据
      */
     @GetMapping("/bar")
     public AjaxResult getBar() {
         TAudit audit = new TAudit();
         audit.setDeptId(getLoginUser().getDeptId().toString());
         TAudit latest = tAuditService.selectTAuditLatest(audit);
+        HashMap<String, String> map = new HashMap<String, String>();
         if(latest != null) {
-            HashMap<String, String> map = new HashMap<String, String>();
             int code0Count = 0;
             int code1Count = 0;
             int code2Count = 0;
@@ -151,14 +185,23 @@ public class TAuditController extends BaseController
             map.put("code7", code7CompleteProgress.toString());
             map.put("code8", code8CompleteProgress.toString());
             map.put("code9", code9CompleteProgress.toString());
-            return success(map);
         } else {
-            return success();
+            map.put("code0", "0");
+            map.put("code1", "0");
+            map.put("code2", "0");
+            map.put("code3", "0");
+            map.put("code4", "0");
+            map.put("code5", "0");
+            map.put("code6", "0");
+            map.put("code7", "0");
+            map.put("code8", "0");
+            map.put("code9", "0");
         }
+        return success(map);
     }
 
     /**
-     * 查询首页饼图数据
+     * 普通员工页面:查询首页饼图数据
      */
     @GetMapping("/pie")
     public AjaxResult getPie() {
@@ -168,29 +211,32 @@ public class TAuditController extends BaseController
         TAudit audit = new TAudit();
         audit.setDeptId(getLoginUser().getDeptId().toString());
         TAudit latest = tAuditService.selectTAuditLatest(audit);
-        Long auditId = latest.getId();
-        TChapter chapter = new TChapter();
-        chapter.setAuditId(auditId);
-        List<TChapter> tChapters = tChapterService.selectTChapterList(chapter);
-        for (TChapter tChapter : tChapters) {
-            TQuestionnaire questionnaire = new TQuestionnaire();
-            questionnaire.setChapterId(tChapter.getId());
-            List<TQuestionnaire> tQuestionnaires = tQuestionnaireService.selectTQuestionnaireList(questionnaire);
-            for (TQuestionnaire tQuestionnaire : tQuestionnaires) {
-                TOpenItem openItem = new TOpenItem();
-                openItem.setQuestionnaireId(tQuestionnaire.getId());
-                List<TOpenItem> tOpenItems = itOpenItemService.selectTOpenItemList(openItem);
-                for (TOpenItem tOpenItem : tOpenItems) {
-                    count++;
-                    String status = tOpenItem.getStatus();
-                    if ("4".equals(status)) {
-                        completeCount++;
+        if (latest != null) {
+            Long auditId = latest.getId();
+            TChapter chapter = new TChapter();
+            chapter.setAuditId(auditId);
+            List<TChapter> tChapters = tChapterService.selectTChapterList(chapter);
+            for (TChapter tChapter : tChapters) {
+                TQuestionnaire questionnaire = new TQuestionnaire();
+                questionnaire.setChapterId(tChapter.getId());
+                List<TQuestionnaire> tQuestionnaires = tQuestionnaireService.selectTQuestionnaireList(questionnaire);
+                for (TQuestionnaire tQuestionnaire : tQuestionnaires) {
+                    TOpenItem openItem = new TOpenItem();
+                    openItem.setQuestionnaireId(tQuestionnaire.getId());
+                    List<TOpenItem> tOpenItems = itOpenItemService.selectTOpenItemList(openItem);
+                    for (TOpenItem tOpenItem : tOpenItems) {
+                        count++;
+                        String status = tOpenItem.getStatus();
+                        if ("4".equals(status)) {
+                            completeCount++;
+                        }
                     }
                 }
             }
-        }
-        if (count != 0) {
-            progress = new BigDecimal(completeCount).divide(new BigDecimal(count), 4, BigDecimal.ROUND_HALF_UP);
+            if (count != 0) {
+                progress = new BigDecimal(completeCount).divide(new BigDecimal(count), 4, BigDecimal.ROUND_HALF_UP);
+            }
+
         }
         return success(progress);
     }

+ 10 - 0
rc-buisness/src/main/java/com/ruoyi/rc/mapper/TAuditMapper.java

@@ -1,5 +1,6 @@
 package com.ruoyi.rc.mapper;
 
+import java.math.BigDecimal;
 import java.util.List;
 import com.ruoyi.rc.domain.TAudit;
 
@@ -11,6 +12,15 @@ import com.ruoyi.rc.domain.TAudit;
  */
 public interface TAuditMapper 
 {
+    public int selectHomeData1();
+
+    public BigDecimal selectHomeData2();
+
+    public int selectHomeData3(Long auditId);
+
+    public int selectHomeData4(Long auditId);
+
+
     public TAudit selectTAuditLatest(TAudit tAudit);
 
     /**

+ 19 - 0
rc-buisness/src/main/resources/mapper/rc/TAuditMapper.xml

@@ -86,4 +86,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectHomeData1" resultType="int">
+      select count(*) from t_audit where audit_time > now() and extract(year from audit_time) = extract(year from now());
+    </select>
+
+    <select id="selectHomeData2" resultType="java.math.BigDecimal">
+      select (select count(*) from t_audit where audit_result='绿区通过') / (select count(*) from t_audit) from dual;
+    </select>
+
+    <select id="selectHomeData3" parameterType="Long" resultType="int">
+      select count(*) from t_open_item
+      where questionnaire_id in (select questionnaire_id from t_questionnaire where audit_id = #{auditId});
+    </select>
+
+    <select id="selectHomeData4" parameterType="Long" resultType="int">
+      select count(*) from t_open_item
+      where questionnaire_id in (select questionnaire_id from t_questionnaire where audit_id = #{auditId})
+      and status = 4;
+    </select>
 </mapper>

+ 8 - 0
ruoyi-ui/src/api/rc/audit.js

@@ -1,5 +1,13 @@
 import request from '@/utils/request'
 
+// 查询首页顶部四个方框数据
+export function getHomeData() {
+  return request({
+    url: '/rc/audit/homeData',
+    method: 'get'
+  })
+}
+
 // 查询首页柱状图数据
 export function getBar() {
   return request({

+ 23 - 4
ruoyi-ui/src/views/home1.vue

@@ -7,7 +7,7 @@
         </div>
         <div class="word">
           <div class="topItemTitle">本年待审装置数量</div>
-          <div class="topItemContent">1147</div>
+          <div class="topItemContent">{{homeData1}}</div>
         </div>
 
       </div>
@@ -17,7 +17,7 @@
         </div>
         <div class="word">
           <div class="topItemTitle">历年装置审计绿区通过率</div>
-          <div class="topItemContent">16</div>
+          <div class="topItemContent">{{homeData2}}</div>
         </div>
       </div>
       <div class="topItem itembg3">
@@ -26,7 +26,7 @@
         </div>
         <div class="word">
           <div class="topItemTitle">待审装置开项问题汇总</div>
-          <div class="topItemContent">16</div>
+          <div class="topItemContent">{{homeData3}}</div>
         </div>
       </div>
       <div class="topItem itembg4">
@@ -35,7 +35,7 @@
         </div>
         <div class="word">
           <div class="topItemTitle">待审装置开项问题处理完成数量</div>
-          <div class="topItemContent">0</div>
+          <div class="topItemContent">{{homeData4}}</div>
         </div>
       </div>
     </div>
@@ -276,7 +276,26 @@
 </template>
 
 <script>
+  import { getHomeData } from "@/api/rc/audit";
+
   export default {
+    data() {
+      return {
+        homeData1: 0,
+        homeData2: 0,
+        homeData3: 0,
+        homeData4: 0,
+      }
+    },
+    created() {
+      getHomeData().then(response => {
+        this.homeData1 = response.data.homeData1;
+        this.homeData2 = (response.data.homeData2 * 100) + "%";
+        this.homeData3 = response.data.homeData3;
+        this.homeData4 = response.data.homeData4;
+        console.log(response)
+      });
+    }
   };
 </script>
 <style scoped>

+ 20 - 8
ruoyi-ui/src/views/home2.vue

@@ -119,17 +119,29 @@ export default {
           series: [
             {
               data: [
-                {value: data.code0 * 100, itemStyle: {color: '#5470C6'}},
+                {value: data.code0 * 100, itemStyle: {color: '#91CC75'}},
                 {value: data.code1 * 100, itemStyle: {color: '#91CC75'}},
-                {value: data.code2 * 100, itemStyle: {color: '#FAC858'}},
-                {value: data.code3 * 100, itemStyle: {color: '#EE6666'}},
-                {value: data.code4 * 100, itemStyle: {color: '#73C0DE'}},
-                {value: data.code5 * 100, itemStyle: {color: '#3BA272'}},
-                {value: data.code6 * 100, itemStyle: {color: '#FC8452'}},
-                {value: data.code7 * 100, itemStyle: {color: '#9A60B4'}},
-                {value: data.code8 * 100, itemStyle: {color: '#5470C6'}},
+                {value: data.code2 * 100, itemStyle: {color: '#91CC75'}},
+                {value: data.code3 * 100, itemStyle: {color: '#91CC75'}},
+                {value: data.code4 * 100, itemStyle: {color: '#91CC75'}},
+                {value: data.code5 * 100, itemStyle: {color: '#91CC75'}},
+                {value: data.code6 * 100, itemStyle: {color: '#91CC75'}},
+                {value: data.code7 * 100, itemStyle: {color: '#91CC75'}},
+                {value: data.code8 * 100, itemStyle: {color: '#91CC75'}},
                 {value: data.code9 * 100, itemStyle: {color: '#91CC75'}},
               ],
+              // data: [
+              //   {value: data.code0 * 100, itemStyle: {color: '#5470C6'}},
+              //   {value: data.code1 * 100, itemStyle: {color: '#91CC75'}},
+              //   {value: data.code2 * 100, itemStyle: {color: '#FAC858'}},
+              //   {value: data.code3 * 100, itemStyle: {color: '#EE6666'}},
+              //   {value: data.code4 * 100, itemStyle: {color: '#73C0DE'}},
+              //   {value: data.code5 * 100, itemStyle: {color: '#3BA272'}},
+              //   {value: data.code6 * 100, itemStyle: {color: '#FC8452'}},
+              //   {value: data.code7 * 100, itemStyle: {color: '#9A60B4'}},
+              //   {value: data.code8 * 100, itemStyle: {color: '#5470C6'}},
+              //   {value: data.code9 * 100, itemStyle: {color: '#91CC75'}},
+              // ],
               type: 'bar',
             }
           ]