فهرست منبع

增加双十一活动接口

周箭河 4 سال پیش
والد
کامیت
8f723cf397

+ 47 - 0
mec-student/src/main/java/com/ym/mec/student/controller/ActivityController.java

@@ -0,0 +1,47 @@
+package com.ym.mec.student.controller;
+
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.entity.SporadicChargeInfo;
+import com.ym.mec.biz.service.SporadicChargeInfoService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Comparator;
+import java.util.List;
+
+@RequestMapping("activity")
+@Api(tags = "活动")
+@RestController
+public class ActivityController extends BaseController {
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
+    @Autowired
+    private SporadicChargeInfoService sporadicChargeInfoService;
+
+    @ApiOperation(value = "分部双11活动信息")
+    @GetMapping("/doubleEleven2020")
+    public HttpResponseResult<List<SporadicChargeInfo>> doubleEleven2020() throws Exception {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null || sysUser.getId() == null) {
+            return failed("请先登录");
+        }
+        if (sysUser.getOrganId() == null) {
+            return failed("用户信息有误,没有分部信息");
+        }
+        Integer organId = sysUser.getOrganId();
+
+        List<SporadicChargeInfo> activeInfos = sporadicChargeInfoService.getOrganActiveInfo(organId, 12);
+        activeInfos.sort(Comparator.comparing(SporadicChargeInfo::getAmount).reversed());
+        if (activeInfos.size() <= 0) {
+            return failed("分部活动不存在");
+        }
+        return succeed(activeInfos);
+    }
+}

+ 86 - 0
mec-web/src/main/java/com/ym/mec/web/controller/education/ActivityController.java

@@ -0,0 +1,86 @@
+package com.ym.mec.web.controller.education;
+
+
+import com.ym.mec.biz.dal.dao.SporadicChargeInfoDao;
+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.entity.Organization;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@RequestMapping("activity")
+@Api(tags = "活动")
+@RestController
+public class ActivityController extends BaseController {
+    @Autowired
+    private StudentPaymentOrderDao studentPaymentOrderDao;
+    @Autowired
+    private SporadicChargeInfoDao sporadicChargeInfoDao;
+    @Autowired
+    private StudentRegistrationDao studentRegistrationDao;
+
+    @ApiOperation(value = "分部双11活动统计")
+    @GetMapping("/doubleEleven2020Statis")
+    public HttpResponseResult<LuckStatisDto> doubleEleven2020Statis() {
+        //获取所有参与分部
+        List<Organization> organs = sporadicChargeInfoDao.getActiveOrgans(12);
+        //获取所有分部参与的订单
+        List<OrderStatisDto> orders = studentPaymentOrderDao.doubleEleven2020Statis(organs);
+        Set<Integer> orderOrganIds = orders.stream().map(OrderStatisDto::getOrganId).collect(Collectors.toSet());
+        //获取所有分部预计的人数
+        List<OrderStatisDto> organNormalStudents = studentRegistrationDao.getOrganNormalStudent();
+
+        for (Organization organ : organs) {
+            if (!orderOrganIds.contains(organ.getId())) {
+                OrderStatisDto orderStatisDto = new OrderStatisDto();
+                orderStatisDto.setOrganId(organ.getId());
+                orderStatisDto.setOrganName(organ.getName());
+                orders.add(orderStatisDto);
+            }
+        }
+        BigDecimal totalMoney = BigDecimal.ZERO;
+        Integer totalEstimatedNums = 0;
+        Integer totalNum = 0;
+        for (OrderStatisDto order : orders) {
+            for (OrderStatisDto organNormalStudent : organNormalStudents) {
+                if (order.getOrganId().equals(organNormalStudent.getOrganId())) {
+                    order.setEstimatedNums(organNormalStudent.getEstimatedNums());
+                    break;
+                }
+            }
+            totalEstimatedNums += order.getEstimatedNums();
+            totalNum += order.getNums();
+            totalMoney = totalMoney.add(order.getMoney());
+            if (order.getEstimatedNums() <= 0) {
+                order.setEstimatedNums(1);
+            }
+            order.setScale(new BigDecimal(order.getNums()).multiply(new BigDecimal(100)).divide(new BigDecimal(order.getEstimatedNums()), 2, BigDecimal.ROUND_HALF_UP));
+        }
+        orders.sort(Comparator.comparing(OrderStatisDto::getMoney).reversed());
+
+        LuckStatisDto luckStatisDto = new LuckStatisDto();
+        luckStatisDto.setOrderStatisDtoList(orders);
+        luckStatisDto.setTotalEstimatedNums(totalEstimatedNums);
+        luckStatisDto.setTotalNum(totalNum);
+        luckStatisDto.setTotalMoney(totalMoney);
+        if (luckStatisDto.getTotalEstimatedNums() <= 0) {
+            totalEstimatedNums = 1;
+        }
+        luckStatisDto.setScale(new BigDecimal(totalNum).multiply(new BigDecimal(100)).divide(new BigDecimal(totalEstimatedNums), 2, BigDecimal.ROUND_HALF_UP));
+        return succeed(luckStatisDto);
+    }
+}