package com.xcong.farmer.cms.modules.system.service.Impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.xcong.farmer.cms.common.exception.GlobalException;
|
import com.xcong.farmer.cms.common.utils.FileUtils;
|
import com.xcong.farmer.cms.configurations.GlobalExceptionHandler;
|
import com.xcong.farmer.cms.core.template.TemplateConfiguration;
|
import com.xcong.farmer.cms.modules.system.dto.TemplateListDto;
|
import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity;
|
import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper;
|
import com.xcong.farmer.cms.modules.system.service.ICmsTemplateService;
|
import com.xcong.farmer.cms.modules.system.util.LoginUserUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* @author wzy
|
* @date 2022-07-04
|
**/
|
@Service
|
public class CmsTemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTemplateEntity> implements ICmsTemplateService {
|
|
@Autowired
|
private TemplateConfiguration cfg;
|
|
private List<String> fileSuffix = Arrays.asList(".zip", ".html");
|
|
@Override
|
public void updateTemplate(MultipartFile upload) {
|
String templatePath = cfg.templatePath;
|
String staticPath = cfg.staticPath;
|
|
String filename = upload.getOriginalFilename();
|
String suffix = filename.substring(filename.lastIndexOf("."));
|
|
if (!fileSuffix.contains(suffix)) {
|
throw new GlobalException("请上传正确格式文件");
|
}
|
|
try {
|
if (".zip".equals(suffix)) {
|
String path = FileUtils.path(templatePath, filename);
|
System.out.println(path);
|
File file = new File(path);
|
upload.transferTo(file);
|
FileUtils.zipUpload(file, templatePath, staticPath);
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
System.out.println(suffix);
|
}
|
|
@Override
|
public IPage<CmsTemplateEntity> findInPage(TemplateListDto templateListDto) {
|
Long companyId = LoginUserUtil.getCompanyId();
|
IPage<CmsTemplateEntity> page = new Page<>(templateListDto.getPageNum(), templateListDto.getPageSize());
|
|
CmsTemplateEntity template = new CmsTemplateEntity();
|
template.setCompanyId(companyId);
|
return this.baseMapper.selectInPage(page, template);
|
}
|
|
@Override
|
public void delete(Long id) {
|
Long companyId = LoginUserUtil.getCompanyId();
|
this.baseMapper.delete(id, companyId);
|
}
|
}
|