StructureMapper.xml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.StructureMapper">
  4. <!--插入数据-->
  5. <!--int insert(Structure structure);-->
  6. <insert id="insert" useGeneratedKeys="true" keyProperty="id">
  7. insert into structure (parent_id, structure_name, path, remark, product_id, create_person_id,
  8. create_person_name)
  9. values (#{parentId}, #{structureName}, #{path}, #{remark}, #{productId}, #{createPersonId},
  10. #{createPersonName});
  11. </insert>
  12. <!--根据id删除数据-->
  13. <!--int deleteById(Integer id);-->
  14. <delete id="deleteById">
  15. delete
  16. from structure
  17. where id = #{id}
  18. </delete>
  19. <!--根据id批量删除数据-->
  20. <!--int deleteByIds(List<Integer> ids);-->
  21. <delete id="deleteByIds">
  22. delete
  23. from structure
  24. where id in (
  25. <foreach collection="list" item="n" separator=",">
  26. #{n}
  27. </foreach>
  28. )
  29. </delete>
  30. <!--根据id修改数据-->
  31. <!--int update(Structure structure);-->
  32. <update id="update">
  33. update structure
  34. <set>
  35. <if test="parentId != null">
  36. parent_id = #{parentId},
  37. </if>
  38. <if test="structureName != null">
  39. structure_name = #{structureName},
  40. </if>
  41. <if test="path != null">
  42. path = #{path},
  43. </if>
  44. <if test="remark != null">
  45. remark = #{remark},
  46. </if>
  47. <if test="productId != null">
  48. product_id = #{productId},
  49. </if>
  50. </set>
  51. where id = #{id}
  52. </update>
  53. <!--根据父级id和名称和架构id统计数量-->
  54. <!--int countByparentIdAndStructureName(Integer parentId, String structureName, Integer structureId);-->
  55. <select id="countByparentIdAndStructureName" resultType="int">
  56. select count(*)
  57. from structure
  58. where
  59. parent_id = #{parentId}
  60. and structure_name = #{structureName}
  61. <if test="structureId != null">
  62. and id != #{structureId}
  63. </if>
  64. </select>
  65. <!--根据id查询数据-->
  66. <!--Structure selectById(Integer id);-->
  67. <select id="getStandardById" resultMap="getStandardByIdMap">
  68. select id,
  69. parent_id,
  70. structure_name,
  71. path,
  72. remark,
  73. product_id,
  74. create_person_name,
  75. create_time
  76. from structure
  77. where id = #{id}
  78. </select>
  79. <resultMap id="getStandardByIdMap" type="cn.cslg.pas.domain.Structure">
  80. <id column="id" property="id"/>
  81. <result column="parent_id" property="parentId"/>
  82. <result column="structure_name" property="structureName"/>
  83. <result column="path" property="path"/>
  84. <result column="remark" property="remark"/>
  85. <result column="product_id" property="productId"/>
  86. <result column="create_person_name" property="createPersonName"/>
  87. <result column="create_time" property="createTime"/>
  88. </resultMap>
  89. <!--根据id查询数据和图片-->
  90. <!--StructureVO getStandAndPictureById(Integer id);-->
  91. <!-- <select id="getStandardAndPictureById" resultMap="selectByParentIdMap">-->
  92. <!-- select id s_id,-->
  93. <!-- parent_id,-->
  94. <!-- structure_name,-->
  95. <!-- path,-->
  96. <!-- remark,-->
  97. <!-- product_id,-->
  98. <!-- create_person_name,-->
  99. <!-- create_time-->
  100. <!-- from structure-->
  101. <!-- where id = #{id}-->
  102. <!-- </select>-->
  103. <select id="getStandardAndPictureById" resultMap="selectTreeMap">
  104. select stru.id as stru_id,
  105. stru.parent_id,
  106. stru.structure_name,
  107. stru.path,
  108. stru.remark,
  109. stru.product_id,
  110. stru.create_person_name,
  111. stru.create_time,
  112. count(distinct struP.patent_no) as patent_num
  113. from structure stru
  114. left join asso_structure_patent struP on find_in_set(stru.id, struP.path)
  115. where stru.id = #{id}
  116. </select>
  117. <!--根据父级id和产品id查询数据-->
  118. <!--List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId, List<Integer> ids);-->
  119. <select id="selectByParentIdAndProductId" resultMap="selectByParentIdMap">
  120. select id s_id,
  121. parent_id,
  122. structure_name,
  123. path,
  124. remark,
  125. product_id,
  126. create_person_name,
  127. create_time
  128. from structure
  129. where parent_id = #{parentId}
  130. and product_id = #{productId}
  131. <if test="ids != null">
  132. and id in
  133. <foreach collection="ids" item="item" separator="," open="(" close=")">
  134. #{item}
  135. </foreach>
  136. </if>
  137. order by s_id
  138. </select>
  139. <resultMap id="selectByParentIdMap" type="cn.cslg.pas.common.model.vo.StructureVO">
  140. <id column="s_id" property="id"/>
  141. <result column="parent_id" property="parentId"/>
  142. <result column="structure_name" property="structureName"/>
  143. <result column="path" property="path"/>
  144. <result column="remark" property="remark"/>
  145. <result column="product_id" property="productId"/>
  146. <result column="create_person_name" property="createPersonName"/>
  147. <result column="create_time" property="createTime"/>
  148. <collection property="pictures" ofType="cn.cslg.pas.common.model.vo.StructurePictureVO"
  149. select="selectByParentId2" column="s_id">
  150. </collection>
  151. <collection property="patentNum" ofType="integer"
  152. select="selectByParentId3" column="s_id">
  153. </collection>
  154. </resultMap>
  155. <select id="selectByParentId2" resultMap="selectByParentIdMap2">
  156. select id,
  157. structure_id,
  158. name,
  159. suffix,
  160. url
  161. from asso_structure_picture
  162. where structure_id = #{s_id}
  163. </select>
  164. <resultMap id="selectByParentIdMap2" type="cn.cslg.pas.common.model.vo.StructurePictureVO">
  165. <id column="id" property="id"/>
  166. <result column="structure_id" property="structureId"/>
  167. <result column="name" property="name"/>
  168. <result column="suffix" property="suffix"/>
  169. <result column="url" property="url"/>
  170. </resultMap>
  171. <select id="selectByParentId3" resultType="integer">
  172. select count(*)
  173. from asso_structure_patent
  174. where structure_id in (select id from structure where find_in_set(#{s_id}, path))
  175. </select>
  176. <!--根据父级id和产品id查询数据-->
  177. <!--List<StructureVO> selectTree(Integer parentId, Integer productId, List<Integer> ids);-->
  178. <select id="selectTree" resultMap="selectTreeMap">
  179. select stru.id as stru_id,
  180. stru.parent_id,
  181. stru.structure_name,
  182. stru.path,
  183. stru.remark,
  184. stru.product_id,
  185. stru.create_person_name,
  186. stru.create_time,
  187. count(distinct struP.patent_no) as patent_num
  188. from structure stru
  189. left join asso_structure_patent struP on find_in_set(stru.id, struP.path)
  190. where stru.parent_id = #{parentId}
  191. and stru.product_id = #{productId}
  192. <if test="ids != null">
  193. and stru.id in (
  194. <foreach collection="ids" item="item" separator=",">
  195. #{item}
  196. </foreach>
  197. )
  198. </if>
  199. group by stru.id
  200. order by stru.id
  201. </select>
  202. <resultMap id="selectTreeMap" type="cn.cslg.pas.common.model.vo.StructureVO">
  203. <id column="stru_id" property="id"/>
  204. <result column="parent_id" property="parentId"/>
  205. <result column="structure_name" property="structureName"/>
  206. <result column="path" property="path"/>
  207. <result column="remark" property="remark"/>
  208. <result column="product_id" property="productId"/>
  209. <result column="create_person_name" property="createPersonName"/>
  210. <result column="create_time" property="createTime"/>
  211. <result column="patent_num" property="patentNum"/>
  212. </resultMap>
  213. <!--根据模糊路径查询数据-->
  214. <!--List<StructureVO> selectByFindInSetPath(String findInSetPath);-->
  215. <select id="selectByFindInSetPath" resultMap="selectByFindInSetPathMap">
  216. select id,
  217. parent_id,
  218. structure_name,
  219. path,
  220. remark,
  221. product_id
  222. from structure
  223. where find_in_set(#{findInSetPath}, path)
  224. order by id
  225. </select>
  226. <resultMap id="selectByFindInSetPathMap" type="cn.cslg.pas.common.model.vo.StructureVO">
  227. <id column="id" property="id"/>
  228. <result column="parent_id" property="parentId"/>
  229. <result column="structure_name" property="structureName"/>
  230. <result column="path" property="path"/>
  231. <result column="remark" property="remark"/>
  232. <result column="product_id" property="productId"/>
  233. </resultMap>
  234. <!--根据产品id查询数据-->
  235. <!--List<StructureVO> selectAllByProductId(Integer productId);-->
  236. <select id="selectAllByProductId" resultMap="selectByFindInSetPathMap">
  237. select id,
  238. parent_id,
  239. structure_name,
  240. path,
  241. remark,
  242. product_id
  243. from structure
  244. where product_id = #{productId}
  245. order by path
  246. </select>
  247. <!--根据架构id查询数据-->
  248. <!--List<StructureVO> selectAllByStructureId(Integer structureId);-->
  249. <select id="selectAllByStructureId" resultMap="selectByFindInSetPathMap">
  250. select id,
  251. parent_id,
  252. structure_name,
  253. path,
  254. remark,
  255. product_id
  256. from structure
  257. where find_in_set(#{structureId}, path)
  258. order by path
  259. </select>
  260. </mapper>