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 selectTTextContentByIds(String[] ids) { return tTextContentMapper.selectTTextContentByIds(ids); } @Override public List selectTextContentAndQuestion(String[] ids) { return tTextContentMapper.selectTextContentAndQuestion(ids); } @Override public List 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 TTextContent jsonConvertInsert(List list, Date now, Function mapper) { String frameTextContent = null; if (null == mapper) { frameTextContent = JsonUtil.toJsonStr(list); } else { List mapList = list.stream().map(mapper).collect(Collectors.toList()); frameTextContent = JsonUtil.toJsonStr(mapList); } TTextContent textContent = new TTextContent(frameTextContent, now); return textContent; } @Override public TTextContent jsonConvertUpdate(TTextContent textContent, List list, Function mapper) { String frameTextContent = null; if (null == mapper) { frameTextContent = JsonUtil.toJsonStr(list); } else { List mapList = list.stream().map(mapper).collect(Collectors.toList()); frameTextContent = JsonUtil.toJsonStr(mapList); } textContent.setContent(frameTextContent); return textContent; } }