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 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 TextContent 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); } TextContent textContent = new TextContent(); textContent.setContent(frameTextContent); textContent.setCreateTime(now); return textContent; } @Override public TextContent jsonConvertUpdate(TextContent 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; } }