liuxiaolong
2019-05-06 f99bc8c6a1d10610373738edd7d0aa0181c81d99
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?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="com.cloud.user.dao.BbEmployeeRelationDao" >
 
    <sql id="table"> bb_employee_relation </sql>
 
    <resultMap id="beanMap" type="com.cloud.model.sys.BbEmployeeRelation">
        <id column="id" property="id" />                                      <!--id-->
        <result column="orgId" property="orgId"/>                             <!--组织机构Id-->
        <result column="employeeId" property="employeeId"/>                   <!--被关联人Id-->
        <result column="relationoId" property="relationoId"/>                 <!--关联人Id-->
        <result column="relation" property="relation"/>                       <!--家属关系-->
        <!--后续可以补电话字段-->
        <result column="createBy" property="createBy"/>                       <!--创建者-->
        <result column="createTime" property="createTime"/>                   <!--创建时间-->
        <result column="updateBy" property="updateBy"/>                       <!--更新者-->
        <result column="updateTime" property="updateTime"/>                   <!--更新时间-->
        <result column="remarks" property="remarks"/>                         <!--备注信息-->
        <result column="delFlag" property="delFlag"/>                         <!--逻辑删除标记(0-->
        <result column="rev_json1" property="revJson1"/>                      <!--预留json格式字段1-->
    </resultMap>
 
    <insert id="add" parameterType="com.cloud.model.sys.BbEmployeeRelation" keyProperty="id" useGeneratedKeys="true">
        insert into <include refid="table" />
            (
                id                  , <!--id-->
                orgId               , <!--组织机构Id-->
                employeeId          , <!--被关联人Id-->
                relationoId         , <!--关联人Id-->
                relation            , <!--家属关系-->
                createBy            , <!--创建者-->
                createTime          , <!--创建时间-->
                updateBy            , <!--更新者-->
                updateTime          , <!--更新时间-->
                remarks             , <!--备注信息-->
                delFlag             , <!--逻辑删除标记(0-->
                rev_json1             <!--预留json格式字段1-->
            )
        values 
            (
                #{id}               , <!--id-->
                #{orgId}            , <!--组织机构Id-->
                #{employeeId}       , <!--被关联人Id-->
                #{relationoId}      , <!--关联人Id-->
                #{relation}         , <!--家属关系-->
                #{createBy}         , <!--创建者-->
                #{createTime}       , <!--创建时间-->
                #{updateBy}         , <!--更新者-->
                #{updateTime}       , <!--更新时间-->
                #{remarks}          , <!--备注信息-->
                #{delFlag}          , <!--逻辑删除标记(0-->
                #{revJson1}           <!--预留json格式字段1-->
            )
    </insert>
 
    <update id="update" parameterType="com.cloud.model.sys.BbEmployeeRelation">
        update 
            <include refid="table" />
        set 
            id                  = #{id}               , <!--id-->
            orgId               = #{orgId}            , <!--组织机构Id-->
            employeeId          = #{employeeId}       , <!--被关联人Id-->
            relationoId         = #{relationoId}      , <!--关联人Id-->
            relation            = #{relation}         , <!--家属关系-->
            createBy            = #{createBy}         , <!--创建者-->
            createTime          = #{createTime}       , <!--创建时间-->
            updateBy            = #{updateBy}         , <!--更新者-->
            updateTime          = #{updateTime}       , <!--更新时间-->
            remarks             = #{remarks}          , <!--备注信息-->
            delFlag             = #{delFlag}          , <!--逻辑删除标记(0-->
            rev_json1           = #{revJson1}           <!--预留json格式字段1-->
            
        <where>
            <if test="orgId != null and orgId != ''">
                and orgId = #{orgId}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
        </where>
    </update>
 
    <update id="deleteById">
        update
            <include refid="table" />
        set 
            delFlag = '1'
        <where>
            <if test="orgId != null and orgId != ''">
                and orgId = #{orgId}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
        </where>
    </update>
    
    <sql id="base_column_list">
        id                  , <!--id-->
        orgId               , <!--组织机构Id-->
        employeeId          , <!--被关联人Id-->
        relationoId         , <!--关联人Id-->
        relation            , <!--家属关系-->
        createBy            , <!--创建者-->
        createTime          , <!--创建时间-->
        updateBy            , <!--更新者-->
        updateTime          , <!--更新时间-->
        remarks             , <!--备注信息-->
        delFlag             , <!--逻辑删除标记(0-->
        rev_json1             <!--预留json格式字段1-->
    </sql>
 
    <select id="findById" resultMap="beanMap">
        select 
            <include refid="base_column_list" />
        from 
            <include refid="table" />
        <where>
            <if test="orgId != null and orgId != ''">
                and orgId = #{orgId}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
        </where>
    </select>
 
    <sql id="where">
        <where>
            delFlag = '0'
            <if test="orgId != null and orgId != ''">
                and orgId = #{orgId}
            </if>
        </where>
    </sql>
 
    <select id="count" resultType="int">
        select count(*) from <include refid="table" /> t
        <include refid="where" />
    </select>
    
    <select id="findData" resultType="com.cloud.model.sys.BbEmployeeRelation">
        select * from <include refid="table" /> t
        <include refid="where" />
        order by t.id desc
        <if test="start != null and start != '' and length != null and length != '' ">
            LIMIT #{start}, #{length}
        </if>
    </select>
 
    <select id="findRelationById" resultType="map">
        SELECT er.id,er.orgId,er.relationoId,e.`name`,er.relation,e.phone,e.photos
        from bb_employee_relation er INNER JOIN bb_employee e on er.relationoId = e.id
        where er.delFlag = '0' and er.employeeId = #{id}
        <if test="orgId != null and orgId !=''">
            and er.orgId = #{orgId}
        </if>
    </select>
    
</mapper>