feiyu02
2022-06-28 5670e4a15fba292ef5f8fb90e96072de976bb621
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
package cn.flightfeather.supervision.lightshare.service.Impl;
 
import cn.flightfeather.supervision.domain.entity.OnLineQuestion;
import cn.flightfeather.supervision.domain.mapper.OnLineQuestionMapper;
import cn.flightfeather.supervision.lightshare.service.OnLineQuestionService;
import cn.flightfeather.supervision.lightshare.vo.QCondition;
import com.github.pagehelper.PageHelper;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
 
/**
*@Description: 月问题实现类
*@author :LiuYuJun
*@Date:2019/7/10
*@Time:13:52
*/
@Service
@Component
public class OnLineQuestionServiceImpl implements OnLineQuestionService {
    @Resource
    private OnLineQuestionMapper onLineQuestionMapper;
 
    @Override
    public int addQuestions(@NotNull String userId, @NotNull List<? extends OnLineQuestion> questions) {
        int r = 0;
        for (OnLineQuestion q:questions) {
            r += onLineQuestionMapper.insert(q);
        }
        return r;
    }
 
    @NotNull
    @Override
    public List<OnLineQuestion> getQuestions(@NotNull String userId, boolean inUse, int page, int perPage, @NotNull HttpServletResponse httpServletResponse) {
 
        // 1.计算出起始位置
        int startPosition = (page-1)*perPage;
        //2.分页的方法查询数据
        PageHelper.startPage(startPosition,perPage);
        List<OnLineQuestion> allMeetings;
        //3.分页显示数据
        if (inUse){
            allMeetings = onLineQuestionMapper.findAll();
        }else {
            allMeetings = onLineQuestionMapper.findAllfalse();
        }
        int counts = onLineQuestionMapper.count();
        int totalPage = (int)Math.ceil(counts/perPage*1.0);
        httpServletResponse.setIntHeader("totalPage",totalPage);
        httpServletResponse.setIntHeader("currentPage",page);
        return allMeetings;
    }
 
    @NotNull
    @Override
    public String getQDescription(@NotNull String userId, @NotNull String questionId) {
        return onLineQuestionMapper.getQDescription(questionId);
    }
 
    @NotNull
    @Override
    public List<String> getQResource(@NotNull String userId, @NotNull String questionId, int page, int perPage, @NotNull HttpServletResponse httpServletResponse){
        // 1.计算出起始位置
        int startPosition = (page-1)*perPage;
        String getQDescription = onLineQuestionMapper.getQResource(questionId);
        List<String> lis = Arrays.asList(getQDescription.split("、"));
        List<String> result ;
        if (startPosition+perPage<lis.size()){
            result = lis.subList(startPosition,startPosition+perPage);
        }else {
            result = lis.subList(startPosition,lis.size());
        }
        int counts = lis.size();
        int totalPage = (int)Math.ceil(counts/perPage*1.0);
        httpServletResponse.setIntHeader("totalPage",totalPage);
        httpServletResponse.setIntHeader("currentPage",page);
        return result;
    }
 
    @NotNull
    @Override
    public List<OnLineQuestion> getQByConditions(@NotNull String userId, boolean inUse, @NotNull QCondition qCondition, int page, int perPage, @NotNull HttpServletResponse httpServletResponse) {
        String keywords = qCondition.getKeywords();
        Byte factorType = qCondition.getFactorType();
        Byte resourceKind = qCondition.getResourceKind();
        Byte showLevel = qCondition.getShowLevel();
        Byte worKind = qCondition.getWorKind();
        // 1.计算出起始位置
        int startPosition = (page-1)*perPage;
        //2.分页的方法查询数据
        PageHelper.startPage(startPosition,perPage);
        //3.分页显示数据  //模糊查询
        List<OnLineQuestion> result = onLineQuestionMapper.getQByConditions(keywords,factorType,resourceKind,showLevel,worKind);
 
        int counts = onLineQuestionMapper.getQByConditionsCounts(keywords,factorType,resourceKind,showLevel,worKind);
        int totalPage = (int)Math.ceil(counts/perPage*1.0);
        httpServletResponse.setIntHeader("totalPage",totalPage);
        httpServletResponse.setIntHeader("currentPage",page);
        return result;
    }
}