| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?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.sckw.payment.dao.KwpSettlementLogisticsMapper">
- <resultMap id="BaseResultMap" type="com.sckw.payment.model.KwpSettlementLogistics">
- <!--@mbg.generated-->
- <!--@Table kwp_settlement_logistics-->
- <id column="id" jdbcType="BIGINT" property="id"/>
- <result column="ent_id" jdbcType="BIGINT" property="entId"/>
- <result column="l_ledger_id" jdbcType="BIGINT" property="lLedgerId"/>
- <result column="sl_order_no" jdbcType="VARCHAR" property="slOrderNo"/>
- <result column="name" jdbcType="VARCHAR" property="name"/>
- <result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
- <result column="actual_price" jdbcType="DECIMAL" property="actualPrice"/>
- <result column="receipt_time" jdbcType="TIMESTAMP" property="receiptTime"/>
- <result column="remark" jdbcType="VARCHAR" property="remark"/>
- <result column="trading" jdbcType="VARCHAR" property="trading"/>
- <result column="audit_user" jdbcType="VARCHAR" property="auditUser"/>
- <result column="audit_phone" jdbcType="VARCHAR" property="auditPhone"/>
- <result column="success_user" jdbcType="VARCHAR" property="successUser"/>
- <result column="success_phone" jdbcType="VARCHAR" property="successPhone"/>
- <result column="status" jdbcType="INTEGER" property="status"/>
- <result column="create_by" jdbcType="BIGINT" property="createBy"/>
- <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
- <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
- <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
- <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
- </resultMap>
- <sql id="Base_Column_List">
- id,
- ent_id,
- l_ledger_id,
- sl_order_no,
- name,
- total_price,
- actual_price,
- receipt_time,
- remark,
- trading,
- audit_user,
- audit_phone,
- success_user,
- success_phone,
- status,
- create_by,
- create_time,
- update_by,
- update_time,
- del_flag
- </sql>
- <sql id="Join_Column_List">
- s.id,
- s.ent_id as entId,
- s.l_ledger_id as lLedgerId,
- s.sl_order_no as slOrderNo,
- s.name,
- s.total_price as totalPrice,
- s.actual_price as actualPrice,
- s.receipt_time as receiptTime,
- s.remark,
- s.audit_user as auditUser,
- s.audit_phone as auditPhone,
- s.success_user as successUser,
- s.success_phone as successPhone,
- s.status,
- s.create_by as createBy,
- s.create_time as createTime,
- s.update_by as updateBy,
- s.update_time as updateTime,
- s.del_flag as delFlag
- </sql>
- <!-- 连表筛选准备 -->
- <sql id="settlementLogisticsSelect">
- select l.name as ledgerName,
- l.l_ledger_no as lLedgerNo,
- l.trading as trading,
- l.settle_price as ledgerSettlePrice,
- l.url as attachmentUrl,
- lu2.unit_type as unitType,
- lu2.firm_name as firmName,
- <include refid="Join_Column_List"/>
- from kwp_settlement_logistics s
- inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
- inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
- inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
- </sql>
- <!-- 连表筛选准备 -->
- <sql id="settlementLogisticsSelectSum">
- select count(l.id) total,
- sum(l.settle_price) as actualReceivable,
- sum(s.actual_price) as currentReceipt
- from kwp_settlement_logistics s
- inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
- inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
- inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
- </sql>
- <!-- 根据连表,查询条件准备 -->
- <sql id="settlementLogisticsSelectWhere">
- <if test="settlementReq.status != null and settlementReq.status != 0">
- and s.status = #{settlementReq.status}
- </if>
- <if test="settlementReq.unitType != null">
- and lu.unit_type = #{settlementReq.unitType,jdbcType=INTEGER}
- </if>
- <if test="settlementReq.unitTypeTwo != null">
- and lu2.unit_type = #{settlementReq.unitTypeTwo,jdbcType=INTEGER}
- </if>
- <if test="settlementReq.entId != null">
- and lu2.top_ent_id = #{settlementReq.entId,jdbcType=INTEGER}
- </if>
- <if test="settlementReq.trading != null and settlementReq.trading != ''">
- and l.trading = #{settlementReq.trading,jdbcType=VARCHAR}
- </if>
- <if test="settlementReq.startCreateTime != null and settlementReq.startCreateTime != '' and settlementReq.endCreateTime != null and settlementReq.endCreateTime != ''">
- and s.create_time between #{settlementReq.startCreateTime,jdbcType=TIMESTAMP} and #{settlementReq.endCreateTime,jdbcType=TIMESTAMP}
- </if>
- <if test="settlementReq.startReceiptTime != null and settlementReq.endReceiptTime != null">
- and s.receipt_time between #{settlementReq.startReceiptTime,jdbcType=TIMESTAMP} and #{settlementReq.endReceiptTime,jdbcType=TIMESTAMP}
- </if>
- <if test="settlementReq.keywords != null and settlementReq.keywords != ''">
- and ( l.name like concat('%'
- , #{settlementReq.keywords,jdbcType=VARCHAR}
- , '%')
- or lu2.firm_name like concat('%'
- , #{settlementReq.keywords,jdbcType=VARCHAR}
- , '%')
- or s.sl_order_no like concat('%'
- , #{settlementReq.keywords,jdbcType=VARCHAR}
- , '%')
- )
- </if>
- </sql>
- <!-- 结算运费-物流订单列表 -->
- <select id="pageSelect" resultType="com.sckw.payment.model.dto.SettlementLogisticsDto">
- <include refid="settlementLogisticsSelect"/>
- <where>
- l.del_flag = 0
- and s.del_flag = 0
- and lu.del_flag = 0
- and lu2.del_flag = 0
- <include refid="settlementLogisticsSelectWhere"/>
- </where>
- order by s.update_time desc
- </select>
- <!-- 结算运费-物流订单列表合计 -->
- <select id="selectSum" resultType="com.sckw.payment.model.vo.res.SettlementLogisticsSumVo">
- select a.*, (a.actualReceivable - a.currentReceipt) AS remainingReceivables From (
- <include refid="settlementLogisticsSelectSum"/>
- <where>
- l.del_flag = 0
- and s.del_flag = 0
- and lu.del_flag = 0
- and lu2.del_flag = 0
- <include refid="settlementLogisticsSelectWhere"/>
- </where>
- ) a
- </select>
- <!-- 结算运费-物流订单列表头部汇总数 -->
- <select id="getCountList" resultType="java.lang.Long">
- select count(s.id) as num
- from kwp_settlement_logistics s
- inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
- inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
- inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
- <where>
- l.del_flag = 0
- and s.del_flag = 0
- and lu.del_flag = 0
- and lu2.del_flag = 0
- <include refid="settlementLogisticsSelectWhere"/>
- </where>
- </select>
- <!-- 根据结算物流订单id查详情 -->
- <select id="detail" parameterType="java.lang.Long"
- resultType="com.sckw.payment.model.dto.SettlementLogisticsDto">
- select l.name as ledgerName,
- l.l_ledger_no as lLedgerNo,
- l.trading as trading,
- l.settle_price as settlePrice,
- l.url as attachmentUrl,
- lu.unit_type as unitType,
- lu2.firm_name as firmName,
- <include refid="Join_Column_List"/>
- from kwp_settlement_logistics s
- inner join kwp_ledger_logistics l on s.l_ledger_id = l.id
- inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
- inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id
- where s.id = #{id,jdbcType=BIGINT}
- <if test="unitType != null">
- and lu.unit_type = #{unitType,jdbcType=INTEGER}
- </if>
- <if test="unitTypeTwo != null">
- and lu2.unit_type = #{unitTypeTwo,jdbcType=INTEGER}
- </if>
- </select>
- <!-- 根据多个结算运费物流订单id查订单,用于导出 -->
- <select id="selectLogisticsList" resultType="com.sckw.payment.model.dto.SettlementLogisticsDto">
- <include refid="settlementLogisticsSelect"/>
- <where>
- l.del_flag = 0
- and s.del_flag = 0
- and lu.del_flag = 0
- and lu2.del_flag = 0
- <include refid="settlementLogisticsSelectWhere"/>
- <if test="ids != null and ids.size() > 0">
- and s.id in
- <foreach collection="ids" item="id" close=")" open="(" separator=",">
- #{id,jdbcType=BIGINT}
- </foreach>
- </if>
- </where>
- order by s.update_time desc
- </select>
- <select id="getListById" resultType="com.sckw.payment.model.dto.LedgerUnitDto">
- select kltu.top_ent_id,
- kltu.ent_id,
- kltu.unit_type
- from kwp_settlement_logistics kst
- inner join kwp_ledger_logistics klt on kst.l_ledger_id = klt.id and klt.del_flag = 0
- inner join kwp_ledger_logistics_unit kltu on klt.id = kltu.l_ledger_id and kltu.del_flag = 0
- <where>
- kst.del_flag = 0
- and kst.id = #{id,jdbcType=BIGINT}
- </where>
- </select>
- <select id="selectJoin" resultType="java.lang.String">
- select s.sl_order_no
- from kwp_settlement_logistics s
- inner join kwp_ledger_logistics l on s.l_ledger_id = l.id and l.del_flag = 0
- inner join kwp_ledger_logistics_unit lu on s.l_ledger_id = lu.l_ledger_id
- and lu.del_flag = 0 and lu.unit_type = 1
- inner join kwp_ledger_logistics_unit lu2 on s.l_ledger_id = lu2.l_ledger_id and lu2.del_flag = 0
- and lu2.unit_type = 2
- <where>
- s.del_flag = 0
- and s.status != 3
- and lu.top_ent_id = #{entId,jdbcType=BIGINT}
- and lu2.top_ent_id = #{entTarget,jdbcType=BIGINT}
- </where>
- </select>
- <select id="sumMoneyType" resultType="com.sckw.payment.model.dto.MoneyType">
- select ifnull(sum(ksl.total_price - ksl.actual_price), '0') money,
- 1 type
- from kwp_settlement_logistics ksl
- inner join kwp_ledger_logistics kll on ksl.l_ledger_id = kll.id and kll.del_flag = 0
- inner join kwp_ledger_logistics_unit kllu on kll.id = kllu.l_ledger_id and kllu.del_flag = 0 and
- kllu.unit_type = #{unitType,jdbcType=INTEGER}
- <where>
- ksl.del_flag = 0
- and kllu.top_ent_id = #{entId,jdbcType=BIGINT}
- and ksl.create_time
- <foreach collection="cur" item="item" open="between" close="" separator="and">
- #{item,jdbcType=TIMESTAMP}
- </foreach>
- </where>
- union all
- select ifnull(sum(ksl.total_price - ksl.actual_price), '0') money,
- 2 type
- from kwp_settlement_logistics ksl
- inner join kwp_ledger_logistics kll on ksl.l_ledger_id = kll.id and kll.del_flag = 0
- inner join kwp_ledger_logistics_unit kllu on kll.id = kllu.l_ledger_id and kllu.del_flag = 0 and
- kllu.unit_type = #{unitType,jdbcType=INTEGER}
- <where>
- ksl.del_flag = 0
- and kllu.top_ent_id = #{entId,jdbcType=BIGINT}
- and ksl.create_time
- <foreach collection="pre" item="item" open="between" close="" separator="and">
- #{item,jdbcType=TIMESTAMP}
- </foreach>
- </where>
- </select>
- <select id="queryRecord" resultType="com.sckw.payment.model.KwpSettlementRecord">
- SELECT kllu.top_ent_id entId,
- sum(IF(kllu.unit_type = 2, ksl.total_price, 0.0)) totalReceiveMoney,
- sum(IF(kllu.unit_type = 1, ksl.total_price, 0.0)) totalPayMoney,
- sum(IF(kllu.unit_type = 2, ksl.actual_price, 0.0)) receivedMoney,
- sum(IF(kllu.unit_type = 1, ksl.actual_price, 0.0)) paidMoney,
- sum(IF(kllu.unit_type = 2, ksl.total_price - ksl.actual_price, 0.0)) exactMoney,
- sum(IF(kllu.unit_type = 1, ksl.total_price - ksl.actual_price, 0.0)) unpaidMoney,
- sum(
- IF
- (ksl.receipt_time < now() && kllu.unit_type = 2,
- ksl.total_price - ksl.actual_price, 0.0)
- ) overdueExactMoney,
- sum(
- IF
- (ksl.receipt_time < now() && kllu.unit_type = 2,
- ksl.total_price - ksl.actual_price, 0.0)
- ) overduePaidMoney
- FROM kwp_settlement_logistics ksl
- LEFT JOIN kwp_ledger_logistics_unit kllu ON ksl.l_ledger_id = kllu.l_ledger_id
- AND kllu.del_flag = 0
- WHERE ksl.del_flag = 0
- GROUP BY kllu.top_ent_id
- </select>
- </mapper>
|