Files
nanguangszwlback/mhd-user-center/src/main/resources/mapper/MotorcadeMapper.xml
T

411 lines
18 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.mhd.user.domain.motorcade.repository.mapper.MotorcadeMapper">
<resultMap type="com.mhd.user.domain.motorcade.repository.po.MotorcadePo" id="MotorcadeResult">
<result property="motorcadeId" column="motorcade_id" />
<result property="organizationName" column="organization_name" />
<result property="motorcadeName" column="motorcade_name" />
<result property="motorcadeImage" column="motorcade_image" />
<result property="motorcadeDescribtion" column="motorcade_describtion" />
<result property="motorcadeStatus" column="motorcade_status" />
<result property="motorcadeHeaderId" column="motorcade_header_id" />
<result property="motorcadeHeaderName" column="motorcade_header_name" />
<result property="motorcadeHeaderAccount" column="motorcade_header_account" />
<result property="motorcadeScore" column="motorcade_score" />
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="createByName" column="create_by_name" />
<result property="updateTime" column="update_time" />
<result property="updateBy" column="update_by" />
<result property="updateByName" column="update_by_name" />
<result property="delFlag" column="del_flag" />
<result property="checkPersonId" column="check_person_id" />
<result property="checkPersonName" column="check_person_name" />
<result property="checkPersonTime" column="check_person_time" />
<result property="motorcadeDissolutionStatus" column="motorcade_dissolution_status" />
<result property="blackListReason" column="black_list_reason" />
</resultMap>
<sql id="selectMotorcadePo">
SELECT
motorcade_id,
organization_name,
motorcade_name,
motorcade_image,
motorcade_describtion,
motorcade_status,
motorcade_header_id,
motorcade_header_name,
motorcade_header_account,
motorcade_score,
create_time,
create_by,
create_by_name,
update_time,
update_by,
update_by_name,
del_flag,
check_person_id,
check_person_name,
check_person_time,
motorcade_dissolution_status
FROM
motorcade
</sql>
<sql id="selectMotorcadePo1">
<where>
del_flag = 1
<if test="motorcadeId != null and motorcadeId != ''">
and motorcade_id = #{motorcadeId}
</if>
<if test="motorcadeName != null and motorcadeName != ''">
and motorcade_name like concat('%', #{motorcadeName}, '%')
</if>
<if test="motorcadeImage != null and motorcadeImage != ''">
and motorcade_image = #{motorcadeImage}
</if>
<if test="motorcadeDescribtion != null and motorcadeDescribtion != ''">
and motorcade_describtion = #{motorcadeDescribtion}
</if>
<if test="motorcadeStatus != null ">
and motorcade_status = #{motorcadeStatus}
</if>
<if test="motorcadeHeaderId != null ">
and motorcade_header_id = #{motorcadeHeaderId}
</if>
<if test="motorcadeHeaderName != null and motorcadeHeaderName != ''">
and motorcade_header_name like concat('%', #{motorcadeHeaderName}, '%')
</if>
<if test="motorcadeHeaderAccount != null and motorcadeHeaderAccount != ''">
and motorcade_header_account like concat('%', #{motorcadeHeaderAccount}, '%')
</if>
<if test="motorcadeScore != null ">
and motorcade_score = #{motorcadeScore}
</if>
<if test="createByName != null and createByName != ''">
and create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="motorcadeDissolutionStatus != null ">
and motorcade_dissolution_status = #{motorcadeDissolutionStatus}
</if>
<if test="organizationName != null and organizationName != ''">
and organization_name like concat('%', #{organizationName}, '%')
</if>
<if test="organizationIdList != null ">
AND organization_id in
<foreach item="id" collection="organizationIdList" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</sql>
<select id="queryList" parameterType="com.mhd.user.domain.motorcade.repository.todo.MotorcadeDO" resultMap="MotorcadeResult">
SELECT
m.motorcade_id,
m.organization_id,
m.organization_name,
m.top_organization_id,
COUNT(d.user_id) AS driver_num,
SUM(u.vehicle_num) AS vehicle_num,
m.motorcade_name,
m.motorcade_image,
m.motorcade_describtion,
m.motorcade_status,
m.motorcade_header_id,
m.motorcade_reject_reason,
m.black_list_reason,
m.motorcade_header_name,
m.motorcade_header_account,
m.motorcade_score,
m.create_time,
m.create_by,
m.create_by_name,
m.update_time,
m.update_by,
m.update_by_name,
m.del_flag,
m.check_person_id,
m.check_person_name,
m.check_person_time,
m.motorcade_dissolution_status,
m.default_flag
FROM
motorcade m
LEFT JOIN
motorcade_driver d
ON m.motorcade_id = d.motorcade_id and d.del_flag = 1
LEFT JOIN
(SELECT
u.user_id,
COUNT(b.vehicle_id) AS vehicle_num
FROM
user_driver u
LEFT JOIN
driver_vehicle_bind b
ON u.user_id = b.driver_bind_id and b.del_flag = 1
WHERE
u.del_flag = 1
GROUP BY
u.user_id) u
ON u.user_id = d.user_id
<where>
m.del_flag = 1
<if test="checkPersonName != null and checkPersonName != ''">
and m.check_person_name like concat('%', #{checkPersonName}, '%')
</if>
/*添加时间*/
<if test="createTimeFrom!=null and createTimeTo!=null ">
and DATE_FORMAT(m.create_time,'%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{createTimeFrom},'%Y-%m-%d')
and DATE_FORMAT(m.create_time,'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{createTimeTo},'%Y-%m-%d')
</if>
/*审核时间*/
<if test="userAuthTimeFrom!=null and userAuthTimeTo!=null ">
and DATE_FORMAT(m.check_person_time,'%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{userAuthTimeFrom},'%Y-%m-%d')
and DATE_FORMAT(m.check_person_time,'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{userAuthTimeTo},'%Y-%m-%d')
</if>
<if test="motorcadeName != null and motorcadeName != ''">
and m.motorcade_name like concat('%', #{motorcadeName}, '%')
</if>
<if test="motorcadeImage != null and motorcadeImage != ''">
and m.motorcade_image = #{motorcadeImage}
</if>
<if test="motorcadeDescribtion != null and motorcadeDescribtion != ''">
and m.motorcade_describtion = #{motorcadeDescribtion}
</if>
<if test="motorcadeStatus != null ">
and m.motorcade_status = #{motorcadeStatus}
</if>
<if test="motorcadeHeaderId != null ">
and m.motorcade_header_id = #{motorcadeHeaderId}
</if>
<if test="motorcadeHeaderName != null and motorcadeHeaderName != ''">
and m.motorcade_header_name like concat('%', #{motorcadeHeaderName}, '%')
</if>
<if test="motorcadeHeaderAccount != null and motorcadeHeaderAccount != ''">
and m.motorcade_header_account like concat('%', #{motorcadeHeaderAccount}, '%')
</if>
<if test="motorcadeScore != null ">
and m.motorcade_score = #{motorcadeScore}
</if>
<if test="createByName != null and createByName != ''">
and m.create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and m.update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="motorcadeDissolutionStatus != null ">
and m.motorcade_dissolution_status = #{motorcadeDissolutionStatus}
</if>
<if test="organizationName != null and organizationName != ''">
and m.organization_name like concat('%', #{organizationName}, '%')
</if>
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and m.organization_id = #{organizationId}
and m.organization_name IS NOT NULL
</if>
<if test="topOrganizationId != null">
<!-- 如果设置了 topOrganizationId,添加 top_organization_id 条件 -->
and m.top_organization_id = #{topOrganizationId}
<if test="organizationId == null">
<!-- 如果没有设置 organizationId,添加 organization_name IS NOT NULL 条件 -->
and m.organization_name IS NOT NULL
</if>
</if>
<if test="organizationIdList != null ">
AND m.organization_id in
<foreach item="id" collection="organizationIdList" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
GROUP BY
m.motorcade_id
order by m.create_time desc
</select>
<select id="selectMotorcadeIdList" parameterType="java.lang.Long" resultType="java.lang.Long">
SELECT
m.motorcade_id
FROM
motorcade m
LEFT JOIN
motorcade_driver d
ON m.motorcade_id = d.motorcade_id AND d.del_flag = 1
WHERE
m.del_flag = 1
AND d.user_id = #{values}
</select>
<select id="selectMotorcadeDriverByDriverId" resultType="com.mhd.user.domain.motorcade.entity.MotorcadeDriver" parameterType="java.lang.Long">
SELECT
b.*
FROM
motorcade a
LEFT JOIN motorcade_driver b ON a.motorcade_id = b.motorcade_id
AND b.del_flag = 1
WHERE
a.del_flag = 1
AND a.motorcade_header_id = #{driverId}
</select>
<select id="queryMyMotorcadeList" resultType="com.mhd.user.domain.motorcade.repository.po.MotorcadeAppPo" parameterType="com.mhd.user.domain.motorcade.repository.todo.MotorcadeDO">
SELECT
m.*,
COUNT( d.user_id ) AS driver_num,
SUM( dvb.vehicle_num ) AS vehicle_num,
WM_CONCAT(d.user_id) AS userIds,
u.user_phone
FROM
motorcade m
LEFT JOIN motorcade_driver d ON m.motorcade_id = d.motorcade_id AND d.del_flag = 1
LEFT JOIN "USER" u ON u.user_id = m.motorcade_header_id
LEFT JOIN (
SELECT
u.user_id,
COUNT( u.user_id ) AS vehicle_num
FROM
driver_vehicle_bind u
WHERE
u.del_flag = 1
GROUP BY
u.user_id
) dvb ON dvb.user_id = d.user_id AND d.del_flag = 1
WHERE
m.del_flag = 1
<include refid="common_where"></include>
GROUP BY
m.motorcade_id
ORDER BY
m.create_time DESC
</select>
<sql id="common_where">
<if test="motorcadeDo.motorcadeId !=null">
AND m.motorcade_id = #{motorcadeDo.motorcadeId}
</if>
<if test="motorcadeDo.myMotorcadeUserId !=null">
AND (m.motorcade_header_id = #{motorcadeDo.myMotorcadeUserId} or d.user_id = #{motorcadeDo.myMotorcadeUserId})
</if>
<if test="motorcadeDo.motorcadeHeaderId !=null">
AND m.motorcade_header_id = #{motorcadeDo.motorcadeHeaderId}
</if>
<if test="motorcadeDo.userId !=null">
AND d.user_id = #{motorcadeDo.userId}
</if>
</sql>
<select id="getDriverListById" resultType="com.mhd.user.domain.motorcade.repository.po.MotorcadeDriverPo" parameterType="com.mhd.user.domain.motorcade.repository.todo.MotorcadeDO">
select md.motorcade_driver_id,
u.user_name,
u.user_id,
u.user_account,
group_concat( DISTINCT dvb.vehicle_license_plate_number) as vehiclePlateNumbers,
count(dvb.vehicle_license_plate_number) as vehicleNum,
ud.driver_fill,
md.create_time,
mc.agreement_url,
u.create_by,
m.motorcade_header_id,
mc.contract_status,
mc.file_id,
mc.agreement_url_pdf
from motorcade_driver md
left join "USER" u on md.user_id = u.user_id and u.del_flag = 1
left join user_driver ud on ud.user_id = md.user_id and ud.del_flag = 1
left join driver_vehicle_bind dvb
on md.user_id = dvb.driver_bind_id and dvb.del_flag = 1
left join motorcade m on m.motorcade_id = md.motorcade_id
LEFT JOIN motorcade_collection mc ON mc.user_id = md.user_id and mc.motorcade_header_id = m.motorcade_header_id
where md.del_flag = 1 and md.motorcade_id = #{motorcadeDo.motorcadeId}
group by motorcade_driver_id
</select>
<select id="fleetInviteDriverList" resultType="com.mhd.user.domain.userAggregate.repository.po.UserDriverPo" parameterType="com.mhd.user.domain.motorcade.repository.todo.MotorcadeDriverDO">
select
u.user_account,
u.user_phone,
u.user_name,
dvb.vehicle_license_plate_number,
ud.*,
r.roleCode
from user_driver ud
left join "USER" u on ud.user_id = u.user_id
LEFT JOIN (SELECT
user_id,
LISTAGG(DISTINCT r.role_code, '&amp;') WITHIN GROUP(ORDER BY r.role_code) AS roleCode
FROM
role r
LEFT JOIN user_role ur ON r.role_id = ur.role_id
AND ur.del_flag = 1
WHERE
r.del_flag = 1
AND role_code IN ( 'driver', 'carrier', 'captain' )
GROUP BY
user_id
) r ON r.user_id = u.user_id
left join motorcade_driver md on md.user_id = ud.user_id and md.del_flag = 1
left join driver_vehicle_bind dvb on u.user_id = dvb.user_id and dvb.del_flag = 1 and dvb.default_flag = 1
<where>ud.del_flag = 1
and u.del_flag = 1
and ud.driver_fill = 3
and u.top_organization_id = #{motorcadeDriverDO.topOrganizationId}
and r.roleCode not like '%carrier%' and r.roleCode not like '%captain%'
<if test="motorcadeDriverDO.motorcadeId !=null">
and (md.motorcade_id != #{motorcadeDriverDO.motorcadeId} or md.motorcade_id is null)
</if>
<if test="motorcadeDriverDO.userPhone !=null and motorcadeDriverDO.userPhone != ''">
and u.user_phone = #{motorcadeDriverDO.userPhone}
</if>
<if test="motorcadeDriverDO.userName !=null and motorcadeDriverDO.userName != ''">
and u.user_name like concat('%', #{motorcadeDriverDO.userName}, '%')
</if>
<if test="motorcadeDriverDO.vehicleLicensePlateNumber !=null and motorcadeDriverDO.vehicleLicensePlateNumber != ''">
and dvb.vehicle_license_plate_number like concat('%', #{motorcadeDriverDO.vehicleLicensePlateNumber}, '%')
</if>
</where>
group by u.user_id
</select>
<select id="queryNonePagingList" resultType="com.mhd.user.domain.motorcade.repository.po.MotorcadePo">
SELECT
m.motorcade_id,
m.motorcade_name
FROM
motorcade m
LEFT JOIN
motorcade_driver d
ON m.motorcade_id = d.motorcade_id and d.del_flag = 1
<where>
m.del_flag = 1
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and m.organization_id = #{organizationId}
and m.organization_name IS NOT NULL
</if>
<if test="topOrganizationId != null">
<!-- 如果设置了 topOrganizationId,添加 top_organization_id 条件 -->
and m.top_organization_id = #{topOrganizationId}
<if test="organizationId == null">
<!-- 如果没有设置 organizationId,添加 organization_name IS NOT NULL 条件 -->
and m.organization_name IS NOT NULL
</if>
</if>
</where>
</select>
</mapper>