| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007 |
- <?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 d.ent_id as customerId,
- d.firm_name as customerName,
- ktog.goods_id as goodsId,
- kto.amount as amount,
- kto.price as price,
- DATE_FORMAT(kto.create_time, '%Y-%m-%d') 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>
- </mapper>
|