Просмотр исходного кода

机构负责人和合伙人数据统计逻辑修改

hxl13994548489 2 лет назад
Родитель
Сommit
d0bcbdbd0b

+ 2 - 1
src/main/java/com/ydtech/modules/admin/dao/DeptBalanceMapper.java

@@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.HashMap;
 
 @Mapper
@@ -27,7 +28,7 @@ public interface DeptBalanceMapper {
      *  @Date: 2024/08/23 9:04
      *  @Description:  合伙人保费金额
      */
-    HashMap<String, BigDecimal> getByDeptId(@Param("deptId") String deptId);
+    HashMap<String, BigDecimal> getByDeptId(@Param("deptId") String deptId, @Param("createTime")  String createTime);
 
     /**
      * @version

+ 11 - 0
src/main/java/com/ydtech/modules/admin/dao/SysAgencyLeaderMapper.java

@@ -1,7 +1,11 @@
 package com.ydtech.modules.admin.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ydtech.modules.admin.model.SysAgencyLeader;
+import com.ydtech.modules.admin.model.dto.DeptBalanceDto;
+import com.ydtech.modules.admin.model.vo.DeptBalanceVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -17,5 +21,12 @@ import java.util.List;
 public interface SysAgencyLeaderMapper extends BaseMapper<SysAgencyLeader> {
 
     List<SysAgencyLeader> getByUserIdList( @Param("userIds") List<String> collect);
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/8/31 12:42
+     *  @Description: 分页查询机构负责人
+     */
+    IPage<DeptBalanceDto> queryPage(Page page, @Param("vo") DeptBalanceVo deptBalanceVo);
 }
 

+ 8 - 0
src/main/java/com/ydtech/modules/admin/dao/SysRelationPersonMapper.java

@@ -2,6 +2,7 @@ package com.ydtech.modules.admin.dao;
 
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ydtech.modules.admin.model.SysAgencyLeader;
 import com.ydtech.modules.admin.model.SysRelationPerson;
 import com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto;
 import org.apache.ibatis.annotations.Mapper;
@@ -23,5 +24,12 @@ public interface SysRelationPersonMapper extends BaseMapper<SysRelationPerson> {
 
     List<SysRelationPerson> getByAgencyLeaderId(String userId);
     List<SysPartnerConsoleDto> getBySuggestId( @Param("vo") SysPartnerConsoleDto sysPartnerConsoleDto);
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/8/31 11:24
+     *  @Description:  通过合伙人id和类型查询机构负责人数据
+     */
+    List<SysAgencyLeader> selectListByLeaderId(@Param("userId") String userId, @Param("type") int type);
 }
 

+ 6 - 1
src/main/java/com/ydtech/modules/admin/model/SysAgencyLeader.java

@@ -1,6 +1,7 @@
 package com.ydtech.modules.admin.model;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import io.swagger.annotations.ApiModel;
@@ -93,6 +94,10 @@ public class SysAgencyLeader implements Serializable {
     private String updateBy;
 
 
-
+    /***
+     * 机构地址
+     */
+    @TableField(exist = false)
+    private String deptAddress;
 }
 

+ 30 - 2
src/main/java/com/ydtech/modules/admin/model/dto/DeptBalanceDto.java

@@ -8,13 +8,13 @@ import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  *  机构管理费统计dto
  */
 @Data
 @ApiModel("机构管理费")
-@NoArgsConstructor
 public class DeptBalanceDto implements Serializable {
 
     @ApiModelProperty(value = "机构名称")
@@ -39,5 +39,33 @@ public class DeptBalanceDto implements Serializable {
     private BigDecimal notWithdrawn;
 
     @ApiModelProperty(value = "机构级别")
-    private BigDecimal comLevel;
+    private String comLevel;
+    /***
+     *  用戶id
+     */
+    private String userId;
+    /***
+     *  机构id
+     */
+    private String  deptId;
+
+    private  String proportional;
+
+    private Date  createTime;
+
+    private Date updateTime;
+
+    public DeptBalanceDto() {
+    }
+
+    public DeptBalanceDto(String deptName, String deptLeader, String deptAddress, BigDecimal deptManagementFee, BigDecimal totalIncome, BigDecimal withdrawn, BigDecimal notWithdrawn, String comLevel) {
+        this.deptName = deptName;
+        this.deptLeader = deptLeader;
+        this.deptAddress = deptAddress;
+        this.deptManagementFee = deptManagementFee;
+        this.totalIncome = totalIncome;
+        this.withdrawn = withdrawn;
+        this.notWithdrawn = notWithdrawn;
+        this.comLevel = comLevel;
+    }
 }

+ 2 - 1
src/main/java/com/ydtech/modules/admin/model/dto/SysPartnerConsoleDto.java

@@ -66,5 +66,6 @@ public class SysPartnerConsoleDto implements Serializable {
     @ApiModelProperty(value = "性别")
     private String sex;
 
-
+    //用户创建时间
+    private String createTime;
 }

+ 88 - 43
src/main/java/com/ydtech/modules/admin/service/impl/DeptBalanceServiceImpl.java

@@ -1,34 +1,33 @@
 package com.ydtech.modules.admin.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ydtech.core.page.HttpResult;
-import com.ydtech.modules.admin.dao.DeptBalanceMapper;
-import com.ydtech.modules.admin.dao.SysPartnerMapper;
-import com.ydtech.modules.admin.dao.SysRelationPersonMapper;
-import com.ydtech.modules.admin.model.SysAgencyLeader;
-import com.ydtech.modules.admin.model.SysPartner;
-import com.ydtech.modules.admin.model.SysRelationPerson;
-import com.ydtech.modules.admin.model.SysUser;
+import com.ydtech.modules.admin.dao.*;
+import com.ydtech.modules.admin.model.*;
 import com.ydtech.modules.admin.model.dto.DeptBalanceDto;
 import com.ydtech.modules.admin.model.dto.MySumAmountQueryDto;
 import com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto;
 import com.ydtech.modules.admin.model.po.SysUserAccount;
-import com.ydtech.modules.admin.model.vo.DeptBalanceVo;
-import com.ydtech.modules.admin.model.vo.PartnerBalanceVo;
-import com.ydtech.modules.admin.model.vo.SysAmountAuditingVo;
-import com.ydtech.modules.admin.model.vo.SysUserVO;
+import com.ydtech.modules.admin.model.vo.*;
 import com.ydtech.modules.admin.service.*;
 import com.ydtech.modules.base.model.vo.PageVo;
+import com.ydtech.modules.order.entity.InsAreaCompany;
+import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.order.service.InsOrdersService;
 import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
 import com.ydtech.utils.StringUtils;
+import io.swagger.annotations.ApiModelProperty;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -55,7 +54,11 @@ public class DeptBalanceServiceImpl implements DeptBalanceService {
     private InsFeeOrderNewService insFeeOrderNewService;
     @Autowired
     private SysUserAccountService sysUserAccountService;
+    @Resource
+    private SysAgencyLeaderMapper sysAgencyLeaderMapper;
 
+    @Autowired
+    private SysAgencyFeeApprovalMapper sysAgencyFeeApprovalMapper;
     /**
      * @version
      * @author: whp
@@ -69,8 +72,53 @@ public class DeptBalanceServiceImpl implements DeptBalanceService {
             Page page = new Page(deptBalanceVo.getPageNum(), deptBalanceVo.getPageSize());
             pageVo.setPageNum(deptBalanceVo.getPageNum());
             pageVo.setPageSize(deptBalanceVo.getPageSize());
-            IPage<DeptBalanceDto> sysUserListPage = deptBalanceMapper.queryDeptLeaderStatistics(page, deptBalanceVo);
-            return HttpResult.ok(sysUserListPage);
+            //通过机构id 用户等条件机构负责人集合
+            IPage<DeptBalanceDto> sysLeaderPage = sysAgencyLeaderMapper.queryPage(page, deptBalanceVo);
+            List<DeptBalanceDto> records = sysLeaderPage.getRecords();
+            List<DeptBalanceDto>  newList =new ArrayList<>();
+            if (records !=null && records.size()>0) {
+                for (DeptBalanceDto itemLeader : records) {
+                    BigDecimal allTotalIncome = BigDecimal.ZERO;  // 总保费
+                    BigDecimal allDeptManagementFee = BigDecimal.ZERO;//机构管理费
+                    BigDecimal allWithdrawn = BigDecimal.ZERO;//已体现
+                    BigDecimal allNotWithdrawn = BigDecimal.ZERO;//未提现
+                    String deptId = itemLeader.getDeptId();
+                    String proportional = itemLeader.getProportional();
+                    Date updateTime = itemLeader.getUpdateTime();
+                    Date createTime = itemLeader.getCreateTime();
+                    String dateStr = "";
+                    if (updateTime != null) {
+                        dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(updateTime);
+                    } else {
+                        dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(createTime);
+                    }
+                    HashMap<String, BigDecimal> orderAmount = deptBalanceMapper.getByDeptId(deptId, dateStr);
+                    if (orderAmount != null && !orderAmount.isEmpty()) {
+                        BigDecimal totalIncome = orderAmount.get("totalIncome")==null ? BigDecimal.ZERO : orderAmount.get("totalIncome");
+                        allTotalIncome = totalIncome.multiply(new BigDecimal(proportional))
+                                .divide(new BigDecimal("100")).setScale(2, RoundingMode.DOWN);
+                        allDeptManagementFee = this.calculateTotal(orderAmount.get("deptManagementFee"), allDeptManagementFee, null);//机构管理费
+                    }
+                    // 填充 已提现抽成费用和可提现抽成费用
+                    List<SysAgencyFeeApproval> sysAgencyFeeApprovals = sysAgencyFeeApprovalMapper.selectList(new LambdaQueryWrapper<SysAgencyFeeApproval>()
+                            .eq(SysAgencyFeeApproval::getUserId, itemLeader.getUserId())
+                            .eq(SysAgencyFeeApproval::getStatus, 1));
+                    if (sysAgencyFeeApprovals.size() > 0) {
+                        for (SysAgencyFeeApproval sysAgencyFeeApproval : sysAgencyFeeApprovals) {
+                            allWithdrawn = allWithdrawn.add(sysAgencyFeeApproval.getHistoryFee());
+                        }
+                    }
+                    //可提现 = 总抽成-已提现
+                    allNotWithdrawn = allTotalIncome.subtract(allWithdrawn);
+                    itemLeader.setDeptManagementFee(allTotalIncome);
+                    itemLeader.setTotalIncome(allDeptManagementFee);
+                    itemLeader.setWithdrawn(allWithdrawn);
+                    itemLeader.setNotWithdrawn(allNotWithdrawn);
+                    newList.add(itemLeader);
+                }
+            }
+            sysLeaderPage.setRecords(newList);
+            return HttpResult.ok(sysLeaderPage);
         } catch (Exception e) {
             e.printStackTrace();
             return HttpResult.error("查询异常");
@@ -90,14 +138,7 @@ public class DeptBalanceServiceImpl implements DeptBalanceService {
             Page page = new Page(deptBalanceVo.getPageNum(), deptBalanceVo.getPageSize());
             pageVo.setPageNum(deptBalanceVo.getPageNum());
             pageVo.setPageSize(deptBalanceVo.getPageSize());
-            SysUser sysUserQuery = new SysUser();
-            sysUserQuery.setDeptId(deptBalanceVo.getDeptId());
-            List<SysUserVO> listByDeptIdUser = this.sysUserService.findListByDeptIdNew(sysUserQuery);
-            List<String> userListDept = listByDeptIdUser.stream().map(SysUserVO::getId).collect(Collectors.toList());
-            if (userListDept.isEmpty()) {
-                userListDept.add("0");
-            }
-            deptBalanceVo.setUserIdList(userListDept);
+            //通过机构id 用户等条件查询合伙人集合
             IPage<SysPartnerConsoleDto> sysPartnersPage = sysPartnerMapper.queryPage(page, deptBalanceVo);
 
             List<SysPartnerConsoleDto> sysPartners = sysPartnersPage.getRecords();
@@ -106,40 +147,44 @@ public class DeptBalanceServiceImpl implements DeptBalanceService {
                 BigDecimal allDeptManagementFee = BigDecimal.ZERO;//机构管理费
                 BigDecimal allWithdrawn = BigDecimal.ZERO;//已体现
                 BigDecimal allNotWithdrawn = BigDecimal.ZERO;//未提现
-//              查询机构负责人
-
-                List<SysAgencyLeader> deptLeader = sysAgencyLeaderService.lambdaQuery().eq(SysAgencyLeader::getSuggestId, item.getUserId()).list();
 
+                List<SysAgencyLeader> deptLeader = sysRelationPersonMapper.selectListByLeaderId(item.getUserId(),1);
 //                  机构负责人
                 for (SysAgencyLeader itemLeader : deptLeader) {
                     String deptId = itemLeader.getDeptId();
                     if (StringUtils.isNotEmpty(deptId)) {
                         String proportional = item.getProportional();
-                        HashMap<String, BigDecimal> orderAmount = deptBalanceMapper.getByDeptId(deptId);
+                        Date updateTime = itemLeader.getUpdateTime();
+                        Date createTime = itemLeader.getCreateTime();
+                        String dateStr="";
+                        if(updateTime!=null){
+                            dateStr=  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(updateTime);
+                        }else{
+                            dateStr=  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(createTime);
+                        }
+                        HashMap<String, BigDecimal> orderAmount = deptBalanceMapper.getByDeptId(deptId,dateStr);
 
                         if (orderAmount != null && !orderAmount.isEmpty()) {
-                            allTotalIncome = this.calculateTotal(orderAmount.get("totalIncome").multiply(new BigDecimal(proportional).divide(new BigDecimal(100))), allTotalIncome, null);  // 总保费
+                            BigDecimal totalIncome = orderAmount.get("totalIncome")==null ? BigDecimal.ZERO : orderAmount.get("totalIncome");
+                            allTotalIncome = totalIncome.multiply(new BigDecimal(proportional))
+                                    .divide(new BigDecimal("100")).setScale(2, RoundingMode.DOWN);
                             allDeptManagementFee = this.calculateTotal(orderAmount.get("deptManagementFee"), allDeptManagementFee, null);//机构管理费
                         }
-                        SysUser sysUser = new SysUser();
-                        sysUser.setDeptId(deptId);
-//                          机构下的userId
-                        List<SysUserVO> listByDeptId = sysUserService.findListByDeptId(sysUser);
-                        List<String> institutionId = listByDeptId.stream().map(SysUserVO::getId).collect(Collectors.toList());
-//                          已提现
-                        SysAmountAuditingVo sysAmountAuditingVo = new SysAmountAuditingVo();
-                        sysAmountAuditingVo.setUserIdList(institutionId);
-                        sysAmountAuditingVo.setAuditingStatus("3");
-                        BigDecimal withdrawn = sysAmountAuditingService.querySumAmount(sysAmountAuditingVo);
-                        allWithdrawn = this.calculateTotal(withdrawn, allWithdrawn, null);
-//                          未提现
-                        sysAmountAuditingVo.setAuditingStatus("2");
-                        BigDecimal notWithdrawn = sysAmountAuditingService.querySumAmount(sysAmountAuditingVo);
-                        allNotWithdrawn = this.calculateTotal(notWithdrawn, allNotWithdrawn, null);
+                        // 填充 已提现抽成费用和可提现抽成费用
+                        List<SysAgencyFeeApproval> sysAgencyFeeApprovals = sysAgencyFeeApprovalMapper.selectList(new LambdaQueryWrapper<SysAgencyFeeApproval>()
+                                .eq(SysAgencyFeeApproval::getUserId, item.getUserId())
+                                .eq(SysAgencyFeeApproval::getStatus, 1));
+                        if (sysAgencyFeeApprovals.size() > 0) {
+                            for (SysAgencyFeeApproval sysAgencyFeeApproval : sysAgencyFeeApprovals) {
+                                allWithdrawn = allWithdrawn.add(sysAgencyFeeApproval.getHistoryFee());
+                            }
+                        }
+                        //可提现 = 总抽成-已提现
+                        allNotWithdrawn = allTotalIncome.subtract(allWithdrawn);
                     }
                 }
-                item.setTotalIncome(allTotalIncome);
-                item.setDeptManagementFee(allDeptManagementFee);
+                item.setTotalIncome(allDeptManagementFee);
+                item.setDeptManagementFee(allTotalIncome);
                 item.setWithdrawn(allWithdrawn);
                 item.setNotWithdrawn(allNotWithdrawn);
             }

+ 6 - 4
src/main/resources/mapper/modules/admin/DeptBalanceMapper.xml

@@ -96,14 +96,16 @@
         sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as
         "deptManagementFee"
         FROM
-        ins_orders io
-        left join ins_area_company iac on iac.orderno = io.orderno
+        ins_area_company iac
+        left join ins_orders io on iac.orderno = io.orderno
         <where>
-            io.orderstatus ='3'
-            and iac.orderstatus ='3'
+             iac.orderstatus ='3'
             <if test="deptId  != null  and  deptId !=''">
                and io.deptid like CONCAT( #{deptId}, '%' )
             </if>
+            <if test="createTime  != null  and  createTime !=''">
+                and io.createtime >= #{createTime}
+            </if>
         </where>
     </select>
 

+ 35 - 0
src/main/resources/mapper/modules/admin/SysAgencyLeaderMapper.xml

@@ -38,6 +38,41 @@
         </where>
 
     </select>
+    <select id="queryPage" resultType="com.ydtech.modules.admin.model.dto.DeptBalanceDto">
+        select
+            sal.user_id AS "userId",
+            sal.user_name AS "deptLeader",
+            sd.address AS "deptAddress",
+            sd.comlevel AS "comlevel",
+            sal.dept_id AS deptId,
+            sal.proportional AS "proportional",
+            sal.create_time AS "createTime",
+            sal.update_time AS "updateTime"
+        from sys_agency_leader sal
+        left  join  sys_user   su  on  sal.user_id = su.id
+        left  join  sys_dept   sd  on  sal.dept_id   =sd.id
+        <where>
+            sal.del_flag =1
+            <if test="vo.deptId !=null  and  vo.deptId !=''">
+                and su.dept_id like  concat('%',#{vo.deptId},'%')
+            </if>
+            <if test="vo.phoneNumber !=null  and  vo.phoneNumber !=''">
+                and su.mobile =#{vo.phoneNumber}
+            </if>
+            <if test="vo.name !=null  and  vo.name !=''">
+                and su.name =#{vo.name}
+            </if>
+            <if test="vo.userCode !=null  and  vo.userCode !=''">
+                and su.id= #{vo.userCode}
+            </if>
+            <if test="vo.days !=null  and vo.days !='' ">
+                and su.create_time >= DATE_SUB(NOW(), INTERVAL #{vo.days} DAY)
+            </if>
+            <if test="vo.beginDate !=null and vo.beginDate != '' and vo.endDate !=null and vo.endDate != ''">
+                AND   DATE_FORMAT( su.create_time, '%Y-%m-%d')   BETWEEN #{vo.beginDate} AND #{vo.endDate}
+            </if>
+        </where>
+    </select>
 
 </mapper>
 

+ 2 - 5
src/main/resources/mapper/modules/admin/SysPartnerMapper.xml

@@ -33,11 +33,8 @@
         <where>
             1=1
             and sp.del_flag ='1'
-            <if test="vo.userIdList !=null and  vo.userIdList!=''  and vo.userIdList.size() >0">
-                and sp.user_id IN
-                <foreach item="item" index="index" collection="vo.userIdList" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
+            <if test="vo.deptId !=null and  vo.deptId!=''  ">
+                and sd.id  LIKE concat('%', #{vo.deptId}, '%')
             </if>
             <if test="vo.phoneNumber !=null  and  vo.phoneNumber !=''">
                 and su.mobile =#{vo.phoneNumber}

+ 10 - 0
src/main/resources/mapper/modules/admin/SysRelationPersonMapper.xml

@@ -62,5 +62,15 @@
         </where>
 
     </select>
+    <select id="selectListByLeaderId" resultType="com.ydtech.modules.admin.model.SysAgencyLeader">
+        select
+            sal.*
+        from sys_relation_person a
+        left  join  sys_user  su  on su.id = a.agency_leader_id
+        left  join  sys_agency_leader  sal  on a.agency_leader_id  = sal.user_id
+       where
+            a.suggest_id =#{userId}
+            and a.type =#{type}
+    </select>
 </mapper>