| | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.panzhihua.common.model.vos.community.*; |
| | | import com.panzhihua.common.model.vos.community.screen.work.ActActivityListVO; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.WxUtil; |
| | | import com.panzhihua.common.utlis.WxXCXTempSend; |
| | | import com.panzhihua.service_community.dao.ComActActSignDAO; |
| | | import com.panzhihua.service_community.dao.ComActActivityDAO; |
| | | import com.panzhihua.service_community.dao.ComActDiscussOptionUserDAO; |
| | |
| | | import com.panzhihua.service_community.service.ComActActivityService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public R putActivity(ComActActivityVO comActActivityVO) { |
| | | ComActActivityDO comActActivityDO=new ComActActivityDO(); |
| | | ComActActivityDO comActActivityDO = this.comActActivityDAO.selectById(comActActivityVO.getId()); |
| | | if(comActActivityDO == null){ |
| | | return R.fail("未找到社区活动"); |
| | | } |
| | | |
| | | if(!comActActivityDO.getActivityAddr().equals(comActActivityVO.getActivityAddr()) || !comActActivityDO.getBeginAt().equals(comActActivityVO.getBeginAt())){ |
| | | //修改活动开始时间与活动地点需要推送订阅消息给用户 |
| | | ActivitySignVO activitySignVO = new ActivitySignVO(); |
| | | activitySignVO.setActivityId(comActActivityVO.getId()); |
| | | List<ActivitySignVO> activitySignVOS = comActActSignDAO.listActivitySigns(activitySignVO); |
| | | if(!activitySignVOS.isEmpty()){ |
| | | try { |
| | | WxXCXTempSend util = new WxXCXTempSend(); |
| | | String accessToken = util.getAppAccessToken(); |
| | | |
| | | activitySignVOS.forEach(activitySignVO1 -> { |
| | | //变更社区活动推送订阅消息给用户 |
| | | WxUtil.sendSubscribeHDBG(activitySignVO1.getOpenid(),accessToken,comActActivityVO.getActivityName() |
| | | , com.panzhihua.common.utlis.DateUtils.format(comActActivityDO.getBeginAt() |
| | | , com.panzhihua.common.utlis.DateUtils.ymdhms_format),comActActivityDO.getActivityAddr(), |
| | | com.panzhihua.common.utlis.DateUtils.format(comActActivityVO.getBeginAt() |
| | | , com.panzhihua.common.utlis.DateUtils.ymdhms_format),comActActivityVO.getActivityAddr()); |
| | | }); |
| | | }catch (Exception e){ |
| | | log.error("消息推送失败,失败原因:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | BeanUtils.copyProperties(comActActivityVO,comActActivityDO); |
| | | |
| | | //结束时间大于当前时间则设置为“进行中” |
| | |
| | | public ComActActivityVO inforActivity(Long id, Long userId) { |
| | | ComActActivityVO comActActivityVO=comActActivityDAO.inforActivity(id); |
| | | if (!ObjectUtils.isEmpty(comActActivityVO)) { |
| | | ComActActSignDO comActActSignDO = comActActSignDAO.selectOne(new QueryWrapper<ComActActSignDO>().lambda().eq(ComActActSignDO::getActivityId, id).eq(ComActActSignDO::getUserId, userId)); |
| | | if (!ObjectUtils.isEmpty(comActActSignDO)) { |
| | | comActActivityVO.setIsSign(1); |
| | | comActActivityVO.setIsVolunteer(comActActSignDO.getIsVolunteer()); |
| | | }else { |
| | | |
| | | if(userId != null){ |
| | | LambdaQueryWrapper<ComActActSignDO> actSignQuery = new LambdaQueryWrapper<>(); |
| | | actSignQuery.eq(ComActActSignDO::getActivityId, id); |
| | | actSignQuery.eq(ComActActSignDO::getUserId, userId); |
| | | ComActActSignDO comActActSignDO = comActActSignDAO.selectOne(actSignQuery); |
| | | if (!ObjectUtils.isEmpty(comActActSignDO)) { |
| | | comActActivityVO.setIsSign(1); |
| | | comActActivityVO.setIsVolunteer(comActActSignDO.getIsVolunteer()); |
| | | } |
| | | } |
| | | } |
| | | return comActActivityVO; |
| | |
| | | //查询当前活动下参与志愿者/居民数量 |
| | | Integer count = comActActSignDAO.selectCount(new QueryWrapper<ComActActSignDO>().lambda().eq(ComActActSignDO::getActivityId,activityId) |
| | | .eq(ComActActSignDO::getIsVolunteer,isVolunteer)); |
| | | if(isVolunteer.equals(1) && actActivityDO.getVolunteerMax() <= count){ |
| | | if(isVolunteer.equals(1) && actActivityDO.getVolunteerMax() <= count && !actActivityDO.getVolunteerMax().equals(-1)){ |
| | | return R.fail("志愿者报名人数已满"); |
| | | } |
| | | |
| | | if(isVolunteer.equals(0) && actActivityDO.getParticipantMax() <= count){ |
| | | if(isVolunteer.equals(0) && actActivityDO.getParticipantMax() <= count && !actActivityDO.getParticipantMax().equals(-1)){ |
| | | return R.fail("居民报名人数已满"); |
| | | } |
| | | } |
| | |
| | | // 修改报名状态 变为报名中 |
| | | int num1=comActActivityDAO.updateStatusToBeginSign(); |
| | | log.info("定时任务--修改社区活动报名状态活动数量【{}】",num1); |
| | | //查询已经结束的活动,需要计算积分 |
| | | List<Long> activityEndIds = comActActivityDAO.getActivityEndIds(); |
| | | // 修改进行状态 变为进行中或者已结束 |
| | | int num2=comActActivityDAO.updateStatusToBeginActiveOrEnd(); |
| | | log.info("定时任务--修改社区活动进行状态活动数量【{}】",num2); |
| | | int num3=comActActivityDAO.updateStatusToBeginAfterSingEnd(); |
| | | log.info("定时任务--报名结束修改社区活动进行状态活动数量【{}】",num3); |
| | | return R.ok(); |
| | | return R.ok(activityEndIds); |
| | | } |
| | | |
| | | /** |
| | |
| | | return dates; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | List<Date> dates=new ArrayList<>(); |
| | | Date date=new Date(); |
| | | for(int i=6;i>=0;i--){ |
| | | Date date1= DateUtils.addDays(date,-i); |
| | | dates.add(date1); |
| | | |
| | | /** |
| | | * 定时任务检测即将开始的社区活动,并使用订阅消息通知用户 |
| | | */ |
| | | @Override |
| | | public R timedTaskActivityNotice(){ |
| | | //查询所有即将开始的活动 |
| | | List<ComActActivityDO> actActivityList = comActActivityDAO.selectList(new QueryWrapper<ComActActivityDO>().lambda() |
| | | .le(ComActActivityDO::getBeginAt, DateUtils.addDays(new Date(),1)) |
| | | .ge(ComActActivityDO::getBeginAt,new Date())); |
| | | if(!actActivityList.isEmpty()){ |
| | | WxXCXTempSend util = new WxXCXTempSend(); |
| | | try { |
| | | String accessToken = util.getAppAccessToken(); |
| | | actActivityList.forEach(actActivity -> { |
| | | //查询报名活动人员列表 |
| | | List<ComActActSignDO> actSignList = comActActSignDAO.selectList(new QueryWrapper<ComActActSignDO>().lambda() |
| | | .eq(ComActActSignDO::getActivityId,actActivity.getId())); |
| | | actSignList.forEach(actSign -> { |
| | | //查询用户openId |
| | | Map<String,String> map = comActActSignDAO.getUserOpenId(actSign.getUserId()); |
| | | if(map != null){ |
| | | String openid = map.get("openid"); |
| | | //推送消息 |
| | | WxUtil.sendSubscribeHDJJKS(openid,accessToken,actActivity.getActivityName() |
| | | , com.panzhihua.common.utlis.DateUtils.format(actActivity.getBeginAt() |
| | | ,com.panzhihua.common.utlis.DateUtils.ymdhms_format),actActivity.getActivityAddr() |
| | | ,actSignList.size()+""); |
| | | } |
| | | |
| | | }); |
| | | |
| | | }); |
| | | }catch (Exception e){ |
| | | log.error("推送失败,错误原因:" + e.getMessage()); |
| | | } |
| | | } |
| | | System.out.println(dates); |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |