<?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.PrintManagementDao">

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

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

	<select id="findList" resultType="com.scm.contract.model.print.PrintManagement">
		SELECT
			*
		FROM
			(
				SELECT
					<include refid="columns"/>,
					`create_time` AS "printTime",
					TRUE AS "isReprint"
				FROM
					`reprint_code` UNION ALL
				SELECT
					<include refid="columns"/>,
					`print_time` AS "printTime",
					FALSE AS "isReprint"
				FROM
					`label_application_detail`
			) a
		<where>
			<if test="id != null and id != ''">
				AND a.id = #{id}
			</if>
			<if test="isPrint != null">
				AND a.isPrint = #{isPrint}
			</if>
			<if test="printStatus != null and printStatus != ''">
				AND a.printStatus = #{printStatus}
			</if>
		</where>
		ORDER BY
			`a`.`printTime`,`a`.`labelApplicationId`,`a`.`goodsCode`,`a`.`minimumPackingNumber`
	</select>


</mapper>
