|
@@ -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);
|
|
|
+ }
|
|
|
+}
|