<?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.scm.contract.dao.management.MaterielDao">

	<sql id="columns">
		a.`id` AS "id",
		a.`goods_code` AS "goodsCode",
		a.`materiel_code` AS "materielCode",
		a.`goods_name` AS "goodsName",
		a.`big_category_id` AS "bigCategoryId",
		a.`middle_category_id` AS "middleCategoryId",
		a.`small_category_id` AS "smallCategoryId",
		a.`materiel_describe` AS "materielDescribe",
		a.`brand` AS "brand",
		a.`manufacturer` AS "manufacturer",
		a.`provider_id` AS "providerId",
		a.`specifications` AS "specifications",
		a.`minimum_packing_number` AS "minimumPackingNumber",
		a.`minimum_packing_unit` AS "minimumPackingUnit",
		a.`tag_type_id` AS "tagTypeId",
		a.`create_time` AS "cTime",
		a.`update_time` AS "updateTime"
	</sql>

	<sql id="joins">
	</sql>
    <update id="updateTagType">
		<foreach item="materiel" index="index" collection="materiels" separator=";">
			UPDATE
				materiel_data a
			SET
				a.`tag_type_id` = #{materiel.tagTypeId}
			WHERE
			    a.`id` = #{materiel.id}
		</foreach>
	</update>

    <select id="list" resultType="com.scm.contract.model.management.Materiel">
		SELECT
		<include refid="columns"/>
		FROM materiel_data a
		<include refid="joins"/>
	</select>

	<select id="findList" resultType="com.scm.contract.model.management.Materiel">
		SELECT
		<include refid="columns"/>
		FROM materiel_data a
		<include refid="joins"/>
		<where>
			<if test="id != null and id != ''">
				AND a.`id` = #{id}
			</if>
			<if test="goodsName != null and goodsName != ''">
				AND a.`goods_name` LIKE '%' #{goodsName} '%'
			</if>
			<if test="materielDescribe != null and materielDescribe != ''">
				AND a.`materiel_describe` LIKE '%' #{materielDescribe} '%'
			</if>
			<if test="materielCode != null and materielCode != ''">
				AND a.`materiel_code` LIKE '%' #{materielCode} '%'
			</if>
			<if test="bigCategoryId != null and bigCategoryId != ''">
				AND a.`big_category_id` = #{bigCategoryId}
			</if>
			<if test="middleCategoryId != null and middleCategoryId != ''">
				AND a.`middle_category_id` = #{middleCategoryId}
			</if>
			<if test="smallCategoryId != null and smallCategoryId != ''">
				AND a.`small_category_id` = #{smallCategoryId}
			</if>
			<if test="providerId != null and providerId != ''">
				AND a.`provider_id` = #{providerId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
		</choose>
	</select>
	<select id="listByIds" resultType="com.scm.contract.model.management.Materiel">
		SELECT
		<include refid="columns"/>
		FROM materiel_data a
		<include refid="joins"/>
		WHERE a.id IN
		<foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
			#{id}
		</foreach>
	</select>

	<select id="getById" resultType="com.scm.contract.model.management.Materiel">
		SELECT
		<include refid="columns"/>
		FROM materiel_data a
		<include refid="joins"/>
		WHERE a.`id` = #{id}
	</select>

</mapper>
