郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
<?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.ReserveMapper" >
  <resultMap id="BaseResultMap" type="com.gk.hotwork.Domain.Reserve" >
    <!--          -->
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="space" property="space" jdbcType="INTEGER" />
    <result column="hoisting" property="hoisting" jdbcType="INTEGER" />
    <result column="soild" property="soild" jdbcType="INTEGER" />
    <result column="breaks" property="breaks" jdbcType="INTEGER" />
    <result column="high" property="high" jdbcType="INTEGER" />
    <result column="electricity" property="electricity" jdbcType="INTEGER" />
    <result column="blindboard" property="blindboard" jdbcType="INTEGER" />
    <result column="fire" property="fire" jdbcType="INTEGER" />
    <result column="appointment" property="appointment" jdbcType="TIMESTAMP" />
    <result column="createtime" property="createtime" jdbcType="TIMESTAMP" />
    <result column="updatetime" property="updatetime" jdbcType="TIMESTAMP" />
    <result column="validflag" property="validflag" jdbcType="TINYINT" />
    <result column="createby" property="createby" jdbcType="BIGINT" />
    <result column="createbyname" property="createbyname" jdbcType="VARCHAR" />
    <result column="updatebyname" property="updatebyname" jdbcType="VARCHAR" />
    <result column="createbydepartment" property="createbydepartment" jdbcType="VARCHAR" />
 
  </resultMap>
  <sql id="Base_Column_List" >
    <!--          -->
    id, space, hoisting, soild, breaks, high, electricity, blindboard, fire, appointment,
    createtime, updatetime, validflag, createby, createbyname, updatebyname,createbydepartment
  </sql>
  <select id="statistics" resultType="java.util.Map">
 
    select
    department.department,
    ifnull(reserve.space,0) space,
    ifnull(reserve.hoisting,0) hoisting,
    ifnull(reserve.soild,0) soild,
    ifnull(reserve.breaks,0) breaks,
    ifnull(reserve.high,0) high,
    ifnull(reserve.electricity,0) electricity,
    ifnull(reserve.blindboard,0) blindboard,
    ifnull(reserve.fire,0) fire,
    date_format(reserve.appointment,"%Y-%m-%d") appointment
    from reserve as reserve
    right join (
      select d.department
      from department as d
      where d.isdel = 0
      <if test="params.department != null and params.department != ''">
        and d.department =  #{params.department}
      </if>
    ) as department on department.department = reserve.createbydepartment
    where reserve.validflag = 1
    <if test="params.appointment != null and params.appointment != ''">
      and date(reserve.appointment)  = date(#{params.appointment})
    </if>
 
 
 
 
  </select>
  <select id="selectStatisticsTotal" resultType="java.util.Map">
 
 
      select
      count(0) department,
      sum(reserve.space) space,
      sum(reserve.hoisting) hoisting,
      sum(reserve.soild) soild,
      sum(reserve.breaks) breaks,
      sum(reserve.high) high,
      sum(reserve.electricity) electricity,
      sum(reserve.blindboard) blindboard,
      sum(reserve.fire) fire
      from (
      select
      reserve.createbydepartment ,
      sum(reserve.space) space,
      sum(reserve.hoisting) hoisting,
      sum(reserve.soild) soild,
      sum(reserve.breaks) breaks,
      sum(reserve.high) high,
      sum(reserve.electricity) electricity,
      sum(reserve.blindboard) blindboard,
      sum(reserve.fire) fire
      from reserve as reserve
      where reserve.validflag = 1
      <if test="params.appointment != null and params.appointment != ''">
          and date(reserve.appointment)  = date(#{params.appointment})
      </if>
      <if test="params.department != null and params.department != ''">
          and reserve.createbydepartment =  #{params.department}
      </if>
      group by reserve.createbydepartment) as reserve
 
 
 
  </select>
 
</mapper>