<?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.print.ReprintCodeDao">

	<sql id="columns">
		a.`id` AS "id",
		a.`label_application_id` AS "labelApplicationId",
		a.`detail_id` AS "detailId",
		a.`is_print` AS "isPrint",
		a.`print_status` AS "printStatus",
		a.`number` AS "number",
		a.`create_time` AS "cTime",
		a.`update_time` AS "updateTime",
		a.`tag_type_id` AS "tagTypeId",
		a.`materiel_id` AS "materielId",
		a.`materiel_code` AS "materielCode",
		a.`materiel_describe` AS "materielDescribe",
		a.`goods_code` AS "goodsCode",
		a.`goods_name` AS "goodsName",
		a.`minimum_packing_number` AS "minimumPackingNumber",
		a.`minimum_packing_unit` AS "minimumPackingUnit"
	</sql>

	<sql id="joins">
	</sql>

	<insert id="save">
		INSERT INTO
			reprint_code
		(
			`id`,
			`label_application_id`,
			`detail_id`,
			`is_print`,
			`print_status`,
			`number`,
			`tag_type_id`,
			`materiel_id`,
			`materiel_code`,
			`materiel_describe`,
			`goods_code`,
			`goods_name`,
			`minimum_packing_number`,
			`minimum_packing_unit`
		)
		VALUES
			(
				#{id},
				#{labelApplicationId},
				#{detailId},
				#{isPrint},
				#{printStatus},
				#{number},
				#{tagTypeId},
				#{materielId},
				#{materielCode},
				#{materielDescribe},
				#{goodsCode},
				#{goodsName},
				#{minimumPackingNumber},
				#{minimumPackingUnit}
			)
	</insert>
	<update id="updatePrintBash">
		<foreach item="reprintCode" index="index" collection="reprintCodes" separator=";">
			UPDATE
			reprint_code
			SET
			<if test="reprintCode.number != null and reprintCode.number > 0">
				`number` = #{reprintCode.number},
			</if>
			`is_print` = #{reprintCode.isPrint},
			`print_status` = #{reprintCode.printStatus}
			WHERE `id` = #{reprintCode.id}
		</foreach>
	</update>
	<delete id="deleteById">
		DELETE
		FROM reprint_code
		WHERE `id` = #{id}
	</delete>
	<select id="getReprinting" resultType="com.scm.contract.model.print.ReprintCode">
		SELECT
		<include refid="columns"/>
		FROM reprint_code a
		<include refid="joins"/>
		WHERE a.is_print = #{isPrint}
	</select>
	<select id="getListByIds" resultType="com.scm.contract.model.print.ReprintCode">
		SELECT
		<include refid="columns"/>
		FROM reprint_code a
		<include refid="joins"/>
		WHERE a.`id` IN
		<foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
			#{id}
		</foreach>
	</select>
	<select id="getListBylApplicationIds" resultType="com.scm.contract.model.print.ReprintCode">
		SELECT
		<include refid="columns"/>
		FROM reprint_code a
		<include refid="joins"/>
		WHERE a.`label_application_id` IN
		<foreach item="id" index="index" collection="reprintLabelApplicationIds" open="(" separator="," close=")">
			#{id}
		</foreach>
	</select>
</mapper>
