|
- <?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.iformall.mapper.WxAllBillMapper">
- <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxAllBill">
- <id column="id" jdbcType="BIGINT" property="id"/>
- <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
- <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
- <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
- <result column="rent_shop_type" jdbcType="INTEGER" property="rentShopType"/>
- <result column="createtime" jdbcType="TIMESTAMP" property="createtime"/>
- <result column="create_by" jdbcType="BIGINT" property="createBy"/>
- <result column="create_by_name" jdbcType="VARCHAR" property="createByName"/>
- <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
- <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
- <result column="update_by_name" jdbcType="VARCHAR" property="updateByName"/>
- <result column="need_pay" jdbcType="VARCHAR" property="needPay"/>
- <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
- <result column="pay" jdbcType="VARCHAR" property="pay"/>
- <result column="bill_type" jdbcType="INTEGER" property="billType"/>
- <result column="pay_way" jdbcType="BIGINT" property="payWay"/>
- <result column="pay_date" jdbcType="TIMESTAMP" property="payDate"/>
- <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
- <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
- <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
- <result column="status" jdbcType="INTEGER" property="status"/>
- <result column="energy_fees_id" jdbcType="BIGINT" property="energyFeesId"/>
- <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
- <result column="bill_remark" jdbcType="VARCHAR" property="billRemark"/>
- <result column="last_owe_call_time" jdbcType="TIMESTAMP" property="lastOweCallTime"/>
- <result column="last_owe_call_user" jdbcType="VARCHAR" property="lastOweCallUser"/>
-
- <result column="bussiness_manage_fee_need_pay" jdbcType="VARCHAR" property="bussinessManageFeeNeedPay"/>
- <result column="operating_manage_fee_need_pay" jdbcType="VARCHAR" property="operatingManageFeeNeedPay"/>
- <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
- <result column="shop_number" jdbcType="VARCHAR" property="shopNumber"/>
- <result column="is_preview" jdbcType="INTEGER" property="isPreview"/>
- <result column="shop_info" jdbcType="VARCHAR" property="shopInfo"/>
- <result column="rent_contract_id" jdbcType="BIGINT" property="rentContractId"/>
- <result column="property_contract_id" jdbcType="BIGINT" property="propertyContractId"/>
- <result column="parent_bill_id" jdbcType="BIGINT" property="parentBillId"/>
- <result column="energy_reading_calcuteId" jdbcType="BIGINT" property="energyReadingCalcuteId" />
- <result column="energy_reading_id" jdbcType="BIGINT" property="energyReadingId" />
-
- </resultMap>
-
- <sql id="allColumns">
- `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`rent_shop_type`,`createtime`,`create_by`,`create_by_name`,`updatetime`,`update_by`,`update_by_name`,
- `need_pay`,`receive_pay`,`pay`,`bill_type`,`pay_way`,`pay_date`,`set_off`,`starttime`,`endtime`,`status`,`energy_fees_id`,`return_pay`,`bill_remark`,
- `last_owe_call_time`,`last_owe_call_user`,`bussiness_manage_fee_need_pay`,`operating_manage_fee_need_pay`,`shop_id`,`shop_number`,`is_preview`,
- `shop_info`,`rent_contract_id`,`property_contract_id`,`parent_bill_id`,`energy_reading_calcuteId`,`energy_reading_id`
- </sql>
-
- <sql id="dynamicWhereConditions">
- where `tenant_id` = #{tenantId}
- <if test=" null != id ">and `id` = #{id}</if>
- <if test=" null != parentTenantId and '' != parentTenantId"> and `parent_tenant_id` = #{parentTenantId}</if>
- <if test=" null != merchantId ">and `merchant_id` = #{merchantId}</if>
- <if test=" null != rentShopType ">and `rent_shop_type` = #{rentShopType}</if>
- <if test=" null != createBy ">and `create_by` = #{createBy}</if>
- <if test=" null != createByName and '' != createByName"> and `create_by_name` like concat('%',#{createByName},'%')</if>
- <if test=" null != billType ">and `bill_type` = #{billType}</if>
- <if test=" null != payWay ">and `pay_way` = #{payWay}</if>
- <if test=" null != status ">and `status` = #{status}</if>
- <if test=" null != energyFeesId ">and `energy_fees_id` = #{energyFeesId}</if>
- <if test=" null != rentContractId ">and `rent_contract_id` = #{rentContractId}</if>
- <if test=" null != propertyContractId ">and `property_contract_id` = #{propertyContractId}</if>
- <if test=" null != parentBillId ">and `parent_bill_id` = #{parentBillId}</if>
- <if test=" null != isPreview ">and `is_preview` = #{isPreview}</if>
- <if test=" null != starttime">and `starttime` <= #{starttime}</if>
- <if test=" null != endtime">and `endtime` >= #{endtime}</if>
- <if test=" null != month and '' != month">
- and date_format(starttime,'%Y-%m') <= #{month} and date_format(endtime,'%Y-%m') >= #{month}
- </if>
- <if test=" null == nearBillLastTime and null != oweBillLastTime">
- and (`starttime` <= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7))
- </if>
- <if test=" null != nearBillLastTime and null != oweBillLastTime">
- and (`starttime` > #{oweBillLastTime} and `starttime` <= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7))
- </if>
- <if test=" null != needPayStartDay">
- and (`starttime` <= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7))
- </if>
- <if test=" 1 == notifyed ">and (`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7) )</if>
- <if test=" null != hasMerchant ">and `merchant_id` is not null</if>
- <if test=" 1 == hasParentBillId ">and `parent_bill_id` is not null</if>
- <if test=" 0 == hasParentBillId ">and `parent_bill_id` is null</if>
- <if test=" 1 == hasFeesStardarsId ">and `energy_fees_id` is not null</if>
- <if test=" 0 == hasFeesStardarsId ">and `energy_fees_id` is null</if>
- <if test=" null != energyReadingCalcuteId ">and `energy_reading_calcuteId` = #{energyReadingCalcuteId}</if>
- <if test=" null != energyReadingId ">and `energy_reading_id` = #{energyReadingId}</if>
- <if test=" null != rentContractIdList ">
- and `rent_contract_id` in
- <foreach collection="rentContractIdList" index="index" item="ridItem" open="(" separator="," close=")">
- #{ridItem}
- </foreach>
- </if>
- <if test=" null != propertyContractIds ">
- and property_contract_id in
- <foreach collection="propertyContractIds" index="index" item="pidItem" open="(" separator="," close=")">
- #{pidItem}
- </foreach>
- </if>
- <if test=" null != merchantIdList ">
- and `merchant_id` in
- <foreach collection="merchantIdList" index="index" item="midItem" open="(" separator="," close=")">
- #{midItem}
- </foreach>
- </if>
- <if test=" null != statusList ">
- and `status` in
- <foreach collection="statusList" index="index" item="stItem" open="(" separator="," close=")">
- #{stItem}
- </foreach>
- </if>
- <if test=" null != notInIds ">
- and id not in
- <foreach collection="notInIds" index="index" item="nidItem" open="(" separator="," close=")">
- #{nidItem}
- </foreach>
- </if>
- <if test=" null != sortColumns">order by ${sortColumns}</if>
- <if test="null != limitStart and null != limitEnd">
- limit #{limitStart},#{limitEnd}
- </if>
- </sql>
-
- <select id="findList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="BaseResultMap">
- select
- <include refid="allColumns"/>
- from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap">
- select
- <include refid="allColumns"/>
- from wx_all_bill where id = #{id} and `tenant_id` = #{tenantId}
- </select>
-
- <select id="queryBillRentContractIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
- select distinct rent_contract_id from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <resultMap id="SumBaseResultMap" type="com.iformall.domain.vo.WxBillSum">
- <result column="receive_pay" jdbcType="VARCHAR" property="needPay"/>
- <result column="paid" jdbcType="VARCHAR" property="paid" />
- <result column="min_date" jdbcType="TIMESTAMP" property="minDate" />
- <result column="max_date" jdbcType="TIMESTAMP" property="maxDate" />
- <result column="return_pay" jdbcType="VARCHAR" property="returnPay"/>
- <result column="set_off" jdbcType="VARCHAR" property="setOff"/>
- </resultMap>
- <select id="getBillMonthSum" parameterType="com.iformall.domain.po.WxAllBill" resultMap="SumBaseResultMap">
- select
- sum(CAST(receive_pay AS DECIMAL(20,2))) receive_pay ,
- sum(CAST(pay AS DECIMAL(20,2))) paid,
- min(starttime) min_date,
- max(endtime) max_date,
- sum(CAST(set_off AS DECIMAL(20,2))) set_off ,
- sum(CAST(return_pay AS DECIMAL(20,2))) return_pay
- from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <select id="getMerchantIdList" parameterType="com.iformall.domain.po.WxAllBill" resultType="Long">
- select distinct merchant_id from wx_all_bill
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <resultMap id="HotNotifyBaseResultMap" type="com.iformall.domain.vo.WxBillHotNotify">
- <result column="total_count" jdbcType="INTEGER" property="totalCount"/>
- <result column="total_money" jdbcType="VARCHAR" property="totalMoney" />
- <result column="min_begin_time" jdbcType="TIMESTAMP" property="minBeginTime"/>
- <result column="bill_type" jdbcType="INTEGER" property="billType"/>
- </resultMap>
- <select id="getBillHotNotify" parameterType="com.iformall.domain.po.WxAllBill" resultMap="HotNotifyBaseResultMap">
- select
- bill_type,
- count(1) total_count ,
- sum(CAST(`receive_pay` AS DECIMAL(20,2)) - CAST(`pay` AS DECIMAL(20,2)) - CAST(IFNULL(`set_off`,'0') AS DECIMAL(20,2)) + CAST(IFNULL(`return_pay`,'0') AS DECIMAL(20,2))) total_money,
- MIN(br.starttime) min_begin_time from wx_all_bill
- <include refid="queryBillRentListCondition"/>
- group by bill_type
- </select>
-
- <resultMap id="NotifyResultMap" type="com.iformall.domain.vo.WxBillNotify">
- <result column="bill_type" jdbcType="INTEGER" property="billType"/>
- <result column="bill_id" jdbcType="BIGINT" property="billId" />
- <result column="starttime" jdbcType="TIMESTAMP" property="starttime"/>
- <result column="endtime" jdbcType="TIMESTAMP" property="endtime"/>
- <result column="receive_pay" jdbcType="VARCHAR" property="receivePay"/>
- <result column="pay" jdbcType="VARCHAR" property="pay"/>
- <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
- </resultMap>
- <select id="getBillNotifyList" parameterType="com.iformall.domain.po.WxAllBill" resultMap="NotifyResultMap">
- select bill_type,br.id as bill_id, br.starttime,br.endtime,br.receive_pay,br.pay,br.merchant_id from wx_all_bill br
- <include refid="queryBillRentListCondition"/>
- </select>
-
- <delete id="deleteBillByContract" parameterType="com.iformall.domain.po.WxRentContract">
- delete from wx_all_bill where rent_contract_id = #{id}
- </delete>
-
- <delete id="deletePreviewBill" parameterType="com.iformall.domain.po.WxAllBill">
- delete from wx_all_bill where rent_contract_id = #{rentContractId}
- <if test=" null != isPreview "> and is_preview = #{isPreview}</if>
- </delete>
-
- <delete id="deleteNoNeedPayBill" parameterType="com.iformall.domain.po.WxAllBill">
- delete from wx_all_bill where rent_contract_id = #{rentContractId} and is_preview = 0 and status = 2
- and starttime > #{shopEndtime} and IFNULL(`pay`,'0') <= 0 AND IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0
- </delete>
-
- <update id="updatePreviewStatus" parameterType="com.iformall.domain.po.WxAllBill">
- update wx_all_bill set is_preview = #{isPreview},merchant_id = #{merchantId},need_pay = receive_pay
- where rent_contract_id = #{rentContractId}
- </update>
-
- <insert id="insertBills" parameterType="HashMap">
- INSERT INTO wx_all_bill (
- <include refid="allColumns"/>
- )
- VALUES
- <foreach collection="list" item="item" index="index" separator=",">
- (
- #{item.id},#{item.tenantId},#{item.parentTenantId},#{item.merchantId},#{item.rentShopType},#{item.createtime},
- #{item.createBy},#{item.createByName},#{item.updatetime},#{item.updateBy},#{item.updateByName},#{item.needPay},
- #{item.receivePay},#{item.pay},#{item.billType},#{item.payWay},#{item.payDate},#{item.setOff},
- #{item.starttime},#{item.endtime},#{item.status},#{item.energyFeesId},#{item.returnPay},#{item.billRemark},
- #{item.lastOweCallTime},#{item.lastOweCallUser},#{item.bussinessManageFeeNeedPay},#{item.operatingManageFeeNeedPay},
- #{item.shopId},#{item.shopNumber},#{item.isPreview},#{item.shopInfo},#{item.rentContractId},#{item.propertyContractId},
- #{item.parentBillId},#{item.energyReadingCalcuteId},#{item.energyReadingId}
- )
- </foreach>
- </insert>
-
- <delete id = "deleteById" parameterType="HashMap">
- delete from wx_all_bill where id = #{id} and tenant_id = #{tenantId}
- </delete>
-
- </mapper>
|