123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?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">
- <!-- 结果集 -->
- <resultMap type="com.huaxu.dto.MonthRevenueDto" id="revenueDtoMap">
- <result property="id" column="id" jdbcType="INTEGER"/>
- <result property="collectDateString" column="collect_date_string" jdbcType="VARCHAR"/>
- <result property="receivableTotalAmount" column="receivable_total_amount" jdbcType="VARCHAR"/>
- <result property="receivedTotalAmount" column="received_total_amount" jdbcType="VARCHAR"/>
- <result property="meterReadingUsage" column="meter_reading_usage" jdbcType="VARCHAR"/>
- <result property="generalUserUsage" column="general_user_usage" jdbcType="VARCHAR"/>
- <result property="bigUserUsage" column="big_user_usage" jdbcType="VARCHAR"/>
- <result property="generalUserUsageReceived" column="general_user_usage_received" jdbcType="VARCHAR"/>
- <result property="bigUserUsageReceived" column="big_user_usage_received" jdbcType="VARCHAR"/>
- <collection property="monthSellList" ofType="com.huaxu.entity.MonthSellwaterEntity" javaType="list">
- <result property="id" column="sell_id" jdbcType="INTEGER"/>
- <result property="propertyId" column="property_id" jdbcType="INTEGER"/>
- <result property="waterUsage" column="water_usage" jdbcType="VARCHAR"/>
- </collection>
- </resultMap>
- <!--查询本月售水信息-->
- <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`,
- `general_user_usage_received`, `big_user_usage_received`)
- values (#{tenantId},#{companyOrgId},#{collectDate},#{userMeterCount},#{userMeterAddCount},#{meterReadingCount},
- #{meterReadingUsage},#{chargingUsage},#{meterReadingFinishedRate},#{meterReadingArrivalRate},#{meterReadingErrorRate},
- #{receivableTotalAmount},#{receivedTotalAmount},#{invoicedTotalAmount},#{arrearsTotalAmount},#{generalUserUsage},
- #{bigUserUsage},#{remark},now(),null,now(),null,#{generalUserUsageReceived},#{bigUserUsageReceived})
- </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>
- <!-- 新增售水信息-->
- <insert id="insertSellWater">
- insert into sms_month_sellwater (tenant_id,company_org_id,property_id,collect_date,water_usage,remark,create_by)
- values(#{tenantId}, #{companyOrgId}, #{propertyId}, #{collectDate}, #{waterUsage},#{remark},#{createBy})
- </insert>
- <!-- 通过id修改营收数据 -->
- <update id="updateRevenue">
- update sms_month_revenue
- <set>
- <if test="collectDate != null">
- collect_date = #{collectDate},
- </if>
- <if test="userMeterAddCount != null">
- user_meter_add_count = #{userMeterAddCount},
- </if>
- <if test="userMeterCount != null">
- user_meter_count = #{userMeterCount},
- </if>
- <if test="meterReadingCount != null">
- meter_reading_count = #{meterReadingCount},
- </if>
- <if test="meterReadingUsage != null">
- meter_reading_usage = #{meterReadingUsage},
- </if>
- <if test="chargingUsage != null">
- charging_usage = #{chargingUsage},
- </if>
- <if test="meterReadingFinishedRate != null">
- meter_reading_finished_rate = #{meterReadingFinishedRate},
- </if>
- <if test="meterReadingArrivalRate != null">
- meter_reading_arrival_rate = #{meterReadingArrivalRate},
- </if>
- <if test="meterReadingErrorRate != null">
- meter_reading_error_rate = #{meterReadingErrorRate},
- </if>
- <if test="receivableTotalAmount != null">
- receivable_total_amount = #{receivableTotalAmount},
- </if>
- <if test="receivedTotalAmount != null">
- received_total_amount = #{receivedTotalAmount},
- </if>
- <if test="invoicedTotalAmount != null">
- invoiced_total_amount = #{invoicedTotalAmount},
- </if>
- <if test="arrearsTotalAmount != null">
- arrears_total_amount = #{arrearsTotalAmount},
- </if>
- <if test="generalUserUsage != null">
- general_user_usage = #{generalUserUsage},
- </if>
- <if test="bigUserUsage != null">
- big_user_usage = #{bigUserUsage},
- </if>
- <if test="remark != null">
- remark = #{remark},
- </if>
- <if test="updateBy != null">
- update_by = #{updateBy},
- </if>
- <if test="generalUserUsageReceived != null">
- general_user_usage_received = #{generalUserUsageReceived},
- </if>
- <if test="bigUserUsageReceived != null">
- big_user_usage_received = #{bigUserUsageReceived},
- </if>
- </set>
- where id = #{id}
- </update>
- <!-- 通过id修改售水数据 -->
- <update id="updateSellWater">
- update sms_month_sellwater
- <set>
- <if test="collectDate != null">
- collect_date = #{collectDate},
- </if>
- <if test="waterUsage != null">
- water_usage = #{waterUsage},
- </if>
- <if test="remark != null">
- remark = #{remark},
- </if>
- <if test="updateBy != null">
- update_by = #{updateBy},
- </if>
- </set>
- where id = #{id}
- </update>
- <!-- 通过公司id查询营收数据 -->
- <select id="selectList" resultMap="revenueDtoMap">
- select t1.id,date_format(t1.collect_date,'%Y年%m月') as collect_date_string,meter_reading_usage*10000 as meter_reading_usage
- ,receivable_total_amount*10000 as receivable_total_amount,received_total_amount*10000 as received_total_amount,big_user_usage*10000 as big_user_usage
- ,general_user_usage*10000 as general_user_usage,t2.id as property_id,t3.id as sell_id,t3.water_usage*10000 as water_usage
- ,general_user_usage_received*10000 as general_user_usage_received,big_user_usage_received*10000 as big_user_usage_received
- from sms_month_revenue t1
- left join sms_water_property t2 on t1.company_org_id=t2.company_org_id and t1.tenant_id=t2.tenant_id and t2.status=1
- left join sms_month_sellwater t3 on t2.id=t3.property_id and date_format(t1.collect_date,'%Y-%m-%d')= date_format(t3.collect_date,'%Y-%m-%d')
- where t1.company_org_id = #{companyOrgId} and t1.collect_date >= concat(#{startDate}, '-1')
- and t1.collect_date < concat(#{endDate}, '-1') + interval 1 month
- order by t1.collect_date
- </select>
- </mapper>
|