OfficeMapper.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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.jeeplus.modules.sys.mapper.OfficeMapper">
  4. <resultMap id="officeResult" type="Office">
  5. <id property="id" column="id" />
  6. <result property="parentIds" column="parent_ids" />
  7. <result property="name" column="name" />
  8. <result property="code" column="code" />
  9. <result property="type" column="type" />
  10. <result property="grade" column="grade" />
  11. <result property="address" column="address" />
  12. <result property="zipCode" column="zip_code" />
  13. <result property="master" column="master" />
  14. <result property="phone" column="phone" />
  15. <result property="fax" column="fax" />
  16. <result property="email" column="email" />
  17. <result property="useable" column="useable" />
  18. <result property="type" column="type" />
  19. <result property="remarks" column="remarks" />
  20. <association property="area" column="area_id" select="getArea" />
  21. <association property="hasChildren" column="id" select="hasChildren" />
  22. </resultMap>
  23. <sql id="officeColumns">
  24. a.id,
  25. a.parent_id AS "parent.id",
  26. a.parent_ids,
  27. a.area_id AS "area.id",
  28. a.code,
  29. a.name,
  30. a.sort,
  31. a.type,
  32. a.grade,
  33. a.address,
  34. a.zip_code,
  35. a.master,
  36. a.phone,
  37. a.fax,
  38. a.email,
  39. a.remarks,
  40. a.create_by AS "createBy.id",
  41. a.create_date,
  42. a.update_by AS "updateBy.id",
  43. a.update_date,
  44. a.del_flag,
  45. a.useable AS useable,
  46. a.primary_person AS "primaryPerson.id",
  47. a.deputy_person AS "deputyPerson.id",
  48. p.name AS "parent.name",
  49. ar.name AS "area.name",
  50. ar.parent_ids AS "area.parentIds",
  51. pp.name AS "primaryPerson.name",
  52. dp.name AS "deputyPerson.name"
  53. </sql>
  54. <sql id="officeJoins">
  55. LEFT JOIN sys_office p ON p.id = a.parent_id
  56. LEFT JOIN sys_area ar ON ar.id = a.area_id
  57. LEFT JOIN sys_user pp ON pp.id = a.primary_person
  58. LEFT JOIN sys_user dp ON dp.id = a.deputy_person
  59. </sql>
  60. <select id="getChildren" parameterType="String" resultMap="officeResult">
  61. select * from sys_office where parent_id = #{id} ORDER BY sort
  62. </select>
  63. <select id="getArea" parameterType="String" resultType="Area">
  64. select * from sys_area where id = #{id}
  65. </select>
  66. <select id="hasChildren" parameterType="String" resultType="Boolean">
  67. select case when exists(select 1 from sys_office where parent_id = #{id}) then 1 else 0 end ${dual}
  68. </select>
  69. <select id="get" resultType="Office">
  70. SELECT
  71. <include refid="officeColumns"/>
  72. FROM sys_office a
  73. <include refid="officeJoins"/>
  74. WHERE a.id = #{id}
  75. </select>
  76. <select id="getByCode" resultType="Office">
  77. SELECT
  78. <include refid="officeColumns"/>
  79. FROM sys_office a
  80. <include refid="officeJoins"/>
  81. WHERE a.code = #{code}
  82. </select>
  83. <select id="findList" resultType="Office">
  84. SELECT
  85. <include refid="officeColumns"/>
  86. FROM sys_office a
  87. <include refid="officeJoins"/>
  88. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  89. <!-- 数据范围过滤 -->
  90. ${dataScope}
  91. <if test="name != null and name != ''">
  92. AND a.name = #{name}
  93. </if>
  94. ORDER BY a.code
  95. </select>
  96. <select id="findAllList" resultType="Office">
  97. SELECT
  98. <include refid="officeColumns"/>
  99. FROM sys_office a
  100. <include refid="officeJoins"/>
  101. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  102. <!-- 数据范围过滤 -->
  103. ${dataScope}
  104. ORDER BY a.code
  105. </select>
  106. <select id="findByParentIdsLike" resultType="Office">
  107. SELECT
  108. <include refid="officeColumns"/>
  109. FROM sys_office a
  110. <include refid="officeJoins"/>
  111. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.parent_ids LIKE #{parentIds}
  112. ORDER BY a.code
  113. </select>
  114. <insert id="insert">
  115. INSERT INTO sys_office(
  116. id,
  117. parent_id,
  118. parent_ids,
  119. area_id,
  120. code,
  121. name,
  122. sort,
  123. type,
  124. grade,
  125. address,
  126. zip_code,
  127. master,
  128. phone,
  129. fax,
  130. email,
  131. create_by,
  132. create_date,
  133. update_by,
  134. update_date,
  135. remarks,
  136. del_flag,
  137. useable,
  138. primary_person,
  139. deputy_person
  140. ) VALUES (
  141. #{id},
  142. #{parent.id},
  143. #{parentIds},
  144. #{area.id},
  145. #{code},
  146. #{name},
  147. #{sort},
  148. #{type},
  149. #{grade},
  150. #{address},
  151. #{zipCode},
  152. #{master},
  153. #{phone},
  154. #{fax},
  155. #{email},
  156. #{createBy.id},
  157. #{createDate},
  158. #{updateBy.id},
  159. #{updateDate},
  160. #{remarks},
  161. #{delFlag},
  162. #{useable},
  163. #{primaryPerson.id},
  164. #{deputyPerson.id}
  165. )
  166. </insert>
  167. <update id="update">
  168. UPDATE sys_office SET
  169. parent_id = #{parent.id},
  170. parent_ids = #{parentIds},
  171. area_id = #{area.id},
  172. code = #{code},
  173. name = #{name},
  174. type = #{type},
  175. grade = #{grade},
  176. address = #{address},
  177. zip_code = #{zipCode},
  178. master = #{master},
  179. phone = #{phone},
  180. fax = #{fax},
  181. email = #{email},
  182. update_by = #{updateBy.id},
  183. update_date = #{updateDate},
  184. remarks = #{remarks},
  185. useable=#{useable},
  186. primary_person=#{primaryPerson.id},
  187. deputy_person=#{deputyPerson.id}
  188. WHERE id = #{id}
  189. </update>
  190. <update id="updateParentIds">
  191. UPDATE sys_office SET
  192. parent_id = #{parent.id},
  193. parent_ids = #{parentIds}
  194. WHERE id = #{id}
  195. </update>
  196. <update id="delete">
  197. DELETE FROM sys_office
  198. WHERE id = #{id} OR parent_ids LIKE
  199. <if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
  200. <if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
  201. <if test="dbName == 'mssql'">'%'+#{id}+'%'</if>
  202. </update>
  203. <update id="deleteByLogic">
  204. UPDATE sys_office SET
  205. del_flag = #{DEL_FLAG_DELETE}
  206. WHERE id = #{id} OR parent_ids LIKE
  207. <if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
  208. <if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
  209. <if test="dbName == 'mssql'">'%'+#{id}+'%'</if>
  210. </update>
  211. </mapper>