WorkUserProjectMapper.xml 2.64 KB
Newer Older
cq990612's avatar
cq990612 committed
1 2 3 4 5 6 7 8 9 10 11
<?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.WorkUserProjectMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkUserProject">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="project_id" property="projectId" />
    </resultMap>

cq990612's avatar
cq990612 committed
12 13 14 15 16 17
    <resultMap id="MinUserMap" type="cn.wisenergy.model.dto.UserProjectDto">
        <id column="user_id" property="id"/>
        <result column="name" property="name"/>
        <result column="project_id" property="projectId"/>
    </resultMap>

cq990612's avatar
cq990612 committed
18 19 20 21
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, project_id
    </sql>
cq990612's avatar
cq990612 committed
22 23 24 25 26 27 28 29
    <insert id="insertBatch">
        INSERT INTO work_user_project
        (user_id,project_id)
        VALUES
        <foreach collection ="userIds" item="userId" separator =",">
            ( #{userId}, #{projectId})
        </foreach >
    </insert>
30

cq990612's avatar
cq990612 committed
31 32 33 34
    <delete id="deleteByProjectId">
        DELETE
        FROM work_user_project
        WHERE project_id = #{projectId}
35 36 37 38
         <if test="userIds != null and userIds.size != 0">
         AND user_id not in
        <foreach collection="userIds" open="(" close=")" separator="," item="userId">#{userId}</foreach>
         </if>
cq990612's avatar
cq990612 committed
39
    </delete>
40

cq990612's avatar
cq990612 committed
41 42 43
    <select id="getUserByProjectId" resultMap="MinUserMap" >
        SELECT p.user_id,u.name,p.project_id
        FROM work_user_project p JOIN work_user u ON p.user_id = u.id
44
        WHERE project_id = #{projectId} and u.status = 1
cq990612's avatar
cq990612 committed
45
    </select>
cq990612's avatar
cq990612 committed
46

nie'hong's avatar
nie'hong committed
47
    <select id="selectUserIdByProjectIds" resultType="java.lang.Integer">
nie'hong's avatar
nie'hong committed
48 49 50
        select distinct user_id
        from work_user_project up join work_project p on up.project_id = p.id
        <where>
nie'hong's avatar
nie'hong committed
51 52
            <if test="isConclusion != null">
                AND p.is_conclusion = #{isConclusion}
nie'hong's avatar
nie'hong committed
53
            </if>
nie'hong's avatar
nie'hong committed
54 55 56 57 58 59 60 61
            <if test="deptId != null and managerId == null">
                AND p.dept_id = #{deptId}
            </if>
            <if test="deptId != null and managerId != null">
                AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
            </if>
            <if test="managerId != null and deptId == null">
                AND p.manager_id = #{managerId}
nie'hong's avatar
nie'hong committed
62 63
            </if>
        </where>
nie'hong's avatar
nie'hong committed
64 65
    </select>

66 67 68 69 70 71
    <select id="getUserByProjectAndStatus" resultType="java.lang.Integer">
    select  u.id
    from work_user_project up join work_user u on u.id = up.user_id
    where up.project_id = #{projectId} and u.status = 0
    </select>

cq990612's avatar
cq990612 committed
72
</mapper>