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;
|
}
|
}
|