WorkTimeOrderMapper.xml 25.6 KB
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 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 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
<?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.wisenergy.mapper.WorkTimeOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkTimeOrder">
        <id column="work_id" property="workId"/>
        <result column="user_id" property="userId"/>
        <result column="project_id" property="projectId"/>
        <result column="dept_id" property="deptId"/>
        <result column="work_time" property="workTime"/>
        <result column="work_day" property="workDay"/>
        <result column="status" property="status"/>
        <result column="reviewer_id" property="reviewerId"/>
        <result column="des" property="des"/>
        <result column="reason" property="reason"/>
        <result column="type" property="type"/>
        <result column="is_overtime" property="isOvertime"/>
        <result column="reject_time" property="rejectTime"/>
        <result column="create_time" property="createTime"/>
        <result column="modify_time" property="modifyTime"/>
    </resultMap>

    <resultMap id="userWorkTimeStatisticsByProject" type="cn.wisenergy.model.dto.UserWorkTimeStatisticsByProject">
        <result property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="userDeptName" column="dept_name"/>
        <collection property="projectWorkTimeAndType" ofType="cn.wisenergy.model.dto.ProjectWorkTimeAndType">
            <result property="projectId" column="project_id"/>
            <result property="workTimeType" column="work_time_type"/>
            <result property="projectName" column="project_name"/>
            <result property="overTime" column="over_time"/>
            <result property="normalTime" column="normal_time"/>
        </collection>
    </resultMap>

    <resultMap id="workTimeAndCostCollect" type="cn.wisenergy.model.dto.WorkTimeAndCostCollect">
        <result property="type" column="type"/>
        <result property="typeName" column="type_name"/>
        <collection property="deptProjectWorkTimeAndCosts" resultMap="deptProjectWorkTimeAndCosts">
        </collection>
    </resultMap>

    <resultMap id="deptProjectWorkTimeAndCosts" type="cn.wisenergy.model.dto.DeptProjectWorkTimeAndCost">
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
        <collection property="projectWorkTimeAndCostStatistics"
                    ofType="cn.wisenergy.model.dto.ProjectWorkTimeAndCostStatistics">
            <result property="projectId" column="project_id"/>
            <result property="projectName" column="project_name"/>
            <result property="statisticsTime" column="statistics_time"/>
            <result property="totalTime" column="total_time"/>
            <result property="cost" column="cost"/>
        </collection>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="vals">
       #{userId},#{projectId},#{deptId},#{workTime},#{workDay},#{status},#{reviewerId},#{des},#{reason},#{type},#{isOvertime},#{rejectTime},now(),#{modifyTime}
    </sql>
    <sql id="cols_exclude_id">
      user_id, project_id, dept_id, work_time, work_day, status, reviewer_id, des, reason, type, is_overtime,reject_time, create_time,modify_time
    </sql>

    <sql id="criteria">
        <if test="workId != null">and work_id = #{workId}</if>
        <if test="userId != null">and user_id = #{userId}</if>
        <if test="projectId != null">and project_id =#{projectId}</if>
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="workTime != null">and work_time = #{workTime}</if>
        <if test="workDay != null">and work_day = #{workDay}</if>
        <if test=" status != null">and `status` = #{status}</if>
        <if test=" reviewerId != null">and reviewer_id = #{reviewerId}</if>
        <if test="des != null">and des =#{des}</if>
        <if test="reason != null">and reason = #{reason}</if>
        <if test="type != null">and type = #{type}</if>
        <if test="isOvertime != null">and is_overtime = #{isOvertime}</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="rejectTime !=null">and reject_time = #{rejectTime}</if>
    </sql>

    <resultMap id="dayWorkTimeAndType" type="cn.wisenergy.model.dto.DayWorkTimeAndType">
        <result property="userId" column="user_id"/>
        <result property="day" column="day(work_day)"/>
        <result property="type" column="type"/>
        <result property="workTime" column="sum(work_time)"/>
    </resultMap>

    <resultMap id="monthlyWorkHourStatistics" type="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
        <result property="count" column="count(1)"/>
        <result property="workTime" column="sum(work_time)"/>
        <result property="projectType" column="id"/>
        <result property="typeName" column="name"/>
        <result property="approved" column="approved"/>
    </resultMap>

    <resultMap id="ProjectWorkTimeStatisticsDto" type="cn.wisenergy.model.dto.ProjectWorkTimeStatisticsDto">
        <result property="projectName" column="project_name"/>
        <result property="username" column="name"/>
        <!--<result property="userDept" column="user_dept"/>-->
        <result property="normalTime" column="normal_time"/>
        <result property="overTime" column="over_time"/>
    </resultMap>

    <sql id="table">
        work_time_order
    </sql>

    <insert id="save" keyProperty="workId" useGeneratedKeys="true">
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>

    <insert id="addManyLeaveOrder" useGeneratedKeys="true" keyProperty="workId">
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        values
        <foreach collection="workTimeOrders"  item="workTimeOrder" separator=",">
            (#{workTimeOrder.userId},
            null,#{workTimeOrder.deptId},#{workTimeOrder.workTime},#{workTimeOrder.workDay},
            #{workTimeOrder.status},null,#{workTimeOrder.des},null,#{workTimeOrder.type},#{workTimeOrder.isOvertime},
            null,#{workTimeOrder.createTime},#{workTimeOrder.modifyTime}
            )
        </foreach>
    </insert>


    <update id="updateByIds">
        UPDATE
        <include refid="table"/>
        SET status = 2,reviewer_id = #{reviewerId},modify_time = now()
        WHERE work_id IN
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>

    <update id="updateStatusById">
        UPDATE
        <include refid="table"/>
        SET status = 3,reason = #{reason},reviewer_id = #{reviewerId},modify_time=now(),reject_time=now()
        WHERE work_id = #{id}

    </update>
    <update id="updateAutoExamine">
        UPDATE
        <include refid="table"/>
        SET status = 5,modify_time=now()
        <where>work_id IN
            <foreach collection="workIds" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </where>
    </update>


    <select id="getByDay" resultType="cn.wisenergy.model.app.WorkTimeOrder" flushCache="true">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        <include refid="table"/>
        <where>
            <if test="null !=userId">
                <if test="null != userId">
                    AND user_id = #{userId}
                </if>
                <if test="null != workDay">
                    AND DATE_FORMAT(work_day, '%Y%m%d') = DATE_FORMAT(#{workDay} ,'%Y%m%d')
                </if>
            </if>
        </where>

    </select>
    <select id="queryByPage" resultType="cn.wisenergy.model.app.WorkTimeOrder">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        <include refid="table"/>
        <where>
            <if test="null != projectIds and projectIds.size()>0">
                AND project_id IN
                <foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
                    #{projectId}
                </foreach>
                <if test=" null != status and status.size()>0">
                    AND status IN
                    <foreach collection="status" item="sta" open="(" close=")" separator=",">
                        #{sta}
                    </foreach>
                </if>
            </if>
            <if test="null != types and types.size()>0">
                OR (type IN
                <foreach collection="types" item="type" open="(" close=")" separator=",">
                    #{type}
                </foreach>

                <if test=" null != deptId ">
                    AND dept_id = #{deptId}
                </if>
                <if test=" null != status and status.size()>0">
                    AND status in
                    <foreach collection="status" item="sta" open="(" close=")" separator=",">
                        #{sta}
                    </foreach>
                </if>
                )
            </if>
        </where>
        ORDER BY work_day DESC,create_time DESC
    </select>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        work_id, user_id, project_id,  dept_id, work_time, work_day, status, reviewer_id, des, reason, type, is_overtime, create_time, modify_time,reject_time
    </sql>

    <select id="statisticsByProjectType" resultMap="monthlyWorkHourStatistics">
        select ty.id AS id , ty.name AS name ,count(1),sum(work_time)
        from work_time_order t join work_type ty on t.type = ty.id
        where user_id = #{userId} AND work_day >= #{currentMonthFirstDay} AND t.status != 3
        group by type
        order by ty.sort
    </select>

    <select id="listByDateAndUserId" resultMap="dayWorkTimeAndType">
        select user_id,day(work_day),CASE when `type` = 3 then "请假" when `type` = 4 then "调休" else if(is_overtime = 0,"正常","加班") end AS `type`,
        sum(work_time)
        from
        <include refid="table"/>
        where year(work_day) = #{year} AND month(work_day) = #{month} AND (status = 2 OR status=5)AND user_id IN
        <foreach collection="userIds" separator="," close=")" item="userId" open="(">
            #{userId}
        </foreach>
        group by user_id,day(work_day), CASE when `type` = 3 then "请假" when `type` = 4 then "调休" else if(is_overtime = 0,"正常","加班") end
        order by day(work_day)
    </select>

    <select id="getCountByCondition" resultType="integer" parameterType="map">
        select count(1)
        from
        <include refid="table"/>
        <where>
            <include refid="criteria"/>
            <if test="startModifyTime != null">
                AND modify_time>=#{startModifyTime}
            </if>
            <if test="startWorkDay != null">
                AND work_day>=#{startWorkDay}
            </if>
            <if test="projectIdList != null">
                AND project_id IN
                <foreach collection="projectIdList" item="projectId" open="(" close=")" separator=",">
                    #{projectId}
                </foreach>
            </if>
            <if test="statusArray != null">
                AND `status` IN
                <foreach collection="statusArray" item="workStatus" open="(" close=")" separator=",">
                    #{workStatus}
                </foreach>
            </if>
            <if test="typeList != null">
                AND `type` IN
                <foreach collection="typeList" item="type" open="(" close=")" separator=",">
                    #{type}
                </foreach>
            </if>

        </where>
    </select>

    <select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect">
        SELECT t.type AS type, d.id AS dept_id,dept_name,
        IF (YEAR (work_day) &lt; YEAR (NOW()), concat(YEAR (work_day),'年',MONTH (work_day),'月') , concat(YEAR(work_day),
        '年')) AS statistics_time ,SUM(t.work_time)/8 AS
        total_time, SUM(t.work_time * s.day_salary)/8 AS cost,ty.sort AS ty_sort, d.sort AS d_sort
        FROM work_time_order t join work_dept d on d.id = t.dept_id join work_user_salary s on s.user_id = t.user_id join work_type ty on t.type = ty.id
        WHERE t.status IN (2,5) AND s.create_time &lt; t.work_day AND s.end_time > t.work_day AND year(t.work_day) &lt; year(NOW())
        <if test="firstDayOfMonth != null">
            AND work_day >= #{firstDayOfMonth}
        </if>
        <if test="deptId != null">
            AND t.dept_id = #{deptId}
        </if>
        AND t.type in
        <foreach collection="types" item="type" open="(" close=")" separator=",">
            #{type}
        </foreach>
        <if test="centreId != null">
            AND centre_id = #{centreId}
        </if>
        group by t.type,d.id, dept_name,year(work_day)

        union

        SELECT t.type AS type, d.id AS dept_id,dept_name,
        IF (YEAR (work_day) = YEAR (NOW()), concat(YEAR (work_day),'年',MONTH (work_day),'月') , concat(YEAR(work_day),
        '年')) AS statistics_time ,SUM(t.work_time)/8 AS
        total_time, SUM(t.work_time * s.day_salary)/8 AS cost,ty.sort AS ty_sort, d.sort AS d_sort
        FROM work_time_order t join work_dept d on d.id = t.dept_id join work_user_salary s on s.user_id = t.user_id join work_type ty on t.type = ty.id
        WHERE t.status IN (2,5) AND s.create_time &lt; t.work_day AND s.end_time > t.work_day AND year(t.work_day) = year(NOW())
        <if test="firstDayOfMonth != null">
            AND work_day >= #{firstDayOfMonth}
        </if>
        <if test="deptId != null">
            AND t.dept_id = #{deptId}
        </if>
        AND t.type in
        <foreach collection="types" item="type" open="(" close=")" separator=",">
            #{type}
        </foreach>
        <if test="centreId != null">
            AND centre_id = #{centreId}
        </if>
        group by t.type,d.id, dept_name,month(work_day)
        ORDER BY ty_sort, d_sort, statistics_time
    </select>

    <select id="getDaysByDateAndStatus" resultType="date">
        select distinct(work_day)
        from
        <include refid="table"/>
        where year(#{date}) = year(work_day) AND month(#{date}) = month(work_day) AND user_id = #{userId} AND status !=
        3
    </select>

    <select id="geByMonth" resultType="cn.wisenergy.model.app.WorkTimeOrder">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        <include refid="table"/>
        <where>
            <if test="null != userId">
                AND user_id = #{userId}
            </if>
            <if test="null != workMonth">
                AND DATE_FORMAT(work_day, '%Y%m') = DATE_FORMAT(#{workMonth} ,'%Y%m')
            </if>
            <if test="null != status">
                AND status = #{status}
            </if>
        </where>


    </select>
    <select id="getAutoOrder" resultType="cn.wisenergy.model.app.WorkTimeOrder">
        select
        <include refid="Base_Column_List"/>
        FROM
        <include refid="table"/>
        <where>
            status IN (1,4)
            AND TIMESTAMPDIFF(HOUR,create_time,now()) > #{autoExamine}
            AND TIMESTAMPDIFF(DAY,work_day,now()) > (#{autoExamine}/24)
        </where>
    </select>


    <select id="getUserProjectWorkTimeStatistics" resultMap="userWorkTimeStatisticsByProject">
        SELECT <if test="isAll">u.id AS user_id, u.`name` AS user_name, d.dept_name AS dept_name,</if>
        <if test="!isAll">'合计' AS user_name ,</if> t.project_id AS project_id, t.type AS work_time_type, p.project_name AS project_name,
        IF(t.is_overtime = 0, <if test="!isAll">0</if> <if test="isAll">null</if>, sum(t.work_time)) AS over_time,
        IF(t.is_overtime=1, <if test="!isAll">0</if><if test="isAll">null</if>, sum(t.work_time)) AS normal_time

        from work_time_order t left join work_project p on t.project_id = p.id join work_user u on t.user_id = u.id join work_type ty on t.type = ty.id join work_dept d on u.dept_id = d.id
        where
        t.status in (2,5) AND
        t.work_day &lt;= #{endDate}
        AND t.dept_id = #{deptId}
        <if test="startDate != null">
            AND t.work_day >= #{startDate}
        </if>
        GROUP BY <if test="isAll">u.id,u.`name`,d.dept_name,</if> t.project_id,t.type,p.project_name, t.is_overtime
        ORDER BY <if test="isAll">convert(u.`name` using gbk) asc</if>
        <if test="!isAll">ty.sort</if> ,t.project_id
    </select>

    <select id="selectCountByTypeAndStatus" resultType="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
        select type AS projectType, count(1) AS approved
        from
        <include refid="table"/>
        where user_id = #{userId} and work_day >= #{firstDayOfMonth} AND `type` is not null AND status in
        <foreach collection="status" open="(" close=")" separator="," item="s">
            #{s}
        </foreach>
        GROUP BY type
    </select>

    <select id="selectListByType" resultMap="userWorkTimeStatisticsByProject">
        SELECT <if test="isAll">u.id AS user_id, u.`name` AS user_name,</if>
        <if test="!isAll">'合计' AS user_name,</if> t.type AS work_time_type,
        IF(t.is_overtime = 0, <if test="!isAll">0</if>
        <if test="isAll">null</if>, sum(t.work_time)) AS over_time, IF(t.is_overtime=1, <if test="!isAll">0</if>
        <if test="isAll">null</if>, sum(t.work_time)) AS normal_time
        from work_time_order t JOIN work_user u ON t.user_id = u.id
        where
        t.work_day &lt;= #{endDate} AND t.status IN (2, 5)
        AND t.type in
        <foreach collection="queryType" item="type" open="(" close=")" separator=",">
            #{type}
        </foreach>
        <if test="startDate != null">
            AND t.work_day >= #{startDate}
        </if>
        AND user_id in (
        select user_id
        from work_project p JOIN work_user_project up ON p.id = up.project_id
        <if test="isConclusion != null">
            AND p.is_conclusion = #{isConclusion}
        </if>
        <if test="deptId != null and managerId == null">
            AND p.dept_id = #{deptId}
        </if>
        <if test="deptId != null and managerId != null">
            AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
        </if>
        <if test="managerId != null and deptId == null">
            AND p.manager_id = #{managerId}
        </if>
        )
        GROUP BY <if test="isAll">u.id,u.`name`,</if> t.type, t.is_overtime
    </select>

    <resultMap id="DeptUserCollectDto" type="cn.wisenergy.model.dto.DeptUserCollectDto">
        <result property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
        <result property="createTime" column="create_time"/>
        <collection property="workDay"
                    javaType="ArrayList"
                    ofType="java.util.Date">
            <result column="work_day"/>
        </collection>
    </resultMap>


    <select id="getDeptNotOrderInfo" resultMap="DeptUserCollectDto">
        select d.id as 'dept_id',d.dept_name,u.id as 'user_id',u.name as 'user_name',u.create_time,c.work_day
        from work_user u LEFT JOIN work_collect c ON u.id = c.user_id LEFT JOIN work_dept d on u.dept_id = d.id
        <where>
            u.submit_order = 1 and u.`status` = 1 and (c.`status` !=3 and c.total_time = 8
            <if test=" startDate !=null and endDate !=null">
                and c.work_day between #{startDate} and #{endDate}
            </if>
            <if test="depts !=null and depts.size()>0">
                AND d.id in
                <foreach collection="depts" item="dept" open="(" close=")" separator=",">
                    #{dept}
                </foreach>
            </if>
            ) or (c.work_day is null and u.submit_order = 1 and u.`status` = 1
            <if test="depts !=null and depts.size()>0">
                AND d.id in
                <foreach collection="depts" item="dept" open="(" close=")" separator=",">
                    #{dept}
                </foreach>
            </if>
            )

        </where>
        ORDER BY CONVERT( u.name USING gbk )
    </select>

    <select id="getProjectStatisticsDetail" resultMap="ProjectWorkTimeStatisticsDto">
        SELECT t1.project_name,t1.name,if(sum(normal_time/8) is null,0,sum(normal_time/8)) AS normal_time,if(sum(over_time/8) is null,0,sum(over_time/8)) AS over_time
        FROM (
        SELECT project_name,u.name,sum(t.work_time) AS normal_time
        FROM work_time_order t join work_user u on t.user_id = u.id
        join work_project p on t.project_id = p.id
        join work_type ty on t.type = ty.id
        WHERE t.status in(2,5) AND is_overtime = 0 AND t.work_day>=#{startDate} AND t.work_day &lt;=#{endDate}
            <if test="userId != null and deptId == null">
            AND p.manager_id = #{userId}
              </if>
              <if test="deptId != null and userId == null">
                  AND p.dept_id = #{deptId}
              </if>
              <if test="deptId != null and userId != null">
                  AND (p.manager_id = #{userId} OR p.dept_id = #{deptId})
              </if>
              GROUP BY project_name,u.`name`
        ) t1 left join (
        SELECT project_name,u.name,sum(t.work_time) AS over_time
        FROM work_time_order t join work_user u on t.user_id = u.id
              join work_project p on t.project_id = p.id
              join work_type ty on t.type = ty.id
        WHERE t.status in(2,5) AND is_overtime = 1 AND t.work_day>=#{startDate} AND t.work_day &lt;=#{endDate}
              <if test="userId != null and deptId == null">
                  AND p.manager_id = #{userId}
              </if>
              <if test="deptId != null and userId == null">
                  AND p.dept_id = #{deptId}
              </if>
              <if test="deptId != null and userId != null">
                  AND (p.manager_id = #{userId} OR p.dept_id = #{deptId})
              </if>
              GROUP BY project_name,u.`name`
        ) t2 on t1.project_name = t2.project_name and t1.name = t2.name
        GROUP BY t1.project_name,t1.`name`
        ORDER BY CONVERT (t1.project_name USING gbk),CONVERT (t1. NAME USING gbk)
    </select>

    <select id="getOrderChangePage" resultType="cn.wisenergy.model.dto.OrderChangePageDto">
        select o.work_id,o.project_id,p.project_name,u.name 'user_name',o.work_day,
        o.work_time,t.name 'type_name',o.des,o.status
        from work_time_order o LEFT JOIN work_type t on o.type = t.id
        LEFT JOIN work_user u on o.user_id = u.id
        LEFT JOIN work_project p on o.project_id = p.id
        <where>
            <if test="projectIds !=null and projectIds.size()>0">
                AND o.project_id IN
                <foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
                    #{projectId}
                </foreach>

            <if test="startDate !=null">
                AND o.work_day >= #{startDate}
            </if>
            <if test="endDate !=null">
                AND o.work_day &lt;= #{endDate}
            </if>
            <if test="userName !=null">
                AND (u.name like concat('%',#{userName},'%') or
                p.project_name like concat('%',#{userName},'%'))
            </if>
            </if>
            <if test="types !=null and types.size()>0 ">
                OR (o.type IN <foreach collection="types" item="type" open="(" close=")" separator=",">
                    #{type}
            </foreach>
                <if test="deptIds !=null and deptIds.size()>0">
                    AND o.dept_id IN<foreach collection="deptIds" item="deptId" open="(" close=")" separator=",">
                    #{deptId}
                </foreach>
                </if>
                <if test="startDate !=null">
                    AND o.work_day >= #{startDate}
                </if>
                <if test="endDate !=null">
                    AND o.work_day &lt;= #{endDate}
                </if>
                <if test="userName !=null">
                    AND (u.name like concat('%',#{userName},'%') or
                         p.project_name like concat('%',#{userName},'%'))
                </if>
                )
            </if>

        </where>
        ORDER BY  o.work_day desc, o.create_time desc
    </select>

    <select id="countByWorkDay" resultType="java.lang.Integer">
      SELECT COUNT(1)
      FROM work_time_order
      WHERE work_day >= #{startDate} AND work_day &lt;= #{enbDate} AND user_id = #{userId}
    </select>

    <select id="selectPeojectNumbers" resultMap="BaseResultMap" parameterType="map">
        select project_id,user_id,`type`
        from work_time_order
        <where>
        <if test="deptId !=null">
            dept_id =#{deptId}
        </if>
            AND type IN (1,2)
         <if test="userId !=null">
             AND user_id=#{userId}
         </if>
            <if test="startDate !=null">
                AND work_day >= #{startDate}
            </if>
            <if test="endDate !=null">
                AND work_day &lt;= #{endDate}
            </if>
        </where>
        GROUP BY project_id,user_id
    </select>

    <select id="getIsOvertime" resultMap="BaseResultMap" parameterType="map">
        select project_id,user_id,`type`,is_overtime
        from work_time_order
        <where>
            <if test="deptId !=null">
                dept_id =#{deptId}
            </if>
            AND year(work_day) = #{year} AND month(work_day) = #{month} AND (status = 2 OR status=5)
            <if test="userId !=null">
                AND user_id=#{userId}
            </if>
        </where>
        group by day(work_day),is_overtime
    </select>
</mapper>