ProductCategoryMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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.ProductCategoryMapper">
  4. <!--插入数据-->
  5. <!--int insert(ProductCategory productCategory);-->
  6. <insert id="insert" useGeneratedKeys="true" keyProperty="id">
  7. insert into product_category (product_category_name, remark, license_rate, tenant_id, create_person_id,
  8. create_person_name)
  9. values (#{productCategoryName}, #{remark}, #{licenseRate}, #{tenantId}, #{createPersonId},
  10. #{createPersonName})
  11. </insert>
  12. <!--根据id删除数据-->
  13. <!--int deleteById(Integer id);-->
  14. <delete id="deleteById">
  15. delete
  16. from product_category
  17. where id = #{id}
  18. </delete>
  19. <!--根据id修改数据-->
  20. <!--int updateById(ProductCategory productCategory);-->
  21. <update id="updateById">
  22. update product_category
  23. <set>
  24. <if test="productCategoryName != null">
  25. product_category_name = #{productCategoryName},
  26. </if>
  27. <if test="remark != null">
  28. remark = #{remark},
  29. </if>
  30. <if test="licenseRate != null">
  31. license_rate = #{licenseRate},
  32. </if>
  33. </set>
  34. where id = #{id}
  35. </update>
  36. <!--根据产品类别名称统计数量-->
  37. <!--int countByProductCategoryName(String productCategoryName);-->
  38. <select id="countByProductCategoryName" resultType="int">
  39. select count(*)
  40. from product_category
  41. where product_category_name = #{productCategoryName}
  42. and tenant_id = #{tenantId}
  43. </select>
  44. <!--根据id和名称统计数量-->
  45. <!--int countByIdAndName(Integer id, String productCategoryName, Integer tenantId);-->
  46. <select id="countByIdAndName" resultType="int">
  47. select count(*)
  48. from product_category
  49. where product_category_name = #{productCategoryName}
  50. and tenant_id = #{tenantId}
  51. and id != #{id}
  52. </select>
  53. <!--根据id统计数量-->
  54. <!--int countById(Integer id);-->
  55. <select id="countById" resultType="int">
  56. select count(*)
  57. from product_category
  58. where id = #{id}
  59. </select>
  60. <!--分页查询产品类别和图片-->
  61. <!--List<ProductCategoryVO> query(ProductCategoryQueryPageDTO productCategoryQueryPageDTO);-->
  62. <select id="query" resultMap="queryMap">
  63. select
  64. id pc_id,
  65. product_category_name,
  66. remark,
  67. license_rate,
  68. create_person_name
  69. from product_category
  70. <where>
  71. <if test="productCategoryName != null">
  72. and product_category_name like '%${productCategoryName}%'
  73. </if>
  74. <if test="createPersonName != null">
  75. and create_person_id in (select id from pcs_test.personnel where personnel_name like
  76. '%${createPersonName}%')
  77. </if>
  78. <if test="productName != null">
  79. and id in (select product_category_id from product where product_name like '%${productName}%')
  80. </if>
  81. <if test="patentNo != null">
  82. and id in (select product_category_id from product where id in (select product_id from
  83. asso_product_patent where patent_no = #{patentNo} union select product_id from
  84. asso_structure_patent where patent_no = #{patentNo}))
  85. </if>
  86. <if test="true">
  87. and tenant_id = #{tenantId}
  88. </if>
  89. </where>
  90. order by pc_id
  91. </select>
  92. <resultMap id="queryMap" type="cn.cslg.pas.common.model.vo.ProductCategoryVO">
  93. <id column="pc_id" property="id"/>
  94. <result column="product_category_name" property="productCategoryName"/>
  95. <result column="remark" property="remark"/>
  96. <result column="license_rate" property="licenseRate"/>
  97. <result column="create_person_name" property="createPersonName"/>
  98. <collection property="pictures" ofType="cn.cslg.pas.common.model.vo.ProductCategoryPictureVO"
  99. select="query2" column="pc_id">
  100. </collection>
  101. </resultMap>
  102. <select id="query2" resultMap="queryMap2">
  103. select id, product_category_id, name, suffix, url
  104. from asso_product_category_picture
  105. where product_category_id = #{pc_id}
  106. </select>
  107. <resultMap id="queryMap2" type="cn.cslg.pas.common.model.vo.ProductCategoryPictureVO">
  108. <id column="id" property="id"/>
  109. <result column="product_category_id" property="productCategoryId"/>
  110. <result column="name" property="name"/>
  111. <result column="suffix" property="suffix"/>
  112. <result column="url" property="url"/>
  113. </resultMap>
  114. <resultMap id="queryByDateMap" type="cn.cslg.pas.common.model.vo.ProductMarketDataTrendVO">
  115. <result column="market_date" property="marketDate"/>
  116. <result column="sale_total_money" property="saleTotalMoney"/>
  117. <result column="custom_license_money" property="customLicenseMoney"/>
  118. </resultMap>
  119. <!--根据产品架构id、公司名称、营销地区、时间单位查询产品类别营销数据-->
  120. <!--按照月份返回总体-->
  121. <select id="categoryQueryByMonth" resultMap="queryByDateMap">
  122. SELECT CONCAT(YEAR(CONCAT(sale_time,'-02')),'-',MONTH(CONCAT(sale_time,'-02'))) AS market_date,
  123. sum(sale_money) AS sale_total_money,
  124. CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
  125. FROM product_market_data
  126. WHERE product_id IN(SELECT id AS product_id
  127. FROM product
  128. WHERE product_category_id = #{categoryId}
  129. <if test="companyName != null and companyName != ''">
  130. AND company_name = #{companyName}
  131. </if>)
  132. <if test="categoryArea != null and categoryArea != ''">
  133. AND sale_area = #{categoryArea}
  134. </if>
  135. GROUP BY market_date
  136. </select>
  137. <!--按照季度返回总体-->
  138. <select id="categoryQueryBySeason" resultMap="queryByDateMap">
  139. SELECT CONCAT(YEAR(CONCAT(sale_time,'-02')),'年','第',QUARTER(CONCAT(sale_time,'-02')),'季度') AS market_date,
  140. sum(sale_money) AS sale_total_money,
  141. CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
  142. FROM product_market_data
  143. WHERE product_id IN(SELECT id AS product_id
  144. FROM product
  145. WHERE product_category_id = #{categoryId}
  146. <if test="companyName != null and companyName != ''">
  147. AND company_name = #{companyName}
  148. </if>)
  149. <if test="categoryArea != null and categoryArea != ''">
  150. AND sale_area = #{categoryArea}
  151. </if>
  152. GROUP BY market_date
  153. </select>
  154. <!--按照年度返回总体-->
  155. <select id="categoryQueryByYear" resultMap="queryByDateMap">
  156. SELECT CONCAT(YEAR(CONCAT(sale_time,'-02')),'年') AS market_date,
  157. sum(sale_money) AS sale_total_money,
  158. CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
  159. FROM product_market_data
  160. WHERE product_id IN(SELECT id AS product_id
  161. FROM product
  162. WHERE product_category_id = #{categoryId}
  163. <if test="companyName != null and companyName != ''">
  164. AND company_name = #{companyName}
  165. </if>)
  166. <if test="categoryArea != null and categoryArea != ''">
  167. AND sale_area = #{categoryArea}
  168. </if>
  169. GROUP BY market_date
  170. </select>
  171. <!--按照年度返回每个-->
  172. <select id="queryByYear" resultMap="queryByDateMap">
  173. SELECT CONCAT(YEAR(CONCAT(sale_time,'-02')),'年') AS market_date,
  174. sum(sale_money) AS sale_total_money,
  175. CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
  176. FROM product_market_data
  177. WHERE product_id = #{productId}
  178. <if test="categoryArea != null and categoryArea != ''">
  179. AND sale_Area = #{categoryArea}
  180. </if>
  181. GROUP BY market_date
  182. </select>
  183. <!--按照季度返回每个-->
  184. <select id="queryBySeason" resultMap="queryByDateMap">
  185. SELECT CONCAT(YEAR(CONCAT(sale_time,'-02')),'年','第',QUARTER(CONCAT(sale_time,'-02')),'季度') AS market_date,
  186. sum(sale_money) AS sale_total_money,
  187. CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
  188. FROM product_market_data
  189. WHERE product_id = #{productId}
  190. <if test="categoryArea != null and categoryArea != ''">
  191. AND sale_Area = #{categoryArea}
  192. </if>
  193. GROUP BY market_date
  194. </select>
  195. <!--按照月份返回每个-->
  196. <select id="queryByMonth" resultMap="queryByDateMap">
  197. SELECT CONCAT(YEAR(CONCAT(sale_time,'-02')),'-',MONTH(CONCAT(sale_time,'-02'))) AS market_date,
  198. sum(sale_money) AS sale_total_money,
  199. CAST(sum(custom_license_rate * sale_money) AS DECIMAL (19, 2)) AS custom_license_money
  200. FROM product_market_data
  201. WHERE product_id = #{productId}
  202. <if test="categoryArea != null and categoryArea != ''">
  203. AND sale_Area = #{categoryArea}
  204. </if>
  205. GROUP BY market_date
  206. </select>
  207. <!--根据架构id查询产品id和名称-->
  208. <resultMap id="idNameMap" type="cn.cslg.pas.common.model.vo.ProductIdAndNameVO">
  209. <result column="product_id" property="productId"/>
  210. <result column="product_name" property="productName"/>
  211. </resultMap>
  212. <select id="queryProductIdAndNameByCategoryId" resultMap="idNameMap">
  213. SELECT id AS product_id,product_name
  214. FROM product
  215. WHERE product_category_id = #{categoryId}
  216. <if test="companyName != null and companyName != ''">
  217. AND company_name = #{companyName}
  218. </if>
  219. </select>
  220. <!--根据产品id、架构id和专利号集合三者其一查询地区集合-->
  221. <resultMap id="getAreaListMap" type="String">
  222. <result column="sale_area" property="saleArea"/>
  223. </resultMap>
  224. <select id="getAreaList" resultMap="getAreaListMap">
  225. SELECT DISTINCT sale_area
  226. FROM product_market_data a left join product b on a.product_id =b.id
  227. <where>
  228. <if test="productId != null and productId != ''">
  229. a.product_id = #{productId} and b.tenant_id=#{tenantId}
  230. </if>
  231. <if test="categoryId !=null and categoryId != ''">
  232. product_id
  233. IN(
  234. SELECT id
  235. FROM product
  236. WHERE
  237. product_category_id = #{categoryId})
  238. and tenant_id=#{tenantId}
  239. </if>
  240. <if test="patentNoList != null and patentNoList.size() > 0 ">
  241. product_id IN(
  242. SELECT product_id
  243. FROM asso_product_patent c left join product d on c.product_id =d.id
  244. WHERE c.patent_no IN
  245. <foreach collection="patentNoList" item="patentNo" index="index" open="(" close=")" separator=",">
  246. #{patentNo}
  247. </foreach>
  248. and d.tenant_id=#{tenantId}
  249. )
  250. </if>
  251. </where>
  252. </select>
  253. </mapper>