WorkProjectTimeCost.xml 6.19 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
<?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"/>
nie'hong's avatar
nie'hong committed
25
            <result property="statisticsTime" column="statistics_time"/>
nie'hong's avatar
nie'hong committed
26 27 28 29 30
            <result property="totalTime" column="total_time"/>
            <result property="cost" column="cost"/>
        </collection>
    </resultMap>

31 32 33
    <resultMap id="projectStatisticsByMonth" type="cn.wisenergy.model.dto.ProjectStatisticsByMonth">
        <result property="projectId" column="project_id"/>
        <result property="projectName" column="project_name"/>
34
        <result property="deptName" column="dept_name"/>
35 36 37 38 39 40 41
        <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
42 43 44 45 46 47
    <delete id="deleteStatisticsByQuarter">
        delete
        from work_project_time_cost
        where statistics_start >= #{date}
    </delete>

nie'hong's avatar
nie'hong committed
48

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


    <select id="selectList" resultMap="workTimeAndCostCollect">
nie'hong's avatar
nie'hong committed
86 87
        SELECT type ,<if test="centreId == null">'汇总' AS dept_name,</if> <if test="centreId != null"> dept_name,p.dept_id,</if>p.id AS
        project_id,project_name,concat(min(statistics_start),'~' ,max(statistics_end)) AS statistics_time ,sum(total_time) AS total_time,sum(cost) AS cost
nie'hong's avatar
nie'hong committed
88
        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
89 90 91
        <where>
        <if test="projectIds != null">
        project_id in
nie'hong's avatar
nie'hong committed
92 93 94
        <foreach collection="projectIds" open="(" close=")" separator="," item="projectId">
            #{projectId}
        </foreach>
95
        </if>
nie'hong's avatar
nie'hong committed
96
        <if test="deptId != null">
nie'hong's avatar
nie'hong committed
97
            AND ptc.dept_id = #{deptId}
nie'hong's avatar
nie'hong committed
98
        </if>
nie'hong's avatar
nie'hong committed
99

nie'hong's avatar
nie'hong committed
100 101 102
        <if test="centreId != null">
           AND centre_id = #{centreId}
        </if>
nie'hong's avatar
nie'hong committed
103 104 105
        <if test="firstDayOfMonth != null">
            AND statistics_start >= #{firstDayOfMonth}
        </if>
106
        </where>
nie'hong's avatar
nie'hong committed
107
        GROUP BY type, <if test="centreId == null"> dept_name,</if> <if test="centreId != null"> dept_name,p.dept_id,</if>p.id,project_name
nie'hong's avatar
nie'hong committed
108
        <if test="centreId != null"> ORDER BY d.sort</if>
nie'hong's avatar
nie'hong committed
109
    </select>
110 111 112


    <select id="selectListByMonth" resultMap="projectStatisticsByMonth">
nie'hong's avatar
nie'hong committed
113
        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
114 115 116 117 118 119 120 121 122
        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
123
        group by <if test="projectId != null"> project_name,</if> year(statistics_start),MONTH(statistics_start)
nie'hong's avatar
nie'hong committed
124 125 126
    </select>

    <select id="selectListStatistics" resultMap="projectStatisticsByMonth">
127
        select ptc.project_id AS project_id, project_name,
nie'hong's avatar
nie'hong committed
128
        group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,
129 130
        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
131 132 133 134 135
        <where>
        <if test="projectId != null ">
            ptc.project_id = #{projectId}
        </if>
        <if test="deptId != null">
136
            AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
137 138
        </if>
        </where>
nie'hong's avatar
nie'hong committed
139
        group by ptc.project_id,project_name,year(statistics_start),MONTH(statistics_start) <if test="projectId != null "> ,d.dept_name</if>
140
    </select>
nie'hong's avatar
nie'hong committed
141

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