package com.ots.project.exam.service.impl;
|
import com.ots.common.utils.DateUtils;
|
import com.ots.common.utils.text.Convert;
|
import com.ots.project.exam.domain.TTextContent;
|
import com.ots.project.exam.domain.TTextContentAndQuestion;
|
import com.ots.project.exam.mapper.TTextContentMapper;
|
import com.ots.project.exam.service.ITTextContentService;
|
import com.ots.project.tool.exam.JsonUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.function.Function;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class TTextContentServiceImpl implements ITTextContentService {
|
@Autowired
|
private TTextContentMapper tTextContentMapper;
|
|
@Override
|
public TTextContent selectTTextContentById(Long id) {
|
return tTextContentMapper.selectTTextContentById(id);
|
}
|
|
@Override
|
public List<TTextContent> selectTTextContentByIds(String[] ids) {
|
return tTextContentMapper.selectTTextContentByIds(ids);
|
}
|
@Override
|
public List<TTextContentAndQuestion> selectTextContentAndQuestion(String[] ids) {
|
return tTextContentMapper.selectTextContentAndQuestion(ids);
|
}
|
|
@Override
|
public List<TTextContent> selectTTextContentList(TTextContent tTextContent) {
|
return tTextContentMapper.selectTTextContentList(tTextContent);
|
}
|
|
@Override
|
public int insertTTextContent(TTextContent tTextContent) {
|
tTextContent.setCreateTime(DateUtils.getNowDate());
|
return tTextContentMapper.insertTTextContent(tTextContent);
|
}
|
|
@Override
|
public int updateTTextContent(TTextContent tTextContent) {
|
tTextContent.setUpdateTime(DateUtils.getNowDate());
|
return tTextContentMapper.updateTTextContent(tTextContent);
|
}
|
|
@Override
|
public int deleteTTextContentByIds(String ids) {
|
return tTextContentMapper.deleteTTextContentByIds(Convert.toStrArray(ids));
|
}
|
|
public int deleteTTextContentById(Long id) {
|
return tTextContentMapper.deleteTTextContentById(id);
|
}
|
@Override
|
public <T, R> TTextContent jsonConvertInsert(List<T> list, Date now, Function<? super T, ? extends R> mapper) {
|
String frameTextContent = null;
|
if (null == mapper) {
|
frameTextContent = JsonUtil.toJsonStr(list);
|
} else {
|
List<R> mapList = list.stream().map(mapper).collect(Collectors.toList());
|
frameTextContent = JsonUtil.toJsonStr(mapList);
|
}
|
TTextContent textContent = new TTextContent(frameTextContent, now);
|
|
return textContent;
|
}
|
@Override
|
public <T, R> TTextContent jsonConvertUpdate(TTextContent textContent, List<T> list, Function<? super T, ? extends R> mapper) {
|
String frameTextContent = null;
|
if (null == mapper) {
|
frameTextContent = JsonUtil.toJsonStr(list);
|
} else {
|
List<R> mapList = list.stream().map(mapper).collect(Collectors.toList());
|
frameTextContent = JsonUtil.toJsonStr(mapList);
|
}
|
textContent.setContent(frameTextContent);
|
|
return textContent;
|
}
|
}
|