OcMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.zhyc.xps.sys.mapper.OcMapper">
  4. <resultMap id="BaseResultMap" type="com.zhyc.xps.sys.entity.Oc">
  5. <result column="oc_id" property="ocId" jdbcType="BIGINT" />
  6. <result column="oc_name" property="ocName" jdbcType="VARCHAR"/>
  7. <result column="oc_type_id" property="ocTypeId" jdbcType="BIGINT" />
  8. <result column="root_id" property="rootId" jdbcType="BIGINT" />
  9. <result column="parent_id" property="parentId" jdbcType="BIGINT" />
  10. <result column="admin_id" property="adminId" jdbcType="BIGINT" />
  11. <result column="group_id" property="groupId" jdbcType="BIGINT" />
  12. <result column="node_left" property="nodeLeft" jdbcType="BIGINT" />
  13. <result column="node_right" property="nodeRight" jdbcType="BIGINT" />
  14. <result column="node_level" property="nodeLevel" jdbcType="BIGINT" />
  15. <result column="is_leaf" property="isLeaf" jdbcType="BIGINT" />
  16. <result column="status" property="status" jdbcType="BIGINT" />
  17. <result column="if_lic" property="ifLic" jdbcType="BIGINT" />
  18. </resultMap>
  19. <resultMap id="OcDtoResultMap" type="com.zhyc.xps.sys.dto.OcDto" extends="BaseResultMap">
  20. <result column="admin_name" property="adminName" jdbcType="VARCHAR"/>
  21. </resultMap>
  22. <resultMap id="AdminDtoMap" type="com.zhyc.xps.sys.dto.AdminDto">
  23. <result column="oc_id" property="ocId" jdbcType="BIGINT" />
  24. <result column="admin_id" property="adminId" jdbcType="BIGINT" />
  25. <result column="admin_name" property="adminName" jdbcType="VARCHAR"/>
  26. <result column="admin_phone" property="adminPhone" jdbcType="VARCHAR"/>
  27. </resultMap>
  28. <sql id="OcDto_Cols">
  29. A.oc_id,
  30. A.oc_name,
  31. A.oc_type_id,
  32. A.root_id,
  33. A.parent_id,
  34. A.admin_id,
  35. B.account_name AS admin_name,
  36. A.group_id,
  37. A.node_left,
  38. A.node_right,
  39. A.node_level,
  40. A.is_leaf,
  41. A.status,
  42. A.if_lic
  43. </sql>
  44. <sql id="AdminDto_Cols">
  45. A.oc_id,
  46. A.admin_id,
  47. B.account_name AS admin_name,
  48. B.account_phone AS admin_phone
  49. </sql>
  50. <!--基于ID查询-->
  51. <select id="getById" resultMap="OcDtoResultMap">
  52. SELECT
  53. <include refid="OcDto_Cols"/>
  54. FROM oc AS A
  55. LEFT JOIN account AS B ON (A.oc_id = B.oc_id AND A.admin_id = B.account_id)
  56. WHERE A.oc_id = #{ocId ,jdbcType=BIGINT}
  57. </select>
  58. <!--分页查询-->
  59. <select id="getByPage" parameterType="java.util.Map" resultMap="BaseResultMap">
  60. SELECT
  61. <include refid="OcDto_Cols"/>
  62. FROM oc AS A
  63. LEFT JOIN account AS B ON (A.oc_id = B.oc_id AND A.admin_id = B.account_id)
  64. WHERE A.deleted_flag = 0
  65. <if test="ocTypeId != null">
  66. AND A.oc_type_id = #{ocTypeId ,jdbcType=BIGINT}
  67. </if>
  68. <if test="keywords != null and keywords != ''">
  69. AND A.oc_name LIKE "%"#{keywords}"%"
  70. </if>
  71. ORDER BY A.oc_id DESC
  72. </select>
  73. <!--列表查询-->
  74. <select id="getByList" parameterType="java.util.Map" resultMap="BaseResultMap">
  75. SELECT
  76. <include refid="OcDto_Cols"/>
  77. FROM oc AS A
  78. LEFT JOIN account AS B ON (A.oc_id = B.oc_id AND A.admin_id = B.account_id)
  79. WHERE A.deleted_flag = 0
  80. <if test="ocTypeId != null">
  81. AND A.oc_type_id = #{ocTypeId ,jdbcType = BIGINT}
  82. </if>
  83. <if test="keywords != null and keywords != ''">
  84. AND A.oc_name LIKE "%"#{keywords}"%"
  85. </if>
  86. ORDER BY A.oc_id DESC
  87. </select>
  88. <!--Get Admin-->
  89. <select id="getAdmin" resultMap="AdminDtoMap">
  90. SELECT
  91. <include refid="AdminDto_Cols"/>
  92. FROM oc AS A
  93. LEFT JOIN account AS B ON (A.oc_id = B.oc_id AND A.admin_id = B.account_id)
  94. WHERE A.deleted_flag=0
  95. AND A.oc_id = #{ocId, jdbcType=BIGINT}
  96. </select>
  97. <!--新增Create-->
  98. <insert id="create" parameterType="com.zhyc.xps.sys.entity.Oc">
  99. INSERT INTO oc
  100. <trim prefix="(" suffix=")" suffixOverrides=",">
  101. <if test="ocId != null">
  102. oc_id,
  103. </if>
  104. <if test="ocName != null and ocName != ''">
  105. oc_name,
  106. </if>
  107. <if test="ocTypeId != null">
  108. oc_type_id,
  109. </if>
  110. <if test="rootId != null">
  111. root_id,
  112. </if>
  113. <if test="parentId != null">
  114. parent_id,
  115. </if>
  116. <if test="adminId != null">
  117. admin_id,
  118. </if>
  119. <if test="groupId != null">
  120. group_id,
  121. </if>
  122. <if test="nodeLeft != null">
  123. node_left,
  124. </if>
  125. <if test="nodeRight != null">
  126. node_right,
  127. </if>
  128. <if test="nodeLevel != null">
  129. node_level,
  130. </if>
  131. <if test="isLeaf != null">
  132. is_leaf,
  133. </if>
  134. <if test="status != null">
  135. status,
  136. </if>
  137. <if test="createdBy != null">
  138. created_by,
  139. </if>
  140. <if test="createdAt != null">
  141. created_at,
  142. </if>
  143. </trim>
  144. <trim prefix="values (" suffix=")" suffixOverrides=",">
  145. <if test="ocId != null ">
  146. #{ocId ,jdbcType=BIGINT},
  147. </if>
  148. <if test="ocName != null and ocName != ''">
  149. #{ocName ,jdbcType=VARCHAR},
  150. </if>
  151. <if test="ocTypeId != null">
  152. #{ocTypeId ,jdbcType=BIGINT},
  153. </if>
  154. <if test="rootId != null">
  155. #{rootId ,jdbcType=BIGINT},
  156. </if>
  157. <if test="parentId != null">
  158. #{parentId ,jdbcType=BIGINT},
  159. </if>
  160. <if test="adminId != null">
  161. #{adminId ,jdbcType=BIGINT},
  162. </if>
  163. <if test="groupId != null">
  164. #{groupId ,jdbcType=BIGINT},
  165. </if>
  166. <if test="nodeLeft != null">
  167. #{nodeLeft ,jdbcType=BIGINT},
  168. </if>
  169. <if test="nodeRight != null">
  170. #{nodeRight ,jdbcType=BIGINT},
  171. </if>
  172. <if test="nodeLevel != null">
  173. #{nodeLevel ,jdbcType=BIGINT},
  174. </if>
  175. <if test="isLeaf != null">
  176. #{isLeaf ,jdbcType=BIGINT},
  177. </if>
  178. <if test="status != null">
  179. #{status ,jdbcType=BIGINT},
  180. </if>
  181. <if test="createdBy != null">
  182. #{createdBy ,jdbcType=BIGINT},
  183. </if>
  184. <if test="createdAt != null">
  185. #{createdAt ,jdbcType=TIMESTAMP},
  186. </if>
  187. </trim>
  188. </insert>
  189. <!--更新-->
  190. <update id="update" parameterType="com.zhyc.xps.sys.entity.Oc">
  191. UPDATE oc
  192. <trim suffixOverrides=",">
  193. <set>
  194. <if test="ocName != null and ocName != ''">
  195. oc_name = #{ocName, jdbcType=VARCHAR},
  196. </if>
  197. <if test="ocTypeId != null">
  198. oc_type_id = #{ocTypeId ,jdbcType=BIGINT},
  199. </if>
  200. <if test="rootId != null">
  201. root_id = #{rootId ,jdbcType=BIGINT},
  202. </if>
  203. <if test="parentId != null">
  204. parent_id = #{parentId ,jdbcType=BIGINT},
  205. </if>
  206. <if test="adminId != null">
  207. admin_id = #{adminId ,jdbcType=BIGINT},
  208. </if>
  209. <if test="groupId != null">
  210. group_id = #{groupId ,jdbcType=BIGINT},
  211. </if>
  212. <if test="nodeLeft != null">
  213. node_left = #{nodeLeft ,jdbcType=BIGINT},
  214. </if>
  215. <if test="nodeRight != null">
  216. node_right = #{nodeRight ,jdbcType=BIGINT},
  217. </if>
  218. <if test="nodeLevel != null">
  219. node_level = #{nodeLevel ,jdbcType=BIGINT},
  220. </if>
  221. <if test="isLeaf != null">
  222. is_leaf = #{isLeaf ,jdbcType=BIGINT},
  223. </if>
  224. <if test="status != null">
  225. status = #{status ,jdbcType=BIGINT},
  226. </if>
  227. <if test="ifLic != null">
  228. if_lic = #{ifLic ,jdbcType=BIGINT},
  229. </if>
  230. <if test="updatedBy != null ">
  231. updated_by = #{updatedBy ,jdbcType=BIGINT},
  232. </if>
  233. <if test="updatedAt != null">
  234. updated_at = #{updatedAt ,jdbcType=TIMESTAMP},
  235. </if>
  236. </set>
  237. </trim>
  238. WHERE oc_Id = #{ocId ,jdbcType=BIGINT}
  239. </update>
  240. <!--删除-->
  241. <update id="delete" parameterType="java.util.Map">
  242. UPDATE oc
  243. <trim prefix="set" suffixOverrides=",">
  244. <if test="deletedFlag != null">
  245. deleted_flag = #{deletedFlag,jdbcType=BIGINT},
  246. </if>
  247. <if test="deletedAt != null">
  248. deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
  249. </if>
  250. <if test="deletedBy != null">
  251. deleted_by = #{deletedBy,jdbcType=BIGINT}
  252. </if>
  253. </trim>
  254. WHERE 1=1
  255. <if test="ocId != null">
  256. AND oc_id = #{ocId ,jdbcType=BIGINT}
  257. </if>
  258. <if test="parentId != null">
  259. AND parent_id = #{parentId ,jdbcType=BIGINT}
  260. </if>
  261. <if test="nodeLeft != null and nodeRight != null">
  262. <![CDATA[
  263. AND node_left >= #{nodeLeft ,jdbcType=BIGINT}
  264. AND node_right <= #{nodeRight ,jdbcType=BIGINT}
  265. ]]>
  266. </if>
  267. </update>
  268. <!--获取子公司的数目-->
  269. <select id="countOfSub" resultType="java.lang.Long">
  270. SELECT count(*)
  271. FROM oc
  272. WHERE deleted_flag = 0
  273. AND parent_id = #{parentId, jdbcType=BIGINT}
  274. </select>
  275. </mapper>