AuthProductMapper.xml 20 KB

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