WorkProjectMapper.xml 12.2 KB
Newer Older
nie'hong's avatar
nie'hong committed
1 2 3 4 5 6
<?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">
cq990612's avatar
cq990612 committed
7 8 9 10 11 12 13 14 15 16 17 18 19
        <id column="id" property="id"/>
        <result column="oa_project_id" property="oaProjectId"/>
        <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"/>
cq990612's avatar
cq990612 committed
20 21
        <result column="business_id" property="businessId"/>
        <result column="business_name" property="businessName"/>
nie'hong's avatar
nie'hong committed
22
        <result column="conclusion_time" property="conclusionTime"/>
nie'hong's avatar
nie'hong committed
23 24 25 26
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
nie'hong's avatar
nie'hong committed
27
        id, oa_project_id, project_name,business_id,business_name, type, manager_id, dept_id, work_time, cost_budget, is_conclusion,start_time,end_time, create_time, modify_time,conclusion_time
nie'hong's avatar
nie'hong committed
28 29 30 31 32 33 34 35
    </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
36
        <if test="oaProjectId != null">and oa_project_id = #{oaProjectId}</if>
nie'hong's avatar
nie'hong committed
37
        <if test="projectName != null">and project_name = #{projectName}</if>
cq990612's avatar
cq990612 committed
38 39
        <if test="businessId !=null">and business_id = #{businessId}</if>
        <if test="businessName !=null">and business_name = #{businessName}</if>
nie'hong's avatar
nie'hong committed
40
        <if test="type != null">and `type` =#{type}</if>
nie'hong's avatar
nie'hong committed
41
        <if test="managerId != null">and manager_id = #{managerId}</if>
nie'hong's avatar
nie'hong committed
42
        <if test="deptId != null">and dept_id = #{deptId}</if>
nie'hong's avatar
nie'hong committed
43 44
        <if test="workTime != null">and work_time =#{workTime}</if>
        <if test="costBudget != null">and cost_budget = #{costBudget}</if>
45
        <if test="isConclusion != null">and is_conclusion =#{isConclusion}</if>
nie'hong's avatar
nie'hong committed
46 47
        <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
48
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
nie'hong's avatar
nie'hong committed
49
        <if test="modifyTime != null">and modify_time &gt;= modifyTime</if>
nie'hong's avatar
nie'hong committed
50
        <if test="conclusionTime != null">and conclusion_time &gt;= conclusionTime</if>
nie'hong's avatar
nie'hong committed
51 52
    </sql>

cq990612's avatar
cq990612 committed
53 54 55
    <update id="updateIsConclusionById">
        UPDATE
        <include refid="table"/>
nie'hong's avatar
nie'hong committed
56
        SET is_conclusion = 0, conclusion_time = now()
cq990612's avatar
cq990612 committed
57
        WHERE id = #{id}
cq990612's avatar
cq990612 committed
58
    </update>
nie'hong's avatar
nie'hong committed
59

60 61 62 63 64 65 66
    <update id="updateIsConclusionById2">
        UPDATE
        <include refid="table"/>
        SET is_conclusion = 1, conclusion_time = now()
        WHERE id = #{id}
    </update>

cq990612's avatar
cq990612 committed
67 68 69 70 71 72 73
    <update id="updateProject">
        UPDATE
        <include refid="table"/>
        <set>
                start_time = #{startTime},
                end_time = #{endTime},
                work_time = #{workTime},
cq990612's avatar
cq990612 committed
74
                cost_budget =#{costBudget},
cq990612's avatar
cq990612 committed
75
                manager_id = #{managerId},
cq990612's avatar
cq990612 committed
76 77 78
                dept_id = #{deptId},
                business_id = #{businessId},
                business_name = #{businessName},
cq990612's avatar
cq990612 committed
79 80
                oa_project_id = #{oaProjectId},
                project_name = #{projectName},
cq990612's avatar
cq990612 committed
81
                modify_time = now()
cq990612's avatar
cq990612 committed
82 83 84 85 86 87 88 89 90 91 92
        </set>
        <where>
            <if test="null != projectId">
                id = #{projectId}
            </if>

        </where>


    </update>

nie'hong's avatar
nie'hong committed
93
    <select id="getProjectsByCriteria" resultMap="BaseResultMap" parameterType="map">
cq990612's avatar
cq990612 committed
94 95 96 97
        select
        <include refid="Base_Column_List"/>
        from
        <include refid="table"/>
98
        <where>
cq990612's avatar
cq990612 committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
            <if test="isConclusion != null">
                is_conclusion = #{isConclusion}
            </if>
            <if test="managerId != null">
                AND manager_id = #{managerId}
            </if>
            <if test="deptId != null">
                OR dept_id = #{deptId}
            </if>
            <if test="deptIds != null">
                OR dept_id IN
                <foreach collection="deptIds" item="deptId" separator="," open="(" close=")">
                    #{deptId}
                </foreach>
            </if>
114
        </where>
nie'hong's avatar
nie'hong committed
115
    </select>
116

cq990612's avatar
cq990612 committed
117
    <select id="getProjectsByIds" resultType="cn.wisenergy.model.app.WorkProject">
cq990612's avatar
cq990612 committed
118 119 120 121
        select
        <include refid="Base_Column_List"/>
        from
        <include refid="table"/>
cq990612's avatar
cq990612 committed
122 123 124 125 126 127 128
        <where>
            <if test="ids != null">
                AND id IN
                <foreach collection="ids" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </if>
nie'hong's avatar
nie'hong committed
129
            <if test="null != isConclusion">
cq990612's avatar
cq990612 committed
130 131 132
                AND is_conclusion = #{isConclusion}
            </if>
        </where>
cq990612's avatar
cq990612 committed
133
    </select>
nie'hong's avatar
nie'hong committed
134

cq990612's avatar
cq990612 committed
135
    <select id="getManagerProjectsDto" resultType="cn.wisenergy.model.dto.ManagerProjectsDto">
cq990612's avatar
cq990612 committed
136
        select
cq990612's avatar
cq990612 committed
137
        p.id,p.oa_project_id,p.project_name,p.business_id,p.business_name,p.manager_id,d.dept_name,lu.manager_name,p.dept_id,p.modify_time,p.type,p.create_time,p.is_conclusion,
cq990612's avatar
cq990612 committed
138 139
        GROUP_CONCAT(DISTINCT(u.name) ORDER BY CONVERT( u.name USING gbk )) as
        'participants',p.cost_budget,p.work_time,p.start_time,p.end_time,
cq990612's avatar
cq990612 committed
140 141 142 143
        if(cost is NULL,0,0 + cast(cost as char)) as 'currentLaborCost',if(total_time is NULL,0,0 + cast(total_time as
        char)) as 'totalCurrentWorkingHours',
        if(p.end_time>=curdate(),'否','是') as 'isItOverdue',
        if(p.create_time = p.modify_time,'否','是') as 'isThereABudgetChange'
cq990612's avatar
cq990612 committed
144
        from work_project p LEFT JOIN (select project_id,SUM(total_time) as 'total_time',SUM(cost)/10000 as 'cost'
cq990612's avatar
cq990612 committed
145 146
        FROM work_project_time_cost
        GROUP BY project_id) o on p.id = o.project_id
cq990612's avatar
cq990612 committed
147
        LEFT JOIN (select id,`name` as 'manager_name'from work_user) lu on p.manager_id=lu.id
cq990612's avatar
cq990612 committed
148
        LEFT JOIN work_dept d on p.dept_id=d.id
cq990612's avatar
cq990612 committed
149 150
        LEFT JOIN work_user_project up ON p.id = up.project_id
        LEFT JOIN work_user u on u.id = up.user_id
cq990612's avatar
cq990612 committed
151
        <where>
cq990612's avatar
cq990612 committed
152
            <if test="deptAndManager >0">
cq990612's avatar
cq990612 committed
153 154 155 156 157 158 159 160 161 162 163 164
                <if test="null !=type">
                    AND p.type = #{type}
                </if>
                <if test="null !=isConclusion">
                    AND p.is_conclusion = #{isConclusion}
                </if>
                <if test="deptIds != null and deptIds.size>0">
                    AND p.dept_id IN
                    <foreach collection="deptIds" item="deptId" separator="," open="(" close=")">
                        #{deptId}
                    </foreach>
                </if>
cq990612's avatar
cq990612 committed
165 166 167
                <if test="null != key and key!=''">
                    AND (
                    p.project_name like concat('%',#{key},'%') OR
168 169
                    lu.manager_name like concat('%',#{key},'%') or
                    p.business_id like concat('%',#{key},'%')
cq990612's avatar
cq990612 committed
170 171
                    )
                </if>
cq990612's avatar
cq990612 committed
172
            </if>
cq990612's avatar
cq990612 committed
173

cq990612's avatar
cq990612 committed
174 175 176 177 178
            <if test="null != userId">
                OR (p.manager_id = #{userId}
                <if test="null !=type">
                    AND p.type = #{type}
                </if>
cq990612's avatar
cq990612 committed
179 180 181
                <if test="null !=isConclusion">
                    AND p.is_conclusion = #{isConclusion}
                </if>
cq990612's avatar
cq990612 committed
182 183 184 185 186
                <if test="deptIds != null and deptIds.size>0">
                    AND p.dept_id IN
                    <foreach collection="deptIds" item="deptId" separator="," open="(" close=")">
                        #{deptId}
                    </foreach>
cq990612's avatar
cq990612 committed
187
                </if>
cq990612's avatar
cq990612 committed
188 189 190
                <if test="null != key and key!=''">
                    AND (
                    p.project_name like concat('%',#{key},'%') OR
191 192
                    lu.manager_name like concat('%',#{key},'%') or
                    p.business_id like concat('%',#{key},'%')
cq990612's avatar
cq990612 committed
193 194
                    )
                </if>
cq990612's avatar
cq990612 committed
195 196
                )
            </if>
197
            AND u.status = 1
cq990612's avatar
cq990612 committed
198 199 200 201

        </where>

        GROUP BY p.id
nie'hong's avatar
nie'hong committed
202
        ORDER BY p.is_conclusion DESC, p.conclusion_time DESC, p.create_time DESC
cq990612's avatar
cq990612 committed
203

cq990612's avatar
cq990612 committed
204
    </select>
nie'hong's avatar
nie'hong committed
205

cq990612's avatar
cq990612 committed
206

207
    <select id="getListByCriteria" resultType="cn.wisenergy.model.app.WorkProject">
cq990612's avatar
cq990612 committed
208 209 210 211
        select
        <include refid="Base_Column_List"/>
        from
        <include refid="table"/>
212
        <where>
nie'hong's avatar
nie'hong committed
213 214 215 216 217 218 219 220 221 222 223 224
            <if test="isConclusion != null">
                AND is_conclusion = #{isConclusion}
            </if>
            <if test="deptId != null and managerId == null">
                AND dept_id = #{deptId}
            </if>
            <if test="deptId != null and managerId != null">
                AND (dept_id = #{deptId} OR manager_id = #{managerId})
            </if>
            <if test="managerId != null and deptId == null">
                AND manager_id = #{managerId}
            </if>
nie'hong's avatar
nie'hong committed
225

nie'hong's avatar
nie'hong committed
226
            <if test="year != null">
nie'hong's avatar
nie'hong committed
227
                AND YEAR (create_time) &lt;= #{year} AND( year(conclusion_time) >= #{year} or is_conclusion = 1)
nie'hong's avatar
nie'hong committed
228
            </if>
229
        </where>
nie'hong's avatar
nie'hong committed
230 231
    </select>

nie'hong's avatar
nie'hong committed
232
    <select id="getProjectIdByManager" resultType="java.lang.Integer">
cq990612's avatar
cq990612 committed
233 234 235 236
        select id
        from
        <include refid="table"/>
        where manager_id = #{userId}
nie'hong's avatar
nie'hong committed
237 238
    </select>

239
    <select id="getListByCentreIdAndIsConclusion" resultType="cn.wisenergy.model.app.WorkProject">
cq990612's avatar
cq990612 committed
240 241
        select
        <include refid="Base_Column_List"/>
242 243 244 245 246 247 248
        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
249 250 251 252 253 254 255 256 257 258 259 260 261 262
    <select id="getLastDate" resultType="java.lang.String">
    SELECT
	CONCAT(YEAR (IF (is_conclusion = 0,max(work_day),now())),
		'年',
		MONTH (IF (is_conclusion = 0,max(work_day),now())),
			'月'
		)
	FROM
		work_project p
	JOIN work_time_order t ON p.id = t.project_id
	WHERE
		p.id = #{projectId}
    </select>

cq990612's avatar
cq990612 committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    <resultMap id="orderChangeType" type="cn.wisenergy.model.dto.OrderChangeTypeDto">
        <id column="type" property="type"/>
        <result column="type_name" property="typeName"/>
        <collection property="orderChangeProjectDtos" ofType="cn.wisenergy.model.dto.OrderChangeProjectDto">
            <id column="project_id" property="projectId"/>
            <result column="project_name" property="projectName"/>
            <collection property="deptUserDtos" resultMap = "deptUserDto"/>
        </collection>
    </resultMap>
    <resultMap id="deptUserDto" type="cn.wisenergy.model.dto.DeptUserDto">
        <id column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <collection property="userDtos" ofType="cn.wisenergy.model.dto.UserDto">
        <id column="user_id" property="id"/>
        <result column="user_name" property="name"/>
        </collection>
    </resultMap>

    <select id="getOrderChangeTypeDtos" resultMap="orderChangeType">
cq990612's avatar
cq990612 committed
282 283 284
        select p.type,t.name 'type_name',p.id 'project_id',p.project_name,up.user_id,u.name 'user_name',u.dept_id,d.dept_name,d1.id,d1.dept_name
        from work_project p LEFT JOIN work_user_project up on p.id = up.project_id
        LEFT JOIN work_user u ON up.user_id = u.id
nie'hong's avatar
nie'hong committed
285
        LEFT JOIN work_dept d1 ON d1.id = p.dept_id
cq990612's avatar
cq990612 committed
286 287
        LEFT JOIN work_dept d ON d.id = u.dept_id
        LEFT JOIN work_type t ON p.type = t.id
cq990612's avatar
cq990612 committed
288
<where>
cq990612's avatar
cq990612 committed
289
    p.is_conclusion = 1
cq990612's avatar
cq990612 committed
290 291 292 293
    <if test="userId !=null">
     AND   p.manager_id = #{userId}
    </if>
</where>
nie'hong's avatar
nie'hong committed
294
       ORDER BY t.sort,d.sort,p.id
cq990612's avatar
cq990612 committed
295 296
    </select>

nie'hong's avatar
nie'hong committed
297

nie'hong's avatar
nie'hong committed
298 299
    <select id="getListByDeptAndType" resultType="string">
        select distinct oa_project_id
nie'hong's avatar
nie'hong committed
300
        from <include refid="table"/>
nie'hong's avatar
nie'hong committed
301 302 303
        <where>
             type = #{typeId} AND (oa_project_id like CONCAT("%" ,#{projectNameOrNo},"%") OR project_name like CONCAT("%" ,#{projectNameOrNo},"%"))
        </where>
nie'hong's avatar
nie'hong committed
304 305
    </select>

nie'hong's avatar
nie'hong committed
306
    <select id="getByProjectOaId" resultType="cn.wisenergy.model.app.WorkProject">
nie'hong's avatar
nie'hong committed
307 308
        select <include refid="Base_Column_List"/>
        from <include refid="table"/>
nie'hong's avatar
nie'hong committed
309
        where  oa_project_id = #{oaId}
nie'hong's avatar
nie'hong committed
310 311
    </select>

nie'hong's avatar
nie'hong committed
312

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