Browse Source

综合展示营收接口

yuejiaying 4 years ago
parent
commit
0b5a79673e

+ 1 - 1
sms_water/src/main/java/com/huaxu/controller/OnlineMonitorController.java

@@ -48,7 +48,7 @@ public class OnlineMonitorController {
     @RequestMapping(value="selectAlarmDetails" , method = RequestMethod.GET)
     @ApiOperation(value = "查询实时报警信息")
     public AjaxMessage<List<AlarmDetailsDto>> selectAlarmDetails(
-            @ApiParam(value = "一级场景类型名称", required = true) @RequestParam String sceneTypeName,
+            @ApiParam(value = "一级场景类型名称", required = false) @RequestParam(required = false) String sceneTypeName,
             @ApiParam(value = "场景名称", required = false) @RequestParam(required = false) String sceneName){
         AlarmDetailsDto alarmDetailsDto=new AlarmDetailsDto();
         alarmDetailsDto.setSceneTypeName(sceneTypeName);

+ 101 - 0
sms_water/src/main/java/com/huaxu/controller/RevenueController.java

@@ -0,0 +1,101 @@
+package com.huaxu.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.common.StringUtils;
+import com.huaxu.dto.AlarmSettingDto;
+import com.huaxu.dto.MonthRevenueDto;
+import com.huaxu.dto.MonthSellwaterDto;
+import com.huaxu.entity.AlarmSetting;
+import com.huaxu.entity.SceneEntity;
+import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.LoginUser;
+import com.huaxu.model.Pagination;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.service.AlarmSettingService;
+import com.huaxu.service.RevenueService;
+import com.huaxu.service.SceneService;
+import com.huaxu.util.OrgInfoUtil;
+import com.huaxu.util.UserUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 营收控制层
+ *
+ * @author yjy
+ * @since 2021-2-24
+ */
+@RestController
+@RequestMapping("/revenue")
+@Api(tags = "营收信息")
+public class RevenueController {
+    /**
+     * 服务对象
+     */
+    @Autowired
+    private RevenueService revenueService;
+
+    @Autowired
+    private OrgInfoUtil orgInfoUtil;
+
+    /**
+     * 查询本月售水信息
+     *
+     * @param companyOrgId
+     * @return
+     */
+    @RequestMapping(value = "selectMonthSell", method = RequestMethod.GET)
+    @ApiOperation(value = "查询本月售水信息")
+    public AjaxMessage<List<MonthSellwaterDto>> selectMonthSell(
+            @ApiParam(value = "公司机构id", required = false)@RequestParam(required = false) Integer companyOrgId) {
+        List<MonthSellwaterDto> result = revenueService.selectMonthSell(companyOrgId);
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+    /**
+     * 查询近6个月总售水量
+     *
+     * @param companyOrgId
+     * @return
+     */
+    @RequestMapping(value = "selectMonthSellTotal", method = RequestMethod.GET)
+    @ApiOperation(value = "查询近6个月总售水量")
+    public AjaxMessage<List<MonthSellwaterDto>> selectMonthSellTotal(
+            @ApiParam(value = "公司机构id", required = false)@RequestParam(required = false) Integer companyOrgId) {
+        List<MonthSellwaterDto> result = revenueService.selectMonthSellTotal(companyOrgId);
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+    /**
+     * 查询月营收情况
+     *
+     * @param companyOrgId
+     * @return
+     */
+    @RequestMapping(value = "selectMonthRevenue", method = RequestMethod.GET)
+    @ApiOperation(value = "查询月营收情况")
+    public AjaxMessage<List<MonthRevenueDto>> selectMonthRevenue(
+            @ApiParam(value = "近几月", required = true)@RequestParam Integer months,
+            @ApiParam(value = "公司机构id", required = false)@RequestParam(required = false) Integer companyOrgId) {
+        List<MonthRevenueDto> result = revenueService.selectMonthRevenue(companyOrgId,months);
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+    /**
+     * 查询本月各分公司的营收情况
+     *
+     * @return
+     */
+    @RequestMapping(value = "selectCompanyRevenue", method = RequestMethod.GET)
+    @ApiOperation(value = "查询本月各分公司的营收情况")
+    public AjaxMessage<List<MonthRevenueDto>> selectCompanyRevenue() {
+        List<MonthRevenueDto> result = revenueService.selectCompanyRevenue();
+        for(MonthRevenueDto revenue : result){
+            revenue.setCompanyOrgName(orgInfoUtil.getOrgName(revenue.getCompanyOrgId()));
+        }
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+}

+ 44 - 0
sms_water/src/main/java/com/huaxu/dao/RevenueMapper.java

@@ -0,0 +1,44 @@
+package com.huaxu.dao;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.*;
+import com.huaxu.entity.AlarmDetailsEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @description
+ * @auto yjy
+ * @data 2021-2-24
+ */
+@Mapper
+public interface RevenueMapper {
+
+    /**
+     * 查询本月售水信息
+     * @return
+     */
+    List<MonthSellwaterDto> selectMonthSell(MonthSellwaterDto monthSellwaterDto);
+
+    /**
+     * 查询近6个月的售水量
+     * @return
+     */
+    List<MonthSellwaterDto> selectMonthSellTotal(MonthSellwaterDto monthSellwaterDto);
+
+    /**
+     * 查询近几个月的月营收情况
+     * @return
+     */
+    List<MonthRevenueDto> selectMonthRevenue(MonthRevenueDto monthRevenueDto);
+
+    /**
+     * 查询本月各分公司的营收情况
+     * @return
+     */
+    List<MonthRevenueDto> selectCompanyRevenue(MonthRevenueDto monthRevenueDto);
+
+}

+ 59 - 0
sms_water/src/main/java/com/huaxu/dto/MonthRevenueDto.java

@@ -0,0 +1,59 @@
+package com.huaxu.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.huaxu.common.converter.Double1Serializer;
+import com.huaxu.entity.MonthRevenueEntity;
+import com.huaxu.model.ProgramItem;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @description
+ * @auto yjy
+ * @data 2021-2-24
+ */
+@ApiModel("营收情况")
+@Data
+public class MonthRevenueDto extends MonthRevenueEntity {
+
+    private static final long serialVersionUID = -3866939316262264972L;
+
+    @ApiModelProperty(value = "所属公司名称")
+    private String companyOrgName;
+
+    @ApiModelProperty(value = "时间")
+    private String collectDateString;
+
+    @JsonSerialize(using = Double1Serializer.class)
+    @ApiModelProperty(value = "普通客户用水占比")
+    private Double generalUserPercent;
+
+    @JsonSerialize(using = Double1Serializer.class)
+    @ApiModelProperty(value = "大客户用水占比")
+    private Double bigUserPercent;
+
+    @JsonSerialize(using = Double1Serializer.class)
+    @ApiModelProperty(value = "水费回收率")
+    private Double waterFeeRecoveryRate;
+
+    @ApiModelProperty(value="近几月",hidden = true)
+    @JsonIgnore
+    private Integer months;
+
+    @ApiModelProperty(value ="权限",hidden = true)
+    @JsonIgnore
+    private List<ProgramItem> programItems;
+
+    @ApiModelProperty(value="用户权限类型",hidden = true)
+    @JsonIgnore
+    private Integer permissonType;
+
+    @ApiModelProperty(value = "用户类型(-9999 超管 -999普通用户 2普通用户)",hidden = true)
+    @JsonIgnore
+    private String userType;
+
+}

+ 43 - 0
sms_water/src/main/java/com/huaxu/dto/MonthSellwaterDto.java

@@ -0,0 +1,43 @@
+package com.huaxu.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.huaxu.entity.MonthSellwaterEntity;
+import com.huaxu.model.ProgramItem;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 月度售水表(sms_month_sellwater)扩展类
+ *
+ * @author yjy
+ * @since 2021-2-24
+ */
+@Data
+@ApiModel(value = "供水分析")
+public class MonthSellwaterDto extends MonthSellwaterEntity {
+    private static final long serialVersionUID = 460807634914426955L;
+
+    @ApiModelProperty(value = "用水性质名称")
+    private String propertyName;
+
+    @ApiModelProperty(value = "时间")
+    private String collectDateString;
+
+    @ApiModelProperty(value ="权限",hidden = true)
+    @JsonIgnore
+    private List<ProgramItem> programItems;
+
+    @ApiModelProperty(value="用户权限类型",hidden = true)
+    @JsonIgnore
+    private Integer permissonType;
+
+    @ApiModelProperty(value = "用户类型(-9999 超管 -999普通用户 2普通用户)",hidden = true)
+    @JsonIgnore
+    private String userType;
+}

+ 97 - 0
sms_water/src/main/java/com/huaxu/entity/MonthRevenueEntity.java

@@ -0,0 +1,97 @@
+package com.huaxu.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 月度营收表(sms_month_revenue)实体类
+ *
+ * @author yjy
+ * @since 2021-2-23
+ */
+@Data
+@ApiModel(value = "月度营收表")
+public class MonthRevenueEntity implements Serializable {
+    private static final long serialVersionUID = 460807634914426955L;
+
+    @ApiModelProperty(value = "主键")
+    private Integer id;
+
+    @ApiModelProperty(value = "租户标识")
+    private String tenantId;
+
+    @ApiModelProperty(value = "所属公司")
+    private Integer companyOrgId;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
+    @ApiModelProperty(value = "采集时间")
+    private Date collectDate;
+
+    @ApiModelProperty(value = "总户数")
+    private Integer userMeterCount;
+
+    @ApiModelProperty(value = "新增用户数")
+    private Integer userMeterAddCount;
+
+    @ApiModelProperty(value = "抄表数")
+    private Integer meterReadingCount;
+
+    @ApiModelProperty(value = "抄表总水量")
+    private Double meterReadingUsage;
+
+    @ApiModelProperty(value = "计费总水量")
+    private Double chargingUsage;
+
+    @ApiModelProperty(value = "抄表完成率")
+    private Double meterReadingFinishedRate;
+
+    @ApiModelProperty(value = "抄表到户率")
+    private Double meterReadingArrivalRate;
+
+    @ApiModelProperty(value = "抄表错误率")
+    private Double meterReadingErrorRate;
+
+    @ApiModelProperty(value = "应收总金额")
+    private Double receivableTotalAmount;
+
+    @ApiModelProperty(value = "实收总金额")
+    private Double receivedTotalAmount;
+
+    @ApiModelProperty(value = "开票总金额")
+    private Double invoicedTotalAmount;
+
+    @ApiModelProperty(value = "欠费总金额")
+    private Double arrearsTotalAmount;
+
+    @ApiModelProperty(value = "普通客户用水")
+    private Double generalUserUsage;
+
+    @ApiModelProperty(value = "大客户用水")
+    private Double bigUserUsage;
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
+    @ApiModelProperty(value = "创建时间")
+    private Date dateCreate;
+
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
+    @ApiModelProperty(value = "更新时间")
+    private Date dateUpdate;
+}

+ 57 - 0
sms_water/src/main/java/com/huaxu/entity/MonthSellwaterEntity.java

@@ -0,0 +1,57 @@
+package com.huaxu.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 月度售水表(sms_month_sellwater)实体类
+ *
+ * @author yjy
+ * @since 2021-2-24
+ */
+@Data
+@ApiModel(value = "月度售水表")
+public class MonthSellwaterEntity implements Serializable {
+    private static final long serialVersionUID = 460807634914426955L;
+
+    @ApiModelProperty(value = "主键")
+    private Integer id;
+
+    @ApiModelProperty(value = "租户标识")
+    private String tenantId;
+
+    @ApiModelProperty(value = "所属公司")
+    private Integer companyOrgId;
+
+    @ApiModelProperty(value = "用水性质id")
+    private Integer propertyId;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
+    @ApiModelProperty(value = "采集时间")
+    private Date collectDate;
+
+    @ApiModelProperty(value = "用水量")
+    private Double waterUsage;
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
+    @ApiModelProperty(value = "创建时间")
+    private Date dateCreate;
+
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
+    @ApiModelProperty(value = "更新时间")
+    private Date dateUpdate;
+}

+ 39 - 0
sms_water/src/main/java/com/huaxu/service/RevenueService.java

@@ -0,0 +1,39 @@
+package com.huaxu.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.*;
+import com.huaxu.entity.AlarmDetailsEntity;
+
+import java.util.List;
+
+/**
+ * @description
+ * @auto yjy
+ * @data 2021-2-24
+ */
+public interface RevenueService {
+
+    /**
+     * 查询本月售水信息
+     * @return
+     */
+    List<MonthSellwaterDto> selectMonthSell(Integer companyOrgId);
+
+    /**
+     * 查询近6个月总售水量
+     * @return
+     */
+    List<MonthSellwaterDto> selectMonthSellTotal(Integer companyOrgId);
+
+    /**
+     * 查询月营收情况
+     * @return
+     */
+    List<MonthRevenueDto> selectMonthRevenue(Integer companyOrgId,Integer months);
+
+    /**
+     * 查询本月各分公司的营收情况
+     * @return
+     */
+    List<MonthRevenueDto> selectCompanyRevenue();
+}

+ 132 - 0
sms_water/src/main/java/com/huaxu/service/impl/RevenueServiceImpl.java

@@ -0,0 +1,132 @@
+package com.huaxu.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.client.OperationManagerClient;
+import com.huaxu.client.UserCenterClient;
+import com.huaxu.dao.AlarmDetailMapper;
+import com.huaxu.dao.RevenueMapper;
+import com.huaxu.dto.*;
+import com.huaxu.entity.AlarmDetailsEntity;
+import com.huaxu.entity.Message;
+import com.huaxu.model.LoginUser;
+import com.huaxu.service.AlarmDetailsService;
+import com.huaxu.service.RevenueService;
+import com.huaxu.util.DatesUtil;
+import com.huaxu.util.MessageSendUtil;
+import com.huaxu.util.UserUtil;
+import javafx.beans.binding.DoubleExpression;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * @description
+ * @auto yjy
+ * @data 2021-2-24
+ */
+@Service
+@Log4j2
+public class RevenueServiceImpl implements RevenueService {
+
+    @Resource
+    private RevenueMapper revenueMapper;
+    /**
+     * 查询本月售水信息
+     * @return
+     */
+    @Override
+    public  List<MonthSellwaterDto> selectMonthSell(Integer companyOrgId) {
+        MonthSellwaterDto monthSellwaterDto=new MonthSellwaterDto();
+        monthSellwaterDto.setCompanyOrgId(companyOrgId);
+
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        monthSellwaterDto.setTenantId(loginUser.getTenantId());
+        monthSellwaterDto.setProgramItems(loginUser.getProgramItemList());
+        monthSellwaterDto.setUserType(loginUser.getType());
+        //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
+        monthSellwaterDto.setPermissonType(loginUser.getPermissonType());
+        List<MonthSellwaterDto> monthSell=revenueMapper.selectMonthSell(monthSellwaterDto);
+        List<MonthSellwaterDto> result=new ArrayList<>();
+        Double othersUsage=0d;
+        if(monthSell.size()>4){
+            for(int i=0;i<monthSell.size();i++){
+                if(i<3){
+                    result.add(monthSell.get(i));
+                } else{
+                    othersUsage+=monthSell.get(i).getWaterUsage();
+                }
+            }
+            monthSellwaterDto.setPropertyName("其他用水");
+            monthSellwaterDto.setWaterUsage(othersUsage);
+            result.add(monthSellwaterDto);
+        }else{
+            result=monthSell;
+        }
+        return result;
+    }
+    /**
+     * 查询近6个月总售水量
+     *
+     * @param companyOrgId
+     * @return
+     */
+    @Override
+    public  List<MonthSellwaterDto> selectMonthSellTotal(Integer companyOrgId) {
+        MonthSellwaterDto monthSellwaterDto=new MonthSellwaterDto();
+        monthSellwaterDto.setCompanyOrgId(companyOrgId);
+
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        monthSellwaterDto.setTenantId(loginUser.getTenantId());
+        monthSellwaterDto.setProgramItems(loginUser.getProgramItemList());
+        monthSellwaterDto.setUserType(loginUser.getType());
+        //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
+        monthSellwaterDto.setPermissonType(loginUser.getPermissonType());
+        return revenueMapper.selectMonthSellTotal(monthSellwaterDto);
+    }
+
+    /**
+     * 查询月营收情况
+     *
+     * @param companyOrgId
+     * @return
+     */
+    @Override
+    public  List<MonthRevenueDto> selectMonthRevenue(Integer companyOrgId,Integer months) {
+        MonthRevenueDto monthRevenueDto=new MonthRevenueDto();
+        monthRevenueDto.setCompanyOrgId(companyOrgId);
+        monthRevenueDto.setMonths(months);
+
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        monthRevenueDto.setTenantId(loginUser.getTenantId());
+        monthRevenueDto.setProgramItems(loginUser.getProgramItemList());
+        monthRevenueDto.setUserType(loginUser.getType());
+        //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
+        monthRevenueDto.setPermissonType(loginUser.getPermissonType());
+        return revenueMapper.selectMonthRevenue(monthRevenueDto);
+    }
+
+    /**
+     * 查询本月各分公司的营收情况
+     *
+     * @return
+     */
+    @Override
+    public  List<MonthRevenueDto> selectCompanyRevenue() {
+        MonthRevenueDto monthRevenueDto=new MonthRevenueDto();
+
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        monthRevenueDto.setTenantId(loginUser.getTenantId());
+        monthRevenueDto.setProgramItems(loginUser.getProgramItemList());
+        monthRevenueDto.setUserType(loginUser.getType());
+        //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
+        monthRevenueDto.setPermissonType(loginUser.getPermissonType());
+        return revenueMapper.selectCompanyRevenue(monthRevenueDto);
+    }
+}

+ 4 - 1
sms_water/src/main/resources/mapper/OnlineMonitorMapper.xml

@@ -129,7 +129,10 @@
         from sms_scene t1
         inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
         inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
-        where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
+        where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t6.state=1
+        <if test="sceneTypeName != null and sceneTypeName != ''">
+            and t3.scene_type_name = #{sceneTypeName}
+        </if>
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
             <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">

+ 100 - 0
sms_water/src/main/resources/mapper/RevenueMapper.xml

@@ -0,0 +1,100 @@
+<?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_month_sellwater t1
+        inner join sms_water_property t2 on t1.property_id=t2.id
+        where 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>
+        group by t2.property_name
+        order by water_usage desc
+    </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(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>
+
+</mapper>