WorkProjectTimeCost.xml 6.34 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>

32 33 34
    <resultMap id="projectStatisticsByMonth" type="cn.wisenergy.model.dto.ProjectStatisticsByMonth">
        <result property="projectId" column="project_id"/>
        <result property="projectName" column="project_name"/>
35
        <result property="deptName" column="dept_name"/>
36 37 38 39 40 41 42
        <collection property="statisticsDateAndWorkTimes" ofType="cn.wisenergy.model.dto.ProjectStatisticsByMonth$StatisticsDateAndWorkTime">
            <result property="date" column="date"/>
            <result property="totalTime" column="total_time"/>
            <result property="cost" column="cost"/>
        </collection>
    </resultMap>

nie'hong's avatar
nie'hong committed
43 44 45 46 47 48
    <delete id="deleteStatisticsByQuarter">
        delete
        from work_project_time_cost
        where statistics_start >= #{date}
    </delete>

nie'hong's avatar
nie'hong committed
49

50 51
    <insert id="statisticsTimeOrderByMonth" useGeneratedKeys="true">
        INSERT INTO work_project_time_cost (
nie'hong's avatar
nie'hong committed
52
        project_id,
nie'hong's avatar
nie'hong committed
53
        user_id,
54
        dept_id,
55 56 57
        statistics_start,
        statistics_end,
        total_time,
58 59
        cost,
        create_time
60 61 62 63
        )
        SELECT
        project_id,
        t.user_id,
64
        t.dept_id,
65 66 67
        min(work_day),
        max(work_day),
        sum(work_time / 8),
68 69
        sum(work_time / 8 * s.day_salary),
        now() AS create_time
70 71
        FROM
        work_time_order t
nie'hong's avatar
nie'hong committed
72
        LEFT JOIN work_user_salary s ON t.user_id = s.user_id
73 74
        WHERE
        t.work_day >= #{date} AND s.create_time &lt;work_day AND s.end_time > work_day
nie'hong's avatar
nie'hong committed
75
        AND t.`status` IN (2, 5) AND project_id is not null
76 77
        GROUP BY
        project_id,
78
        t.dept_id,
79
        t.user_id,
nie'hong's avatar
nie'hong committed
80 81
        YEAR (work_day),
        MONTH (work_day)
nie'hong's avatar
nie'hong committed
82
        ORDER BY min(work_day)
83
     </insert>
nie'hong's avatar
nie'hong committed
84 85 86


    <select id="selectList" resultMap="workTimeAndCostCollect">
nie'hong's avatar
nie'hong committed
87
        SELECT type ,<if test="centreId == null">'汇总' AS dept_name,</if> <if test="centreId != null"> dept_name,ptc.dept_id,</if>ptc.project_id AS
nie'hong's avatar
nie'hong committed
88 89 90 91 92 93 94 95 96 97
        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>
nie'hong's avatar
nie'hong committed
98 99 100 101 102 103 104 105 106
        <if test="types != null">
            AND type in
            <foreach collection="types" open="(" close=")" separator="," item="type">
                #{type}
            </foreach>
        </if>
        <if test="centreId != null">
           AND centre_id = #{centreId}
        </if>
nie'hong's avatar
nie'hong committed
107 108 109
        <if test="firstDayOfMonth != null">
            AND statistics_start >= #{firstDayOfMonth}
        </if>
nie'hong's avatar
nie'hong committed
110
        GROUP BY type, <if test="centreId == null"> dept_name,</if> <if test="centreId != null"> dept_name,ptc.dept_id,</if>ptc.project_id,project_name
nie'hong's avatar
nie'hong committed
111
    </select>
112 113 114


    <select id="selectListByMonth" resultMap="projectStatisticsByMonth">
nie'hong's avatar
nie'hong committed
115
        select <if test="deptId != null">'合计' AS project_name,</if> <if test="projectId != null"> project_name,</if>  group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,sum(total_time) AS total_time, sum(cost) AS cost
nie'hong's avatar
nie'hong committed
116 117 118 119 120 121 122 123 124
        from work_project_time_cost ptc join work_project p on ptc.project_id = p.id join work_dept d on ptc.dept_id = d.id
        <where>
        <if test="projectId != null ">
            ptc.project_id = #{projectId}
        </if>
        <if test="deptId != null">
            AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
        </if>
        </where>
nie'hong's avatar
nie'hong committed
125
        group by <if test="projectId != null"> project_name,</if> year(statistics_start),MONTH(statistics_start)
nie'hong's avatar
nie'hong committed
126 127 128
    </select>

    <select id="selectListStatistics" resultMap="projectStatisticsByMonth">
129
        select ptc.project_id AS project_id, project_name,
nie'hong's avatar
nie'hong committed
130
        group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,
131 132
        sum(total_time) AS total_time, sum(cost) AS cost <if test="projectId != null "> ,d.dept_name AS dept_name</if>
        from work_project_time_cost ptc join work_project p on ptc.project_id = p.id join work_dept d on ptc.dept_id = d.id
133 134 135 136 137
        <where>
        <if test="projectId != null ">
            ptc.project_id = #{projectId}
        </if>
        <if test="deptId != null">
138
            AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
139 140
        </if>
        </where>
nie'hong's avatar
nie'hong committed
141
        group by ptc.project_id,project_name,year(statistics_start),MONTH(statistics_start) <if test="projectId != null "> ,d.dept_name</if>
142
    </select>
nie'hong's avatar
nie'hong committed
143

nie'hong's avatar
nie'hong committed
144
</mapper>