ScratchWordsMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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="cn.cslg.pas.mapper.ScratchWordsMapper">
  4. <!--namespace根据自己需要创建的的mapper的路径和名称填写-->
  5. <select id="querySW" resultMap="querySWResultMap">
  6. select * from scratch_words
  7. <where>
  8. patent_no = #{patentNo}
  9. and(
  10. <if test="projectId != null and reportId != null and createId != null and tenantId != null">
  11. -- 所有地方可见/公开
  12. (range_type = "false" and permission_type = 1 and tenant_id = #{tenantId})
  13. -- 所有地方可见/私有
  14. or(range_type = "false" and permission_type = 0 and create_id = #{createId})
  15. -- 只在来源出可见/公开
  16. or(range_type = "true" and create_from = 2 and range_id = #{reportId} and permission_type = 1 and
  17. tenant_id = #{tenantId})
  18. or(range_type = "true" and create_from = 1 and range_id = #{projectId} and permission_type = 1 and
  19. tenant_id = #{tenantId})
  20. or(create_from = 0 and permission_type = 1 and tenant_id = #{tenantId})
  21. -- 只在来源出可见/私有
  22. or(range_type = "true" and create_from = 2 and range_id = #{reportId} and permission_type = 0 and
  23. create_id = #{createId})
  24. or(range_type = "true" and create_from = 1 and range_id = #{projectId} and permission_type = 0 and
  25. create_id = #{createId})
  26. or(create_from = 0 and permission_type = 0 and create_id = #{createId})
  27. </if>
  28. )
  29. </where>
  30. </select>
  31. <resultMap id="querySWResultMap" type="cn.cslg.pas.common.model.vo.ScratchWordsVO">
  32. <id column="id" property="id"/>
  33. <result column="create_id" property="createId"/>
  34. <result column="tenant_id" property="tenantId"/>
  35. <result column="patent_no" property="patentNo"/>
  36. <result column="position" property="position"/>
  37. <result column="text" property="text"/>
  38. <result column="scratch_field" property="scratchField"/>
  39. <result column="scratch_type" property="scratchType"/>
  40. <result column="color" property="color"/>
  41. <result column="remark" property="remark"/>
  42. <result column="create_from" property="createFrom"/>
  43. <result column="range_id" property="rangeId"/>
  44. <result column="permission_type" property="permissionType"/>
  45. <result column="range_type" property="rangeType"/>
  46. </resultMap>
  47. <select id="selectByConditions" resultMap="querySWResultMap">
  48. SELECT id, create_id, tenant_id, patent_no, create_from, range_id, permission_type, range_type
  49. FROM scratch_words
  50. WHERE patent_no = #{patentNo}
  51. <!-- 如果公开范围为 F,公开类型为 1,公司名为 tenantId,则拼接该条件 -->
  52. <if test="rangeType == 'F' and permissionType == 1 and tenantId != null">
  53. AND range_type = 'F' AND permission_type = 1 AND tenant_id = #{tenantId}
  54. </if>
  55. <!-- 如果公开范围为 F,公开类型为 0,创建人为 createId,则拼接该条件 -->
  56. <if test="rangeType == 'F' and permissionType == 0 and createId != null">
  57. AND range_type = 'F' AND permission_type = 0 AND create_id = #{createId}
  58. </if>
  59. <!-- 如果公开范围为 T,创建来源为 2,抽象id为 reportId,公开类型为 1,公司名为 tenantId,则拼接该条件 -->
  60. <if test="rangeType == 'T' and createFrom == 2 and rangeId == 'reportId' and permissionType == 1 and tenantId != null">
  61. AND range_type = 'T' AND create_from = 2 AND range_id = 'reportId' AND permission_type = 1 AND tenant_id =
  62. #{tenantId}
  63. </if>
  64. <!-- 如果公开范围为 T,创建来源为 2,抽象id为 reportId,公开类型为 0,创建人为 createId,则拼接该条件 -->
  65. <if test="rangeType == 'T' and createFrom == 2 and rangeId == 'reportId' and permissionType == 0 and createId != null">
  66. AND range_type = 'T' AND create_from = 2 AND range_id = 'reportId' AND permission_type = 0 AND create_id =
  67. #{createId}
  68. </if>
  69. </select>
  70. <select id="queryScratchWords" resultMap="queryScratchWordsResultMap">
  71. select * from scratch_words
  72. <where>
  73. <if test="true">
  74. 1 = 1
  75. and(
  76. -- 所有地方可见/公开
  77. (range_type = "false" and permission_type = 1 and tenant_id = #{tenantId})
  78. -- 所有地方可见/私有
  79. or(range_type = "false" and permission_type = 0 and create_id = #{personId})
  80. -- 只在来源出可见/公开
  81. or(range_type = "true" and create_from = 2 and range_id in (
  82. <foreach collection="reportIds" item="n" separator=",">
  83. #{n}
  84. </foreach>)
  85. and permission_type = 1 and
  86. tenant_id = #{tenantId})
  87. or(range_type = "true" and create_from = 1 and range_id in (
  88. <foreach collection="projectIds" item="n" separator=",">
  89. #{n}
  90. </foreach>)
  91. and permission_type = 1 and
  92. tenant_id = #{tenantId})
  93. or(create_from = 0 and permission_type = 1 and tenant_id = #{tenantId})
  94. -- 只在来源出可见/私有
  95. or(range_type = "true" and create_from = 2 and range_id in (
  96. <foreach collection="reportIds" item="n" separator=",">
  97. #{n}
  98. </foreach>)
  99. and permission_type = 0 and
  100. create_id = #{personId})
  101. or(range_type = "true" and create_from = 1 and range_id in (
  102. <foreach collection="projectIds" item="n" separator=",">
  103. #{n}
  104. </foreach>)
  105. and permission_type = 0 and
  106. create_id = #{personId})
  107. or(create_from = 0 and permission_type = 0 and create_id = #{personId})
  108. )
  109. </if>
  110. <if test="search != null and search.size > 0">
  111. <foreach collection="search" item="searchItem">
  112. <if test="searchItem.value == 'remark'">
  113. and remark like '%${searchItem.content}%'
  114. </if>
  115. <if test="searchItem.value == 'patentNo'">
  116. and patent_no like '%${searchItem.content}%'
  117. </if>
  118. <if test="searchItem.value == 'date'">
  119. and create_time like '%${searchItem.content}%'
  120. </if>
  121. </foreach>
  122. </if>
  123. <if test="createIds != null and createIds.size > 0">
  124. and create_id in (
  125. <foreach collection="createIds" item="createId" separator=",">
  126. #{createId}
  127. </foreach>
  128. )
  129. </if>
  130. </where>
  131. order by create_time desc
  132. </select>
  133. <resultMap id="queryScratchWordsResultMap" type="cn.cslg.pas.common.model.vo.ScratchWordVO">
  134. <id column="id" property="id"/>
  135. <result column="create_id" property="createId"/>
  136. <result column="remark" property="remark"/>
  137. <result column="patent_no" property="patentNo"/>
  138. <result column="name" property="name"/>
  139. <result column="create_time" property="date"/>
  140. <result column="scratch_field" property="scratchField"/>
  141. <result column="text" property="text"/>
  142. <result column="color" property="color"/>
  143. <result column="scratch_type" property="scratchType"/>
  144. <result column="create_from" property="createFrom"/>
  145. <result column="range_id" property="rangeId"/>
  146. <result column="permission_type" property="permissionType"/>
  147. <result column="range_type" property="rangeType"/>
  148. </resultMap>
  149. <select id="queryGroupScratchs" resultMap="queryGroupScratchsResultMap">
  150. select create_id,
  151. patent_no,
  152. DATE_FORMAT(create_time, '%Y-%m-%d') as YmD
  153. from scratch_words
  154. <where>
  155. <if test="true">
  156. 1 = 1
  157. and(
  158. -- 所有地方可见/公开
  159. (range_type = "false" and permission_type = 1 and tenant_id = #{tenantId})
  160. -- 所有地方可见/私有
  161. or(range_type = "false" and permission_type = 0 and create_id = #{personId})
  162. -- 只在来源出可见/公开
  163. or(range_type = "true" and create_from = 2 and range_id in (
  164. <foreach collection="reportIds" item="n" separator=",">
  165. #{n}
  166. </foreach>)
  167. and permission_type = 1 and
  168. tenant_id = #{tenantId})
  169. or(range_type = "true" and create_from = 1 and range_id in (
  170. <foreach collection="projectIds" item="n" separator=",">
  171. #{n}
  172. </foreach>)
  173. and permission_type = 1 and
  174. tenant_id = #{tenantId})
  175. or(create_from = 0 and permission_type = 1 and tenant_id = #{tenantId})
  176. -- 只在来源出可见/私有
  177. or(range_type = "true" and create_from = 2 and range_id in (
  178. <foreach collection="reportIds" item="n" separator=",">
  179. #{n}
  180. </foreach>)
  181. and permission_type = 0 and
  182. create_id = #{personId})
  183. or(range_type = "true" and create_from = 1 and range_id in (
  184. <foreach collection="projectIds" item="n" separator=",">
  185. #{n}
  186. </foreach>)
  187. and permission_type = 0 and
  188. create_id = #{personId})
  189. or(create_from = 0 and permission_type = 0 and create_id = #{personId})
  190. )
  191. </if>
  192. <if test="search != null and search.size > 0">
  193. <foreach collection="search" item="searchItem">
  194. <if test="searchItem.value == 'remark'">
  195. and remark like '%${searchItem.content}%'
  196. </if>
  197. <if test="searchItem.value == 'patentNo'">
  198. and patent_no like '%${searchItem.content}%'
  199. </if>
  200. <if test="searchItem.value == 'date'">
  201. and create_time like '%${searchItem.content}%'
  202. </if>
  203. </foreach>
  204. </if>
  205. <if test="createIds != null and createIds.size > 0">
  206. and create_id in (
  207. <foreach collection="createIds" item="createId" separator=",">
  208. #{createId}
  209. </foreach>
  210. )
  211. </if>
  212. </where>
  213. group by
  214. <if test="grouping != null and grouping == 'name'">
  215. create_id
  216. </if>
  217. <if test="grouping != null and grouping == 'patentNo'">
  218. patent_no
  219. </if>
  220. <if test="grouping != null and grouping == 'date'">
  221. YmD
  222. </if>
  223. order by create_time desc
  224. </select>
  225. <resultMap id="queryGroupScratchsResultMap" type="cn.cslg.pas.domain.GroupName">
  226. <result column="create_id" property="createId"/>
  227. <result column="patent_no" property="patentNo"/>
  228. <result column="YmD" property="date"/>
  229. </resultMap>
  230. </mapper>