WorkProjectTimeCost.xml 3.59 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 23 24 25 26 27 28 29 30 31
<?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.WorkProjectTimeCostMapper">
    <resultMap id="workProjectTimeCost" type="cn.wisenergy.model.app.WorkProjectTimeCost">
        <id column="id" property="id"/>
        <result property="projectId" column="project_id"/>
        <result property="statisticsStart" column="statistics_start"/>
        <result property="statisticsEnd" column="statistics_end"/>
        <result property="totalTime" column="total_time"/>
        <result property="cost" column="cost"/>
    </resultMap>

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

    <resultMap id="deptProjectWorkTimeAndCost" 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="firstTime" column="statistics_start"/>
            <result property="lastTime" column="statistics_end"/>
            <result property="totalTime" column="total_time"/>
            <result property="cost" column="cost"/>
        </collection>
    </resultMap>

nie'hong's avatar
nie'hong committed
32 33 34 35 36 37
    <delete id="deleteStatisticsByQuarter">
        delete
        from work_project_time_cost
        where statistics_start >= #{date}
    </delete>

nie'hong's avatar
nie'hong committed
38 39

    <insert id="statisticsTimeOrderByMonth">
nie'hong's avatar
nie'hong committed
40
    INSERT into work_project_time_cost(project_id,user_id,is_overtime,statistics_start,statistics_end,total_time,cost)
nie'hong's avatar
nie'hong committed
41 42
    SELECT
	project_id,
nie'hong's avatar
nie'hong committed
43 44 45
	user_id,
	is_overtime,
	min(work_day),
nie'hong's avatar
nie'hong committed
46 47
	max(work_day),
	sum(work_time/8),
nie'hong's avatar
nie'hong committed
48
	sum(work_time/8*s.day_salary)
nie'hong's avatar
nie'hong committed
49 50 51 52 53
    FROM
        work_time_order t join work_user_salary s on t.user_id = s.user_id
    WHERE status in (2,5) AND s.create_time &lt; work_day AND s.end_time>work_day AND
    GROUP BY
        project_id,
nie'hong's avatar
nie'hong committed
54 55
        user_id,
        is_overtime,
nie'hong's avatar
nie'hong committed
56 57
        YEAR (work_day),
        MONTH (work_day)
nie'hong's avatar
nie'hong committed
58
    ON DUPLICATE key UPDATE is_overtime = VALUES(is_overtime), statistics_end = VALUES(statistics_end),total_time = VALUES(total_time),cost= VALUES(cost)
nie'hong's avatar
nie'hong committed
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
    </insert>


    <select id="selectList" resultMap="workTimeAndCostCollect">
        SELECT case `type` when 1 then "项目" else "商机" end AS type ,dept_name,dept_id,ptc.project_id AS
        project_id,project_name,min(statistics_start) AS statistics_start,max(statistics_end) AS
        statistics_end,sum(total_time) AS total_time,sum(cost) AS cost
        from work_project_time_cost ptc join work_project p on ptc.project_id=p.id join work_dept d on p.dept_id=d.id
        where project_id in
        <foreach collection="projectIds" open="(" close=")" separator="," item="projectId">
            #{projectId}
        </foreach>
        <if test="deptId != null">
            AND dept_id = #{deptId}
        </if>
        AND type in
        <foreach collection="types" open="(" close=")" separator="," item="type">
            #{type}
        </foreach>
        <if test="firstDayOfMonth != null">
            AND statistics_start >= #{firstDayOfMonth}
        </if>
        GROUP BY type,dept_name,dept_id,ptc.project_id,project_name
    </select>
</mapper>