IMProductSupplierMapper.xml 16.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sibu.orderHelper.integral.web.dao.IMProductSupplierDao">
  <resultMap id="BaseResultMap" type="com.sibu.orderHelper.integral.model.IMProductSupplier">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="product_id" jdbcType="VARCHAR" property="productId" />
    <result column="supplier_id" jdbcType="VARCHAR" property="supplierId" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, product_id, supplier_id
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from im_product_supplier
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from im_product_supplier
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <insert id="insert" parameterType="com.sibu.orderHelper.integral.model.IMProductSupplier">
    insert into im_product_supplier (id, product_id, supplier_id,create_dt
      )
    values (#{id,jdbcType=VARCHAR}, #{productId,jdbcType=VARCHAR}, #{supplierId,jdbcType=VARCHAR},NOW()
      )
  </insert>
  <insert id="insertSelective" parameterType="com.sibu.orderHelper.integral.model.IMProductSupplier">
    insert into im_product_supplier
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="productId != null">
        product_id,
      </if>
      <if test="supplierId != null">
        supplier_id,
      </if>
      create_dt
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="productId != null">
        #{productId,jdbcType=VARCHAR},
      </if>
      <if test="supplierId != null">
        #{supplierId,jdbcType=VARCHAR},
      </if>
      NOW()
    </trim>
  </insert>


  <update id="updateByPrimaryKeySelective" parameterType="com.sibu.orderHelper.integral.model.IMProductSupplier">
    update im_product_supplier
    <set>
      <if test="productId != null">
        product_id = #{productId,jdbcType=VARCHAR},
      </if>
      <if test="supplierId != null">
        supplier_id = #{supplierId,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.sibu.orderHelper.integral.model.IMProductSupplier">
    update im_product_supplier
    set product_id = #{productId,jdbcType=VARCHAR},
      supplier_id = #{supplierId,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="listProductSupplier" parameterType="map" resultMap="supplierProductMap">
    SELECT
    imp.im_product_id,imp.name,imp.short_name,imp.stock_num,
    imp.exchange_integral,imp.xws_exchange_integral,imp.sibukg_exchange_integral,
    imp.onther1_exchange_integral,imp.onther2_exchange_integral,imp.onther3_exchange_integral,
    imp.thumb_img,
    imp.is_new,imp.is_hot,imp.is_reco,
    imp.create_date,
    imp.limit_exchange_number,
    imp.product_type,
    imp.member_price,imp.retail_price,imp.market_price,
    imp.is_show,
    imp.is_open_spec,imp.spec,
    imp.mini_purchase_number,
    imp.erp_code,
    imp.product_campagin,
    imp.is_group,
    imp.share_status,
    imp.share_percentage,
    s.id AS supplierId, s.`name` AS supplierName,s.`contact`,s.`contact_phone`,
    ps.id
    FROM  im_product_supplier ps
    LEFT JOIN im_product imp ON imp.im_product_id=ps.product_id
    LEFT JOIN im_supplier s ON s.`id`=ps.supplier_id
    WHERE imp.delete_flag=1
    <if test="supplierId != null and supplierId !=''">
        and s.`id`=#{supplierId}
      </if>
      <if test="categoryId !=null and categoryId != ''">
        and (imp.im_category_id =#{categoryId} or
        imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})
        or imp.im_category_id in (select ic3.im_category_id from im_category ic3 where ic3.child_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})))
      </if>
      <if test="productName != null and productName !=''">
        and imp.name like concat('%',#{productName},'%')
      </if>
      <if test="erpCode != null and erpCode !=''">
        and imp.erp_code like concat('%',#{erpCode},'%')
      </if>
      <if test="isShow != null and isShow !=''">
        and imp.is_show = ${isShow}
      </if>
      <if test="isHot != null and isHot !=''">
        and imp.is_hot = ${isHot}
      </if>
      <if test="supplierName != null and supplierName !=''">
        and s.`name` like concat('%',#{supplierName},'%')
      </if>
      <if test="contact != null and contact !=''">
        and contact like concat('%',#{contact},'%')
      </if>
      <if test="contactPhone != null and contactPhone !=''">
        and contact_phone = ${contactPhone}
      </if>
      ORDER BY ps.create_dt desc
      LIMIT ${pageNow}, ${pageSize}
  </select>

  <select id="totalProductSupplier" parameterType="map" resultType="java.lang.Integer">
    SELECT COUNT(*)
    FROM  im_product_supplier ps
    LEFT JOIN im_product imp ON imp.im_product_id=ps.product_id
    LEFT JOIN im_supplier s ON s.`id`=ps.supplier_id
    WHERE imp.delete_flag=1
    <if test="supplierId != null and supplierId !=''">
      and s.`id`=#{supplierId}
    </if>
    <if test="categoryId !=null and categoryId != ''">
      and (imp.im_category_id =#{categoryId} or
      imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})
      or imp.im_category_id in (select ic3.im_category_id from im_category ic3 where ic3.child_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})))
    </if>
    <if test="productName != null and productName !=''">
      and imp.name like concat('%',#{productName},'%')
    </if>
    <if test="erpCode != null and erpCode !=''">
      and imp.erp_code like concat('%',#{erpCode},'%')
    </if>
    <if test="isShow != null and isShow !=''">
      and imp.is_show = ${isShow}
    </if>
    <if test="isHot != null and isHot !=''">
      and imp.is_hot = ${isHot}
    </if>
    <if test="supplierName != null and supplierName !=''">
      and s.`name` like concat('%',#{supplierName},'%')
    </if>
    <if test="contact != null and contact !=''">
      and contact like concat('%',#{contact},'%')
    </if>
    <if test="contactPhone != null and contactPhone !=''">
      and contact_phone = ${contactPhone}
    </if>
  </select>

  <select id="listProduct" resultMap="supplierProductMap" parameterType="map">
    SELECT
    imp.im_product_id,
    imp.name,
    imp.short_name,
    imp.stock_num,
    imp.exchange_integral,
    imp.xws_exchange_integral,
    imp.sibukg_exchange_integral,
    imp.onther1_exchange_integral,
    imp.onther2_exchange_integral,
    imp.onther3_exchange_integral,
    imp.thumb_img,
    imp.is_new,
    imp.is_hot,
    imp.is_reco,
    imp.cost,
    imp.attention,
    imp.total_comment_score,
    imp.product_type,
    imp.market_price,
    imp.erp_code,
    imp.total_comment_number,
    imp.is_group
    FROM  im_product imp
    WHERE  imp.delete_flag=1  AND imp.im_product_id NOT IN(
    SELECT ps.product_id FROM  im_product_supplier ps
    )
    <if test="categoryId !=null and categoryId != ''">
      and (imp.im_category_id =#{categoryId} or
      imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})
      or imp.im_category_id in (select ic3.im_category_id from im_category ic3 where ic3.child_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})))
    </if>
    <if test="keyword != null and keyword !=''">
      and imp.name like concat('%',#{keyword},'%')
    </if>
    <if test="erpCode != null and erpCode !=''">
      and imp.erp_code like concat('%',#{erpCode},'%')
    </if>
    <if test="isHot != null and isHot !=''">
      and imp.is_hot = ${isHot}
    </if>
    LIMIT ${pageNow}, ${pageSize}
  </select>

  <select id="totalProduct" resultType="java.lang.Integer" parameterType="map">
    SELECT count(*) FROM  im_product imp
    WHERE  imp.delete_flag=1  AND imp.im_product_id NOT IN(
    SELECT ps.product_id FROM  im_product_supplier ps
    )
    <if test="categoryId !=null and categoryId != ''">
      and (imp.im_category_id =#{categoryId} or
      imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})
      or imp.im_category_id in (select ic3.im_category_id from im_category ic3 where ic3.child_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})))
    </if>
    <if test="keyword != null and keyword !=''">
      and imp.name like concat('%',#{keyword},'%')
    </if>
    <if test="erpCode != null and erpCode !=''">
      and imp.erp_code like concat('%',#{erpCode},'%')
    </if>
    <if test="isHot != null and isHot !=''">
      and imp.is_hot = ${isHot}
    </if>
</select>

  <select id="checkProducTSupplier" parameterType="map" resultType="java.lang.Integer">
    select count(*) from im_product_supplier
    where product_id = #{productId,jdbcType=VARCHAR} and supplier_id = #{supplierId,jdbcType=VARCHAR}
  </select>

  <select id="checkSupplierByProduct" parameterType="java.lang.String" resultType="java.lang.Integer">
    select count(*) from im_product_supplier
    where product_id = #{productId,jdbcType=VARCHAR}
  </select>

  <select id="checkProductToSupplier" parameterType="java.lang.String" resultType="java.lang.Integer">
    select count(*) from im_product_supplier
    where supplier_id = #{supplierId,jdbcType=VARCHAR}
  </select>

  <select id="checkSupplierByAddress" parameterType="java.lang.String" resultType="java.lang.Integer">
    select count(*) from im_supplier_refund_address
    where supplier_id = #{supplierId,jdbcType=VARCHAR}
  </select>

  <select id="totalSupplierProduct" parameterType="java.lang.String" resultType="java.lang.Integer">
    select count(*) from im_product_supplier where supplier_id=#{supplierId}
  </select>

  <insert id="insertCampaginProducts" parameterType="java.util.List">
      INSERT INTO im_product_supplier ( id, product_id, supplier_id,create_dt
      ) VALUES
      <foreach collection="list" item="campaginProduct" separator=",">
        (#{campaginProduct.id}, #{campaginProduct.productId}, #{campaginProduct.supplierId},NOW())
      </foreach>
  </insert>

  <resultMap type="com.sibu.orderHelper.integral.model.SupplierRelatedProduct" id="supplierProductMap">
    <result column="im_product_id" property="imProductId" />
    <result column="im_category_id" property="imCategoryId" />
    <result column="name" property="name" />
    <result column="short_name" property="shortName" />
    <result column="stock_num" property="stockNum" />
    <result column="details" property="details" />
    <result column="exchange_integral" property="exchangeIntegral" />
    <result column="xws_exchange_integral" property="xwsExchangeIntegral" />
    <result column="sibukg_exchange_integral" property="sibukgExchangeIntegral" />
    <result column="onther1_exchange_integral" property="onther1ExchangeIntegral" />
    <result column="onther2_exchange_integral" property="onther2ExchangeIntegral" />
    <result column="onther3_exchange_integral" property="onther3ExchangeIntegral" />
    <result column="thumb_img" property="thumbImg" />
    <result column="bannel_img1" property="bannelImg1" />
    <result column="bannel_img2" property="bannelImg2" />
    <result column="bannel_img3" property="bannelImg3" />
    <result column="bannel_img4" property="bannelImg4" />
    <result column="bannel_img5" property="bannelImg5" />
    <result column="limit_exchange_number" property="limitExchangeNumber"/>
    <result column="is_new" property="isNew" />
    <result column="is_hot" property="isHot" />
    <result column="is_reco" property="isReco" />
    <result column="cost" property="cost" />
    <result column="attention" property="attention" />
    <result column="total_comment_score" property="totalCommentScore" />
    <result column="total_comment_number" property="totalCommentNumber" />
    <result column="create_date" property="createDate"/>
    <result column="product_type" property="productType"/>
    <result column="member_price" property="memberPrice"/>
    <result column="retail_price" property="retailPrice"/>
    <result column="market_price" property="marketPrice"/>
    <result column="delete_flag" property="deleteFlag"/>
    <result column="is_show" property="isShow"/>
    <result column="sort_index" property="sortIndex"/>
    <result column="is_open_spec" property="isOpenSpec"/>
    <result column="spec" property="spec"/>
    <result column="mini_purchase_number" property="miniPurchaseNumber"/>
    <result column="erp_code" property="erpCode"/>
    <result column="format_str" property="formatStr"/>
    <result column="bar_code" property="barCode"/>
    <result column="is_copy" property="isCopy"/>
    <result column="product_campagin" property="productCampagin"/>
    <result column="is_group" property="isGroup"/>
    <result column="share_status" property="shareStatus"/>
    <result column="share_percentage" property="sharePercentage"/>
    <result column="supplierId"  property="supplierId" />
    <result column="supplierName"  property="supplierName" />
    <result column="contact"  property="contact" />
    <result column="contact_phone"  property="contactPhone" />
    <result column="id" property="id"/>
  </resultMap>

  <!-- 根据名字查询供应商-->
  <select id="selectSupplierByName"  parameterType="java.util.Map" resultMap="supplierMap">
    select id,name from im_supplier
      where name = #{supplierName,jdbcType=VARCHAR}
  </select>

  <!-- 根据名字查询供应商-->
  <select id="checkSupplierByName"  parameterType="java.util.Map" resultType="java.lang.Integer">
    select count(*) from im_supplier
    where name = #{supplierName,jdbcType=VARCHAR}
  </select>


  <resultMap type="com.sibu.orderHelper.integral.reponse.ImSupplieResponse" id="supplierMap">
    <result column="id" property="id" />
    <result column="name" property="name" />
  </resultMap>

  <select id="checkGiftSupplierProductRelation" parameterType="java.util.Map" resultType="java.lang.Integer">
    SELECT COUNT(*) FROM im_product_supplier WHERE product_id = #{productId} AND supplier_id = #{supplierId}
  </select>

</mapper>