OrgMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.huaxu.dao.OrgMapper">
  4. <!-- 结果集 -->
  5. <resultMap type="com.huaxu.entity.Org" id="OrgMap">
  6. <result property="id" column="ID" jdbcType="INTEGER"/>
  7. <result property="tenantId" column="TENANT_ID" jdbcType="VARCHAR"/>
  8. <result property="orgType" column="ORG_TYPE" jdbcType="VARCHAR"/>
  9. <result property="parentOrgId" column="PARENT_ORG_ID" jdbcType="INTEGER"/>
  10. <result property="orgAreaId" column="ORG_AREA_ID" jdbcType="INTEGER"/>
  11. <result property="orgName" column="ORG_NAME" jdbcType="VARCHAR"/>
  12. <result property="orgState" column="ORG_STATE" jdbcType="INTEGER"/>
  13. <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
  14. <result property="orgLeaderName" column="ORG_LEADER_NAME" jdbcType="VARCHAR"/>
  15. <result property="orgLeaderPhone" column="ORG_LEADER_PHONE" jdbcType="VARCHAR"/>
  16. <result property="orgLeaderEmail" column="ORG_LEADER_EMAIL" jdbcType="VARCHAR"/>
  17. <result property="orgLeaderSex" column="ORG_LEADER_SEX" jdbcType="VARCHAR"/>
  18. <result property="status" column="STATUS" jdbcType="INTEGER"/>
  19. <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
  20. <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
  21. <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
  22. <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
  23. <result property="parentId" column="parentId" jdbcType="INTEGER"/>
  24. <result property="parentName" column="parentName" jdbcType="VARCHAR"/>
  25. <result property="areaName" column="areaName" jdbcType="VARCHAR"/>
  26. </resultMap>
  27. <!-- 基本字段 -->
  28. <sql id="Base_Column_List">
  29. ID, TENANT_ID, ORG_TYPE, PARENT_ORG_ID, ORG_AREA_ID, ORG_NAME, ORG_STATE, REMARK, ORG_LEADER_NAME, ORG_LEADER_PHONE, ORG_LEADER_EMAIL, ORG_LEADER_SEX, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY </sql>
  30. <!-- 查询单个 -->
  31. <select id="selectById" resultMap="OrgMap">
  32. select a.id, a.tenant_id, a.org_type, a.parent_org_id, a.org_area_id, a.org_name, a.org_state, a.remark, a.org_leader_name, a.org_leader_phone, a.org_leader_email, a.org_leader_sex, a.status
  33. ,b.id parentId,b.ORG_NAME parentName,c.NAME areaName
  34. from uims_org a left join uims_org b on a.PARENT_ORG_ID=b.ID
  35. left join uims_area c on a.ORG_AREA_ID=c.id
  36. where a.ID = #{id}
  37. </select>
  38. <!-- 查询全部 -->
  39. <select id="selectAll" resultMap="OrgMap">
  40. select
  41. <include refid="Base_Column_List"/>
  42. from uims_org
  43. </select>
  44. <!--通过实体作为筛选条件查询-->
  45. <select id="selectList" resultMap="OrgMap">
  46. select
  47. <include refid="Base_Column_List"/>
  48. from uims_org
  49. <where>
  50. <if test="id != null">
  51. and ID = #{id}
  52. </if>
  53. <if test="tenantId != null and tenantId != ''">
  54. and TENANT_ID = #{tenantId}
  55. </if>
  56. <if test="orgType != null and orgType != ''">
  57. and ORG_TYPE = #{orgType}
  58. </if>
  59. <if test="parentOrgId != null">
  60. and PARENT_ORG_ID = #{parentOrgId}
  61. </if>
  62. <if test="orgAreaId != null">
  63. and ORG_AREA_ID = #{orgAreaId}
  64. </if>
  65. <if test="orgName != null and orgName != ''">
  66. and ORG_NAME = #{orgName}
  67. </if>
  68. <if test="orgState != null">
  69. and ORG_STATE = #{orgState}
  70. </if>
  71. <if test="remark != null and remark != ''">
  72. and REMARK = #{remark}
  73. </if>
  74. <if test="orgLeaderName != null and orgLeaderName != ''">
  75. and ORG_LEADER_NAME = #{orgLeaderName}
  76. </if>
  77. <if test="orgLeaderPhone != null and orgLeaderPhone != ''">
  78. and ORG_LEADER_PHONE = #{orgLeaderPhone}
  79. </if>
  80. <if test="orgLeaderEmail != null and orgLeaderEmail != ''">
  81. and ORG_LEADER_EMAIL = #{orgLeaderEmail}
  82. </if>
  83. <if test="orgLeaderSex != null and orgLeaderSex != ''">
  84. and ORG_LEADER_SEX = #{orgLeaderSex}
  85. </if>
  86. <if test="status != null">
  87. and STATUS = #{status}
  88. </if>
  89. <if test="dateCreate != null">
  90. and DATE_CREATE = #{dateCreate}
  91. </if>
  92. <if test="createBy != null and createBy != ''">
  93. and CREATE_BY = #{createBy}
  94. </if>
  95. <if test="dateUpdate != null">
  96. and DATE_UPDATE = #{dateUpdate}
  97. </if>
  98. <if test="updateBy != null and updateBy != ''">
  99. and UPDATE_BY = #{updateBy}
  100. </if>
  101. </where>
  102. </select>
  103. <!-- 新增所有列 -->
  104. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  105. insert into uims_org(ID, TENANT_ID, ORG_TYPE, PARENT_ORG_ID, ORG_AREA_ID, ORG_NAME, ORG_STATE, REMARK, ORG_LEADER_NAME, ORG_LEADER_PHONE, ORG_LEADER_EMAIL, ORG_LEADER_SEX, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
  106. values ( #{id}, #{tenantId}, #{orgType}, #{parentOrgId}, #{orgAreaId}, #{orgName}, #{orgState}, #{remark}, #{orgLeaderName}, #{orgLeaderPhone}, #{orgLeaderEmail}, #{orgLeaderSex}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
  107. </insert>
  108. <!-- 批量新增 -->
  109. <insert id="batchInsert">
  110. insert into uims_org(ID, TENANT_ID, ORG_TYPE, PARENT_ORG_ID, ORG_AREA_ID, ORG_NAME, ORG_STATE, REMARK,
  111. ORG_LEADER_NAME, ORG_LEADER_PHONE, ORG_LEADER_EMAIL, ORG_LEADER_SEX, STATUS, DATE_CREATE, CREATE_BY,
  112. DATE_UPDATE, UPDATE_BY)
  113. values
  114. <foreach collection="orgs" item="item" index="index" separator=",">
  115. (
  116. #{item.id}, #{item.tenantId}, #{item.orgType}, #{item.parentOrgId}, #{item.orgAreaId}, #{item.orgName},
  117. #{item.orgState}, #{item.remark}, #{item.orgLeaderName}, #{item.orgLeaderPhone}, #{item.orgLeaderEmail},
  118. #{item.orgLeaderSex}, #{item.status}, #{item.dateCreate}, #{item.createBy}, #{item.dateUpdate},
  119. #{item.updateBy} )
  120. </foreach>
  121. </insert>
  122. <!-- 通过主键修改数据 -->
  123. <update id="update">
  124. update uims.uims_org
  125. <set>
  126. <if test="tenantId != null and tenantId != ''">
  127. TENANT_ID = #{tenantId},
  128. </if>
  129. <if test="orgType != null and orgType != ''">
  130. ORG_TYPE = #{orgType},
  131. </if>
  132. <if test="parentOrgId != null">
  133. PARENT_ORG_ID = #{parentOrgId},
  134. </if>
  135. <if test="orgAreaId != null">
  136. ORG_AREA_ID = #{orgAreaId},
  137. </if>
  138. <if test="orgName != null and orgName != ''">
  139. ORG_NAME = #{orgName},
  140. </if>
  141. <if test="orgState != null">
  142. ORG_STATE = #{orgState},
  143. </if>
  144. <if test="remark != null and remark != ''">
  145. REMARK = #{remark},
  146. </if>
  147. <if test="orgLeaderName != null and orgLeaderName != ''">
  148. ORG_LEADER_NAME = #{orgLeaderName},
  149. </if>
  150. <if test="orgLeaderPhone != null and orgLeaderPhone != ''">
  151. ORG_LEADER_PHONE = #{orgLeaderPhone},
  152. </if>
  153. <if test="orgLeaderEmail != null and orgLeaderEmail != ''">
  154. ORG_LEADER_EMAIL = #{orgLeaderEmail},
  155. </if>
  156. <if test="orgLeaderSex != null and orgLeaderSex != ''">
  157. ORG_LEADER_SEX = #{orgLeaderSex},
  158. </if>
  159. <if test="status != null">
  160. STATUS = #{status},
  161. </if>
  162. <if test="dateCreate != null">
  163. DATE_CREATE = #{dateCreate},
  164. </if>
  165. <if test="createBy != null and createBy != ''">
  166. CREATE_BY = #{createBy},
  167. </if>
  168. <if test="dateUpdate != null">
  169. DATE_UPDATE = #{dateUpdate},
  170. </if>
  171. <if test="updateBy != null and updateBy != ''">
  172. UPDATE_BY = #{updateBy},
  173. </if>
  174. </set>
  175. where ID = #{id}
  176. </update>
  177. <!--通过主键删除-->
  178. <delete id="deleteById">
  179. delete from uims_org where ID = #{id}
  180. </delete>
  181. <!-- 总数 -->
  182. <select id="count" resultType="int">
  183. select count(*) from uims_org
  184. </select>
  185. <select id="selectPage" resultMap="OrgMap">
  186. select
  187. <include refid="Base_Column_List"/>
  188. from uims_org
  189. <where>
  190. status!=0
  191. <if test="org.id != null">
  192. and ID = #{org.id}
  193. </if>
  194. <if test="org.tenantId != null and org.tenantId != ''">
  195. and TENANT_ID = #{org.tenantId}
  196. </if>
  197. <if test="org.orgType != null and org.orgType != ''">
  198. and ORG_TYPE = #{org.orgType}
  199. </if>
  200. <if test="org.parentOrgId != null">
  201. and PARENT_ORG_ID = #{org.parentOrgId}
  202. </if>
  203. <if test="org.orgAreaId != null">
  204. and ORG_AREA_ID = #{org.orgAreaId}
  205. </if>
  206. <if test="org.orgName != null and org.orgName != ''">
  207. and ORG_NAME = #{org.orgName}
  208. </if>
  209. <if test="org.orgState != null">
  210. and ORG_STATE = #{org.orgState}
  211. </if>
  212. <if test="org.remark != null and org.remark != ''">
  213. and REMARK = #{org.remark}
  214. </if>
  215. <if test="org.orgLeaderName != null and org.orgLeaderName != ''">
  216. and ORG_LEADER_NAME = #{org.orgLeaderName}
  217. </if>
  218. <if test="org.orgLeaderPhone != null and org.orgLeaderPhone != ''">
  219. and ORG_LEADER_PHONE = #{org.orgLeaderPhone}
  220. </if>
  221. <if test="org.orgLeaderEmail != null and org.orgLeaderEmail != ''">
  222. and ORG_LEADER_EMAIL = #{org.orgLeaderEmail}
  223. </if>
  224. <if test="org.orgLeaderSex != null and org.orgLeaderSex != ''">
  225. and ORG_LEADER_SEX = #{org.orgLeaderSex}
  226. </if>
  227. <if test="org.status != null">
  228. and STATUS = #{org.status}
  229. </if>
  230. <if test="org.dateCreate != null">
  231. and DATE_CREATE = #{org.dateCreate}
  232. </if>
  233. <if test="org.createBy != null and org.createBy != ''">
  234. and CREATE_BY = #{org.createBy}
  235. </if>
  236. <if test="org.dateUpdate != null">
  237. and DATE_UPDATE = #{org.dateUpdate}
  238. </if>
  239. <if test="org.updateBy != null and org.updateBy != ''">
  240. and UPDATE_BY = #{org.updateBy}
  241. </if>
  242. </where>
  243. </select>
  244. <select id="findOrgUser" resultType="com.huaxu.entity.Org">
  245. select a.ID,a.ORG_NAME orgName from uims_org a join uims_user b on
  246. (a.ID=b.DEPT_ORG_ID or a.ID=b.COMPANY_ORG_ID)
  247. where a.id=#{id} and b.status!=0
  248. limit 1
  249. </select>
  250. <select id="selectTrees" resultType="com.huaxu.dto.OrgTree">
  251. select ID, TENANT_ID, ORG_TYPE, PARENT_ORG_ID, ORG_AREA_ID, ORG_NAME, ORG_STATE, REMARK, ORG_LEADER_NAME, ORG_LEADER_PHONE, ORG_LEADER_EMAIL, ORG_LEADER_SEX, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY
  252. from uims_org
  253. <where>
  254. and status!=0
  255. <if test="tenantId!=null ">
  256. and TENANT_ID=#{tenantId}
  257. </if>
  258. <if test="orgType=='company'||orgType=='department'">
  259. and ORG_TYPE=#{orgType}
  260. </if>
  261. <if test="id!=null">
  262. and id=#{id}
  263. </if>
  264. </where>
  265. </select>
  266. <select id="findOrgType" resultType="com.huaxu.entity.Org">
  267. select a.ORG_TYPE , b.ORG_TYPE parentType,c.ORG_TYPE childType
  268. from uims_org a left join uims_org b on a.PARENT_ORG_ID=b.ID
  269. left join uims_org c on a.id=c.PARENT_ORG_ID
  270. where a.id=#{id} limit 1
  271. </select>
  272. </mapper>