package com.ruoyi.common.handlefile; import com.ruoyi.common.utils.PublicUtils; import com.ruoyi.common.utils.YamlUtils; import com.ruoyi.common.utils.file.FileUtils; import org.springframework.web.multipart.MultipartFile; import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Map; /** * @author jianglw * @version 1.0 * @date 2021/1/28 18:59 */ public class HandleYmlFile implements HandleFile { /** * 读取数据 */ private Map<String,Object> map; @Override public HandleFile readFile(MultipartFile file) { map=YamlUtils.getYamlFile( file ); return this; } @Override public HandleFile encryptionFile() throws Exception { map=PublicUtils.getEncryptionMap( map ) ; return this; } @Override public HandleFile decryptFile() throws Exception { map=PublicUtils.getDecryptMap( map ) ; return this; } @Override public void createFile(String fileName,String userName,String createdPath) throws IOException { Yaml yaml = new Yaml(); FileUtils.createdFile(fileName,userName,createdPath,yaml.dumpAsMap( map )); } public Map<String, Object> getMap() { return map; } public void setMap(Map<String, Object> map) { this.map = map; } }