<?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.stylefeng.guns.modular.system.dao.TLineMapper">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TLine">
|
<id column="id" property="id" />
|
<result column="name" property="name" />
|
<result column="shiftInterval" property="shiftInterval" />
|
<result column="dispatchPhone" property="dispatchPhone" />
|
<result column="rakeRate" property="rakeRate" />
|
<result column="state" property="state" />
|
<result column="insertTime" property="insertTime" />
|
</resultMap>
|
|
<!-- 通用查询结果列 -->
|
<sql id="Base_Column_List">
|
id, name, shiftInterval, dispatchPhone, rakeRate, state, insertTime
|
</sql>
|
|
<!--根据条件查询线路列表-->
|
<select id="getLineList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
|
SELECT * FROM (SELECT IFNULL(ls.num,0) as shiftNum,su.`name` as insertUser,IFNULL(lc.num,0) as companyNum,ll.* FROM t_line as ll
|
LEFT JOIN (SELECT COUNT(id) as num,lineId FROM t_line_shift where state != 3 GROUP BY lineId) as ls on ls.lineId = ll.id
|
LEFT JOIN sys_user as su on su.id = ll.insertUserId
|
LEFT JOIN (SELECT COUNT(id) as num,lineId FROM t_line_company GROUP BY lineId) as lc on lc.lineId = ll.id
|
) as o
|
<where>
|
o.state != 3
|
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
|
AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
|
</if>
|
<if test="name != null and name != ''">
|
and o.name LIKE CONCAT('%',#{name},'%')
|
</if>
|
<if test="insertUser != null and insertUser != ''">
|
and o.insertUser LIKE CONCAT('%',#{insertUser},'%')
|
</if>
|
<if test="state != null and state != ''">
|
and o.state = #{state}
|
</if>
|
<if test="companyId != null">
|
and (o.id in (select lineId from t_line_company where companyId = #{companyId}) or o.companyId = #{companyId})
|
</if>
|
</where>
|
order by o.id desc
|
</select>
|
|
<!--根据线路ID查询线路已分配公司-->
|
<select id="getLineCompanyList" resultType="java.util.Map">
|
SELECT cc.`name` as companyName,lc.* FROM t_line_company as lc
|
LEFT JOIN t_company as cc on cc.id = lc.companyId
|
where lc.lineId = #{lineId}
|
</select>
|
|
<!--行程列表-->
|
<select id="getTravelList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
|
SELECT
|
lsd.id as lineShiftDriverId,
|
CONCAT(DATE_FORMAT(lsd.`day`, '%Y-%m-%d'), ' ', ls.startTime, ' - ', ls.endTime) as shiftTime,
|
l.`name` as lineName,
|
IFNULL(s.city, '') as city,
|
CONCAT(d.`name`, '-', d.phone) as driver,
|
COUNT(oc.id) as orderNum,
|
'排班' as tripType,
|
case
|
when NOW() < STR_TO_DATE(CONCAT(DATE_FORMAT(lsd.`day`, '%Y-%m-%d'), ' ', ls.startTime, ':00'), '%Y-%m-%d %H:%i:%s') then 1
|
when NOW() > STR_TO_DATE(CONCAT(DATE_FORMAT(lsd.`day`, '%Y-%m-%d'), ' ', ls.endTime, ':00'), '%Y-%m-%d %H:%i:%s') then 3
|
else 2
|
end as status,
|
lsd.driverId as driverId,
|
ls.lineId as lineId,
|
lsd.`day` as day
|
FROM t_line_shift_driver lsd
|
LEFT JOIN t_line_shift ls on ls.id = lsd.lineShiftId and ls.state != 3
|
LEFT JOIN t_line l on l.id = ls.lineId and l.state != 3
|
LEFT JOIN t_driver d on d.id = lsd.driverId and d.flag != 3
|
LEFT JOIN t_line_site lsite on lsite.lineId = l.id and lsite.type = 1
|
LEFT JOIN t_site s on s.id = lsite.siteId
|
LEFT JOIN t_order_cross_city oc on oc.lineShiftDriverId = lsd.id and oc.lineId = ls.lineId and oc.isDelete = 1
|
<where>
|
l.id is not null
|
<if test="city != null and city != ''">
|
and s.city LIKE CONCAT('%',#{city},'%')
|
</if>
|
<if test="lineName != null and lineName != ''">
|
and l.name LIKE CONCAT('%',#{lineName},'%')
|
</if>
|
<if test="driverKeyword != null and driverKeyword != ''">
|
and (d.name LIKE CONCAT('%',#{driverKeyword},'%') or d.phone LIKE CONCAT('%',#{driverKeyword},'%'))
|
</if>
|
<if test="roleType != null and roleType != '' and roleType != 1">
|
and (l.id in (select lineId from t_line_company where companyId = #{companyId}) or l.companyId = #{companyId})
|
</if>
|
</where>
|
GROUP BY lsd.id
|
<if test="status != null">
|
HAVING status = #{status}
|
</if>
|
order by lsd.day desc, ls.startTime desc, lsd.id desc
|
</select>
|
|
<!--行程对应订单列表-->
|
<select id="getTravelOrders" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
|
SELECT
|
o.id as id,
|
o.orderNum as orderNum,
|
o.travelId as travelId,
|
o.travelTime as travelTime,
|
o.passengers as passengers,
|
o.passengersPhone as passengersPhone,
|
o.startAddress as startAddress,
|
o.endAddress as endAddress,
|
o.orderMoney as orderMoney,
|
o.state as state,
|
CONCAT(d.`name`, '-', d.phone) as driver,
|
l.`name` as lineName
|
FROM t_order_cross_city o
|
LEFT JOIN t_driver d on d.id = o.driverId
|
LEFT JOIN t_line l on l.id = o.lineId
|
<where>
|
o.isDelete = 1
|
<if test="lineShiftDriverId != null">
|
and o.lineShiftDriverId = #{lineShiftDriverId}
|
</if>
|
<if test="lineId != null">
|
and o.lineId = #{lineId}
|
</if>
|
<if test="driverId != null">
|
and o.driverId = #{driverId}
|
</if>
|
<if test="roleType != null and roleType != '' and roleType == 2">
|
and (o.companyId = #{companyId} or FIND_IN_SET(o.companyId,(SELECT GROUP_CONCAT(id) as ids FROM t_company where superiorId = #{companyId} GROUP BY superiorId)))
|
</if>
|
<if test="roleType != null and roleType != '' and roleType == 3">
|
and o.companyId = #{companyId}
|
</if>
|
</where>
|
order by o.id desc
|
</select>
|
|
</mapper>
|