AuthProductMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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="com.caimei.mapper.cmMapper.AuthProductMapper">
  4. <insert id="insertProduct" keyColumn="id" keyProperty="productId" useGeneratedKeys="true" parameterType="com.caimei.model.po.ProductPo">
  5. insert into cm_brand_auth_product(`authId`, `brandId`, `productTypeId`, `snCode`, name, image,
  6. `originalCertificateImage`, `certificateImage`, `pcCertificateImage`,
  7. `appletsCertificateImage`, `addQrCodeFlag`, `addTemplateType`,
  8. purchaseWay, invoiceImage, `status`, auditBy, auditTime,
  9. `auditStatus`, shopAuditStatus, `createTime`, `createBy`, createSource)
  10. values (#{authId}, #{brandId}, #{productTypeId}, #{snCode}, #{name}, #{image},
  11. #{originalCertificateImage}, #{certificateImage}, #{pcCertificateImage},
  12. #{appletsCertificateImage}, #{addQrCodeFlag}, #{addTemplateType},
  13. #{purchaseWay}, #{invoiceImage}, #{status}, #{auditBy}, #{auditTime},
  14. #{auditStatus}, #{shopAuditStatus}, #{createTime}, #{createBy}, #{createSource})
  15. </insert>
  16. <insert id="insertProductParam">
  17. insert into cm_brand_product_param (`productId`, `name`, `content`)
  18. values (#{productId}, #{paramName}, #{paramContent})
  19. </insert>
  20. <insert id="insertProductType" keyColumn="id" keyProperty="productTypeId" useGeneratedKeys="true" parameterType="com.caimei.model.po.ProductTypePo">
  21. insert into cm_brand_product_type (authUserId, name, image, pcImage, appletsImage, status, auditStatus, auditBy, auditTime, createBy, createSource, createTime, delFlag)
  22. values (#{authUserId}, #{name}, #{image}, #{pcImage}, #{appletsImage}, #{status}, #{auditStatus}, #{auditBy}, #{auditTime}, #{createBy}, #{createSource}, #{createTime}, 0)
  23. </insert>
  24. <update id="updateProductStatusByProductId">
  25. update cm_brand_auth_product
  26. set status = #{status}
  27. where id = #{productId}
  28. </update>
  29. <update id="updateProductByProductId">
  30. update cm_brand_auth_product
  31. <set>
  32. `brandId` = #{brandId},
  33. `productTypeId` = #{productTypeId},
  34. `snCode` = #{snCode},
  35. `certificateImage` = #{certificateImage},
  36. `addQrCodeFlag` = #{addQrCodeFlag},
  37. `addTemplateType` = #{addTemplateType},
  38. <if test="originalCertificateImage != null and originalCertificateImage != ''">
  39. `originalCertificateImage` = #{originalCertificateImage},
  40. </if>
  41. <if test="pcCertificateImage != null and pcCertificateImage != ''">
  42. `pcCertificateImage` = #{pcCertificateImage},
  43. </if>
  44. <if test="appletsCertificateImage != null and appletsCertificateImage != ''">
  45. `appletsCertificateImage` = #{appletsCertificateImage},
  46. </if>
  47. <if test="name != null and name != ''">
  48. name = #{name},
  49. image = #{image},
  50. </if>
  51. <if test="productTypeId != null">
  52. productTypeId = #{productTypeId},
  53. name = null,
  54. image = null,
  55. </if>
  56. purchaseWay = #{purchaseWay},
  57. invoiceImage = #{invoiceImage},
  58. `status` = #{status},
  59. `auditStatus` = #{auditStatus},
  60. `shopAuditStatus` = #{shopAuditStatus},
  61. </set>
  62. where id = #{productId};
  63. </update>
  64. <update id="updateImageByProductId">
  65. update cm_brand_auth_product
  66. set `pcImage` = #{pcImage},
  67. `appletsImage` = #{appletsImage},
  68. `pcCertificateImage` = #{pcCertificateImage},
  69. `appletsCertificateImage` = #{appletsCertificateImage}
  70. where id = #{productId};
  71. </update>
  72. <update id="updateProductAuditStatus">
  73. update cm_brand_auth_product
  74. set status = #{status},
  75. auditStatus = #{auditStatus},
  76. invalidReason = #{invalidReason},
  77. auditBy = #{auditBy},
  78. <if test="productTypeId != null">
  79. productTypeId = #{productTypeId},
  80. name = null,
  81. image = null,
  82. </if>
  83. auditTime = #{auditTime}
  84. where id = #{productId}
  85. </update>
  86. <update id="updateCertificateImage">
  87. update cm_brand_auth_product
  88. set certificateImage = #{certificateImage},
  89. pcCertificateImage = #{pcCertificateImage},
  90. appletsCertificateImage = #{appletsCertificateImage}
  91. where id = #{productId}
  92. </update>
  93. <update id="updateProductType">
  94. update cm_brand_product_type
  95. set name = #{name},
  96. <if test="pcImage != null and pcImage != ''">
  97. pcImage = #{pcImage},
  98. </if>
  99. <if test="appletsImage != null and appletsImage != ''">
  100. appletsImage = #{appletsImage},
  101. </if>
  102. image = #{image},
  103. status = #{status},
  104. auditStatus = #{auditStatus}
  105. where id = #{productTypeId}
  106. </update>
  107. <update id="updateProductTypeStatus">
  108. update cm_brand_product_type
  109. set status = #{status}
  110. where id = #{productTypeId}
  111. </update>
  112. <update id="updateProductTypeAuditStatus">
  113. update cm_brand_product_type
  114. set status = #{status},
  115. auditStatus = #{auditStatus},
  116. invalidReason = #{invalidReason},
  117. auditBy = #{auditBy},
  118. auditTime = #{auditTime}
  119. where id = #{productTypeId}
  120. </update>
  121. <delete id="deleteProductByProductId">
  122. delete from cm_brand_auth_product where id = #{productId}
  123. </delete>
  124. <delete id="deleteParamsByProductId">
  125. delete from cm_brand_product_param where productId = #{productId}
  126. </delete>
  127. <update id="deleteProductType">
  128. update cm_brand_product_type set delFlag = 1 where id = #{productTypeId}
  129. </update>
  130. <update id="updateProductShopAuditStatus">
  131. update cm_brand_auth_product
  132. set shopAuditStatus = #{shopAuditStatus},
  133. status = #{status},
  134. auditStatus = #{shopAuditStatus},
  135. shopInvalidReason = #{shopInvalidReason},
  136. <if test="productTypeId != null">
  137. productTypeId = #{productTypeId},
  138. name = null,
  139. image = null,
  140. </if>
  141. shopAuditBy = #{shopAuditBy},
  142. shopAuditTime = #{shopAuditTime}
  143. where id = #{productId}
  144. </update>
  145. <select id="getProductList" resultType="com.caimei.model.vo.ProductListVo">
  146. select p.id as productId,if(p.productTypeId is null,p.name,t.name) as productName,
  147. snCode,p.status,p.auditStatus,p.shopAuditStatus, p.createTime,
  148. if(p.createSource = 1,cu.name,cbcu.mobile) as createBy,
  149. au.name as auditBy,p.auditTime,p.invalidReason,au1.name as shopAuditBy,p.shopAuditTime
  150. from cm_brand_auth_product p
  151. left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
  152. left join cm_brand_auth_user cu on p.createBy = cu.authUserId
  153. left join cm_brand_auth_user au on p.auditBy = au.authUserId
  154. left join cm_brand_auth_user au1 on p.shopAuditBy = au1.authUserId
  155. left join cm_brand_club_user cbcu on p.createBy = cbcu.id
  156. where p.authId = #{authId}
  157. <if test="productName != null and productName != ''">
  158. and (t.name like CONCAT('%',#{productName},'%') or t.name like CONCAT('%',#{productName},'%'))
  159. </if>
  160. <if test="snCode != null and snCode != ''">
  161. and snCode like CONCAT('%',#{snCode},'%')
  162. </if>
  163. <if test="status != null">
  164. and p.status = #{status}
  165. </if>
  166. <if test="auditStatus != null">
  167. and p.auditStatus = #{auditStatus}
  168. </if>
  169. <if test="1 == listType or 2 == listType">
  170. and p.shopAuditStatus = 1
  171. </if>
  172. <if test="shopAuditStatus != null">
  173. <if test="0 == shopAuditStatus">
  174. and p.shopAuditStatus = 2
  175. </if>
  176. <if test="1 == shopAuditStatus">
  177. and (p.shopAuditStatus = 0 or p.shopAuditStatus = 1)
  178. </if>
  179. </if>
  180. <choose>
  181. <when test="listType == 2">
  182. order by (case p.auditStatus when 2 then 2 when 0 then 1 else 0 end) desc,p.createTime desc
  183. </when>
  184. <when test="listType == 3">
  185. order by (case p.shopAuditStatus when 2 then 2 when 0 then 1 else 0 end) desc, p.createTime desc
  186. </when>
  187. <otherwise>
  188. order by p.createTime desc
  189. </otherwise>
  190. </choose>
  191. </select>
  192. <select id="getProductIdBySnCode" resultType="java.lang.Integer">
  193. select id from cm_brand_auth_product where snCode = #{snCode} limit 1
  194. </select>
  195. <select id="getProductFormByProductId" resultType="com.caimei.model.vo.ProductFormVo">
  196. select p.`id` as productId,
  197. `authId`,
  198. `brandId`,
  199. cb.name as brandName,
  200. p.productTypeId,
  201. if(p.productTypeId is null, p.name, t.name) as productName,
  202. `snCode`,
  203. if(p.productTypeId is null, p.image, t.image) as productImage,
  204. `certificateImage`,
  205. `originalCertificateImage`,
  206. addQrCodeFlag,
  207. addTemplateType,
  208. purchaseWay,
  209. invoiceImage,
  210. p.`status`,
  211. p.auditStatus,
  212. if(shopAuditStatus = 0,shopInvalidReason,p.invalidReason) as invalidReason
  213. from cm_brand_auth_product p
  214. left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
  215. left join cm_brand cb on p.brandId = cb.id
  216. where p.id = #{productId}
  217. </select>
  218. <select id="getParamsByProductId" resultType="com.caimei.model.po.ProductParamPo">
  219. select `name` as paramName, `content` as paramContent
  220. from cm_brand_product_param
  221. where productId = #{productId}
  222. </select>
  223. <select id="getProductIdsByAuthId" resultType="java.lang.Integer">
  224. select id from cm_brand_auth_product where authId = #{authId}
  225. </select>
  226. <select id="getImageByProductId" resultType="com.caimei.model.po.ProductPo">
  227. select t.image as productImage,
  228. t.pcImage,
  229. t.appletsImage,
  230. addQrCodeFlag,
  231. originalCertificateImage,
  232. certificateImage,
  233. pcCertificateImage,
  234. appletsCertificateImage,
  235. addQrCodeFlag,
  236. addTemplateType
  237. from cm_brand_auth_product p
  238. left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
  239. where p.id = #{productId}
  240. </select>
  241. <select id="getAllImage" resultType="com.caimei.model.po.ProductPo">
  242. select id as productId,
  243. image,
  244. pcImage,
  245. appletsImage,
  246. certificateImage,
  247. pcCertificateImage,
  248. appletsCertificateImage
  249. from cm_brand_auth_product
  250. </select>
  251. <select id="getWxProductList" resultType="com.caimei.model.vo.WxProductListVo">
  252. select p.id as productId,
  253. p.authId,
  254. if(p.productTypeId is null,p.name,t.name) as productName,
  255. p.snCode,
  256. if(p.productTypeId is null,p.image,t.image) as productImage,
  257. a.authParty as clubName,
  258. p.auditStatus
  259. from cm_brand_auth_product p
  260. left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
  261. left join cm_brand_auth a on p.authId = a.id
  262. left join cm_brand_auth_user au on a.authUserId = au.authUserId
  263. <where>
  264. <if test="listType == 1">
  265. and p.productTypeId = #{productTypeId}
  266. and au.status = 1
  267. and a.status = 1
  268. and a.auditStatus = 1
  269. and p.status = 1
  270. and p.auditStatus = 1
  271. and t.status = 1
  272. and t.auditStatus = 1
  273. </if>
  274. <if test="snCode != null and snCode != ''">
  275. and p.snCode like concat('%',#{snCode},'%')
  276. </if>
  277. <if test="authId != null">
  278. and p.authId = #{authId}
  279. </if>
  280. <if test="authParty != null and authParty != ''">
  281. and a.authParty like concat('%',#{authParty},'%')
  282. </if>
  283. </where>
  284. order by p.createTime desc
  285. </select>
  286. <select id="getBrandIdByBrandName" resultType="java.lang.Integer">
  287. select id from cm_brand where name = #{brand}
  288. </select>
  289. <select id="getAuthProductList" resultType="com.caimei.model.vo.ProductFormVo">
  290. select p.id as productId,
  291. if(p.productTypeId is null,p.name,t.name) as productName,snCode,cb.name as brandName,
  292. if(p.productTypeId is null,p.image,t.image) as productImage,certificateImage
  293. from cm_brand_auth_product p
  294. left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
  295. left join cm_brand cb on p.brandId = cb.id
  296. where authId = #{authId}
  297. order by p.createTime desc
  298. </select>
  299. <select id="getAuthProductByProductId" resultType="com.caimei.model.vo.AuthProductVo">
  300. select t.name as productName,
  301. p.snCode,
  302. t.image as pcImage,
  303. t.image as appletsImage,
  304. p.certificateImage as pcCertificateImage,
  305. p.certificateImage as appletsCertificateImage,
  306. p.brandId,
  307. b.authLogo,
  308. b.name as brandName,
  309. c.name as productionPlace,
  310. a.id as authId,
  311. a.authParty,
  312. u.authUserId as authUserId,
  313. u.name as shopName,
  314. u.shopType,
  315. u.qrCodeImage,
  316. i.securityLink,
  317. i.manufacturer,
  318. i.statementType,
  319. i.statementContent,
  320. i.statementLink,
  321. i.statementImage
  322. from cm_brand_auth_product p
  323. left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
  324. left join cm_brand_auth a on p.authId = a.id
  325. left join cm_brand_auth_user u on a.authUserId = u.authUserId
  326. left join cm_brand_auth_shop_info i on u.authUserId = i.authUserId and p.brandId = i.brandId
  327. left join cm_brand b on i.brandId = b.id
  328. left join country c on i.countryId = c.countryId
  329. where p.id = #{productId}
  330. and u.status = 1
  331. and a.status = 1
  332. and p.status = 1
  333. and a.auditStatus = 1
  334. and p.auditStatus = 1
  335. and t.status = 1
  336. and t.auditStatus = 1
  337. </select>
  338. <select id="getStatementFile" resultType="com.caimei.model.vo.StatementFileVo">
  339. select name,ossName,md5Hex,uploadTime
  340. from cm_brand_auth_file
  341. where authUserId = #{authUserId}
  342. and brandId = #{brandId}
  343. limit 1
  344. </select>
  345. <select id="getAuthProductParams" resultType="com.caimei.model.po.ProductParamPo">
  346. select name as paramName, content as paramContent
  347. from cm_brand_product_param
  348. where productId = #{productId}
  349. </select>
  350. <select id="getClubProductList" resultType="com.caimei.model.vo.WxProductListVo">
  351. select p.id as productId, t.name as productName, p.snCode
  352. from cm_brand_auth_product p
  353. left join cm_brand_product_type t on p.productTypeId = t.id and t.delFlag = 0
  354. where p.authId = #{authId}
  355. and p.status = 1
  356. and p.auditStatus = 1
  357. order by p.createTime desc
  358. </select>
  359. <select id="getProductTypeList" resultType="com.caimei.model.vo.ProductTypeListVo">
  360. select t.id as productTypeId,t.name,t.image,t.status,t.auditStatus,t.createTime,
  361. if(t.createSource = 1,cu.name,cbcu.mobile) as createBy,
  362. au.name as auditBy,t.auditTime,t.invalidReason
  363. from cm_brand_product_type t
  364. left join cm_brand_auth_user cu on t.createBy = cu.authUserId
  365. left join cm_brand_auth_user au on t.auditBy = au.authUserId
  366. left join cm_brand_club_user cbcu on t.createBy = cbcu.id
  367. where t.authUserId = #{authUserId} and t.delFlag = 0
  368. <if test="name != null and name != ''">
  369. and t.name like CONCAT('%',#{name},'%')
  370. </if>
  371. <if test="status != null">
  372. and t.status = #{status}
  373. </if>
  374. <if test="auditStatus != null">
  375. and t.auditStatus = #{auditStatus}
  376. </if>
  377. <choose>
  378. <when test="listType == 2">
  379. order by (case t.auditStatus when 2 then 2 when 0 then 1 else 0 end) desc,t.createTime desc
  380. </when>
  381. <otherwise>
  382. order by t.createTime desc
  383. </otherwise>
  384. </choose>
  385. </select>
  386. <select id="getWxProductTypeList" resultType="com.caimei.model.vo.WxProductTypeListVo">
  387. select t.id as productTypeId,t.name,t.image
  388. from cm_brand_product_type t
  389. left join cm_brand_auth_user u on t.authUserId = u.authUserId
  390. where u.authUserId = #{authUserId} and t.delFlag = 0 and t.status = 1 and auditStatus = 1
  391. <if test="name != null and name != ''">
  392. and t.name like concat('%',#{name},'%')
  393. </if>
  394. order by t.id desc
  395. </select>
  396. <select id="getProductType" resultType="com.caimei.model.po.ProductTypePo">
  397. select id as productTypeId, name, image, pcImage, appletsImage
  398. from cm_brand_product_type
  399. <where>
  400. <if test="productTypeId != null">
  401. and id = #{productTypeId}
  402. </if>
  403. <if test="productName != null and productName != ''">
  404. and name = #{productName}
  405. </if>
  406. <if test="authUserId != null">
  407. and authUserId = #{authUserId}
  408. </if>
  409. </where>
  410. limit 1
  411. </select>
  412. <select id="getProductCountByTypeId" resultType="java.lang.Integer">
  413. select count(*) from cm_brand_auth_product where productTypeId = #{productTypeId}
  414. </select>
  415. <select id="getProductPo" resultType="com.caimei.model.po.ProductPo">
  416. select id as productId, productTypeId, name, image, createBy
  417. from cm_brand_auth_product
  418. where id = #{productId}
  419. </select>
  420. <select id="getAuthUserIdByProductId" resultType="java.lang.Integer">
  421. select a.authUserId
  422. from cm_brand_auth_product p
  423. left join cm_brand_auth a on p.authId = a.id
  424. where p.id = #{productId}
  425. </select>
  426. </mapper>