<?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.zcxk.rmcp.core.dao.ProductMapper">
  <resultMap id="BaseResultMap" type="com.zcxk.rmcp.core.entity.Product">
    <!--@mbg.generated-->
    <!--@Table rmcp_product-->
    <id column="id" property="id" />
    <result column="product_category_id" property="productCategoryId" />
    <result column="manufacturer_id" property="manufacturerId" />
    <result column="product_name" property="productName" />
    <result column="product_model" property="productModel" />
    <result column="product_desc" property="productDesc" />
    <result column="status" property="status" />
    <result column="create_date" property="createDate" />
    <result column="create_by" property="createBy" />
    <result column="update_date" property="updateDate" />
    <result column="update_by" property="updateBy" />
    <result column="is_support_valve" property="isSupportValve" />
    <result column="valve_measuring_code" property="valveMeasuringCode" />
    <result column="reading_measuring_code" property="readingMeasuringCode" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, product_category_id, manufacturer_id, product_name, product_model, product_desc, 
    `status`, create_date, create_by, update_date, update_by, is_support_valve, valve_measuring_code, 
    reading_measuring_code
  </sql>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.zcxk.rmcp.core.entity.Product" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into rmcp_product
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="productCategoryId != null">
        product_category_id,
      </if>
      <if test="manufacturerId != null">
        manufacturer_id,
      </if>
      <if test="productName != null">
        product_name,
      </if>
      <if test="productModel != null">
        product_model,
      </if>
      <if test="productDesc != null">
        product_desc,
      </if>
      <if test="status != null">
        `status`,
      </if>
      <if test="createDate != null">
        create_date,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="updateDate != null">
        update_date,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="isSupportValve != null">
        is_support_valve,
      </if>
      <if test="valveMeasuringCode != null">
        valve_measuring_code,
      </if>
      <if test="readingMeasuringCode != null">
        reading_measuring_code,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="productCategoryId != null">
        #{productCategoryId},
      </if>
      <if test="manufacturerId != null">
        #{manufacturerId},
      </if>
      <if test="productName != null">
        #{productName},
      </if>
      <if test="productModel != null">
        #{productModel},
      </if>
      <if test="productDesc != null">
        #{productDesc},
      </if>
      <if test="status != null">
        #{status},
      </if>
      <if test="createDate != null">
        #{createDate},
      </if>
      <if test="createBy != null">
        #{createBy},
      </if>
      <if test="updateDate != null">
        #{updateDate},
      </if>
      <if test="updateBy != null">
        #{updateBy},
      </if>
      <if test="isSupportValve != null">
        #{isSupportValve},
      </if>
      <if test="valveMeasuringCode != null">
        #{valveMeasuringCode},
      </if>
      <if test="readingMeasuringCode != null">
        #{readingMeasuringCode},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.zcxk.rmcp.core.entity.Product">
    <!--@mbg.generated-->
    update rmcp_product
    <set>
      <if test="productCategoryId != null">
        product_category_id = #{productCategoryId},
      </if>
      <if test="manufacturerId != null">
        manufacturer_id = #{manufacturerId},
      </if>
      <if test="productName != null">
        product_name = #{productName},
      </if>
      <if test="productModel != null">
        product_model = #{productModel},
      </if>
      <if test="productDesc != null">
        product_desc = #{productDesc},
      </if>
      <if test="status != null">
        `status` = #{status},
      </if>
      <if test="createDate != null">
        create_date = #{createDate},
      </if>
      <if test="createBy != null">
        create_by = #{createBy},
      </if>
      <if test="updateDate != null">
        update_date = #{updateDate},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy},
      </if>
      <if test="isSupportValve != null">
        is_support_valve = #{isSupportValve},
      </if>
      <if test="valveMeasuringCode != null">
        valve_measuring_code = #{valveMeasuringCode},
      </if>
      <if test="readingMeasuringCode != null">
        reading_measuring_code = #{readingMeasuringCode},
      </if>
    </set>
    where id = #{id}
  </update>

  <select id="findList" resultType="com.zcxk.rmcp.api.dto.product.ProductVo">
    select
    rp.id,
    rp.product_category_id as category_id,
    rp.manufacturer_id,
    rp.product_name,
    rp.product_model,
    rm.name as manufacturer_name
    from rmcp_product rp left join rmcp_manufacturer rm on rp.manufacturer_id = rm.id
    where rp.status = 1
    <if test="categoryId != null">and product_category_id = #{categoryId}</if>
    order by rm.create_date desc
  </select>

  <select id="findById" resultType="com.zcxk.rmcp.core.entity.Product">
    select <include refid="Base_Column_List"></include>
    from rmcp_product
    where
    id = #{id} and status = 1
  </select>

  <select id="getByName" resultMap="BaseResultMap">
    select id,product_category_id,manufacturer_id from rmcp_product where status = 1 and product_name = #{productName} and product_model = #{productModel}
    </select>
</mapper>