PurchaseOrderInfoMapper.xml 10.2 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.PurchaseOrderInfoMapper">

    <resultMap id="PurchaseOrderInfo" type="com.lframework.xingyun.sc.entity.PurchaseOrderInfo">
        <id column="id" property="id"/>
        <result column="contract_id" property="contractId"/>
        <result column="replenishment_order_id" property="replenishmentOrderId"/>
        <result column="order_no" property="orderNo"/>
        <result column="supply_unit" property="supplyUnit"/>
        <result column="ordering_unit" property="orderingUnit"/>
        <result column="ordering_unit_name" property="orderingUnitName"/>
        <result column="order_date" property="orderDate"/>
        <result column="settlement_terms" property="settlementTerms"/>
        <result column="delivery_method" property="deliveryMethod"/>
        <result column="price_list_no" property="priceListNo"/>
        <result column="execution_standard" property="executionStandard"/>
        <result column="execution_standard_remarks" property="executionStandardRemarks"/>
        <result column="invoicing_status" property="invoicingStatus"/>
        <result column="shipping_cost" property="shippingCost"/>
        <result column="piece_weight_header" property="pieceWeightHeader"/>
        <result column="surface" property="surface"/>
        <result column="tolerance" property="tolerance"/>
        <result column="performance" property="performance"/>
        <result column="element" property="element"/>
        <result column="packaging" property="packaging"/>
        <result column="remarks" property="remarks"/>
        <result column="status" property="status"/>
        <result column="examine_status" property="examineStatus"/>
        <result column="revoke_status" property="revokeStatus"/>
        <result column="spec_change_status" property="specChangeStatus"/>
        <result column="production_process" property="productionProcess"/>
        <result column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="workshop_id" property="workshopId"/>
        <result column="workshop_name" property="workshopName"/>
        <result column="customer_credit_id" property="customerCreditId"/>
        <result column="customer_tier" property="customerTier"/>
        <result column="enterprise_type" property="enterpriseType"/>
        <result column="type" property="type"/>
        <result column="total_quantity" property="totalQuantity"/>
        <result column="packaging_fee" property="packagingFee"/>
        <result column="contract_create_by_id" property="contractCreateById"/>
        <result column="contract_create_by_name" property="contractCreateByName"/>
        <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="PurchaseOrderInfo_sql">
        SELECT
            tb.id,
            tb.contract_id,
            tb.replenishment_order_id,
            tb.order_no,
            tb.supply_unit,
            tb.ordering_unit,
            cu.name AS ordering_unit_name,
            tb.order_date,
            tb.settlement_terms,
            tb.delivery_method,
            tb.price_list_no,
            tb.execution_standard,
            tb.execution_standard_remarks,
            tb.invoicing_status,
            tb.shipping_cost,
            tb.piece_weight_header,
            tb.surface,
            tb.tolerance,
            tb.performance,
            tb.element,
            tb.packaging,
            tb.remarks,
            tb.status,
            tb.examine_status,
            tb.revoke_status,
            tb.spec_change_status,
            tb.production_process,
            tb.dept_id,
            sd.name AS dept_name,
            tb.workshop_id,
            ws.name AS workshop_name,
            tb.customer_credit_id,
            cc.company_suggested_category AS customer_tier,
            cc.enterprise_type,
            tb.type,
            tb.total_quantity,
            tb.packaging_fee,
            tb.contract_create_by_id,
            su.name as contract_create_by_name,
            tb.create_by_id,
            tb.create_by,
            tb.update_by_id,
            tb.update_by,
            tb.create_time,
            tb.update_time
        FROM purchase_order_info AS tb
        left join base_data_customer as cu on cu.id = tb.ordering_unit
        left join sys_dept as sd on sd.id = tb.dept_id
        left join base_data_workshop as ws on ws.id = tb.workshop_id
        left join customer_credit as cc on cc.id = tb.customer_credit_id
        left join sys_user as su on su.id = tb.contract_create_by_id
    </sql>

    <select id="query" resultMap="PurchaseOrderInfo">
        <include refid="PurchaseOrderInfo_sql"/>
        <where>
            <if test="vo.orderNo != null and vo.orderNo != ''">
                AND tb.order_no LIKE CONCAT('%', #{vo.orderNo},'%')
            </if>
            <if test="vo.orderingUnitName != null and vo.orderingUnitName != ''">
                AND cu.name LIKE CONCAT('%', #{vo.orderingUnitName},'%')
            </if>
            <if test="vo.orderDateStart != null">
                AND tb.order_date >= #{vo.orderDateStart}
            </if>
            <if test="vo.orderDateEnd != null">
                <![CDATA[
               AND tb.order_date <= #{vo.orderDateEnd}
                ]]>
            </if>
            <if test="vo.status != null and vo.status != ''">
                AND tb.status = #{vo.status}
            </if>
            <if test="vo.examineStatus != null and vo.examineStatus != ''">
                AND tb.examine_status = #{vo.examineStatus}
            </if>
            <if test="vo.revokeStatus != null and vo.revokeStatus != ''">
                AND tb.revoke_status = #{vo.revokeStatus}
            </if>
            <if test="vo.deptId != null and vo.deptId != ''">
                AND tb.dept_id = #{vo.deptId}
            </if>
            <if test="vo.deptName != null and vo.deptName != ''">
                AND sd.name LIKE CONCAT('%', #{vo.deptName},'%')
            </if>
            <if test="vo.workshopId != null and vo.workshopId != ''">
                AND tb.workshop_id = #{vo.workshopId}
            </if>
            <if test="vo.type != null and vo.type != ''">
                AND tb.type = #{vo.type}
            </if>
            <if test="vo.orderingUnitNameOrOrderNo != null and vo.orderingUnitNameOrOrderNo != ''">
                AND (cu.name LIKE CONCAT('%', #{vo.orderingUnitNameOrOrderNo},'%')
                or tb.order_no LIKE CONCAT('%', #{vo.orderingUnitNameOrOrderNo},'%'))
            </if>
        </where>
        ORDER BY tb.update_time DESC
    </select>

    <select id="queryCanRevokeOrChangeList" resultMap="PurchaseOrderInfo">
        <include refid="PurchaseOrderInfo_sql"/>
        <where>
            AND tb.type = 'PRODUCTION'
            AND tb.status != 'CANCEL'
            <if test="vo.orderNo != null and vo.orderNo != ''">
                AND tb.order_no LIKE CONCAT('%', #{vo.orderNo},'%')
            </if>
            <if test="vo.orderingUnitName != null and vo.orderingUnitName != ''">
                AND cu.name LIKE CONCAT('%', #{vo.orderingUnitName},'%')
            </if>
            <if test="vo.orderDateStart != null">
                AND tb.order_date >= #{vo.orderDateStart}
            </if>
            <if test="vo.orderDateEnd != null">
                <![CDATA[
               AND tb.order_date <= #{vo.orderDateEnd}
                ]]>
            </if>
            <if test="vo.status != null and vo.status != ''">
                AND tb.status = #{vo.status}
            </if>
            <if test="vo.examineStatus != null and vo.examineStatus != ''">
                AND tb.examine_status = #{vo.examineStatus}
            </if>
            <if test="vo.revokeStatus != null and vo.revokeStatus != ''">
                AND tb.revoke_status = #{vo.revokeStatus}
            </if>
            <if test="vo.deptId != null and vo.deptId != ''">
                AND tb.dept_id = #{vo.deptId}
            </if>
            <if test="vo.workshopId != null and vo.workshopId != ''">
                AND tb.workshop_id = #{vo.workshopId}
            </if>
            <choose>
            <when test="vo.queryType == 'REVOKE'">
            AND (tb.revoke_status = '' OR tb.revoke_status = null OR tb.revoke_status='CANCEL' OR
            tb.revoke_status='PARTIAL' OR tb.revoke_status IS NULL)
            AND (tb.status='ISSUED' OR tb.status='WAIT' OR tb.status='TRANSIT')
            AND tb.examine_status = 'PASS'
            AND (tb.spec_change_status != 'IN_PROGRESS' OR tb.spec_change_status IS NULL)
            </when>
            <when test="vo.queryType == 'CHANGE'">
                AND tb.examine_status = 'PASS'
                AND tb.status NOT IN ('SHIPPED', 'DELIVERED', 'CANCEL')
                AND (tb.revoke_status != 'UNDOING' OR tb.revoke_status IS NULL)
                AND (tb.spec_change_status != 'IN_PROGRESS' OR tb.spec_change_status IS NULL)
            </when>
            <when test="vo.queryType == 'REPLENISHMENT'">
                AND tb.examine_status = 'PASS'
                AND tb.status IN ('TRANSIT', 'SHIPPED', 'DELIVERED')
            </when>
            <otherwise>
                AND 1 = 0  <!-- 确保查询不到任何数据 -->
            </otherwise>
            </choose>
        </where>
        ORDER BY tb.update_time DESC
    </select>

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

    <select id="queryByIds" resultType="com.lframework.xingyun.sc.entity.PurchaseOrderInfo">
        <include refid="PurchaseOrderInfo_sql"/>
        where tb.id in
        <foreach collection="ids" open="(" separator="," close=")" item="id">
            #{id}
        </foreach>
    </select>
</mapper>