¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.common.util; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description: PmsUtil |
| | | * @author: jeecg-boot |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class PmsUtil { |
| | | |
| | | |
| | | private static String uploadPath; |
| | | |
| | | @Value("${jeecg.path.upload}") |
| | | public void setUploadPath(String uploadPath) { |
| | | PmsUtil.uploadPath = uploadPath; |
| | | } |
| | | |
| | | public static String saveErrorTxtByList(List<String> msg, String name) { |
| | | Date d = new Date(); |
| | | String saveDir = "logs" + File.separator + DateUtils.yyyyMMdd.get().format(d) + File.separator; |
| | | String saveFullDir = uploadPath + File.separator + saveDir; |
| | | |
| | | File saveFile = new File(saveFullDir); |
| | | if (!saveFile.exists()) { |
| | | saveFile.mkdirs(); |
| | | } |
| | | name += DateUtils.yyyymmddhhmmss.get().format(d) + Math.round(Math.random() * 10000); |
| | | String saveFilePath = saveFullDir + name + ".txt"; |
| | | |
| | | try { |
| | | //å°è£
ç®çå° |
| | | BufferedWriter bw = new BufferedWriter(new FileWriter(saveFilePath)); |
| | | //éåéå |
| | | for (String s : msg) { |
| | | //åæ°æ® |
| | | if (s.indexOf("_") > 0) { |
| | | String[] arr = s.split("_"); |
| | | bw.write("第" + arr[0] + "è¡:" + arr[1]); |
| | | } else { |
| | | bw.write(s); |
| | | } |
| | | //bw.newLine(); |
| | | bw.write("\r\n"); |
| | | } |
| | | //éæ¾èµæº |
| | | bw.flush(); |
| | | bw.close(); |
| | | } catch (Exception e) { |
| | | log.info("excel导å
¥çæé误æ¥å¿æä»¶å¼å¸¸:" + e.getMessage()); |
| | | } |
| | | return saveDir + name + ".txt"; |
| | | } |
| | | |
| | | public static String saveErrorMsgByList(List<String> msg, String name) { |
| | | Date d = new Date(); |
| | | String saveDir = "logs" + File.separator + DateUtils.yyyyMMdd.get().format(d) + File.separator; |
| | | String saveFullDir = uploadPath + File.separator + saveDir; |
| | | |
| | | File saveFile = new File(saveFullDir); |
| | | if (!saveFile.exists()) { |
| | | saveFile.mkdirs(); |
| | | } |
| | | name += DateUtils.yyyymmddhhmmss.get().format(d) + Math.round(Math.random() * 10000); |
| | | String saveFilePath = saveFullDir + name + ".txt"; |
| | | |
| | | try { |
| | | //å°è£
ç®çå° |
| | | BufferedWriter bw = new BufferedWriter(new FileWriter(saveFilePath)); |
| | | //éåéå |
| | | for (String s : msg) { |
| | | //åæ°æ® |
| | | bw.write(s); |
| | | //bw.newLine(); |
| | | bw.write("\r\n"); |
| | | } |
| | | //éæ¾èµæº |
| | | bw.flush(); |
| | | bw.close(); |
| | | } catch (Exception e) { |
| | | log.info("excel导å
¥çæé误æ¥å¿æä»¶å¼å¸¸:" + e.getMessage()); |
| | | } |
| | | return saveDir + name + ".txt"; |
| | | } |
| | | } |