| | |
| | | package com.xcong.farmer.cms.modules.system.service.Impl; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.io.file.FileWriter; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.core.util.ZipUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import com.xcong.farmer.cms.common.exception.GlobalException; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.common.utils.FileUtils; |
| | | import com.xcong.farmer.cms.configurations.GlobalExceptionHandler; |
| | | import com.xcong.farmer.cms.configurations.properties.CmsProperties; |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminSaveTemplateInfoDto; |
| | | 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.entity.UserEntity; |
| | | 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.jsoup.nodes.Document; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result saveTemplateInfo(AdminSaveTemplateInfoDto adminSaveTemplateInfoDto) { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | Long id = adminSaveTemplateInfoDto.getId(); |
| | | CmsTemplateEntity cmsTemplateEntity = this.baseMapper.selectByIdAndCompanyId(id,companyId); |
| | | String name = cmsTemplateEntity.getName(); |
| | | Integer type = cmsTemplateEntity.getType(); |
| | | String templatePath = cmsProperties.getTemplatePath(); |
| | | String path = cmsTemplateEntity.getPath(); |
| | | |
| | | this.baseMapper.delete(id,companyId); |
| | | String pathNew = FileUtils.path(templatePath, path); |
| | | File file = new File(pathNew); |
| | | FileUtil.touch(file); |
| | | |
| | | //文件写入,直接覆盖 |
| | | FileWriter writer = new FileWriter(file); |
| | | writer.write(adminSaveTemplateInfoDto.getTemplateInfo(), false); |
| | | |
| | | CmsTemplateEntity cmsTemplate = new CmsTemplateEntity(); |
| | | cmsTemplate.setCompanyId(companyId); |
| | | cmsTemplate.setType(type); |
| | | cmsTemplate.setName(name); |
| | | cmsTemplate.setPath(path); |
| | | this.baseMapper.insert(cmsTemplate); |
| | | |
| | | return Result.ok("保存成功"); |
| | | } |
| | | |
| | | } |