package com.ycl.jxkg.service.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ycl.jxkg.domain.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.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
|
@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;
|
}
|
|
|
|
}
|