| | |
| | | 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 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 |
| | |
| | | @Autowired |
| | | private TemplateConfiguration cfg; |
| | | |
| | | private List<String> fileSuffix = Arrays.asList(".zip", ".html"); |
| | | |
| | | @Override |
| | | public void updateTemplate(MultipartFile file) { |
| | | 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 |