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.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
SELECT
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
a.del_flag = 0
-- 数据权限匹配
and (
d.top_ent_id = #{query.entId}
and d.contacts_id in
#{authUserId}
or d.create_by in
#{authUserId}
e.top_ent_id = #{query.entId}
and e.contacts_id in
#{authUserId}
or e.create_by in
#{authUserId}
)
and (
d.top_ent_id = #{query.entId}
e.top_ent_id = #{query.entId}
)
and a.ent_id in
#{item}
-- 状态匹配
and a.status =#{query.status}
-- 草稿状态只能创建订单的人能看
and a.create_by = #{query.userId}
-- 非草稿状态or草稿状态且是当前人
and (
a.status != 0
or (a.status = 0 and a.create_by = #{query.userId})
)
-- 关键词匹配
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}, '%')
or g.goods_id in
#{goodId}
)
and a.create_time >= #{query.startCreateTime}
and a.create_time <= #{query.endCreateTime}
and a.id in (
SELECT t_order_id from kwo_trade_order_address where del_flag = 0
and address_type = 1
and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) = left( #{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER} )
and address_type = 2
and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) = left( #{query.unloadAddressCode, jdbcType=INTEGER}, #{query.unloadAddressLevel, jdbcType=INTEGER} )
)
and a.trading =#{query.trading}
and a.source =#{query.source}
and a.delivery_type =#{query.deliveryType}
and a.delivery_type =#{query.deliveryType}
and a.pickup_type =#{query.pickupType}
ORDER BY a.create_time DESC
SELECT
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
a.del_flag = 0
-- 数据权限匹配
and (
d.top_ent_id = #{query.entId}
and d.contacts_id in
#{authUserId}
or d.create_by in
#{authUserId}
e.top_ent_id = #{query.entId}
and e.contacts_id in
#{authUserId}
or e.create_by in
#{authUserId}
)
and (
d.top_ent_id = #{query.entId}
e.top_ent_id = #{query.entId}
)
-- 状态匹配
and a.status =#{query.status}
-- 草稿状态只能创建订单的人能看
and a.create_by = #{query.userId}
-- 非草稿状态or草稿状态且是当前人
and (
a.status != 0
or (a.status = 0 and a.create_by = #{query.userId})
)
-- 关键词匹配
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}, '%')
or g.goods_id in
#{goodId}
)
and a.create_time >= #{query.startCreateTime}
and a.create_time <= #{query.endCreateTime}
and a.id in (
SELECT t_order_id from kwo_trade_order_address where del_flag = 0
and address_type = 1
and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) = left( #{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER} )
and address_type = 2
and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) = left( #{query.unloadAddressCode, jdbcType=INTEGER}, #{query.unloadAddressLevel, jdbcType=INTEGER} )
)
and a.trading =#{query.trading}
and a.source =#{query.source}
and a.delivery_type =#{query.deliveryType}
and a.delivery_type =#{query.deliveryType}
-- 指定贸易订单id导出
and a.id in
#{item}
d.top_ent_id = #{query.entId}
e.top_ent_id = #{query.entId}
ORDER BY a.create_time DESC
SELECT
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
a.status = 5 and a.associate_statement ]]> 1 and a.del_flag = 0
and d.top_ent_id = #{query.entId}
and e.top_ent_id = #{query.entId}
and a.id not in
#{item}
and g.goods_id in
#{goodId}
and d.ent_id = #{query.procureEntId}
and a.trading =#{query.trading}
and a.start_time >= #{query.startTime}
and a.end_time <= #{query.endTime}
ORDER BY a.create_time DESC
SELECT
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
a.del_flag = 0
and d.top_ent_id = #{query.entId}
and e.top_ent_id = #{query.entId}
and f.contract_id in
#{item}
ORDER BY f.contract_id, a.create_time DESC
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
a.del_flag = 0
and d.top_ent_id = #{procureTopEntId}
and a.status not in
#{item}
ORDER BY a.create_time DESC LIMIT 10;
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
a.del_flag = 0
-- 数据权限匹配
and (
d.top_ent_id = #{query.entId}
and d.contacts_id in
#{authUserId}
or d.create_by in
#{authUserId}
e.top_ent_id = #{query.entId}
and e.contacts_id in
#{authUserId}
or e.create_by in
#{authUserId}
)
and (
d.top_ent_id = #{query.entId}
e.top_ent_id = #{query.entId}
)
-- 状态匹配
and a.status =#{query.status}
-- 草稿状态只能创建订单的人能看
and a.create_by = #{query.userId}
-- 非草稿状态or草稿状态且是当前人
and (
a.status != 0
or (a.status = 0 and a.create_by = #{query.userId})
)
-- 关键词匹配
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}, '%')
or g.goods_id in
#{goodId}
)
and a.create_time >= #{query.startCreateTime}
and a.create_time <= #{query.endCreateTime}
and a.id in (
SELECT t_order_id from kwo_trade_order_address where del_flag = 0
and address_type = 1
and left(city_code, #{query.loadAddressLevel, jdbcType=INTEGER}) = left( #{query.loadAddressCode, jdbcType=INTEGER}, #{query.loadAddressLevel, jdbcType=INTEGER} )
and address_type = 2
and left(city_code, #{query.unloadAddressLevel, jdbcType=INTEGER}) = left( #{query.unloadAddressCode, jdbcType=INTEGER}, #{query.unloadAddressLevel, jdbcType=INTEGER} )
)
and a.trading =#{query.trading}
and a.source =#{query.source}
and a.delivery_type =#{query.deliveryType}
and a.delivery_type =#{query.deliveryType}
GROUP BY a.status
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
a.del_flag = 0
-- 数据权限匹配
and (
d.top_ent_id = #{query.entId}
and d.contacts_id in
#{authUserId}
e.top_ent_id = #{query.entId}
and e.contacts_id in
#{authUserId}
)
and (
d.top_ent_id = #{query.entId}
e.top_ent_id = #{query.entId}
)
and d.top_ent_id = #{query.entId}
and e.top_ent_id = #{query.entId}
-- 状态匹配
and a.status in
#{item}
GROUP BY a.status
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
a.del_flag = 0
and a.unit =#{query.unit}
and a.create_time >= #{query.startCreateTime}
and a.create_time <= #{query.endCreateTime}
and a.status not in
#{item}
and d.top_ent_id = #{query.entId}
and e.top_ent_id = #{query.entId}
SELECT MAX(t_order_no)
FROM kwo_trade_order
WHERE create_time >= #{date};
SELECT u.unit_type AS orderType,
COUNT(*) AS num
FROM kwo_trade_order o
LEFT JOIN kwo_trade_order_unit u
ON o.id = u.t_order_id
o.del_flag = 0 AND o.status NOT IN (0, 2) AND u.del_flag = 0
and u.top_ent_id = #{topEntId}
and o.ent_id in
#{item}
GROUP BY u.unit_type
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});