nickchange
2023-11-17 a9564eae9f0169ca39329b2f14a8f13d13358a0a
cloud-server-competition/src/main/java/com/dsh/competition/service/impl/PaymentCompetitionServiceImpl.java
@@ -12,12 +12,11 @@
import com.dsh.competition.feignclient.account.model.Student;
import com.dsh.competition.feignclient.course.CoursePackagePaymentClient;
import com.dsh.competition.feignclient.course.model.PaymentDeductionClassHour;
import com.dsh.competition.feignclient.model.BillingRequest;
import com.dsh.competition.feignclient.other.StoreClient;
import com.dsh.competition.feignclient.other.model.Store;
import com.dsh.competition.mapper.PaymentCompetitionMapper;
import com.dsh.competition.model.CompetitionInfo;
import com.dsh.competition.model.CompetitionListVo;
import com.dsh.competition.model.ParticipantVo;
import com.dsh.competition.model.*;
import com.dsh.competition.service.CompetitionService;
import com.dsh.competition.service.IParticipantService;
import com.dsh.competition.service.IPaymentCompetitionService;
@@ -25,15 +24,13 @@
import com.dsh.competition.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -66,6 +63,8 @@
    @Resource
    private StudentClient studentClient;
    @Autowired
    private PaymentCompetitionMapper paymentCompetitionMapper;
@@ -81,7 +80,10 @@
     */
    @Override
    public List<CompetitionListVo> queryMyCompetitionList(Integer uid, Integer type, Integer pageSize, Integer pageNo) throws Exception {
        pageSize = (pageSize - 1) * pageNo;
        pageNo = (pageNo - 1) * pageSize;
        if(0 == type){
            type = null;
        }
        return this.baseMapper.queryMyCompetitionList(uid, type, pageSize, pageNo);
    }
@@ -102,7 +104,7 @@
        competitionInfo.setImgs(competition.getImgs());
        competitionInfo.setName(competition.getName());
        competitionInfo.setRegisterCondition(competition.getRegisterCondition());
        Store store = storeClient.queryStoreById(competition.getStoreId());
        Store store = storeClient.queryStoreById(Integer.valueOf(competition.getStoreId().split(",")[0]));
        competitionInfo.setStoreName(store.getName());
        competitionInfo.setStoreAddress(store.getAddress());
        competitionInfo.setStoreLon(store.getLon());
@@ -114,15 +116,66 @@
        competitionInfo.setAge(competition.getStartAge() + "-" + competition.getEndAge());
        competitionInfo.setProvince(competition.getEntryProvince());
        competitionInfo.setCity(competition.getEntryCity());
        competitionInfo.setAddress(competition.getEntryAddress());
        competitionInfo.setPayType(competition.getPayType());
        competitionInfo.setPrice(competition.getPrice().doubleValue());
        String str = competition.getAddress();
        str = str.substring(str.indexOf("省") + 1);
        // 去掉第一个“市”及之前的字符串
        str = str.substring(str.indexOf("市") + 1);
        // 去掉第一个“区”及之前的字符串
        str = str.substring(str.indexOf("区") + 1);
        competitionInfo.setAddress(str);
        competitionInfo.setCashPrice(competition.getCashPrice());
        competitionInfo.setPlayPaiCoin(competition.getPlayPaiCoin());
        competitionInfo.setClassPrice(competition.getClassPrice());
        competitionInfo.setIntroduction(competition.getIntroduction());
        competitionInfo.setRegistrationNotes(competition.getRegistrationNotes());
        competitionInfo.setApply(1);
        ArrayList<Map<String,Object>> objects = new ArrayList<>();
        if(null != competition.getStoreId()){
            String storeId = competition.getStoreId();
            for (String s : storeId.split(",")) {
                HashMap<String, Object> map = new HashMap<>();
                Store store1 = storeClient.queryStoreById(Integer.valueOf(s));
                map.put("name",store1.getName());
                String str1 = store1.getAddress();
                str1 = str1.substring(str1.indexOf("省") + 1);
                // 去掉第一个“市”及之前的字符串
                str1 = str1.substring(str1.indexOf("市") + 1);
                // 去掉第一个“区”及之前的字符串
                str1 = str1.substring(str1.indexOf("区") + 1);
                map.put("address",str1);
                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);
            }
        }
        competitionInfo.setStoreInfos(objects);
        List<ParticipantVo> participant = new ArrayList<>();
        List<UserCompetition> list = userCompetitionService.list(new QueryWrapper<UserCompetition>().eq("paymentCompetitionId", paymentCompetition.getId()));
        List<Integer> collect = list.stream().map(UserCompetition::getParticipantId).collect(Collectors.toList());
        if(collect.size()==0){
            collect.add(-1);
        }
        List<Participant> participants = participantService.listByIds(collect);
        SimpleDateFormat sdf_year = new SimpleDateFormat("yyyy");
        for (Participant participant1 : participants) {
@@ -132,6 +185,7 @@
            participantVo.setIdcard(participant1.getIdcard());
            Integer age = Integer.valueOf(sdf_year.format(new Date())) - Integer.valueOf(sdf_year.format(participant1.getBirthday()));
            participantVo.setAge(age);
            participantVo.setPhone(participant1.getPhone());
            participant.add(participantVo);
        }
        competitionInfo.setParticipant(participant);
@@ -139,6 +193,8 @@
        if(paymentCompetition.getPayStatus() == 3){
            competitionInfo.setStatus(4);
        }
        competitionInfo.setPayMoney(paymentCompetition.getAmount());
        competitionInfo.setPayType(paymentCompetition.getPayType());
        return competitionInfo;
    }
@@ -172,6 +228,10 @@
            String refund_id = map.get("refund_id");
            paymentCompetition.setRefundOrderNo(refund_id);
            this.updateById(paymentCompetition);
            storeClient.addBackRecord(paymentCompetition.getAmount()+"_"+paymentCompetition.getAppUserId());
        }
        if(paymentCompetition.getPayType() == 2){//支付宝支付
            Map<String, String> map = payMoneyUtil.aliRefund(payOrderNo, amount.toString());
@@ -183,6 +243,7 @@
            paymentCompetition.setRefundOrderNo(refund_id);
            paymentCompetition.setRefundTime(new Date());
            paymentCompetition.setPayStatus(3);
            paymentCompetition.setAppUserId(null);
            this.updateById(paymentCompetition);
            competition.setApplicantsNumber(competition.getApplicantsNumber() - 1);
@@ -196,6 +257,7 @@
            paymentCompetition.setRefundOrderNo("");
            paymentCompetition.setRefundTime(new Date());
            paymentCompetition.setPayStatus(3);
            paymentCompetition.setAppUserId(null);
            this.updateById(paymentCompetition);
            competition.setApplicantsNumber(competition.getApplicantsNumber() - 1);
@@ -208,7 +270,7 @@
                Student student = studentClient.queryStudentByPhone(participant.getPhone());
                PaymentDeductionClassHour paymentDeductionClassHour = new PaymentDeductionClassHour();
                paymentDeductionClassHour.setId(student.getId());
                paymentDeductionClassHour.setClassHour(competition.getPrice().intValue());
                paymentDeductionClassHour.setClassHour(competition.getClassPrice());
                paymentDeductionClassHour.setCode(code);
                coursePackagePaymentClient.rollbackPaymentDeductionClassHour(paymentDeductionClassHour);
            }
@@ -216,6 +278,7 @@
            paymentCompetition.setRefundOrderNo("");
            paymentCompetition.setRefundTime(new Date());
            paymentCompetition.setPayStatus(3);
            paymentCompetition.setAppUserId(null);
            this.updateById(paymentCompetition);
            competition.setApplicantsNumber(competition.getApplicantsNumber() - 1);
@@ -223,4 +286,31 @@
        }
        return ResultUtil.success();
    }
    @Override
    public List<BillingRequest> queryDatas(Integer appUserId, String monthStart, String monthEnd) {
        return this.baseMapper.queryDatas(appUserId,monthStart,monthEnd);
    }
    @Override
    public List<BillingRequest> queryCancelDatas(Integer appUserId, String monthStart, String monthEnd) {
        return this.baseMapper.queryCancelDatas(appUserId,monthStart,monthEnd);
    }
    @Override
    public List<PaymentCompetition> listAll(CompetitionQuery query) {
        String STime = null;
        String ETime = null;
        if (StringUtils.hasLength(query.getTime())) {
            STime = query.getTime().split(" - ")[0] + " 00:00:00";
            ETime = query.getTime().split(" - ")[1] + " 23:59:59";
        }
        return paymentCompetitionMapper.listAll(query,STime,ETime,query.getAmount());
    }
    @Override
    public Integer queryByCode(String code) {
        return this.baseMapper.queryBycode(code);
    }
}