ProductMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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.ProductMapper">
  4. <!--插入数据-->
  5. <!--int insert(Product product);-->
  6. <insert id="insert" useGeneratedKeys="true" keyProperty="id">
  7. insert into product (product_name, market_time, company_name, tenant_id, create_person_tenant_id,
  8. product_explain, product_category_id, license_rate, create_person_id, create_person_name)
  9. values (#{productName}, #{marketTime}, #{companyName}, #{tenantId}, #{createPersonTenantId}, #{productExplain},
  10. #{productCategoryId}, #{licenseRate}, #{createPersonId}, #{createPersonName});
  11. </insert>
  12. <!--根据id删除产品-->
  13. <!--int deleteById(Integer id);-->
  14. <delete id="deleteById">
  15. delete
  16. from product
  17. where id = #{id}
  18. </delete>
  19. <!--根据产品id修改数据-->
  20. <!--int updateById(Product product);-->
  21. <update id="updateById">
  22. update product
  23. <set>
  24. product_name = #{productName},
  25. market_time = #{marketTime},
  26. company_name = #{companyName},
  27. <if test="tenantId != null">
  28. tenant_id = #{tenantId},
  29. </if>
  30. <if test="createPersonTenantId != null">
  31. create_person_tenant_id = #{createPersonTenantId},
  32. </if>
  33. product_explain = #{productExplain},
  34. product_category_id = #{productCategoryId},
  35. license_rate = #{licenseRate},
  36. </set>
  37. where id = #{id}
  38. </update>
  39. <!--根据产品名称统计数量-->
  40. <!--int countByProductName(String productName, Integer productCategoryId);-->
  41. <select id="countByProductName" resultType="int">
  42. select count(*)
  43. from product
  44. where product_name = #{productName}
  45. and product_category_id = #{productCategoryId}
  46. </select>
  47. <!--根据id统计数量-->
  48. <!--int countById(Integer id);-->
  49. <select id="countById" resultType="int">
  50. select count(*)
  51. from product
  52. where id = #{id}
  53. </select>
  54. <!--根据id查询名称-->
  55. <!-- String queryNameById(Integer id);;-->
  56. <select id="queryNameById" resultType="String">
  57. select product_Name
  58. from product
  59. where id = #{id}
  60. </select>
  61. <!--根据所属产品类别id统计数量-->
  62. <!--int countByProductCategoryId(Integer productCategoryId);-->
  63. <select id="countByProductCategoryId" resultType="int">
  64. select count(*)
  65. from product
  66. where product_category_id = #{productCategoryId}
  67. </select>
  68. <!--根据id查询数据-->
  69. <!--ProductVO getStandardById(Integer id);-->
  70. <select id="getStandardById" resultMap="queryMap">
  71. select id as p_id,
  72. product_name,
  73. market_time,
  74. company_name,
  75. tenant_id,
  76. product_explain,
  77. product_category_id,
  78. license_rate,
  79. create_person_name
  80. from product
  81. where id = #{id}
  82. </select>
  83. <!--分页查询数据-->
  84. <!--List<ProductVO> query(ProductQueryPageDTO productQueryPageDTO);-->
  85. <select id="query" resultMap="queryMap">
  86. select p.id p_id,
  87. product_name,
  88. market_time,
  89. company_name,
  90. p.tenant_id,
  91. create_person_tenant_id,
  92. product_explain,
  93. product_category_id,
  94. p.license_rate,
  95. p.create_person_name,
  96. product_category_name
  97. from product p
  98. join product_category pc on p.product_category_id = pc.id
  99. <where>
  100. <if test="productName != null and productName != ''">
  101. and product_name like '%${productName}%'
  102. </if>
  103. <if test="companyName != null and companyName != ''">
  104. and company_name like '%${companyName}%'
  105. </if>
  106. <if test="patentNo != null and patentNo != ''">
  107. and p.id in
  108. (select product_id from asso_product_patent where patent_no = #{patentNo})
  109. </if>
  110. <if test="productCategoryId != null and productCategoryId != ''">
  111. and product_category_id = #{productCategoryId}
  112. </if>
  113. <if test="productCategoryName != null and productCategoryName != ''">
  114. and product_category_id in (select id from product_category where product_category_name like
  115. '%${productCategoryName}%')
  116. </if>
  117. <if test="true">
  118. and create_person_tenant_id = #{createPersonTenantId}
  119. </if>
  120. </where>
  121. order by
  122. <choose>
  123. <when test="orderBy != null and orderBy != ''">
  124. ${orderBy} ${orderType}
  125. </when>
  126. <otherwise>
  127. p_id
  128. </otherwise>
  129. </choose>
  130. </select>
  131. <resultMap id="queryMap" type="cn.cslg.pas.common.model.vo.ProductVO">
  132. <id column="p_id" property="id"/>
  133. <result column="product_name" property="productName"/>
  134. <result column="market_time" property="marketTime"/>
  135. <result column="company_name" property="companyName"/>
  136. <result column="tenant_id" property="tenantId"/>
  137. <result column="product_explain" property="productExplain"/>
  138. <result column="product_category_id" property="productCategoryId"/>
  139. <result column="license_rate" property="licenseRate"/>
  140. <result column="create_person_name" property="createPersonName"/>
  141. <collection property="pictures" ofType="cn.cslg.pas.common.model.vo.ProductPictureVO"
  142. select="query2" column="{p_id=p_id}">
  143. </collection>
  144. <collection property="productPatentNum" ofType="Integer"
  145. select="query3" column="{p_id=p_id}">
  146. </collection>
  147. <collection property="patentNum" ofType="Integer"
  148. select="query33" column="{p_id=p_id}">
  149. </collection>
  150. <collection property="productCategory" ofType="cn.cslg.pas.common.model.vo.ProductCategoryVO"
  151. select="query4" column="{pc_id=product_category_id}">
  152. </collection>
  153. </resultMap>
  154. <select id="query2" resultMap="query2Map">
  155. select id, product_id, name, suffix, url
  156. from asso_product_picture
  157. where product_id = #{p_id}
  158. </select>
  159. <resultMap id="query2Map" type="cn.cslg.pas.common.model.vo.ProductPictureVO">
  160. <id column="id" property="id"/>
  161. <result column="product_id" property="productId"/>
  162. <result column="name" property="name"/>
  163. <result column="suffix" property="suffix"/>
  164. <result column="url" property="url"/>
  165. </resultMap>
  166. <select id="query3" resultType="Integer">
  167. select count(distinct patent_no)
  168. from asso_product_patent
  169. where product_id = #{p_id}
  170. </select>
  171. <select id="query33" resultType="Integer">
  172. select count(distinct patent_no)
  173. from asso_structure_patent
  174. where product_id = #{p_id}
  175. </select>
  176. <select id="query4" resultMap="query4Map">
  177. select id pc_id,
  178. product_category_name,
  179. remark,
  180. license_rate,
  181. create_person_name
  182. from product_category
  183. where id = #{pc_id}
  184. </select>
  185. <resultMap id="query4Map" type="cn.cslg.pas.common.model.vo.ProductCategoryVO">
  186. <id column="pc_id" property="id"/>
  187. <result column="product_category_name" property="productCategoryName"/>
  188. <result column="remark" property="remark"/>
  189. <result column="license_rate" property="licenseRate"/>
  190. <result column="create_person_name" property="createPersonName"/>
  191. <collection property="pictures" ofType="cn.cslg.pas.common.model.vo.ProductCategoryPictureVO"
  192. select="query41" column="pc_id">
  193. </collection>
  194. </resultMap>
  195. <select id="query41" resultMap="query41Map">
  196. select id, product_category_id, name, suffix, url
  197. from asso_product_category_picture
  198. where product_category_id = #{pc_id}
  199. </select>
  200. <resultMap id="query41Map" type="cn.cslg.pas.common.model.vo.ProductCategoryPictureVO">
  201. <id column="id" property="id"/>
  202. <result column="product_category_id" property="productCategoryId"/>
  203. <result column="name" property="name"/>
  204. <result column="suffix" property="suffix"/>
  205. <result column="url" property="url"/>
  206. </resultMap>
  207. <!--根据产品类别分组分页查询数据-->
  208. <!--List<ProductGroupVO> queryByGroupProductCategoryId(ProductQueryPageDTO productQueryPageDTO);-->
  209. <select id="queryByGroupProductCategoryId" resultMap="queryByGroupProductCategoryIdMap">
  210. select product_category_id pci,
  211. product_category_name,
  212. create_person_tenant_id as createPersonTenantId,
  213. ifnull(#{orderBy}, '') orderBy,
  214. ifnull(#{orderType}, '') orderType,
  215. ifnull(#{productName}, '') productName,
  216. ifnull(#{companyName}, '') companyName,
  217. ifnull(#{patentNo}, '') patentNo,
  218. ifnull(#{productCategoryId}, '') productCategoryId,
  219. ifnull(#{productCategoryName}, '') productCategoryName
  220. from product p
  221. join product_category pc on p.product_category_id = pc.id
  222. <where>
  223. <if test="productName != null and productName != ''">
  224. and product_name like '%${productName}%'
  225. </if>
  226. <if test="companyName != null and companyName != ''">
  227. and company_name like '%${companyName}%'
  228. </if>
  229. <if test="patentNo != null and patentNo != ''">
  230. and p.id in
  231. (select product_id from asso_product_patent where patent_no = #{patentNo})
  232. </if>
  233. <if test="productCategoryId != null and productCategoryId != ''">
  234. and product_category_id = #{productCategoryId}
  235. </if>
  236. <if test="productCategoryName != null and productCategoryName != ''">
  237. and product_category_id in (select id from product_category where product_category_name like
  238. '%${productCategoryName}%')
  239. </if>
  240. <if test="true">
  241. and p.create_person_tenant_id = #{createPersonTenantId}
  242. </if>
  243. </where>
  244. group by product_category_id
  245. order by product_category_id
  246. </select>
  247. <resultMap id="queryByGroupProductCategoryIdMap" type="cn.cslg.pas.common.model.vo.ProductGroupVO">
  248. <result column="product_category_id" property="productCategoryId"/>
  249. <result column="product_category_name" property="productCategoryName"/>
  250. <collection property="products" ofType="cn.cslg.pas.common.model.vo.ProductVO"
  251. select="queryByGroupProductCategoryId2"
  252. column="{pci=pci, orderBy=orderBy, orderType=orderType, productName=productName, companyName=companyName,
  253. patentNo=patentNo, productCategoryId=productCategoryId, productCategoryName=productCategoryName, createPersonTenantId=createPersonTenantId}">
  254. </collection>
  255. </resultMap>
  256. <select id="queryByGroupProductCategoryId2" resultMap="queryMap">
  257. select p.id p_id,
  258. product_name,
  259. market_time,
  260. company_name,
  261. p.tenant_id,
  262. product_explain,
  263. product_category_id,
  264. p.license_rate,
  265. p.create_person_name,
  266. product_category_name
  267. from product p
  268. join product_category pc on p.product_category_id = pc.id
  269. <where>
  270. <if test="productName != null and productName != ''">
  271. and product_name like '%${productName}%'
  272. </if>
  273. <if test="companyName != null and companyName != ''">
  274. and company_name like '%${companyName}%'
  275. </if>
  276. <if test="patentNo != null and patentNo != ''">
  277. and p.id in
  278. (select product_id from asso_product_patent where patent_no = #{patentNo}
  279. union select product_id from asso_structure_patent where patent_no = #{patentNo})
  280. </if>
  281. <if test="productCategoryId != null and productCategoryId != ''">
  282. and product_category_id = #{productCategoryId}
  283. </if>
  284. <if test="productCategoryName != null and productCategoryName != ''">
  285. and product_category_id in (select id from product_category where product_category_name like
  286. '%${productCategoryName}%')
  287. </if>
  288. <if test="true">
  289. and product_category_id = #{pci}
  290. </if>
  291. <if test="true">
  292. and p.create_person_tenant_id = #{createPersonTenantId}
  293. </if>
  294. </where>
  295. order by
  296. <choose>
  297. <when test="orderBy != null and orderBy != ''">
  298. ${orderBy} ${orderType}
  299. </when>
  300. <otherwise>
  301. p_id
  302. </otherwise>
  303. </choose>
  304. </select>
  305. <!--根据公司分组分页查询数据-->
  306. <!--List<ProductGroupVO> queryByGroupCompanyName(ProductQueryPageDTO productQueryPageDTO);-->
  307. <select id="queryByGroupCompanyName" resultMap="queryByGroupCompanyNameMap">
  308. select company_name cn,
  309. create_person_tenant_id as createPersonTenantId,
  310. ifnull(#{orderBy}, '') orderBy,
  311. ifnull(#{orderType}, '') orderType,
  312. ifnull(#{productName}, '') productName,
  313. ifnull(#{companyName}, '') companyName,
  314. ifnull(#{patentNo}, '') patentNo,
  315. ifnull(#{productCategoryId}, '') productCategoryId,
  316. ifnull(#{productCategoryName}, '') productCategoryName
  317. from product
  318. <where>
  319. <if test="productName != null and productName != ''">
  320. and product_name like '%${productName}%'
  321. </if>
  322. <if test="companyName != null and companyName != ''">
  323. and company_name like '%${companyName}%'
  324. </if>
  325. <if test="patentNo != null and patentNo != ''">
  326. and id in
  327. (select product_id from asso_product_patent where patent_no = #{patentNo})
  328. </if>
  329. <if test="productCategoryId != null and productCategoryId != ''">
  330. and product_category_id = #{productCategoryId}
  331. </if>
  332. <if test="productCategoryName != null and productCategoryName != ''">
  333. and product_category_id in (select id from product_category where product_category_name like
  334. '%${productCategoryName}%')
  335. </if>
  336. <if test="true">
  337. and company_name is not null
  338. </if>
  339. <if test="true">
  340. and create_person_tenant_id = #{createPersonTenantId}
  341. </if>
  342. </where>
  343. group by company_name
  344. order by company_name
  345. </select>
  346. <resultMap id="queryByGroupCompanyNameMap" type="cn.cslg.pas.common.model.vo.ProductGroupVO">
  347. <result column="cn" property="companyName"/>
  348. <collection property="products" ofType="cn.cslg.pas.common.model.vo.ProductVO"
  349. select="queryByGroupCompanyName2"
  350. column="{cn=cn, orderBy=orderBy, orderType=orderType, productName=productName, companyName=companyName,
  351. patentNo=patentNo, productCategoryId=productCategoryId, productCategoryName=productCategoryName, createPersonTenantId=createPersonTenantId}">
  352. </collection>
  353. </resultMap>
  354. <select id="queryByGroupCompanyName2" resultMap="queryMap">
  355. select p.id p_id,
  356. product_name,
  357. market_time,
  358. company_name,
  359. p.tenant_id,
  360. product_explain,
  361. product_category_id,
  362. p.license_rate,
  363. p.create_person_name,
  364. product_category_name
  365. from product p
  366. join product_category pc on p.product_category_id = pc.id
  367. <where>
  368. <if test="productName != null and productName != ''">
  369. and product_name like '%${productName}%'
  370. </if>
  371. <if test="companyName != null and companyName != ''">
  372. and company_name like '%${companyName}%'
  373. </if>
  374. <if test="patentNo != null and patentNo != ''">
  375. and p.id in
  376. (select product_id from asso_product_patent where patent_no = #{patentNo}
  377. union select product_id from asso_structure_patent where patent_no = #{patentNo})
  378. </if>
  379. <if test="productCategoryId != null and productCategoryId != ''">
  380. and product_category_id = #{productCategoryId}
  381. </if>
  382. <if test="productCategoryName != null and productCategoryName != ''">
  383. and product_category_id in (select id from product_category where product_category_name like
  384. '%${productCategoryName}%')
  385. </if>
  386. <if test="true">
  387. and company_name = #{cn}
  388. </if>
  389. <if test="true">
  390. and p.create_person_tenant_id = #{createPersonTenantId}
  391. </if>
  392. </where>
  393. order by
  394. <choose>
  395. <when test="orderBy != null and orderBy != ''">
  396. ${orderBy} ${orderType}
  397. </when>
  398. <otherwise>
  399. p_id
  400. </otherwise>
  401. </choose>
  402. </select>
  403. </mapper>