njzscloud/njzscloud-svr/src/main/resources/mapper/order/OrderInfoMapper.xml

371 lines
16 KiB
XML

<?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.njzscloud.supervisory.order.mapper.OrderInfoMapper">
<sql id="base_select">
SELECT a.id,
a.target_order_id,
a.target_station_id,
g.settlement_way,
CASE g.settlement_way
WHEN 'month' THEN '月结'
WHEN 'balance' THEN '余额抵扣'
WHEN 'cash' THEN '现付'
ELSE ''
END settlement_way_txt,
a.sn,
a.station_id,
a.certificate_sn,
a.lane,
a.project_id,
a.trans_company_id,
a.user_id,
a.audit_status,
a.qu_audit_picture,
a.shi_audit_picture,
a.shi_audit_memo,
a.shi_audit_time,
a.qu_audit_memo,
a.qu_audit_time,
a.qu_audit_user_id,
a.shi_audit_user_id,
n.nickname qu_audit_user_name,
o.nickname shi_audit_user_name,
a.order_category,
a.order_status,
a.checker_id,
a.check_status,
a.truck_id,
a.driver_id,
a.goods_id,
a.discount_money,
a.revise_money,
a.settle_money,
a.total_money,
a.refund_money,
a.payment_status,
a.customer_memo,
a.checker_memo,
a.cargo_photo,
a.check_photo,
a.creator_id,
a.modifier_id,
a.create_time,
a.modify_time,
a.pay_time,
a.refund_time,
a.expect_time,
a.estimated_quantity,
a.deleted,
a.cargo_place_id,
a.car_in_out_id,
a.trans_time,
a.site_photos,
b.province,
b.city,
b.area,
b.town,
b.province_name,
b.city_name,
b.area_name,
b.town_name,
b.address,
b.lng,
b.lat,
c.goods_category_id,
c.origin_goods_id,
c.goods_name,
c.unit_price,
c.unit,
c.money_strategy,
c.money_config_id,
c.picture,
c.tax_rate,
i.category_name,
d.rough_weight,
d.tare_weight,
d.settle_weight,
d.in_front_photo,
d.in_body_photo,
d.out_front_photo,
d.out_body_photo,
d.in_time,
d.out_time,
e.license_plate,
e.truck_license,
e.vn_code,
e.qualification,
e.carrying_capacity,
e.tare_weight history_tare_weight,
p.txt truck_category,
e.picture truck_picture,
f.user_id driver_user_id,
f.driver_name,
f.phone driver_phone,
f.driving_licence,
f.licence_start_time,
f.licence_end_time,
f.driving_licence_no,
g.uscc trans_uscc,
g.company_name trans_company_name,
g.business_license trans_business_license,
g.license_start_time trans_license_start_time,
g.license_end_time trans_license_end_time,
g.legal_representative trans_legal_representative,
g.province trans_province,
g.city trans_city,
g.area trans_area,
g.town trans_town,
g.province_name trans_province_name,
g.city_name trans_city_name,
g.area_name trans_area_name,
g.town_name trans_town_name,
g.address trans_address,
g.lng trans_lng,
g.lat trans_lat,
g.contacts trans_contacts,
g.phone trans_phone,
g.idcard trans_idcard,
g.idcard_start_time trans_idcard_start_time,
g.idcard_end_time trans_idcard_end_time,
g.idcard_front trans_idcard_front,
g.idcard_back trans_idcard_back,
h.nickname,
h.biz_obj,
h.phone user_phone,
j.company_name,
j.uscc,
k.nickname checker_name,
k.phone checker_phone,
l.project_name,
m.station_name,
m.station_type,
m.company_name station_company_name,
m.address station_address,
m.uscc station_uscc,
m.contacts station_contacts,
m.phone station_phone,
m.lng station_lng,
m.lat station_lat,
a.contacts,
a.check_time,
a.assignment_trans_time,
a.assignment_driver_time,
a.driver_confirm_time,
a.phone,
a.expect_time,
a.estimated_quantity,
e.truck_license_date,
e.qualification_date truck_qualification_date,
f.licence_start_time driver_licence_start_time,
f.licence_end_time driver_licence_end_time,
j.license_start_time,
j.license_end_time,
g.idcard trans_idcard,
g.idcard_start_time trans_idcard_start_time,
g.idcard_end_time trans_idcard_end_time,
c.money_way
FROM order_info a
LEFT JOIN order_cargo_place b ON b.id = a.cargo_place_id
LEFT JOIN order_goods c ON c.id = a.goods_id
LEFT JOIN goods_info gi ON gi.id = c.origin_goods_id
LEFT JOIN order_car_in_out d ON d.id = a.car_in_out_id
LEFT JOIN biz_truck e ON e.id = a.truck_id
LEFT JOIN biz_driver f ON f.id = a.driver_id
LEFT JOIN biz_company g ON g.id = a.trans_company_id
LEFT JOIN sys_user h ON h.id = a.user_id
LEFT JOIN goods_category i ON i.id = c.goods_category_id
LEFT JOIN biz_company j ON j.user_id = a.user_id
LEFT JOIN sys_user k ON k.id = a.checker_id
LEFT JOIN biz_project l ON l.id = a.project_id
LEFT JOIN biz_company m ON m.id = a.station_id AND m.station = 1
LEFT JOIN sys_user n ON n.id = a.qu_audit_user_id
LEFT JOIN sys_user o ON o.id = a.shi_audit_user_id
LEFT JOIN sys_dict_item p ON p.dict_key = 'vehicle_type' AND p.val = e.truck_category
</sql>
<update id="busyDriver">
UPDATE biz_driver
SET busy = #{busy}
WHERE id = #{driverId}
</update>
<update id="busyTruck">
UPDATE biz_truck
SET busy = #{busy}
WHERE id = #{truckId}
</update>
<resultMap id="OrderPagingResultMap" autoMapping="true" type="com.njzscloud.supervisory.order.pojo.result.OrderPagingResult">
<result property="truckLicenseDate" column="truck_license_date" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
<result property="truckQualificationDate" column="truck_qualification_date" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
<result property="cargoPhoto" column="cargo_photo" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
<result property="checkPhoto" column="check_photo" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
<result property="sitePhotos" column="site_photos" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
<result property="truckLicense" column="truck_license" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
<result property="qualification" column="qualification" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
<result property="auditStatus" column="audit_status" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
<result property="orderCategory" column="order_category" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
<result property="orderStatus" column="order_status" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
<result property="checkStatus" column="check_status" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
<result property="payerCategory" column="payer_category" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
<result property="paymentStatus" column="payment_status" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
<result property="moneyStrategy" column="money_strategy" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
</resultMap>
<resultMap id="OrderExportResultMap" type="com.njzscloud.supervisory.order.pojo.result.OrderExportResult">
<result property="id" column="id"/>
<result property="transTime" column="trans_time"/>
<result property="stationName" column="station_name"/>
<result property="transCompanyName" column="trans_company_name"/>
<result property="licensePlate" column="license_plate"/>
<result property="truckCategory" column="truck_category"/>
<result property="estimatedQuantity" column="estimated_quantity"/>
<result property="inTime" column="in_time"/>
<result property="cfCompanyName" column="cf_company_name"/>
<result property="areaName" column="area_name"/>
<result property="roughWeight" column="rough_weight"/>
<result property="tareWeight" column="tare_weight"/>
<result property="settleWeight" column="settle_weight"/>
<result property="driverName" column="driver_name"/>
<result property="checkerMemo" column="checker_memo"/>
</resultMap>
<resultMap id="OrderExportDetailResultMap" type="com.njzscloud.supervisory.order.pojo.result.OrderExportDetailResult">
<result property="orderId" column="order_id"/>
<result property="expenseItemName" column="expense_item_name"/>
<result property="settleMoney" column="settle_money"/>
</resultMap>
<select id="paging" resultMap="OrderPagingResultMap">
<include refid="base_select"/>
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
</select>
<select id="exportList" resultMap="OrderExportResultMap">
SELECT
a.id,
DATE_FORMAT( a.trans_time, '%Y-%m-%d' ) AS trans_time,
b.station_name,
g.company_name AS trans_company_name,
d.license_plate,
e.txt AS truck_category,
a.estimated_quantity,
TIME_FORMAT( ocio.in_time, '%H:%i' ) AS in_time,
su.nickname AS cf_company_name,
h.area_name,
h.town_name,
h.address,
ROUND( ocio.rough_weight / 1000, 2 ) AS rough_weight,
ROUND( ocio.tare_weight / 1000, 2 ) AS tare_weight,
ROUND( ocio.settle_weight / 1000, 2 ) AS settle_weight,
f.driver_name,
a.checker_memo
FROM
order_info a
LEFT JOIN biz_company b ON b.id = a.station_id
LEFT JOIN biz_company g ON g.id = a.trans_company_id
LEFT JOIN biz_truck d ON d.id = a.truck_id
LEFT JOIN sys_dict_item e ON d.truck_category = e.val
AND e.dict_key = 'vehicle_type'
LEFT JOIN order_car_in_out ocio ON ocio.id = a.car_in_out_id
LEFT JOIN sys_user su ON a.user_id = su.id
LEFT JOIN order_cargo_place h ON h.id = a.cargo_place_id
LEFT JOIN biz_driver f ON f.id = a.driver_id
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
ORDER BY
a.create_time DESC
</select>
<select id="exportDetailList" resultMap="OrderExportDetailResultMap">
SELECT
oei.order_id,
oei.expense_item_name,
oei.settle_money
FROM
order_expense_items oei
LEFT JOIN order_info a ON a.id = oei.order_id
LEFT JOIN biz_company g ON g.id = a.trans_company_id
LEFT JOIN biz_truck d ON d.id = a.truck_id
LEFT JOIN biz_driver f ON f.id = a.driver_id
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
ORDER BY
oei.create_time DESC
</select>
<select id="detail" resultMap="OrderPagingResultMap">
<include refid="base_select"/>
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
</select>
<select id="pendingOrder" resultMap="OrderPagingResultMap">
<include refid="base_select"/>
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
LIMIT 1
</select>
<select id="obtainWeighBill" resultMap="OrderPagingResultMap">
<include refid="base_select"/>
WHERE a.id = #{orderId}
</select>
<select id="getDriverId" resultType="java.lang.Long">
SELECT IFNULL(id, 0) id
FROM biz_driver
WHERE user_id = #{userId}
</select>
<select id="paymentContext" resultType="com.njzscloud.supervisory.order.pojo.result.PaymentContextResult">
SELECT
a.id AS orderId,
a.trans_company_id AS transCompanyId,
a.sn,
a.settlement_way as oi_pay_way,
a.out_trade_no,
bc.user_id AS companyUserId,
ma1.id AS companyAccountId,
ma1.money AS companyBalance,
ma1.revenue,
bc.settlement_way,
sua.wechat_openid,
a.refund_money,
a.settle_money
FROM order_info a
LEFT JOIN biz_company bc ON bc.id = a.trans_company_id
LEFT JOIN money_account ma1 ON ma1.station_id = a.trans_company_id
LEFT JOIN biz_driver bd ON a.driver_id = bd.id
LEFT JOIN sys_user_account sua ON bd.user_id = sua.user_id
WHERE a.id = #{orderId}
</select>
<select id="getTruckInfo" resultType="com.njzscloud.supervisory.biz.pojo.entity.BizTruckEntity">
SELECT *
FROM biz_truck
WHERE id = #{truckId}
</select>
<select id="getTransInfo" resultType="com.njzscloud.supervisory.biz.pojo.entity.BizCompanyEntity">
SELECT *
FROM biz_company
WHERE id = #{transCompanyId}
</select>
<select id="gpsLastOnlineTime"
resultType="com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity">
select *
from device_localizer
where terminal_id = #{gpsId}
and deleted = 0
</select>
<select id="getRoute" resultType="java.lang.String">
SELECT b.name route_name
FROM order_route a
INNER JOIN order_route_detail b ON a.id = b.order_route_id
WHERE a.order_id = #{id}
AND b.name IS NOT NULL
AND TRIM(b.name) != ''
ORDER BY b.sort, b.create_time, b.id
</select>
</mapper>