Explorar o código

1.人员渠道毛利润显示

wuhp hai 1 ano
pai
achega
f1696da37a

+ 3 - 0
src/main/java/com/ydtech/modules/admin/model/dto/QxFrontlineAgentDto.java

@@ -129,6 +129,9 @@ public class QxFrontlineAgentDto implements Serializable {
     @ApiModelProperty(value = "是否出单 0  不出单  1 出单")
     private String outThere;
 
+    @ApiModelProperty(value = "预计利润")
+    private BigDecimal estimatedProfit;
+
     private Integer totalManpowerNum;
 
     private Double totalPremiumNum;

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

@@ -62,4 +62,7 @@ public class BusinessAgentData {
     @ApiModelProperty(value = "部门id")
     private String deptId;
 
+    @ApiModelProperty(value = "管理人名称")
+    private String leaderName;
+
 }

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

@@ -269,6 +269,10 @@ public class UserReportServiceImpl implements UserReportService {
                         }
                     }
                 }
+                //预期净利润
+                BigDecimal ExpectNetProfit = insAreaCompanyService.getExpectNetProfit(dto.getUserId());
+                dto.setEstimatedProfit(ExpectNetProfit);
+
             }
             resultPage.setContent(qxFrontlineAgentDtos);
             resultPage.setPageNum(qxFrontlineAgentVo.getPageNum());

+ 16 - 0
src/main/java/com/ydtech/modules/order/dao/InsAreaCompanyMapper.java

@@ -377,6 +377,13 @@ public interface InsAreaCompanyMapper extends BaseMapper<InsAreaCompany> {
      * @date: 2024/10/12
      **/
     TaskStatisticsDto getCountBusinessData(@Param("vo") TaskStatisticsVo taskStatisticsVo);
+
+    /**
+     * @param userId
+     * @return  入口金额 出口金额  分销金额
+     */
+    InsAreaCompany getExpectNetProfit(String userId);
+
     /**
      *  @version
      *  @author: hxl
@@ -384,6 +391,15 @@ public interface InsAreaCompanyMapper extends BaseMapper<InsAreaCompany> {
      *  @Description: 查询已承保的保单数据
      */
     Page<InsOrders> queryPageOrderCB(@Param("page") Page<InsAreaCompany> page, @Param("params") OrderQueryVo orderQueryVo);
+
+    /**
+     *
+     *
+     * @param userId
+     * @return  通过 用户id 获取1-3 级分销金额
+     */
+    HashMap<String, BigDecimal> getDistributionAllAmount(String userId);
+
 }
 
 

+ 9 - 0
src/main/java/com/ydtech/modules/order/entity/InsAreaCompany.java

@@ -558,6 +558,15 @@ public class InsAreaCompany implements Serializable {
     @TableField(value = "leader_name")
     private String leaderName;
 
+    //入口总金额
+    @TableField(exist = false)
+    private BigDecimal entranceAllFee;
+
+
+    //出口总金额
+    @TableField(exist = false)
+    private BigDecimal exportAllFee;
+
     public InsAreaCompany(QuoteRespVo quoteRespVo, PtlAgreementAttribution ptlAgreementAttribution) {
         this.id = IdGenerate.nextId();
         this.orderno = quoteRespVo.getOrderno();

+ 7 - 0
src/main/java/com/ydtech/modules/order/service/InsAreaCompanyService.java

@@ -274,4 +274,11 @@ public interface InsAreaCompanyService extends IService<InsAreaCompany> {
      *  @Description: 查詢已承保的保单数据
      */
     Page<InsOrders> queryPageOrderCB(Page<InsAreaCompany> page, OrderQueryVo orderQueryVo);
+
+    /**
+     *  通过用户id获取预收净利润
+     * @param userId
+     * @return
+     */
+    BigDecimal getExpectNetProfit(String userId);
 }

+ 20 - 0
src/main/java/com/ydtech/modules/order/service/impl/InsAreaCompanyServiceImpl.java

@@ -1116,6 +1116,26 @@ public class InsAreaCompanyServiceImpl extends ServiceImpl<InsAreaCompanyMapper,
     public Page<InsOrders> queryPageOrderCB(Page<InsAreaCompany> page, OrderQueryVo orderQueryVo) {
         return  baseMapper.queryPageOrderCB(page, orderQueryVo);
     }
+
+    @Override
+    public BigDecimal getExpectNetProfit(String userId) {
+
+        InsAreaCompany insAreaCompany = baseMapper.getExpectNetProfit(userId);
+        if(!ObjectUtils.isEmpty(insAreaCompany)){
+            BigDecimal entranceAllFee = insAreaCompany.getEntranceAllFee();// 入口金额
+            BigDecimal exportAllFee = insAreaCompany.getExportAllFee(); // 出口金额
+            // 计算三级分销金额
+            HashMap<String,BigDecimal> distribution  =baseMapper.getDistributionAllAmount(userId);
+            if(!distribution.isEmpty()){
+                BigDecimal bigDecimal = distribution.get("distributionAmount");
+                // 利润= 入口- 出口 - 分销
+                return entranceAllFee.subtract(exportAllFee).subtract(bigDecimal);
+            }else {
+                return entranceAllFee.subtract(exportAllFee) ;
+            }
+        }
+        return BigDecimal.ZERO;
+    }
 }
 
 

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

@@ -3283,4 +3283,62 @@
         order by iac.createtime desc
     </select>
 
+    <select id="getExpectNetProfit" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
+        select
+        IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL (ifon.no_costs_premiums,0) as "entranceAllFee",
+        IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0) +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
+        +IFNULL(no_export_supervise_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0)  as "exportAllFee"
+        from ins_area_company iac
+        left join ins_orders io on io.orderno = iac.orderno
+        LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
+        <where>
+            <if test="userId !=null  and  userId  !=''">
+                iac.leader_id  =#{userId}
+            </if>
+        </where>
+    </select>
+
+    <select id="getDistributionAllAmount" resultType="java.util.HashMap">
+        select
+        IFNULL(sum(IFNULL(first_detail_premiums,0)),0) + IFNULL(b.secondDetailPremiums,0) +IFNULL(c.thirdDetailPremiums,0) as "distributionAmount"
+        from ins_area_company iac
+        left join ins_orders io on io.orderno = iac.orderno
+        LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
+        <where>
+            <if test="userId !=null  and  userId  !=''">
+                ifon.first_level_user_id  =#{userId}
+            </if>
+        </where>
+        group  by   ifon.first_level_user_id
+        left join  (
+        select
+        sum(IFNULL(second_detail_premiums,0)) as "secondDetailPremiums",
+        ifon.two_level_user_id as "twoLevelUserId",
+        from ins_area_company iac
+        left join ins_orders io on io.orderno = iac.orderno
+        LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
+        <where>
+            <if test="userId !=null  and  userId  !=''">
+                ifon.two_level_user_id  =#{userId}
+            </if>
+        </where>
+        group  by   ifon.two_level_user_id
+        )  b  on b.twoLevelUserId  =ifon.first_level_user_id
+        left  join  (
+        select
+        sum(IFNULL(third_detail_premiums,0)) as "thirdDetailPremiums",
+        ifon.three_level_user_id as "threeLevelUserId",
+        from ins_area_company iac
+        left join ins_orders io on io.orderno = iac.orderno
+        LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
+        <where>
+            <if test="userId !=null  and  userId  !=''">
+                ifon.three_level_user_id  =#{userId}
+            </if>
+        </where>
+        group  by   ifon.three_level_user_id
+        ) c on  c.threeLevelUserId = ifon.first_level_user_id
+
+    </select>
+
 </mapper>