ProductModuleMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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
  33. </sql>
  34. <sql id="ProductDetail_Column_List">
  35. productDetailInfoID, productID, propValueAlias, propValueImages, detailInfo, detailInfoTxt,
  36. seoTitle, seoKeyword, seoDes, serviceInfo, orderInfo
  37. </sql>
  38. <sql id="LadderPrice_Column_List">
  39. id, productId, userType, ladderNum, buyNum, buyPrice, createBy, createDate, updateBy,
  40. updateDate, delFlag
  41. </sql>
  42. <sql id="Image_Column_List">
  43. productImageID, productID, shopID, addTime, image, mainFlag, sortIndex
  44. </sql>
  45. <sql id="Shop_Column_List">
  46. shopID, userID, `name`, sname, nameEn, site, ledgerNo, logo, rebateAmount, `level`,
  47. score, productCount, legalPerson, businessLicense, businessLicenseImage, taxCertificate,
  48. taxCertificateImage, provinceID, cityID, townID, address, registeredCapital, nature,
  49. turnover, linkMan, contractPhone, contractMobile, fax, zipCode, linkMan1, duty1,
  50. contractPhone1, contractMobile1, contractQQ1, wechat1, contractEmail1, linkMan2,
  51. duty2, contractPhone2, contractMobile2, contractQQ2, wechat2, contractEmail2, `scope`,
  52. info, productDesc, lng, lat, addTime, auditStatus, auditTime, auditNote, favoriteTimes,
  53. validFlag, payFlag1, auditFlag1, payFlag2, auditFlag2, payFlag3, auditFlag3, note,
  54. `status`, sortIndex, rate1, rate2, masterFlag, erpFlag, shopSecret, masterLogo, cooperateFlag,
  55. bail, businessScope, socialCreditCode, mainpro, firstShopType, secondShopType, medicalPracticeLicenseImg1,
  56. medicalPracticeLicenseImg2, medicalPracticeLicenseImg3, bankAccount, bankAccountName,
  57. bankName, ableRebateAmount,authorizationCertificateImage
  58. </sql>
  59. <select id="getBigType" resultType="com.caimei.module.base.entity.vo.BigtypeVo">
  60. select
  61. <include refid="BigType_Column_List" />
  62. from bigtype
  63. where validFlag = '1'
  64. </select>
  65. <select id="getSmallType" resultType="com.caimei.module.base.entity.vo.SmalltypeVo">
  66. select
  67. <include refid="SmallType_Column_List" />
  68. from smalltype
  69. where bigTypeID = #{bigTypeID,jdbcType=INTEGER}
  70. and validFlag = '1'
  71. </select>
  72. <select id="getTinytype" resultType="com.caimei.module.base.entity.vo.TinytypeVo">
  73. select
  74. <include refid="Tinytype_Column_List" />
  75. from tinytype
  76. where smallTypeID = #{smallTypeID,jdbcType=INTEGER}
  77. and validFlag = '1'
  78. </select>
  79. <!-- sortType (3:价格升序, 4:价格降序, 7:人气, 8:销量) -->
  80. <select id="getProductsByTinyType" resultType="com.caimei.module.base.entity.vo.ProductVo" parameterType="java.lang.Integer">
  81. select
  82. <include refid="Product_Column_List" />
  83. from product
  84. where validFlag = 2
  85. and tinyTypeID = #{tinyTypeID,jdbcType=INTEGER}
  86. <choose>
  87. <when test="sortType == 3">
  88. order by price1 asc
  89. </when>
  90. <when test="sortType == 4">
  91. order by price1 desc
  92. </when>
  93. <when test="sortType == 7">
  94. order by favoriteTimes desc
  95. </when>
  96. <when test="sortType == 8">
  97. order by sellNumber desc
  98. </when>
  99. <otherwise>
  100. order by onlineTime desc
  101. </otherwise>
  102. </choose>
  103. </select>
  104. <select id="searchProduct" resultType="com.caimei.module.base.entity.vo.ProductVo">
  105. select
  106. *
  107. from product
  108. where validFlag = 2
  109. and name like CONCAT('%',#{searchWord,jdbcType=VARCHAR},'%')
  110. </select>
  111. <select id="findProductById" resultType="com.caimei.module.base.entity.vo.ProductVo">
  112. select
  113. <include refid="Product_Column_List" />
  114. from product
  115. where validFlag in (2,3,9)
  116. and productId = #{productId,jdbcType=BIGINT}
  117. </select>
  118. <select id="getSearchHistoryList" resultType="com.caimei.module.base.entity.vo.SearchHistoryVo">
  119. select id, userId, searchWord, searchDate, delFlag
  120. from user_search_history
  121. where userId = #{userId,jdbcType=BIGINT}
  122. order by id desc
  123. </select>
  124. <select id="getSearchHistoryIdByWord" resultType="java.lang.Long">
  125. select id
  126. from user_search_history
  127. where searchWord = #{searchWord,jdbcType=VARCHAR}
  128. limit 1
  129. </select>
  130. <select id="findLowerLadderPrice" resultType="com.caimei.module.base.entity.vo.LadderPriceVo">
  131. select
  132. <include refid="LadderPrice_Column_List" />
  133. from product_ladder_price
  134. WHERE delFlag = '0'
  135. AND productId = #{productId,jdbcType=BIGINT}
  136. ORDER BY ladderNum DESC
  137. LIMIT 1
  138. </select>
  139. <select id="findProductImage" resultType="com.caimei.module.base.entity.vo.ProductImageVo">
  140. select
  141. <include refid="Image_Column_List" />
  142. from productimage
  143. where productID = #{productID,jdbcType=INTEGER}
  144. ORDER BY mainFlag DESC
  145. </select>
  146. <select id="findImageByProductId" resultType="String">
  147. select
  148. image
  149. from productimage
  150. where productID = #{productID,jdbcType=INTEGER}
  151. ORDER BY mainFlag DESC
  152. </select>
  153. <select id="findProductImageString" 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="findProductDetailById" resultType="com.caimei.module.base.entity.vo.ProductDetailVo">
  161. select
  162. <include refid="ProductDetail_Column_List" />
  163. from productdetailinfo
  164. where productId = #{productId,jdbcType=BIGINT}
  165. </select>
  166. <select id="findProductShopById" resultType="com.caimei.module.base.entity.vo.ShopVo">
  167. SELECT
  168. <include refid="Shop_Column_List" />
  169. FROM shop
  170. where shopID = #{shopID,jdbcType=INTEGER}
  171. </select>
  172. <!--新品上线(001) 优惠商品(010) 常用商品(100),三者同时存在111-->
  173. <select id="getProductsByPreferredFlag" resultType="com.caimei.module.base.entity.vo.ProductVo">
  174. select
  175. <include refid="Product_Column_List" />
  176. from product
  177. where validFlag = 2
  178. <if test="preferredFlag == 100">
  179. and preferredFlag in (100,101,110,111)
  180. </if>
  181. <if test="preferredFlag == 10">
  182. and preferredFlag in (10,11,110,111)
  183. </if>
  184. <if test="preferredFlag == 1">
  185. and preferredFlag in (1,11,101,111)
  186. </if>
  187. </select>
  188. <update id="updateSearchHistoryById" parameterType="com.caimei.module.base.entity.vo.SearchHistoryVo">
  189. update user_search_history
  190. <set>
  191. <if test="userId != null">
  192. userId = #{userId,jdbcType=BIGINT},
  193. </if>
  194. <if test="searchWord != null">
  195. searchWord = #{searchWord,jdbcType=VARCHAR},
  196. </if>
  197. <if test="searchDate != null">
  198. searchDate = #{searchDate,jdbcType=TIMESTAMP},
  199. </if>
  200. <if test="delFlag != null">
  201. delFlag = #{delFlag,jdbcType=VARCHAR},
  202. </if>
  203. </set>
  204. where id = #{id,jdbcType=BIGINT}
  205. </update>
  206. <update id="updateViewingNum">
  207. UPDATE cm_second_hand_detail SET
  208. viewingNum = #{viewingNum}
  209. WHERE id = #{id}
  210. </update>
  211. <update id="updatSecondHnadproductSold">
  212. UPDATE cm_second_hand_detail SET sold = 1 where productID = #{productID}
  213. </update>
  214. <update id="updateProductValidFlag">
  215. UPDATE product SET validFlag = #{validFlag} where productID = #{productID}
  216. </update>
  217. <insert id="insertSearchHistory" keyColumn="id" keyProperty="id" parameterType="com.caimei.module.base.entity.vo.SearchHistoryVo">
  218. insert into user_search_history
  219. <trim prefix="(" suffix=")" suffixOverrides=",">
  220. <if test="userId != null">
  221. userId,
  222. </if>
  223. <if test="searchWord != null">
  224. searchWord,
  225. </if>
  226. <if test="searchDate != null">
  227. searchDate,
  228. </if>
  229. <if test="delFlag != null">
  230. delFlag,
  231. </if>
  232. </trim>
  233. <trim prefix="values (" suffix=")" suffixOverrides=",">
  234. <if test="userId != null">
  235. #{userId,jdbcType=BIGINT},
  236. </if>
  237. <if test="searchWord != null">
  238. #{searchWord,jdbcType=VARCHAR},
  239. </if>
  240. <if test="searchDate != null">
  241. #{searchDate,jdbcType=TIMESTAMP},
  242. </if>
  243. <if test="delFlag != null">
  244. #{delFlag,jdbcType=VARCHAR},
  245. </if>
  246. </trim>
  247. </insert>
  248. <insert id="saveSencondHandProduct" parameterType="com.caimei.module.base.entity.po.SeconHandProduct" keyProperty="id" useGeneratedKeys="true">
  249. INSERT INTO cm_second_hand_detail(
  250. productID,
  251. sold,
  252. secondHandType,
  253. instrumentType,
  254. fixedYears,
  255. maturityYears,
  256. companyName,
  257. detailTalkFlag,
  258. originalPrice,
  259. contactName,
  260. contactMobile,
  261. secondProductType,
  262. townId,
  263. brandName,
  264. provinceCityDistrict,
  265. address,
  266. productQuality,
  267. productDetails,
  268. viewingNum,
  269. payStatus,
  270. payAmount,
  271. payFormData,
  272. payType,
  273. payDate,
  274. submitDate,
  275. reviewedDate,
  276. onLineDate,
  277. source
  278. ) VALUES (
  279. #{productID},
  280. #{sold},
  281. #{secondHandType},
  282. #{instrumentType},
  283. #{fixedYears},
  284. #{maturityYears},
  285. #{companyName},
  286. #{detailTalkFlag},
  287. #{originalPrice},
  288. #{contactName},
  289. #{contactMobile},
  290. #{secondProductType},
  291. #{townId},
  292. #{brandName},
  293. #{provinceCityDistrict},
  294. #{address},
  295. #{productQuality},
  296. #{productDetails},
  297. #{viewingNum},
  298. #{payStatus},
  299. #{payAmount},
  300. #{payFormData},
  301. #{payType},
  302. #{payDate},
  303. #{submitDate},
  304. #{reviewedDate},
  305. #{onLineDate},
  306. #{source}
  307. )
  308. </insert>
  309. <!--删除大于10条的历史记录-->
  310. <delete id="deleteSearchHistoryByUserId">
  311. DELETE FROM user_search_history
  312. WHERE userId=#{userId}
  313. AND id NOT IN (
  314. SELECT temp.id FROM (
  315. SELECT id FROM user_search_history WHERE userId=#{userId} ORDER BY id DESC LIMIT 10
  316. ) AS temp
  317. )
  318. </delete>
  319. <select id="getAddressInfo" resultType="com.caimei.module.base.entity.vo.AddressVo">
  320. SELECT a.name as "province"
  321. ,b.name as "city"
  322. ,c.name as "town"
  323. ,c.townId as "townID"
  324. FROM province a
  325. RIGHT JOIN city b ON a.provinceId = b.provinceId
  326. RIGHT JOIN town c ON b.cityId = c.cityId WHERE c.townId = #{townId}
  327. </select>
  328. <delete id="deleteAllSearchHistory">
  329. DELETE FROM
  330. user_search_history
  331. WHERE
  332. userId=#{userId}
  333. </delete>
  334. <select id="findLadderPrice" resultType="com.caimei.module.base.entity.vo.LadderPriceVo">
  335. SELECT
  336. <include refid="LadderPrice_Column_List" />
  337. FROM
  338. product_ladder_price
  339. WHERE
  340. productId = #{productID}
  341. AND userType = '3'
  342. AND delFlag = '0'
  343. ORDER BY
  344. ladderNum ASC
  345. </select>
  346. <select id="getRecommendIds" resultType="java.lang.Integer">
  347. SELECT recommendProductID FROM cm_product_recommend WHERE productID=#{productID} ORDER BY sort ASC
  348. </select>
  349. <select id="getRecommendByIds" resultType="com.caimei.module.base.entity.vo.ProductVo">
  350. SELECT
  351. <include refid="Product_Column_List"/>
  352. FROM
  353. product
  354. WHERE
  355. validFlag = '2'
  356. AND productID IN
  357. <foreach collection="productIDs" open="(" separator="," close=")" item="productID">
  358. #{productID}
  359. </foreach>
  360. </select>
  361. <select id="getDeFaultRecommend" resultType="com.caimei.module.base.entity.vo.ProductVo">
  362. select
  363. <include refid="Product_Column_List" />
  364. from product
  365. where validFlag = 2
  366. and tinyTypeID = #{tinyTypeID}
  367. order by sellNumber desc,onlineTime desc
  368. limit 7
  369. </select>
  370. <select id="getSeconHandProductList" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  371. SELECT
  372. IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",p.*,cb.*,cshd.*
  373. FROM
  374. product p
  375. LEFT JOIN cm_second_hand_detail cshd ON p.productID = cshd.productID
  376. left join cm_brand cb on cb.id = p.brandID
  377. WHERE
  378. p.productCategory = 2
  379. AND p.validFlag = 2
  380. <if test="secondHandType != null and secondHandType != ''">
  381. and cshd.secondHandType = #{secondHandType}
  382. </if>
  383. <if test="instrumentType != null and instrumentType != '' and instrumentType != '0' and instrumentType != 0">
  384. and cshd.instrumentType like CONCAT('%',#{instrumentType},'%')
  385. </if>
  386. ORDER BY cshd.onLineDate DESC
  387. </select>
  388. <select id="getSencondHandProductDetail" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  389. SELECT
  390. IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",p.*,cb.*,cshd.*,cb.description as "brandInfo"
  391. FROM
  392. product p
  393. LEFT JOIN cm_second_hand_detail cshd ON p.productID = cshd.productID
  394. left join cm_brand cb on cb.id = p.brandID
  395. WHERE
  396. p.productCategory = 2
  397. AND p.productID = #{productId}
  398. </select>
  399. <select id="getBrandList" resultType="com.caimei.module.base.entity.po.CmBrand">
  400. select b.id AS id, b.name AS name from cm_brand b
  401. where b.status = '1' and b.delFlag = '0' and b.description is not null and b.description != '' and b.id not in (161)
  402. order by b.sort
  403. </select>
  404. <select id="getSecondHandProductRecommend" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  405. 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};
  406. </select>
  407. <select id="getOrderSecondHandProductList" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  408. SELECT
  409. *
  410. FROM
  411. product p
  412. LEFT JOIN cm_second_hand_detail cshd ON cshd.productID = p.productID
  413. WHERE
  414. p.productCategory = 2 and p.validFlag = 2
  415. <if test="secondHandType != null and secondHandType != ''">
  416. and cshd.secondHandType = #{secondHandType}
  417. </if>
  418. <if test="instrumentType != null and instrumentType != ''">
  419. and cshd.instrumentType like CONCAT('%',#{instrumentType},'%')
  420. </if>
  421. <if test="searchKeyword != null and searchKeyword != ''">
  422. and p.name like CONCAT('%',#{searchKeyword},'%')
  423. </if>
  424. and cshd.sold != 1
  425. ORDER BY cshd.onLineDate DESC
  426. </select>
  427. <select id="getSeconHandProductByLimit" resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  428. SELECT
  429. *
  430. FROM
  431. product p
  432. LEFT JOIN cm_second_hand_detail cshd ON p.productID = cshd.productID
  433. WHERE
  434. p.productCategory = 2
  435. AND p.validFlag = 2
  436. <if test="secondHandType != null and secondHandType != ''">
  437. and cshd.secondHandType = #{secondHandType}
  438. </if>
  439. ORDER BY cshd.onLineDate DESC
  440. limit 10
  441. </select>
  442. <select id="getSecondHandProductListByMaturity"
  443. resultType="com.caimei.module.base.entity.po.SeconHandProduct">
  444. SELECT
  445. *
  446. FROM
  447. cm_second_hand_detail cshd
  448. LEFT JOIN product p ON p.productID = cshd.productID
  449. WHERE
  450. p.validFlag = 2
  451. AND cshd.onLineDate <![CDATA[ < ]]> #{beforeDays}
  452. </select>
  453. </mapper>