<?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="cn.com.ty.lift.business.contract.dao.mapper.ContractsMapper" >
    <resultMap id="BaseResultMap" type="cn.com.ty.lift.business.contract.dao.entity.Contracts" >
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="project_id" property="projectId" jdbcType="BIGINT" />
        <result column="mt_company_id" property="mtCompanyId" jdbcType="BIGINT" />
        <result column="code" property="code" jdbcType="VARCHAR" />
        <result column="source" property="source" jdbcType="INTEGER" />
        <result column="pay_mode" property="payMode" jdbcType="VARCHAR" />
        <result column="lift_num" property="liftNum" jdbcType="INTEGER" />
        <result column="moneys" property="moneys" jdbcType="DECIMAL" />
        <result column="plan_money_total" property="planMoneyTotal" jdbcType="DECIMAL" />
        <result column="work_money_total" property="workMoneyTotal" jdbcType="DECIMAL" />
        <result column="invoice_money_total" property="invoiceMoneyTotal" jdbcType="DECIMAL" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="status" property="status" jdbcType="INTEGER" />
        <result column="given_date" property="givenDate" jdbcType="TIMESTAMP" />
        <result column="given_user" property="givenUser" jdbcType="VARCHAR" />
        <result column="star_date" property="starDate" jdbcType="TIMESTAMP" />
        <result column="end_date" property="endDate" jdbcType="TIMESTAMP" />
        <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
        <result column="next_id" property="nextId" jdbcType="BIGINT" />
        <result column="accessory_url" property="accessoryUrl" jdbcType="LONGVARCHAR" />
        <result column="end_reason" property="endReason" jdbcType="LONGVARCHAR" />
        <result column="remarks" property="remarks" jdbcType="LONGVARCHAR" />
        <result column="previous_id" property="previousId" jdbcType="BIGINT" />
    </resultMap>

    <sql id="Base_Column_List" >
		id, project_id, mt_company_id, code, source, pay_mode, lift_num, moneys, type, status,
		given_date, given_user, star_date, end_date, create_date, next_id, previous_id, accessory_url, end_reason, remarks
	</sql>

    <!-- 根据项目、合同号、合同类型、合同状态查询合同管理列表-->
    <select id="findByCondition" resultType="cn.com.ty.lift.business.contract.dao.entity.model.response.ContractResponse"
            parameterType="cn.com.ty.lift.business.contract.dao.entity.model.request.ContractRequest" >
        SELECT
            c.id            AS id,
            c.code          AS contractCode,
            c.next_id       AS nextId,
            c.source        AS contractSource,
            c.type          AS contractType,
            c.star_date     AS starDate,
            c.end_date      AS endDate,
            c.lift_num      AS liftNum,
            c.moneys        AS moneys,
            c.given_date    AS givenDate,
            c.given_user    AS givenUser,
            c.accessory_url AS accessoryUrl,
            c.remarks       AS remarks,
            c.status        AS contractStatus,
            p.project_name  AS projectName,
            c.is_check      AS isCheck
            FROM contracts c
        LEFT JOIN project p ON c.project_id = p.id
        WHERE c.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
        <if test="request.contractCode!=null and request.contractCode!=''">
            AND c.code LIKE CONCAT('%',#{request.contractCode,jdbcType=VARCHAR},'%')
        </if>
        <if test="request.contractType!=null and request.contractType!=''">
            AND c.type = #{request.contractType,jdbcType=INTEGER}
        </if>
        <if test="request.contractStatus!=null and request.contractStatus!=''">
            AND c.status = #{request.contractStatus,jdbcType=INTEGER}
        </if>
        <if test="request.projectName!=null and request.projectName!=''">
            AND p.project_name LIKE CONCAT('%',#{request.projectName,jdbcType=VARCHAR},'%')
        </if>
    </select>

</mapper>