<?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.nantian.cloud.dbcapp.mapper.record.TApplyRecordMapper">

    <resultMap id="BaseResultMap" type="com.nantian.cloud.dbcapp.entity.TApplyRecord">
        <id column="id" property="id" />
        <result column="enterprise_code" property="enterpriseCode" />
        <result column="collect_name" property="collectName" />
        <result column="edit_reason" property="editReason" />
        <result column="remark" property="remark" />
        <result column="data_code" property="dataCode" />
        <result column="apply_time" property="applyTime" />
        <result column="data_value" property="dataValue" />
        <result column="audit_type" property="auditType" />
        <result column="apply_type" property="applyType" />
        <result column="audit_text" property="auditText" />
        <result column="opera_type" property="operaType" />
        <result column="audit_time" property="auditTime" />
        <result column="stat_date" property="statDate" />
        <result column="stat_type" property="statType" />
        <result column="convert_ration" property="convertRation" />
        <result column="edit_data_value" property="editDataValue" />
        <result column="edit_convert_ration" property="editConvertRation" />
        <result column="data_id" property="dataId" />
    </resultMap>

    <insert id="insertInfo">
        insert into t_apply_record (enterprise_code,collect_name,edit_reason,remark,data_code,apply_time,data_value,
        audit_type,audit_text,audit_time,data_id,stat_date,stat_type,convert_ration,edit_data_value,edit_convert_ration) values
        (#{query.enterpriseCode},#{query.collectName},#{query.editReason},#{query.remark},#{query.dataCode},
        #{query.applyTime},#{query.dataValue},#{query.auditType},#{query.auditText},#{query.auditTime},#{query.dataId},
        #{query.statDate},#{query.statType},#{query.convertRation},#{query.editDataValue},#{query.editConvertRation})
    </insert>

    <update id="updateRecordById">
        UPDATE t_apply_record a
        set a.audit_type=#{query.auditType} , a.audit_text=#{query.auditText} , a.audit_time = (select now())
        where a.enterprise_code=#{query.enterpriseCode} and  a.id=#{query.id}
    </update>

    <select id="getList" resultType="java.util.Map">
        select a.id, a.enterprise_code as enterpriseCode,a.collect_name as collectName,
        a.edit_reason as editReason,a.remark,a.data_code as dataCode,a.apply_time as applyTime,
        a.data_value as dataValue,a.audit_type as auditType,a.apply_type as applyType,a.audit_text as auditText
        ,a.audit_time as auditTime,a.stat_date as statDate,a.stat_type as statType,a.data_id as dataId,
        a.convert_ration as convertRation,a.edit_data_value as editDataValue, a.edit_convert_ration as editConvertRation,
        e.cmpName,a.opera_type as operaType from t_apply_record a
        join enterprise_info e on  a.enterprise_code=e.enterpriseCode
        where e.enterpriseCode = #{epc}
<!--        <trim prefix="where" prefixOverrides="and">-->
<!--            <if test="epc!=null">-->
<!--                and e.cmpName like  CONCAT('%',#{epc},'%')-->
<!--            </if>-->
<!--        </trim>-->
    </select>

    <select id="getListByPage" resultType="com.nantian.cloud.dbcapp.entity.TApplyRecord">
        select  a.id,
                a.enterprise_code,
                a.collect_name,
                a.edit_reason,
                a.remark,
                a.data_code,
                a.apply_time,
                a.data_value,
                a.audit_type,
                a.apply_type,
                a.audit_text,
                a.audit_time,
                a.stat_date,
                a.stat_type,
                a.data_id,
                a.convert_ration,
                a.edit_data_value,
                a.edit_convert_ration,
                e.cmpName,
                a.opera_type
        from t_apply_record a join enterprise_info e on  a.enterprise_code=e.enterpriseCode
        where e.enterpriseCode = #{query.enterpriseCode}
            <if test=" query.cmpName != null and query.cmpName != ''">
                and e.cmpName like  CONCAT('%',#{query.cmpName},'%')
            </if>
            <if test=" query.collectName != null and query.collectName != '' ">
                and a.collect_name like  CONCAT('%',#{query.collectName},'%')
            </if>
            <if test=" query.dataCode != null and query.dataCode != '' ">
                and a.data_code like  CONCAT('%',#{query.dataCode},'%')
            </if>
            <if test=" query.auditType != null and query.auditType != ''">
                and a.audit_type like  CONCAT('%',#{query.auditType},'%')
            </if>
            <if test=" query.operaType != null and query.operaType != ''">
                and a.opera_type like  CONCAT('%',#{query.operaType},'%')
            </if>
            <if test=" query.applyType != null and query.applyType != '' ">
                and a.apply_type like  CONCAT('%',#{query.applyType},'%')
            </if>
            <if test=" query.applyTime != null and query.applyTime != ''">
                and date(a.apply_time) like  CONCAT('%',#{query.applyTime},'%')
            </if>
            <if test=" query.auditTime != null and query.auditTime != ''">
                and date(a.audit_time) like  CONCAT('%',#{query.auditTime},'%')
            </if>
            <if test=" query.startDate != null and query.startDate != ''">
                and left(a.stat_date,10) &gt;= left(#{query.startDate},10)
            </if>
            <if test=" query.endDate != null and query.endDate != ''">
                and left(a.stat_date,10) &lt;= left(#{query.endDate},10)
            </if>
    </select>

    <select id="getRecordPage" resultType="com.nantian.cloud.dbcapp.entity.TApplyRecord">
        select a.id,
               a.enterprise_code,
               a.collect_name,
               a.edit_reason,
               a.remark,
               a.data_code,
               a.apply_time,
               a.data_value,
               a.audit_type,
               a.apply_type,
               a.audit_text,
               a.audit_time,
               a.stat_date,
               a.stat_type,
               a.data_id,
               a.convert_ration,
               a.edit_data_value,
               a.edit_convert_ration,
               e.cmpName,
               a.opera_type
        from t_apply_record a left join enterprise_info e on a.enterprise_code = e.enterpriseCode
        <trim prefix="where" prefixOverrides="and">
            <if test=" query.enterpriseCode != null and query.enterpriseCode != ''">
                and a.enterprise_code like  CONCAT('%',#{query.enterpriseCode},'%')
            </if>
            <if test=" query.cmpName != null and query.cmpName != ''">
                and e.cmpName like  CONCAT('%',#{query.cmpName},'%')
            </if>
            <if test=" query.collectName != null and query.collectName != '' ">
                and a.collect_name like  CONCAT('%',#{query.collectName},'%')
            </if>
            <if test=" query.dataCode != null and query.dataCode != '' ">
                and a.data_code like  CONCAT('%',#{query.dataCode},'%')
            </if>
            <if test=" query.auditType != null and query.auditType != ''">
                and a.audit_type like  CONCAT('%',#{query.auditType},'%')
            </if>
            <if test=" query.operaType != null and query.operaType != ''">
                and a.opera_type like  CONCAT('%',#{query.operaType},'%')
            </if>
            <if test=" query.applyType != null and query.applyType != '' ">
                and a.apply_type like  CONCAT('%',#{query.applyType},'%')
            </if>
            <if test=" query.applyTime != null and query.applyTime != ''">
                and date(a.apply_time) like  CONCAT('%',#{query.applyTime},'%')
            </if>
            <if test=" query.auditTime != null and query.auditTime != ''">
                and date(a.audit_time) like  CONCAT('%',#{query.auditTime},'%')
            </if>
            <if test=" query.startDate != null and query.startDate != ''">
                and left(a.stat_date,10) &gt;= left(#{query.startDate},10)
            </if>
            <if test=" query.endDate != null and query.endDate != ''">
                and left(a.stat_date,10) &lt;= left(#{query.endDate},10)
            </if>
        </trim>
    </select>
</mapper>
