| | |
| | | package com.dsh.activity.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.activity.entity.BenefitsVideoClassification; |
| | | import com.dsh.activity.entity.BenefitsVideos; |
| | | import com.dsh.activity.entity.UserBenefitsVideos; |
| | | import com.dsh.activity.feignclient.account.UserIntegralChangesClient; |
| | | import com.dsh.activity.feignclient.account.model.SaveUserIntegralChangesVo; |
| | | import com.dsh.activity.feignclient.course.CourseClient; |
| | | import com.dsh.activity.feignclient.course.model.Course; |
| | | import com.dsh.activity.mapper.BenefitsVideosMapper; |
| | | import com.dsh.activity.model.BenefitsVideoClassificationListVo; |
| | | import com.dsh.activity.model.BenefitsVideosInfoVo; |
| | | import com.dsh.activity.model.BenefitsVideosListVo; |
| | | import com.dsh.activity.service.BenefitsVideosService; |
| | | import com.dsh.activity.service.IBenefitsVideoClassificationService; |
| | | import com.dsh.activity.service.IUserBenefitsVideosService; |
| | | import com.dsh.activity.util.ToolUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class BenefitsVideosServiceImpl extends ServiceImpl<BenefitsVideosMapper, BenefitsVideos> implements BenefitsVideosService { |
| | | |
| | | @Autowired |
| | | private IBenefitsVideoClassificationService benefitsVideoClassificationService; |
| | | |
| | | @Autowired |
| | | private IUserBenefitsVideosService userBenefitsVideosService; |
| | | |
| | | @Resource |
| | | private CourseClient courseClient; |
| | | |
| | | @Resource |
| | | private UserIntegralChangesClient userIntegralChangesClient; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取福利视频分类列表数据 |
| | | * @param uid |
| | | * @param search |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<BenefitsVideoClassificationListVo> queryClassificationBenefitsVideosList(Integer uid, Integer position, String search) throws Exception { |
| | | QueryWrapper<BenefitsVideoClassification> wrapper = new QueryWrapper<BenefitsVideoClassification>().eq("position", position); |
| | | if(ToolUtil.isNotEmpty(search)){ |
| | | wrapper.like("name", search); |
| | | } |
| | | List<BenefitsVideoClassification> list = benefitsVideoClassificationService.list(wrapper.orderByAsc("sort")); |
| | | List<UserBenefitsVideos> userBenefitsVideos = userBenefitsVideosService.list(new QueryWrapper<UserBenefitsVideos>().eq("appUserId", uid)); |
| | | List<Integer> collect = userBenefitsVideos.stream().map(UserBenefitsVideos::getBenefitsVideosId).collect(Collectors.toList()); |
| | | |
| | | List<BenefitsVideoClassificationListVo> listVos = new ArrayList<>(); |
| | | for (BenefitsVideoClassification benefitsVideoClassification : list) { |
| | | BenefitsVideoClassificationListVo benefitsVideoClassificationListVo = new BenefitsVideoClassificationListVo(); |
| | | benefitsVideoClassificationListVo.setId(benefitsVideoClassification.getId()); |
| | | benefitsVideoClassificationListVo.setName(benefitsVideoClassification.getName()); |
| | | |
| | | List<BenefitsVideos> list1 = this.list(new QueryWrapper<BenefitsVideos>().eq("state", 1).notIn("id", collect).orderByDesc("insertTime").last(" limit 4")); |
| | | List<BenefitsVideosListVo> lists = new ArrayList<>(); |
| | | for (BenefitsVideos benefitsVideos : list1) { |
| | | Integer courseId = benefitsVideos.getCourseId(); |
| | | Course course = courseClient.queryCourseById(courseId); |
| | | BenefitsVideosListVo benefitsVideosListVo = new BenefitsVideosListVo(); |
| | | benefitsVideosListVo.setId(benefitsVideos.getId()); |
| | | benefitsVideosListVo.setName(course.getName()); |
| | | benefitsVideosListVo.setCover(course.getCoverDrawing()); |
| | | benefitsVideosListVo.setIntroduce(course.getIntroduce()); |
| | | lists.add(benefitsVideosListVo); |
| | | } |
| | | benefitsVideoClassificationListVo.setList(lists); |
| | | listVos.add(benefitsVideoClassificationListVo); |
| | | } |
| | | return listVos; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<BenefitsVideosListVo> queryBenefitsVideosList(Integer uid, Integer classificationId, Integer pageSize, Integer pageNo) throws Exception { |
| | | pageSize = (pageSize - 1) * pageNo; |
| | | List<Map<String, Object>> benefitsVideos = this.baseMapper.queryBenefitsVideosList(uid, classificationId, pageSize, pageNo); |
| | | List<BenefitsVideosListVo> lists = new ArrayList<>(); |
| | | for (Map<String, Object> benefitsVideo : benefitsVideos) { |
| | | Integer id = Integer.valueOf(benefitsVideo.get("id").toString()); |
| | | Integer courseId = Integer.valueOf(benefitsVideo.get("courseId").toString()); |
| | | Integer integral = Integer.valueOf(benefitsVideo.get("integral").toString()); |
| | | Integer study = Integer.valueOf(benefitsVideo.get("study").toString()); |
| | | Course course = courseClient.queryCourseById(courseId); |
| | | BenefitsVideosListVo benefitsVideosListVo = new BenefitsVideosListVo(); |
| | | benefitsVideosListVo.setId(id); |
| | | benefitsVideosListVo.setName(course.getName()); |
| | | benefitsVideosListVo.setCover(course.getCoverDrawing()); |
| | | benefitsVideosListVo.setIntroduce(course.getIntroduce()); |
| | | benefitsVideosListVo.setIntegral(integral); |
| | | benefitsVideosListVo.setStudy(study); |
| | | lists.add(benefitsVideosListVo); |
| | | } |
| | | return lists; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取福利视频详情 |
| | | * @param uid |
| | | * @param id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public BenefitsVideosInfoVo queryBenefitsVideosInfo(Integer uid, Integer id) throws Exception { |
| | | BenefitsVideos benefitsVideos = this.getById(id); |
| | | Integer courseId = benefitsVideos.getCourseId(); |
| | | Course course = courseClient.queryCourseById(courseId); |
| | | BenefitsVideosInfoVo benefitsVideosInfoVo = new BenefitsVideosInfoVo(); |
| | | benefitsVideosInfoVo.setId(id); |
| | | benefitsVideosInfoVo.setName(course.getName()); |
| | | benefitsVideosInfoVo.setCover(course.getCoverDrawing()); |
| | | benefitsVideosInfoVo.setIntroduce(course.getIntroduce()); |
| | | benefitsVideosInfoVo.setIntroductionDrawing(course.getIntroductionDrawing()); |
| | | benefitsVideosInfoVo.setCourseVideo(course.getCourseVideo()); |
| | | benefitsVideosInfoVo.setIntegral(benefitsVideos.getIntegral()); |
| | | UserBenefitsVideos one = userBenefitsVideosService.getOne(new QueryWrapper<UserBenefitsVideos>().eq("appUserId", uid).eq("benefitsVideosId", id)); |
| | | benefitsVideosInfoVo.setStudy(null == one ? 0 : 1); |
| | | return benefitsVideosInfoVo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 视频观看完毕后获得奖励 |
| | | * @param uid |
| | | * @param id |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void receiveAward(Integer uid, Integer id) throws Exception { |
| | | BenefitsVideos benefitsVideos = this.getById(id); |
| | | UserBenefitsVideos one = userBenefitsVideosService.getOne(new QueryWrapper<UserBenefitsVideos>().eq("appUserId", uid).eq("benefitsVideosId", id)); |
| | | if(null == one){ |
| | | one = new UserBenefitsVideos(); |
| | | one.setAppUserId(uid); |
| | | one.setBenefitsVideoClassificationId(benefitsVideos.getBenefitsVideoClassificationId()); |
| | | one.setBenefitsVideosId(id); |
| | | one.setInsertTime(new Date()); |
| | | one.setIntegral(benefitsVideos.getIntegral()); |
| | | userBenefitsVideosService.save(one); |
| | | |
| | | //添加积分 |
| | | SaveUserIntegralChangesVo vo = new SaveUserIntegralChangesVo(); |
| | | vo.setAppUserId(uid); |
| | | vo.setIntegral(benefitsVideos.getIntegral()); |
| | | vo.setType(4); |
| | | userIntegralChangesClient.saveUserIntegralChanges(vo); |
| | | } |
| | | } |
| | | } |