<?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.erp.print.repository.PrintTemplateRepository">

    <resultMap id="BaseResultMap" type="com.erp.print.entity.PrintTemplate">
        <id column="id" property="id"/>
        <result column="template_code" property="templateCode"/>
        <result column="template_name" property="templateName"/>
        <result column="template_type" property="templateType"/>
        <result column="template_content" property="templateContent"/>
        <result column="description" property="description"/>
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="is_default" property="isDefault"/>
        <result column="status" property="status"/>
        <result column="creator_id" property="creatorId"/>
        <result column="creator_name" property="creatorName"/>
        <result column="created_at" property="createdAt"/>
        <result column="updated_at" property="updatedAt"/>
        <result column="deleted" property="deleted"/>
    </resultMap>

    <select id="selectPageList" resultMap="BaseResultMap">
        SELECT * FROM print_template WHERE deleted = 0
        <if test="templateType != null and templateType != ''">
            AND template_type = #{templateType}
        </if>
        ORDER BY created_at DESC
    </select>

    <select id="selectByTemplateCode" resultMap="BaseResultMap">
        SELECT * FROM print_template WHERE deleted = 0 AND template_code = #{templateCode}
    </select>

    <select id="selectDefaultByType" resultMap="BaseResultMap">
        SELECT * FROM print_template WHERE deleted = 0 AND template_type = #{templateType} AND is_default = 1
    </select>

</mapper>
