WorkProjectMapper.xml 6.67 KB
Newer Older
nie'hong's avatar
nie'hong committed
1 2 3 4 5 6 7
<?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.WorkProjectMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkProject">
        <id column="id" property="id" />
nie'hong's avatar
nie'hong committed
8
        <result column="oa_project_id" property="oaProjectId" />
nie'hong's avatar
nie'hong committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
        <result column="project_name" property="projectName" />
        <result column="type" property="type" />
        <result column="manager_id" property="managerId" />
        <result column="dept_id" property="deptId" />
        <result column="work_time" property="workTime" />
        <result column="cost_budget" property="costBudget" />
        <result column="is_conclusion" property="isConclusion" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="create_time" property="createTime" />
        <result column="modify_time" property="modifyTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
nie'hong's avatar
nie'hong committed
24
        id, oa_project_id, project_name, type, manager_id, dept_id, work_time, cost_budget, is_conclusion,start_time,end_time, create_time, modify_time
nie'hong's avatar
nie'hong committed
25 26 27 28 29 30 31 32
    </sql>

    <sql id="table">
        work_project
    </sql>
    <!--查询条件-->
    <sql id="criteria">
        <if test="id != null">and id = #{id}</if>
nie'hong's avatar
nie'hong committed
33
        <if test="oaProjectId != null">and oa_project_id = #{oaProjectId}</if>
nie'hong's avatar
nie'hong committed
34
        <if test="projectName != null">and project_name = #{projectName}</if>
nie'hong's avatar
nie'hong committed
35
        <if test="type != null">and `type` =#{type}</if>
nie'hong's avatar
nie'hong committed
36
        <if test="managerId != null">and manager_id = #{managerId}</if>
nie'hong's avatar
nie'hong committed
37
        <if test="deptId != null">and dept_id = #{deptId}</if>
nie'hong's avatar
nie'hong committed
38 39
        <if test="workTime != null">and work_time =#{workTime}</if>
        <if test="costBudget != null">and cost_budget = #{costBudget}</if>
40
        <if test="isConclusion != null">and is_conclusion =#{isConclusion}</if>
nie'hong's avatar
nie'hong committed
41 42
        <if test="startTime != null">and start_time =#{startTime}</if>
        <if test="endTime != null">and end_time =#{endTime}</if>
nie'hong's avatar
nie'hong committed
43
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
nie'hong's avatar
nie'hong committed
44
        <if test="modifyTime != null">and modify_time &gt;= modifyTime</if>
nie'hong's avatar
nie'hong committed
45 46
    </sql>

cq990612's avatar
cq990612 committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    <update id="updateIsConclusionById">
        UPDATE
        <include refid="table"/>
        SET is_conclusion = 0
        WHERE  id = #{id}
    </update>
    <update id="updateProject">
        UPDATE
        <include refid="table"/>
        <set>
            <if test="null != startTime">
                start_time = #{startTime},
            </if>
            <if test="null != endTime">
                end_time = #{endTime},
            </if>
            <if test="null != workTime">
                work_time = #{workTime},
            </if>
            <if test="null != costBudget">
cq990612's avatar
cq990612 committed
67
                cost_budget =#{costBudget},
cq990612's avatar
cq990612 committed
68
            </if>
cq990612's avatar
cq990612 committed
69
            modify_time = now()
cq990612's avatar
cq990612 committed
70 71 72 73 74 75 76 77 78 79 80
        </set>
        <where>
            <if test="null != projectId">
                id = #{projectId}
            </if>

        </where>


    </update>

nie'hong's avatar
nie'hong committed
81 82 83
    <select id="getProjectsByCriteria" resultMap="BaseResultMap" parameterType="map">
        select <include refid="Base_Column_List"/>
        from <include refid="table"/>
84
        <where>
nie'hong's avatar
nie'hong committed
85 86 87
        <if test="isConclusion != null">
            is_conclusion = #{isConclusion}
        </if>
88
        <if test="managerId != null">
nie'hong's avatar
nie'hong committed
89
          AND  manager_id = #{managerId}
90
        </if>
91
        <if test="deptId != null">
92 93 94 95 96 97 98 99 100
            OR dept_id = #{deptId}
        </if>
        <if test="deptIds != null">
            OR dept_id IN
            <foreach collection="deptIds" item="deptId" separator="," open="(" close=")">
                #{deptId}
            </foreach>
        </if>
        </where>
nie'hong's avatar
nie'hong committed
101
    </select>
102

cq990612's avatar
cq990612 committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    <select id="getProjectsByIds" resultType="cn.wisenergy.model.app.WorkProject">
        select <include refid="Base_Column_List"/>
        from <include refid="table"/>
        <where>

            <if test="ids != null">
                AND id IN
                <foreach collection="ids" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </if>
            <if test="null !=isConclusion">
                AND is_conclusion = #{isConclusion}
            </if>
        </where>
cq990612's avatar
cq990612 committed
118 119
    </select>
    <select id="getManagerProjectsDto" resultType="cn.wisenergy.model.dto.ManagerProjectsDto">
cq990612's avatar
cq990612 committed
120 121
select p.id,p.oa_project_id,p.project_name,p.type,p.create_time,p.is_conclusion,
GROUP_CONCAT(DISTINCT(u.name)) as 'participants',p.cost_budget,p.work_time,p.start_time,p.end_time,
cq990612's avatar
cq990612 committed
122
if(cost is NULL,0.00,cost) as 'currentLaborCost',if(total_time is NULL,0.00,total_time) as 'totalCurrentWorkingHours',
cq990612's avatar
cq990612 committed
123
if(p.end_time>=curdate(),'否','是') as 'isItOverdue',
cq990612's avatar
cq990612 committed
124
if(p.create_time = p.modify_time,'否','是') as 'isThereABudgetChange'
cq990612's avatar
cq990612 committed
125
        from work_project p LEFT JOIN (select project_id,SUM(total_time) as 'total_time',SUM(cost) as 'cost'
cq990612's avatar
cq990612 committed
126 127
        FROM work_project_time_cost
        GROUP BY project_id) o on p.id = o.project_id
cq990612's avatar
cq990612 committed
128 129 130 131
        LEFT JOIN work_user_project up ON p.id = up.project_id
        LEFT JOIN work_user u on u.id = up.user_id
<where>

cq990612's avatar
cq990612 committed
132 133 134 135
    <if test="null != userId">
    AND   p.manager_id = #{userId}
    </if>
    <if test="null !=type">
cq990612's avatar
cq990612 committed
136
         AND   p.type = #{type}
cq990612's avatar
cq990612 committed
137 138 139 140
    </if>
    <if test="null !=isConclusion">
     AND   p.is_conclusion = #{isConclusion}
    </if>
cq990612's avatar
cq990612 committed
141

cq990612's avatar
cq990612 committed
142
    <if test="deptIds != null">
cq990612's avatar
cq990612 committed
143
        OR (p.dept_id IN
cq990612's avatar
cq990612 committed
144 145 146
        <foreach collection="deptIds" item="deptId" separator="," open="(" close=")">
            #{deptId}
        </foreach>
cq990612's avatar
cq990612 committed
147 148 149 150 151 152 153
        <if test="null !=isConclusion">
            AND   p.is_conclusion = #{isConclusion}
        </if>
        <if test="null !=type">
            AND   p.type = #{type}
        </if>
        )
cq990612's avatar
cq990612 committed
154
    </if>
cq990612's avatar
cq990612 committed
155 156 157 158

</where>

GROUP BY p.id
cq990612's avatar
cq990612 committed
159
ORDER BY p.is_conclusion DESC
cq990612's avatar
cq990612 committed
160

cq990612's avatar
cq990612 committed
161
    </select>
nie'hong's avatar
nie'hong committed
162

cq990612's avatar
cq990612 committed
163

164
    <select id="getListByCriteria" resultType="cn.wisenergy.model.app.WorkProject">
nie'hong's avatar
nie'hong committed
165 166
        select <include refid="Base_Column_List"/>
        from <include refid="table"/>
167 168 169
        <where>
            <include refid="criteria"/>
        </where>
nie'hong's avatar
nie'hong committed
170 171
    </select>

nie'hong's avatar
nie'hong committed
172 173 174 175 176 177
    <select id="getProjectIdByManager" resultType="java.lang.Integer">
    select id
    from <include refid="table"/>
    where manager_id = #{userId}
    </select>

178 179 180 181 182 183 184 185 186
    <select id="getListByCentreIdAndIsConclusion" resultType="cn.wisenergy.model.app.WorkProject">
        select <include refid="Base_Column_List"/>
        from work_project p join work_dept d on p.dept_id = d.id
        where centre_id = #{centreId}
        <if test="isConclusion != null">
            AND is_conclusion = #{isConclusion}
        </if>
    </select>

nie'hong's avatar
nie'hong committed
187

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