SysOrderFileMapper.xml 8.27 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.glsx.ordercenter.mapper.SysOrderFileMapper">
    <resultMap id="BaseResultMap" type="com.glsx.ordercenter.pojo.SysOrderFile">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="order_id" jdbcType="INTEGER" property="orderId"/>
        <result column="sub_order_id" jdbcType="INTEGER" property="subOrderId"/>
        <result column="file_path" jdbcType="VARCHAR" property="filePath"/>
        <result column="file_type" jdbcType="TINYINT" property="fileType"/>
        <result column="sort" jdbcType="TINYINT" property="sort"/>
        <result column="create_by" jdbcType="INTEGER" property="createBy"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>

        <result column="fileName" jdbcType="VARCHAR" property="fileName"/>
        <result column="fileDesc" jdbcType="VARCHAR" property="fileDesc"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, order_id, sub_order_id, file_path, file_type, sort, create_by, create_time
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_order_file
        where id = #{id,jdbcType=INTEGER}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from sys_order_file
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <insert id="insert" parameterType="com.glsx.ordercenter.pojo.SysOrderFile">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into sys_order_file (order_id, sub_order_id, file_path, file_type, sort, create_by,
            create_time)
        values (#{orderId,jdbcType=INTEGER}, #{subOrderId,jdbcType=INTEGER},
            #{filePath,jdbcType=VARCHAR}, #{fileType,jdbcType=TINYINT},
            #{sort,jdbcType=TINYINT}, #{createBy,jdbcType=INTEGER},
            #{createTime,jdbcType=TIMESTAMP})
    </insert>

    <insert id="insertSelective" parameterType="com.glsx.ordercenter.pojo.SysOrderFile">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into sys_order_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">
                order_id,
            </if>
            <if test="subOrderId != null">
                sub_order_id,
            </if>
            <if test="filePath != null">
                file_path,
            </if>
            <if test="fileType != null">
                file_type,
            </if>
            <if test="sort != null">
                sort,
            </if>
            <if test="createBy != null">
                create_by,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">
                #{orderId,jdbcType=INTEGER},
            </if>
            <if test="subOrderId != null">
                #{subOrderId,jdbcType=INTEGER},
            </if>
            <if test="filePath != null">
                #{filePath,jdbcType=VARCHAR},
            </if>
            <if test="fileType != null">
                #{fileType,jdbcType=TINYINT},
            </if>
            <if test="sort != null">
                #{sort,jdbcType=TINYINT},
            </if>
            <if test="createBy != null">
                #{createBy,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.glsx.ordercenter.pojo.SysOrderFile">
        update sys_order_file
        <set>
            <if test="orderId != null">
                order_id = #{orderId,jdbcType=INTEGER},
            </if>
            <if test="subOrderId != null">
                sub_order_id = #{subOrderId,jdbcType=INTEGER},
            </if>
            <if test="filePath != null">
                file_path = #{filePath,jdbcType=VARCHAR},
            </if>
            <if test="fileType != null">
                file_type = #{fileType,jdbcType=TINYINT},
            </if>
            <if test="sort != null">
                sort = #{sort,jdbcType=TINYINT},
            </if>
            <if test="createBy != null">
                create_by = #{createBy,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="updateByPrimaryKey" parameterType="com.glsx.ordercenter.pojo.SysOrderFile">
        update sys_order_file
        set order_id = #{orderId,jdbcType=INTEGER},
            sub_order_id = #{subOrderId,jdbcType=INTEGER},
            file_path = #{filePath,jdbcType=VARCHAR},
            file_type = #{fileType,jdbcType=TINYINT},
            sort = #{sort,jdbcType=TINYINT},
            create_by = #{createBy,jdbcType=INTEGER},
            create_time = #{createTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=INTEGER}
    </update>



    <insert id="addOrderFileList" keyProperty="id" useGeneratedKeys="true">
        insert into sys_order_file (order_id, sub_order_id, file_path, file_type, sort, create_by,
            create_time)
        values
        <foreach item="item" collection="fileList" separator=",">
            (#{item.orderId,jdbcType=INTEGER}, #{item.subOrderId,jdbcType=INTEGER},
             #{item.filePath,jdbcType=VARCHAR}, #{item.fileType,jdbcType=TINYINT},
             #{item.sort,jdbcType=TINYINT}, #{item.createBy,jdbcType=INTEGER},
             #{item.createTime,jdbcType=TIMESTAMP})
        </foreach>
    </insert>

    <select id="countByOrderIdAndFilePath" resultType="java.lang.Integer">
        select count(0)
        from sys_order_file
        where order_id = #{orderId}
        <if test="filePath != null">
            and file_path = #{filePath}
        </if>
        <if test="fileType != null">
            and file_type = #{fileType}
        </if>
    </select>

    <select id="selectByOrderIdAndFileType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_order_file
        where order_id = #{orderId} and file_type = #{fileType}
    </select>

    <select id="selectByOrderId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_order_file
        where order_id = #{orderId}
    </select>

    <select id="selectOrderFile" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_order_file
        where order_id = #{orderId} and sort = #{sort}
    </select>

    <select id="selectListByRecord" parameterType="com.glsx.ordercenter.pojo.SysOrderFile"
            resultMap="BaseResultMap">
        select f.id, f.order_id, f.sub_order_id, f.file_path, f.file_type, f.sort, f.create_by,
            f.create_time,
            <!-- 照片名称相关 -->
            sipc.photo_name fileName, sipc.photo_desc fileDesc
        from sys_order_file f
        left join sys_order o on o.id = f.order_id
        left join sys_service_item si on si.service_code = o.service_code
        left join sys_service_item_photo_config sipc on sipc.service_item_id = si.id
        <where>
            <if test="orderId != null">
                and f.order_id = #{orderId,jdbcType=INTEGER}
            </if>
            <if test="subOrderId != null">
                and f.sub_order_id = #{subOrderId,jdbcType=INTEGER}
            </if>
            <if test="sort != null">
                and f.sort = #{sort,jdbcType=INTEGER}
            </if>
            and f.sort = sipc.sort
        </where>
    </select>
</mapper>