nickchange
2023-11-25 cad9305c4cbffe978370f4c39bfde63b248619c7
cloud-server-competition/src/main/java/com/dsh/competition/controller/CompetitionController.java
@@ -2,6 +2,7 @@
import cn.hutool.core.date.DateUtil;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -12,7 +13,9 @@
import com.dsh.competition.feignclient.account.AppUserClient;
import com.dsh.competition.feignclient.account.model.AppUser;
import com.dsh.competition.feignclient.course.CoursePackagePaymentClient;
import com.dsh.competition.feignclient.course.model.PaymentDeductionClassHour;
import com.dsh.competition.feignclient.model.*;
import com.dsh.competition.feignclient.other.StoreClient;
import com.dsh.competition.model.*;
import com.dsh.competition.service.CompetitionService;
import com.dsh.competition.service.IParticipantService;
@@ -33,7 +36,9 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletionService;
@@ -75,7 +80,36 @@
    @Autowired
    private AppUserClient appUserClient;
    /**
     * 根据门店ids 获取对应的赛事 根据赛事支付记录获取用户ids
     */
    @ResponseBody
    @PostMapping("/base/competition/getUserIds")
    public List<Integer> getUserIds(@RequestBody ListQuery query){
        List<Competition> list = cttService.list(new QueryWrapper<Competition>());
        // 赛事id集合
        List<Integer> comIds = new ArrayList<>();
        for (Integer id : query.getIds()) {
            for (Competition competition : list) {
                if (competition.getStoreId().contains(id.toString())){
                    comIds.add(competition.getId());
                }
            }
        }
        // 获取到赛事id集合 去重
        List<Integer> collect = comIds.stream().distinct().collect(Collectors.toList());
        // 根据赛事id 查询赛事支付记录 获取用户ids
        if (collect.size() == 0){
            return new ArrayList<>();
        }else{
            List<Integer> userIds = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>()
                    .in("competitionId", collect)).stream()
                    .map(PaymentCompetition::getAppUserId).collect(Collectors.toList());
            return userIds;
        }
    }
    /**
     * 获取赛事报名记录
     */
@@ -154,10 +188,14 @@
//        integers.add(2);
        integers.add(3);
        ArrayList<Integer> pays = new ArrayList<>();
        pays.add(2);
        pays.add(3);
        return paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>()
                .in("payType",integers)
                .eq("appUserId",appUserId)
                .eq("payStatus",2));
                .in("payStatus",pays));
    }
@@ -252,7 +290,11 @@
    public ResultUtil<List<CompetitionListVo>> queryCompetitionList(String cityCode, String content, Integer registerCondition, String heat){
        try {
            List<CompetitionListVo> competitionListVos = cttService.queryCompetitionList(cityCode, content, registerCondition, heat);
            return ResultUtil.success(competitionListVos);
            List<CompetitionListVo> filteredList = competitionListVos.stream()
                    .filter(vo -> vo.getStatus() == 1 || vo.getStatus() == 2)
                    .collect(Collectors.toList());
            return ResultUtil.success(filteredList);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -277,6 +319,19 @@
                return ResultUtil.tokenErr();
            }
            CompetitionInfo competitionInfo = cttService.queryCompetitionInfo(uid, id, lon, lat);
            String dateString = competitionInfo.getRegisterEndTime();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date date = sdf.parse(dateString);
            if (new Date().after(date)){
                competitionInfo.setHasPass(1);
            }else {
                competitionInfo.setHasPass(0);
            }
            return ResultUtil.success(competitionInfo);
        }catch (Exception e){
            e.printStackTrace();
@@ -316,7 +371,7 @@
                return ResultUtil.tokenErr();
            }
            if (byId.getRegisterCondition()==3){
             Integer counts =    coursePackagePaymentClient.isHave(uid);
             Integer counts =    coursePackagePaymentClient.isHave(paymentCompetitionVo.getIds());
                if (counts==0){
                    return new ResultUtil(0,"当前赛事仅限已购课学员报名");
                }
@@ -565,20 +620,29 @@
                wrapper.like(Competition::getName,listQuery.getEventName());
            }
            if(ToolUtil.isNotEmpty(listQuery.getTime())){
                wrapper.gt(Competition::getStartTime,listQuery.getTime().split(" - ")[0]+" 00:00:00");
                wrapper.lt(Competition::getEndTime,listQuery.getTime().split(" - ")[1]+" 23:59:59");
                wrapper.lt(Competition::getStartTime,listQuery.getTime().split(" - ")[0]+" 00:00:00");
                wrapper.gt(Competition::getEndTime,listQuery.getTime().split(" - ")[1]+" 23:59:59");
            }
            if(ToolUtil.isNotEmpty(listQuery.getState())){
                wrapper.eq(Competition::getStatus,listQuery.getState());
            }
            if(ToolUtil.isNotEmpty(listQuery.getRegisterCondition())){
                wrapper.eq(Competition::getRegisterCondition,listQuery.getRegisterCondition());
            }
            wrapper.in(Competition::getStoreId,listQuery.getIds());
            wrapper.eq(Competition::getAuditStatus,2);
            wrapper.orderByDesc(Competition::getInsertTime);
            Page<Competition> page = cttService.page(competitionPage, wrapper);
            for (Competition record : page.getRecords()) {
                // 查询当前赛事有多少人报名了
                List<UserCompetition> competitionId = ucttService.list(new QueryWrapper<UserCompetition>()
                        .eq("competitionId", record.getId()));
                // 报名数量
                int temp = competitionId.size();
                String value = String.valueOf(temp);
                record.setCount(record.getApplicantsNumber()+"-"+value);
            }
            return page;
        }catch (Exception e){
            e.printStackTrace();
@@ -594,7 +658,7 @@
                wrapper.eq(Competition::getProvinceCode,listQuery.getProvinceCode());
            }
            if(ToolUtil.isNotEmpty(listQuery.getCityCode())){
                wrapper.eq(Competition::getProvinceCode,listQuery.getCityCode());
                wrapper.eq(Competition::getCityCode,listQuery.getCityCode());
            }
            if(ToolUtil.isNotEmpty(listQuery.getEventName())){
                wrapper.like(Competition::getName,listQuery.getEventName());
@@ -624,6 +688,16 @@
    @PostMapping("/base/competition/add")
    public void add(@RequestBody Competition competition){
        try {
            if (competition.getStartTime().after(new Date())){
                competition.setStatus(1);
            }
            if (competition.getStartTime().before(new Date())){
                if (competition.getEndTime().after(new Date())){
                    competition.setStatus(2);
                }else{
                    competition.setStatus(3);
                }
            }
            competition.setInsertTime(new Date());
            cttService.save(competition);
        }catch (Exception e){
@@ -634,11 +708,28 @@
    @PostMapping("/base/competition/update")
    public void update(@RequestBody Competition competition){
        try {
            if (competition.getStartTime().after(new Date())){
                competition.setStatus(1);
            }
            if (competition.getStartTime().before(new Date())){
                if (competition.getEndTime().after(new Date())){
                    competition.setStatus(2);
                }else{
                    competition.setStatus(3);
                }
            }
            cttService.updateById(competition);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    @Resource
    private StoreClient storeClient;
    @Autowired
    private UserCompetitionService userCompetitionService;
    @PostMapping("/base/competition/cancel")
    public void cancel(@RequestBody Integer id){
@@ -646,6 +737,87 @@
            Competition byId = cttService.getById(id);
            byId.setStatus(4);
            cttService.updateById(byId);
            List<PaymentCompetition> list = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>().eq("competitionId", byId.getId()).eq("payStatus", 2));
            for (PaymentCompetition pay : list) {
                PaymentCompetition paymentCompetition = pay;
                String code = paymentCompetition.getCode();
                Double amount = paymentCompetition.getAmount();
                Competition competition = competitionService.getById(paymentCompetition.getCompetitionId());
                String payOrderNo = paymentCompetition.getPayOrderNo();
                if(paymentCompetition.getPayType() == 1){//微信支付
                    Map<String, String> map = payMoneyUtil.wxRefund(payOrderNo, code, amount.toString(), amount.toString(), "/base/competition/weChatCancelPaymentCompetitionCallback");
                    String return_code = map.get("return_code");
                    if(!"SUCCESS".equals(return_code)){
//                        return ResultUtil.error(map.get("return_msg"));
                        continue;
                    }
                    String refund_id = map.get("refund_id");
                    paymentCompetition.setRefundOrderNo(refund_id);
                    paymentCompetitionService.updateById(paymentCompetition);
                    storeClient.addBackRecord(paymentCompetition.getAmount()+"_"+paymentCompetition.getAppUserId());
                }
                if(paymentCompetition.getPayType() == 2){//支付宝支付
                    Map<String, String> map = payMoneyUtil.aliRefund(payOrderNo, amount.toString());
                    String return_code = map.get("code");
                    if(!"10000".equals(return_code)){
//                        return ResultUtil.error(map.get("msg"));
                        continue;
                    }
                    String refund_id = map.get("trade_no");
                    paymentCompetition.setRefundOrderNo(refund_id);
                    paymentCompetition.setRefundTime(new Date());
                    paymentCompetition.setPayStatus(3);
                    paymentCompetition.setAppUserId(null);
                    paymentCompetitionService.updateById(paymentCompetition);
//            competition.setApplicantsNumber(competition.getApplicantsNumber() - 1);
                    competitionService.updateById(competition);
                }
                if(paymentCompetition.getPayType() == 3){//玩湃币支付
                    AppUser appUser = appUserClient.queryAppUser(paymentCompetition.getAppUserId());
                    appUser.setPlayPaiCoins(appUser.getPlayPaiCoins() + amount.intValue());
                    appUserClient.updateAppUser(appUser);
                    paymentCompetition.setRefundOrderNo("");
                    paymentCompetition.setRefundTime(new Date());
                    paymentCompetition.setPayStatus(3);
                    paymentCompetition.setAppUserId(null);
                    paymentCompetitionService.updateById(paymentCompetition);
//            competition.setApplicantsNumber(competition.getApplicantsNumber() - 1);
                    competitionService.updateById(competition);
                }
                if(paymentCompetition.getPayType() == 4){//课程支付
                    List<UserCompetition> list1 = userCompetitionService.list(new QueryWrapper<UserCompetition>().eq("paymentCompetitionId", paymentCompetition.getId()));
                    for (UserCompetition userCompetition : list1) {
//                Participant participant = participantService.getById(userCompetition.getId());
//                Student student = studentClient.queryStudentByPhone(participant.getPhone());
                        PaymentDeductionClassHour paymentDeductionClassHour = new PaymentDeductionClassHour();
                        paymentDeductionClassHour.setId(userCompetition.getParticipantId());
                        paymentDeductionClassHour.setClassHour(competition.getClassPrice());
                        paymentDeductionClassHour.setCode(code);
                        coursePackagePaymentClient.rollbackPaymentDeductionClassHour(paymentDeductionClassHour);
                    }
                    paymentCompetition.setRefundOrderNo("");
                    paymentCompetition.setRefundTime(new Date());
                    paymentCompetition.setPayStatus(3);
                    paymentCompetition.setAppUserId(null);
                    paymentCompetitionService.updateById(paymentCompetition);
//            competition.setApplicantsNumber(competition.getApplicantsNumber() - 1);
                    competitionService.updateById(competition);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
@@ -662,6 +834,13 @@
            e.printStackTrace();
            return null;
        }
    }
    @PostMapping("/base/competition/getPeoples")
    @ResponseBody
    public  List<CompetitionUser> getPeoples(@RequestBody GetPeopleQuery getPeopleQuery){
        List<CompetitionUser> list = participantService.getPeoples(
                getPeopleQuery.getId(),getPeopleQuery.getState());
        return list;
    }
@@ -794,9 +973,7 @@
        map.put("monthsUser",monthsUser);
        return map;
    }
}