123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?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.huaxu.dao.RevenueMapper">
- <!--查询本月售水信息-->
- <select id="selectMonthSell" resultType="com.huaxu.dto.MonthSellwaterDto">
- select t2.property_name ,sum(t1.water_usage) water_usage
- from sms_water_property t2
- left join sms_month_sellwater t1 on t1.property_id=t2.id and t1.collect_date>=date_format(curdate(), '%Y-%m' )
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id=#{tenantId}
- </if>
- <if test="companyOrgId != null and companyOrgId !=''">
- and t1.company_org_id=#{companyOrgId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
- and t1.company_org_id in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- </if>
- inner join (
- select distinct property_id
- from sms_month_sellwater
- where 1=1
- <if test="tenantId != null and tenantId != ''">
- and tenant_id=#{tenantId}
- </if>
- <if test="companyOrgId != null and companyOrgId !=''">
- and company_org_id=#{companyOrgId}
- </if>
- )t3 on t2.id=t3.property_id
- group by t2.property_name
- order by water_usage desc,t2.property_name
- </select>
- <!--查询近6个月的售水量-->
- <select id="selectMonthSellTotal" resultType="com.huaxu.dto.MonthSellwaterDto">
- select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,sum(t1.water_usage) water_usage
- from sms_month_sellwater t1
- where t1.collect_date>=date_sub(date_format(curdate(), '%Y-%m-1' ), interval 5 month)
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id=#{tenantId}
- </if>
- <if test="companyOrgId != null and companyOrgId !=''">
- and t1.company_org_id=#{companyOrgId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
- and t1.company_org_id in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- </if>
- group by collect_date_string
- order by collect_date_string
- </select>
- <!--查询月营收情况-->
- <select id="selectMonthRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
- select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,sum(user_meter_count) user_meter_count,
- sum(receivable_total_amount) receivable_total_amount,sum(received_total_amount) received_total_amount,
- sum(general_user_usage) general_user_usage,sum(big_user_usage) big_user_usage,
- if(sum(receivable_total_amount)=0,null,sum(received_total_amount)/sum(receivable_total_amount)*100) water_fee_recovery_rate,
- if(sum(receivable_total_amount)=0,null,sum(general_user_usage)/sum(receivable_total_amount)*100) general_user_percent,
- if(sum(receivable_total_amount)=0,null,sum(big_user_usage)/sum(receivable_total_amount)*100) big_user_percent
- from sms_month_revenue t1
- where t1.collect_date>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id=#{tenantId}
- </if>
- <if test="companyOrgId != null and companyOrgId !=''">
- and t1.company_org_id=#{companyOrgId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
- and t1.company_org_id in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- </if>
- group by collect_date_string
- order by collect_date_string
- </select>
- <!--查询本月各分公司的营收情况-->
- <select id="selectCompanyRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
- select company_org_id,sum(receivable_total_amount) receivable_total_amount,sum(received_total_amount) received_total_amount,
- if(sum(receivable_total_amount)=0,null,sum(received_total_amount)/sum(receivable_total_amount)*100) water_fee_recovery_rate
- from sms_month_revenue t1
- where t1.collect_date>=date_format(curdate(), '%y-%m-1' )
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id=#{tenantId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
- and t1.company_org_id in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- </if>
- group by company_org_id
- order by company_org_id
- </select>
- <!--App总览-生产-售水量(本月,本年)-->
- <select id="selectOverviewRevenue" resultType="com.huaxu.dto.MonthRevenueDto">
- select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,
- sum(METER_READING_USAGE) meter_reading_usage,
- sum(RECEIVABLE_TOTAL_AMOUNT) receivable_total_amount,
- sum(RECEIVED_TOTAL_AMOUNT) received_total_amount,
- sum(GENERAL_USER_USAGE) general_user_usage,
- sum(BIG_USER_USAGE) big_user_usage
- from sms_month_revenue t1
- where t1.collect_date>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id=#{tenantId}
- </if>
- <if test="companyOrgId != null and companyOrgId !=''">
- and t1.company_org_id=#{companyOrgId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
- and t1.company_org_id in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- </if>
- group by collect_date_string
- order by collect_date_string
- </select>
- <!--App总览-生产数据-按时间段查询(环比)-->
- <select id="selectRevenueByDate" resultType="com.huaxu.dto.MonthRevenueDto">
- select date_format(t1.collect_date, '%Y-%m' ) collect_date_string,
- sum(METER_READING_USAGE) meter_reading_usage,
- sum(RECEIVABLE_TOTAL_AMOUNT) receivable_total_amount,
- sum(RECEIVED_TOTAL_AMOUNT) received_total_amount,
- sum(GENERAL_USER_USAGE) general_user_usage,
- sum(BIG_USER_USAGE) big_user_usage,
- from sms_month_revenue t1
- where t1.collect_date>=date_format(#{startDate}, '%y-%m-1' ) and t1.collect_date <= date_format(#{endDate}, '%y-%m-1')
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id=#{tenantId}
- </if>
- <if test="companyOrgId != null and companyOrgId !=''">
- and t1.company_org_id=#{companyOrgId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2 or permissonType == 1">
- and t1.company_org_id in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- </if>
- group by collect_date_string
- order by collect_date_string
- </select>
- <!--查询是否当月有营收数据-->
- <select id="isExistThisMonthRevenue" resultType="java.lang.Integer">
- select count(1)
- from sms_month_revenue t1
- where t1.collect_date>=date_format(curdate(), '%Y-%m' )
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id=#{tenantId}
- </if>
- </select>
- <!-- 新增所有列 -->
- <insert id="insert" keyProperty="id" useGeneratedKeys="true">
- insert into sms_month_revenue(`tenant_id`, `company_org_id`, `collect_date`, `user_meter_count`, `user_meter_add_count`,
- `meter_reading_count`, `meter_reading_usage`, `charging_usage`, `meter_reading_finished_rate`, `meter_reading_arrival_rate`,
- `meter_reading_error_rate`, `receivable_total_amount`, `received_total_amount`, `invoiced_total_amount`,
- `arrears_total_amount`, `general_user_usage`, `big_user_usage`, `remark`, `date_create`, `create_by`, `date_update`, `update_by`)
- values (#{tenantId},#{companyOrgId},#{collectDate},#{userMeterCount},#{userMeterAddCount},#{meterReadingCount},
- #{meterReadingUsage},#{chargingUsage},#{meterReadingFinishedRate},#{meterReadingArrivalRate},#{meterReadingErrorRate},
- #{receivableTotalAmount},#{receivedTotalAmount},#{invoicedTotalAmount},#{arrearsTotalAmount},#{generalUserUsage},
- #{bigUserUsage},#{remark},now(),null,now(),null)
- </insert>
- <!-- 通过租户id修改当月数据 -->
- <update id="update">
- update sms_month_revenue
- <set>
- <if test="userMeterCount != null and userMeterCount != 0">
- user_meter_count = #{userMeterCount},
- </if>
- <if test="userMeterAddCount != null and userMeterAddCount != 0">
- user_meter_add_count = #{userMeterAddCount},
- </if>
- DATE_UPDATE = now()
- </set>
- where tenant_id = #{tenantId} and collect_date>=date_format(curdate(), '%Y-%m-1' )
- </update>
- <!--查询该租户一级公司id-->
- <select id="selectCompanyIdByTenant" resultType="java.lang.Integer">
- select id
- from uims.uims_org
- where parent_org_id=0 and tenant_id=#{tenantId}
- </select>
- </mapper>
|