zf
2023-08-30 464fe41610a39c3a06f070d5a01c930134ff0163
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.gk.hotwork.Mapper.SafetySelfInspectionMapper" >
  <resultMap id="BaseResultMap" type="com.gk.hotwork.Domain.SafetySelfInspection" >
    <!--          -->
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="valid_flag" property="validFlag" jdbcType="TINYINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="create_by" property="createBy" jdbcType="VARCHAR" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="update_by" property="updateBy" jdbcType="VARCHAR" />
    <result column="checked_company_id" property="checkedCompanyId" jdbcType="BIGINT" />
    <result column="checked_company_name" property="checkedCompanyName" jdbcType="VARCHAR" />
 
    <result column="inspection_name" property="inspectionName" jdbcType="BIGINT" />
    <result column="inspection_time" property="inspectionTime" jdbcType="BIGINT" />
    <result column="inspector" property="inspector" jdbcType="BIGINT" />
    <result column="status" property="status" jdbcType="VARCHAR" />
    <result column="inspector_name" property="inspectorName" jdbcType="VARCHAR" />
 
  </resultMap>
  <select id="selectPages" resultMap="BaseResultMap">
    select a.*,
    b.realname inspector_name,c.roleid
    from safety_self_inspection as a
    left join user as b on a.inspector = b.id and b.isdel = 0
    LEFT JOIN userroles as c on b.id = c.userid
    left join company as co on a.checked_company_id = co.id
    where a.valid_flag = 1
    <if test="params.flag != null and params.flag != '' ">
      and a.flag = #{params.flag}
    </if>
    <if test="params.inspectionName != null  and params.inspectionName != ''">
      and a.inspection_name like concat("%",#{params.inspectionName},"%")
    </if>
    <if test="params.checkedCompanyId != null">
      and a.checked_company_id = #{params.checkedCompanyId}
    </if>
    <if test="params.checkedCompanyName != null and params.checkedCompanyName != ''">
      and a.checked_company_name like concat("%",#{params.checkedCompanyName},"%")
    </if>
    <if test="params.roleid != null ">
      and c.roleid = #{params.roleid}
    </if>
    <if test="params.inspectorName != null  and params.inspectorName != ''">
      and b.realname like concat("%",#{params.inspectorName},"%")
    </if>
    <if test="params.inspectionStartTime != null and params.inspectionStartTime != ''" >
      and a.inspection_time <![CDATA[ >= ]]> #{params.inspectionStartTime}
    </if>
    <if test="params.inspectionEndTime != null and params.inspectionEndTime != ''" >
      and a.inspection_time <![CDATA[ <= ]]> #{params.inspectionEndTime}
    </if>
    <if test="params.province != null and params.province != ''" >
      and co.province = #{params.province}
    </if>
    <if test="params.city != null and params.city != ''" >
      and co.city = #{params.city}
    </if>
    <if test="params.area != null and params.area != ''" >
      and co.area = #{params.area}
    </if>
    order by a.create_time desc
  </select>
  <select id="companyStatisticInspection" resultType="com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO">
    SELECT
      count( 1 ) checkCompanyCount,
      sum( l.endCount ) endTotal,
      sum( l.toDoCount ) toDoTotal,
      sum( l.checkCount ) checkTotal,
      sum( l.unRectifyCount ) unRectifyTotal,
      sum( l.rectifyCount ) rectifyTotal,
      sum( l.hdCount ) AS hdTotal
    FROM
      (
        SELECT
          s.checked_company_id,
          count( s.`status` = 2 OR NULL ) endCount,
          count( s.`status` = 1 OR NULL ) toDoCount,
          count( 1 ) AS checkCount,
          sum( t.unRectify ) AS unRectifyCount,
          sum( t.rectify ) AS rectifyCount,
          sum( t.hd ) AS hdCount
        FROM
          safety_self_inspection s
            INNER JOIN company c ON c.id = s.checked_company_id
            LEFT JOIN (
            SELECT
              h.self_Inspection_id,
              count( h.`status` = - 1 OR NULL ) unRectify,
              count( h.`status` = 1 OR NULL ) rectify,
              count( 1 ) hd
            FROM
              inspection_hidden_danger h
            WHERE
              h.valid_flag = 1
            GROUP BY
              h.self_Inspection_id
          ) t ON t.self_Inspection_id = s.id
        WHERE
          s.valid_flag = 1
          AND s.flag = 2
          <if test="params.startTime != null" >
            and s.inspection_time <![CDATA[ >= ]]> #{params.startTime}
          </if>
          <if test="params.endTime != null " >
            and s.inspection_time <![CDATA[ <= ]]> #{params.endTime}
          </if>
          <if test="params.province != null and params.province != ''" >
            and c.province = #{params.province}
          </if>
          <if test="params.city != null and params.city != ''" >
            and c.city = #{params.city}
          </if>
          <if test="params.area != null and params.area != ''" >
            and c.area = #{params.area}
          </if>
        GROUP BY
          s.checked_company_id
      ) l
  </select>
</mapper>