StructureMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. product_id = #{productId}
  60. and parent_id = #{parentId}
  61. and structure_name = #{structureName}
  62. <if test="structureId != null">
  63. and id != #{structureId}
  64. </if>
  65. </select>
  66. <!--根据id查询数据-->
  67. <!--Structure selectById(Integer id);-->
  68. <select id="getStandardById" resultMap="getStandardByIdMap">
  69. select id,
  70. parent_id,
  71. structure_name,
  72. path,
  73. remark,
  74. product_id,
  75. create_person_name,
  76. create_time
  77. from structure
  78. where id = #{id}
  79. </select>
  80. <resultMap id="getStandardByIdMap" type="cn.cslg.pas.domain.Structure">
  81. <id column="id" property="id"/>
  82. <result column="parent_id" property="parentId"/>
  83. <result column="structure_name" property="structureName"/>
  84. <result column="path" property="path"/>
  85. <result column="remark" property="remark"/>
  86. <result column="product_id" property="productId"/>
  87. <result column="create_person_name" property="createPersonName"/>
  88. <result column="create_time" property="createTime"/>
  89. </resultMap>
  90. <!--根据id查询数据和图片-->
  91. <!--StructureVO getStandAndPictureById(Integer id);-->
  92. <!-- <select id="getStandardAndPictureById" resultMap="selectByParentIdMap">-->
  93. <!-- select id s_id,-->
  94. <!-- parent_id,-->
  95. <!-- structure_name,-->
  96. <!-- path,-->
  97. <!-- remark,-->
  98. <!-- product_id,-->
  99. <!-- create_person_name,-->
  100. <!-- create_time-->
  101. <!-- from structure-->
  102. <!-- where id = #{id}-->
  103. <!-- </select>-->
  104. <select id="getStandardAndPictureById" resultMap="selectTreeMap">
  105. select stru.id as stru_id,
  106. stru.parent_id,
  107. stru.structure_name,
  108. stru.path,
  109. stru.remark,
  110. stru.product_id,
  111. stru.create_person_name,
  112. stru.create_time,
  113. count(distinct struP.patent_no) as patent_num
  114. from structure stru
  115. left join asso_structure_patent struP on find_in_set(stru.id, struP.path)
  116. where stru.id = #{id}
  117. </select>
  118. <!--根据父级id和产品id查询数据-->
  119. <!--List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId, List<Integer> ids);-->
  120. <select id="selectByParentIdAndProductId" resultMap="selectByParentIdMap">
  121. select id s_id,
  122. parent_id,
  123. structure_name,
  124. path,
  125. remark,
  126. product_id,
  127. create_person_name,
  128. create_time
  129. from structure
  130. where parent_id = #{parentId}
  131. and product_id = #{productId}
  132. <if test="ids != null">
  133. and id in
  134. <foreach collection="ids" item="item" separator="," open="(" close=")">
  135. #{item}
  136. </foreach>
  137. </if>
  138. order by s_id
  139. </select>
  140. <resultMap id="selectByParentIdMap" type="cn.cslg.pas.common.model.vo.StructureVO">
  141. <id column="s_id" property="id"/>
  142. <result column="parent_id" property="parentId"/>
  143. <result column="structure_name" property="structureName"/>
  144. <result column="path" property="path"/>
  145. <result column="remark" property="remark"/>
  146. <result column="product_id" property="productId"/>
  147. <result column="create_person_name" property="createPersonName"/>
  148. <result column="create_time" property="createTime"/>
  149. <collection property="pictures" ofType="cn.cslg.pas.common.model.vo.StructurePictureVO"
  150. select="selectByParentId2" column="s_id">
  151. </collection>
  152. <collection property="patentNum" ofType="integer"
  153. select="selectByParentId3" column="s_id">
  154. </collection>
  155. </resultMap>
  156. <select id="selectByParentId2" resultMap="selectByParentIdMap2">
  157. select id,
  158. structure_id,
  159. name,
  160. suffix,
  161. url
  162. from asso_structure_picture
  163. where structure_id = #{s_id}
  164. </select>
  165. <resultMap id="selectByParentIdMap2" type="cn.cslg.pas.common.model.vo.StructurePictureVO">
  166. <id column="id" property="id"/>
  167. <result column="structure_id" property="structureId"/>
  168. <result column="name" property="name"/>
  169. <result column="suffix" property="suffix"/>
  170. <result column="url" property="url"/>
  171. </resultMap>
  172. <select id="selectByParentId3" resultType="integer">
  173. select count(*)
  174. from asso_structure_patent
  175. where structure_id in (select id from structure where find_in_set(#{s_id}, path))
  176. </select>
  177. <!--根据父级id和产品id查询数据-->
  178. <!--List<StructureVO> selectTree(Integer parentId, Integer productId, List<Integer> ids);-->
  179. <select id="selectTree" resultMap="selectTreeMap">
  180. select stru.id as stru_id,
  181. stru.parent_id,
  182. stru.structure_name,
  183. stru.path,
  184. stru.remark,
  185. stru.product_id,
  186. stru.create_person_name,
  187. stru.create_time,
  188. count(distinct struP.patent_no) as patent_num
  189. from structure stru
  190. left join asso_structure_patent struP on find_in_set(stru.id, struP.path)
  191. where stru.parent_id = #{parentId}
  192. and stru.product_id = #{productId}
  193. <if test="ids != null and ids.size > 0">
  194. and stru.id in (
  195. <foreach collection="ids" item="item" separator=",">
  196. #{item}
  197. </foreach>
  198. )
  199. </if>
  200. group by stru.id
  201. order by stru.id
  202. </select>
  203. <resultMap id="selectTreeMap" type="cn.cslg.pas.common.model.vo.StructureVO">
  204. <id column="stru_id" property="id"/>
  205. <result column="parent_id" property="parentId"/>
  206. <result column="structure_name" property="structureName"/>
  207. <result column="path" property="path"/>
  208. <result column="remark" property="remark"/>
  209. <result column="product_id" property="productId"/>
  210. <result column="create_person_name" property="createPersonName"/>
  211. <result column="create_time" property="createTime"/>
  212. <result column="patent_num" property="patentNum"/>
  213. </resultMap>
  214. <!--根据模糊路径查询数据-->
  215. <!--List<StructureVO> selectByFindInSetPath(String findInSetPath);-->
  216. <select id="selectByFindInSetPath" resultMap="selectByFindInSetPathMap">
  217. select id,
  218. parent_id,
  219. structure_name,
  220. path,
  221. remark,
  222. product_id
  223. from structure
  224. where find_in_set(#{findInSetPath}, path)
  225. order by id
  226. </select>
  227. <resultMap id="selectByFindInSetPathMap" type="cn.cslg.pas.common.model.vo.StructureVO">
  228. <id column="id" property="id"/>
  229. <result column="parent_id" property="parentId"/>
  230. <result column="structure_name" property="structureName"/>
  231. <result column="path" property="path"/>
  232. <result column="remark" property="remark"/>
  233. <result column="product_id" property="productId"/>
  234. </resultMap>
  235. <!--根据产品id查询数据-->
  236. <!--List<StructureVO> selectAllByProductId(Integer productId);-->
  237. <select id="selectAllByProductId" resultMap="selectByFindInSetPathMap">
  238. select id,
  239. parent_id,
  240. structure_name,
  241. path,
  242. remark,
  243. product_id
  244. from structure
  245. where product_id = #{productId}
  246. order by path
  247. </select>
  248. <!--根据架构id查询数据-->
  249. <!--List<StructureVO> selectAllByStructureId(Integer structureId);-->
  250. <select id="selectAllByStructureId" resultMap="selectByFindInSetPathMap">
  251. select id,
  252. parent_id,
  253. structure_name,
  254. path,
  255. remark,
  256. product_id
  257. from structure
  258. where find_in_set(#{structureId}, path)
  259. order by path
  260. </select>
  261. </mapper>