<?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.usky.iot.mapper.PmWorkContentMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.iot.domain.PmWorkContent">
        <id column="id" property="id"/>
        <result column="report_id" property="reportId"/>
        <result column="project_id" property="projectId"/>
        <result column="project_name" property="projectName"/>
        <result column="submitter_id" property="submitterId"/>
        <result column="work_content" property="workContent"/>
        <result column="work_time" property="workTime"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="dept_id" property="deptId"/>
        <result column="tenant_id" property="tenantId"/>
    </resultMap>
    <select id="workTimeCount" resultType="com.usky.iot.service.vo.PmProjectWorkTimeVo">
    SELECT pc.project_name, SUM(pc.work_time) as workTime
    FROM pm_work_content pc
    JOIN pm_work_report pr ON pc.report_id = pr.id
    WHERE pr.submitter_id = #{userId}
    AND pr.report_date BETWEEN #{startTime} AND #{endTime}
    GROUP BY pc.project_name
    </select>

    <select id="workHoursStatistics" resultType="com.usky.iot.service.vo.WorkHoursStatisticsVO">
        SELECT u.nick_name as nickName, pc.project_name as projectName, SUM(pc.work_time) as workTime
        FROM pm_work_content pc
        JOIN pm_work_report pr ON pc.report_id = pr.id
        JOIN sys_user u ON pc.submitter_id = u.user_id
        <if test="userId != null and userId != '' and userId != 0 ">
            AND pr.submitter_id = #{userId}
        </if>
        AND pr.report_date BETWEEN #{startTime} AND #{endTime}
        AND pc.tenant_id = #{tenantId}
        GROUP BY u.nick_name, pc.project_name
    </select>

    <select id="statisticsDept" resultType="com.usky.iot.service.vo.WorkHoursStatisticsVO">
        SELECT u.nick_name as nickName, pc.project_name as projectName, SUM(pc.work_time) as workTime
        FROM pm_work_content pc
        JOIN pm_work_report pr ON pc.report_id = pr.id
        JOIN sys_user u ON pc.submitter_id = u.user_id
        <if test="userId != null and userId != '' and userId != 0 ">
            AND pr.submitter_id = #{userId}
        </if>
        AND pc.tenant_id = #{tenantId}
        AND pc.dept_id = #{deptId}
        AND pr.report_date BETWEEN #{startTime} AND #{endTime}
        GROUP BY u.nick_name, pc.project_name
    </select>

</mapper>
