<?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.muchinfo.mtp3interface.mapper.IPerformanceplantemplateMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.muchinfo.mtp3pojos.entity.Performanceplantemplate">
        <id column="AUTOID" property="autoid" />
        <result column="TEMPLATENAME" property="templatename" />
        <result column="PAYMENTTYPE" property="paymenttype" />
        <result column="CREATETIME" property="createtime" />
        <result column="CREATORID" property="creatorid" />
        <result column="TEMPLATETYPE" property="templatetype" />
        <result column="TAKEMODE" property="takemode" />
        <result column="USERID" property="userid" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        AUTOID, TEMPLATENAME, PAYMENTTYPE, CREATETIME, CREATORID, TEMPLATETYPE, TAKEMODE, USERID
    </sql>
    <select id="querySpotFulfillment"
            resultType="com.muchinfo.mtp3pojos.vo.tradingmarket.SpotFulfillmentResult">
        SELECT
        ppt.AUTOID,
        ppt.TEMPLATENAME,
        ppt.PAYMENTTYPE,
        ppt.TEMPLATETYPE TYPE,
        ppt.CREATETIME,
        ppt.CREATORID,
        ppt.userid,
        SM.username as creatorname
        FROM
        PERFORMANCEPLANTEMPLATE ppt
        LEFT JOIN SYSTEMMANAGER sm ON PPT.CREATORID = SM.AUTOID
        <where>
            <choose>
                <when test="type != null and type == 1">
                    and ppt.TEMPLATETYPE in (0,1)
                </when>
                <when test="type != null and type == 2">
                    and ppt.TEMPLATETYPE in (0,2,3,7,8,9)
                </when>
                <otherwise>

                </otherwise>
            </choose>
        </where>
        ORDER BY ppt.CREATETIME DESC
    </select>
    <select id="getPerformanceStepByTmpId" resultType="com.muchinfo.mtp3pojos.entity.Performancesteptemplate"
            parameterType="java.lang.Long">
        select p.performancestepid,
               p.planid,
               p.stepindex,
               p.stepdays,
               p.steptypeid,
               pt.StepTypeName,
               p.stepvalue,
               p.stepamount,
               p.realamount,
               p.remaindays,
               p.delaydays,
               p.isauto,
               p.islastreceivestep,
               p.stepstatus,
               p.steplanchtype,
               p.executeside,
               p.starttime,
               p.endtime,
               p.remark,
               p.stepremark
        from PerformanceStep p
                 left join PerformancePlan pl on pl.PerformancePlanID = p.planid
                 left join PerformanceStepType pt on p.StepTypeID = pt.StepTypeID
        where p.planid = #{autoid}
        order by p.starttime asc
    </select>

</mapper>
