package com.mzl.flower.service.system;
|
|
import com.mzl.flower.config.exception.ValidationException;
|
import com.mzl.flower.config.security.SecurityUtils;
|
import com.mzl.flower.dto.request.system.ContentSaveDTO;
|
import com.mzl.flower.dto.response.system.ContentDTO;
|
import com.mzl.flower.dto.response.system.ContentListDTO;
|
import com.mzl.flower.entity.system.ConfigContent;
|
import com.mzl.flower.mapper.system.ConfigContentMapper;
|
import com.mzl.flower.service.BaseService;
|
import io.micrometer.core.instrument.util.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Service
|
@Transactional
|
public class ConfigContentService extends BaseService {
|
|
@Autowired
|
private ConfigContentMapper contentMapper;
|
|
public String saveContent(ContentSaveDTO dto) {
|
String id = dto.getId();
|
if(StringUtils.isEmpty(id)){
|
throw new ValidationException("id不能为空");
|
}
|
ConfigContent cc = contentMapper.selectById(id);
|
|
if(cc == null){
|
cc = new ConfigContent();
|
BeanUtils.copyProperties(dto, cc);
|
cc.create(SecurityUtils.getUserId());
|
contentMapper.insert(cc);
|
} else {
|
BeanUtils.copyProperties(dto, cc);
|
cc.update(SecurityUtils.getUserId());
|
contentMapper.updateById(cc);
|
}
|
|
return id;
|
}
|
|
public List<ContentListDTO> selectContentList(){
|
List<ConfigContent> ls = contentMapper.selectList(null);
|
|
List<ContentListDTO> result = new ArrayList<>();
|
if(ls != null && ls.size() > 0){
|
for(ConfigContent cc : ls){
|
ContentListDTO dto = new ContentListDTO();
|
BeanUtils.copyProperties(cc, dto);
|
|
result.add(dto);
|
}
|
}
|
|
return result;
|
}
|
|
public ContentDTO getContent(String id){
|
ConfigContent cc = contentMapper.selectById(id);
|
ContentDTO dto = new ContentDTO();
|
if(cc!=null){
|
BeanUtils.copyProperties(cc, dto);
|
}
|
return dto;
|
}
|
}
|