Browse Source

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 4 years ago
parent
commit
2d47b2994f

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SporadicChargeInfoDao.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.dal.dao;
 
+import com.ym.mec.biz.dal.dto.OrganMaxAmountDto;
 import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.entity.SporadicChargeInfo;
 import com.ym.mec.common.dal.BaseDAO;
@@ -14,6 +15,7 @@ public interface SporadicChargeInfoDao extends BaseDAO<Integer, SporadicChargeIn
 
     /**
      * 根据分部和类型获取活动信息
+     *
      * @param organId
      * @param chargeType
      * @return
@@ -22,8 +24,16 @@ public interface SporadicChargeInfoDao extends BaseDAO<Integer, SporadicChargeIn
 
     /**
      * 获取所有的活动分部
+     *
      * @param type
      * @return
      */
     List<Organization> getActiveOrgans(@Param("type") Integer type);
+
+    /**
+     * 获取活动分部的最大缴费金额
+     * @param type
+     * @return
+     */
+    List<OrganMaxAmountDto> getActiveOrgansMaxAmount(@Param("type") Integer type);
 }

+ 12 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/LuckStatisDto.java

@@ -20,7 +20,10 @@ public class LuckStatisDto {
     @ApiModelProperty(value = "总金额",required = true)
     private BigDecimal totalMoney = BigDecimal.ZERO;
 
-    @ApiModelProperty(value = "总转化率",required = true)
+    @ApiModelProperty(value = "总目标金额",required = true)
+    private BigDecimal totalMaxAmount= BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "总完成度",required = true)
     private BigDecimal scale = BigDecimal.ZERO;
 
     public List<OrderStatisDto> getOrderStatisDtoList() {
@@ -70,4 +73,12 @@ public class LuckStatisDto {
     public void setTotalTimes(Integer totalTimes) {
         this.totalTimes = totalTimes;
     }
+
+    public BigDecimal getTotalMaxAmount() {
+        return totalMaxAmount;
+    }
+
+    public void setTotalMaxAmount(BigDecimal totalMaxAmount) {
+        this.totalMaxAmount = totalMaxAmount;
+    }
 }

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/OrderStatisDto.java

@@ -1,5 +1,7 @@
 package com.ym.mec.biz.dal.dto;
 
+import io.swagger.annotations.ApiModelProperty;
+
 import java.math.BigDecimal;
 
 public class OrderStatisDto {
@@ -10,6 +12,8 @@ public class OrderStatisDto {
     private Integer times = 0;
     private BigDecimal scale = BigDecimal.ZERO;
     private BigDecimal money = BigDecimal.ZERO;
+    @ApiModelProperty(value = "目标金额", required = true)
+    private BigDecimal maxAmount = BigDecimal.ZERO;
 
     public Integer getOrganId() {
         return organId;
@@ -66,4 +70,12 @@ public class OrderStatisDto {
     public void setTimes(Integer times) {
         this.times = times;
     }
+
+    public BigDecimal getMaxAmount() {
+        return maxAmount;
+    }
+
+    public void setMaxAmount(BigDecimal maxAmount) {
+        this.maxAmount = maxAmount;
+    }
 }

+ 36 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/OrganMaxAmountDto.java

@@ -0,0 +1,36 @@
+package com.ym.mec.biz.dal.dto;
+
+import java.math.BigDecimal;
+
+public class OrganMaxAmountDto {
+    //分部id
+    private Integer id;
+
+    private String name;
+
+    private BigDecimal maxAmount;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public BigDecimal getMaxAmount() {
+        return maxAmount;
+    }
+
+    public void setMaxAmount(BigDecimal maxAmount) {
+        this.maxAmount = maxAmount;
+    }
+}

+ 8 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -305,11 +305,14 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             if (chargeInfo.getOpenMaxTerm().equals(YesOrNoEnum.YES) && chargeInfo.getMaxAmount().compareTo(chargeInfo.getPaidAmount()) <= 0) {
                 throw new Exception("活动人数暂时已满,请稍后再试");
             }
-            chargeInfo.setPaidAmount(chargeInfo.getPaidAmount().add(chargeInfo.getAmount()));
-            chargeInfo.setUpdateTime(new Date());
-            int update = sporadicChargeInfoDao.update(chargeInfo);
-            if (update <= 0) {
-                throw new BizException("活动火爆,请稍后再试");
+            List<SporadicChargeInfo> activeInfos = sporadicChargeInfoDao.getOrganActiveInfo(chargeInfo.getOrganId(), 12);
+            for (SporadicChargeInfo activeInfo : activeInfos) {
+                activeInfo.setPaidAmount(activeInfo.getPaidAmount().add(chargeInfo.getAmount()));
+                activeInfo.setUpdateTime(new Date());
+                int update = sporadicChargeInfoDao.update(activeInfo);
+                if (update <= 0) {
+                    throw new BizException("活动火爆,请稍后再试");
+                }
             }
         }
 

+ 8 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SporadicChargeInfoImpl.java

@@ -149,11 +149,14 @@ public class SporadicChargeInfoImpl extends BaseServiceImpl<Integer, SporadicCha
         }
         if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
             if (info.getMaxAmount() != null && info.getPaidAmount().compareTo(BigDecimal.ZERO) > 0) {
-                info.setPaidAmount(info.getPaidAmount().subtract(studentPaymentOrder.getActualAmount()));
-                info.setUpdateTime(new Date());
-                int update = sporadicChargeInfoDao.update(info);
-                if (update <= 0) {
-                    throw new BizException("已收金额更新失败,请重试");
+                List<SporadicChargeInfo> activeInfos = sporadicChargeInfoDao.getOrganActiveInfo(info.getOrganId(), 12);
+                for (SporadicChargeInfo activeInfo : activeInfos) {
+                    activeInfo.setPaidAmount(activeInfo.getPaidAmount().subtract(info.getAmount()));
+                    activeInfo.setUpdateTime(new Date());
+                    int update = sporadicChargeInfoDao.update(activeInfo);
+                    if (update <= 0) {
+                        throw new BizException("已收金额更新失败,请重试");
+                    }
                 }
             }
             if (info.getOrganId().equals(42) && info.getChargeType().equals(SporadicChargeTypeEnum.LEVEL)) {

+ 9 - 0
mec-biz/src/main/resources/config/mybatis/SporadicChargeInfo.xml

@@ -185,4 +185,13 @@
           AND sci.del_flag_ = 0
         GROUP BY o.id_
     </select>
+
+    <select id="getActiveOrgansMaxAmount" resultType="com.ym.mec.biz.dal.dto.OrganMaxAmountDto">
+        SELECT o.id_ id,o.name_ name ,(SUM(sci.max_amount_)/COUNT(*)) maxAmount
+        FROM sporadic_charge_info sci
+        LEFT JOIN organization o ON o.id_ = sci.organ_id_
+        WHERE sci.charge_type_ = #{type}
+        AND sci.del_flag_ = 0
+        GROUP BY o.id_
+    </select>
 </mapper>

+ 20 - 7
mec-web/src/main/java/com/ym/mec/web/controller/education/ActivityController.java

@@ -6,6 +6,7 @@ import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
 import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
 import com.ym.mec.biz.dal.dto.LuckStatisDto;
 import com.ym.mec.biz.dal.dto.OrderStatisDto;
+import com.ym.mec.biz.dal.dto.OrganMaxAmountDto;
 import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
@@ -43,6 +44,8 @@ public class ActivityController extends BaseController {
         Set<Integer> orderOrganIds = orders.stream().map(OrderStatisDto::getOrganId).collect(Collectors.toSet());
         //获取所有分部预计的人数
         List<OrderStatisDto> organNormalStudents = studentRegistrationDao.getOrganNormalStudent();
+        //获取分部的目标金额
+        List<OrganMaxAmountDto> maxAmount4Organs = sporadicChargeInfoDao.getActiveOrgansMaxAmount(12);
 
         for (Organization organ : organs) {
             if (!orderOrganIds.contains(organ.getId())) {
@@ -56,7 +59,15 @@ public class ActivityController extends BaseController {
         Integer totalEstimatedNums = 0;
         Integer totalNum = 0;
         Integer totalTimes = 0;
+        BigDecimal totalMaxAmount = BigDecimal.ZERO;
         for (OrderStatisDto order : orders) {
+            for (OrganMaxAmountDto maxAmount4Organ : maxAmount4Organs) {
+                if (order.getOrganId().equals(maxAmount4Organ.getId())) {
+                    order.setMaxAmount(maxAmount4Organ.getMaxAmount() == null ? BigDecimal.ZERO.setScale(2) : maxAmount4Organ.getMaxAmount().setScale(2));
+                    break;
+                }
+            }
+
             for (OrderStatisDto organNormalStudent : organNormalStudents) {
                 if (order.getOrganId().equals(organNormalStudent.getOrganId())) {
                     order.setEstimatedNums(organNormalStudent.getEstimatedNums());
@@ -67,10 +78,11 @@ public class ActivityController extends BaseController {
             totalNum += order.getNums();
             totalTimes += order.getTimes();
             totalMoney = totalMoney.add(order.getMoney());
-            if (order.getEstimatedNums() <= 0) {
-                order.setScale(new BigDecimal(order.getNums()).multiply(new BigDecimal(100)).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP));
-            }else {
-                order.setScale(new BigDecimal(order.getNums()).multiply(new BigDecimal(100)).divide(new BigDecimal(order.getEstimatedNums()), 2, BigDecimal.ROUND_HALF_UP));
+            totalMaxAmount = totalMaxAmount.add(order.getMaxAmount());
+            if (order.getMaxAmount().compareTo(BigDecimal.ZERO) <= 0) {
+                order.setScale(new BigDecimal("100.00"));
+            } else {
+                order.setScale(order.getMoney().multiply(new BigDecimal(100)).divide(order.getMaxAmount(), 2, BigDecimal.ROUND_HALF_UP));
             }
         }
         orders.sort(Comparator.comparing(OrderStatisDto::getMoney).reversed());
@@ -81,10 +93,11 @@ public class ActivityController extends BaseController {
         luckStatisDto.setTotalNum(totalNum);
         luckStatisDto.setTotalTimes(totalTimes);
         luckStatisDto.setTotalMoney(totalMoney);
-        if (luckStatisDto.getTotalEstimatedNums() <= 0) {
-            totalEstimatedNums = 1;
+        luckStatisDto.setTotalMaxAmount(totalMaxAmount);
+        if (luckStatisDto.getTotalMaxAmount().compareTo(BigDecimal.ZERO) <= 0) {
+            totalMaxAmount = BigDecimal.ONE;
         }
-        luckStatisDto.setScale(new BigDecimal(totalNum).multiply(new BigDecimal(100)).divide(new BigDecimal(totalEstimatedNums), 2, BigDecimal.ROUND_HALF_UP));
+        luckStatisDto.setScale(totalMoney.multiply(new BigDecimal(100)).divide(totalMaxAmount, 2, BigDecimal.ROUND_HALF_UP));
         return succeed(luckStatisDto);
     }
 }