| | |
| | | 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.CompanyEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.CompanyMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.ICmsTemplateService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import org.jsoup.Jsoup; |
| | |
| | | @Autowired |
| | | private CmsProperties properties; |
| | | |
| | | @Autowired |
| | | private CompanyMapper companyMapper; |
| | | |
| | | |
| | | private List<String> fileSuffix = Arrays.asList(".zip", ".html"); |
| | | |
| | | @Override |
| | |
| | | String templatePath = properties.getTemplatePath(); |
| | | String staticPath = properties.getStaticPath(); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | CompanyEntity company = companyMapper.selectById(companyId); |
| | | |
| | | String companyCode = company.getCode(); |
| | | templatePath = FileUtils.path(templatePath, companyCode); |
| | | staticPath = FileUtils.path(staticPath, companyCode); |
| | | |
| | | String filename = upload.getOriginalFilename(); |
| | | String suffix = filename.substring(filename.lastIndexOf(".")); |
| | |
| | | continue; |
| | | } |
| | | |
| | | insertTemplate(templateFile, companyId); |
| | | insertTemplate(templateFile, companyId, companyCode); |
| | | } |
| | | } |
| | | |
| | | if (".html".equals(suffix)) { |
| | | FileUtil.touch(file); |
| | | |
| | | insertTemplate(file, companyId); |
| | | insertTemplate(file, companyId, companyCode); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | } |
| | | |
| | | private void insertTemplate(File file, Long companyId) throws IOException { |
| | | private void insertTemplate(File file, Long companyId, String companyCode) throws IOException { |
| | | Document parse = Jsoup.parse(file, null); |
| | | String attr = parse.head().attr("name"); |
| | | |
| | | staticPathParser(parse, "img", "src"); |
| | | staticPathParser(parse, "link", "href"); |
| | | staticPathParser(parse, "script", "src"); |
| | | staticPathParser(parse, "img", "src", companyCode); |
| | | staticPathParser(parse, "link", "href", companyCode); |
| | | staticPathParser(parse, "script", "src", companyCode); |
| | | |
| | | FileOutputStream outputStream = new FileOutputStream(file); |
| | | outputStream.write(parse.html().getBytes()); |
| | |
| | | this.baseMapper.insert(cmsTemplate); |
| | | } |
| | | |
| | | private void staticPathParser(Document document, String tagName, String attrKey) { |
| | | private void staticPathParser(Document document, String tagName, String attrKey, String companyCode) { |
| | | Elements elements = document.getElementsByTag(tagName); |
| | | if (elements.isEmpty()) { |
| | | return; |
| | |
| | | for (Element element : elements) { |
| | | String attr = element.attr(attrKey); |
| | | if (StrUtil.isNotBlank(attr) && !attr.contains("http://") && !attr.contains("https://")) { |
| | | element.attr(attrKey, cmsProperties.getStaticPath() + attr); |
| | | element.attr(attrKey, cmsProperties.getStaticUrl() + companyCode + "/" + attr); |
| | | } |
| | | } |
| | | } |