EarthsitesCreditMapper.xml 6.73 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.EarthsitesCreditMapper">

    <resultMap type="com.trash.business.domain.EarthsitesCredit" id="EarthsitesCreditResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="time"    column="time"    />
        <result property="place"    column="place"    />
        <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"    />
    </resultMap>

    <sql id="selectEarthsitesCreditVo">
        select id, name, type, time, place, reason, status, lost_credit, object_id from earthsites_credit
    </sql>

    <select id="selectEarthsitesCreditList" parameterType="EarthsitesCredit" resultMap="EarthsitesCreditResult">
        <include refid="selectEarthsitesCreditVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="time != null "> and DATE_FORMAT(time,("%y%m%d")) = DATE_FORMAT(#{time},("%y%m%d")) </if>
            <if test="place != null  and place != ''"> and place = #{place}</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="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="selectEarthsitesCreditById" parameterType="Long" resultMap="EarthsitesCreditResult">
        <include refid="selectEarthsitesCreditVo"/>
        where id = #{id}
    </select>

    <insert id="insertEarthsitesCredit" parameterType="EarthsitesCredit" useGeneratedKeys="true" keyProperty="id">
        insert into earthsites_credit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="time != null">time,</if>
            <if test="place != null">place,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="time != null">#{time},</if>
            <if test="place != null">#{place},</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>
        </trim>
    </insert>

    <update id="updateEarthsitesCredit" parameterType="EarthsitesCredit">
        update earthsites_credit
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="time != null">time = #{time},</if>
            <if test="place != null">place = #{place},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEarthsitesCreditById" parameterType="Long">
        delete from earthsites_credit where id = #{id}
    </delete>

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


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

        select DISTINCT name from earthsites_credit
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
        </where>
    </select>
    
        <select id="getTypes" parameterType="EarthsitesCredit" resultType="String">
    	select DISTINCT type from earthsites_credit 
        <where>  
            <if test="name != null  and name != ''"> and type like concat('%', #{type}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
        </where>
    </select>
        <select id="getPlaces" parameterType="EarthsitesCredit" resultType="String">
    	select DISTINCT place from earthsites_credit 
        <where>  
            <if test="name != null  and name != ''"> and place like concat('%', #{place}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
        </where>
    </select>
    

    <select id="selectEarthsitesCreditHistory" parameterType="EarthsitesCredit" resultMap="EarthsitesCreditResult">

        select c.* from (select a.* from earthsites_credit a where not exists (select b.* from earthsites_credit b where a.name = b.name and a.id &lt; id )) c

        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="place != null  and place != ''"> and place = #{place}</if>
            <if test="ids != null "> 
            	and object_id in 
			        <foreach item="id" collection="ids" open="(" separator="," close=")">
			            #{id}
			        </foreach>
			</if>
        </where>
    </select>

</mapper>