StudentOrderController.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. package com.ym.mec.student.controller;
  2. import com.ym.mec.biz.dal.enums.OrderTypeEnum;
  3. import io.swagger.annotations.Api;
  4. import io.swagger.annotations.ApiImplicitParam;
  5. import io.swagger.annotations.ApiImplicitParams;
  6. import io.swagger.annotations.ApiOperation;
  7. import java.io.IOException;
  8. import java.math.BigDecimal;
  9. import java.net.URLEncoder;
  10. import java.util.ArrayList;
  11. import java.util.Arrays;
  12. import java.util.Comparator;
  13. import java.util.HashMap;
  14. import java.util.Iterator;
  15. import java.util.LinkedHashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.Objects;
  19. import java.util.stream.Collectors;
  20. import javax.servlet.http.HttpServletResponse;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.scheduling.annotation.EnableScheduling;
  26. import org.springframework.web.bind.annotation.GetMapping;
  27. import org.springframework.web.bind.annotation.ModelAttribute;
  28. import org.springframework.web.bind.annotation.PostMapping;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import org.springframework.web.bind.annotation.RequestParam;
  31. import org.springframework.web.bind.annotation.RestController;
  32. import com.alibaba.fastjson.JSON;
  33. import com.huifu.adapay.model.payment.PayChannelEnum;
  34. import com.huifu.adapay.model.payment.Payment;
  35. import com.ym.mec.biz.dal.dao.CourseScheduleEvaluateDao;
  36. import com.ym.mec.biz.dal.dao.OrganizationDao;
  37. import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
  38. import com.ym.mec.biz.dal.dao.SysConfigDao;
  39. import com.ym.mec.biz.dal.dao.TeacherCourseStatisticsDao;
  40. import com.ym.mec.biz.dal.dto.LuckStatisDto;
  41. import com.ym.mec.biz.dal.dto.OrderStatisDto;
  42. import com.ym.mec.biz.dal.dto.PracticeGroupsDto;
  43. import com.ym.mec.biz.dal.dto.VipBuyResultDto;
  44. import com.ym.mec.biz.dal.dto.practiceGroupStatisDto;
  45. import com.ym.mec.biz.dal.entity.Goods;
  46. import com.ym.mec.biz.dal.entity.MusicGroup;
  47. import com.ym.mec.biz.dal.entity.Organization;
  48. import com.ym.mec.biz.dal.entity.SporadicChargeInfo;
  49. import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
  50. import com.ym.mec.biz.dal.enums.DealStatusEnum;
  51. import com.ym.mec.biz.dal.enums.GroupType;
  52. import com.ym.mec.biz.service.MusicGroupService;
  53. import com.ym.mec.biz.service.SporadicChargeInfoService;
  54. import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
  55. import com.ym.mec.biz.service.StudentPaymentOrderService;
  56. import com.ym.mec.biz.service.StudentRegistrationService;
  57. import com.ym.mec.biz.service.VipGroupService;
  58. import com.ym.mec.common.controller.BaseController;
  59. import com.ym.mec.common.entity.HttpResponseResult;
  60. import com.ym.mec.thirdparty.adapay.NotifyEvent;
  61. import com.ym.mec.thirdparty.adapay.Pay;
  62. import com.ym.mec.thirdparty.yqpay.Msg;
  63. import com.ym.mec.thirdparty.yqpay.RsqMsg;
  64. import com.ym.mec.thirdparty.yqpay.YqPayFeignService;
  65. import com.ym.mec.thirdparty.yqpay.YqPayUtil;
  66. import com.ym.mec.util.http.HttpUtil;
  67. @RequestMapping("studentOrder")
  68. @Api(tags = "订单回调")
  69. @RestController
  70. @EnableScheduling
  71. public class StudentOrderController extends BaseController {
  72. private static final Logger logger = LoggerFactory.getLogger(StudentOrderController.class);
  73. @Autowired
  74. private StudentPaymentOrderService studentPaymentOrderService;
  75. @Autowired
  76. private StudentRegistrationService studentRegistrationService;
  77. @Autowired
  78. private VipGroupService vipGroupService;
  79. @Autowired
  80. private MusicGroupService musicGroupService;
  81. @Autowired
  82. private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
  83. @Autowired
  84. private YqPayFeignService yqPayFeignService;
  85. @Autowired
  86. private StudentPaymentOrderDao studentPaymentOrderDao;
  87. @Autowired
  88. private SysConfigDao sysConfigDao;
  89. @Autowired
  90. private SporadicChargeInfoService sporadicChargeInfoService;
  91. @Autowired
  92. private OrganizationDao organizationDao;
  93. @Autowired
  94. private TeacherCourseStatisticsDao teacherCourseStatisticsDao;
  95. @Autowired
  96. private CourseScheduleEvaluateDao courseScheduleEvaluateDao;
  97. @PostMapping("/notify")
  98. public Msg notify(@ModelAttribute Msg msg) throws Exception {
  99. logger.info(msg.toString());
  100. Map<String, Object> rqMap = new LinkedHashMap<String, Object>();
  101. rqMap.put("code", msg.getCode());
  102. rqMap.put("msg", msg.getMsg());
  103. rqMap.put("responseType", msg.getResponseType());
  104. rqMap.put("responseParameters", msg.getResponseParameters());
  105. rqMap.put("sign", msg.getSign());
  106. //boolean rs = YqPayUtil.verify(rqMap);
  107. msg.setMsg("fail");
  108. Map<String, String> notifyMap = new HashMap<>();
  109. //if (rs) {
  110. notifyMap = JSON.parseObject(msg.getResponseParameters(), Map.class);
  111. //}
  112. //支付中订单存在,更新状态
  113. if (msg.getResponseType().equals("1") && notifyMap.size() > 0) {
  114. String tradeState = msg.getCode().equals("88") ? "1" : "0";
  115. String channelType = notifyMap.get("channelType").equals("1") ? "WXPay" : (notifyMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
  116. notifyMap.put("tradeState", tradeState);
  117. notifyMap.put("totalMoney", notifyMap.get("payAmount"));
  118. notifyMap.put("merOrderNo", notifyMap.get("merMerOrderNo"));
  119. notifyMap.put("channelType", channelType);
  120. studentPaymentOrderService.updateOrder(notifyMap);
  121. msg.setCode("000000");
  122. msg.setMsg("success");
  123. }
  124. return msg;
  125. }
  126. @ApiOperation(value = "查询订单状态")
  127. @PostMapping("/checkOrderStatus")
  128. public Object checkOrderStatus(String orderNo) {
  129. if (StringUtils.isBlank(orderNo)) {
  130. return failed("请指定订单");
  131. }
  132. StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(orderNo);
  133. if (Objects.isNull(orderByOrderNo)) {
  134. return failed("未找到指定订单");
  135. }
  136. HashMap<String, Object> orderDetail = new HashMap<>();
  137. orderDetail.put("order", orderByOrderNo);
  138. orderDetail.put("groupType", orderByOrderNo.getGroupType());
  139. if (orderByOrderNo.getGroupType().equals(GroupType.MUSIC)) {
  140. MusicGroup musicGroup = musicGroupService.get(orderByOrderNo.getMusicGroupId());
  141. List<Goods> goodsList = studentPaymentOrderDetailService.findApplyOrderGoods(orderByOrderNo.getId());
  142. orderDetail.put("goods", goodsList);
  143. orderDetail.put("course", musicGroup.getCourseForm());
  144. orderDetail.put("ownershipType", musicGroup.getOwnershipType());
  145. } else if (orderByOrderNo.getGroupType().equals(GroupType.VIP)) {
  146. VipBuyResultDto vipBuyResultInfo = vipGroupService.findVipBuyResultInfo(Integer.valueOf(orderByOrderNo.getMusicGroupId()));
  147. orderDetail.put("detail", vipBuyResultInfo);
  148. } else if (orderByOrderNo.getGroupType().equals(GroupType.SPORADIC)) {
  149. SporadicChargeInfo info = sporadicChargeInfoService.get(Integer.valueOf(orderByOrderNo.getMusicGroupId()));
  150. orderDetail.put("detail", info);
  151. }
  152. return succeed(orderDetail);
  153. }
  154. @ApiOperation(value = "台牌支付")
  155. @PostMapping("/executePayment")
  156. @ApiImplicitParams({
  157. @ApiImplicitParam(name = "amount", value = "支付金额", required = true, dataType = "BigDecimal"),
  158. @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String"),
  159. @ApiImplicitParam(name = "payChannel", value = "支付方式(alipay-支付宝app支付)", required = true, dataType = "String"),
  160. })
  161. public Object executePayment(BigDecimal amount, String orderNo, String payChannel, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sign, String code) throws Exception {
  162. String appId = "wxcf8e8b33a9477845";
  163. String appSecret = "1286452b9c68b13325dece7cdf892645";
  164. String wxMpOAuth2AccessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
  165. payChannel = PayChannelEnum.ALIPAY_QR.getCode();
  166. // if (!new Pay().verifySign(amount, orderNo, notifyUrl, orderSubject, orderBody,sign)) {
  167. // return failed("签名验证失败");
  168. // }
  169. String openid = "";
  170. if (payChannel == "wx_pub") {
  171. if (code == null || code.isEmpty()) {
  172. return failed("微信支付请先授权");
  173. }
  174. wxMpOAuth2AccessTokenUrl = String.format(wxMpOAuth2AccessTokenUrl, appId, appSecret, code);
  175. Map<String, String> weChatRes = JSON.parseObject(HttpUtil.get(wxMpOAuth2AccessTokenUrl, new HashMap<>()), Map.class);
  176. if (!weChatRes.containsKey("openid")) {
  177. return failed("授权失败,请重新授权");
  178. }
  179. openid = weChatRes.get("openid");
  180. }
  181. StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(orderNo);
  182. if (order == null) {
  183. return failed("订单不存在");
  184. }
  185. Payment payment = new Pay().executePayment(amount, orderNo, payChannel, orderSubject, orderBody, code);
  186. order.setTransNo(payment.getId());
  187. studentPaymentOrderService.update(order);
  188. return succeed(payment);
  189. }
  190. @PostMapping("/adaNotify")
  191. public void adaNotify(@ModelAttribute NotifyEvent notifyEvent) throws Exception {
  192. logger.info(notifyEvent.toString());
  193. if (notifyEvent.getType().equals("payment.success") && notifyEvent.getType().equals("payment.failed")) {
  194. return;
  195. }
  196. Map<String, String> notifyMap = JSON.parseObject(notifyEvent.getData(), Map.class);
  197. //支付中订单存在,更新状态
  198. if (notifyMap.size() > 0) {
  199. String tradeState = notifyEvent.getType().equals("payment.success") ? "1" : "0";
  200. notifyMap.put("tradeState", tradeState);
  201. notifyMap.put("totalMoney", notifyMap.get("pay_amt"));
  202. notifyMap.put("merOrderNo", notifyMap.get("order_no"));
  203. notifyMap.put("merOrderNo", notifyMap.get("order_no"));
  204. notifyMap.put("remarks", notifyMap.get("description"));
  205. studentPaymentOrderService.updateOrder(notifyMap);
  206. }
  207. }
  208. @GetMapping("/authorize")
  209. public String authorize(@RequestParam("returnUrl") String returnUrl) {
  210. String appId = "wxcf8e8b33a9477845";
  211. String url = URLEncoder.encode("http://wxwechat.utools.club/studentOrder/userInfo");
  212. String redirectURL = String.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect",
  213. appId, url);
  214. return "redirect:" + redirectURL;
  215. }
  216. @GetMapping("/userInfo")
  217. public Object userInfo(@RequestParam("code") String code,
  218. @RequestParam("state") String returnUrl) throws Exception {
  219. String appId = "wxcf8e8b33a9477845";
  220. String appSecret = "1286452b9c68b13325dece7cdf892645";
  221. String wxMpOAuth2AccessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
  222. wxMpOAuth2AccessTokenUrl = String.format(wxMpOAuth2AccessTokenUrl, appId, appSecret, code);
  223. Map<String, String> map = JSON.parseObject(HttpUtil.get(wxMpOAuth2AccessTokenUrl, new HashMap<>()), Map.class);
  224. if (!map.containsKey("openid")) {
  225. return failed("授权失败,请重新授权");
  226. }
  227. return map.get("openid");
  228. }
  229. // @Scheduled(cron = "0/30 * * * * ?")
  230. @GetMapping("/setSuccessStatus")
  231. public void setSuccessStatus() throws Exception {
  232. List<StudentPaymentOrder> payingOrders = studentPaymentOrderService.findOrdersByStatus(DealStatusEnum.ING, "YQPAY");
  233. String[] statusArr = {"0", "1", "7"};
  234. for (StudentPaymentOrder payingOrder : payingOrders) {
  235. Map<String, String> rpMap = new HashMap<>();
  236. rpMap.put("tradeState", "1");
  237. rpMap.put("remarks", "模拟支付成功");
  238. rpMap.put("merOrderNo", payingOrder.getOrderNo());
  239. rpMap.put("orderNo", payingOrder.getOrderNo());
  240. rpMap.put("channelType", "1");
  241. String channelType = rpMap.get("channelType").equals("1") ? "WXPay" : (rpMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
  242. rpMap.put("channelType", channelType);
  243. if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
  244. try {
  245. studentPaymentOrderService.updateOrder(rpMap); //更新订单
  246. } catch (Exception e) {
  247. e.printStackTrace();
  248. continue;
  249. }
  250. }
  251. }
  252. }
  253. @GetMapping("/getOrderStatus")
  254. private HttpResponseResult getOrderStatus(String orderNo) throws Exception {
  255. if (orderNo == null || orderNo.isEmpty()) {
  256. return failed("订单号必须填");
  257. }
  258. String notifyUrl = ""; //回调地址
  259. Map<String, Object> resultMap = new LinkedHashMap<>();
  260. resultMap.put("merOrderNoList", orderNo);
  261. Map<String, Object> requestMap = YqPayUtil.getRequestMap(notifyUrl, resultMap);
  262. RsqMsg rsqMsg = new RsqMsg(requestMap);
  263. Msg queryRs = yqPayFeignService.orderQuery(rsqMsg);
  264. if (queryRs.getCode().equals("88")) {
  265. String responseParameters = queryRs.getResponseParameters();
  266. List<Map<String, Object>> responseList = JSON.parseObject(responseParameters, List.class);
  267. return succeed(responseList);
  268. }
  269. return succeed("订单不存在");
  270. }
  271. @RequestMapping("paymentResult")
  272. public void paymentResult(HttpServletResponse response, String orderNo) {
  273. try {
  274. String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
  275. response.sendRedirect(baseApiUrl + "/#/paymentresult?orderNo=" + orderNo);
  276. } catch (IOException e) {
  277. e.printStackTrace();
  278. }
  279. }
  280. @GetMapping("/getLuckStatis")
  281. public HttpResponseResult getLuckStatis() {
  282. List<Organization> organs = organizationDao.findAllOrgans();
  283. List<OrderStatisDto> orders = studentPaymentOrderDao.getLuckStatis();
  284. for (Organization organ : organs) {
  285. boolean flag = false;
  286. for (OrderStatisDto order : orders) {
  287. if (organ.getName().equals(order.getOrganName())) {
  288. flag = true;
  289. break;
  290. }
  291. }
  292. if (!flag) {
  293. OrderStatisDto orderStatisDto = new OrderStatisDto();
  294. orderStatisDto.setOrganName(organ.getName());
  295. orderStatisDto.setMoney(BigDecimal.ZERO);
  296. orderStatisDto.setNums(0);
  297. orders.add(orderStatisDto);
  298. }
  299. }
  300. BigDecimal totalMoney = BigDecimal.ZERO;
  301. Integer totalNum = 0;
  302. Iterator<OrderStatisDto> iterator = orders.iterator();
  303. while (iterator.hasNext()) {
  304. OrderStatisDto order = iterator.next();
  305. if (order.getOrganName().equals("总部国际") || order.getOrganName().equals("阳光总部国际") || order.getOrganName().equals("武汉小学")) {
  306. iterator.remove();
  307. continue;
  308. }
  309. totalMoney = totalMoney.add(order.getMoney());
  310. totalNum += order.getNums();
  311. }
  312. orders = orders.stream().sorted(Comparator.comparing(OrderStatisDto::getNums).reversed()).collect(Collectors.toList());
  313. LuckStatisDto luckStatisDto = new LuckStatisDto();
  314. luckStatisDto.setOrderStatisDtoList(orders);
  315. luckStatisDto.setTotalNum(totalNum);
  316. luckStatisDto.setTotalMoney(totalMoney);
  317. return succeed(luckStatisDto);
  318. }
  319. @GetMapping("/getPracticeGroupStatis")
  320. public HttpResponseResult getPracticeGroupStatis() {
  321. List<Organization> organs = organizationDao.findAllOrgans();
  322. List<PracticeGroupsDto> hasReportNums = courseScheduleEvaluateDao.getHasReportNums();
  323. List<PracticeGroupsDto> organMoneys = courseScheduleEvaluateDao.getOrganMoney();
  324. List<PracticeGroupsDto> organPracticeGroups = courseScheduleEvaluateDao.getOrganPracticeGroups();
  325. List<PracticeGroupsDto> practiceGroupsFrees = courseScheduleEvaluateDao.getPracticeGroupsFree();
  326. List<PracticeGroupsDto> practiceGroupsBuys = courseScheduleEvaluateDao.getPracticeGroupsBuy();
  327. List<PracticeGroupsDto> practiceGroupsRenews = courseScheduleEvaluateDao.getPracticeGroupsRenew();
  328. List<PracticeGroupsDto> monthOrganBuyMoneys = courseScheduleEvaluateDao.getMonthOrganMoney(OrderTypeEnum.PRACTICE_GROUP_BUY);
  329. List<PracticeGroupsDto> monthOrganRenewMoneys = courseScheduleEvaluateDao.getMonthOrganMoney(OrderTypeEnum.PRACTICE_GROUP_RENEW);
  330. List<PracticeGroupsDto> practiceGroups = new ArrayList<>();
  331. for (Organization organ : organs) {
  332. PracticeGroupsDto practiceGroupsDto = new PracticeGroupsDto();
  333. practiceGroupsDto.setOrganName(organ.getName());
  334. practiceGroupsDto.setOrganId(organ.getId());
  335. //体验人数
  336. for (PracticeGroupsDto practiceGroupsFree : practiceGroupsFrees) {
  337. if (organ.getId().equals(practiceGroupsFree.getOrganId())) {
  338. practiceGroupsDto.setTotalNums(practiceGroupsFree.getTotalNums());
  339. break;
  340. }
  341. }
  342. //购买人数
  343. for (PracticeGroupsDto practiceGroupsBuy : practiceGroupsBuys) {
  344. if (organ.getId().equals(practiceGroupsBuy.getOrganId())) {
  345. practiceGroupsDto.setBuyNums(practiceGroupsBuy.getBuyNums());
  346. break;
  347. }
  348. }
  349. //续费人数
  350. for (PracticeGroupsDto practiceGroupsRenew : practiceGroupsRenews) {
  351. if (organ.getId().equals(practiceGroupsRenew.getOrganId())) {
  352. practiceGroupsDto.setRenewNums(practiceGroupsRenew.getRenewNums());
  353. break;
  354. }
  355. }
  356. //已完成人数
  357. for (PracticeGroupsDto organPracticeGroup : organPracticeGroups) {
  358. if (organ.getId().equals(organPracticeGroup.getOrganId()) && organPracticeGroup.getBuyNums() >= organPracticeGroup.getTotalNums()) {
  359. practiceGroupsDto.setOverNums(practiceGroupsDto.getOverNums() + 1);
  360. }
  361. }
  362. //已提交报告人数
  363. for (PracticeGroupsDto hasReportNum : hasReportNums) {
  364. if (organ.getId().equals(hasReportNum.getOrganId())) {
  365. practiceGroupsDto.setReportNums(hasReportNum.getReportNums());
  366. break;
  367. }
  368. }
  369. //成交金额
  370. for (PracticeGroupsDto organMoney : organMoneys) {
  371. if (organ.getId().equals(organMoney.getOrganId())) {
  372. practiceGroupsDto.setTotalMoney(organMoney.getTotalMoney());
  373. break;
  374. }
  375. }
  376. //当月新增金额和人数
  377. for (PracticeGroupsDto monthOrganBuyMoney : monthOrganBuyMoneys) {
  378. if (organ.getId().equals(monthOrganBuyMoney.getOrganId())) {
  379. practiceGroupsDto.setMonthBuyMoney(monthOrganBuyMoney.getTotalMoney());
  380. practiceGroupsDto.setMonthBuyNums(monthOrganBuyMoney.getBuyNums());
  381. break;
  382. }
  383. }
  384. //当月续费金额和人数
  385. for (PracticeGroupsDto monthOrganRenewMoney : monthOrganRenewMoneys) {
  386. if (organ.getId().equals(monthOrganRenewMoney.getOrganId())) {
  387. practiceGroupsDto.setMonthRenewNums(monthOrganRenewMoney.getBuyNums());
  388. practiceGroupsDto.setMonthRenewMoney(monthOrganRenewMoney.getTotalMoney());
  389. break;
  390. }
  391. }
  392. if(practiceGroupsDto.getTotalNums() >0 ){
  393. double scale = new BigDecimal(practiceGroupsDto.getBuyNums()).multiply(new BigDecimal(100)).divide(new BigDecimal(practiceGroupsDto.getTotalNums()),2, BigDecimal.ROUND_HALF_UP).doubleValue();
  394. practiceGroupsDto.setBuyScale(scale);
  395. }
  396. practiceGroups.add(practiceGroupsDto);
  397. }
  398. BigDecimal totalMoney = BigDecimal.ZERO;
  399. Integer totalNum = 0;
  400. Integer buyNum = 0;
  401. Integer renewNum = 0;
  402. Integer overNum = 0;
  403. Integer reportNum = 0;
  404. Integer monthBuyNums = 0;
  405. Integer monthRenewNums = 0;
  406. BigDecimal monthBuyMoney = BigDecimal.ZERO;
  407. BigDecimal monthRenewMoney= BigDecimal.ZERO;
  408. Iterator<PracticeGroupsDto> iterator = practiceGroups.iterator();
  409. while (iterator.hasNext()) {
  410. PracticeGroupsDto next = iterator.next();
  411. if (next.getOrganName().equals("总部国际") || next.getOrganName().equals("阳光总部国际") || next.getOrganName().equals("武汉小学")) {
  412. iterator.remove();
  413. continue;
  414. }
  415. totalMoney = totalMoney.add(next.getTotalMoney());
  416. totalNum += next.getTotalNums();
  417. overNum += next.getOverNums();
  418. buyNum += next.getBuyNums();
  419. reportNum += next.getReportNums();
  420. renewNum += next.getRenewNums();
  421. monthBuyNums += next.getMonthBuyNums();
  422. monthRenewNums += next.getMonthRenewNums();
  423. monthBuyMoney = monthBuyMoney.add(next.getMonthBuyMoney());
  424. monthRenewMoney = monthRenewMoney.add(next.getMonthRenewMoney());
  425. }
  426. practiceGroups = practiceGroups.stream().sorted(Comparator.comparingDouble(PracticeGroupsDto::getBuyScale).reversed()).collect(Collectors.toList());
  427. practiceGroupStatisDto practiceGroupStatisDto = new practiceGroupStatisDto();
  428. practiceGroupStatisDto.setPracticeGroupsDtoList(practiceGroups);
  429. practiceGroupStatisDto.setTotalMoney(totalMoney);
  430. practiceGroupStatisDto.setTotalNum(totalNum);
  431. practiceGroupStatisDto.setBuyNum(buyNum);
  432. practiceGroupStatisDto.setRenewNum(renewNum);
  433. practiceGroupStatisDto.setOverNum(overNum);
  434. practiceGroupStatisDto.setReportNum(reportNum);
  435. practiceGroupStatisDto.setMonthBuyNums(monthBuyNums);
  436. practiceGroupStatisDto.setMonthBuyMoney(monthBuyMoney);
  437. practiceGroupStatisDto.setMonthRenewNums(monthRenewNums);
  438. practiceGroupStatisDto.setMonthRenewMoney(monthRenewMoney);
  439. if(totalNum >0 ){
  440. BigDecimal scale = new BigDecimal(buyNum).multiply(new BigDecimal(100)).divide(new BigDecimal(totalNum), 2, BigDecimal.ROUND_HALF_UP);
  441. practiceGroupStatisDto.setBuyScale(scale);
  442. }
  443. return succeed(practiceGroupStatisDto);
  444. }
  445. }