WorkTimeOrderMapper.xml 8.02 KB
Newer Older
nie'hong's avatar
nie'hong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?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="create_time" property="createTime" />
        <result column="modify_time" property="modifyTime" />
    </resultMap>

nie'hong's avatar
nie'hong committed
23

cq990612's avatar
cq990612 committed
24 25
    <!-- 通用查询结果列 -->
    <sql id="vals">
26
       #{userId},#{projectId},#{deptId},#{workTime},#{workDay},#{status},#{reviewerId},#{des},#{reason},#{type},#{isOvertime},now(),now()
cq990612's avatar
cq990612 committed
27 28
    </sql>
    <sql id="cols_exclude_id">
29
      user_id, project_id, dept_id, work_time, work_day, status, reviewer_id, des, reason, type, is_overtime, create_time, modify_time
nie'hong's avatar
nie'hong committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    </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="modifyTime != null">and #{modifyTime} &gt;= modify_time</if>
    </sql>

cq990612's avatar
cq990612 committed
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
    <resultMap id="dayWorkTimeAndType" type="cn.wisenergy.model.dto.DayWorkTimeAndType">
        <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)"/>
    </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>

    <update id="updateByIds">
        UPDATE
        <include refid="table"/>
        SET status = 2,reviewer_id = #{reviewerId}
        WHERE work_id IN
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>
nie'hong's avatar
nie'hong committed
82

cq990612's avatar
cq990612 committed
83 84 85 86 87 88
    <update id="updateStatusById">
        UPDATE
        <include refid="table"/>
        SET status = 3,reason = #{reason},reviewer_id = #{reviewerId},modify_time=now()
        WHERE work_id = #{id}
    </update>
cq990612's avatar
cq990612 committed
89 90 91 92 93 94 95
    <update id="updateToNull">
        UPDATE
        <include refid="table"/>
        SET project_id=null,dept_id=null,des=null,reason=null,reviewer_id=null,modify_time=now()
        WHERE work_id = #{workId}

    </update>
cq990612's avatar
cq990612 committed
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


    <select id="getByDay" resultType="cn.wisenergy.model.app.WorkTimeOrder">
        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 != projectId">
            AND   project_id = #{projectId}
            </if>
            <if test="null != status">
            AND status = #{status}
            </if>
            <if test="null != types">
            AND type IN
            <foreach collection="types" item="type" open="(" close=")" separator=",">
                #{type}
            </foreach>
            </if>
        </where>
cq990612's avatar
cq990612 committed
132
        ORDER BY work_day DESC
cq990612's avatar
cq990612 committed
133
    </select>
nie'hong's avatar
nie'hong committed
134 135 136

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
137
        work_id, user_id, project_id,  dept_id, work_time, work_day, status, reviewer_id, des, reason, type, is_overtime, create_time, modify_time
nie'hong's avatar
nie'hong committed
138 139
    </sql>

nie'hong's avatar
nie'hong committed
140 141
    <select id="statisticsByProjectType" resultMap="monthlyWorkHourStatistics">
        select count(1),sum(work_time)
nie'hong's avatar
nie'hong committed
142 143 144 145 146 147 148 149 150 151 152
        from <include refid="table"/>
        where user_id = #{userId} AND type = #{projectType} AND work_day >=#{currentMonthFirstDay}
    </select>

    <select id="listByDateAndUserId" resultMap="dayWorkTimeAndType">
    select user_id,day(work_day),CASE when `type` = 3 then 1 when `type` = 4 then 2 else 0 end AS `type`, sum(work_time)
    from <include refid="table"/>
    where year(work_day) = #{year} AND month(work_day) = #{month} AND user_id = #{userId} AND status in (2,5)
    group by user_id,day(work_day), CASE when `type` = 3 then 1 when `type` = 4 then 2 else 0 end
    order by day(work_day)
    </select>
cq990612's avatar
cq990612 committed
153

nie'hong's avatar
nie'hong committed
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
    <select id="getCountByCondition" resultType="integer" parameterType="map">
        select count(1)
        from <include refid="table"/>
        <where>
            <include refid="criteria"/>
            <if test="startDay != null">
                AND work_day>=#{startDay}
            </if>
            <if test="projectIds != null">
                AND project_id IN
                <foreach collection="projectIds" 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="typeArray != null">
                AND `type` IN
                <foreach collection="typeArray" item="type" open="(" close=")" separator=",">
                    #{type}
                </foreach>
            </if>
        </where>
    </select>
nie'hong's avatar
nie'hong committed
180 181

    <select id="getWorkTimeAndCostCollect" resultType="cn.wisenergy.model.dto.WorkTimeAndCostCollect" parameterType="integer">
182
        select case when `type`= 1 then '商机' when `type`= 0 then '项目' end AS type,dept_id, project_id,MIN(work_day) AS firstTime,MAX(work_day) AS lastTime,SUM(work_time)/8 AS totalTime,(SUM(work_time))/8*10 AS cost
nie'hong's avatar
nie'hong committed
183 184 185 186 187 188
        from <include refid="table"/>
        where status in (2,5) and project_id in
        <foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
            #{projectId}
        </foreach>
        <if test="firstDayOfMonth != null">
nie'hong's avatar
nie'hong committed
189
            AND work_day >= date(#{firstDayOfMonth})
nie'hong's avatar
nie'hong committed
190
        </if>
191
        group by `type`,dept_id, project_id
nie'hong's avatar
nie'hong committed
192 193
    </select>

194 195 196 197 198
    <select id="getDaysByDateAndStatus" resultType="date" >
        select distinct(work_day)
        from <include refid="table"/>
        where work_day >= #{firstDayOfMonth} AND user_id = #{userId}
    </select>
nie'hong's avatar
nie'hong committed
199
</mapper>