PurchaseOrderInfoMapper.xml 18.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
<?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="contract_type" property="contractType"/>
        <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="finish_date" property="finishDate"/>
        <result column="production_process" property="productionProcess"/>
        <result column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="dept_code" property="deptCode"/>
        <result column="region" property="region"/>
        <result column="region_name" property="regionName"/>
        <result column="stock_up_company_id" property="stockUpCompanyId"/>
        <result column="stock_up_company_name" property="stockUpCompanyName"/>
        <result column="workshop_id" property="workshopId"/>
        <result column="workshop_name" property="workshopName"/>
        <result column="workshop_code" property="workshopCode"/>
        <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="contract_create_by_telephone" property="contractCreateByTelephone"/>
        <result column="sample_order" property="sampleOrder"/>
        <result column="warranty_certificate_file_id" property="warrantyCertificateFileId"/>
        <result column="warranty_certificate_file_name" property="warrantyCertificateFileName"/>
        <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,
            cds.type AS contract_type,
            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.finish_date,
            tb.production_process,
            tb.dept_id,
            sd.name AS dept_name,
            sd.code AS dept_code,
            tb.region,
            sd1.name AS region_name,
            tb.stock_up_company_id,
            cu1.name AS stock_up_company_name,
            tb.workshop_id,
            ws.name AS workshop_name,
            ws.code AS workshop_code,
            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,
            su.telephone as contract_create_by_telephone,
            tb.freeze,
            tb.sample_order,
            tb.warranty_certificate_file_id,
            tb.warranty_certificate_file_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
        left join sys_dept as sd1 on sd1.id = tb.region
        left join base_data_customer as cu1 on cu1.id = tb.stock_up_company_id
        left join tbl_contract_distributor_standard as cds on cds.id = tb.contract_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.freeze != null and vo.freeze != ''">
                AND tb.freeze = #{vo.freeze}
            </if>
            <if test="vo.sampleOrder != null and vo.sampleOrder != ''">
                AND tb.sample_order = #{vo.sampleOrder}
            </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>
            <if test="vo.contractId != null and vo.contractId != ''">
                AND tb.contract_id = #{vo.contractId}
            </if>
            <if test="vo.orderingUnitIds != null and !vo.orderingUnitIds.isEmpty()">
                AND tb.ordering_unit IN
                <foreach collection="vo.orderingUnitIds" item="orderingUnit" open="(" separator="," close=")">
                    #{orderingUnit}
                </foreach>
            </if>
            <if test="vo.excludeIds != null and !vo.excludeIds.isEmpty()">
                AND tb.id NOT IN
                <foreach collection="vo.excludeIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="vo.includeStatus != null and !vo.includeStatus.isEmpty()">
                AND tb.status IN
                <foreach collection="vo.includeStatus" item="status" open="(" separator="," close=")">
                    #{status}
                </foreach>
            </if>
            <if test="vo.ids != null and vo.ids.size() > 0">
                AND tb.id IN
                <foreach collection="vo.ids" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="vo.createTimeStart != null">
                AND tb.create_time >= #{vo.createTimeStart}
            </if>
            <if test="vo.createTimeEnd != null">
                <![CDATA[
                  AND tb.create_time < DATE_ADD(#{vo.createTimeEnd}, INTERVAL 1 DAY)
                ]]>
            </if>
            <if test="vo.contractType != null and vo.contractType != ''">
                AND cds.type = #{vo.contractType}
            </if>
            <if test="vo.finishDateStart != null">
                AND tb.finish_date >= #{vo.finishDateStart}
            </if>
            <if test="vo.finishDateEnd != null">
                <![CDATA[
                  AND tb.finish_date < DATE_ADD(#{vo.finishDateEnd}, INTERVAL 1 DAY)
                ]]>
            </if>
        </where>
        ORDER BY tb.create_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.searchKey != null and vo.searchKey != ''">
                AND (cu.name LIKE CONCAT('%', #{vo.searchKey},'%')
                or tb.order_no LIKE CONCAT('%', #{vo.searchKey},'%'))
            </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.sample_order = false
                    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.sample_order = false
                    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.sample_order = false
                    AND tb.status IN ('TRANSIT', 'SHIPPED', 'DELIVERED')
                </when>
                <otherwise>
                    AND 1 = 0  <!-- 确保查询不到任何数据 -->
                </otherwise>
            </choose>
            <if test="vo.finishDateStart != null">
                AND tb.finish_date >= #{vo.finishDateStart}
            </if>
            <if test="vo.finishDateEnd != null">
                <![CDATA[
                  AND tb.finish_date < DATE_ADD(#{vo.finishDateEnd}, INTERVAL 1 DAY)
                ]]>
            </if>
        </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>

    <select id="queryHisProProcess" resultType="java.lang.String">
        select ol.production_process
        from purchase_order_info o
        inner join tbl_purchase_order_line ol on o.id = ol.purchase_order_id
        where o.ordering_unit = #{params.orderingUnit} and o.workshop_id = #{params.workshopId}
        and ol.production_process is not null
        <choose>
            <when test="params.industry != null and params.industry != ''">
                and ol.industry = #{params.industry}
            </when>
            <otherwise>
                and (ol.industry is null or ol.industry = '')
            </otherwise>
        </choose>
        <choose>
            <when test="params.brand != null and params.brand != ''">
                and ol.brand = #{params.brand}
            </when>
            <otherwise>
                and (ol.brand is null or ol.brand = '')
            </otherwise>
        </choose>
        <choose>
            <when test="params.status != null and params.status != ''">
                and ol.status = #{params.status}
            </when>
            <otherwise>
                and (ol.status is null or ol.status = '')
            </otherwise>
        </choose>
        <choose>
            <when test="params.thickness != null">
                and ol.thickness = #{params.thickness}
            </when>
            <otherwise>
                and ol.thickness is null
            </otherwise>
        </choose>
        <choose>
            <when test="params.thicknessTolNeg != null">
                and ol.thickness_tol_neg = #{params.thicknessTolNeg}
            </when>
            <otherwise>
                and ol.thickness_tol_neg is null
            </otherwise>
        </choose>
        <choose>
            <when test="params.thicknessTolPos != null">
                and ol.thickness_tol_pos = #{params.thicknessTolPos}
            </when>
            <otherwise>
                and ol.thickness_tol_pos is null
            </otherwise>
        </choose>
        <choose>
            <when test="params.width != null">
                and ol.width = #{params.width}
            </when>
            <otherwise>
                and ol.width is null
            </otherwise>
        </choose>
<!--        <choose>-->
<!--            <when test="params.widthTolNeg != null">-->
<!--                and ol.width_tol_neg = #{params.widthTolNeg}-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                and ol.width_tol_neg is null-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        <choose>-->
<!--            <when test="params.widthTolPos != null">-->
<!--                and ol.width_tol_pos = #{params.widthTolPos}-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                and ol.width_tol_pos is null-->
<!--            </otherwise>-->
<!--        </choose>-->
        order by ol.update_time desc
        limit 1
    </select>

    <select id="getReviewerById" resultType="com.lframework.xingyun.sc.dto.ReviewerDto">
        SELECT business_id,
               JSON_UNQUOTE(JSON_EXTRACT(def_json, '$.nodeList[1].extMap.handleInfos[0].createBy')) AS officeClerk,
               JSON_UNQUOTE(JSON_EXTRACT(def_json, '$.nodeList[2].extMap.handleInfos[0].createBy')) AS officeSupervisor
        FROM flow_instance
        WHERE business_id = #{id}
        ORDER BY create_time DESC LIMIT 1
    </select>
</mapper>