nickchange
2023-11-09 c036557db88c6297b9a626a892dce35c14ab8ee5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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.BenefitsVideoClassificationMapper;
import com.dsh.activity.mapper.BenefitsVideosMapper;
import com.dsh.activity.model.*;
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.aspectj.weaver.ast.Var;
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>
 * 福利视频 服务实现类
 * </p>
 *
 * @author jqs
 * @since 2023-07-06
 */
@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;
    @Autowired
    private BenefitsVideoClassificationMapper benefitsVideoClassificationMapper;
    @Autowired
    private BenefitsVideosMapper benefitsVideosMapper;
 
 
 
 
 
    /**
     * 获取福利视频分类列表数据
     * @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) {
            if (benefitsVideoClassification.getState() == 1) {
                BenefitsVideoClassificationListVo benefitsVideoClassificationListVo = new BenefitsVideoClassificationListVo();
                benefitsVideoClassificationListVo.setId(benefitsVideoClassification.getId());
                benefitsVideoClassificationListVo.setName(benefitsVideoClassification.getName());
                QueryWrapper<BenefitsVideos> benefitsVideosQueryWrapper = new QueryWrapper<BenefitsVideos>().eq("state", 1).eq("benefitsVideoClassificationId", benefitsVideoClassification.getId());
                if (collect.size() > 0) {
                    benefitsVideosQueryWrapper.notIn("id", collect);
                }
                List<BenefitsVideos> list1 = this.list(benefitsVideosQueryWrapper.eq("state",1).orderByDesc("insertTime").last(" limit 0, 4"));
                List<BenefitsVideosListVo> lists = new ArrayList<>();
                for (BenefitsVideos benefitsVideos : list1) {
                    if (benefitsVideos.getState()==1) {
                        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<BenefitsVideoClassificationListVo> queryClassificationBenefitsVideosListOne(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", -1));
        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());
            QueryWrapper<BenefitsVideos> benefitsVideosQueryWrapper = new QueryWrapper<BenefitsVideos>().eq("state", 1);
            if(collect.size() > 0){
                benefitsVideosQueryWrapper.notIn("id", collect);
            }
            List<BenefitsVideos> list1 = this.list(benefitsVideosQueryWrapper.orderByDesc("insertTime").last(" limit 0, 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, String search, Integer pageSize, Integer pageNo) throws Exception {
        pageSize = (pageSize - 1) * pageNo;
        List<Integer> ids = null;
 
        if(ToolUtil.isNotEmpty(search)){
            List<Course> courses = courseClient.queryCourseByName(search);
            ids = courses.stream().map(Course::getId).collect(Collectors.toList());
        }
        int offset = (pageNo - 1) * pageSize;
        int limit = pageSize;
 
 
        List<Map<String, Object>> benefitsVideos = this.baseMapper.queryBenefitsVideosList(uid, classificationId, ids, offset, limit);
        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);
        }
    }
 
    @Override
    public List<BenefitsVideos> getBenefitVideoById(Integer id) {
        return benefitsVideosMapper.getBenefitVideoById(id);
    }
 
    @Override
    public List<BenefitsVideos> getBybIdAndcId(Integer benefitsVideoClassificationId, Integer courseId) {
        return  benefitsVideosMapper.getBybIdAndcId(benefitsVideoClassificationId,courseId);
    }
 
 
}