xiangpei
2025-05-14 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403
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
package com.mindskip.xzs.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.OnlineStudy;
import com.mindskip.xzs.domain.question.QuestionObject;
import com.mindskip.xzs.domain.vo.OnlineStudyVO;
import com.mindskip.xzs.domain.vo.StudentOnlineVO;
import com.mindskip.xzs.domain.vo.StudyTypeVO;
import com.mindskip.xzs.repository.OnlineStudyMapper;
import com.mindskip.xzs.repository.StudyTypeMapper;
import com.mindskip.xzs.service.OnlineStudyService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * @author:xp
 * @date:2024/5/16 10:53
 */
@Service
@RequiredArgsConstructor
public class OnlineStudySeerviceImpl implements OnlineStudyService {
 
    private final OnlineStudyMapper mapper;
    private final StudyTypeMapper studyTypeMapper;
 
    @Override
    public RestResponse add(OnlineStudyVO form) {
        OnlineStudy onlineStudy = new OnlineStudy();
        BeanUtils.copyProperties(form, onlineStudy);
        if (Objects.nonNull(form.getContentUrl())) {
            onlineStudy.setContentUrl(JSON.toJSONString(form.getContentUrl()));
        }
        if (! CollectionUtils.isEmpty(form.getAttachment())) {
            onlineStudy.setAttachment(JSON.toJSONString(form.getAttachment()));
        }
        onlineStudy.setCreateTime(new Date());
        onlineStudy.setUpdateTime(new Date());
        mapper.add(onlineStudy);
        return RestResponse.ok("添加成功");
    }
 
    @Override
    public RestResponse update(OnlineStudyVO form) {
        if (Objects.isNull(form.getId())) {
            throw new RuntimeException("请选择要修改的数据");
        }
        OnlineStudy onlineStudy = new OnlineStudy();
        BeanUtils.copyProperties(form, onlineStudy);
        onlineStudy.setContentUrl(JSON.toJSONString(form.getContentUrl()));
        if (! CollectionUtils.isEmpty(form.getAttachment())) {
            onlineStudy.setAttachment(JSON.toJSONString(form.getAttachment()));
        } else {
            onlineStudy.setAttachment("");
        }
        mapper.update(onlineStudy);
        return RestResponse.ok("修改成功");
    }
 
    @Override
    public RestResponse remove(List<Integer> ids) {
        mapper.remove(ids);
        return RestResponse.ok("删除成功");
    }
 
    @Override
    public RestResponse page(OnlineStudyVO query) {
        PageInfo<OnlineStudyVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() ->
                mapper.page(query));
        page.getList().stream().forEach(item -> {
            item.setContentUrl(JSON.parseObject(item.getContentUrlString(), OnlineStudyVO.UploadFile.class));
            item.setAttachment(JSON.parseArray(item.getAttachmentString(), OnlineStudyVO.UploadFile.class));
        });
        return RestResponse.ok(page.getList()).put("total", page.getTotal());
    }
 
    @Override
    public RestResponse byType(StudentOnlineVO query) {
        PageInfo<OnlineStudyVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() ->
                mapper.byType(query));
        page.getList().stream().forEach(item -> {
            item.setContentUrl(JSON.parseObject(item.getContentUrlString(), OnlineStudyVO.UploadFile.class));
            item.setAttachment(JSON.parseArray(item.getAttachmentString(), OnlineStudyVO.UploadFile.class));
        });
        return RestResponse.ok(page.getList()).put("total", page.getTotal());
    }
 
    @Override
    public RestResponse typeList() {
        List<StudyTypeVO> list = studyTypeMapper.list();
        return RestResponse.ok(list);
    }
}