archiveMapper.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.gz.mapper.archive.ArchiveMapper">
  4. <select id="searchList" resultType="com.gz.rvo.archive.ArchiveRVO"
  5. parameterType="com.gz.vo.archive.SearchArchiveVO">
  6. SELECT
  7. d.dict_name mj_text,
  8. a.*
  9. FROM `tab_archives` a
  10. LEFT JOIN tab_dict d
  11. ON a.mj = d.dict_code
  12. LEFT JOIN tab_secondary_archive sa
  13. ON a.id = sa.archive_id
  14. LEFT JOIN tab_admin u on u.id = a.created
  15. <where>
  16. a.deleted = 0
  17. and ml IN (
  18. SELECT
  19. `code`
  20. FROM
  21. tab_archives_tree atr
  22. LEFT JOIN tab_menu_role tmr ON atr.id = tmr.menu_id
  23. WHERE
  24. tmr.role_id = #{roleId}
  25. AND tmr.role_type = 1
  26. )
  27. and mj in (select d.dict_code from tab_dict d left join tab_menu_role mr on d.id = mr.menu_id where
  28. mr.role_id = #{roleId} and mr.role_type = 2 )
  29. <if test="deptId!=null and deptId!=''">
  30. and u.dept_id = #{deptId}
  31. </if>
  32. <if test="dh != null and dh != ''">
  33. AND a.dh like concat(concat('%',#{dh}),'%')
  34. </if>
  35. <if test="mlh != null and mlh != ''">
  36. AND a.mlh = #{mlh}
  37. </if>
  38. <if test="wjbh != null and wjbh != ''">
  39. AND (a.wjbh like concat(concat('%',#{wjbh}),'%') OR sa.wh like concat(concat('%',#{wjbh}),'%'))
  40. </if>
  41. <if test="ml != null and ml != ''">
  42. AND (a.ml = #{ml} or a.ml in (select `code` FROM tab_archives_tree where parent_id = (SELECT id FROM `tab_archives_tree` where code = #{ml})))
  43. </if>
  44. <if test="bgqx != null and bgqx != ''">
  45. <choose>
  46. <when test="bgqx == 'D10' or bgqx == '005'">
  47. AND a.bgqx in ('D10','005')
  48. </when>
  49. <when test="bgqx == 'D30' or bgqx == '004'">
  50. AND a.bgqx in ('D30','004')
  51. </when>
  52. <when test="bgqx == 'Y'.toString() or bgqx == '001'">
  53. AND a.bgqx in ('Y','001')
  54. </when>
  55. <otherwise>
  56. AND a.bgqx = #{bgqx}
  57. </otherwise>
  58. </choose>
  59. </if>
  60. <if test="mj != null and mj != ''">
  61. AND a.mj = #{mj}
  62. </if>
  63. <if test="gdnd != null and gdnd != ''">
  64. AND a.gdnd = #{gdnd}
  65. </if>
  66. <if test="ztc != null and ztc != ''">
  67. AND (a.ztc like concat(concat('%',#{ztc}),'%') OR a.tm like concat(concat('%',#{ztc}),'%') OR sa.tm like concat(concat('%',#{ztc}),'%'))
  68. </if>
  69. <if test="sql != null and sql != ''">
  70. ${sql}
  71. </if>
  72. </where>
  73. group by a.id
  74. <if test="field != null and field != '' and order != null and order != ''">
  75. order by ${field} ${order}
  76. </if>
  77. </select>
  78. <select id="againSearchList" resultType="com.gz.rvo.archive.ArchiveRVO"
  79. parameterType="com.gz.vo.archive.SearchArchiveVO">
  80. SELECT
  81. a.*
  82. FROM (${searchSql}) a
  83. <where>
  84. <if test="dh != null and dh != ''">
  85. AND a.dh like concat(concat('%',#{dh}),'%')
  86. </if>
  87. <if test="mlh != null and mlh != ''">
  88. AND a.mlh = #{mlh}
  89. </if>
  90. <if test="wjbh != null and wjbh != ''">
  91. AND (a.wjbh like concat(concat('%',#{wjbh}),'%') OR sa.wh like concat(concat('%',#{wjbh}),'%'))
  92. </if>
  93. <if test="ml != null and ml != ''">
  94. AND a.ml = #{ml} or a.ml in (select `code` FROM tab_archives_tree where parent_id = (SELECT id FROM `tab_archives_tree` where code = #{ml}))
  95. </if>
  96. <if test="bgqx != null and bgqx != ''">
  97. AND a.bgqx = #{bgqx}
  98. </if>
  99. <if test="gdnd != null and gdnd != ''">
  100. AND a.gdnd = #{gdnd}
  101. </if>
  102. <if test="mj != null and mj != ''">
  103. AND a.mj = #{mj}
  104. </if>
  105. <if test="ztc != null and ztc != ''">
  106. AND (a.ztc like concat(concat('%',#{ztc}),'%') OR a.tm like concat(concat('%',#{ztc}),'%'))
  107. </if>
  108. <if test="sql != null and sql != ''">
  109. ${sql}
  110. </if>
  111. </where>
  112. <if test="field != null and field != '' and order != null and order != ''">
  113. order by ${field} ${order}
  114. </if>
  115. </select>
  116. <select id="selectBorrowList" resultType="com.gz.rvo.borrow.ArchiveBorrowListRVO" parameterType="int">
  117. <![CDATA[
  118. SELECT IF
  119. (
  120. (SELECT count(admin_id) num
  121. FROM tab_archive_borrow ab
  122. WHERE ab.archive_id = a.id
  123. AND ab.borrow_type = 1
  124. AND ab.audit_status = 2
  125. AND ab.return_status = 0) <= 0,
  126. '可借阅',
  127. '已借阅'
  128. ) original_status,
  129. a.*
  130. FROM tab_archives a
  131. WHERE a.deleted = 0
  132. and a.ml IN (
  133. SELECT `code`
  134. FROM tab_archives_tree atr
  135. LEFT JOIN tab_menu_role tmr ON atr.id = tmr.menu_id
  136. WHERE tmr.role_id = #{roleId}
  137. AND tmr.role_type = 1
  138. )
  139. and a.mj in (select d.dict_code
  140. from tab_dict d
  141. left join tab_menu_role mr on d.id = mr.menu_id
  142. where mr.role_id = #{roleId}
  143. and mr.role_type = 2)
  144. ]]>
  145. </select>
  146. <select id="selectMaxJH" resultType="java.lang.Integer" parameterType="string">
  147. SELECT max(jh) + 1
  148. from tab_archives
  149. where deleted = 0
  150. and ml = #{mlCode}
  151. </select>
  152. <select id="selectRoleAll" resultType="com.gz.dto.archive.ArchiveDTO" parameterType="int">
  153. SELECT *
  154. FROM tab_archives
  155. WHERE deleted = 0
  156. and ml IN (
  157. SELECT `code`
  158. FROM tab_archives_tree atr
  159. LEFT JOIN tab_menu_role tmr ON atr.id = tmr.menu_id
  160. WHERE tmr.role_id = #{roleId}
  161. AND tmr.role_type = 1
  162. )
  163. and mj in (select d.dict_code
  164. from tab_dict d
  165. left join tab_menu_role mr on d.id = mr.menu_id
  166. where mr.role_id = #{roleId}
  167. and mr.role_type = 2)
  168. order by create_time desc
  169. </select>
  170. <select id="selectByRolePrimaryKey" resultType="com.gz.dto.archive.ArchiveDTO" parameterType="int">
  171. SELECT *
  172. FROM tab_archives
  173. WHERE deleted = 0
  174. and id = #{id}
  175. and ml IN (
  176. SELECT `code`
  177. FROM tab_archives_tree atr
  178. LEFT JOIN tab_menu_role tmr ON atr.id = tmr.menu_id
  179. WHERE tmr.role_id = #{roleId}
  180. AND tmr.role_type = 1
  181. )
  182. and mj in (select d.dict_code
  183. from tab_dict d
  184. left join tab_menu_role mr on d.id = mr.menu_id
  185. where mr.role_id = #{roleId}
  186. and mr.role_type = 2)
  187. order by create_time desc
  188. </select>
  189. <select id="selectByPrimaryKeyText" resultType="com.gz.rvo.archive.ArchiveRVO">
  190. SELECT IF
  191. (
  192. atr.parent_id = - 1,
  193. atr.title,
  194. concat(
  195. concat((SELECT c.title FROM tab_archives_tree c WHERE c.id = atr.parent_id), '-'),
  196. atr.title
  197. )
  198. ) mlText,
  199. d.dict_name mjText,
  200. d1.dict_name bgqxText,
  201. a.*
  202. FROM tab_archives a
  203. LEFT JOIN tab_archives_tree atr ON a.ml = atr.CODE
  204. left join tab_dict d on a.mj = d.dict_code
  205. left join tab_dict d1 on a.bgqx = d1.dict_code
  206. where a.deleted = 0
  207. and d.deleted = 0
  208. and atr.deleted = 0
  209. and a.id = #{id}
  210. </select>
  211. <select id="selectByPk" resultType="com.gz.rvo.archive.ArchiveRVO" parameterType="int">
  212. SELECT
  213. d.dict_name mj_text,
  214. d1.dict_name bgqx_text,
  215. d2.title ml_Text,
  216. a.*
  217. FROM `tab_archives` a
  218. LEFT JOIN tab_dict d ON a.mj = d.dict_code
  219. LEFT JOIN tab_dict d1 ON a.bgqx = d1.dict_code
  220. LEFT JOIN tab_archives_tree d2 ON a.ml = d2.code
  221. where a.deleted = 0
  222. and a.id = #{id}
  223. </select>
  224. <select id="selectByDh" resultType="com.gz.rvo.archive.ArchiveRVO" parameterType="string">
  225. SELECT
  226. d.dict_name mj_text,
  227. d1.dict_name bgqx_text,
  228. d2.title ml_Text,
  229. a.*
  230. FROM `tab_archives` a
  231. LEFT JOIN tab_dict d ON a.mj = d.dict_code
  232. LEFT JOIN tab_dict d1 ON a.bgqx = d1.dict_code
  233. LEFT JOIN tab_archives_tree d2 ON a.ml = d2.code
  234. where a.deleted = 0
  235. and a.dh = #{dh}
  236. </select>
  237. <select id="getMenuId" resultType="int">
  238. select menu_id from tab_menu_role where role_id = #{id} and role_type = 4
  239. </select>
  240. <select id="getDeptId" resultType="string">
  241. select dept_id from tab_admin where id=#{id}
  242. </select>
  243. </mapper>