| | |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import cn.mb.cloud.common.core.exception.BusinessException; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | List<Integer> operatorId = cttService.list(new QueryWrapper<Competition>() |
| | | .eq("operatorId", operatorId1)).stream().map(Competition::getId).collect(Collectors.toList()); |
| | | query.setUserIds(operatorId); |
| | | } else if (query.getStoreId() != null) { |
| | | List<Competition> list = cttService.list(new QueryWrapper<Competition>()); |
| | | List<Integer> integers = new ArrayList<>(); |
| | | for (Competition competition : list) { |
| | | for (String s : competition.getStoreId().split(",")) { |
| | | if (s.equals(""+query.getStoreId())){ |
| | | integers.add(competition.getId()); |
| | | } |
| | | } |
| | | } |
| | | if (integers.isEmpty()){ |
| | | integers.add(-1); |
| | | } |
| | | query.setUserIds(integers); |
| | | } |
| | | List<PaymentCompetition> paymentCompetitions = paymentCompetitionService.listAll(query); |
| | | List<PaymentCompetition> result = new ArrayList<>(); |
| | |
| | | } |
| | | return result; |
| | | } else if (query.getStoreId() != null) { |
| | | for (PaymentCompetition paymentCompetition : paymentCompetitions) { |
| | | Integer competitionId = paymentCompetition.getCompetitionId(); |
| | | Competition byId = cttService.getById(competitionId); |
| | | if (byId != null) { |
| | | String storeId = byId.getStoreId(); |
| | | if (storeId.contains(query.getStoreId().toString())) { |
| | | result.add(paymentCompetition); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | return paymentCompetitions; |
| | | } |
| | | return paymentCompetitions; |
| | | } |
| | |
| | | wrapper.ne(Competition::getAuditStatus,2); |
| | | } |
| | | wrapper.in(Competition::getStoreId,listQuery.getIds()); |
| | | wrapper.orderByDesc(Competition::getInsertTime); |
| | | wrapper.orderByDesc(Competition::getInsertTime) |
| | | .orderByDesc(Competition::getId); |
| | | Page<Competition> page = cttService.page(competitionPage, wrapper); |
| | | for (Competition record : page.getRecords()) { |
| | | // 查询当前赛事有多少人报名了 |
| | |
| | | integers.add(1); |
| | | integers.add(3); |
| | | wrapper.in(Competition::getAuditStatus, integers); |
| | | wrapper.orderByDesc(Competition::getInsertTime); |
| | | wrapper.orderByDesc(Competition::getInsertTime) |
| | | .orderByDesc(Competition::getId); |
| | | |
| | | Page<Competition> page = cttService.page(competitionPage, wrapper); |
| | | return page; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新活动配置。 |
| | | * |
| | | * @param competition 管理端提交的活动信息 |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | if(competition.getStatus() == 2){ |
| | | //添加勋章数据 |
| | | List<PaymentCompetition> list = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>() |
| | | .eq("competitionId", competition.getId()).eq("payStatus", 2).eq("state", 1)); |
| | | Set<Integer> collect = list.stream().map(PaymentCompetition::getAppUserId).collect(Collectors.toSet()); |
| | | for (Integer integer : collect) { |
| | | int count = paymentCompetitionService.count(new QueryWrapper<PaymentCompetition>() |
| | | .eq("appUserId", integer).eq("payStatus", 2).eq("state", 1)); |
| | | StudentHonor studentHonor = new StudentHonor(); |
| | | studentHonor.setAppUserId(integer); |
| | | studentHonor.setHonorType(2); |
| | | studentHonor.setNumber(count); |
| | | studentHonorClient.saveStudentHonor(studentHonor); |
| | | } |
| | | } |
| | | } |
| | | cttService.updateById(competition); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | public void update(@RequestBody Competition competition) throws BusinessException { |
| | | cttService.updateCompetition(competition); |
| | | } |
| | | |
| | | @Resource |
| | |
| | | // 年 |
| | | ArrayList<Integer> years = new ArrayList<>(); |
| | | ArrayList<Integer> yearsUser = new ArrayList<>(); |
| | | Integer operatorId = vo.getOperatorId(); |
| | | List<Integer> operatorId1 = cttService.list(new QueryWrapper<Competition>().eq("operatorId", operatorId)) |
| | | .stream().map(Competition::getId).collect(Collectors.toList()); |
| | | for (Object o : collect) { |
| | | String s = o.toString(); |
| | | int count = cttService.count(new LambdaQueryWrapper<Competition>().like(Competition::getInsertTime, s).eq(Competition::getOperatorId, vo.getOperatorId())); |
| | | int count1 = ucttService.count(new LambdaQueryWrapper<UserCompetition>().in(UserCompetition::getAppUserId, vo.getIds()).like(UserCompetition::getInsertTime, s)); |
| | | List<Integer> competitionIds = listCompetitionIds(vo, s); |
| | | int count = competitionIds.size(); |
| | | int count1 = countUserCompetitions(vo, s, competitionIds); |
| | | years.add(count); |
| | | yearsUser.add(count1); |
| | | } |
| | |
| | | m = "0" + i; |
| | | } |
| | | String s = year + "-" + m; |
| | | int count = cttService.count(new LambdaQueryWrapper<Competition>().like(Competition::getInsertTime, s).eq(Competition::getOperatorId, operatorId)); |
| | | int count1 = ucttService.count(new LambdaQueryWrapper<UserCompetition>().in(UserCompetition::getAppUserId, vo.getIds()).like(UserCompetition::getInsertTime, s)); |
| | | List<Integer> competitionIds = listCompetitionIds(vo, s); |
| | | int count = competitionIds.size(); |
| | | int count1 = countUserCompetitions(vo, s, competitionIds); |
| | | months.add(count); |
| | | monthsUser.add(count1); |
| | | } |
| | |
| | | return map; |
| | | } |
| | | |
| | | /** 门店活动统计:仅统计指定门店的赛事及其报名记录。 */ |
| | | @ResponseBody |
| | | @PostMapping("/base/competition/actStore") |
| | | public HashMap<String, Object> actStore(@RequestBody CompetionVO vo) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | if (vo.getStoreIds() == null || vo.getStoreIds().isEmpty()) { |
| | | vo.setStoreIds(Collections.singletonList(-1)); |
| | | } |
| | | ArrayList<Integer> years = new ArrayList<>(); |
| | | ArrayList<Integer> yearsUser = new ArrayList<>(); |
| | | int year = DateUtil.year(new Date()); |
| | | for (int statisticYear = year - 9; statisticYear <= year; statisticYear++) { |
| | | String dateText = String.valueOf(statisticYear); |
| | | List<Integer> competitionIds = listStoreCompetitionIds(vo, dateText); |
| | | years.add(competitionIds.size()); |
| | | yearsUser.add(countStoreUserCompetitions(dateText, competitionIds)); |
| | | } |
| | | map.put("yearData", years); |
| | | map.put("yearsUser", yearsUser); |
| | | |
| | | ArrayList<Integer> months = new ArrayList<>(); |
| | | ArrayList<Integer> monthsUser = new ArrayList<>(); |
| | | for (int month = 1; month <= 12; month++) { |
| | | String dateText = String.format("%d-%02d", year, month); |
| | | List<Integer> competitionIds = listStoreCompetitionIds(vo, dateText); |
| | | months.add(competitionIds.size()); |
| | | monthsUser.add(countStoreUserCompetitions(dateText, competitionIds)); |
| | | } |
| | | map.put("monthData", months); |
| | | map.put("monthsUser", monthsUser); |
| | | return map; |
| | | } |
| | | |
| | | private List<Integer> listCompetitionIds(CompetionVO vo, String dateText) { |
| | | return cttService.list(buildCompetitionCountWrapper(vo, dateText)) |
| | | .stream() |
| | | .map(Competition::getId) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private List<Integer> listStoreCompetitionIds(CompetionVO vo, String dateText) { |
| | | Set<String> storeIds = vo.getStoreIds().stream() |
| | | .filter(Objects::nonNull) |
| | | .map(String::valueOf) |
| | | .collect(Collectors.toSet()); |
| | | return cttService.list(new LambdaQueryWrapper<Competition>() |
| | | .like(Competition::getInsertTime, dateText)) |
| | | .stream() |
| | | .filter(competition -> containsStoreId(competition.getStoreId(), storeIds)) |
| | | .map(Competition::getId) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private boolean containsStoreId(String competitionStoreIds, Set<String> storeIds) { |
| | | if (competitionStoreIds == null || competitionStoreIds.trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | return Arrays.stream(competitionStoreIds.split(",")) |
| | | .map(String::trim) |
| | | .anyMatch(storeIds::contains); |
| | | } |
| | | |
| | | private int countStoreUserCompetitions(String dateText, List<Integer> competitionIds) { |
| | | if (competitionIds.isEmpty()) { |
| | | return 0; |
| | | } |
| | | return ucttService.count(new LambdaQueryWrapper<UserCompetition>() |
| | | .in(UserCompetition::getCompetitionId, competitionIds) |
| | | .like(UserCompetition::getInsertTime, dateText)); |
| | | } |
| | | |
| | | private int countUserCompetitions(CompetionVO vo, String dateText, List<Integer> competitionIds) { |
| | | if (competitionIds.isEmpty()) { |
| | | return 0; |
| | | } |
| | | return ucttService.count(new LambdaQueryWrapper<UserCompetition>() |
| | | .in(UserCompetition::getAppUserId, vo.getIds()) |
| | | .in(UserCompetition::getCompetitionId, competitionIds) |
| | | .like(UserCompetition::getInsertTime, dateText)); |
| | | } |
| | | |
| | | private LambdaQueryWrapper<Competition> buildCompetitionCountWrapper(CompetionVO vo, String dateText) { |
| | | LambdaQueryWrapper<Competition> wrapper = new LambdaQueryWrapper<Competition>() |
| | | .like(Competition::getInsertTime, dateText) |
| | | .eq(Competition::getOperatorId, vo.getOperatorId()); |
| | | appendStoreIdFilter(wrapper, vo.getStoreIds()); |
| | | return wrapper; |
| | | } |
| | | |
| | | private void appendStoreIdFilter(LambdaQueryWrapper<Competition> wrapper, List<Integer> storeIds) { |
| | | if (storeIds == null || storeIds.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<Integer> validStoreIds = storeIds.stream() |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | if (validStoreIds.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | wrapper.and(item -> { |
| | | item.apply("FIND_IN_SET({0}, storeId)", validStoreIds.get(0)); |
| | | for (int i = 1; i < validStoreIds.size(); i++) { |
| | | item.or().apply("FIND_IN_SET({0}, storeId)", validStoreIds.get(i)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/competition/queryAppUserId") |
| | | public List<Integer> queryAppUserId(@RequestBody List<Integer> storeIds){ |
| | | List<Competition> list = competitionService.list(new QueryWrapper<Competition>().in("storeId", storeIds).eq("auditStatus", 2).eq("state", 1)); |
| | | if (storeIds == null || storeIds.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | LambdaQueryWrapper<Competition> wrapper = new LambdaQueryWrapper<Competition>() |
| | | .eq(Competition::getAuditStatus, 2).eq(Competition::getState, 1); |
| | | appendStoreIdFilter(wrapper, storeIds); |
| | | List<Competition> list = competitionService.list(wrapper); |
| | | List<Integer> collect = list.stream().map(Competition::getId).collect(Collectors.toList()); |
| | | if(collect.size() == 0){ |
| | | return new ArrayList<>(); |
| | |
| | | return list1.stream().map(PaymentCompetition::getAppUserId).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |