DataStatisticsMapper.xml 17.6 KB
Newer Older
qinhu's avatar
qinhu committed
1 2 3 4 5
<?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="cn.wise.sc.cement.business.mapper.DataStatisticsMapper">

    <select id="countTeamByTime" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
竹天卫's avatar
竹天卫 committed
6
        SELECT  DATE_FORMAT(sd.create_time,'%Y-%m-%d') as name, count(sd.id) as value
qinhu's avatar
qinhu committed
7 8
        FROM sample_distribution sd
        where sd.finish_time is not null
竹天卫's avatar
竹天卫 committed
9 10 11 12 13 14 15 16 17
        <if test="params.cycle == 1 ">
            and YEARWEEK(date_format(sd.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        <if test="params.cycle == 2 ">
            and DATE_FORMAT( sd.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m')
        </if>
        <if test="params.cycle = 3 ">
            and YEAR(sd.create_time) = YEAR( NOW( ) )
        </if>
qinhu's avatar
qinhu committed
18 19 20 21 22 23
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(sd.create_time) &gt;= #{params.startDate}
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(sd.create_time) &lt;= #{params.endDate}
        </if>
竹天卫's avatar
竹天卫 committed
24
        <if test="params.startDate == null and params.endDate == null">
竹天卫's avatar
竹天卫 committed
25 26
            and date(sd.create_time)  > date_sub(curdate(),interval 30 day)
        </if>
qinhu's avatar
qinhu committed
27 28 29
        group by name
    </select>

竹天卫's avatar
竹天卫 committed
30

qinhu's avatar
qinhu committed
31 32 33 34 35
    <select id="countTeamByOrigin" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
        SELECT s.origin as name, count(sd.id) as value
        FROM sample_distribution sd
        left join sample s on s.id = sd.sample_id
        where sd.finish_time is not null
竹天卫's avatar
竹天卫 committed
36 37 38 39 40 41 42 43 44
        <if test="params.cycle == 1 ">
            and YEARWEEK(date_format(sd.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        <if test="params.cycle == 2 ">
            and DATE_FORMAT( sd.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m')
        </if>
        <if test="params.cycle == 3 ">
            and YEAR(sd.create_time) = YEAR( NOW( ) )
        </if>
竹天卫's avatar
竹天卫 committed
45 46
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(sd.create_time) &gt;= #{params.startDate}
qinhu's avatar
qinhu committed
47 48 49 50 51 52
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(sd.create_time) &lt;= #{params.endDate}
        </if>
        group by s.origin
    </select>
竹天卫's avatar
竹天卫 committed
53

竹天卫's avatar
竹天卫 committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    <select id="countEntrustSumNum" resultType="integer">
        SELECT count(*)
        FROM entrust e
        left join client c on c.id = e.client_id
        where e.status != 0 and e.project_type is not null
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(e.create_time) &gt;= #{params.startDate}
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(e.create_time) &lt;= #{params.endDate}
        </if>
        <if test="params.clientId != null">
            and e.clientId = #{clientId}
        </if>
        <if test="params.clientName != null and params.clientName != ''">
            and c.name like concat('%', #{params.clientName}, '%')
        </if>

    </select>

竹天卫's avatar
竹天卫 committed
74 75 76 77 78 79 80 81 82 83 84 85 86

    <select id="countEntrustStatus" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
        SELECT (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
竹天卫's avatar
竹天卫 committed
87
        WHEN 9 THEN '修改待确认'
竹天卫's avatar
竹天卫 committed
88 89 90 91 92
        ELSE ''
        END
        ) as name,
		count(*) as value
        FROM entrust e
竹天卫's avatar
竹天卫 committed
93
        left join client c on c.id = e.client_id
竹天卫's avatar
竹天卫 committed
94 95 96 97 98 99 100 101 102 103
        where e.status != 0 and e.project_type is not null
        <if test="params.cycle == 1 ">
            and YEARWEEK(date_format(e.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        <if test="params.cycle == 2 ">
            and DATE_FORMAT( e.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m')
        </if>
        <if test="params.cycle == 3 ">
            and YEAR(e.create_time) = YEAR( NOW( ) )
        </if>
竹天卫's avatar
竹天卫 committed
104 105
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(e.create_time) &gt;= #{params.startDate}
竹天卫's avatar
竹天卫 committed
106 107 108
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(e.create_time) &lt;= #{params.endDate}
竹天卫's avatar
竹天卫 committed
109 110 111 112 113 114
        </if>
        <if test="params.clientId != null">
            and e.clientId = #{clientId}
        </if>
        <if test="params.clientName != null and params.clientName != ''">
            and c.name like concat('%', #{params.clientName}, '%')
竹天卫's avatar
竹天卫 committed
115 116 117 118 119
        </if>
		group by e.status
    </select>

    <select id="countEntrustType" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
竹天卫's avatar
竹天卫 committed
120
       select e.project_type as name, count(*) as value
竹天卫's avatar
竹天卫 committed
121
        from entrust e
竹天卫's avatar
竹天卫 committed
122
        left join client c on c.id = e.client_id
竹天卫's avatar
竹天卫 committed
123 124 125 126 127 128 129 130 131 132
        where e.status != 0 and e.project_type is not null
        <if test="params.cycle == 1 ">
            and YEARWEEK(date_format(e.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        <if test="params.cycle == 2 ">
            and DATE_FORMAT( e.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m')
        </if>
        <if test="params.cycle == 3 ">
            and YEAR(e.create_time) = YEAR( NOW( ) )
        </if>
竹天卫's avatar
竹天卫 committed
133 134
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(e.create_time) &gt;= #{params.startDate}
竹天卫's avatar
竹天卫 committed
135 136 137 138
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(e.create_time) &lt;= #{params.endDate}
        </if>
竹天卫's avatar
竹天卫 committed
139 140 141 142 143 144
        <if test="params.clientId != null">
            and e.clientId = #{clientId}
        </if>
        <if test="params.clientName != null and params.clientName != ''">
            and c.name like concat('%', #{params.clientName}, '%')
        </if>
竹天卫's avatar
竹天卫 committed
145 146 147 148
        group by e.project_type
    </select>

    <select id="countEntrustPage" resultType="cn.wise.sc.cement.business.model.vo.EntrustVo">
竹天卫's avatar
竹天卫 committed
149
        select e.*, p.name as projectName, p.code as projectCode, c.name as clientName, su.name as userName,
竹天卫's avatar
竹天卫 committed
150 151 152 153 154 155 156 157 158 159 160
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
竹天卫's avatar
竹天卫 committed
161
        WHEN 9 THEN '修改待确认'
竹天卫's avatar
竹天卫 committed
162 163 164 165 166 167 168 169
        ELSE ''
        END
        ) as statusValue
        from entrust e
        left join project p on p.id = e.project_id
        left join client c on c.id = e.client_id
        left join sys_user su on su.id = e.user_id
        where e.status != 0 and e.project_type is not null
竹天卫's avatar
竹天卫 committed
170 171 172
        <if test="params.clientId != null">
            and e.clientId = #{clientId}
        </if>
竹天卫's avatar
竹天卫 committed
173 174 175
        <if test="params.clientName != null and params.clientName != ''">
            and c.name like concat('%', #{params.clientName}, '%')
        </if>
竹天卫's avatar
竹天卫 committed
176 177 178 179 180 181
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(e.create_time) &gt;= #{params.startDate}
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(e.create_time) &lt;= #{params.endDate}
        </if>
竹天卫's avatar
竹天卫 committed
182 183 184
        order by create_time desc
    </select>

竹天卫's avatar
竹天卫 committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    <select id="exportEntrustList" resultType="java.util.HashMap">
        SELECT
        (@i:=@i+1) as 序号,
        e.id as entrustId,
        IF(ISNULL(e.entrust_code),'',e.entrust_code) as 委托单号,
        IF(ISNULL(p.name),'',p.name) as 项目名称,
        IF(ISNULL(p.name),'',p.name)  as 项目编号,
        e.project_type as 项目类型,
        IF(ISNULL(su.name),'',su.name) as 委托人,
        IF(ISNULL(c.name),'',c.name) as 委托单位,
        IF(ISNULL(e.entrust_date),'',e.entrust_date)  as 委托日期,
        IF(ISNULL(e.sample_num),'',e.sample_num) as 样品数量,
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
        WHEN 9 THEN '修改待确认'
        ELSE ''
        END
        ) as 状态
        from entrust e
        left join project p on p.id = e.project_id
        left join client c on c.id = e.client_id
        left join sys_user su on su.id = e.user_id
        ,(select @i:=0)aa
        where e.status != 0 and e.project_type is not null
        <if test="params.clientId != null">
            and e.clientId = #{clientId}
        </if>
        <if test="params.clientName != null and params.clientName != ''">
            and c.name like concat('%', #{params.clientName}, '%')
        </if>
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(e.create_time) &gt;= #{params.startDate}
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(e.create_time) &lt;= #{params.endDate}
        </if>
        order by 序号
    </select>

竹天卫's avatar
竹天卫 committed
233 234

    <select id="countHandlePage" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
竹天卫's avatar
竹天卫 committed
235
       SELECT su.id as id, su.name as name, count(*) as value FROM sample_handle sh
竹天卫's avatar
竹天卫 committed
236
        left join sys_user su on su.id = sh.user_id
竹天卫's avatar
竹天卫 committed
237
        where sh.status = 1 or sh.status = 5
竹天卫's avatar
竹天卫 committed
238 239 240
        group by sh.user_id
    </select>

竹天卫's avatar
竹天卫 committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    <select id="countHandleWeek" resultType="integer">
       SELECT count(*)
        FROM sample_handle sh
        left join sys_user su on su.id = sh.user_id
        where (sh.status =2 or sh.status =4)
        <if test="userId != null ">
            and sh.user_id = #{userId}
        </if>
        <if test="weekType == 1 ">
            and YEARWEEK(date_format(sh.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())-1
        </if>
        <if test="weekType == 2 ">
            and YEARWEEK(date_format(sh.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        group by sh.user_id
    </select>


竹天卫's avatar
竹天卫 committed
259
    <select id="countDistributionPage" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
竹天卫's avatar
竹天卫 committed
260
       SELECT su.id as id, su.name as name, count(*) as value FROM sample_distribution sd
竹天卫's avatar
竹天卫 committed
261
        left join sys_user su on su.id = sd.user_id
竹天卫's avatar
竹天卫 committed
262
        where sd.status = 1 or sd.status = 5
竹天卫's avatar
竹天卫 committed
263 264 265
        group by sd.user_id
    </select>

竹天卫's avatar
竹天卫 committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

    <select id="countDistributionWeek" resultType="integer">
        SELECT count(*)
        FROM sample_distribution sd
        left join sys_user su on su.id = sd.user_id
        where (sd.status =2 or sd.status =4)
        <if test="userId != null ">
            and sd.user_id = #{userId}
        </if>
        <if test="weekType == 1 ">
            and YEARWEEK(date_format(sd.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())-1
        </if>
        <if test="weekType == 2 ">
            and YEARWEEK(date_format(sd.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        group by sd.user_id
    </select>



竹天卫's avatar
竹天卫 committed
286 287 288
    <select id="countTeamIng" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
       SELECT t.name as name, count(*) as value FROM sample_distribution sd
        left join team t on t.id = sd.team_id
竹天卫's avatar
竹天卫 committed
289
        where sd.status = 1  or sd.status = 5
竹天卫's avatar
竹天卫 committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
        group by sd.team_id
    </select>

    <select id="countTeam" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
       SELECT t.name as name, count(*) as value FROM sample_distribution sd
        left join team t on t.id = sd.team_id
        where 1=1
        <if test="params.cycle == 1 ">
            and YEARWEEK(date_format(sd.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        <if test="params.cycle == 2 ">
            and DATE_FORMAT( sd.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m')
        </if>
        <if test="params.cycle == 3 ">
            and YEAR(sd.create_time) = YEAR( NOW( ) )
        </if>
竹天卫's avatar
竹天卫 committed
306 307 308
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(sd.create_time) &gt;= #{params.startDate}
        </if>
竹天卫's avatar
竹天卫 committed
309 310 311
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(sd.create_time) &lt;= #{params.endDate}
        </if>
竹天卫's avatar
竹天卫 committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
        group by sd.team_id
    </select>

    <select id="countTeamPage" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsTeamVo">
        SELECT t.id as id, t.name as teamName, count(*) as teamNum FROM sample_distribution sd
        left join team t on t.id = sd.team_id
        where 1=1
        <if test="params.cycle == 1 ">
            and YEARWEEK(date_format(sd.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        <if test="params.cycle == 2 ">
            and DATE_FORMAT( sd.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m')
        </if>
        <if test="params.cycle == 3 ">
            and YEAR(sd.create_time) = YEAR( NOW( ) )
        </if>
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(sd.create_time) &gt;= #{params.startDate}
        </if>
竹天卫's avatar
竹天卫 committed
331 332 333 334 335 336
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(sd.create_time) &lt;= #{params.endDate}
        </if>
        group by sd.team_id
    </select>

竹天卫's avatar
竹天卫 committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
    <select id="exportTeamList" resultType="java.util.HashMap">
        SELECT (@i:=@i+1) as 序号,t.id as id, t.name as 检测项目, count(*) as 检测项数量
        FROM sample_distribution sd
        left join team t on t.id = sd.team_id
        ,(select @i:=0)t
        where 1=1
        <if test="params.cycle == 1 ">
            and YEARWEEK(date_format(sd.create_time,'%Y-%m-%d' ) ) = YEARWEEK(now())
        </if>
        <if test="params.cycle == 2 ">
            and DATE_FORMAT( sd.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m')
        </if>
        <if test="params.cycle == 3 ">
            and YEAR(sd.create_time) = YEAR( NOW( ) )
        </if>
        <if test="params.startDate != null and params.startDate != ''">
            and DATE(sd.create_time) &gt;= #{params.startDate}
        </if>
        <if test="params.endDate != null and params.endDate != ''">
            and DATE(sd.create_time) &lt;= #{params.endDate}
        </if>
        group by sd.team_id
        order by 序号
    </select>

竹天卫's avatar
竹天卫 committed
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
    <select id="countEntrustNum" resultType="integer">
        select count(*) as entrustNum  from (
            SELECT sd.entrust_id as id, count(*) as entrustNum FROM sample_distribution sd
            where sd.team_id = #{teamId}
            group by sd.entrust_id
        )aa
    </select>

    <select id="countSampleNum" resultType="integer">
        select count(*) as sampleNum  from (
            SELECT sd.sample_id as id, count(*) as entrustNum FROM sample_distribution sd
            where sd.team_id = #{teamId}
            group by sd.sample_id
        )aa
    </select>



    <select id="countByClient" resultType="cn.wise.sc.cement.business.model.vo.DataStatisticsVo">
        select c.name as name, count(*) as value   from entrust e
        left join client c on c.id = e.client_id
        group by e.client_id
竹天卫's avatar
竹天卫 committed
384 385 386
    </select>


qinhu's avatar
qinhu committed
387 388 389 390 391
    <select id="countItemDistributionSample"
            resultType="cn.wise.sc.cement.business.entity.ItemDistributionSample">
        SELECT COUNT(sd.team_id) as `count`,t.`name` FROM sample_distribution sd
        LEFT JOIN sample s ON sd.sample_id = s.id
        LEFT JOIN team t ON t.id = sd.team_id
竹天卫's avatar
竹天卫 committed
392 393 394 395
        WHERE 1=1
        <if test="start != null  and end != null">
            AND (sd.finish_time between #{start} and #{end})
        </if>
qinhu's avatar
qinhu committed
396 397 398
        <if test="origin != null and origin != '' ">
            AND s.origin = #{origin}
        </if>
竹天卫's avatar
竹天卫 committed
399
        <if test="teamId != '' and teamId != null ">
qinhu's avatar
qinhu committed
400 401 402
            AND sd.team_id = #{teamId}
        </if>
    </select>
竹天卫's avatar
竹天卫 committed
403

qinhu's avatar
qinhu committed
404 405 406 407 408 409
    <select id="countItemDistribution" resultType="cn.wise.sc.cement.business.entity.ItemDistribution">
        SELECT COUNT(a.sample_id) as `count`,`key` from
        (SELECT sd.team_id,sd.sample_id,t.`name`,sd.finish_time,CONCAT(sd.team_id,',',s.origin,',',s.is_foreign) as
        `key` FROM sample_distribution sd
        LEFT JOIN sample s ON sd.sample_id = s.id
        LEFT JOIN team t ON t.id = sd.team_id
竹天卫's avatar
竹天卫 committed
410 411 412 413
        WHERE 1=1
        <if test="start != null  and end != null">
          AND (sd.finish_time between #{start} and #{end})
        </if>
竹天卫's avatar
竹天卫 committed
414
        <if test="origins != null  and origins.size()>0">
qinhu's avatar
qinhu committed
415 416 417 418 419 420 421 422 423 424 425
            AND s.origin in
            <foreach collection="origins" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="itemId != null">
            AND sd.team_id = #{itemId}
        </if>
        ) a GROUP BY a.`key`
    </select>

竹天卫's avatar
竹天卫 committed
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
    <select id="exporItemDistributionList" resultType="java.util.HashMap">
        SELECT (@i:=@i+1) as 序号,
        COUNT(a.sample_id) as `count`,
        `key`
        from
        (SELECT sd.team_id,sd.sample_id,t.`name`,sd.finish_time,CONCAT(sd.team_id,',',s.origin,',',s.is_foreign) as
        `key` FROM sample_distribution sd
        LEFT JOIN sample s ON sd.sample_id = s.id
        LEFT JOIN team t ON t.id = sd.team_id
        ,(select @i:=0)t
        WHERE 1=1
        <if test="start != null  and end != null">
            AND (sd.finish_time between #{start} and #{end})
        </if>
        <if test="origins != null  and origins.size()>0">
            AND s.origin in
            <foreach collection="origins" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="itemId != null">
            AND sd.team_id = #{itemId}
        </if>
        ) a GROUP BY a.`key`
        order by 序号
    </select>
竹天卫's avatar
竹天卫 committed
452 453 454



qinhu's avatar
qinhu committed
455
</mapper>