From 6c6d51775200fc1c17b0cd5fc9464016aed13327 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 05 三月 2024 14:14:08 +0800
Subject: [PATCH] 合并代码

---
 cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java |  148 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 136 insertions(+), 12 deletions(-)

diff --git a/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java b/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java
index 414218c..4daf04b 100644
--- a/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java
+++ b/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java
@@ -19,15 +19,13 @@
 import com.dsh.communityWorldCup.mapper.WorldCupMapper;
 import com.dsh.communityWorldCup.model.*;
 import com.dsh.communityWorldCup.service.*;
-import com.dsh.communityWorldCup.util.GeodesyUtil;
-import com.dsh.communityWorldCup.util.PayMoneyUtil;
-import com.dsh.communityWorldCup.util.ResultUtil;
-import com.dsh.communityWorldCup.util.UUIDUtil;
+import com.dsh.communityWorldCup.util.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -163,7 +161,47 @@
         if(null == worldCupList.getStoreId()){
             worldCupList.setStoreId(worldCupList.getStoreId());
         }
-        return this.baseMapper.getWorldCupList(worldCupList);
+        List<WorldCupListVo> worldCupList1 = this.baseMapper.getWorldCupList(worldCupList);
+        for (WorldCupListVo worldCupListVo : worldCupList1) {
+            Integer id = Integer.valueOf(worldCupListVo.getId());
+            List<WorldCupPayment> list = worldCupPaymentService.list(new QueryWrapper<WorldCupPayment>().eq("worldCupId", id).eq("payStatus", 2).eq("state", 1));
+            List<Long> collect = list.stream().map(WorldCupPayment::getId).collect(Collectors.toList());
+            Integer heat = worldCupListVo.getHeat();
+            if(collect.size() > 0){
+                int count = worldCupPaymentParticipantService.count(new QueryWrapper<WorldCupPaymentParticipant>().in("worldCupPaymentId", collect));
+                heat += count;
+            }
+            worldCupListVo.setHeat(heat);
+            String lat = worldCupListVo.getLat();
+            String lon = worldCupListVo.getLon();
+            Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, worldCupList.getLon() + "," + worldCupList.getLat());
+            worldCupListVo.setDistance(distance.get("WGS84"));
+        }
+
+
+        if(null != worldCupList.getSort()){
+            Collections.sort(worldCupList1, new Comparator<WorldCupListVo>() {
+                @Override
+                public int compare(WorldCupListVo o1, WorldCupListVo o2) {
+                    if(worldCupList.getSort() == 1){
+                        return o1.getHeat().compareTo(o2.getHeat());
+                    }
+                    if(worldCupList.getSort() == 2){
+                        return o1.getHeat().compareTo(o2.getHeat()) * -1;
+                    }
+                    return 0;
+                }
+            });
+        }else{
+            Collections.sort(worldCupList1, new Comparator<WorldCupListVo>() {
+                @Override
+                public int compare(WorldCupListVo o1, WorldCupListVo o2) {
+                    return o1.getDistance().compareTo(o2.getDistance()) * -1;
+                }
+            });
+        }
+
+        return worldCupList1;
     }
 
 
@@ -173,7 +211,7 @@
      * @return
      */
     @Override
-    public WorldCupInfo getWorldCupInfo(Integer id) {
+    public WorldCupInfo getWorldCupInfo(Integer id, String lon, String lat) {
         WorldCupInfo worldCupInfo = this.baseMapper.getWorldCupInfo(id);
         List<WorldCupStore> worldCupStores = worldCupStoreService.list(new QueryWrapper<WorldCupStore>().eq("worldCupId", id));
         JSONArray jsonArray = new JSONArray();
@@ -182,6 +220,43 @@
             jsonArray.add(store.getName());
         }
         worldCupInfo.setStores(jsonArray.toJSONString());
+
+        List<WorldCupPayment> list = worldCupPaymentService.list(new QueryWrapper<WorldCupPayment>().eq("worldCupId", id).eq("payStatus", 2).eq("state", 1));
+        List<Long> collect = list.stream().map(WorldCupPayment::getId).collect(Collectors.toList());
+        Integer heat = worldCupInfo.getHeat();
+        if(collect.size() > 0){
+            int count = worldCupPaymentParticipantService.count(new QueryWrapper<WorldCupPaymentParticipant>().in("worldCupPaymentId", collect));
+            heat += count;
+        }
+        worldCupInfo.setHeat(heat);
+        ArrayList<Map<String, Object>> objects = new ArrayList<>();
+        for (WorldCupStore worldCupStore : worldCupStores) {
+            HashMap<String, Object> map = new HashMap<>();
+            Store store = storeClient.queryStoreById(worldCupStore.getStoreId());
+            map.put("name", store.getName());
+
+
+            String str = store.getAddress();
+            str = str.substring(str.indexOf("省") + 1);
+
+            // 去掉第一个“市”及之前的字符串
+            str = str.substring(str.indexOf("市") + 1);
+
+            // 去掉第一个“区”及之前的字符串
+            str = str.substring(str.indexOf("区") + 1);
+
+            map.put("address", str);
+            map.put("storeLon", store.getLon());
+            map.put("storeLat", store.getLat());
+            map.put("storeCoverDrawing", store.getCoverDrawing());
+            if (ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)) {
+                Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
+                double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
+                map.put("distance", wgs84);
+            }
+            objects.add(map);
+        }
+        worldCupInfo.setStoreInfos(objects);
         return worldCupInfo;
     }
 
@@ -240,7 +315,7 @@
         if(null == worldCup){
             return ResultUtil.error("报名数据异常");
         }
-        if(System.currentTimeMillis() > worldCup.getRegistrationClosingTime().getTime()){
+        if(null != worldCup.getRegistrationClosingTime() && System.currentTimeMillis() > worldCup.getRegistrationClosingTime().getTime()){
             return ResultUtil.error("报名时间已结束,无法完成报名");
         }
         if(System.currentTimeMillis() > worldCup.getEndTime().getTime()){
@@ -256,18 +331,18 @@
             Integer isStudent = jsonObject.getInteger("isStudent");
             if(isStudent == 1){
                 TStudent tStudent = studentClient.queryById(id);
-                if(worldCup.getStartAge() > Integer.valueOf(sdf.format(tStudent.getBirthday()))){
+                if(worldCup.getStartAge() > (Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(tStudent.getBirthday())))){
                     return ResultUtil.error("【" + tStudent.getName() + "】年龄不符合要求");
                 }
-                if(worldCup.getEndAge() < Integer.valueOf(sdf.format(tStudent.getBirthday()))){
+                if(worldCup.getEndAge() < (Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(tStudent.getBirthday())))){
                     return ResultUtil.error("【" + tStudent.getName() + "】年龄不符合要求");
                 }
             }else{
                 Participant participant = participantClient.getParticipant(id);
-                if(worldCup.getStartAge() > Integer.valueOf(sdf.format(participant.getBirthday()))){
+                if(worldCup.getStartAge() > (Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(participant.getBirthday())))){
                     return ResultUtil.error("【" + participant.getName() + "】年龄不符合要求");
                 }
-                if(worldCup.getEndAge() < Integer.valueOf(sdf.format(participant.getBirthday()))){
+                if(worldCup.getEndAge() < (Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(participant.getBirthday())))){
                     return ResultUtil.error("【" + participant.getName() + "】年龄不符合要求");
                 }
             }
@@ -303,7 +378,8 @@
         worldCupPayment.setEntrant(paymentWorldCup.getIds());
         int num = JSON.parseArray(paymentWorldCup.getIds()).size();
         //不免费
-        if(worldCup.getPayType() != 0){
+        String payType1 = worldCup.getPayType().split(",")[0];
+        if(!"0".equals(payType1)){
             Integer payType = paymentWorldCup.getPayType();
             //微信
             if(payType == 1){
@@ -349,6 +425,7 @@
                     worldCupPaymentParticipant.setAppUserId(paymentWorldCup.getUid());
                     worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
                     worldCupPaymentParticipant.setParticipantId(id);
+                    worldCupPaymentParticipant.setAlreadyEntered(0);
                     worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
                 }
                 return ResultUtil.success();
@@ -408,6 +485,24 @@
                 worldCupPayment.setPayStatus(2);
                 worldCupPayment.setPayTime(new Date());
                 worldCupPaymentService.save(worldCupPayment);
+
+                //添加报名明细
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    JSONObject jsonObject = jsonArray.getJSONObject(i);
+                    Integer id = jsonObject.getInteger("id");
+                    //是否是学员(0=否,1=是)
+                    Integer isStudent = jsonObject.getInteger("isStudent");
+
+                    WorldCupPaymentParticipant worldCupPaymentParticipant = new WorldCupPaymentParticipant();
+                    worldCupPaymentParticipant.setWorldCupId(paymentWorldCup.getId());
+                    worldCupPaymentParticipant.setWorldCupPaymentId(worldCupPayment.getId());
+                    worldCupPaymentParticipant.setAppUserId(paymentWorldCup.getUid());
+                    worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
+                    worldCupPaymentParticipant.setParticipantId(id);
+                    worldCupPaymentParticipant.setAlreadyEntered(0);
+                    worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
+                }
+
                 return ResultUtil.success();
             }
         }else{
@@ -432,6 +527,7 @@
                 worldCupPaymentParticipant.setAppUserId(paymentWorldCup.getUid());
                 worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
                 worldCupPaymentParticipant.setParticipantId(id);
+                worldCupPaymentParticipant.setAlreadyEntered(0);
                 worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
             }
             return ResultUtil.success();
@@ -468,8 +564,36 @@
             worldCupPaymentParticipant.setAppUserId(worldCupPayment.getAppUserId());
             worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
             worldCupPaymentParticipant.setParticipantId(id);
+            worldCupPaymentParticipant.setAlreadyEntered(0);
             worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
         }
         return ResultUtil.success();
     }
+
+
+    /**
+     * 获取比赛管理列表数据
+     * @param worldCupListAll
+     * @return
+     */
+    @Override
+    public Map<String, Object> getWorldCupListAll(WorldCupListAll worldCupListAll) {
+        Map<String, Object> map = new HashMap<>();
+        List<Map<String, Object>> list = this.baseMapper.getWorldCupListAll(worldCupListAll);
+        for (Map<String, Object> map1 : list) {
+            String maxPeople = map1.get("maxPeople").toString();
+            Integer id = Integer.valueOf(map1.get("id").toString());
+            List<WorldCupPayment> lists = worldCupPaymentService.list(new QueryWrapper<WorldCupPayment>().eq("worldCupId", id).eq("payStatus", 2).eq("state", 1));
+            List<Long> collect = lists.stream().map(WorldCupPayment::getId).collect(Collectors.toList());
+            Integer count = 0;
+            if(collect.size() > 0){
+                count = worldCupPaymentParticipantService.count(new QueryWrapper<WorldCupPaymentParticipant>().in("worldCupPaymentId", collect));
+            }
+            map1.put("maxPeople", maxPeople + " - " + count);
+        }
+        Integer count = this.baseMapper.getWorldCupListAllCount(worldCupListAll);
+        map.put("rows", list);
+        map.put("total", count);
+        return map;
+    }
 }

--
Gitblit v1.7.1