ProductModuleMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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.module.product.dao.ProductModuleDao">
  4. <sql id="BigType_Column_List">
  5. bigTypeID, `name`, bigTypeCode, validFlag, sortIndex, seo, displayOnHomePageFlag
  6. </sql>
  7. <sql id="SmallType_Column_List">
  8. smallTypeID, bigTypeID, `name`, smallTypeCode, validFlag, sortIndex, seo, displayOnHomePageFlag
  9. </sql>
  10. <sql id="Tinytype_Column_List">
  11. tinyTypeID, smallTypeID, `name`, tinyTypeCode, icon, validFlag, seo, sortIndex
  12. </sql>
  13. <sql id="Product_Column_List">
  14. productID, brandID, tinyTypeID,productCategory, preferredFlag, selfTypeID, shopID, `name`, aliasName, searchKey, productRemarks,
  15. normalPrice, price, highestUserLevelPrice, lowestUserLevelPrice, lowestUserLevelID,
  16. price0, price0Grade, price0Text, price0TextFlag, price1, price1Grade, price1Text,
  17. price1TextFlag, price8, price8Grade, price8Text, price8TextFlag, ladderPriceFlag,
  18. price2, price3, price4, price5, price6, price7, fee, stock, hasSkuFlag, mainImage,
  19. propertiesInfo, addTime, updateTime, sellNumber, weekSellNumber, beforeValidFlag,
  20. validFlag, favoriteTimes, commentScore, commentTimes, selfRecommendFlag, sysRecommendFlag,
  21. sortIndex, featuredFlag, featuredSortIndex, productCode, rate1, rate2, unit, synToERPFlag,
  22. allAreaFlag, provinceIDs, serviceNumber, maxBuyNumber, virtualFlag, minBuyNumber,
  23. packageCount, byFlag, normalProductFlag, wholeSaleProductFlag, promotionProductFlag,
  24. groupBuyProductFlag, step, speCommisionFlag, speCommision, videourl, props, providers,
  25. serviceCommissionRatio, reCommissionRatio, pushToERPName, prodBeans, useBeansFlag,
  26. privateFlag, invisibleServiceProviderIDs, displayOnCRMFlag, needServiceFlag, actFlag, actStatus,
  27. actSort, actPrice0, actPrice1, actPrice2, actPrice3, actPrice4, actPrice5, actPrice6,
  28. actPrice7, actType, actCreateTime, beginTime, endTime, shopIndexModuleID, onlineTime,
  29. downlineTime, freePostFlag, crmBigTypeId, crmSmallTypeId, costPrice, costProportional,
  30. costCheckFlag, precisehKey, docBoost, cmbeanFlag, cmbeanPrice, cmbeanSort, actBuyGiftNum,
  31. actFullGiftAmount, actFullReduceAmount, actReduceAmount, visibility, surplusTime,
  32. priceType, tags, recommendType, machineType, taxPoint, supplierTaxPoint, includedTax,
  33. invoiceType
  34. </sql>
  35. <sql id="ProductDetail_Column_List">
  36. productDetailInfoID, productID, propValueAlias, propValueImages, detailInfo, detailInfoTxt,
  37. seoTitle, seoKeyword, seoDes, serviceInfo, orderInfo
  38. </sql>
  39. <sql id="LadderPrice_Column_List">
  40. id, productId, userType, ladderNum, buyNum, buyPrice, createBy, createDate, updateBy,
  41. updateDate, delFlag
  42. </sql>
  43. <sql id="Image_Column_List">
  44. productImageID, productID, shopID, addTime, image, mainFlag, sortIndex
  45. </sql>
  46. <sql id="Shop_Column_List">
  47. s.shopID, s.userID, s.`name`, s.sname, s.nameEn, s.site, s.ledgerNo, s.logo, s.rebateAmount, s.`level`,
  48. s.score, s.productCount, s.legalPerson, s.businessLicense, s.businessLicenseImage, s.taxCertificate,
  49. s.taxCertificateImage, s.provinceID, s.cityID, s.townID, s.address, s.registeredCapital, s.nature,
  50. s.turnover, s.linkMan, s.contractPhone, s.contractMobile, s.fax, s.zipCode, s.linkMan1, s.duty1,
  51. s.contractPhone1, s.contractMobile1, s.contractQQ1, s.wechat1, s.contractEmail1, s.linkMan2,
  52. s.duty2, s.contractPhone2, s.contractMobile2, s.contractQQ2, s.wechat2, s.contractEmail2, s.`scope`,
  53. s.info, s.productDesc, s.lng, s.lat, s.addTime, s.auditStatus, s.auditTime, s.auditNote, s.favoriteTimes,
  54. s.validFlag, s.payFlag1, s.auditFlag1, s.payFlag2, s.auditFlag2, s.payFlag3, s.auditFlag3, s.note,
  55. s.`status`, s.sortIndex, s.rate1, s.rate2, s.masterFlag, s.erpFlag, s.shopSecret, s.masterLogo, s.cooperateFlag,
  56. s.bail, s.businessScope, s.socialCreditCode, s.mainpro, s.firstShopType, s.secondShopType, s.medicalPracticeLicenseImg1,
  57. s.medicalPracticeLicenseImg2, s.medicalPracticeLicenseImg3, s.bankAccount, s.bankAccountName,
  58. s.bankName, s.ableRebateAmount,s.authorizationCertificateImage
  59. </sql>
  60. <select id="getBigType" resultType="com.caimei.module.base.entity.vo.BigtypeVo">
  61. select
  62. <include refid="BigType_Column_List" />
  63. from bigtype
  64. where validFlag = '1'
  65. </select>
  66. <select id="getSmallType" resultType="com.caimei.module.base.entity.vo.SmalltypeVo">
  67. select
  68. <include refid="SmallType_Column_List" />
  69. from smalltype
  70. where bigTypeID = #{bigTypeID,jdbcType=INTEGER}
  71. and validFlag = '1'
  72. </select>
  73. <select id="getTinytype" resultType="com.caimei.module.base.entity.vo.TinytypeVo">
  74. select
  75. <include refid="Tinytype_Column_List" />
  76. from tinytype
  77. where smallTypeID = #{smallTypeID,jdbcType=INTEGER}
  78. and validFlag = '1'
  79. </select>
  80. <!-- sortType (3:价格升序, 4:价格降序, 7:人气, 8:销量) -->
  81. <select id="getProductsByTinyType" resultType="com.caimei.module.base.entity.vo.ProductVo" parameterType="java.lang.Integer">
  82. select
  83. <include refid="Product_Column_List" />
  84. from product
  85. where validFlag = 2
  86. and tinyTypeID = #{tinyTypeID,jdbcType=INTEGER}
  87. <choose>
  88. <when test="sortType == 3">
  89. order by price1 asc
  90. </when>
  91. <when test="sortType == 4">
  92. order by price1 desc
  93. </when>
  94. <when test="sortType == 7">
  95. order by favoriteTimes desc
  96. </when>
  97. <when test="sortType == 8">
  98. order by sellNumber desc
  99. </when>
  100. <otherwise>
  101. order by onlineTime desc
  102. </otherwise>
  103. </choose>
  104. </select>
  105. <select id="searchProduct" resultType="com.caimei.module.base.entity.vo.ProductVo">
  106. select
  107. *
  108. from product
  109. where validFlag = 2
  110. and name like CONCAT('%',#{searchWord,jdbcType=VARCHAR},'%')
  111. </select>
  112. <select id="findProductById" resultType="com.caimei.module.base.entity.vo.ProductVo">
  113. select
  114. <include refid="Product_Column_List" />
  115. from product
  116. where validFlag in (1,2,3,9)
  117. and productId = #{productId,jdbcType=BIGINT}
  118. </select>
  119. <select id="findProductUnlimited" resultType="com.caimei.module.base.entity.vo.ProductVo">
  120. select
  121. <include refid="Product_Column_List" />
  122. from product
  123. where productId = #{productId,jdbcType=BIGINT}
  124. </select>
  125. <select id="getSearchHistoryList" resultType="com.caimei.module.base.entity.vo.SearchHistoryVo">
  126. select id, userId, searchWord, searchDate, delFlag
  127. from user_search_history
  128. where userId = #{userId,jdbcType=BIGINT}
  129. order by id desc
  130. </select>
  131. <select id="getSearchHistoryIdByWord" resultType="java.lang.Long">
  132. select id
  133. from user_search_history
  134. where searchWord = #{searchWord,jdbcType=VARCHAR}
  135. limit 1
  136. </select>
  137. <select id="findLowerLadderPrice" resultType="com.caimei.module.base.entity.vo.LadderPriceVo">
  138. select
  139. <include refid="LadderPrice_Column_List" />
  140. from product_ladder_price
  141. WHERE delFlag = '0'
  142. AND productId = #{productId,jdbcType=BIGINT}
  143. ORDER BY ladderNum DESC
  144. LIMIT 1
  145. </select>
  146. <select id="findProductImage" resultType="com.caimei.module.base.entity.vo.ProductImageVo">
  147. select
  148. <include refid="Image_Column_List" />
  149. from productimage
  150. where productID = #{productID,jdbcType=INTEGER}
  151. ORDER BY mainFlag DESC
  152. </select>
  153. <select id="findImageByProductId" resultType="String">
  154. select
  155. image
  156. from productimage
  157. where productID = #{productID,jdbcType=INTEGER}
  158. ORDER BY mainFlag DESC
  159. </select>
  160. <select id="findProductImageString" resultType="string">
  161. select
  162. image
  163. from productimage
  164. where productID = #{productID,jdbcType=INTEGER}
  165. ORDER BY mainFlag DESC
  166. </select>
  167. <select id="findProductDetailById" resultType="com.caimei.module.base.entity.vo.ProductDetailVo">
  168. select
  169. <include refid="ProductDetail_Column_List" />
  170. from productdetailinfo
  171. where productId = #{productId,jdbcType=BIGINT}
  172. </select>
  173. <select id="findProductShopById" resultType="com.caimei.module.base.entity.vo.ShopVo">
  174. SELECT
  175. <include refid="Shop_Column_List" />
  176. ,count(*) as normalNum
  177. FROM shop s
  178. left join product p on s.shopID = p.shopID and p.validFlag = 2
  179. where s.shopID = #{shopID,jdbcType=INTEGER}
  180. group by s.shopID
  181. </select>
  182. <!--新品上线(001) 优惠商品(010) 常用商品(100),三者同时存在111-->
  183. <select id="getProductsByPreferredFlag" resultType="com.caimei.module.base.entity.vo.ProductVo">
  184. select
  185. <include refid="Product_Column_List" />
  186. from product
  187. where validFlag = 2
  188. <if test="preferredFlag == 100">
  189. and preferredFlag in (100,101,110,111)
  190. </if>
  191. <if test="preferredFlag == 10">
  192. and preferredFlag in (10,11,110,111)
  193. </if>
  194. <if test="preferredFlag == 1">
  195. and preferredFlag in (1,11,101,111)
  196. </if>
  197. </select>
  198. <update id="updateSearchHistoryById" parameterType="com.caimei.module.base.entity.vo.SearchHistoryVo">
  199. update user_search_history
  200. <set>
  201. <if test="userId != null">
  202. userId = #{userId,jdbcType=BIGINT},
  203. </if>
  204. <if test="searchWord != null">
  205. searchWord = #{searchWord,jdbcType=VARCHAR},
  206. </if>
  207. <if test="searchDate != null">
  208. searchDate = #{searchDate,jdbcType=TIMESTAMP},
  209. </if>
  210. <if test="delFlag != null">
  211. delFlag = #{delFlag,jdbcType=VARCHAR},
  212. </if>
  213. </set>
  214. where id = #{id,jdbcType=BIGINT}
  215. </update>
  216. <update id="updateViewingNum">
  217. UPDATE cm_second_hand_detail SET
  218. viewingNum = #{viewingNum}
  219. WHERE productID = #{productID}
  220. </update>
  221. <update id="updatSecondHnadproductSold">
  222. UPDATE cm_second_hand_detail SET sold = 1 where productID = #{productID}
  223. </update>
  224. <update id="updateProductValidFlag">
  225. UPDATE product SET validFlag = #{validFlag} where productID = #{productID}
  226. </update>
  227. <insert id="insertSearchHistory" keyColumn="id" keyProperty="id" parameterType="com.caimei.module.base.entity.vo.SearchHistoryVo">
  228. insert into user_search_history
  229. <trim prefix="(" suffix=")" suffixOverrides=",">
  230. <if test="userId != null">
  231. userId,
  232. </if>
  233. <if test="searchWord != null">
  234. searchWord,
  235. </if>
  236. <if test="searchDate != null">
  237. searchDate,
  238. </if>
  239. <if test="delFlag != null">
  240. delFlag,
  241. </if>
  242. </trim>
  243. <trim prefix="values (" suffix=")" suffixOverrides=",">
  244. <if test="userId != null">
  245. #{userId,jdbcType=BIGINT},
  246. </if>
  247. <if test="searchWord != null">
  248. #{searchWord,jdbcType=VARCHAR},
  249. </if>
  250. <if test="searchDate != null">
  251. #{searchDate,jdbcType=TIMESTAMP},
  252. </if>
  253. <if test="delFlag != null">
  254. #{delFlag,jdbcType=VARCHAR},
  255. </if>
  256. </trim>
  257. </insert>
  258. <insert id="saveSencondHandProduct" parameterType="com.caimei.module.base.entity.po.SeconHandProduct" keyProperty="id" useGeneratedKeys="true">
  259. INSERT INTO cm_second_hand_detail(
  260. productID,
  261. sold,
  262. secondHandType,
  263. instrumentType,
  264. fixedYears,
  265. maturityYears,
  266. companyName,
  267. detailTalkFlag,
  268. originalPrice,
  269. contactName,
  270. contactMobile,
  271. secondProductType,
  272. townId,
  273. brandName,
  274. provinceCityDistrict,
  275. address,
  276. productQuality,
  277. productDetails,
  278. viewingNum,
  279. payStatus,
  280. payAmount,
  281. payFormData,
  282. payType,
  283. payDate,
  284. submitDate,
  285. reviewedDate,
  286. onLineDate,
  287. source
  288. ) VALUES (
  289. #{productID},
  290. #{sold},
  291. #{secondHandType},
  292. #{instrumentType},
  293. #{fixedYears},
  294. #{maturityYears},
  295. #{companyName},
  296. #{detailTalkFlag},
  297. #{originalPrice},
  298. #{contactName},
  299. #{contactMobile},
  300. #{secondProductType},
  301. #{townId},
  302. #{brandName},
  303. #{provinceCityDistrict},
  304. #{address},
  305. #{productQuality},
  306. #{productDetails},
  307. #{viewingNum},
  308. #{payStatus},
  309. #{payAmount},
  310. #{payFormData},
  311. #{payType},
  312. #{payDate},
  313. #{submitDate},
  314. #{reviewedDate},
  315. #{onLineDate},
  316. #{source}
  317. )
  318. </insert>
  319. <!--删除大于10条的历史记录-->
  320. <delete id="deleteSearchHistoryByUserId">
  321. DELETE FROM user_search_history
  322. WHERE userId=#{userId}
  323. AND id NOT IN (
  324. SELECT temp.id FROM (
  325. SELECT id FROM user_search_history WHERE userId=#{userId} ORDER BY id DESC LIMIT 10
  326. ) AS temp
  327. )
  328. </delete>
  329. <select id="getAddressInfo" resultType="com.caimei.module.base.entity.vo.AddressVo">
  330. SELECT a.name as "province"
  331. ,b.name as "city"
  332. ,c.name as "town"
  333. ,c.townId as "townID"
  334. FROM province a
  335. RIGHT JOIN city b ON a.provinceId = b.provinceId
  336. RIGHT JOIN town c ON b.cityId = c.cityId WHERE c.townId = #{townId}
  337. </select>
  338. <delete id="deleteAllSearchHistory">
  339. DELETE FROM
  340. user_search_history
  341. WHERE
  342. userId=#{userId}
  343. </delete>
  344. <select id="findLadderPrice" resultType="com.caimei.module.base.entity.vo.LadderPriceVo">
  345. SELECT
  346. <include refid="LadderPrice_Column_List" />
  347. FROM
  348. product_ladder_price
  349. WHERE
  350. productId = #{productID}
  351. AND userType = '3'
  352. AND delFlag = '0'
  353. ORDER BY
  354. ladderNum ASC
  355. </select>
  356. <select id="getRecommendIds" resultType="java.lang.Integer">
  357. SELECT recommendProductID FROM cm_product_recommend WHERE productID=#{productID} ORDER BY sort ASC
  358. </select>
  359. <select id="getRecommendByIds" resultType="com.caimei.module.base.entity.vo.ProductVo">
  360. SELECT
  361. <include refid="Product_Column_List"/>
  362. FROM
  363. product
  364. WHERE
  365. validFlag = '2'
  366. AND productID IN
  367. <foreach collection="productIDs" open="(" separator="," close=")" item="productID">
  368. #{productID}
  369. </foreach>
  370. </select>
  371. <select id="getDeFaultRecommend" resultType="com.caimei.module.base.entity.vo.ProductVo">
  372. select
  373. <include refid="Product_Column_List" />
  374. from product
  375. where validFlag = 2
  376. and tinyTypeID = #{tinyTypeID}
  377. order by sellNumber desc,onlineTime desc
  378. limit 7
  379. </select>
  380. <select id="getSeconHandProductList" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  381. SELECT
  382. IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",p.*,
  383. cshd.sold AS "sold",
  384. cshd.secondHandType AS "secondHandType",
  385. cshd.instrumentType AS "instrumentType",
  386. cshd.fixedYears AS "fixedYears",
  387. cshd.maturityYears AS "maturityYears",
  388. cshd.companyName AS "companyName",
  389. cshd.detailTalkFlag AS "detailTalkFlag",
  390. cshd.originalPrice AS "originalPrice",
  391. cshd.contactName AS "contactName",
  392. cshd.contactMobile AS "contactMobile",
  393. cshd.secondProductType AS "secondProductType",
  394. cshd.provinceCityDistrict AS "provinceCityDistrict",
  395. cshd.townId as "townId",
  396. cshd.address AS "address",
  397. cshd.productQuality AS "productQuality",
  398. cshd.productDetails AS "productDetails",
  399. cshd.viewingNum AS "viewingNum",
  400. cshd.payStatus AS "payStatus",
  401. cshd.payAmount AS "payAmount",
  402. cshd.payFormData AS "payFormData",
  403. cshd.payType AS "payType",
  404. cshd.payDate AS "payDate",
  405. cshd.submitDate AS "submitDate",
  406. cshd.reviewedDate AS "reviewedDate",
  407. cshd.onLineDate AS "onLineDate",
  408. cshd.source AS "source",
  409. cshd.showContactFlag AS "showContactFlag"
  410. FROM
  411. product p
  412. LEFT JOIN cm_second_hand_detail cshd ON p.productID = cshd.productID
  413. left join cm_brand cb on cb.id = p.brandID
  414. WHERE
  415. p.productCategory = 2
  416. AND p.validFlag = 2
  417. <if test="name != null and name != ''">
  418. and p.name like CONCAT('%',#{name},'%')
  419. </if>
  420. <if test="secondHandType != null and secondHandType != ''">
  421. and cshd.secondHandType = #{secondHandType}
  422. </if>
  423. <if test="instrumentType != null and instrumentType != '' and instrumentType != '0' and instrumentType != 0">
  424. and cshd.instrumentType like CONCAT('%',#{instrumentType},'%')
  425. </if>
  426. ORDER BY cshd.onLineDate DESC
  427. </select>
  428. <select id="getSencondHandProductDetail" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  429. SELECT
  430. IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",p.*,cb.*,cshd.*,cb.description as "brandInfo"
  431. FROM
  432. product p
  433. LEFT JOIN cm_second_hand_detail cshd ON p.productID = cshd.productID
  434. left join cm_brand cb on cb.id = p.brandID
  435. WHERE
  436. p.productCategory = 2
  437. AND p.productID = #{productId}
  438. </select>
  439. <select id="getBrandList" resultType="com.caimei.module.base.entity.po.CmBrand">
  440. select b.id AS id, b.name AS name from cm_brand b
  441. where b.status = '1' and b.delFlag = '0' and b.description is not null and b.description != '' and b.id not in (161)
  442. order by b.sort
  443. </select>
  444. <select id="getSecondHandProductRecommend" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  445. select * from cm_second_hand_recommend cshr LEFT JOIN product p on cshr.recommendProductID = p.productID where cshr.delFlag = 0 and p.validFlag = 2 and cshr.secondHandProductID = #{productId};
  446. </select>
  447. <select id="getOrderSecondHandProductList" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  448. SELECT
  449. *
  450. FROM
  451. product p
  452. LEFT JOIN cm_second_hand_detail cshd ON cshd.productID = p.productID
  453. WHERE
  454. p.productCategory = 2 and p.validFlag = 2
  455. <if test="secondHandType != null and secondHandType != ''">
  456. and cshd.secondHandType = #{secondHandType}
  457. </if>
  458. <if test="instrumentType != null and instrumentType != ''">
  459. and cshd.instrumentType like CONCAT('%',#{instrumentType},'%')
  460. </if>
  461. <if test="searchKeyword != null and searchKeyword != ''">
  462. and p.name like CONCAT('%',#{searchKeyword},'%')
  463. </if>
  464. and cshd.sold != 1
  465. ORDER BY cshd.onLineDate DESC
  466. </select>
  467. <select id="getSeconHandProductByLimit" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  468. SELECT
  469. *
  470. FROM
  471. product p
  472. LEFT JOIN cm_second_hand_detail cshd ON p.productID = cshd.productID
  473. WHERE
  474. p.productCategory = 2
  475. AND p.validFlag = 2
  476. <if test="secondHandType != null and secondHandType != ''">
  477. and cshd.secondHandType = #{secondHandType}
  478. </if>
  479. ORDER BY cshd.onLineDate DESC
  480. limit 10
  481. </select>
  482. <select id="getSecondHandProductListByMaturity"
  483. resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  484. SELECT
  485. *
  486. FROM
  487. cm_second_hand_detail cshd
  488. LEFT JOIN product p ON p.productID = cshd.productID
  489. WHERE
  490. p.validFlag = 2
  491. AND cshd.onLineDate <![CDATA[ < ]]> #{beforeDays}
  492. </select>
  493. </mapper>