Browse Source

异常统计

孙伟 3 years ago
parent
commit
7f8588e831

+ 3 - 0
application-facade/src/main/java/com/factory/wx/entity/req/AbnormalDetailReq.java

@@ -24,4 +24,7 @@ public class AbnormalDetailReq {
 
     @ApiModelProperty(value = "计划类型 1首件 2防错")
     private Long checkType;
+
+    @ApiModelProperty(value = "异常类型")
+    private Integer abnormalType;
 }

+ 24 - 0
application-facade/src/main/java/com/factory/wx/mapper/AbnormalStatisticsMapper.java

@@ -1,10 +1,14 @@
 package com.factory.wx.mapper;
 
+import com.factory.web.entity.pm.req.SearchAbnormalReq;
+import com.factory.web.entity.pm.res.AbnormalItemRes;
 import com.factory.web.entity.pm.res.AbnormalTaskInfoRes;
 import com.factory.wx.entity.req.AbnormalPlanReq;
 import com.factory.wx.entity.res.AbnormalPlanRes;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -44,4 +48,24 @@ public interface AbnormalStatisticsMapper {
      * @return
      */
     List<AbnormalTaskInfoRes> getPmReleaseListByPlanId(Long planId);
+
+    /**
+     * 根据计划id获取首件重检
+     *
+     * @param planId
+     * @return
+     */
+    List<AbnormalTaskInfoRes> getFaRecheckedListByPlanId(Long planId);
+
+    /**
+     * 根据计划id获取防错重检
+     *
+     * @param planId
+     * @return
+     */
+    List<AbnormalTaskInfoRes> getPmRecheckedListByPlanId(Long planId);
+
+    List<AbnormalItemRes> getPmAbnormalItemResultList(@Param("req") SearchAbnormalReq searchReq);
+
+    List<AbnormalItemRes> getFaAbnormalItemResultList(@Param("req") SearchAbnormalReq searchReq);
 }

+ 59 - 40
application-facade/src/main/java/com/factory/wx/service/impl/AbnormalStatisticsServiceImpl.java

@@ -75,34 +75,17 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
         abnormalPlanReq.setMonth(month);
 
         List<AbnormalPlanRes> releasedAbnormalPlans = new ArrayList<>();
-        //已放行
-        if (abnormalPlanReq.getAbnormalType() == 2) {
-            releasedAbnormalPlans.addAll(abnormalStatisticsMapper.getReleasedAbnormalPlans(abnormalPlanReq));
-        }
         //已重检
         if (abnormalPlanReq.getAbnormalType() == 1) {
             releasedAbnormalPlans.addAll(abnormalStatisticsMapper.getRecheckedAbnormalPlans(abnormalPlanReq));
         }
+        //已放行
+        if (abnormalPlanReq.getAbnormalType() == 2) {
+            releasedAbnormalPlans.addAll(abnormalStatisticsMapper.getReleasedAbnormalPlans(abnormalPlanReq));
+        }
         return releasedAbnormalPlans;
     }
 
-    /**
-     * 取得检查结果
-     *
-     * @param taskId
-     * @param itemId
-     * @param typeFlag 0表示首件 1表示200件 2表示中断
-     * @return 检查结果
-     */
-    private List<AbnormalItemResultRes> getAbnormalItemResultList(long taskId, long itemId, int typeFlag) {
-        SearchAbnormalReq searchReq = new SearchAbnormalReq();
-        searchReq.setTaskId(taskId);
-        searchReq.setItemId(itemId);
-        searchReq.setTypeFlag(typeFlag);
-        List<AbnormalItemResultRes> abnormalItemResultList = preventMistakeMapper.getFaAbnormalItemResultList(searchReq);
-        return abnormalItemResultList;
-    }
-
     /**
      * 异常放行详情
      *
@@ -116,14 +99,17 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
         abnormalDetailRes.setPlanId(bentelerPlan.getId());
         abnormalDetailRes.setPlanName(bentelerPlan.getName());
 
-        //获取title
         if (abnormalDetailReq.getCheckType() == 1) {
+            //获取title
             FirstArticleTitle title = firstArticleService.getFaTitle(abnormalDetailReq.getPlanId());
             //判断是否有附件
             int attrCount = fileMapper.selectCount(Wrappers.<FileEntry>lambdaQuery()
                     .eq(FileEntry::getId, title.getUploadAttachmentId()));
             abnormalDetailRes.setFirstArticleTitle(title);
             abnormalDetailRes.setAttachment(attrCount == 0 ? 0 : 1);
+            //取放行信息
+            List<AbnormalTaskInfoRes> abnormalTaskInfoResList = getFaAbnormalTaskInfoRes(abnormalDetailReq);
+            abnormalDetailRes.setAbnormalTaskInfos(abnormalTaskInfoResList);
         }
         if (abnormalDetailReq.getCheckType() == 2) {
             //获取title
@@ -133,15 +119,8 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
                     .eq(FileEntry::getId, title.getUploadAttachmentId()));
             abnormalDetailRes.setTitleInfo(title);
             abnormalDetailRes.setAttachment(attrCount == 0 ? 0 : 1);
-        }
-
-        //取放行信息
-        if (abnormalDetailReq.getCheckType() == 1) {
-            List<AbnormalTaskInfoRes> abnormalTaskInfoResList = getFaAbnormalTaskInfoRes(abnormalDetailReq.getPlanId());
-            abnormalDetailRes.setAbnormalTaskInfos(abnormalTaskInfoResList);
-        }
-        if (abnormalDetailReq.getCheckType() == 2) {
-            List<AbnormalTaskInfoRes> abnormalTaskInfoResList = getPMAbnormalTaskInfoRes(abnormalDetailReq.getPlanId());
+            //取放行信息
+            List<AbnormalTaskInfoRes> abnormalTaskInfoResList = getPMAbnormalTaskInfoRes(abnormalDetailReq);
             abnormalDetailRes.setAbnormalTaskInfos(abnormalTaskInfoResList);
         }
 
@@ -151,11 +130,19 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
     /**
      * 获取首件放行信息
      *
-     * @param planId
+     * @param abnormalDetailReq
      * @return
      */
-    private List<AbnormalTaskInfoRes> getFaAbnormalTaskInfoRes(Long planId) {
-        List<AbnormalTaskInfoRes> faList = abnormalStatisticsMapper.getFaReleaseListByPlanId(planId);
+    private List<AbnormalTaskInfoRes> getFaAbnormalTaskInfoRes(AbnormalDetailReq abnormalDetailReq) {
+        List<AbnormalTaskInfoRes> faList = new ArrayList<>();
+        if (abnormalDetailReq.getAbnormalType() == 1) {
+            //重检内容
+            faList = abnormalStatisticsMapper.getFaRecheckedListByPlanId(abnormalDetailReq.getPlanId());
+        }
+        if (abnormalDetailReq.getAbnormalType() == 2) {
+            //放行内容
+            faList = abnormalStatisticsMapper.getFaReleaseListByPlanId(abnormalDetailReq.getPlanId());
+        }
 
         for (AbnormalTaskInfoRes faInfo : faList) {
             List<FirstArticleWorkshop> firstArticleWorkshopList = firstArticleWorkshopService.list(Wrappers.<FirstArticleWorkshop>lambdaQuery()
@@ -174,9 +161,15 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
 
                 SearchAbnormalReq searchReq = new SearchAbnormalReq();
                 searchReq.setWorkshopId(abnormalWorkshopList.get(i).getWorkshopId());
-                List<AbnormalItemRes> abnormalItemList = preventMistakeMapper.getFaAbnormalItemList(searchReq);
+                List<AbnormalItemRes> abnormalItemList = abnormalStatisticsMapper.getFaAbnormalItemResultList(searchReq);
 
                 for (AbnormalItemRes abnormalItemInfo : abnormalItemList) {
+
+                    Long userId = abnormalItemInfo.getItemResultUserId();
+                    if (null != userId) {
+                        String userName = wxPlanService.getUserNameById(abnormalItemInfo.getItemResultUserId());
+                        abnormalItemInfo.setItemResultUser(userName);
+                    }
                     List<AbnormalItemResultRes> firstItemResultList = this.getAbnormalItemResultList(faInfo.getTaskId(), abnormalItemInfo.getItemId(), 0);
                     abnormalItemInfo.setFirstItemResultList(firstItemResultList);
 
@@ -188,7 +181,7 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
                 }
 
                 abnormalWorkshopList.get(i).setAbnormalItemList(abnormalItemList);
-                faInfo.setAbnormalWorkshopList(abnormalWorkshopList);
+                faInfo.setAbnormalWorkshopList(abnormalWorkshopList.stream().filter(workshop -> null != workshop.getAbnormalItemList() && workshop.getAbnormalItemList().size() > 0).collect(Collectors.toList()));
             }
         }
         return faList;
@@ -197,11 +190,20 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
     /**
      * 获取防错放行信息
      *
-     * @param planId
+     * @param abnormalDetailReq
      * @return
      */
-    private List<AbnormalTaskInfoRes> getPMAbnormalTaskInfoRes(Long planId) {
-        List<AbnormalTaskInfoRes> pmList = abnormalStatisticsMapper.getPmReleaseListByPlanId(planId);
+    private List<AbnormalTaskInfoRes> getPMAbnormalTaskInfoRes(AbnormalDetailReq abnormalDetailReq) {
+        List<AbnormalTaskInfoRes> pmList = new ArrayList<>();
+        if (abnormalDetailReq.getAbnormalType() == 1) {
+            //重检内容
+            pmList = abnormalStatisticsMapper.getPmRecheckedListByPlanId(abnormalDetailReq.getPlanId());
+        }
+        if (abnormalDetailReq.getAbnormalType() == 2) {
+            //放行内容
+            pmList = abnormalStatisticsMapper.getPmReleaseListByPlanId(abnormalDetailReq.getPlanId());
+        }
+
         for (AbnormalTaskInfoRes pmInfo : pmList) {
             List<OnsiteWorkshop> onsiteWorkshopList = onsiteWorkshopService.list(Wrappers.<OnsiteWorkshop>lambdaQuery()
                     .eq(OnsiteWorkshop::getBentelerPlanId, pmInfo.getBentelerPlanId()));
@@ -219,7 +221,7 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
                 SearchAbnormalReq searchReq = new SearchAbnormalReq();
                 searchReq.setWorkshopId(abnormalWorkshopList.get(i).getWorkshopId());
                 searchReq.setTaskId(pmInfo.getTaskId());
-                List<AbnormalItemRes> abnormalItemList = preventMistakeMapper.getPmAbnormalItemList(searchReq).stream().filter(abnormalItemRes -> abnormalItemRes.getResult() > 0).collect(Collectors.toList());
+                List<AbnormalItemRes> abnormalItemList = abnormalStatisticsMapper.getPmAbnormalItemResultList(searchReq).stream().filter(abnormalItemRes -> abnormalItemRes.getResult() > 0).collect(Collectors.toList());
                 for (AbnormalItemRes abnormalItemRes : abnormalItemList) {
                     Long userId = abnormalItemRes.getItemResultUserId();
                     if (null != userId) {
@@ -235,6 +237,23 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
         return pmList;
     }
 
+    /**
+     * 取得检查结果
+     *
+     * @param taskId
+     * @param itemId
+     * @param typeFlag 0表示首件 1表示200件 2表示中断
+     * @return 检查结果
+     */
+    private List<AbnormalItemResultRes> getAbnormalItemResultList(long taskId, long itemId, int typeFlag) {
+        SearchAbnormalReq searchReq = new SearchAbnormalReq();
+        searchReq.setTaskId(taskId);
+        searchReq.setItemId(itemId);
+        searchReq.setTypeFlag(typeFlag);
+        List<AbnormalItemResultRes> abnormalItemResultList = preventMistakeMapper.getFaAbnormalItemResultList(searchReq);
+        return abnormalItemResultList;
+    }
+
     /**
      * 验证日期格式
      *

+ 153 - 30
application-facade/src/main/resources/mapper/AbnormalStatisticsMapper.xml

@@ -8,75 +8,101 @@
         SELECT DISTINCT
             bp.id AS plan_id,
             bp.`name` AS plan_name,
-            bp.plan_type
+            bp.plan_type,
+            2 AS abnormal_type
         FROM
             onsite_task ot,
             onsite_calendar oc,
+            onsite_approval_task oat,
             benteler_plan bp
         WHERE
             ot.onsite_calendar_id = oc.id
             AND oc.benteler_plan_id = bp.id
+            AND ot.id = oat.onsite_task_id
             AND ot.`status` = 2
-            <if test="name != ''">
+            AND oat.`status` = 1
+        <if test="name != ''">
                 AND bp.`name` LIKE CONCAT('%',#{name},'%')
-            </if>
-            AND ot.task_time LIKE CONCAT(#{month},'%')
+        </if>
+        AND ot.task_time LIKE CONCAT(#{month},'%')
         UNION
         SELECT DISTINCT
             bp.id AS plan_id,
             bp.`name` AS plan_name,
-            bp.plan_type
+            bp.plan_type,
+            2 AS abnormal_type
         FROM
             first_article_task ot,
             first_article_calendar oc,
+            first_article_approval_task oat,
             benteler_plan bp
         WHERE
             ot.first_article_calendar_id = oc.id
             AND oc.benteler_plan_id = bp.id
+            AND ot.id = oat.first_article_task_id
             AND ot.`status` = 2
-            <if test="name != ''">
-                AND bp.`name` LIKE CONCAT('%',#{name},'%')
-            </if>
-            AND ot.task_time LIKE CONCAT(#{month},'%');
+            AND oat.`status` = 1
+        <if test="name != ''">
+            AND bp.`name` LIKE CONCAT('%',#{name},'%')
+        </if>
+        AND ot.task_time LIKE CONCAT(#{month},'%');
     </select>
     <!-- 获取重检异常计划列表 -->
     <select id="getRecheckedAbnormalPlans" parameterType="com.factory.wx.entity.req.AbnormalPlanReq"
             resultType="com.factory.wx.entity.res.AbnormalPlanRes">
         SELECT DISTINCT
-            bp.id AS plan_id,
+            oc.benteler_plan_id AS plan_id,
             bp.`name` AS plan_name,
-            bp.plan_type
+            bp.plan_type,
+            1 AS abnormal_type
         FROM
-            onsite_task_his_blob othb,
             onsite_task ot,
             onsite_calendar oc,
-            benteler_plan bp
+            benteler_plan bp,
+            (
+                SELECT DISTINCT
+                    othb.onsite_task_id
+                FROM
+                    onsite_task_his_blob othb,
+                    onsite_task ot
+                WHERE
+                    othb.onsite_task_id = ot.id
+            ) r
         WHERE
-            othb.onsite_task_id = ot.id
-          AND ot.onsite_calendar_id = oc.id
-          AND oc.benteler_plan_id = bp.id
-        <if test="name != ''">
-            AND bp.`name` LIKE CONCAT('%',#{name},'%')
-        </if>
-        AND ot.task_time LIKE CONCAT(#{month},'%')
+            ot.id = r.onsite_task_id
+            AND ot.onsite_calendar_id = oc.id
+            AND oc.benteler_plan_id = bp.id
+            <if test="name != ''">
+                AND bp.`name` LIKE CONCAT('%',#{name},'%')
+            </if>
+            AND ot.task_time LIKE CONCAT(#{month},'%')
         UNION
         SELECT DISTINCT
-            bp.id AS plan_id,
+            fac.benteler_plan_id AS plan_id,
             bp.`name` AS plan_name,
-            bp.plan_type
+            bp.plan_type,
+            1 AS abnormal_type
         FROM
-            first_article_task_his_blob othb,
-            first_article_task ot,
-            first_article_calendar oc,
-            benteler_plan bp
+            first_article_task fat,
+            first_article_calendar fac,
+            benteler_plan bp,
+            (
+                SELECT DISTINCT
+                    fathb.first_article_task_id
+                FROM
+                    first_article_task_his_blob fathb,
+                    first_article_task fat
+                WHERE
+                    fathb.first_article_task_id = fat.id
+            ) r
         WHERE
-            othb.first_article_task_id = ot.id
-          AND ot.first_article_calendar_id = oc.id
-          AND oc.benteler_plan_id = bp.id
+            fat.id = r.first_article_task_id
+            AND fat.first_article_calendar_id = fac.id
+            AND fac.benteler_plan_id = bp.id
         <if test="name != ''">
             AND bp.`name` LIKE CONCAT('%',#{name},'%')
         </if>
-        AND ot.task_time LIKE CONCAT(#{month},'%');
+        AND fat.task_time LIKE CONCAT(#{month},'%');
     </select>
 
     <!-- 取得防错放行 -->
@@ -131,5 +157,102 @@
           AND     fat.`status` = 2
           AND     bp.id = #{planId}
     </select>
+    <!-- 防错重检信息 -->
+    <select id="getPmRecheckedListByPlanId" resultType="com.factory.web.entity.pm.res.AbnormalTaskInfoRes">
+        SELECT  oc.benteler_plan_id,
+                bp.`name` AS benteler_plan_name,
+                bp.plan_type,
+                uu.username AS person,
+                2 AS method,
+                ot.`status`,
+                oc.type_flag,
+                ot.id AS task_id
+        FROM    onsite_task ot,
+                onsite_calendar oc,
+                benteler_plan bp,
+                us_user uu,
+                (
+                    SELECT DISTINCT othb.onsite_task_id
+                    FROM   onsite_task_his_blob othb,
+                           onsite_task ot
+                    WHERE  othb.onsite_task_id = ot.id
+                ) r
+        WHERE   ot.id = r.onsite_task_id
+          AND   ot.onsite_calendar_id = oc.id
+          AND   oc.benteler_plan_id = bp.id
+          AND   oc.user_id = uu.id
+          AND   bp.id = #{planId}
+    </select>
+    <!-- 首件重检信息 -->
+    <select id="getFaRecheckedListByPlanId" resultType="com.factory.web.entity.pm.res.AbnormalTaskInfoRes">
+        SELECT  fac.benteler_plan_id,
+                bp.`name` AS benteler_plan_name,
+                bp.plan_type,
+                uu.username AS person,
+                2 AS method,
+                fat.`status`,
+                fac.type_flag,
+                fat.id AS task_id
+        FROM    first_article_task fat,
+                first_article_calendar fac,
+                benteler_plan bp,
+                us_user uu,
+                (
+                    SELECT DISTINCT fathb.first_article_task_id
+                    FROM   first_article_task_his_blob fathb,
+                           first_article_task fat
+                    WHERE  fathb.first_article_task_id = fat.id
+                ) r
+        WHERE   fat.id = r.first_article_task_id
+          AND   fat.first_article_calendar_id = fac.id
+          AND   fac.benteler_plan_id = bp.id
+          AND   fac.user_id = uu.id
+          AND   bp.id = #{planId}
+    </select>
 
+    <!-- 取得防错工作站下的巡检项目和检查结果 -->
+    <select id="getPmAbnormalItemResultList" resultType="com.factory.web.entity.pm.res.AbnormalItemRes">
+        SELECT  oir.onsite_item_id AS item_id,
+                oi.item_content,
+                oir.result,
+                oir.abnormal,
+                oir.created_time AS item_result_create_time,
+                oir.created_user_id AS item_result_user_id
+        FROM    onsite_item_result oir,
+                onsite_item oi
+        WHERE   oir.onsite_item_id = oi.id
+          AND     oir.onsite_task_id = #{req.taskId}
+          AND     oi.workshop_id = #{req.workshopId}
+    </select>
+    <!-- 取得首件工作站下的巡检项目 -->
+    <select id="getFaAbnormalItemResultList" resultType="com.factory.web.entity.pm.res.AbnormalItemRes">
+        SELECT
+            fai.id AS item_id,
+            fai.item_content,
+            fai.item_standard,
+            fai.prefix,
+            fai.sno_start,
+            fai.sno_end,
+            fai.val_flag,
+            fai.val_up,
+            fai.val_down,
+            fai.val_ok,
+            fai.val_desc,
+            fai.level_info,
+            fai.product_info,
+            fai.tool_id,
+            fai.tool_desc,
+            fai.first_flag,
+            fai.two_hundred_flag,
+            fai.catch_flag,
+            fai.val_unit,
+            fair.created_time AS item_result_create_time,
+            fair.created_user_id AS item_result_user_id
+        FROM
+            first_article_item fai,
+            first_article_item_result fair
+        WHERE
+            fai.workshop_id = #{req.workshopId}
+        AND fai.id = fair.first_article_item_id
+    </select>
 </mapper>