Selaa lähdekoodia

Merge remote-tracking branch 'origin/test' into test

wks 2 vuotta sitten
vanhempi
commit
bd0438de14
28 muutettua tiedostoa jossa 968 lisäystä ja 345 poistoa
  1. 1 0
      src/main/java/com/ydtech/components/TokenInterceptor.java
  2. 8 8
      src/main/java/com/ydtech/modules/admin/controller/SysAgencyFeeApprovalController.java
  3. 13 2
      src/main/java/com/ydtech/modules/admin/controller/SysDeptController.java
  4. 43 0
      src/main/java/com/ydtech/modules/admin/controller/SysLoginController.java
  5. 10 1
      src/main/java/com/ydtech/modules/admin/controller/SysPartnerController.java
  6. 1 0
      src/main/java/com/ydtech/modules/admin/dao/SysAgencyFeeApprovalMapper.java
  7. 10 0
      src/main/java/com/ydtech/modules/admin/model/StatusInfo.java
  8. 3 0
      src/main/java/com/ydtech/modules/admin/model/report/profitAnalysis/ProfitAnalysisDto.java
  9. 75 0
      src/main/java/com/ydtech/modules/admin/model/vo/SysAgencyFeeApprovalRecordVo.java
  10. 3 0
      src/main/java/com/ydtech/modules/admin/model/vo/SysDeptTreeVo.java
  11. 3 2
      src/main/java/com/ydtech/modules/admin/service/SysAgencyFeeApprovalService.java
  12. 0 4
      src/main/java/com/ydtech/modules/admin/service/SysAgencyLeaderService.java
  13. 2 0
      src/main/java/com/ydtech/modules/admin/service/SysDeptService.java
  14. 3 1
      src/main/java/com/ydtech/modules/admin/service/SysPartnerService.java
  15. 63 39
      src/main/java/com/ydtech/modules/admin/service/impl/SysAgencyFeeApprovalServiceImpl.java
  16. 159 50
      src/main/java/com/ydtech/modules/admin/service/impl/SysAgencyLeaderServiceImpl.java
  17. 58 0
      src/main/java/com/ydtech/modules/admin/service/impl/SysDeptServiceImpl.java
  18. 132 15
      src/main/java/com/ydtech/modules/admin/service/impl/SysPartnerServiceImpl.java
  19. 6 7
      src/main/java/com/ydtech/modules/admin/service/impl/UserReportServiceImpl.java
  20. 1 0
      src/main/java/com/ydtech/modules/esm/dao/EsmUserReferrerMapper.java
  21. 3 1
      src/main/java/com/ydtech/modules/fnc/dao/InsPlyIncomeMapper.java
  22. 75 43
      src/main/java/com/ydtech/modules/fnc/service/impl/InsPlyIncomeServiceImpl.java
  23. 1 1
      src/main/java/com/ydtech/modules/ins/model/vo/res/BxSettlementFeesNorExcel.java
  24. 3 0
      src/main/resources/mapper/modules/admin/SysAgencyFeeApprovalMapper.xml
  25. 4 4
      src/main/resources/mapper/modules/admin/SysUserMapper.xml
  26. 18 0
      src/main/resources/mapper/modules/esm/EsmUserReferrerMapper.xml
  27. 269 166
      src/main/resources/mapper/modules/fnc/InsPlyIncomeMapper.xml
  28. 1 1
      src/main/resources/mapper/modules/order/InsAreaCompanyMapper.xml

+ 1 - 0
src/main/java/com/ydtech/components/TokenInterceptor.java

@@ -28,6 +28,7 @@ public class TokenInterceptor {
         notMatchList.add("/captchaById"); // 验证码通过ID
         notMatchList.add("/login2");//登录2  配合验证码ID的校验
         notMatchList.add("/aapLogin");//合伙人和机构负责人登录APP接口
+        notMatchList.add("/loginAPPByPhone");//合伙人和机构负责人登录APP接口
 
         notMatchList.add("/sendMsg");
         notMatchList.add("/loginByPhone");

+ 8 - 8
src/main/java/com/ydtech/modules/admin/controller/SysAgencyFeeApprovalController.java

@@ -8,6 +8,7 @@ import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalAddDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalEditDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalPageDto;
+import com.ydtech.modules.admin.model.vo.SysAgencyFeeApprovalRecordVo;
 import com.ydtech.modules.admin.service.SysAgencyFeeApprovalService;
 import com.ydtech.modules.base.controller.BaseController;
 import com.ydtech.modules.order.entity.BasePageResult;
@@ -104,14 +105,7 @@ public class SysAgencyFeeApprovalController extends BaseController {
         return HttpResult.ok(this.sysAgencyFeeApprovalService.queryOperate(id));
     }
 
-    /**
-     * 线下转账,线上确认提现
-     */
-    @ApiOperation(value = "线下转账,线上确认提现")
-    @PostMapping("/confirmAccounts")
-    public HttpResult confirmAccounts(@RequestBody SysAgencyFeeApprovalEditDto sysAgencyFeeApprovalEditDto) {
-        return HttpResult.ok(this.sysAgencyFeeApprovalService.confirmAccounts(sysAgencyFeeApprovalEditDto));
-    }
+
 
     @ApiOperation(value = "当前用户的提现记录")
     @PostMapping("/queryOperateInfo")
@@ -119,6 +113,12 @@ public class SysAgencyFeeApprovalController extends BaseController {
         return HttpResult.ok(this.sysAgencyFeeApprovalService.queryOperateInfo(sysAgencyFeeApprovalDto));
     }
 
+    @ApiOperation(value = "提现记录详情")
+    @PostMapping("/operateInfo/{id}")
+    public HttpResult<SysAgencyFeeApprovalRecordVo> operateInfo(@PathVariable("id") Integer id) {
+        return HttpResult.ok(this.sysAgencyFeeApprovalService.operateInfo(id));
+    }
+
 
 }
 

+ 13 - 2
src/main/java/com/ydtech/modules/admin/controller/SysDeptController.java

@@ -173,16 +173,27 @@ public class SysDeptController extends BaseController {
     }
 
     /**
-     * 合伙人、工作室管理机构树
+     * 工作室管理机构树
      * @return
      */
-    @ApiOperation(value = "合伙人、工作室管理机构树")
+    @ApiOperation(value = "工作室管理机构树")
     @GetMapping(value = "/getSysDeptTree")
     public HttpResult<List<SysDeptTreeVo>> getSysDeptTree() {
 
         return HttpResult.ok(sysDeptService.getSysDeptTree());
     }
 
+    /**
+     * 合伙人管理机构树
+     * @return
+     */
+    @ApiOperation(value = "合伙人管理机构树")
+    @GetMapping(value = "/getPartnerDeptTree")
+    public HttpResult<List<SysDeptTreeVo>> getPartnerDeptTree() {
+
+        return HttpResult.ok(sysDeptService.getPartnerDeptTree());
+    }
+
 
 
 }

+ 43 - 0
src/main/java/com/ydtech/modules/admin/controller/SysLoginController.java

@@ -323,6 +323,49 @@ public class SysLoginController {
 
     }
 
+    /**
+     * 合伙人APP手机验证码登录
+     *
+     * @param phoneLoginVo 手机号登录实体
+     * @return token
+     */
+    @PostMapping("/loginAPPByPhone")
+    @ApiOperation(value = "合伙人APP手机验证码登录")
+    public HttpResult<AAPLoginVo> loginAPPByPhone(@RequestBody PhoneLoginVo phoneLoginVo) {
+        AAPLoginVo aapLoginVo = new AAPLoginVo();
+        // 用户信息
+        String phone = phoneLoginVo.getPhone();
+        String phoneMsg = phoneLoginVo.getPhoneMsg();
+        SysUser user = sysUserService.findByPhone(phone);
+        //验证用户
+        SysUser.verifyUser(user);
+        //校验登录用户是否为合伙人或者是机构负责人
+        boolean a = sysPartnerService.checkPartner(user.getId());
+        boolean b = sysAgencyLeaderService.checkUserId(user.getId());
+        if (a ) {
+            //类型:1.合伙人;2机构负责人
+            aapLoginVo.setType(1);
+        }else if (b) {
+            aapLoginVo.setType(2);
+        }else {
+            throw  new SystemException("该用户无权限登录AAP,只能合伙人或者机构负责人才能登录!");
+
+        }
+        String msg = redisTemplate.opsForValue().get(PHONE_VERIFICATION_CODE_KEY + phone);
+        if (msg == null || msg.isEmpty()) {
+            return HttpResult.error("验证码已失效");
+        }
+
+        if (!phoneMsg.equals(msg)) {
+            return HttpResult.error("短信验证码不正确");
+        }
+        // 获取这个人的token
+        String token = StpUtil.createLoginSession(user.getId());
+        StpUtil.getSessionByLoginId(user.getId()).set(SaSession.USER, user);
+        aapLoginVo.setToken(token);
+        return HttpResult.ok("登录成功", aapLoginVo);
+    }
+
 
     /**
      * 手机验证码登录

+ 10 - 1
src/main/java/com/ydtech/modules/admin/controller/SysPartnerController.java

@@ -80,6 +80,15 @@ public class SysPartnerController extends BaseController {
         }
         return HttpResult.error("添加失败");
     }
+    @PostMapping("/edit")
+    @ApiOperation(value = "编辑合伙人")
+    public HttpResult edit(@RequestBody SysPartnerDto sysPartnerDto) {
+        boolean insert = this.sysPartnerService.edit(sysPartnerDto);
+        if (insert) {
+            return HttpResult.ok("编辑成功");
+        }
+        return HttpResult.error("编辑失败");
+    }
 
     /**
      * 判断当前登陆人是否合伙人
@@ -99,7 +108,7 @@ public class SysPartnerController extends BaseController {
      */
     @GetMapping("/deleteById/{id}")
     @ApiOperation(value = "删除合伙人")
-    public HttpResult deleteById(@PathVariable("id") Integer id) {
+    public HttpResult deleteById(@PathVariable("id") String id) {
         return HttpResult.ok("success", this.sysPartnerService.deleteById(id));
     }
 

+ 1 - 0
src/main/java/com/ydtech/modules/admin/dao/SysAgencyFeeApprovalMapper.java

@@ -15,5 +15,6 @@ import org.apache.ibatis.annotations.Mapper;
 public interface SysAgencyFeeApprovalMapper extends BaseMapper<SysAgencyFeeApproval> {
 
 
+    SysAgencyFeeApproval queryById(Integer id);
 }
 

+ 10 - 0
src/main/java/com/ydtech/modules/admin/model/StatusInfo.java

@@ -0,0 +1,10 @@
+package com.ydtech.modules.admin.model;
+
+import lombok.Data;
+
+@Data
+public class StatusInfo {
+
+    private String processingStatusName;
+    private String processingDate;
+}

+ 3 - 0
src/main/java/com/ydtech/modules/admin/model/report/profitAnalysis/ProfitAnalysisDto.java

@@ -44,6 +44,9 @@ public class ProfitAnalysisDto {
     @ApiModelProperty("变动成本")
     private BigDecimal variableCost;
 
+    @ApiModelProperty("应付")
+    private BigDecimal meet;
+
 
     @ApiModelProperty("经营利润")
     @TableField(value="operating_profit")

+ 75 - 0
src/main/java/com/ydtech/modules/admin/model/vo/SysAgencyFeeApprovalRecordVo.java

@@ -0,0 +1,75 @@
+package com.ydtech.modules.admin.model.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ydtech.modules.admin.model.StatusInfo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Data
+@ApiModel(value = "APP提现详情")
+public class SysAgencyFeeApprovalRecordVo {
+
+    /**
+     * 自增主键
+     */
+    @TableId(value = "id", type= IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 银行卡号
+     */
+    @TableField(value = "bank_number")
+    private String bankNumber;
+
+    /**
+     * 开户行
+     */
+    @TableField(value = "bank_account")
+    private String bankAccount;
+
+
+    @ApiModelProperty(value = "提现编号")
+    private String number;
+
+    /**
+     * 提现金额
+     */
+    @ApiModelProperty(value = "可提现抽成费用")
+    private BigDecimal cashFee;
+
+    /**
+     * 审核状态0未审核 1审核通过 2审核驳回
+     */
+    @ApiModelProperty(value = "审核状态0未审核 1审核通过 2审核驳回")
+    private List<StatusInfo> statusList;
+
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
+    private Date createTime;
+
+    @ApiModelProperty(value = "审批通过时间")
+    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
+    private Date auditTime;
+
+    /**
+     * 审批意见
+     */
+    @ApiModelProperty(value = "审批意见")
+    private String remark;
+
+
+
+}

+ 3 - 0
src/main/java/com/ydtech/modules/admin/model/vo/SysDeptTreeVo.java

@@ -41,6 +41,9 @@ public class SysDeptTreeVo {
     @TableField(exist = false)
     private Integer deptCount;
 
+    @ApiModelProperty(value = "子公司C,门店M,部门D")
+    private String deptType;
+
 
 
 }

+ 3 - 2
src/main/java/com/ydtech/modules/admin/service/SysAgencyFeeApprovalService.java

@@ -9,6 +9,7 @@ import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalAddDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalEditDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalPageDto;
+import com.ydtech.modules.admin.model.vo.SysAgencyFeeApprovalRecordVo;
 import com.ydtech.modules.order.entity.BasePageResult;
 
 import java.util.List;
@@ -30,7 +31,7 @@ public interface SysAgencyFeeApprovalService extends IService<SysAgencyFeeApprov
 
     List<SysAgencyFeeApprovalRecord> queryOperate(Integer id);
 
-    boolean confirmAccounts(SysAgencyFeeApprovalEditDto sysAgencyFeeApprovalEditDto);
-
     List<SysAgencyFeeApproval> queryOperateInfo(SysAgencyFeeApprovalDto sysAgencyFeeApprovalDto);
+
+    SysAgencyFeeApprovalRecordVo operateInfo(Integer id);
 }

+ 0 - 4
src/main/java/com/ydtech/modules/admin/service/SysAgencyLeaderService.java

@@ -27,10 +27,6 @@ public interface SysAgencyLeaderService extends IService<SysAgencyLeader> {
      */
     boolean insert(SysAgencyLeaderDto sysAgencyLeaderDto);
 
-//
-//    List<SysDept> getDeptInfo();
-//
-//    List<SysUser> getUserInfo();
 
     boolean edit(SysAgencyLeaderDto sysAgencyLeaderDto);
 

+ 2 - 0
src/main/java/com/ydtech/modules/admin/service/SysDeptService.java

@@ -115,6 +115,8 @@ public interface SysDeptService extends IService<SysDept> {
 
     List<SysDeptTreeVo> getSysDeptTree();
 
+    List<SysDeptTreeVo> getPartnerDeptTree();
+
 }
 
 

+ 3 - 1
src/main/java/com/ydtech/modules/admin/service/SysPartnerService.java

@@ -33,9 +33,11 @@ public interface SysPartnerService extends IService<SysPartner> {
     boolean checkPartner(String userId);
 
 
-    boolean deleteById(Integer id);
+    boolean deleteById(String id);
 
     BasePageResult<AgencyExtractFeeVo> queryPartnerByPage(SysPartnerPageDto sysPartnerPageDto);
 
     BasePageResult<SysPartnerAPPPageVo> SysPartnerAPPPage(SysPartnerAPPPageDto sysPartnerAPPPageDto);
+
+    boolean edit(SysPartnerDto sysPartnerDto);
 }

+ 63 - 39
src/main/java/com/ydtech/modules/admin/service/impl/SysAgencyFeeApprovalServiceImpl.java

@@ -5,28 +5,22 @@ import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ydtech.aop.exception.DescribeException;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.admin.dao.SysAgencyFeeApprovalMapper;
 import com.ydtech.modules.admin.dao.SysAgencyFeeApprovalRecordMapper;
 import com.ydtech.modules.admin.dao.SysDeptMapper;
-import com.ydtech.modules.admin.model.SysAgencyFeeApproval;
-import com.ydtech.modules.admin.model.SysAgencyFeeApprovalRecord;
-import com.ydtech.modules.admin.model.SysDept;
-import com.ydtech.modules.admin.model.SysUser;
+import com.ydtech.modules.admin.model.*;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalAddDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalEditDto;
 import com.ydtech.modules.admin.model.dto.SysAgencyFeeApprovalPageDto;
 import com.ydtech.modules.admin.model.vo.AgencyExtractFee;
+import com.ydtech.modules.admin.model.vo.SysAgencyFeeApprovalRecordVo;
 import com.ydtech.modules.admin.service.SysAgencyFeeApprovalService;
 import com.ydtech.modules.admin.service.SysAgencyLeaderService;
-import com.ydtech.modules.admin.service.SysDeptService;
-import com.ydtech.modules.admin.service.SysUserService;
 import com.ydtech.modules.base.controller.BaseController;
 import com.ydtech.modules.order.entity.BasePageResult;
-import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.utils.StringUtils;
 import com.ydtech.utils.idgen.IdGenerate;
 import org.springframework.stereotype.Service;
@@ -34,8 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * 机构保费抽成审批表(SysAgencyFeeApproval)表服务实现类
@@ -93,15 +87,16 @@ public class SysAgencyFeeApprovalServiceImpl extends ServiceImpl<SysAgencyFeeApp
         //总保费抽成费用
         sysAgencyFeeApproval.setExtractFee(agencyExtractFee.getExtractFee());
         //已提现抽成费用
-        sysAgencyFeeApproval.setHistoryFee(agencyExtractFee.getHistoryFee());
+//        sysAgencyFeeApproval.setHistoryFee(null);
         //可提现抽成费用
         sysAgencyFeeApproval.setCashFee(actualFee);
         sysAgencyFeeApproval.setStartTime(agencyExtractFee.getStartTime());
         sysAgencyFeeApproval.setProportional(agencyExtractFee.getProportional());
         sysAgencyFeeApproval.setCreateBy(user.getName());
         sysAgencyFeeApproval.setCreateTime(new Date());
+        sysAgencyFeeApproval.setStatus("0");
         //提交审核信息
-        save(sysAgencyFeeApproval);
+        this.save(sysAgencyFeeApproval);
         //保存添加记录
         SysAgencyFeeApprovalRecord sysAgencyFeeApprovalRecord = BeanUtil.copyProperties(sysAgencyFeeApproval, SysAgencyFeeApprovalRecord.class);
         sysAgencyFeeApprovalRecord.setApprovalId(sysAgencyFeeApproval.getId());
@@ -116,14 +111,22 @@ public class SysAgencyFeeApprovalServiceImpl extends ServiceImpl<SysAgencyFeeApp
     @Override
     @Transactional(rollbackFor = Exception.class)
     public HttpResult edit(SysAgencyFeeApprovalEditDto sysAgencyFeeApprovalEditDto) {
-        SysAgencyFeeApproval sysAgencyFeeApproval = sysAgencyFeeApprovalMapper.selectById(sysAgencyFeeApprovalEditDto.getId());
-        String status = sysAgencyFeeApproval.getStatus();
-        if (status.equals("1") || status.equals("2")) {
-            throw new DescribeException("已审批,不可重复操作");
+        SysAgencyFeeApproval sysAgencyFeeApproval1 = sysAgencyFeeApprovalMapper.queryById(sysAgencyFeeApprovalEditDto.getId());
+        if (sysAgencyFeeApproval1.getStatus().equals("1") && sysAgencyFeeApproval1.getStatus().equals("2")) {
+            throw new SystemException("已审批,不允许重复操作");
         }
+        SysAgencyFeeApproval sysAgencyFeeApproval =BeanUtil.copyProperties(sysAgencyFeeApproval1,SysAgencyFeeApproval.class);
+        String status = sysAgencyFeeApprovalEditDto.getStatus();
+        if (StringUtils.isNotEmpty(status) && status.equals("1")) {
+            //审批通过
+            sysAgencyFeeApproval.setHistoryFee(sysAgencyFeeApproval.getCashFee());
+            sysAgencyFeeApproval.setPicture(sysAgencyFeeApprovalEditDto.getPicture());
+            sysAgencyFeeApproval.setExtractFee(sysAgencyFeeApproval1.getExtractFee().subtract(sysAgencyFeeApproval.getCashFee()));
+        }
+        sysAgencyFeeApproval.setId(sysAgencyFeeApprovalEditDto.getId());
         sysAgencyFeeApproval.setAuditTime(new Date());
         sysAgencyFeeApproval.setRemark(sysAgencyFeeApprovalEditDto.getRemark());
-        sysAgencyFeeApproval.setStatus(sysAgencyFeeApprovalEditDto.getStatus());
+        sysAgencyFeeApproval.setStatus(status);
         sysAgencyFeeApproval.setAuditUser(BaseController.getUser().getName());
         //保存审批信息
         sysAgencyFeeApprovalMapper.updateById(sysAgencyFeeApproval);
@@ -158,40 +161,61 @@ public class SysAgencyFeeApprovalServiceImpl extends ServiceImpl<SysAgencyFeeApp
     @Override
     public List<SysAgencyFeeApprovalRecord> queryOperate(Integer id) {
         return sysAgencyFeeApprovalRecordMapper.selectList(new LambdaQueryWrapper<SysAgencyFeeApprovalRecord>()
-                .eq(SysAgencyFeeApprovalRecord::getApprovalId, id));
+                .eq(SysAgencyFeeApprovalRecord::getApprovalId, id).orderByDesc(SysAgencyFeeApprovalRecord::getId));
     }
 
-    @Override
-    public boolean confirmAccounts(SysAgencyFeeApprovalEditDto sysAgencyFeeApprovalEditDto) {
-        SysAgencyFeeApproval sysAgencyFeeApproval = sysAgencyFeeApprovalMapper.selectById(sysAgencyFeeApprovalEditDto.getId());
-        if (sysAgencyFeeApproval.getStatus().equals("0") || sysAgencyFeeApproval.getStatus().equals("2")) {
-            throw new DescribeException("未审批或审批未通,不可确认转账");
-        }
-        sysAgencyFeeApproval.setHistoryFee(sysAgencyFeeApproval.getCashFee());
-        sysAgencyFeeApproval.setPicture(sysAgencyFeeApprovalEditDto.getPicture());
-        sysAgencyFeeApprovalMapper.updateById(sysAgencyFeeApproval);
-        //保存确认转账记录
-        SysAgencyFeeApprovalRecord sysAgencyFeeApprovalRecord = BeanUtil.copyProperties(sysAgencyFeeApproval, SysAgencyFeeApprovalRecord.class);
-        sysAgencyFeeApprovalRecord.setApprovalId(sysAgencyFeeApproval.getId());
-        sysAgencyFeeApprovalRecord.setId(null);
-        sysAgencyFeeApprovalRecord.setCreateTime(new Date());
-        sysAgencyFeeApprovalRecord.setCreateBy(BaseController.getUser().getName());
-
-        return sysAgencyFeeApprovalRecordMapper.insert(sysAgencyFeeApprovalRecord)>0;
-    }
 
     @Override
     public List<SysAgencyFeeApproval> queryOperateInfo(SysAgencyFeeApprovalDto sysAgencyFeeApprovalDto) {
 
         List<SysAgencyFeeApproval> feeApprovalList = sysAgencyFeeApprovalMapper.selectList(new LambdaQueryWrapper<SysAgencyFeeApproval>()
-                .eq(SysAgencyFeeApproval::getUserId, BaseController.getUserId()).eq(SysAgencyFeeApproval::getStatus, 1)
+                .eq(SysAgencyFeeApproval::getUserId, BaseController.getUserId())
                 .ge(StringUtils.isNotEmpty(sysAgencyFeeApprovalDto.getBeginTime()), SysAgencyFeeApproval::getAuditTime,sysAgencyFeeApprovalDto.getBeginTime())
-                .le(StringUtils.isNotEmpty(sysAgencyFeeApprovalDto.getEndTime()),SysAgencyFeeApproval::getAuditTime,sysAgencyFeeApprovalDto.getEndTime()));
+                .le(StringUtils.isNotEmpty(sysAgencyFeeApprovalDto.getEndTime()),SysAgencyFeeApproval::getAuditTime,sysAgencyFeeApprovalDto.getEndTime())
+                .orderByDesc(SysAgencyFeeApproval::getId));
 
         return feeApprovalList;
     }
 
-
+    @Override
+    public SysAgencyFeeApprovalRecordVo operateInfo(Integer id) {
+        SysAgencyFeeApproval sysAgencyFeeApproval = sysAgencyFeeApprovalMapper.selectOne(new LambdaQueryWrapper<SysAgencyFeeApproval>().eq(SysAgencyFeeApproval::getId, id));
+        SysAgencyFeeApprovalRecordVo sysAgencyFeeApprovalRecordVo = new SysAgencyFeeApprovalRecordVo();
+        sysAgencyFeeApprovalRecordVo.setId(sysAgencyFeeApproval.getId());
+        sysAgencyFeeApprovalRecordVo.setCashFee(sysAgencyFeeApproval.getCashFee());
+        sysAgencyFeeApprovalRecordVo.setCreateTime(sysAgencyFeeApproval.getCreateTime());
+        sysAgencyFeeApprovalRecordVo.setNumber(sysAgencyFeeApproval.getNumber());
+        sysAgencyFeeApprovalRecordVo.setRemark(sysAgencyFeeApproval.getRemark());
+        sysAgencyFeeApprovalRecordVo.setBankAccount(sysAgencyFeeApproval.getBankAccount());
+        sysAgencyFeeApprovalRecordVo.setBankNumber(sysAgencyFeeApproval.getBankNumber());
+
+        List<SysAgencyFeeApprovalRecord> sysAgencyFeeApprovalRecords = sysAgencyFeeApprovalRecordMapper.selectList(new LambdaQueryWrapper<SysAgencyFeeApprovalRecord>()
+                .eq(SysAgencyFeeApprovalRecord::getApprovalId, id).orderByAsc(SysAgencyFeeApprovalRecord::getId));
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        List<StatusInfo> list = new ArrayList<>();
+        if (sysAgencyFeeApprovalRecords.size()>0) {
+            for (SysAgencyFeeApprovalRecord sysAgencyFeeApprovalRecord : sysAgencyFeeApprovalRecords) {
+                StatusInfo statusInfo = new StatusInfo();
+                String format;
+                Date auditTime = sysAgencyFeeApprovalRecord.getAuditTime();
+                if (auditTime != null) {
+                    format = sdf.format(auditTime);
+                }else {
+                    Date createTime = sysAgencyFeeApprovalRecord.getCreateTime();
+                    format = sdf.format(createTime);
+                }
+                statusInfo.setProcessingStatusName(sysAgencyFeeApprovalRecord.getStatus());
+                statusInfo.setProcessingDate(format);
+                list.add(statusInfo);
+                if (sysAgencyFeeApprovalRecord.getStatus().equals("1")) {
+                    sysAgencyFeeApprovalRecordVo.setAuditTime(sysAgencyFeeApprovalRecord.getAuditTime());
+                }
+
+            }
+        }
+        sysAgencyFeeApprovalRecordVo.setStatusList(list);
+        return sysAgencyFeeApprovalRecordVo;
+    }
 
 
 }

+ 159 - 50
src/main/java/com/ydtech/modules/admin/service/impl/SysAgencyLeaderServiceImpl.java

@@ -77,7 +77,8 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
     @Transactional(rollbackFor = Exception.class)
     public boolean insert(SysAgencyLeaderDto sysAgencyLeaderDto) {
         //校验一个用户只能是一个机构的负责人,每个机构只有一个负责人
-        List<SysAgencyLeader> sysAgencyLeaders = sysAgencyLeaderMapper.selectList(new QueryWrapper<SysAgencyLeader>().lambda().eq(SysAgencyLeader::getDelFlag, 1));
+        List<SysAgencyLeader> sysAgencyLeaders = sysAgencyLeaderMapper.selectList(new QueryWrapper<SysAgencyLeader>().lambda()
+                .eq(SysAgencyLeader::getDelFlag, 1));
         if (sysAgencyLeaders.size() > 0) {
             //校验用户是否已经机构负责人
             List<String> userIdList = sysAgencyLeaders.stream().map(SysAgencyLeader::getUserId).collect(Collectors.toList());
@@ -99,37 +100,40 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
             }
         }
 
+
         SysAgencyLeader sysAgencyLeader = BeanUtil.copyProperties(sysAgencyLeaderDto, SysAgencyLeader.class);
         sysAgencyLeader.setCreateTime(new Date());
         SysUser user = BaseController.getUser();
         sysAgencyLeader.setCreateBy(user.getId());
-        sysAgencyLeaderMapper.insert(sysAgencyLeader);
-        //sysRelationPerson1为空是无上级
-        SysRelationPerson sysRelationPerson = new SysRelationPerson();
-        sysRelationPerson.setAgencyLeaderId(sysAgencyLeader.getUserId());
-        sysRelationPerson.setCreateBy(user.getId());
-        sysRelationPerson.setCreateTime(new Date());
-        sysRelationPerson.setSuggestId(sysAgencyLeaderDto.getSuggestId());
-        sysRelationPerson.setSource(0);
-        sysRelationPerson.setType(1);
-        boolean b = sysRelationPersonMapper.insert(sysRelationPerson) > 0;
-        //查询推荐人是否有上级 :满足合伙人有多层关系
-        List<SysRelationPerson> sysRelationPersonList = sysRelationPersonMapper.selectList(new LambdaQueryWrapper<SysRelationPerson>()
-                .eq(SysRelationPerson::getAgencyLeaderId, sysAgencyLeaderDto.getSuggestId())
-                .eq(SysRelationPerson::getType, 0));
-
-        if (sysRelationPersonList.size() > 0) {
-            for (SysRelationPerson sysRelation : sysRelationPersonList) {
-                SysRelationPerson sysRelationPerson1 = new SysRelationPerson();
-                sysRelationPerson1.setAgencyLeaderId(sysAgencyLeader.getUserId());
-                sysRelationPerson1.setCreateBy(user.getId());
-                sysRelationPerson1.setCreateTime(new Date());
-                sysRelationPerson1.setSuggestId(sysRelation.getSuggestId());
-                sysRelationPerson1.setSource(1);
-                sysRelationPerson1.setType(1);
-                sysRelationPersonMapper.insert(sysRelationPerson1);
-            }
+        boolean b = sysAgencyLeaderMapper.insert(sysAgencyLeader) > 0;
+        if (!StringUtils.isNullOrEmpty(sysAgencyLeaderDto.getSuggestId())) {
+            //sysRelationPerson1为空是无上级
+            SysRelationPerson sysRelationPerson = new SysRelationPerson();
+            sysRelationPerson.setAgencyLeaderId(sysAgencyLeader.getUserId());
+            sysRelationPerson.setCreateBy(user.getId());
+            sysRelationPerson.setCreateTime(new Date());
+            sysRelationPerson.setSuggestId(sysAgencyLeaderDto.getSuggestId());
+            sysRelationPerson.setSource(0);
+            sysRelationPerson.setType(1);
+            b = sysRelationPersonMapper.insert(sysRelationPerson) > 0;
+            //查询推荐人是否有上级 :满足合伙人有多层关系
+            List<SysRelationPerson> sysRelationPersonList = sysRelationPersonMapper.selectList(new LambdaQueryWrapper<SysRelationPerson>()
+                    .eq(SysRelationPerson::getAgencyLeaderId, sysAgencyLeaderDto.getSuggestId())
+                    .eq(SysRelationPerson::getType, 0));
+
+            if (sysRelationPersonList.size() > 0) {
+                for (SysRelationPerson sysRelation : sysRelationPersonList) {
+                    SysRelationPerson sysRelationPerson1 = new SysRelationPerson();
+                    sysRelationPerson1.setAgencyLeaderId(sysAgencyLeader.getUserId());
+                    sysRelationPerson1.setCreateBy(user.getId());
+                    sysRelationPerson1.setCreateTime(new Date());
+                    sysRelationPerson1.setSuggestId(sysRelation.getSuggestId());
+                    sysRelationPerson1.setSource(1);
+                    sysRelationPerson1.setType(1);
+                    b =sysRelationPersonMapper.insert(sysRelationPerson1)>0;
+                }
 
+            }
         }
         return b;
     }
@@ -143,25 +147,27 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
             sysUserList = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
                     .eq(SysUser::getStatus, 1)
                     .likeRight(SysUser::getId, sysDept.getParentId())
-                    .notLike(SysUser::getId, "M"));
+                    .notLike(SysUser::getId, "M")
+                    .orderByDesc(SysUser::getCreateTime));
 
         } else {
             sysUserList = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
                     .eq(SysUser::getStatus, 1)
                     .likeRight(SysUser::getId, id)
-                    .notLike(SysUser::getId, "M"));
+                    .notLike(SysUser::getId, "M")
+                    .orderByDesc(SysUser::getCreateTime));
 
 
         }
 
         //工作室管理员: 已是管理员不能再成为管理员,已是合伙人的也不能设置为管理员
-        List<SysPartner> sysPartnerList = sysPartnerMapper.selectList(new LambdaQueryWrapper<SysPartner>().eq(SysPartner::getCreateTime, 1));
-        if (sysPartnerList == null) {
+        List<SysPartner> sysPartnerList = sysPartnerMapper.selectList(new LambdaQueryWrapper<SysPartner>().eq(SysPartner::getDelFlag, 1));
+        if (sysPartnerList.size()>0) {
             List<String> stringList = sysPartnerList.stream().map(SysPartner::getUserId).collect(Collectors.toList());
             sysUserList = sysUserList.stream().filter(SysUser -> !stringList.contains(SysUser.getId())).collect(Collectors.toList());
         }
         List<SysAgencyLeader> sysAgencyLeaders = sysAgencyLeaderMapper.selectList(new LambdaQueryWrapper<SysAgencyLeader>().eq(SysAgencyLeader::getDelFlag, 1));
-        if (sysAgencyLeaders == null) {
+        if (sysAgencyLeaders.size()>0) {
             List<String> stringList = sysAgencyLeaders.stream().map(SysAgencyLeader::getUserId).collect(Collectors.toList());
             sysUserList = sysUserList.stream().filter(SysUser -> !stringList.contains(SysUser.getId())).collect(Collectors.toList());
         }
@@ -175,28 +181,115 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
     public boolean edit(SysAgencyLeaderDto sysAgencyLeaderDto) {
         //不修改负责人userId传null
         String userId = sysAgencyLeaderDto.getUserId();
+        String loginId = BaseController.getUserId();
+        boolean b = false;
         SysAgencyLeader sysAgencyLeader1 = sysAgencyLeaderMapper.selectById(sysAgencyLeaderDto.getId());
-        if (StringUtils.isNotEmpty(userId) && !sysAgencyLeader1.getUserId().equals(userId)) {
+        if (!sysAgencyLeader1.getUserId().equals(userId)) {
+            //修改管理员
             List<SysAgencyLeader> sysAgencyLeaders = sysAgencyLeaderMapper.selectList(new QueryWrapper<SysAgencyLeader>().lambda().eq(SysAgencyLeader::getDelFlag, 1));
             List<String> userIdList = sysAgencyLeaders.stream().map(SysAgencyLeader::getUserId).collect(Collectors.toList());
             if (userIdList.contains(sysAgencyLeaderDto.getUserId())) {
                 throw new DescribeException(sysAgencyLeaderDto.getUserName() + "已是机构负责人,不可重复配置");
             }
+            List<SysPartner> sysPartners = sysPartnerMapper.selectList(new LambdaQueryWrapper<SysPartner>().eq(SysPartner::getDelFlag, 1));
+            if (sysPartners.size() > 0) {
+                List<String> list = sysPartners.stream().map(SysPartner::getUserId).collect(Collectors.toList());
+                if (list.contains(sysAgencyLeaderDto.getUserId())) {
+                    throw new DescribeException(sysAgencyLeaderDto.getUserName() + "已是合伙人,不可设置为机构负责人");
+                }
+            }
+
             //修改负责人时解除合伙人或者推荐人与机构负责人的关系
             List<SysRelationPerson> sysRelationPeople = sysRelationPersonMapper.selectList(new LambdaQueryWrapper<SysRelationPerson>()
                     .eq(SysRelationPerson::getAgencyLeaderId, sysAgencyLeader1.getUserId())
                     .eq(SysRelationPerson::getDelFlag, 1)
                     .eq(SysRelationPerson::getType, 1));
             if (sysRelationPeople.size() > 0) {
-                throw new DescribeException(sysAgencyLeaderDto.getUserName() + "有推荐关系,不允许修改");
+                throw new DescribeException(sysAgencyLeader1.getUserName() + "有推荐关系,不允许修改");
+            }
+
+            SysAgencyLeader sysAgencyLeader = BeanUtil.copyProperties(sysAgencyLeaderDto, SysAgencyLeader.class);
+            sysAgencyLeader.setUpdateTime(new Date());
+            sysAgencyLeader.setUpdateBy(loginId);
+            sysAgencyLeaderMapper.updateById(sysAgencyLeader);
+            if (!sysAgencyLeaderDto.getSuggestId().isEmpty()){
+                //sysRelationPerson1为空是无上级
+                SysRelationPerson sysRelationPerson = new SysRelationPerson();
+                sysRelationPerson.setAgencyLeaderId(sysAgencyLeader.getUserId());
+                sysRelationPerson.setCreateBy(loginId);
+                sysRelationPerson.setCreateTime(new Date());
+                sysRelationPerson.setSuggestId(sysAgencyLeaderDto.getSuggestId());
+                sysRelationPerson.setSource(0);
+                sysRelationPerson.setType(1);
+                b = sysRelationPersonMapper.insert(sysRelationPerson) > 0;
+                //查询推荐人是否有上级 :满足合伙人有多层关系
+                List<SysRelationPerson> sysRelationPersonList = sysRelationPersonMapper.selectList(new LambdaQueryWrapper<SysRelationPerson>()
+                        .eq(SysRelationPerson::getAgencyLeaderId, sysAgencyLeaderDto.getSuggestId())
+                        .eq(SysRelationPerson::getType, 0));
+
+                if (sysRelationPersonList.size() > 0) {
+                    for (SysRelationPerson sysRelation : sysRelationPersonList) {
+                        SysRelationPerson sysRelationPerson1 = new SysRelationPerson();
+                        sysRelationPerson1.setAgencyLeaderId(sysAgencyLeader.getUserId());
+                        sysRelationPerson1.setCreateBy(loginId);
+                        sysRelationPerson1.setCreateTime(new Date());
+                        sysRelationPerson1.setSuggestId(sysRelation.getSuggestId());
+                        sysRelationPerson1.setSource(1);
+                        sysRelationPerson1.setType(1);
+                        b = sysRelationPersonMapper.insert(sysRelationPerson1)>0;
+                    }
+
+                }
+            }
+
+
+        }else {
+            if (StringUtils.isNullOrEmpty(sysAgencyLeader1.getSuggestId()) && !sysAgencyLeaderDto.getSuggestId().isEmpty()) {
+                //之前推荐人为空。可以修改
+                SysAgencyLeader sysAgencyLeader = BeanUtil.copyProperties(sysAgencyLeaderDto, SysAgencyLeader.class);
+                sysAgencyLeader.setUpdateBy(loginId);
+                b = sysAgencyLeaderMapper.updateById(sysAgencyLeader)>0;
+
+                //sysRelationPerson1为空是无上级
+                SysRelationPerson sysRelationPerson = new SysRelationPerson();
+                sysRelationPerson.setAgencyLeaderId(sysAgencyLeader.getUserId());
+                sysRelationPerson.setCreateBy(loginId);
+                sysRelationPerson.setCreateTime(new Date());
+                sysRelationPerson.setSuggestId(sysAgencyLeaderDto.getSuggestId());
+                sysRelationPerson.setSource(0);
+                sysRelationPerson.setType(1);
+                b = sysRelationPersonMapper.insert(sysRelationPerson) > 0;
+                //查询推荐人是否有上级 :满足合伙人有多层关系
+                List<SysRelationPerson> sysRelationPersonList = sysRelationPersonMapper.selectList(new LambdaQueryWrapper<SysRelationPerson>()
+                        .eq(SysRelationPerson::getAgencyLeaderId, sysAgencyLeaderDto.getSuggestId())
+                        .eq(SysRelationPerson::getType, 0));
+
+                if (sysRelationPersonList.size() > 0) {
+                    for (SysRelationPerson sysRelation : sysRelationPersonList) {
+                        SysRelationPerson sysRelationPerson1 = new SysRelationPerson();
+                        sysRelationPerson1.setAgencyLeaderId(sysAgencyLeader.getUserId());
+                        sysRelationPerson1.setCreateBy(loginId);
+                        sysRelationPerson1.setCreateTime(new Date());
+                        sysRelationPerson1.setSuggestId(sysRelation.getSuggestId());
+                        sysRelationPerson1.setSource(1);
+                        sysRelationPerson1.setType(1);
+                        b = sysRelationPersonMapper.insert(sysRelationPerson1)>0;
+                    }
+
+                }
+
+            }else {
+
+                SysAgencyLeader sysAgencyLeader = new SysAgencyLeader();
+                sysAgencyLeader.setId(sysAgencyLeaderDto.getId());
+                sysAgencyLeader.setProportional(sysAgencyLeaderDto.getProportional());
+                sysAgencyLeader.setUpdateBy(loginId);
+                b = sysAgencyLeaderMapper.updateById(sysAgencyLeader)>0;
             }
 
         }
-        SysAgencyLeader sysAgencyLeader = BeanUtil.copyProperties(sysAgencyLeaderDto, SysAgencyLeader.class);
-        sysAgencyLeader.setUpdateTime(new Date());
-        SysUser user = BaseController.getUser();
-        sysAgencyLeader.setUpdateBy(user.getId());
-        return sysAgencyLeaderMapper.updateById(sysAgencyLeader) > 0;
+
+        return b;
     }
 
     @Override
@@ -208,7 +301,9 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
                 .eq(SysRelationPerson::getDelFlag, 1)
                 .eq(SysRelationPerson::getType, 1));
         if (sysRelationPeople.size() > 0) {
-            throw new DescribeException(sysAgencyLeader1.getUserName() + "有推荐人,不允许删除");
+            if (sysRelationPeople.get(0).getSuggestId() != null) {
+                throw new DescribeException(sysAgencyLeader1.getUserName() + "有推荐人,不允许删除");
+            }
         }
         SysAgencyLeader sysAgencyLeader = new SysAgencyLeader();
         sysAgencyLeader.setId(id);
@@ -231,7 +326,7 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
         LambdaQueryWrapper<SysAgencyLeader> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(SysAgencyLeader::getDelFlag, 1);
         wrapper.likeRight(!StringUtils.isNullOrEmpty(sysAgencyLeaderPageDto.getDeptId()), SysAgencyLeader::getDeptId, sysAgencyLeaderPageDto.getDeptId());
-        wrapper.orderByAsc(SysAgencyLeader::getId);
+        wrapper.orderByDesc(SysAgencyLeader::getId);
 
         Page<SysAgencyLeader> insOrdersPage = page(page, wrapper);
         List<SysAgencyLeader> records = insOrdersPage.getRecords();
@@ -283,7 +378,7 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
             BigDecimal historyFee = new BigDecimal("0.00");
             //合伙人信息
             SysPartner sysPartner = sysPartnerMapper.selectOne(new LambdaQueryWrapper<SysPartner>()
-                    .eq(SysPartner::getUserId, userId));
+                    .eq(SysPartner::getUserId, userId).eq(SysPartner::getDelFlag,1));
             //填充查询人的姓名和机构
             agencyExtractFee.setUserId(sysPartner.getUserId());
             agencyExtractFee.setUserName(sysPartner.getUserName());
@@ -371,7 +466,8 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
         //校验是否为机构负责人
         boolean b = this.checkUserId(userId);
         if (b) {
-            SysAgencyLeader sysAgencyLeaders = sysAgencyLeaderMapper.selectOne(new LambdaQueryWrapper<SysAgencyLeader>().eq(SysAgencyLeader::getUserId, userId).eq(SysAgencyLeader::getDelFlag, 1));
+            SysAgencyLeader sysAgencyLeaders = sysAgencyLeaderMapper.selectOne(new LambdaQueryWrapper<SysAgencyLeader>()
+                    .eq(SysAgencyLeader::getUserId, userId).eq(SysAgencyLeader::getDelFlag, 1));
             if (sysAgencyLeaders != null) {
                 //填充查询人的姓名和机构
                 agencyExtractFee.setUserId(sysAgencyLeaders.getUserId());
@@ -458,6 +554,7 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
         wrapper.like(StringUtils.isNotEmpty(sysAgencyLeaderPageDto.getUserId()), SysAgencyLeader::getUserId, sysAgencyLeaderPageDto.getUserId());
         wrapper.like(StringUtils.isNotEmpty(sysAgencyLeaderPageDto.getUserName()), SysAgencyLeader::getUserName, sysAgencyLeaderPageDto.getUserName());
         wrapper.eq(SysAgencyLeader::getDelFlag, 1);
+        wrapper.orderByDesc(SysAgencyLeader::getId);
 
         Page<SysAgencyLeader> insOrdersPage = page(page, wrapper);
         List<SysAgencyLeader> records = insOrdersPage.getRecords();
@@ -553,8 +650,10 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
 
         LambdaQueryWrapper<SysDept> wrapper = new LambdaQueryWrapper<>();
         wrapper.likeRight(SysDept::getId, sysAgencyLeaders.getDeptId())
-                .isNull(SysDept::getComlevel).eq(SysDept::getDelFlag, 0).eq(SysDept::getManagementSource, sysAgencyLeaders.getSource())
-                .like(StringUtils.isNotEmpty(teamInformationDto.getDeptName()), SysDept::getName, teamInformationDto.getDeptName());
+                .isNull(SysDept::getComlevel).eq(SysDept::getDelFlag, 0)
+                .eq(SysDept::getManagementSource, sysAgencyLeaders.getSource())
+                .like(StringUtils.isNotEmpty(teamInformationDto.getDeptName()), SysDept::getName, teamInformationDto.getDeptName())
+                .orderByDesc(SysDept::getCreateTime);
 
         Page<SysDept> insOrdersPage = sysDeptService.page(page, wrapper);
         List<SysDept> sysDeptList = insOrdersPage.getRecords();
@@ -658,6 +757,8 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
             LambdaQueryWrapper<SysAgencyLeader> wrapper = new LambdaQueryWrapper<>();
             wrapper.like(StringUtils.isNotEmpty(agencyTeamDto.getDeptName()), SysAgencyLeader::getDeptName, agencyTeamDto.getDeptName());
             wrapper.in(SysAgencyLeader::getUserId, ids);
+            wrapper.eq(SysAgencyLeader::getDelFlag, 1);
+            wrapper.orderByDesc(SysAgencyLeader::getId);
 
             Page<SysAgencyLeader> insOrdersPage = page(page, wrapper);
             List<SysAgencyLeader> leaderList = insOrdersPage.getRecords();
@@ -720,9 +821,14 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
                     }
                     agencyTeamVo.setDeptManNum(deptManNum);
                     agencyTeamVo.setSumpremium(bigDecimal);
-                    BigDecimal multiply = bigDecimal.multiply(new BigDecimal(sysAgencyLeader.getProportional())
-                            .divide(new BigDecimal("100"))).setScale(2, RoundingMode.DOWN);
-                    agencyTeamVo.setExtractFee(multiply);
+                    if (!bigDecimal.equals(new BigDecimal("0.00"))) {
+
+                        BigDecimal multiply = bigDecimal.multiply(new BigDecimal(sysAgencyLeader.getProportional())
+                                .divide(new BigDecimal("100"))).setScale(2, RoundingMode.DOWN);
+                        agencyTeamVo.setExtractFee(multiply);
+                    }else {
+                        agencyTeamVo.setExtractFee(new BigDecimal("0.00"));
+                    }
                     agencyTeamVoList.add(agencyTeamVo);
 
                 }
@@ -748,7 +854,8 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
             //获取机构负责人信息
             List<SysAgencyLeader> sysAgencyLeaders = sysAgencyLeaderMapper.selectList(new LambdaQueryWrapper<SysAgencyLeader>()
                     .in(SysAgencyLeader::getUserId, agencyLeaderIds)
-                    .eq(SysAgencyLeader::getDelFlag, 1));
+                    .eq(SysAgencyLeader::getDelFlag, 1)
+                    .orderByDesc(SysAgencyLeader::getId));
 
             return BeanUtil.copyToList(sysAgencyLeaders, SysAgencyLeaderVo.class);
         }
@@ -762,7 +869,9 @@ public class SysAgencyLeaderServiceImpl extends ServiceImpl<SysAgencyLeaderMappe
         List<TeamUserInfoVo> teamUserInfoVoList = new ArrayList<>();
         Page<SysUser> page = new Page<>(teamUserInfoDto.getPageNum(), teamUserInfoDto.getPageSize());
         LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
-        wrapper.likeRight(SysUser::getId, teamUserInfoDto.getDeptId()).eq(SysUser::getStatus, 1);
+        wrapper.likeRight(SysUser::getId, teamUserInfoDto.getDeptId());
+        wrapper.eq(SysUser::getStatus, 1);
+        wrapper.orderByDesc(SysUser::getCreateTime);
 
         Page<SysUser> insOrdersPage = sysUserService.page(page, wrapper);
         List<SysUser> sysUsers = insOrdersPage.getRecords();

+ 58 - 0
src/main/java/com/ydtech/modules/admin/service/impl/SysDeptServiceImpl.java

@@ -583,6 +583,64 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
         return sysDeptTreeVos;
     }
 
+    @Override
+    public List<SysDeptTreeVo> getPartnerDeptTree() {
+        SysDept sysDept = getById("9");
+        LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(SysDept::getDelFlag, 0);
+        lqw.likeRight(SysDept::getId, "9");
+        lqw.orderByAsc(SysDept::getOrderNum);
+        List<SysDept> sysDeptList = list(lqw);
+
+        List<SysDeptTreeVo> sysDeptTreeVos = BeanUtil.copyToList(sysDeptList, SysDeptTreeVo.class);
+
+        Map<String, List<SysDeptTreeVo>> map = sysDeptTreeVos.stream().sorted(Comparator.comparing(SysDeptTreeVo::getId))
+                .collect(Collectors.groupingBy(SysDeptTreeVo::getParentId));
+        sysDeptTreeVos.forEach(i -> {
+            i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>()));
+            i.setDeptCount(i.getChildren().size());
+        });
+        sysDeptTreeVos = map.get(sysDept.getParentId());
+        //合伙人机构树
+        for (SysDeptTreeVo deptTreeVo : sysDeptTreeVos) {//1
+            List<SysDeptTreeVo> children2 = deptTreeVo.getChildren();
+            for (SysDeptTreeVo children : children2) {//2
+                List<SysDeptTreeVo> children3 = children.getChildren();
+                if (children3.size()>0) {
+                    children3=children3.stream().filter(SysDeptTreeVo -> SysDeptTreeVo.getComlevel() != null).collect(Collectors.toList());
+                    children.setChildren(children3);
+                    for (SysDeptTreeVo child4 : children3) {//3
+                        List<SysDeptTreeVo> children4 = child4.getChildren();
+                        if (children4.size()>0) {
+                            children4=children4.stream().filter(SysDeptTreeVo -> SysDeptTreeVo.getComlevel() != null).collect(Collectors.toList());
+                            child4.setChildren(children4);
+                            for (SysDeptTreeVo child : children4) {//4
+                                List<SysDeptTreeVo> children5 = child.getChildren();
+                                children5 = children5.stream().filter(SysDeptTreeVo ->SysDeptTreeVo.getComlevel() != null).collect(Collectors.toList());
+                                child.setChildren(children5);
+                                if (children5.size()>0) {
+                                    for (SysDeptTreeVo treeVo : children5) {
+                                        List<SysDeptTreeVo> childrenEnd = treeVo.getChildren();
+                                        if (childrenEnd.size()>0) {
+                                            childrenEnd=childrenEnd.stream().filter(SysDeptTreeVo ->SysDeptTreeVo.getComlevel() == null).collect(Collectors.toList());
+                                            treeVo.setChildren(childrenEnd);
+                                        }
+
+                                    }
+
+                                }
+                            }
+                        }
+                    }
+                }
+
+            }
+        }
+
+
+        return sysDeptTreeVos;
+    }
+
 
 }
 

+ 132 - 15
src/main/java/com/ydtech/modules/admin/service/impl/SysPartnerServiceImpl.java

@@ -4,6 +4,7 @@ package com.ydtech.modules.admin.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ydtech.aop.exception.DescribeException;
@@ -15,7 +16,6 @@ import com.ydtech.modules.admin.model.dto.SysPartnerPageDto;
 import com.ydtech.modules.admin.model.vo.AgencyExtractFeeVo;
 import com.ydtech.modules.admin.model.vo.SysPartnerAPPPageVo;
 import com.ydtech.modules.admin.model.vo.SysUserPartner;
-import com.ydtech.modules.admin.model.vo.TeamInformation;
 import com.ydtech.modules.admin.service.SysPartnerService;
 import com.ydtech.modules.admin.service.SysUserService;
 import com.ydtech.modules.base.controller.BaseController;
@@ -35,6 +35,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 配置机构合伙人表(SysPartner)表服务实现类
@@ -72,21 +73,44 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
 
     @Override
     public List<SysPartner> queryRecommendAndPartner(String id) {
-        return sysPartnerMapper.selectList(new LambdaQueryWrapper<SysPartner>().eq(SysPartner::getDelFlag, 1).likeRight(SysPartner::getUserId, id));
+        return sysPartnerMapper.selectList(new LambdaQueryWrapper<SysPartner>().eq(SysPartner::getDelFlag, 1)
+                .likeRight(SysPartner::getUserId, id).orderByDesc(SysPartner::getId));
     }
 
     @Override
     public BasePageResult<SysUserPartner> queryByPage(SysPartnerPageDto sysPartnerPageDto) {
         Page<SysUser> page = new Page<>(sysPartnerPageDto.getPageNum(), sysPartnerPageDto.getPageSize());
+        List<SysAgencyLeader> sysAgencyLeaders = sysAgencyLeaderMapper.selectList(new LambdaQueryWrapper<SysAgencyLeader>().eq(SysAgencyLeader::getDelFlag, 1));
+        List<String> stringList =null;
+        if (sysAgencyLeaders.size()>0) {
+            stringList = sysAgencyLeaders.stream().map(SysAgencyLeader::getUserId).collect(Collectors.toList());
 
+        }
+        List<String> idList =null;
+        List<SysDept> sysDeptLists = sysDeptMapper.selectList(new LambdaQueryWrapper<SysDept>().eq(SysDept::getComlevel, 4).eq(SysDept::getDelFlag,0));
+        if (sysDeptLists.size()>0) {
+            List<String> collect = sysDeptLists.stream().map(SysDept::getId).collect(Collectors.toList());
+
+            List<SysDept> sysDeptList = sysDeptMapper.selectList(new LambdaQueryWrapper<SysDept>()
+                    .in(SysDept::getParentId, collect)
+                    .eq(SysDept::getDelFlag,0).isNull(SysDept::getComlevel).eq(SysDept::getDeptType,"D"));
+            if (sysDeptList.size()>0) {
+                idList = sysDeptList.stream().map(SysDept::getId).collect(Collectors.toList());
+            }
+        }
         LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(SysUser::getStatus, 1);
         wrapper.likeRight(StringUtils.isNotEmpty(sysPartnerPageDto.getDeptId()), SysUser::getId, sysPartnerPageDto.getDeptId());
         wrapper.notLike(SysUser::getId, "M");
+        wrapper.notIn(CollectionUtil.isNotEmpty(stringList),SysUser::getId, stringList);
+        wrapper.in(CollectionUtil.isNotEmpty(idList),SysUser::getDeptId, idList);
+        wrapper.orderByDesc(SysUser::getCreateTime);
 
         Page<SysUser> insOrdersPage = sysUserService.page(page, wrapper);
         List<SysUser> records = insOrdersPage.getRecords();
+
         List<SysUserPartner> sysUserPartners = BeanUtil.copyToList(records, SysUserPartner.class);
+
         if (sysUserPartners.size() > 0) {
             for (SysUserPartner user : sysUserPartners) {
                 SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>().eq(SysDept::getId, user.getDeptId()).eq(SysDept::getDelFlag, 0));
@@ -104,6 +128,7 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
 
         }
 
+
         return new BasePageResult<>(sysPartnerPageDto.getPageNum(), page.getSize(), insOrdersPage.getTotal(), page.getPages(),
                 sysUserPartners);
     }
@@ -177,9 +202,29 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
     }
 
     @Override
-    public boolean deleteById(Integer id) {
+    public boolean deleteById(String id) {
+        SysPartner sysPartner = sysPartnerMapper.selectOne(new LambdaQueryWrapper<SysPartner>().eq(SysPartner::getDelFlag, 1).eq(SysPartner::getUserId, id));
+        List<SysRelationPerson> sysRelationPeople = sysRelationPersonMapper.selectList(new UpdateWrapper<SysRelationPerson>().lambda()
+                .eq(SysRelationPerson::getAgencyLeaderId, id)
+                .eq(SysRelationPerson::getDelFlag, 1)
+                .eq(SysRelationPerson::getType, 0));
+        if (sysRelationPeople.size() > 0) {
+            if (sysRelationPeople.get(0).getSuggestId() != null) {
+                throw new DescribeException(sysPartner.getUserName() + "有推荐人,不允许删除");
+            }
+        }
+        List<SysRelationPerson> sysRelationPeople1 = sysRelationPersonMapper.selectList(new UpdateWrapper<SysRelationPerson>().lambda()
+                .eq(SysRelationPerson::getSuggestId, id)
+                .eq(SysRelationPerson::getDelFlag, 1)
+                .eq(SysRelationPerson::getType, 0));
+        if (sysRelationPeople1.size() > 0) {
+            if (sysRelationPeople1.get(0).getSuggestId() != null) {
+                throw new DescribeException(sysPartner.getUserName() + "是推荐人,不允许删除");
+            }
+        }
+
         SysPartner partner = new SysPartner();
-        partner.setId(id);
+        partner.setId(sysPartner.getId());
         partner.setDelFlag(0);
         return sysPartnerMapper.updateById(partner) > 0;
     }
@@ -193,7 +238,7 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
         wrapper.eq(SysPartner::getDelFlag, 1);
         wrapper.like(StringUtils.isNotEmpty(sysPartnerPageDto.getUserId()), SysPartner::getUserId, sysPartnerPageDto.getUserId());
         wrapper.like(StringUtils.isNotEmpty(sysPartnerPageDto.getUserName()), SysPartner::getUserName, sysPartnerPageDto.getUserName());
-        wrapper.orderByAsc(SysPartner::getId);
+        wrapper.orderByDesc(SysPartner::getId);
 
         Page<SysPartner> insOrdersPage = page(page, wrapper);
         List<SysPartner> sysPartnerList = insOrdersPage.getRecords();
@@ -205,6 +250,7 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
                 //已提现抽成费用
                 BigDecimal historyFee = new BigDecimal("0.00");
                 //填充查询人的姓名和机构
+                agencyExtractFee.setProportional(sysPartner.getProportional());
                 agencyExtractFee.setUserId(sysPartner.getUserId());
                 agencyExtractFee.setUserName(sysPartner.getUserName());
                 SysUser sysUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>()
@@ -260,9 +306,14 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
                         }
                     }
                     agencyExtractFee.setSumpremium(bigDecimal);
-                    BigDecimal multiply = bigDecimal.multiply(new BigDecimal(agencyExtractFee.getProportional())
-                            .divide(new BigDecimal("100"))).setScale(2, RoundingMode.DOWN);
-                    agencyExtractFee.setExtractFee(multiply);
+                    if (!bigDecimal.equals(new BigDecimal("0.00"))) {
+
+                        BigDecimal multiply = bigDecimal.multiply(new BigDecimal(agencyExtractFee.getProportional())
+                                .divide(new BigDecimal("100"))).setScale(2, RoundingMode.DOWN);
+                        agencyExtractFee.setExtractFee(multiply);
+                    }else {
+                        agencyExtractFee.setExtractFee(new BigDecimal("0.00"));
+                    }
                     // 填充 已提现抽成费用和可提现抽成费用
                     List<SysAgencyFeeApproval> sysAgencyFeeApprovals = sysAgencyFeeApprovalMapper.selectList(new LambdaQueryWrapper<SysAgencyFeeApproval>()
                             .eq(SysAgencyFeeApproval::getUserId, sysPartner.getUserId())
@@ -272,17 +323,22 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
                             historyFee = historyFee.add(sysAgencyFeeApproval.getHistoryFee());
                         }
                     }
-
-                    if (!bigDecimal.equals(new BigDecimal("0.00"))) {
+                    BigDecimal extractFee = agencyExtractFee.getExtractFee();
+                    if (!extractFee.equals(new BigDecimal("0.00"))) {
                         //已提现
                         agencyExtractFee.setHistoryFee(historyFee);
                         //可提现 = 总抽成-已提现
-                        agencyExtractFee.setCashFee(multiply.subtract(historyFee));
+                        agencyExtractFee.setCashFee(extractFee.subtract(historyFee));
                     } else {
                         agencyExtractFee.setHistoryFee(new BigDecimal("0.00"));
-                        agencyExtractFee.setCashFee(multiply.subtract(new BigDecimal("0.00")));
+                        agencyExtractFee.setCashFee(extractFee.subtract(new BigDecimal("0.00")));
                     }
 
+                }else {
+                    agencyExtractFee.setSumpremium(BigDecimal.ZERO);
+                    agencyExtractFee.setExtractFee(BigDecimal.ZERO);
+                    agencyExtractFee.setHistoryFee(BigDecimal.ZERO);
+                    agencyExtractFee.setCashFee(BigDecimal.ZERO);
                 }
                 agencyExtractFeeList.add(agencyExtractFee);
 
@@ -324,6 +380,8 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
             LambdaQueryWrapper<SysPartner> wrapper = new LambdaQueryWrapper<>();
             wrapper.like(StringUtils.isNotEmpty(sysPartnerAPPPageDto.getUserName()), SysPartner::getUserName, sysPartnerAPPPageDto.getUserName());
             wrapper.in(SysPartner::getUserId, ids);
+            wrapper.eq(SysPartner::getDelFlag, 1);
+            wrapper.orderByDesc(SysPartner::getId);
 
             Page<SysPartner> insOrdersPage = page(page, wrapper);
             List<SysPartner> sysPartnerList = insOrdersPage.getRecords();
@@ -399,9 +457,14 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
                         }
                     }
                     sysPartnerAPPPageVo.setSumpremium(bigDecimal);
-                    BigDecimal multiply = bigDecimal.multiply(new BigDecimal(sysPartner.getProportional())
-                            .divide(new BigDecimal("100"))).setScale(2, RoundingMode.DOWN);
-                    sysPartnerAPPPageVo.setExtractFee(multiply);
+                    if (!bigDecimal.equals(new BigDecimal("0.00"))) {
+                        BigDecimal multiply = bigDecimal.multiply(new BigDecimal(sysPartner.getProportional())
+                                .divide(new BigDecimal("100"))).setScale(2, RoundingMode.DOWN);
+                        sysPartnerAPPPageVo.setExtractFee(multiply);
+                    }else {
+                        sysPartnerAPPPageVo.setExtractFee(new BigDecimal("0.00"));
+                    }
+
                     sysPartnerAPPPageVoList.add(sysPartnerAPPPageVo);
 
                 }
@@ -415,5 +478,59 @@ public class SysPartnerServiceImpl extends ServiceImpl<SysPartnerMapper, SysPart
                 sysPartnerAPPPageVoList);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean edit(SysPartnerDto sysPartnerDto) {
+        boolean b;
+        SysPartner sysPartner = sysPartnerMapper.selectOne(new LambdaQueryWrapper<SysPartner>()
+                .eq(SysPartner::getDelFlag, 1).eq(SysPartner::getUserId, sysPartnerDto.getUserId()));
+        if (sysPartner == null) throw new DescribeException("系统错误,请联系管理员!");
+
+        if (StringUtils.isNullOrEmpty(sysPartner.getSuggestId()) && StringUtils.isNotEmpty(sysPartnerDto.getSuggestId())) {
+            SysPartner partner = new SysPartner();
+            partner.setId(sysPartner.getId());
+            partner.setProportional(sysPartnerDto.getProportional());
+            partner.setSuggestId(sysPartnerDto.getSuggestId());
+            partner.setSuggestName(sysPartnerDto.getSuggestName());
+            b = sysPartnerMapper.updateById(partner) > 0;
+
+            SysRelationPerson sysRelationPerson = new SysRelationPerson();
+            sysRelationPerson.setAgencyLeaderId(sysPartnerDto.getUserId());
+            sysRelationPerson.setSuggestId(sysPartnerDto.getSuggestId());
+            //'推荐等级(0:直接推荐;1:间接推荐)
+            sysRelationPerson.setSource(0);
+            //推荐类型(0:合伙人  1:机构负责人)
+            sysRelationPerson.setType(0);
+            sysRelationPerson.setCreateBy(BaseController.getUser().getId());
+            sysRelationPerson.setCreateTime(new Date());
+            b = sysRelationPersonMapper.insert(sysRelationPerson) > 0;
+            //查询合伙人的推荐人是否有上级
+            List<SysRelationPerson> sysRelationPeople = sysRelationPersonMapper.selectList(new LambdaQueryWrapper<SysRelationPerson>()
+                    .eq(SysRelationPerson::getAgencyLeaderId, sysPartnerDto.getSuggestId())
+                    .eq(SysRelationPerson::getType, 0));
+            if (sysRelationPeople.size() > 0) {
+                for (SysRelationPerson relationPerson : sysRelationPeople) {
+                    SysRelationPerson sysRelationPerson1 = new SysRelationPerson();
+                    sysRelationPerson1.setAgencyLeaderId(sysPartnerDto.getUserId());
+                    sysRelationPerson1.setSuggestId(relationPerson.getSuggestId());
+                    sysRelationPerson1.setSource(1);
+                    //推荐类型(0:合伙人  1:机构负责人)
+                    sysRelationPerson1.setType(0);
+                    sysRelationPerson1.setCreateBy(BaseController.getUser().getId());
+                    sysRelationPerson1.setCreateTime(new Date());
+                    sysRelationPersonMapper.insert(sysRelationPerson1);
+                }
+            }
+        }else {
+            SysPartner partner = new SysPartner();
+            partner.setId(sysPartner.getId());
+            partner.setProportional(sysPartnerDto.getProportional());
+            b = sysPartnerMapper.updateById(partner) > 0;
+        }
+
+
+        return b;
+    }
+
 
 }

+ 6 - 7
src/main/java/com/ydtech/modules/admin/service/impl/UserReportServiceImpl.java

@@ -460,7 +460,7 @@ public class UserReportServiceImpl implements UserReportService {
                 userList0.add(esmUserReferrer.getId());
                 userPolicyList0 = esmUserReferrerMapper.queryOrderCount(userList0, null, null);
                 //汇总数据加工
-                EsmTeamPolicyVO esmTeamPolicyVO0 = esmUserReferrerMapper.queryOrderCountHz(userList0, null, null);
+                EsmTeamPolicyVO esmTeamPolicyVO0 = esmUserReferrerMapper.queryOrderCountHzNew(userList0, null, null);
                 EsmTeamPolicyVO esmTeamPolicyVO1 = new EsmTeamPolicyVO();
                 EsmTeamPolicyVO esmTeamPolicyVO2 = new EsmTeamPolicyVO();
                 EsmTeamPolicyVO esmTeamPolicyVO3 = new EsmTeamPolicyVO();
@@ -481,7 +481,7 @@ public class UserReportServiceImpl implements UserReportService {
                 esmTeamPolicyVO1.setTeamlevel("一级团队");
                 if (userList1 != null && userList1.size() > 0) {
                     userPolicyList1 = esmUserReferrerMapper.queryOrderCount(userList1, null, null);
-                    EsmTeamPolicyVO esmTeamPolicyVO1_t = esmUserReferrerMapper.queryOrderCountHz(userList1, null,
+                    EsmTeamPolicyVO esmTeamPolicyVO1_t = esmUserReferrerMapper.queryOrderCountHzNew(userList1, null,
                             null);
                     if (esmTeamPolicyVO1_t != null) {
                         esmTeamPolicyVO1.setSumpremium(esmTeamPolicyVO1_t.getSumpremium());
@@ -494,7 +494,7 @@ public class UserReportServiceImpl implements UserReportService {
                     esmTeamPolicyVO2.setTeamlevel("二级团队");
                     if (userList2 != null && userList2.size() > 0) {
                         userPolicyList2 = esmUserReferrerMapper.queryOrderCount(userList2, null, null);
-                        EsmTeamPolicyVO esmTeamPolicyVO2_t = esmUserReferrerMapper.queryOrderCountHz(userList2, null,
+                        EsmTeamPolicyVO esmTeamPolicyVO2_t = esmUserReferrerMapper.queryOrderCountHzNew(userList2, null,
                                 null);
                         if (esmTeamPolicyVO2_t != null) {
                             esmTeamPolicyVO2.setSumpremium(esmTeamPolicyVO2_t.getSumpremium());
@@ -505,7 +505,7 @@ public class UserReportServiceImpl implements UserReportService {
                         userList3 = esmUserReferrerMapper.getIdDown_3(esmUserReferrer.getId());
                         if(userList3!=null && userList3.size()>0){
                             userPolicyList3=esmUserReferrerMapper.queryOrderCount(userList3,null, null);
-                            EsmTeamPolicyVO esmTeamPolicyVO3_t=esmUserReferrerMapper.queryOrderCountHz(userList3,null, null);
+                            EsmTeamPolicyVO esmTeamPolicyVO3_t=esmUserReferrerMapper.queryOrderCountHzNew(userList3,null, null);
                             esmTeamPolicyVO3.setTeamlevel("三级团队");
                             esmTeamPolicyVO3.setTeamnum(userList3.size());
                             if (esmTeamPolicyVO2_t != null) {
@@ -533,7 +533,7 @@ public class UserReportServiceImpl implements UserReportService {
                 userList.addAll(registList);
                 userPolicyList = esmUserReferrerMapper.queryOrderCount(userList, null, null);
                 EsmTeamPolicyVO esmTeamPolicyVO = new EsmTeamPolicyVO();
-                EsmTeamPolicyVO esmTeamPolicyVO_t = esmUserReferrerMapper.queryOrderCountHz(userList, null, null);
+                EsmTeamPolicyVO esmTeamPolicyVO_t = esmUserReferrerMapper.queryOrderCountHzNew(userList, null, null);
                 if (esmTeamPolicyVO_t != null) {
                     esmTeamPolicyVO.setSumpremium(esmTeamPolicyVO_t.getSumpremium());
                     esmTeamPolicyVO.setUsernum(userPolicyList.size());
@@ -590,9 +590,8 @@ public class UserReportServiceImpl implements UserReportService {
             pageVo.setPageNum(qxFrontlineAgentVo.getPageNum());
             pageVo.setPageSize(qxFrontlineAgentVo.getPageSize());
             HashMap<String, List<String>> humanResourcesIdList = new HashMap<>();
-
             IPage<QxFrontlineAgentDto> userResultPage = new Page<>();
-//关系表
+            //关系表
             List<EsmUserReferrerDTO> employeeIncreaseReportDtos = esmUserReferrerMapper.getbyUserNextLevel(null);
             Map<String, EsmUserReferrerDTO> collect = employeeIncreaseReportDtos.stream().collect(Collectors.toMap(EsmUserReferrerDTO::getId, Function.identity()));
             Set<String> visited = new HashSet<>();

+ 1 - 0
src/main/java/com/ydtech/modules/esm/dao/EsmUserReferrerMapper.java

@@ -237,4 +237,5 @@ public interface EsmUserReferrerMapper extends BaseMapper<EsmUserReferrer> {
      */
     List<EsmUserReferrerDTO> getUserLevel(@Param("vo") QxFrontlineAgentVo qxFrontlineAgentVo);
 
+    EsmTeamPolicyVO queryOrderCountHzNew(List<String> userList, String startDate, String endDate);
 }

+ 3 - 1
src/main/java/com/ydtech/modules/fnc/dao/InsPlyIncomeMapper.java

@@ -200,6 +200,8 @@ public interface InsPlyIncomeMapper extends BaseMapper<InsPlyIncome> {
 
     List<InsuranceHandlingSettlementMonthDto> getInvociAmount(@Param("vo") InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo);
 
-    Collection<? extends FinancialReceivablesVo> queryDateByTypePt(FinancialReceivablesQueryVo financialReceivablesQueryVo);
+    Collection<? extends FinancialReceivablesVo> queryDateByTypePt( @Param("vo") FinancialReceivablesQueryVo financialReceivablesQueryVo);
+
+    List<FinancialReceivablesMonthVo> getPatherId( @Param("vo")  FinancialReceivablesQueryMonthVo financialReceivablesQueryVo);
 
 }

+ 75 - 43
src/main/java/com/ydtech/modules/fnc/service/impl/InsPlyIncomeServiceImpl.java

@@ -54,6 +54,7 @@ import com.ydtech.utils.excel.ExcelStyleUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -2164,7 +2165,6 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         }else{
             insuranceHandlingSettlementMonthService.saveBatch(insuranceHandlingListNew);
         }
-
         return HttpResult.ok();
     }
 
@@ -3383,7 +3383,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         BigDecimal sySumAmount =  baseMapper.queryDateByTypeSumAmount(financialReceivablesQueryVo);
 
 
-        return new FinancialReceivablesAllVo(ptSumAmount.toString(),sySumAmount.toString(),year+"",list);
+        return new FinancialReceivablesAllVo(ptSumAmount !=null? ptSumAmount.toString(): "0",sySumAmount !=null  ? sySumAmount.toString() : "0",year+"",list);
     }
     /**
      *  @version
@@ -3448,9 +3448,9 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         } else {
              amountMap = this.platformSett(resultData, financialReceivablesQueryVo);
         }
-//        vo.setYisSumAmount(amountMap.get("yishouAmount").toString());
-//        vo.setYsSumAmount(amountMap.get("yinshouAmount").toString());
-//        vo.setWsSumAmount(amountMap.get("weishouAmount").toString());
+        vo.setYisSumAmount(amountMap.get("yishouAmount").toString());
+        vo.setYsSumAmount(amountMap.get("yinshouAmount").toString());
+        vo.setWsSumAmount(amountMap.get("weishouAmount").toString());
         return vo;
     }
 
@@ -3471,25 +3471,30 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         //平台手续费
         List<FinancialReceivablesMonthVo> handList = baseMapper.queryPlatHanding(financialReceivablesQueryVo);
 
-        Map<String, FinancialReceivablesMonthVo> collect = handList.stream().collect(Collectors.toMap(FinancialReceivablesMonthVo::getPartnerCompaniesId, Function.identity()));
 
-        handList.stream().filter(item -> collect.containsKey(item.getPartnerCompaniesId()))
-                .forEach(item ->{
-                    FinancialReceivablesMonthVo otherItem = collect.get(item.getPartnerCompaniesId());
+        List<FinancialReceivablesMonthVo> patherIdList = baseMapper.getPatherId(financialReceivablesQueryVo);
+
+
 
+        Map<String, List<FinancialReceivablesMonthVo>> groupedByPartnerCompaniesId = handList.stream()
+                .collect(Collectors.groupingBy(FinancialReceivablesMonthVo::getPartnerCompaniesId));
+
+        patherIdList.stream().filter(item -> groupedByPartnerCompaniesId.containsKey(item.getPartnerCompaniesId()))
+                .forEach(item ->{
+                    List<FinancialReceivablesMonthVo> financialReceivablesMonthVosList = groupedByPartnerCompaniesId.get(item.getPartnerCompaniesId());
                     FinancialReceivablesMonthSignleVo financialReceivablesMonthSignleVo = new FinancialReceivablesMonthSignleVo();
                     List<FinancialReceivablesMonthVo> financialReceivablesMonthVos = financialReceivablesMonthSignleVo.getList();
                     financialReceivablesMonthSignleVo.setCompanyName(item.getCompanyName());
                     financialReceivablesMonthSignleVo.setAreaName(item.getAreaName());
-                    financialReceivablesMonthVos.add(otherItem);
-                    financialReceivablesMonthVos.add(item);
-                    if("合计".equals(item.getIsHand())){
-                        yinShouAmountList.add(this.stringToBigdecimal(item.getCommissionFeevalue()));
-                        yishouAmountList.add(this.stringToBigdecimal(item.getReadyCommissionFeevalue()));
-                        weishouAmountList.add(this.stringToBigdecimal(item.getNoInvoicCommissionFeevalue()));
-
-                    }
+                    financialReceivablesMonthVos.addAll(financialReceivablesMonthVosList);
                     resultData.add(financialReceivablesMonthSignleVo);
+                    financialReceivablesMonthVosList.forEach(financialReceivablesMonthVo  ->{
+                        if("合计".equals(financialReceivablesMonthVo.getIsHand())){
+                            yinShouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getCommissionFeevalue()));
+                            yishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getReadyCommissionFeevalue()));
+                            weishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getNoInvoicCommissionFeevalue()));
+                        }
+                    });
                 });
         yinshouAmount = yinshouAmount.add(yinShouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
         yishouAmount = yishouAmount.add(yishouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
@@ -3512,37 +3517,64 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
 
         HashMap<String, BigDecimal> resultMap = new HashMap<>();
 
-
         //手续费未接应收
         List<FinancialReceivablesMonthVo> list = baseMapper.queryDateByTypeByMonthList(financialReceivablesQueryVo);
         //跟单统计
         List<FinancialReceivablesMonthVo> otherList = baseMapper.queryDateByTypeByMonthOtherList(financialReceivablesQueryVo);
 
-        Map<String, FinancialReceivablesMonthVo> collect = otherList.stream().collect(Collectors.toMap(FinancialReceivablesMonthVo::getPartnerCompaniesId, Function.identity()));
-        list.stream()
-                .filter(item -> collect.containsKey(item.getPartnerCompaniesId()))
-                .forEach(
-                        item -> {
-                            FinancialReceivablesMonthVo otherItem = collect.get(item.getPartnerCompaniesId());
-                            FinancialReceivablesMonthSignleVo financialReceivablesMonthSignleVo = new FinancialReceivablesMonthSignleVo();
-                            List<FinancialReceivablesMonthVo> financialReceivablesMonthVos = financialReceivablesMonthSignleVo.getList();
-                            financialReceivablesMonthSignleVo.setCompanyName(item.getCompanyName());
-                            financialReceivablesMonthSignleVo.setAreaName(item.getAreaName());
-//                          合计信息
-                            FinancialReceivablesMonthVo financialReceivablesMonthVo = new FinancialReceivablesMonthVo();
-                            financialReceivablesMonthVo.setCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getCommissionFeevalue()), new BigDecimal(otherItem.getCommissionFeevalue()), null).toString());
-                            financialReceivablesMonthVo.setNoInvoicCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getNoInvoicCommissionFeevalue()), new BigDecimal(otherItem.getNoInvoicCommissionFeevalue()), null).toString());
-                            financialReceivablesMonthVo.setReadyCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getReadyCommissionFeevalue()), new BigDecimal(otherItem.getReadyCommissionFeevalue()), null).toString());
-                            financialReceivablesMonthVo.setSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getSettlementAmount()), new BigDecimal(otherItem.getSettlementAmount()), null).toString());
-                            financialReceivablesMonthVo.setNoSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getNoSettlementAmount()), new BigDecimal(otherItem.getNoSettlementAmount()), null).toString());
-                            financialReceivablesMonthVo.setIsHand("合计");
-                            financialReceivablesMonthVos.add(otherItem);
-                            financialReceivablesMonthVos.add(item);
-                            financialReceivablesMonthVos.add(financialReceivablesMonthVo);
-                            yishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getReadyCommissionFeevalue()));
-                            yinShouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getCommissionFeevalue()));
-                            weishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getNoInvoicCommissionFeevalue()));
-                            resultData.add(financialReceivablesMonthSignleVo);
+        Map<String, FinancialReceivablesMonthVo> otherCollect = otherList.stream().collect(Collectors.toMap(FinancialReceivablesMonthVo::getPartnerCompaniesId, Function.identity()));
+        Map<String, FinancialReceivablesMonthVo>  commCollect= list.stream().collect(Collectors.toMap(FinancialReceivablesMonthVo::getPartnerCompaniesId, Function.identity()));
+        list.forEach(item -> {
+                            if(otherCollect.containsKey(item.getPartnerCompaniesId())){
+                                FinancialReceivablesMonthVo otherItem = otherCollect.get(item.getPartnerCompaniesId());
+                                FinancialReceivablesMonthSignleVo financialReceivablesMonthSignleVo = new FinancialReceivablesMonthSignleVo();
+                                List<FinancialReceivablesMonthVo> financialReceivablesMonthVos = financialReceivablesMonthSignleVo.getList();
+                                financialReceivablesMonthSignleVo.setCompanyName(item.getCompanyName());
+                                financialReceivablesMonthSignleVo.setAreaName(item.getAreaName());
+//                              合计信息
+                                FinancialReceivablesMonthVo financialReceivablesMonthVo = new FinancialReceivablesMonthVo();
+                                financialReceivablesMonthVo.setCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getCommissionFeevalue()), new BigDecimal(otherItem.getCommissionFeevalue()), null).toString());
+                                financialReceivablesMonthVo.setNoInvoicCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getNoInvoicCommissionFeevalue()), new BigDecimal(otherItem.getNoInvoicCommissionFeevalue()), null).toString());
+                                financialReceivablesMonthVo.setReadyCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getReadyCommissionFeevalue()), new BigDecimal(otherItem.getReadyCommissionFeevalue()), null).toString());
+                                financialReceivablesMonthVo.setSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getSettlementAmount()), new BigDecimal(otherItem.getSettlementAmount()), null).toString());
+                                financialReceivablesMonthVo.setNoSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getNoSettlementAmount()), new BigDecimal(otherItem.getNoSettlementAmount()), null).toString());
+                                financialReceivablesMonthVo.setIsHand("合计");
+                                financialReceivablesMonthVos.add(otherItem);
+                                financialReceivablesMonthVos.add(item);
+                                financialReceivablesMonthVos.add(financialReceivablesMonthVo);
+                                yishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getReadyCommissionFeevalue()));
+                                yinShouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getCommissionFeevalue()));
+                                weishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getNoInvoicCommissionFeevalue()));
+                                resultData.add(financialReceivablesMonthSignleVo);
+                            }else {
+                                FinancialReceivablesMonthVo otherItem = new FinancialReceivablesMonthVo() ;
+                                otherItem.setIsHand("跟单费");
+                                otherItem.setCommissionFeevalue(BigDecimal.ZERO.toString());
+                                otherItem.setNoInvoicCommissionFeevalue(BigDecimal.ZERO.toString());
+                                otherItem.setReadyCommissionFeevalue(BigDecimal.ZERO.toString());
+                                otherItem.setSettlementAmount(BigDecimal.ZERO.toString());
+                                otherItem.setNoSettlementAmount(BigDecimal.ZERO.toString());
+                                FinancialReceivablesMonthSignleVo financialReceivablesMonthSignleVo = new FinancialReceivablesMonthSignleVo();
+                                List<FinancialReceivablesMonthVo> financialReceivablesMonthVos = financialReceivablesMonthSignleVo.getList();
+                                financialReceivablesMonthSignleVo.setCompanyName(item.getCompanyName());
+                                financialReceivablesMonthSignleVo.setAreaName(item.getAreaName());
+//                              合计信息
+                                FinancialReceivablesMonthVo financialReceivablesMonthVo = new FinancialReceivablesMonthVo();
+                                financialReceivablesMonthVo.setCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getCommissionFeevalue()), BigDecimal.ZERO, null).toString());
+                                financialReceivablesMonthVo.setNoInvoicCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getNoInvoicCommissionFeevalue()), BigDecimal.ZERO, null).toString());
+                                financialReceivablesMonthVo.setReadyCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getReadyCommissionFeevalue()), BigDecimal.ZERO, null).toString());
+                                financialReceivablesMonthVo.setSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getSettlementAmount()), BigDecimal.ZERO, null).toString());
+                                financialReceivablesMonthVo.setNoSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getNoSettlementAmount()), BigDecimal.ZERO, null).toString());
+                                financialReceivablesMonthVo.setIsHand("合计");
+                                financialReceivablesMonthVos.add(otherItem);
+                                financialReceivablesMonthVos.add(item);
+                                financialReceivablesMonthVos.add(financialReceivablesMonthVo);
+                                yishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getReadyCommissionFeevalue()));
+                                yinShouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getCommissionFeevalue()));
+                                weishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getNoInvoicCommissionFeevalue()));
+                                resultData.add(financialReceivablesMonthSignleVo);
+
+                            }
                         }
                 );
         yinshouAmount = yinshouAmount.add(yinShouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));

+ 1 - 1
src/main/java/com/ydtech/modules/ins/model/vo/res/BxSettlementFeesNorExcel.java

@@ -63,7 +63,7 @@ public class BxSettlementFeesNorExcel implements Serializable {
 
     @ApiModelProperty("手续费金额")
     @ExcelProperty(value = "手续费金额",index = 9)
-    private BigDecimal noSuperviseCostsPremiums;
+    private BigDecimal commissionFeevalue;
 
 
 }

+ 3 - 0
src/main/resources/mapper/modules/admin/SysAgencyFeeApprovalMapper.xml

@@ -21,6 +21,9 @@
         <result property="remark" column="remark" jdbcType="VARCHAR"/>
         <result property="picture" column="picture" jdbcType="VARCHAR"/>
     </resultMap>
+    <select id="queryById" resultType="com.ydtech.modules.admin.model.SysAgencyFeeApproval">
+        select * from sys_agency_fee_approval where id = #{id} FOR UPDATE;
+    </select>
 
 </mapper>
 

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

@@ -1298,16 +1298,16 @@
             and su.id  LIKE '%M%'
             and su.status = '1'
             <if test="vo.provinceId != null and vo.provinceId != ''">
-                and sd.deptid like "$vo.provinceId}%"
+                and sd.id like  concat('%',#{vo.provinceId},'%')
             </if>
             <if test="vo.cityId != null and vo.cityId != ''">
-                and sd.deptid like "${vo.cityId}%"
+                and sd.id like concat('%',#{vo.cityId},'%')
             </if>
             <if test="vo.countyId != null and vo.countyId != ''">
-                and sd.deptid like "${vo.countyId}%"
+                and sd.id like concat('%',#{vo.countyId},'%')
             </if>
             <if test="vo.houseId != null and vo.houseId != ''">
-                and sd.deptid like "${vo.houseId}%"
+                and sd.id like concat('%',#{vo.houseId},'%')
             </if>
         </where>
     </select>

+ 18 - 0
src/main/resources/mapper/modules/esm/EsmUserReferrerMapper.xml

@@ -102,6 +102,24 @@
                   #{item}
               </foreach>
     </select>
+    <select id="queryOrderCountHzNew" resultType="com.ydtech.modules.esm.model.vo.EsmTeamPolicyVO">
+        SELECT
+            sum(iac.sumpremium) sumpremium
+        FROM
+            ins_orders io
+                LEFT JOIN ins_area_company iac ON io.orderno = iac.orderno
+                LEFT JOIN sys_user su ON io.userid = su.id
+        WHERE
+            iac.orderstatus = 3
+          AND io.orderstatus = 3
+          <if test="startDate !=null  and startDate !=''  and endDate!=null  and  endDate!='' ">
+              AND io.createtime BETWEEN #{startDate} AND #{endDate}
+          </if>
+          AND io.userid in
+              <foreach item="item" index="index" collection="userList" open="(" separator="," close=")">
+                  #{item}
+              </foreach>
+    </select>
 
     <select id="getUserPage" resultMap="SysUserMap">
         SELECT

+ 269 - 166
src/main/resources/mapper/modules/fnc/InsPlyIncomeMapper.xml

@@ -2454,8 +2454,8 @@
             <if test="vo.isNotCar !=null  and  vo.isNotCar  !=''">
                 and a.is_not_car =#{vo.isNotCar}
             </if>
-            <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
-                AND  a.create_time  BETWEEN #{vo.beginDate} AND #{vo.endDate}
+            <if test="vo.year !=null  and  vo.year !=''">
+                and  DATE_FORMAT( a.signdate, '%Y' ) =#{vo.year}
             </if>
         </where>
     </select>
@@ -2463,46 +2463,58 @@
     <select id="queryDateByType"
             resultType="com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesVo">
         SELECT
-            a.subSigning as "yearAndMonth",
+            a.subSigndate as "yearAndMonth",
             a.allAmount as "commissionFeevalue",
-            b.commSettLement +c.otherSettlementAmount as "noInvoicCommissionFeevalue",
-            a.allAmount-( b.commSettLement +c.otherSettlementAmount) as "readyCommissionFeevalue",
-            (c.invoicAmount - c.otherSettlementAmount) +  (b.remainingAmount) as "settlementAmount"
+            IFNULL(c.settAmountOther,0) +IFNULL(b.settCommAmount ,0) as "noInvoicCommissionFeevalue",
+            IFNULL(b.remainingAmount,0) +IFNULL(c.invoicNotOther,0) as "settlementAmount",
+            (a.allAmount-(IFNULL(b.invoicComm,0) + IFNULL(c.otherInvoic,0)))  as "noSettlementAmount",
+            a.allAmount-(IFNULL(c.settAmountOther,0) +IFNULL(b.settCommAmount ,0)) as "readyCommissionFeevalue"
         FROM
             (
                 SELECT
-                    sum( a.all_fee_value ) AS "allAmount",
-                    DATE_FORMAT( a.signdate, '%Y-%m' ) AS "subSigning"
+                    DATE_FORMAT( a.signdate, '%Y-%m' ) AS subSigndate,
+                    IFNULL( sum( a.commission_feevalue ), 0 ) + IFNULL( sum( a.other_feevalue ), 0 ) AS "allAmount"
                 FROM
                     ins_ply_income a
                         LEFT JOIN ptl_agreement pa ON pa.id = a.agreement_id
-                WHERE
+                <where>
                     pa.agreement_type = '2'
+                    <if test="vo.year !=null  and  vo.year !=''">
+                        and  DATE_FORMAT( a.signdate, '%Y' ) =#{vo.year}
+                    </if>
+                </where>
                 GROUP BY
                     DATE_FORMAT( a.signdate, '%Y-%m' )
-            )  a    left  join  (
+            ) a
+                LEFT JOIN (
                 SELECT
-                    sum( a.settlement_amount ) as "commSettLement",
-                    sum( a.remaining_amount ) as "remainingAmount",
-                    DATE_FORMAT( a.signing_time, '%Y-%m' )  as "subSigning"
+                    DATE_FORMAT( a.signing_time, '%Y-%m' ) AS "subSigndate",
+                    sum( a.settlement_amount ) AS "settCommAmount",
+                    sum(a.remaining_amount) as "remainingAmount",
+                    sum(a.total_amount) as "invoicComm"
                 FROM
                     sys_insurance_handling_settlement_month a
+                <where>
+                    <if test="vo.year !=null  and  vo.year !=''">
+                          DATE_FORMAT( a.signing_time, '%Y' ) =#{vo.year}
+                    </if>
+                </where>
                 GROUP BY
                     DATE_FORMAT( a.signing_time, '%Y-%m' )
-            ) b  on  b.subSigning=a.subSigning
-                    left  join  (
-                SELECT
-                    SUM( CASE WHEN a.settlement_status = '2' THEN IFNULL( a.settlement_amount, 0 ) ELSE 0 END ) AS "otherSettlementAmount",
-                    SUM( CASE WHEN a.settlement_status = '1' THEN IFNULL( a.settlement_amount, 0 ) ELSE 0 END ) AS "invoicAmount",
-                    DATE_FORMAT( a.signing_time, '%Y-%m' ) AS "subSigning"
-                FROM
-                    settlement_documentary_fees a
-                WHERE
-                    a.handling_fees_status = '1'
-                GROUP BY
-                    DATE_FORMAT( a.signing_time, '%Y-%m' )
-            )  c  on  c.subSigning=a.subSigning
-
+            ) b ON a.subSigndate = b.subSigndate
+                left  join  (
+                select DATE_FORMAT( a.signing_time, '%Y-%m' ) as "subSigndate" ,  sum(settlement_amount) as "otherInvoic", sum(invoiced_settled_amount) as "settAmountOther", sum(Invoiced_not_settled_amount) as "invoicNotOther"
+                from
+                    settlement_documentary_fees  a
+                <where>
+                    a.settlement_status='1'
+                    and handling_fees_status ='1'
+                    <if test="vo.year !=null  and  vo.year !=''">
+                     and    DATE_FORMAT( a.signing_time, '%Y' ) =#{vo.year}
+                    </if>
+                </where>
+                GROUP BY 	DATE_FORMAT( a.signing_time, '%Y-%m' )
+            )  c  on c.subSigndate=a.subSigndate
     </select>
 
     <select id="queryDateByTypeMonthSumAmount" resultType="java.math.BigDecimal">
@@ -2539,6 +2551,9 @@
             <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
                 AND  a.signdate  BETWEEN #{vo.beginDate} AND #{vo.endDate}
             </if>
+           <if test="vo.yearAndMonth  != null  and  vo.yearAndMonth!=''">
+                AND   DATE_FORMAT(a.signdate, '%Y-%m') =#{vo.yearAndMonth}
+            </if>
         </where>
     </select>
 
@@ -2547,74 +2562,64 @@
             a.subPathner,
             sa.area_cname as "areaName",
             eic.namesimple as "companyName",
-            a.handlingReceivable  as "commissionFeevalue",
             a.partnerCompaniesId  as "partnerCompaniesId",
+            IFNULL(a.allAmount,0) as "commissionFeevalue",
             a.companyId as "companyId",
-            IFNULL(a.settleAmount ,0 )   as "settlementAmount",
-            a.unlicensedHandlingFee  as "noSettlementAmount",
-            IFNULL(a.unlicensedHandlingFee ,0 ) + IFNULL(a.settleAmount,0 ) as  "noInvoicCommissionFeevalue",
+            IFNULL(b.noSettHandlingFee,0) as "settlementAmount",
+            IFNULL(a.allAmount,0) - IFNULL( b.settAmount,0)  as "noSettlementAmount",
+            (IFNULL(a.allAmount,0) - IFNULL( b.settAmount,0)) +IFNULL(b.noSettHandlingFee,0) as  "noInvoicCommissionFeevalue",
             "手续费" as  "isHand",
-            IFNULL(a.handlingReceivable ,0 ) - IFNULL((IFNULL(a.unlicensedHandlingFee ,0 ) + IFNULL(a.settleAmount,0 )),0 ) as  "readyCommissionFeevalue"
+            IFNULL( b.settAmount,0)  as "readyCommissionFeevalue"
+
         FROM
-            (SELECT
-                 SUBSTRING( a.partner_companies_id, 6, 11 ) AS "subPathner",
-                 a.company_id as "companyId",
-                 a.partner_companies_id as "partnerCompaniesId",
-                 sum( a.commission_feevalue ) as "handlingReceivable",
-                 SUM( CASE WHEN a.handling_fees_status = '0' THEN a.commission_feevalue ELSE 0 END ) AS "unlicensedHandlingFee",
-                 MAX(b.noSettHandlingFee) AS "settleAmount"
-             FROM
-                 ins_ply_income a
-                     LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
-                     LEFT JOIN (
-                     SELECT
-                         sum(a.commission_feevalue)  as "invoicAmount",
-                         IFNULL(sum(a.commission_feevalue) ,0 ) - IFNULL(max(b.settlementAmount) ,0 ) as  "noSettHandlingFee",
-                         a.signdate,
-                         a.task_id as "taskId" ,
-                        a.partner_companies_id  as "subPathner"
-                     FROM
-                         ins_ply_income a
-                             LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
-                             LEFT JOIN (
-                             select sum(settlement_amount) as "settlementAmount", a.task_id  as "taskId" from settlement_documentary_fees   a
-                             <where>
-                                 a.task_id IS NOT NULL
-                                 and a.settlement_status ='2'
-                                 <if test="vo.isNoCar !=null  and  vo.isNoCar  !=''">
-                                     and a.handling_fees_status =#{vo.isNoCar}
-                                 </if>
-                             </where>
-                             GROUP BY  a.task_id
-                         ) b  on  a.task_id=b.taskId
-                     <where>
-                         pa.agreement_type = '2'
-                         AND a.is_not_documentary = '0'
-                         AND a.task_id  is not  null
-                         <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
-                             AND  a.signdate  BETWEEN #{vo.beginDate} AND #{vo.endDate}
-                         </if>
-                         <if test="vo.isNoCar !=null  and  vo.isNoCar  !=''">
-                             and a.is_not_car =#{vo.isNoCar}
-                         </if>
-                     </where>
-                     GROUP BY
-                         a.task_id , a.signdate,a.partner_companies_id
-                 ) b  on  b.subPathner = a.partner_companies_id
-             <where>
-                 pa.agreement_type = '2'
-                 AND a.is_not_documentary = '0'
-                 <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
-                     AND  a.signdate  BETWEEN #{vo.beginDate} AND #{vo.endDate}
-                 </if>
-                 <if test="vo.isNoCar !=null  and  vo.isNoCar  !=''">
-                     and a.is_not_car =#{vo.isNoCar}
-                 </if>
-             </where>
-             GROUP BY
-        a.partner_companies_id ,a.company_id) a
-        LEFT JOIN esm_ins_company  eic  on eic.id = a.companyId
-        LEFT JOIN sys_area  sa  on sa.area_code = a.subPathner
+            (
+                SELECT
+                    SUBSTRING( a.partner_companies_id, 6, 11 ) AS "subPathner",
+                    a.company_id AS "companyId",
+                    a.partner_companies_id AS "partnerCompaniesId" ,
+                    sum(a.commission_feevalue)   as "allAmount"
+                FROM
+                    ins_ply_income a
+                        LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
+                <where>
+                    pa.agreement_type = '2'
+                    AND a.is_not_documentary = '0'
+                    <if test="vo.isNoCar  != null  and vo.isNoCar !='' ">
+                      and   a.is_not_car =#{vo.isNoCar}
+                    </if>
+                    <if test="vo.yearAndMonth !=null  and  vo.yearAndMonth != ''">
+                      and DATE_FORMAT( a.signdate, '%Y-%m' ) =#{vo.yearAndMonth}
+                    </if>
+                </where>
+                GROUP BY
+                    a.partner_companies_id,
+                    a.company_id
+            ) a
+                LEFT JOIN (
+                SELECT
+                    sum( a.total_amount ) AS "invoicAmount",
+                    sum( a.remaining_amount ) AS "noSettHandlingFee",
+                    sum( a.settlement_amount ) AS "settAmount",
+                    a.task_id AS "taskId",
+                    DATE_FORMAT( a.signing_time, '%Y-%m' ) AS "subSigne",
+                    a.partner_companies_id AS "subPathner"
+                FROM
+                    sys_insurance_handling_settlement_month a
+                <where>
+                    <if test="vo.isNoCar  != null  and vo.isNoCar !='' ">
+                        and   a.is_not_car =#{vo.isNoCar}
+                    </if>
+                    <if test="vo.yearAndMonth !=null  and  vo.yearAndMonth != ''">
+                        and  DATE_FORMAT( a.signing_time, '%Y-%m' ) =#{vo.yearAndMonth}
+                    </if>
+                </where>
+                GROUP BY
+                    a.partner_companies_id,
+                    DATE_FORMAT( a.signing_time, '%Y-%m' ),
+                    a.task_id
+            ) b ON b.subPathner = a.partnerCompaniesId
+                LEFT JOIN esm_ins_company  eic  on eic.id = a.companyId
+                LEFT JOIN sys_area  sa  on sa.area_code = a.subPathner
     </select>
 
 
@@ -2642,10 +2647,10 @@
                 FROM
                     settlement_documentary_fees a
                 <where>
-                    a.settlement_sum_id IS NOT NULL
+                    a.handling_fees_status  ='1'
                     AND settlement_status = '1'
-                    <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
-                        AND  a.signing_time  BETWEEN #{vo.beginDate} AND #{vo.endDate}
+                    <if test="vo.yearAndMonth !=null  and  vo.yearAndMonth != ''">
+                        and  DATE_FORMAT( a.signing_time, '%Y-%m' ) =#{vo.yearAndMonth}
                     </if>
                     <if test="vo.isNoCar !=null  and  vo.isNoCar  !=''">
                         and a.is_not_car =#{vo.isNoCar}
@@ -2659,8 +2664,8 @@
         <where>
             pa.agreement_type = '2'
             AND a.is_not_documentary = '1'
-            <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
-                AND  a.signdate  BETWEEN #{vo.beginDate} AND #{vo.endDate}
+            <if test="vo.yearAndMonth !=null  and  vo.yearAndMonth != ''">
+                and  DATE_FORMAT( a.signdate, '%Y-%m' ) =#{vo.yearAndMonth}
             </if>
             <if test="vo.isNoCar !=null  and  vo.isNoCar  !=''">
                 and a.is_not_car =#{vo.isNoCar}
@@ -2681,7 +2686,8 @@
             SUM(a.commission_feevalue) AS commissionFeevalue,
             SUBSTRING( a.partner_companies_id, 6, 11 ) AS "subPathner",
             SUM(CASE WHEN a.handling_fees_status = '1' THEN a.commission_feevalue ELSE 0 END) AS "readyCommissionFeevalue",
-            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.commission_feevalue ELSE 0 END) AS "noInvoicCommissionFeevalue"
+            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.commission_feevalue ELSE 0 END) AS "noInvoicCommissionFeevalue",
+            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.commission_feevalue ELSE 0 END) AS "noSettlementAmount"
         FROM
             ins_ply_income a
                 LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
@@ -2689,7 +2695,6 @@
                 LEFT JOIN esm_ins_company eic ON eic.id = a.company_id
         <where>
             pa.agreement_type = '1'
-            AND a.is_not_documentary = '1'
             <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
                 AND  a.signdate  BETWEEN #{vo.beginDate} AND #{vo.endDate}
             </if>
@@ -2711,7 +2716,8 @@
             SUM(a.other_feevalue) AS commissionFeevalue,
             SUBSTRING( a.partner_companies_id, 6, 11 ) AS "subPathner",
             SUM(CASE WHEN a.handling_fees_status = '1' THEN a.other_feevalue ELSE 0 END) AS "readyCommissionFeevalue",
-            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.other_feevalue ELSE 0 END) AS "noInvoicCommissionFeevalue"
+            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.other_feevalue ELSE 0 END) AS "noInvoicCommissionFeevalue",
+            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.commission_feevalue ELSE 0 END) AS "noSettlementAmount"
         FROM
             ins_ply_income a
                 LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
@@ -2738,7 +2744,8 @@
             SUM(a.all_fee_value) AS commissionFeevalue,
             SUBSTRING( a.partner_companies_id, 6, 11 ) AS "subPathner",
             SUM(CASE WHEN a.handling_fees_status = '1' THEN a.all_fee_value ELSE 0 END) AS "readyCommissionFeevalue",
-            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.all_fee_value ELSE 0 END) AS "noInvoicCommissionFeevalue"
+            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.all_fee_value ELSE 0 END) AS "noInvoicCommissionFeevalue",
+            SUM(CASE WHEN a.handling_fees_status = '0' THEN a.commission_feevalue ELSE 0 END) AS "noSettlementAmount"
         FROM
             ins_ply_income a
                 LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
@@ -2763,93 +2770,114 @@
 
     <select id="queryPrivateCar" resultType="com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesVo">
         SELECT
-            DATE_FORMAT( a.signdate, '%Y-%m' )  as "yearAndMonth" ,
-            sum(a.all_fee_value)  as "commissionFeevalue",
-            IFNULL(max(b.readyCommissionFeevalue),0) + IFNULL(max(c.readyCommissionFeevalue1),0)  as  "noInvoicCommissionFeevalue",
-            sum(a.all_fee_value) -(IFNULL(max(b.readyCommissionFeevalue),0) + IFNULL(max(c.readyCommissionFeevalue1),0)) as "readyCommissionFeevalue",
-            (IFNULL(max(b.inSettlementAmount),0) -IFNULL(sum(b.readyCommissionFeevalue),0)) +IFNULL(max(c.settlementAmount),0)  as "settlementAmount",
-            IFNULL(max(c.noInvoicCommissionFeevalue),0)  + ((SUM( CASE WHEN a.handling_fees_status = '0' and a.is_not_documentary ='0' THEN a.all_fee_value ELSE 0 END ))) as "noSettlementAmount"
+            a.subSigndate as "yearAndMonth",
+            a.allAmount as "commissionFeevalue",
+            IFNULL(c.settAmountOther,0) +IFNULL(b.settCommAmount ,0) as "noInvoicCommissionFeevalue",
+            IFNULL(b.remainingAmount,0) +IFNULL(c.invoicNotOther,0) as "settlementAmount",
+            (a.allAmount-(IFNULL(b.invoicComm,0) + IFNULL(c.otherInvoic,0)))  as "noSettlementAmount",
+            a.allAmount-(IFNULL(c.settAmountOther,0) +IFNULL(b.settCommAmount ,0)) as "readyCommissionFeevalue"
         FROM
-            ins_ply_income a
-                LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
-                left join (
+            (
                 SELECT
-                    SUM( CASE WHEN settlement_status = '2' THEN a.settlement_amount ELSE 0 END )  as "readyCommissionFeevalue",
-                    SUM( CASE WHEN settlement_status = '1' THEN a.settlement_amount ELSE 0 END )  as "inSettlementAmount",
-                    a.task_id AS "taskId"
+                    DATE_FORMAT( a.signdate, '%Y-%m' ) AS subSigndate,
+                    IFNULL( sum( a.commission_feevalue ), 0 ) + IFNULL( sum( a.other_feevalue ), 0 ) AS "allAmount"
                 FROM
-                    settlement_documentary_fees a
+                    ins_ply_income a
+                        LEFT JOIN ptl_agreement pa ON pa.id = a.agreement_id
                 <where>
-                    a.task_id IS NOT NULL
+                    pa.agreement_type = '2'
                     <if test="vo.isNotCar !=null  and  vo.isNotCar  !=''">
                         and a.is_not_car =#{vo.isNotCar}
                     </if>
                 </where>
                 GROUP BY
-                    a.task_id
-            )  b   on  b .taskId =a.task_id
-                left  join (
+                    DATE_FORMAT( a.signdate, '%Y-%m' )
+            ) a
+                LEFT JOIN (
                 SELECT
-                    DATE_FORMAT( a.signing_time, '%Y-%m' ) as "singDateYear",
-                    sum( a.invoiced_settled_amount ) AS "readyCommissionFeevalue1",
-                    sum( a.Invoiced_not_settled_amount ) AS "settlementAmount",
-                    SUM( CASE WHEN settlement_status = '1' THEN a.settlement_amount ELSE 0 END )  as "invoiceAmount",
-                    IFNULL(sum(b.otherallFeeValue),0) -sum( a.invoiced_settled_amount ) as "noInvoicCommissionFeevalue",
-                    IFNULL(sum(b.otherallFeeValue),0) -sum( a.invoiced_settled_amount ) - SUM( CASE WHEN settlement_status = '1' THEN a.settlement_amount ELSE 0 END ) as "noSettlementAmount"
+                    DATE_FORMAT( a.signing_time, '%Y-%m' ) AS "subSigndate",
+                    sum( a.settlement_amount ) AS "settCommAmount",
+                    sum(a.remaining_amount) as "remainingAmount",
+                    sum(a.total_amount) as "invoicComm"
                 FROM
-                    settlement_documentary_fees a
-                        left join  (
-                        select sum(a.all_fee_value) as "otherallFeeValue", DATE_FORMAT( a.signdate, '%Y-%m' ) as "singDateYear"  from  ins_ply_income a
-                        LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
-                        <where>
-                            pa.agreement_type= '2'
-                            and a.is_not_documentary='1'
-                            <if test="vo.isNotCar !=null  and  vo.isNotCar  !=''">
-                                and a.is_not_car =#{vo.isNotCar}
-                            </if>
-                            <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
-                                AND  a.signdate  BETWEEN #{vo.beginDate} AND #{vo.endDate}
-                            </if>
-                        </where>
-
-                        GROUP BY DATE_FORMAT( a.signdate, '%Y-%m' )
-                    )  b  on b.singDateYear = DATE_FORMAT( a.signing_time, '%Y-%m' )
+                    sys_insurance_handling_settlement_month a
                 <where>
-                    a.settlement_sum_id IS NOT NULL
-                    AND settlement_status = '1'
+                    1=1
+                    <if test="vo.isNotCar !=null  and  vo.isNotCar  !=''">
+                        and a.is_not_car =#{vo.isNotCar}
+                    </if>
                 </where>
-                GROUP BY DATE_FORMAT( a.signing_time, '%Y-%m' )
-            )  c  on  c.singDateYear=DATE_FORMAT( a.signdate, '%Y-%m' )
+                GROUP BY
+                    DATE_FORMAT( a.signing_time, '%Y-%m' )
+            ) b ON a.subSigndate = b.subSigndate
+                left  join  (
+                select DATE_FORMAT( a.signing_time, '%Y-%m' ) as "subSigndate" ,  sum(settlement_amount) as "otherInvoic", sum(invoiced_settled_amount) as "settAmountOther", sum(Invoiced_not_settled_amount) as "invoicNotOther"
+                from
+                    settlement_documentary_fees  a
+                where a.settlement_status='1'
+                  and handling_fees_status ='1'
+                GROUP BY 	DATE_FORMAT( a.signing_time, '%Y-%m' )
+            )  c  on c.subSigndate=a.subSigndate
+    </select>
+
+    <select id="queryDateByTypeMonthSumAmount" resultType="java.math.BigDecimal">
+        SELECT
+        SUM(IFNULL(a.commission_feevalue ,0 ) + IFNULL(a.other_feevalue ,0 ))
+        FROM
+        ins_ply_income a
+        LEFT JOIN
+        ptl_agreement pa ON pa.id = a.agreement_id
         <where>
-            pa.agreement_type ='2'
-            <if test="vo.isNotCar !=null  and  vo.isNotCar  !=''">
-                and a.is_not_car =#{vo.isNotCar}
+            <if test="vo.type !=null  and  vo.type  !=''">
+                and pa.agreement_type =#{vo.type}
+            </if>
+            <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
+                AND  a.create_time  BETWEEN #{vo.beginDate} AND #{vo.endDate}
+            </if>
+        </where>
+    </select>
+    <select id="queryDateByTypeByMonth"
+            resultType="com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesAllMonthVo">
+        SELECT
+        SUM(IFNULL(a.commission_feevalue ,0 ) + IFNULL(a.other_feevalue ,0 )) AS ysSumAmount,
+        SUM(CASE WHEN a.handling_fees_status = '0' THEN IFNULL(a.commission_feevalue ,0 ) + IFNULL(a.other_feevalue ,0 ) ELSE 0 END ) AS "yisSumAmount",
+        SUM(CASE WHEN a.handling_fees_status = '1' THEN IFNULL(a.commission_feevalue ,0 ) + IFNULL(a.other_feevalue ,0 ) ELSE 0 END) AS "wsSumAmount"
+        FROM
+        ins_ply_income a
+        LEFT JOIN
+        ptl_agreement pa ON pa.id = a.agreement_id
+        <where>
+            1=1
+            <if test="vo.type !=null  and  vo.type  !=''">
+                and pa.agreement_type =#{vo.type}
             </if>
             <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
                 AND  a.signdate  BETWEEN #{vo.beginDate} AND #{vo.endDate}
             </if>
+            <if test="vo.yearAndMonth  != null  and  vo.yearAndMonth!=''">
+                AND   DATE_FORMAT(a.signdate, '%Y-%m') =#{vo.yearAndMonth}
+            </if>
         </where>
-        GROUP BY DATE_FORMAT( a.signdate, '%Y-%m' )
     </select>
     <select id="getProfitAnalysisQueryList" resultType="com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto">
         SELECT
-            a.signingTime as "signingTime",
-            a.sumpremium as "sumpremium",
-            b.allAmount as "sumcount",
-            d.settlement as "meet",
-            c.ActualPayment as "paid",
-            ifnull(d.settlement,0) - IFNULL(c.ActualPayment,0)  as "unpaid",
-            IFNULL( b.allAmount,0)- IFNULL (d.settlement,0)  as "grossProfit",
-            e.applyAmount  as "laborCost",
-            f.applyAmount  as "fixedCost",
-            j.applyAmount  as "variableCost",
+            a.signingTime as "yearAndMonth",
+            IFNULL(a.sumpremium,0) as "sumpremium",
+            IFNULL(b.allAmount,0) as "sumcount",
+            IFNULL(d.settlement,0) as "meet",
+            IFNULL(c.actualPayment,0) as "paid",
+            ifnull(d.settlement,0) - IFNULL(c.actualPayment,0)  as "unpaid",
+            IFNULL(b.allAmount,0)- IFNULL (d.settlement,0)  as "grossProfit",
+            IFNULL(e.applyAmount,0)  as "laborCost",
+            IFNULL(f.applyAmount,0)  as "fixedCost",
+            IFNULL(j.applyAmount,0)  as "variableCost",
             (IFNULL (b.allAmount,0) - IFNULL(d.settlement,0) ) -( IFNULL(e.applyAmount,0) + IFNULL(f.applyAmount,0) + IFNULL(j.applyAmount,0) ) as "operatingProfit",
-            g.applyAmount  as "税费",
+            IFNULL(g.applyAmount,0)  as "taxation",
             (IFNULL(b.allAmount,0)- IFNULL(d.settlement,0) ) -( IFNULL(e.applyAmount,0) + IFNULL(f.applyAmount,0) + IFNULL(j.applyAmount,0) ) - IFNULL(g.applyAmount,0) as "netProfit"
         FROM
             (
                 SELECT
-                    sum( iac.sumpremium ) as "sumpremium",
+                    IFNULL(sum( iac.jqpremium ),0) +IFNULL(sum( iac.sypremium ),0) + IFNULL(sum(iac.jypremium),0) as "sumpremium",
                     DATE_FORMAT( iac.signing_time, '%Y-%m' ) AS "signingTime"
                 FROM
                     `ins_fee_audit` ifa
@@ -2862,7 +2890,7 @@
             ) a
                 LEFT JOIN (
                 SELECT
-                    sum( ipi.commission_feevalue +ipi.other_feevalue ) as "allAmount",
+                    sum( ipi.commission_feevalue) + sum(ipi.other_feevalue ) as "allAmount",
                     DATE_FORMAT( ipi.signdate, '%Y-%m' ) AS "signingTime"
                 FROM
                     ins_ply_income ipi
@@ -2871,7 +2899,7 @@
             ) b ON a.signingTime = b.signingTime
                 left  join (
                 select
-                    sum(a.amount) as "ActualPayment",DATE_FORMAT( a.auditing_time, '%Y-%m' )  as "auditingTime"
+                    sum(a.amount) as "actualPayment",DATE_FORMAT( a.auditing_time, '%Y-%m' )  as "auditingTime"
                 from sys_amount_auditing a
                          left join sys_user_account_history b on a.id = b.auditiing_id
                          left join sys_user su on su.id =a.user_id
@@ -2888,15 +2916,17 @@
                     ins_fee_order_new ifo
                         LEFT JOIN ins_fee_audit ifa ON ifo.ins_order_no = ifa.ins_order_no
                         LEFT JOIN ins_area_company iac ON ifa.ins_order_no = iac.id
+                        LEFT JOIN ins_orders io ON iac.orderno = io.orderno
                 WHERE
                     ifa.auditstatus = '1'
                   AND iac.orderstatus = '3'
+                  AND io.orderstatus = '3'
                 GROUP BY
                     DATE_FORMAT( iac.signing_time, '%Y-%m' )
             ) d  on  d.signingTime =a.signingTime
         left join  (
                 SELECT
-                    sum(apply_amount) as "applyAmount",
+                    sum( CAST(a.apply_amount AS DECIMAL(10, 2))) as "applyAmount",
                     DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
                     b.expenditureDetails
                 FROM
@@ -2924,7 +2954,7 @@
             ) e on  e.createTime =a.signingTime
         left  join (
                 SELECT
-                    sum(apply_amount) as "applyAmount",
+                    sum( CAST(a.apply_amount AS DECIMAL(10, 2))) as "applyAmount",
                     DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
                     b.expenditureDetails
                 FROM
@@ -2952,7 +2982,7 @@
             ) f on  f.createTime =a.signingTime
             left join  (
                 SELECT
-                    sum(apply_amount) as "applyAmount",
+                    sum( CAST(a.apply_amount AS DECIMAL(10, 2))) as "applyAmount",
                     DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
                     b.expenditureDetails
                 FROM
@@ -2980,7 +3010,7 @@
             ) j on  j.createTime =a.signingTime
          left  join (
                 SELECT
-                    sum(apply_amount) as "applyAmount",
+                    sum( CAST(a.apply_amount AS DECIMAL(10, 2))) as "applyAmount",
                     DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
                     b.expenditureDetails
                 FROM
@@ -3039,4 +3069,77 @@
         </where>
         group by   a.task_id  , DATE_FORMAT( a.signdate, '%Y-%m' )
     </select>
+
+    <select id="queryDateByTypePt"  resultType="com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesVo">
+        SELECT IFNULL(a.signingTime, 0)     as "yearAndMonth",
+               IFNULL(a.allAmount, 0)       as "commissionFeevalue",
+               IFNULL(c.settAmount, 0)      as "noInvoicCommissionFeevalue",
+               IFNULL(b.notInvoicAmount, 0) as "noSettlementAmount",
+               IFNULL(c.settAmount, 0)      as "readyCommissionFeevalue"
+        FROM (SELECT sum(a.commission_feevalue) + sum(a.other_feevalue) AS "allAmount",
+                     DATE_FORMAT(a.signdate, '%Y-%m')                   as "signingTime"
+              FROM ins_ply_income a
+                       LEFT JOIN ptl_agreement pa ON pa.id = a.agreement_id
+                  <where>
+                      pa.agreement_type = '1'
+                      <if test="vo.year !=null  and  vo.year !=''">
+                       and   DATE_FORMAT( a.signdate, '%Y' ) =#{vo.year}
+                      </if>
+                  </where>
+              GROUP BY DATE_FORMAT(a.signdate, '%Y-%m')) a
+                 left join (SELECT sum(a.commission_feevalue) + sum(a.other_feevalue) AS "notInvoicAmount",
+                                   DATE_FORMAT(a.signdate, '%Y-%m')                   as "signingTime"
+                            FROM ins_ply_income a
+                                     LEFT JOIN ptl_agreement pa ON pa.id = a.agreement_id
+                            <where>
+                                pa.agreement_type = '1'
+                                and a.handling_fees_status = '0'
+                                <if test="vo.year !=null  and  vo.year !=''">
+                                    and   DATE_FORMAT( a.signdate, '%Y' ) =#{vo.year}
+                                </if>
+                            </where>
+                            GROUP BY DATE_FORMAT(a.signdate, '%Y-%m')) b on a.signingTime = b.signingTime
+                 left join (SELECT sum(a.commission_feevalue) + sum(a.other_feevalue) AS "settAmount",
+                                   DATE_FORMAT(a.signdate, '%Y-%m')                   as "signingTime"
+                            FROM ins_ply_income a
+                                     LEFT JOIN ptl_agreement pa ON pa.id = a.agreement_id
+                            <where>
+                                pa.agreement_type = '1'
+                                and a.handling_fees_status = '1'
+                                <if test="vo.year !=null  and  vo.year !=''">
+                                    and   DATE_FORMAT( a.signdate, '%Y' ) =#{vo.year}
+                                </if>
+                            </where>
+
+                            GROUP BY DATE_FORMAT(a.signdate, '%Y-%m')) c on c.signingTime = a.signingTime
+    </select>
+    <select id="getPatherId" resultType="com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesMonthVo">
+        SELECT
+        sa.area_cname as "areaName",
+        eic.namesimple as "companyName",
+        SUBSTRING( a.partner_companies_id, 6, 11 ) AS "subPathner",
+        a.company_id AS "companyId",
+        a.partner_companies_id AS "partnerCompaniesId"
+        FROM
+        ins_ply_income a
+        LEFT JOIN ptl_agreement pa ON a.agreement_id = pa.id
+        LEFT JOIN esm_ins_company  eic  on eic.id = a.company_id
+        LEFT JOIN sys_area  sa  on sa.area_code = SUBSTRING( a.partner_companies_id, 6, 11 )
+        <where>
+            <if test="vo.type !=null  and  vo.type!=''">
+                pa.agreement_type =#{vo.type}
+            </if>
+            <if test="vo.isNoCar  != null  and vo.isNoCar !='' ">
+                and   a.is_not_car =#{vo.isNoCar}
+            </if>
+            <if test="vo.yearAndMonth !=null  and  vo.yearAndMonth != ''">
+                and DATE_FORMAT( a.signdate, '%Y-%m' ) =#{vo.yearAndMonth}
+            </if>
+        </where>
+        GROUP BY
+        a.partner_companies_id,
+        a.company_id,
+        eic.namesimple,
+        sa.area_cname
+    </select>
 </mapper>

+ 1 - 1
src/main/resources/mapper/modules/order/InsAreaCompanyMapper.xml

@@ -874,7 +874,7 @@
                 agree.partner_companies_id = #{vo.parterCompanyId}
             </if>
             <if test="vo.beginDate  != null  and  vo.beginDate!=''  and vo.endDate  != null  and  vo.endDate!=''">
-                AND  iac.createtime  BETWEEN #{vo.beginDate} AND #{vo.endDate}
+                AND  iac.signing_time  BETWEEN #{vo.beginDate} AND #{vo.endDate}
             </if>
             <if test="vo.managementSource  != null  and  vo.managementSource!=''">
                 AND  sd.management_source  =#{vo.managementSource}