TruckCreditMapper.xml 6.7 KB
<?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.trash.business.mapper.TruckCreditMapper">

    <resultMap type="com.trash.business.domain.TruckCredit" id="TruckCreditResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="licensePlate"    column="license_plate"/>
        <result property="reason"    column="reason"    />
        <result property="status"    column="status"    />
        <result property="lostCredit"    column="lost_credit"    />
        <result property="objectId"    column="object_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createType"    column="create_type"    />
        <result property="time"    column="time"    />
    </resultMap>

    <sql id="selectTruckCreditVo">
        select id, company_id,time,license_plate, reason, status, lost_credit, object_id, create_by,create_type from truck_credit
    </sql>



    <select id="selectTruckCreditList" parameterType="TruckCredit" resultMap="TruckCreditResult">
        <include refid="selectTruckCreditVo"/>
        <where>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
            <if test="licensePlate != null  and licensePlate != ''"> and license_plate = #{licensePlate}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
            <if test="objectId != null  and objectId != ''"> and object_id = #{objectId}</if>
            <if test="time != null "> and DATE_FORMAT(time,("%y%m%d")) = DATE_FORMAT(#{time},("%y%m%d"))</if>
             <if test="ids != null "> 
            	and object_id in 
			        <foreach item="id" collection="ids" open="(" separator="," close=")">
			            #{id}
			        </foreach>
			</if>
        </where>
        order by time DESC
    </select>
    
    <select id="selectTruckCreditByObjectId" parameterType="String" resultMap="TruckCreditResult">
        <include refid="selectTruckCreditVo"/>
        where object_id = #{objectId} and status = 0
    </select>

    <select id="selectTruckCreditById" parameterType="Long" resultMap="TruckCreditResult">
        <include refid="selectTruckCreditVo"/>
        where id = #{id}
    </select>

    <insert id="insertTruckCredit" parameterType="TruckCredit" useGeneratedKeys="true" keyProperty="id">
        insert into truck_credit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="licensePlate != null">license_plate,</if>
            <if test="reason != null">reason,</if>
            <if test="status != null">status,</if>
            <if test="lostCredit != null">lost_credit,</if>
            <if test="objectId != null">object_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="time != null">time,</if>
            <if test="createType != null">create_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="licensePlate != null">#{licensePlate},</if>
            <if test="reason != null">#{reason},</if>
            <if test="status != null">#{status},</if>
            <if test="lostCredit != null">#{lostCredit},</if>
            <if test="objectId != null">#{objectId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="time != null">#{time},</if>
            <if test="createType != null">#{createType},</if>
        </trim>
    </insert>

    <update id="updateTruckCredit" parameterType="TruckCredit">
        update truck_credit
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="licensePlate != null">
                license_plate = #{licensePlate},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="status != null">status = #{status},</if>
            <if test="lostCredit != null">lost_credit = #{lostCredit},</if>
            <if test="objectId != null">object_id = #{objectId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="time != null">time = #{time},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTruckCreditById" parameterType="Long">
        delete from truck_credit where id = #{id}
    </delete>

    <delete id="deleteTruckCreditByIds" parameterType="String">
        delete from truck_credit where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getNames" parameterType="TruckCredit" resultType="String">

        select DISTINCT license_plate from truck_credit
        <where>
            <if test="licensePlate != null  and licensePlate != ''"> and license_plate like concat('%',#{licensePlate},'%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
        </where>
    </select>
    
    <select id="getCompanys" parameterType="TruckCredit" resultType="String">

        select DISTINCT company_id from truck_credit
        <where>
            <if test="companyId != null  and companyId != ''"> and company_id like concat('%',#{companyId},'%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
        </where>
    </select>


    <select id="selectTruckCreditHistory" parameterType="TruckCredit" resultMap="TruckCreditResult">

		SELECT t1.*
		FROM truck_credit t1
		INNER JOIN (
		    SELECT license_plate, MAX(id) as max_id
		    FROM truck_credit
		    GROUP BY license_plate
		) t2 ON t1.license_plate = t2.license_plate AND t1.id = t2.max_id 
        <where>
            <if test="companyId != null  and companyId != ''"> and t1.company_id like concat('%',#{companyId},'%')</if>
            <if test="licensePlate != null  and licensePlate != ''"> and t1.license_plate like concat('%', #{licensePlate}, '%')</if>
             <if test="ids != null and ids.size() > 0"> 
            	and t1.object_id in 
			        <foreach item="id" collection="ids" open="(" separator="," close=")">
			            #{id}
			        </foreach>
			</if>
        </where>
        
        ORDER BY id desc
    </select>

</mapper>