DelayedShipmentMapper.xml 2.8 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.lframework.xingyun.sc.mappers.DelayedShipmentMapper">

    <resultMap id="DelayedShipment" type="com.lframework.xingyun.sc.entity.DelayedShipment">
        <id column="id" property="id"/>
        <result column="apply_date" property="applyDate"/>
        <result column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="total_quantity" property="totalQuantity"/>
        <result column="status" property="status"/>
        <result column="create_by_id" property="createById"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by_id" property="updateById"/>
        <result column="update_by" property="updateBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="DelayedShipment_sql">
        SELECT * FROM (
        SELECT
        tb.id,
        tb.apply_date,
        tb.dept_id,
        sd.name AS dept_name,
        tb.total_quantity,
        tb.status,
        tb.create_by_id,
        tb.create_by,
        tb.update_by_id,
        tb.update_by,
        tb.create_time,
        tb.update_time,
        o.workshop_id  <!-- 在子查询内部查出 workshop_id -->
        FROM delayed_shipment AS tb
        LEFT JOIN sys_dept AS sd ON sd.id = tb.dept_id
        LEFT JOIN delayed_shipment_detail AS tbd ON tbd.delayed_shipment_id = tb.id
        LEFT JOIN purchase_order_info o ON tbd.order_id = o.id
        ) AS tb  <!-- 【关键】将子查询的结果集命名为 tb,这样框架拼 tb.workshop_id 就完全合法了 -->
    </sql>

    <select id="query" resultMap="DelayedShipment">
        <include refid="DelayedShipment_sql"/>
        <where>
            <if test="vo.deptName != null and vo.deptName != ''">
                AND sd.name LIKE CONCAT('%', #{vo.deptName},'%')
            </if>
            <if test="vo.applyDateStart != null">
                AND tb.apply_date >= #{vo.applyDateStart}
            </if>
            <if test="vo.applyDateEnd != null">
                <![CDATA[
               AND tb.apply_date <= #{vo.applyDateEnd}
                ]]>
            </if>
            <if test="vo.status != null and vo.status != ''">
                AND tb.status = #{vo.status}
            </if>
        </where>
        ORDER BY tb.create_time DESC
    </select>

    <select id="findById" resultType="com.lframework.xingyun.sc.entity.DelayedShipment">
        <include refid="DelayedShipment_sql"/>
        <where>
            <if test="id != null and id != ''">
                AND tb.id = #{id}
            </if>
        </where>
    </select>
</mapper>