<?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.mandi.fendan.mapper.Fd_XSTDMapper">
|
<sql id="column">
|
a.td_bmbh,a.td_bmmc,a.td_bz,a.td_djrq,a.td_fpbh, a.td_jylx, a.td_khbh,a.td_cqNo,a.committime,
|
CASE WHEN a.td_fpbh IS NULL THEN b.name WHEN a.td_fpbh= '' THEN b.name
|
WHEN a.td_ywdybh= '101' THEN '河南报关' WHEN a.td_ywdybh= '102' THEN '郑州报关' WHEN a.td_ywdybh= '111' THEN '明晟报关' WHEN a.td_ywdybh= '114' THEN '义瑞报关' ELSE '科技报关'
|
END td_khmc,
|
a.td_shddbh,
|
c.name as td_shdd,
|
a.td_tdbh,
|
a.td_tdls,
|
a.td_wfdsl,
|
a.td_wfdzl,
|
a.td_zcwcbz,
|
a.td_zdrmc td_zdr,
|
a.td_zdr as td_zdrbh,
|
CASE a.td_ztbz WHEN '1' THEN '含运费送货' WHEN '3' THEN '不含运费送货' ELSE '自提' END td_ztbz,
|
a.td_shsj td_shsj,
|
a.td_ywdybh,
|
d.name as td_ywdyName,
|
e.name as dq_name
|
</sql>
|
<!--查询地区的厂区 -->
|
<sql id="sqlDq">
|
ISNULL((select STUFF((select distinct ','+b.name from fd_wlgs_fhdq f left join fd_company b on f.wlgsNo=b.companyNo where f.fhdqNo=a.td_shddbh
|
and f.ywdyNo=(case when a.td_ywdybh in ('102','111','114') then a.td_ywdybh else '103' end)
|
and EXISTS (SELECT 1 from fd_company_ywdy c where b.companyNo=c.companyNo and c.ywdyNo=a.td_ywdybh )
|
for xml path('')
|
),1,1,'' ) ),'')
|
</sql>
|
<!--查询物流公司的厂区 -->
|
<sql id="mxWlgsDq">
|
ISNULL(( select STUFF( (
|
select ','+name from fd_company fdc where EXISTS (
|
select * from fd_mx_wlgs where wlgs_no = fdc.companyNo and td_tdls=a.td_tdls
|
) for xml path('')
|
),1,1,'' ) ),'')
|
</sql>
|
|
<!-- 根据地区来决定是否显示 -->
|
<sql id="changqu">
|
<if test=" cqV !=null and cqV !='' ">
|
<if test="companyNo!=null and companyNo!=''"> <!--要确保是管理员或者是fdAdmin的时候companyNo是空-->
|
and ( (a.td_ztbz not in (1,3) and EXISTS ( select * from fd_company_ywdy cy left join fd_company fc on
|
cy.companyNo = fc.companyNo where hasSPR=1 and cy.companyNo=#{companyNo} ) ) <!-- 拥有自提权限的只能看到厂区范围的 -->
|
or
|
(a.td_ztbz in (1,3) and EXISTS (SELECT 1 from fd_wlgs_fhdq b LEFT JOIN nc_dq c on b.fhdqNo=c.code <!-- 拥有非自提权限的只能看到区域范围的 -->
|
where c.code=a.td_shddbh and b.wlgsNo=#{companyNo}
|
<if test=" cqV !=null and cqV !='' ">
|
<choose>
|
<when test="cqV=='102' || cqV=='111' || cqV=='114' ">
|
and b.ywdyNo=#{cqV}
|
</when>
|
<otherwise>
|
and b.ywdyNo!='102' and b.ywdyNo!='111' and b.ywdyNo!='114'
|
</otherwise>
|
</choose>
|
</if>
|
) )
|
)
|
</if>
|
<choose>
|
<when test="cqV=='102' || cqV=='111' || cqV=='114'">
|
and a.td_cqNo=#{cqV}
|
</when>
|
<otherwise>
|
and a.td_cqNo !='102' and a.td_cqNo !='111' and a.td_cqNo !='114'
|
</otherwise>
|
</choose>
|
</if>
|
</sql>
|
<sql id="condition">
|
<if test="companyNo !=null and companyNo !='' ">
|
<choose>
|
<when test="ztbz==0">
|
AND a.td_ztbz in (1,3) <!--非自提-->
|
</when>
|
<otherwise>
|
and a.td_ztbz not in (1,3) <!-- 自提 -->
|
</otherwise>
|
</choose>
|
</if>
|
<if test="sdate !=null and sdate !='' ">
|
and a.td_djrq >= #{sdate}+' 00:00:00'
|
</if>
|
<if test="edate !=null and edate !='' ">
|
and a.td_djrq <= #{edate}+' 23:59:59'
|
</if>
|
<if test="fdAdmin == null || fdAdmin == '' ">
|
<choose>
|
<when test="wcSign==0">
|
and a.td_wfdsl > 0
|
</when>
|
<otherwise>
|
and a.td_wfdsl <= 0
|
</otherwise>
|
</choose>
|
</if>
|
<if test="fdAdmin != null and fdAdmin != '' "> <!-- 在车辆分单页面时 -->
|
and (
|
(a.td_wfdsl=0 and exists
|
(
|
select 1 from fd_xstdmx tdmx where tdmx.tdmx_tdls = a.td_tdls and tdmx.tdmx_gbbz=0 and exists
|
(select 1 from bussinesssheet bs where bussinessNo=tdmx.tdmx_fdywbh and cardno is not null and cardno!='' and sstatus='在办')
|
)
|
) <!-- 全部分单,则车辆有未发卡显示 -->
|
or a.td_wfdsl > 0 <!-- 有未分单显示 -->
|
)
|
</if>
|
<if test="tdbh !=null and tdbh !='' ">
|
and a.td_tdbh like '%'+#{tdbh}+'%'
|
</if>
|
<if test="shdd !=null and shdd !='' ">
|
and c.name = #{shdd}
|
</if>
|
<if test="zdbm !=null and zdbm !='' ">
|
and ( a.td_bmmc like '%'+#{zdbm}+'%')
|
</if>
|
<if test="fpbh !=null and fpbh !='' ">
|
and ( a.td_fpbh like '%'+#{fpbh}+'%')
|
</if>
|
<if test="zdr !=null and zdr !='' ">
|
and ( a.td_zdr like '%'+#{zdr}+'%')
|
</if>
|
<!-- 关联流水号中的可见物流公司(全部为空,显示地区;不全部为空,显示地区+可见;全部不为空,显示可见物流公司) -->
|
<if test=" cqV !=null and cqV !='' ">
|
and case when not exists (select * from fd_mx_wlgs where td_tdls=a.td_tdls)
|
<include refid="changqu"/> <!-- 厂区可见 -->
|
then 1
|
<if test="companyNo!=null and companyNo!=''"> <!--全部不为空,即提单中的每一项都手动分了-->
|
when exists (select * from fd_xstdmx mx where exists (
|
select * from fd_mx_wlgs where tdmx_tdfl=mx.tdmx_Tdfl) and tdmx_tdls=a.td_tdls
|
) then (case when exists (select * from fd_mx_wlgs where td_tdls=a.td_tdls and wlgs_no=#{companyNo} ) then 1 else 0 end) <!--如果分配给了当前公司可见,否则不可见-->
|
when (1=1<include refid="changqu"/>) <!-- 区域物流公司 + 手动分配的物流公司 可见 -->
|
or exists(select * from fd_mx_wlgs where td_tdls=a.td_tdls and wlgs_no=#{companyNo}) then 1
|
</if>
|
else 0 end > 0
|
</if>
|
</sql>
|
|
|
<select id="getList" parameterType="java.util.Map" resultType="com.mandi.fendan.util.persist.WaitXSTD">
|
<choose>
|
<when test="pagesize > 0 ">
|
select top ${pagesize} *
|
</when>
|
<otherwise>
|
select *
|
</otherwise>
|
</choose>
|
from ( select row_number()
|
<choose>
|
<when test="sort!=null and sort!='' ">
|
over (order by ${sort} )
|
</when>
|
<otherwise>
|
over (order by td_djrq desc )
|
</otherwise>
|
</choose>
|
as rownumber, a.* from
|
(select case when a.td_ztbz not in (1,3) then '' <!-- 自提不显示物流公司 -->
|
when not exists (select * from fd_mx_wlgs where td_tdls=a.td_tdls)
|
then <include refid="sqlDq"/> <!-- 未人为分配,显示区域物流公司 -->
|
when exists (select * from fd_xstdmx mx where exists (
|
select * from fd_mx_wlgs where tdmx_tdfl=mx.tdmx_Tdfl) and tdmx_tdls=a.td_tdls
|
) then <include refid="mxWlgsDq"/> <!-- 全部分配,显示分配的物流公司 -->
|
else <include refid="sqlDq"/> + ' ' + <include refid="mxWlgsDq"/> <!-- 其他即“未全部人为分配”,则显示合集 -->
|
end as companyName,
|
DATEDIFF (mi,a.td_djrq,getdate()) timeMinus,
|
<include refid="column"/> from fd_xstd a
|
LEFT JOIN dbo.company b ON a.td_khbh= b.companyNo
|
LEFT JOIN dbo.nc_dq c ON a.td_shddbh= c.code
|
LEFT JOIN dbo.nc_ywdy d ON a.td_ywdybh= d.code
|
left join dbo.nc_dq e on a.td_shddbh = e.code
|
<where>
|
NOT EXISTS ( SELECT 1 FROM dbo.fd_gbxstd g WHERE a.td_tdbh= g.xstdNo )
|
<include refid="condition"/>
|
</where>
|
) a
|
<where>
|
<if test="khmc !=null and khmc !='' ">
|
and ( a.td_khmc like '%'+#{khmc}+'%')
|
</if>
|
</where>
|
) as a where rownumber > #{pagesize}*#{page}
|
|
</select>
|
|
<select id="countPage" parameterType="Map" resultType="int">
|
select count(*) from fd_xstd a
|
LEFT JOIN dbo.company b ON a.td_khbh= b.companyNo
|
LEFT JOIN dbo.nc_dq c ON a.td_shddbh= c.code
|
LEFT JOIN dbo.nc_ywdy d ON a.td_ywdybh= d.code
|
left join dbo.nc_dq e on a.td_shddbh = e.code
|
<where>
|
NOT EXISTS ( SELECT 1 FROM dbo.fd_gbxstd g WHERE a.td_tdbh= g.xstdNo )
|
<include refid="condition"/>
|
</where>
|
</select>
|
</mapper>
|