| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117 |
- <?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.sckw.order.dao.KwoTradeOrderMapper">
- <resultMap id="mainEntityMap" type="com.sckw.order.model.dto.OrderListResDTO">
- <id column="tOrderId" property="tOrderId"/>
- <result column="status" property="status"/>
- <result column="tOrderNo" property="tOrderNo"/>
- <result column="procureEntId" property="procureEntId"/>
- <result column="procureFirmName" property="procureFirmName"/>
- <result column="supplyEntId" property="supplyEntId"/>
- <result column="supplyFirmName" property="supplyFirmName"/>
- <result column="trading" property="trading"/>
- <result column="deliveryType" property="deliveryType"/>
- <result column="pickupType" property="pickupType"/>
- <result column="source" property="source"/>
- <result column="contractId" property="contractId"/>
- <result column="contractNo" property="contractNo"/>
- <result column="goodsId" property="goodsId"/>
- <result column="unitPrice" property="unitPrice"/>
- <result column="price" property="price"/>
- <result column="amount" property="amount"/>
- <result column="entrustAmount" property="entrustAmount"/>
- <result column="actualAmount" property="actualAmount"/>
- <result column="startTime" property="startTime"/>
- <result column="chargeType" property="chargeType"/>
- <result column="unloadAmount" property="unloadAmount"/>
- <result column="loadAmount" property="loadAmount"/>
- <result column="endTime" property="endTime"/>
- <result column="remark" property="remark"/>
- <result column="unit" property="unit"/>
- <result column="createBy" property="createBy"/>
- <result column="createTime" property="createTime"/>
- <result column="addVehicles" property="addVehicles"/>
- <collection property="loadAddresses" ofType="com.sckw.order.model.dto.LoadAddressDTO">
- <id column="loadAddressId" property="loadAddressId"/>
- <result column="loadName" property="loadName"/>
- <result column="loadCityName" property="loadCityName"/>
- <result column="loadDetailAddress" property="loadDetailAddress"/>
- </collection>
- <collection property="unloadAddresses" ofType="com.sckw.order.model.dto.UnloadAddressDTO">
- <id column="unloadAddressId" property="unloadAddressId"/>
- <result column="unloadName" property="unloadName"/>
- <result column="unloadCityName" property="unloadCityName"/>
- <result column="unloadDetailAddress" property="unloadDetailAddress"/>
- </collection>
- </resultMap>
- <sql id="Query_Column_List_Accept_Carriage">
- a.id AS tOrderId,
- a.status AS status,
- a.t_order_no AS tOrderNo,
- d.ent_id AS procureEntId,
- d.firm_name AS procureFirmName,
- e.ent_id AS supplyEntId,
- e.firm_name AS supplyFirmName,
- a.trading AS trading,
- a.delivery_type AS deliveryType,
- a.pickup_type AS pickupType,
- a.source AS source,
- f.contract_id AS contractId,
- f.contract_no AS contractNo,
- g.goods_id AS goodsId,
- g.unit_price AS unitPrice,
- a.price AS price,
- a.amount AS amount,
- a.entrust_amount AS entrustAmount,
- a.charge_type AS chargeType,
- a.load_amount AS loadAmount,
- a.unload_amount AS unloadAmount,
- a.actual_amount AS actualAmount,
- a.start_time AS startTime,
- a.end_time AS endTime,
- a.remark AS remark,
- a.unit AS unit,
- a.create_by AS createBy,
- a.create_time AS createTime,
- a.add_vehicles AS addVehicles
- </sql>
- <select id="tradeOrderSelect" resultMap="mainEntityMap">
- SELECT
- <include refid="Query_Column_List_Accept_Carriage">
- </include>
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
- LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
- LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
- <where>
- a.del_flag = 0
- -- 数据权限匹配
- <choose>
- <when test="query.manager != null and !query.manager">
- <if test="query.isMain == 1">
- <if test="query.entList != null and query.entList.size() > 0 and query.entType != null">
- <if test="query.entType == 1">
- and
- e.top_ent_id in
- <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- <if test="query.entType == 2">
- and
- d.top_ent_id in
- <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- </if>
- </if>
- <if test="query.isMain == 0">
- <if test="query.entId != null and query.entType != null">
- <if test="query.entType == 1">
- and e.top_ent_id = #{query.entId}
- </if>
- <if test="query.entType == 2">
- and d.top_ent_id = #{query.entId}
- </if>
- </if>
- </if>
- </when>
- </choose>
- <if test="query.buyEntId != null">
- and d.ent_id = #{query.buyEntId}
- </if>
- <if test="query.contractId != null">
- and f.contract_id = #{query.contractId}
- </if>
- <!-- <if test="query.dataPermissionForceEmpty != null and query.dataPermissionForceEmpty">-->
- <!-- and 1 = 0-->
- <!-- </if>-->
- <!-- <if test="query.dataPermissionFilter != null and query.dataPermissionFilter">-->
- <!-- and exists (-->
- <!-- select 1-->
- <!-- from kwc_contract_trade ct-->
- <!-- where ct.id = f.contract_id-->
- <!-- and ct.del_flag = 0-->
- <!-- <if test="query.dataPermissionAllVisible != null and !query.dataPermissionAllVisible">-->
- <!-- and ct.ent_id in-->
- <!-- <foreach collection="query.dataPermissionEntIds" item="entId" open="(" close=")" separator=",">-->
- <!-- #{entId}-->
- <!-- </foreach>-->
- <!-- </if>-->
- <!-- <if test="query.dataPermissionPersonal != null and query.dataPermissionPersonal">-->
- <!-- and ct.salesman_id = #{query.dataPermissionUserId}-->
- <!-- </if>-->
- <!-- )-->
- <!-- </if>-->
- <if test="query.saleEntId != null">
- and e.ent_id = #{query.saleEntId}
- </if>
- <if test="query.status != null">
- and a.status = #{query.status}
- </if>
- <if test="query.keywords != null and query.keywords != ''">
- and (
- a.t_order_no like concat('%', #{query.keywords}, '%')
- or d.firm_name like concat('%', #{query.keywords}, '%')
- or e.firm_name like concat('%', #{query.keywords}, '%')
- <if test="goodIds != null and goodIds.size() > 0">
- or g.goods_id in
- <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
- #{goodId}
- </foreach>
- </if>
- )
- </if>
- <if test="query.startCreateTime != null">
- and a.create_time >= #{query.startCreateTime}
- </if>
- <if test="query.endCreateTime != null">
- and a.create_time <= #{query.endCreateTime}
- </if>
- <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
- and a.id in (
- SELECT t_order_id
- from kwo_trade_order_address where del_flag = 0
- <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
- and address_type = 1
- and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
- left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
- </if>
- <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
- and address_type = 2
- and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
- left(#{query.unloadAddressCode, jdbcType=INTEGER},
- #{query.unloadAddressLevel, jdbcType=INTEGER})
- </if>
- )
- </if>
- <if test="query.trading != null and query.trading != ''">
- and a.trading = #{query.trading}
- </if>
- <if test="query.source != null and query.source != ''">
- and a.source = #{query.source}
- </if>
- <if test="query.deliveryType != null and query.deliveryType != ''">
- and a.delivery_type = #{query.deliveryType}
- </if>
- <if test="query.deliveryType != null and query.deliveryType != ''">
- and a.delivery_type = #{query.deliveryType}
- </if>
- <if test="query.pickupType != null and query.pickupType != ''">
- and a.pickup_type = #{query.pickupType}
- </if>
- </where>
- ORDER BY a.create_time DESC
- </select>
- <select id="tradeOrderExport" resultMap="mainEntityMap">
- SELECT
- <include refid="Query_Column_List_Accept_Carriage">
- </include>
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
- LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
- LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
- <where>
- a.del_flag = 0
- -- 数据权限匹配
- <if test="query.isMain == 0">
- and (
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- d.top_ent_id = #{query.entId}
- </if>
- <if test="authUserIds != null and authUserIds.size() > 0">
- and d.contacts_id in
- <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- or d.create_by in
- <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- e.top_ent_id = #{query.entId}
- </if>
- <if test="authUserIds != null and authUserIds.size() > 0">
- and e.contacts_id in
- <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- or e.create_by in
- <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- </if>
- )
- </if>
- <if test="query.isMain == 1">
- and (
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- d.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- e.top_ent_id = #{query.entId}
- </if>
- </if>
- )
- </if>
- -- 状态匹配
- <if test="query.status != null">
- and a.status = #{query.status}
- <if test="query.status == 0">
- -- 草稿状态只能创建订单的人能看
- and a.create_by = #{query.userId}
- </if>
- </if>
- <if test="query.status == null">
- -- 非草稿状态or草稿状态且是当前人
- and (
- a.status != 0
- or (a.status = 0 and a.create_by = #{query.userId})
- )
- </if>
- -- 关键词匹配
- <if test="query.keywords != null and query.keywords != ''">
- and (
- a.t_order_no like concat('%', #{query.keywords}, '%')
- or d.firm_name like concat('%', #{query.keywords}, '%')
- or e.firm_name like concat('%', #{query.keywords}, '%')
- <if test="goodIds != null and goodIds.size() > 0">
- or g.goods_id in
- <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
- #{goodId}
- </foreach>
- </if>
- )
- </if>
- <if test="query.startCreateTime != null">
- and a.create_time >= #{query.startCreateTime}
- </if>
- <if test="query.endCreateTime != null">
- and a.create_time <= #{query.endCreateTime}
- </if>
- <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
- and a.id in (
- SELECT t_order_id
- from kwo_trade_order_address where del_flag = 0
- <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
- and address_type = 1
- and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
- left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
- </if>
- <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
- and address_type = 2
- and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
- left(#{query.unloadAddressCode, jdbcType=INTEGER},
- #{query.unloadAddressLevel, jdbcType=INTEGER})
- </if>
- )
- </if>
- <if test="query.trading != null and query.trading != ''">
- and a.trading = #{query.trading}
- </if>
- <if test="query.source != null and query.source != ''">
- and a.source = #{query.source}
- </if>
- <if test="query.deliveryType != null and query.deliveryType != ''">
- and a.delivery_type = #{query.deliveryType}
- </if>
- <if test="query.deliveryType != null and query.deliveryType != ''">
- and a.delivery_type = #{query.deliveryType}
- </if>
- -- 指定贸易订单id导出
- <if test="ids != null and ids.size() > 0">
- and a.id in
- <foreach collection="ids" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- and d.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- and e.top_ent_id = #{query.entId}
- </if>
- </if>
- </if>
- </where>
- ORDER BY a.create_time DESC
- </select>
- <select id="tradeOrderStatementList" resultMap="mainEntityMap">
- SELECT
- <include refid="Query_Column_List_Accept_Carriage">
- </include>
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_address b ON a.id = b.t_order_id
- AND b.address_type = "1" AND b.del_flag = 0
- LEFT JOIN kwo_trade_order_address c ON a.id = c.t_order_id
- AND c.address_type = "2" AND c.del_flag = 0
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
- AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
- AND e.unit_type = "2" AND e.del_flag = 0
- LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
- LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
- <where>
- a.status = 5
- and a.associate_statement <![CDATA[ <> ]]> 1
- and a.del_flag = 0
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- and d.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- and e.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="excludeIds != null and excludeIds.size() > 0">
- and a.id not in
- <foreach collection="excludeIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="goodIds != null and goodIds.size() > 0">
- and g.goods_id in
- <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
- #{goodId}
- </foreach>
- </if>
- <if test="query.procureEntId != null">
- and d.ent_id = #{query.procureEntId}
- </if>
- <if test="query.trading != null and query.trading != ''">
- and a.trading = #{query.trading}
- </if>
- <if test="query.startTime != null">
- and a.start_time >= #{query.startTime}
- </if>
- <if test="query.endTime != null">
- and a.end_time <= #{query.endTime}
- </if>
- </where>
- ORDER BY a.create_time DESC
- </select>
- <select id="tradeOrderContractList" resultMap="mainEntityMap">
- SELECT
- <include refid="Query_Column_List_Accept_Carriage">
- </include>
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_address b ON a.id = b.t_order_id
- AND b.address_type = "1" AND b.del_flag = 0
- LEFT JOIN kwo_trade_order_address c ON a.id = c.t_order_id
- AND c.address_type = "2" AND c.del_flag = 0
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
- AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
- AND e.unit_type = "2" AND e.del_flag = 0
- LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
- LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
- <where>
- a.del_flag = 0
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- and d.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- and e.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="contractIds != null and contractIds.size() > 0">
- and f.contract_id in
- <foreach collection="contractIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </where>
- ORDER BY f.contract_id, a.create_time DESC
- </select>
- <select id="workbenchPurchaseList" resultType="com.sckw.order.model.dto.WorkbenchPurchaseDTO">
- SELECT a.id as tOrderId,
- a.amount as amount,
- a.unit as unit,
- a.create_time as createTime,
- g.goods_id as goodsId,
- d.firm_name as procureFirmName
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
- AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
- <where>
- a.del_flag = 0
- <if test="procureTopEntId != null">
- and d.top_ent_id = #{procureTopEntId}
- </if>
- <if test="excludeStatuses != null and excludeStatuses.size() > 0">
- and a.status not in
- <foreach collection="excludeStatuses" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </where>
- ORDER BY a.create_time DESC
- LIMIT 10;
- </select>
- <select id="tradeOrderStatistic" resultType="com.sckw.core.model.vo.TableTop">
- SELECT a.status AS `value`, COUNT(a.status) AS total
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
- LEFT JOIN kwo_trade_order_goods g ON a.id = g.t_order_id AND g.del_flag = 0
- LEFT JOIN kwo_trade_order_contract f ON a.id = f.t_order_id AND f.del_flag = 0
- <where>
- a.del_flag = 0
- <choose>
- <when test="query.manager != null and !query.manager">
- <if test="query.isMain == 1">
- <if test="query.entList != null and query.entList.size() > 0 and query.entType != null">
- <if test="query.entType == 1">
- and
- e.top_ent_id in
- <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- <if test="query.entType == 2">
- and
- d.top_ent_id in
- <foreach collection="query.entList" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- </if>
- </if>
- <if test="query.isMain == 0">
- <if test="query.entId != null and query.entType != null">
- <if test="query.entType == 1">
- and e.top_ent_id = #{query.entId}
- </if>
- <if test="query.entType == 2">
- and d.top_ent_id = #{query.entId}
- </if>
- </if>
- </if>
- </when>
- </choose>
- <if test="query.buyEntId != null">
- and d.ent_id = #{query.buyEntId}
- </if>
- <if test="query.saleEntId != null">
- and e.ent_id = #{query.saleEntId}
- </if>
- <!-- <if test="query.dataPermissionForceEmpty != null and query.dataPermissionForceEmpty">-->
- <!-- and 1 = 0-->
- <!-- </if>-->
- <!-- <if test="query.dataPermissionFilter != null and query.dataPermissionFilter">-->
- <!-- and exists (-->
- <!-- select 1-->
- <!-- from kwc_contract_trade ct-->
- <!-- where ct.id = f.contract_id-->
- <!-- and ct.del_flag = 0-->
- <!-- <if test="query.dataPermissionAllVisible != null and !query.dataPermissionAllVisible">-->
- <!-- and ct.ent_id in-->
- <!-- <foreach collection="query.dataPermissionEntIds" item="entId" open="(" close=")" separator=",">-->
- <!-- #{entId}-->
- <!-- </foreach>-->
- <!-- </if>-->
- <!-- <if test="query.dataPermissionPersonal != null and query.dataPermissionPersonal">-->
- <!-- and ct.salesman_id = #{query.dataPermissionUserId}-->
- <!-- </if>-->
- <!-- )-->
- <!-- </if>-->
- <if test="query.status != null">
- and a.status = #{query.status}
- </if>
- <if test="query.keywords != null and query.keywords != ''">
- and (
- a.t_order_no like concat('%', #{query.keywords}, '%')
- or d.firm_name like concat('%', #{query.keywords}, '%')
- or e.firm_name like concat('%', #{query.keywords}, '%')
- <if test="goodIds != null and goodIds.size() > 0">
- or g.goods_id in
- <foreach collection="goodIds" item="goodId" open="(" close=")" separator=",">
- #{goodId}
- </foreach>
- </if>
- )
- </if>
- <if test="query.startCreateTime != null">
- and a.create_time >= #{query.startCreateTime}
- </if>
- <if test="query.endCreateTime != null">
- and a.create_time <= #{query.endCreateTime}
- </if>
- <if test="(query.loadAddressCode != null and query.loadAddressCode != '') or (query.unloadAddressCode != null and query.unloadAddressCode != '')">
- and a.id in (
- SELECT t_order_id
- from kwo_trade_order_address where del_flag = 0
- <if test="query.loadAddressCode != null and query.loadAddressCode != ''">
- and address_type = 1
- and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) =
- left(#{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER})
- </if>
- <if test="query.unloadAddressCode != null and query.unloadAddressCode != ''">
- and address_type = 2
- and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) =
- left(#{query.unloadAddressCode, jdbcType=INTEGER},
- #{query.unloadAddressLevel, jdbcType=INTEGER})
- </if>
- )
- </if>
- <if test="query.trading != null and query.trading != ''">
- and a.trading = #{query.trading}
- </if>
- <if test="query.source != null and query.source != ''">
- and a.source = #{query.source}
- </if>
- <if test="query.deliveryType != null and query.deliveryType != ''">
- and a.delivery_type = #{query.deliveryType}
- </if>
- <if test="query.deliveryType != null and query.deliveryType != ''">
- and a.delivery_type = #{query.deliveryType}
- </if>
- </where>
- GROUP BY a.status
- </select>
- <select id="appStatistic" resultType="com.sckw.order.model.vo.res.TradeOrderAppStatisticVO">
- SELECT a.status AS `value`, COUNT(a.status) AS total
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = "2" AND e.del_flag = 0
- <where>
- a.del_flag = 0
- -- 数据权限匹配
- <if test="query.isMain == 0">
- and (
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- d.top_ent_id = #{query.entId}
- </if>
- <if test="authUserIds != null and authUserIds.size() > 0">
- and d.contacts_id in
- <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- e.top_ent_id = #{query.entId}
- </if>
- <if test="authUserIds != null and authUserIds.size() > 0">
- and e.contacts_id in
- <foreach collection="authUserIds" item="authUserId" open="(" close=")" separator=",">
- #{authUserId}
- </foreach>
- </if>
- </if>
- )
- </if>
- <if test="query.isMain == 1">
- and (
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- d.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- e.top_ent_id = #{query.entId}
- </if>
- </if>
- )
- </if>
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- and d.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- and e.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="statuses != null and statuses.size() > 0">
- and a.status in
- <foreach collection="statuses" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </where>
- GROUP BY a.status
- </select>
- <select id="getOrderStsInfo" resultType="com.sckw.order.model.dto.WorkbenchOrderStsDTO">
- SELECT SUM(a.amount) AS orderAmount,
- SUM(a.price) AS orderPrice,
- SUM(a.actual_amount) AS orderActualAmount
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id
- AND d.unit_type = "1" AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id
- AND e.unit_type = "2" AND e.del_flag = 0
- <where>
- a.del_flag = 0
- <if test="query.unit != null and query.unit != ''">
- and a.unit = #{query.unit}
- </if>
- <if test="query.startCreateTime != null">
- and a.create_time >= #{query.startCreateTime}
- </if>
- <if test="query.endCreateTime != null">
- and a.create_time <= #{query.endCreateTime}
- </if>
- <if test="excludeStatuses != null and excludeStatuses.size() > 0">
- and a.status not in
- <foreach collection="excludeStatuses" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="query.orderType == 1">
- <if test="query.entId != null">
- and d.top_ent_id = #{query.entId}
- </if>
- </if>
- <if test="query.orderType == 2">
- <if test="query.entId != null">
- and e.top_ent_id = #{query.entId}
- </if>
- </if>
- </where>
- </select>
- <select id="getMaxOrderNoByDate" resultType="java.lang.String">
- SELECT MAX(t_order_no)
- FROM kwo_trade_order
- WHERE create_time >= #{date};
- </select>
- <select id="getOrderNumByTopEntId" resultType="com.sckw.order.api.model.TradeOrderCountStatisticsDTO">
- SELECT u.unit_type AS orderType,
- COUNT(0) AS num
- FROM kwo_trade_order o
- LEFT JOIN kwo_trade_order_unit u
- ON o.id = u.t_order_id
- <where>
- o.del_flag = 0
- AND o.status NOT IN (0, 2)
- AND u.del_flag = 0
- <if test="topEntId != null">
- and u.top_ent_id = #{topEntId}
- </if>
- <if test="enterpriseIds != null and enterpriseIds.size() > 0">
- and o.ent_id in
- <foreach collection="enterpriseIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </where>
- GROUP BY u.unit_type
- </select>
- <select id="workbenchExcel" resultType="com.sckw.order.model.dto.WbTOrderExcelStsResDTO">
- SELECT DATE_FORMAT(create_time, #{item.dateFormat}) AS formatDate,
- SUM(CASE
- WHEN #{item.stsFactorsOne} = 1 THEN price
- WHEN #{item.stsFactorsOne} = 2 THEN 1
- ELSE 0
- END) AS stsFactorsOneValue,
- SUM(CASE
- WHEN #{item.stsFactorsTwo} = 1 THEN price
- WHEN #{item.stsFactorsTwo} = 2 THEN 1
- ELSE 0
- END) AS stsFactorsTwoValue
- FROM kwo_trade_order
- WHERE id IN (SELECT t_order_id
- FROM kwo_trade_order_unit
- WHERE del_flag = 0
- AND unit_type = #{item.unitType}
- AND top_ent_id = #{item.topEntId})
- AND create_time >= #{item.startTime}
- AND status NOT IN (0, 2)
- AND del_flag = 0
- GROUP BY DATE_FORMAT(create_time, #{item.dateFormat});
- </select>
- <select id="querySaleOrder" resultType="com.sckw.order.api.model.OrderSaleVo">
- select ktog.goods_id,
- sum(ifnull(kto.amount, 0)) as amount
- from kwo_trade_order kto
- left join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- <where>
- kto.del_flag = 0
- <if test="start != null and end != null">
- and kto.create_time between #{start} and #{end}
- </if>
- group by ktog.goods_id
- order by amount desc
- </where>
- </select>
- <select id="selectData" resultType="com.sckw.order.api.model.TradeOrderVo">
- select a.status,
- a.id tOrderId,
- a.t_order_no tOrderNo,
- d.firm_name buyEntName,
- e.firm_name sellEntName,
- ktog.goods_name,
- ktog.unit_price,
- ktog.unit,
- ktog.goods_type,
- a.amount,
- a.price,
- a.load_amount,
- a.unload_amount,
- a.charge_type,
- a.create_time,
- a.add_vehicles
- FROM kwo_trade_order a
- LEFT JOIN kwo_trade_order_unit d ON a.id = d.t_order_id AND d.unit_type = '1' AND d.del_flag = 0
- LEFT JOIN kwo_trade_order_unit e ON a.id = e.t_order_id AND e.unit_type = '2' AND e.del_flag = 0
- left join kwo_trade_order_goods ktog on a.id = ktog.t_order_id and ktog.del_flag = 0
- <where>
- a.del_flag = 0
- <if test="para.startTime != null and para.endTime != null">
- and a.create_time between #{para.startTime,jdbcType=TIMESTAMP} and #{para.endTime,jdbcType=TIMESTAMP}
- </if>
- <if test="para.orderNo != null and para.orderNo != ''">
- and a.t_order_no = #{para.orderNo}
- </if>
- <if test="para.entId != null and para.entId.size() > 0">
- <if test="para.type != null and para.type == 1">
- and
- e.ent_id in
- <foreach collection="para.entId" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="para.type != null and para.type == 2">
- and d.ent_id in
- <foreach collection="para.entId" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </if>
- limit 10
- </where>
- </select>
- <select id="queryCount" resultType="java.lang.Long">
- select count(1)
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status = 1
- <if test="ids != null and ids.size() != 0">
- and d.ent_id in
- <foreach collection="ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- </where>
- </select>
- <select id="queryList" resultType="com.sckw.order.api.model.TradeVo">
- select kto.id,
- kto.create_time,
- kto.status,
- kto.amount,
- ktog.unit_price,
- ktog.goods_name,
- kto.t_order_no,
- c.firm_name
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
- inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status = 1
- <if test="ids != null and ids.size() != 0">
- and d.ent_id in
- <foreach collection="ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- order by kto.create_time desc
- <if test="all != null and all">
- limit 10
- </if>
- </where>
- </select>
- <select id="querySalesReportRawData" resultType="com.sckw.order.model.SalesReportRawData">
- select
- kto.charge_type as chargeType,
- kto.load_amount as loadAmount,
- kto.unload_amount as unloadAmount,
- d.ent_id as customerId,
- d.firm_name as customerName,
- ktog.goods_id as goodsId,
- ktog.unit_price as unitPrice,
- kto.amount as amount,
- kto.price as price,
- DATE_FORMAT(kto.create_time, '%Y-%m-%d %H:%i:%S') as createTime
- from kwo_trade_order kto
- inner join kwo_trade_order_unit d on kto.id = d.t_order_id and d.unit_type = '1' and d.del_flag = 0
- inner join kwo_trade_order_unit e on kto.id = e.t_order_id and e.unit_type = '2' and e.del_flag = 0
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- where kto.del_flag = 0
- and e.ent_id = #{curEntId}
- <if test="customerId != null">
- and d.ent_id = #{customerId}
- </if>
- <if test="goodsId != null">
- and ktog.goods_id = #{goodsId}
- </if>
- </select>
- <select id="countList" resultType="com.sckw.order.api.model.TradeSaleVo">
- select ktog.goods_id,
- CONCAT(
- LPAD(HOUR(kto.create_time), 2, '0'),
- ':00-',
- LPAD(MOD(HOUR(kto.create_time) + 1, 24), 2, '0'),
- ':00'
- ) AS time_period,
- sum(kto.amount) as amount
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
- inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status in (1, 2, 3, 4)
- <if test="ids != null and ids.size() != 0">
- and d.ent_id in
- <foreach collection="ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and kto.create_time between #{para.startTime} and #{para.endTime}
- group by time_period, ktog.goods_id
- order by time_period
- </where>
- </select>
- <select id="countSale" resultType="com.sckw.order.api.model.SaleVo">
- select DATE_FORMAT(kto.create_time, '%Y-%m-%d') as order_day,
- count(kto.id) count,
- sum(kto.price) as price
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d
- ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
- inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status in (1, 2, 3, 4)
- <if test="ids != null and ids.size() != 0">
- and d.ent_id in
- <foreach collection="ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and kto.create_time between #{para.startTime}
- and #{para.endTime}
- group by order_day
- </where>
- </select>
- <select id="countBuy" resultType="com.sckw.order.api.model.BuyVo">
- select sum(kto.price) as price,
- c.firm_name,
- c.ent_id
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d
- ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
- inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status in (1, 2, 3, 4)
- <if test="ids != null and ids.size() != 0">
- and d.ent_id in
- <foreach collection="ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and kto.create_time between #{para.startTime}
- and #{para.endTime}
- group by c.ent_id, c.firm_name
- order by price desc
- limit 5
- </where>
- </select>
- <select id="countGoods" resultType="com.sckw.order.api.model.GoodsVo">
- select sum(kto.amount), ktog.goods_name, ktog.goods_id
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status in (1, 2, 3, 4)
- <if test="ids != null and ids.size() != 0">
- and d.ent_id in
- <foreach collection="ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and kto.create_time between #{para.startTime} and #{para.endTime}
- group by ktog.goods_name, ktog.goods_id
- </where>
- </select>
- <select id="buyRank" resultType="com.sckw.order.api.model.TradeBuyVo">
- select sum(kto.amount) as amount,
- c.firm_name as firmName
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '2' AND d.del_flag = 0
- inner JOIN kwo_trade_order_unit c ON kto.id = c.t_order_id AND c.unit_type = '1' AND c.del_flag = 0
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status in (1, 2, 3, 4)
- <if test="ids != null and ids.size() != 0">
- and d.ent_id in
- <foreach collection="ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and kto.create_time between #{para.startTime} and #{para.endTime}
- group by c.ent_id, c.firm_name
- order by amount desc
- limit 5
- </where>
- </select>
- <select id="saleTop" resultType="com.sckw.order.model.vo.SaleTopVo">
- select ROW_NUMBER() OVER (ORDER BY amount DESC) AS sort,
- sum(kto.price) as amount,
- d.firm_name entName
- from kwo_trade_order kto
- inner JOIN kwo_trade_order_unit d ON kto.id = d.t_order_id AND d.unit_type = '1' AND d.del_flag = 0
- inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status = 4
- and ku.ent_id in (538038314096136193,538039617157337089,538040297439891457)
- group by kto.id,
- d.firm_name
- </where>
- </select>
- <select id="saleSum" resultType="java.math.BigDecimal">
- select
- sum(kto.price) as amount
- from kwo_trade_order kto
- inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.status = 4
- and ku.ent_id in (538038314096136193,538039617157337089,538040297439891457)
- </where>
- </select>
- <select id="joinSelect" resultType="com.sckw.order.api.model.TradeOrderDto">
- select kto.id,
- ktog.goods_id,
- kto.amount,
- ktog.unit_price
- from kwo_trade_order kto
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
- <where>
- kto.del_flag = 0
- and kto.archive_flag != 1
- and kto.status = 4
- and ku.ent_id in (538038314096136193,538039617157337089,538040297439891457)
- limit 20
- </where>
- </select>
- <select id="selectDailyShipmentByCategory" resultType="com.sckw.order.model.dto.DailyShipmentStatisticsDTO">
- select DATE_FORMAT(kto.create_time, '%Y-%m-%d') as orderDate,
- ktog.goods_type as goodsType,
- SUM(kto.actual_amount) as actualAmount
- from kwo_trade_order kto
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
- where kto.del_flag = 0
- and kto.status = 5
- and ku.top_ent_id = #{entId}
- and kto.create_time >= #{startTime}
- and kto.create_time <= #{endTime}
- group by DATE_FORMAT(kto.create_time, '%Y-%m-%d'), ktog.goods_type
- order by orderDate, goodsType;
- </select>
- <select id="selectDailySalesByCategory" resultType="com.sckw.order.model.dto.DailySalesStatisticsDTO">
- select DATE_FORMAT(kto.create_time, '%Y-%m-%d') as orderDate,
- ktog.goods_type as goodsType,
- SUM(kto.price) as salesAmount
- from kwo_trade_order kto
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
- where kto.del_flag = 0
- and kto.status = 5
- and ku.top_ent_id = #{entId}
- and kto.create_time >= #{startTime}
- and kto.create_time <= #{endTime}
- group by DATE_FORMAT(kto.create_time, '%Y-%m-%d'), ktog.goods_type
- order by orderDate, goodsType;
- </select>
- <select id="selectGoodsVolumeTop5" resultType="com.sckw.order.model.dto.GoodsVolumeStatisticsDTO">
- select ktog.goods_name as goodsName,
- SUM(kto.actual_amount) as totalVolume
- from kwo_trade_order kto
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
- where kto.del_flag = 0
- and kto.status = 5
- and ku.top_ent_id = #{entId}
- group by ktog.goods_name
- order by totalVolume desc
- limit 5;
- </select>
- <select id="selectGoodsAmountTop5" resultType="com.sckw.order.model.dto.GoodsAmountStatisticsDTO">
- select ktog.goods_name as goodsName,
- SUM(kto.price) as totalAmount
- from kwo_trade_order kto
- inner join kwo_trade_order_goods ktog on kto.id = ktog.t_order_id and ktog.del_flag = 0
- inner join kwo_trade_order_unit ku on kto.id = ku.t_order_id and ku.unit_type = '2' and ku.del_flag = 0
- where kto.del_flag = 0
- and kto.status = 5
- and ku.top_ent_id = #{entId}
- group by ktog.goods_name
- order by totalAmount desc
- limit 5;
- </select>
- </mapper>
|