fuliqi
2024-07-10 3b59408f8da4c87da5aacd29cd1b7b0f2575b5ad
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
package com.ycl.jxkg.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.jxkg.domain.entity.TextContent;
import com.ycl.jxkg.mapper.TextContentMapper;
import com.ycl.jxkg.service.TextContentService;
import com.ycl.jxkg.utils.JsonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
 
@Service
@RequiredArgsConstructor
public class TextContentServiceImpl extends ServiceImpl<TextContentMapper, TextContent> implements TextContentService {
 
    private final TextContentMapper textContentMapper;
 
    public TextContent selectById(Integer id) {
        return baseMapper.selectById(id);
    }
 
    public int insertByFilter(TextContent record) {
        return baseMapper.insert(record);
    }
 
    public int updateByIdFilter(TextContent record) {
        return baseMapper.updateById(record);
    }
 
    @Override
    public <T, R> TextContent 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);
        }
        TextContent textContent = new TextContent();
        textContent.setContent(frameTextContent);
        textContent.setCreateTime(now);
        return textContent;
    }
 
    @Override
    public <T, R> TextContent jsonConvertUpdate(TextContent 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;
    }
 
 
 
}