AuthProductMapper.xml 20 KB

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