|
|
|
|
@ -1,11 +1,20 @@
|
|
|
|
|
package com.worker.util.textFileMacker;
|
|
|
|
|
|
|
|
|
|
import com.worker.domain.entity.CpSetinfo;
|
|
|
|
|
import com.worker.scheduler.epost.dto.EPostDto;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.UncheckedIOException;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
@Slf4j
|
|
|
|
|
@ -14,15 +23,30 @@ public class TextMaker {
|
|
|
|
|
String s(String v){ return v==null? "": v.replace("|",""); }
|
|
|
|
|
String t(String v){ return v==null? "": v.replace("\r","").replace("\n","\\n").replace("|",""); }
|
|
|
|
|
|
|
|
|
|
public void generateTextFile(List<EPostDto.SendTarget.Target> cpSendEpostTargets,
|
|
|
|
|
List<EPostDto.SendTarget.Target> epSendEpostTargets,
|
|
|
|
|
List<EPostDto.SendTarget.Target> cpSendEgojiTargets,
|
|
|
|
|
List<EPostDto.SendTarget.Target> epSendEgojiTargets
|
|
|
|
|
) {
|
|
|
|
|
public void generateTextFile(List<EPostDto.SendTarget.Target> sendTargets, CpSetinfo setInfo) {
|
|
|
|
|
|
|
|
|
|
// cpSendTargets을
|
|
|
|
|
log.info(epSendEpostTargets.toString());
|
|
|
|
|
// 전체 타겟을 콘키별로 묶음.
|
|
|
|
|
Map<String, List<EPostDto.SendTarget.Target>> sendTargetGroupingByConkey = sendTargets.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(EPostDto.SendTarget.Target::getConKey));
|
|
|
|
|
|
|
|
|
|
//key로 택스트파일 생성
|
|
|
|
|
sendTargetGroupingByConkey.forEach((conKey, targets) -> {
|
|
|
|
|
Path baseDir = Path.of(setInfo.getStrValue8());
|
|
|
|
|
Path out = baseDir.resolve(conKey + ".txt");
|
|
|
|
|
|
|
|
|
|
List<String> lines = new ArrayList<>(targets.size());
|
|
|
|
|
for(int i = 0; i < targets.size(); i++) {
|
|
|
|
|
EPostDto.SendTarget.Target target = targets.get(i);
|
|
|
|
|
lines.add(addLine(target, String.valueOf(i), String.valueOf(targets.size()), conKey));
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
Files.write(out, lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new UncheckedIOException("파일 쓰기 실패: " + out, e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
log.info(sendTargetGroupingByConkey.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|