linzhijie
2021-04-12 c632636e2f5b4188b430f5efc9d9f68c8dbe3d6d
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
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;
    }
}