101captain
2022-02-18 307ea3042f5b03e735772e5d3eaad8d5fc16b6ba
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/AssemblyUtils.java
@@ -2,7 +2,6 @@
import com.panzhihua.common.model.vos.community.ComActQuestnaireAnswerContentVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import javax.imageio.ImageIO;
import javax.xml.bind.DatatypeConverter;
@@ -34,16 +33,21 @@
        //构建单个用户数据
        List<Object> userData = new ArrayList<>();
        String noExport = "以上信息仅用于疫苗防控";
        String noExport = "以上信息仅用于";
        //遍历答案列表
        Long reserveRecordId = 0L;
        Long reserveSubId = 0L;
        Boolean isOldDuo = false;
        StringBuffer sb = new StringBuffer();
        if (answerContentVOList != null && answerContentVOList.size() > 0) {
            int a=0;
            for (ComActQuestnaireAnswerContentVO userAnswers : answerContentVOList) {
                a++;
                if(answerContentVOList.size()==26&&a==9){
                   userData.add(" ");
                }
                //判断是文字描述直接跳过
                if (userAnswers.getOptionType().equals(5) || userAnswers.getOptionType().equals(11)
                if (userAnswers.getOptionType().equals(5)
                        || (StringUtils.isNotEmpty(userAnswers.getAnswerContent()) && userAnswers.getAnswerContent().contains(noExport))) {
                    continue;
                }
@@ -90,7 +94,19 @@
                        if(userAnswers.getOptionType().equals(11)){
                            reserveSubId = userAnswers.getReserveSubId();
                            try {
                                userData.add(new URL(userAnswers.getAnswerContent()));
                                if(StringUtils.isNotEmpty(userAnswers.getAnswerContent())){
                                    if(userAnswers.getAnswerContent().contains("_compress")){
                                        userData.add(new URL(userAnswers.getAnswerContent()));
                                    }
                                    else {
                                        userData.add(new URL(userAnswers.getAnswerContent().substring(0,userAnswers.getAnswerContent().lastIndexOf("."))+"_compress.jpg"));
                                        log.info(userAnswers.getAnswerContent().substring(0,userAnswers.getAnswerContent().lastIndexOf("."))+"_compress.jpg");
                                    }
                                    //userData.add(new File("/workspace/minio/data/files/"+userAnswers.getAnswerContent().substring(userAnswers.getAnswerContent().indexOf("files/")+6)));
                                }
                                else {
                                    userData.add(" ");
                                }
                            }catch (Exception e){
                                userData.add(" ");
                                log.error("导出转换图片失败!");
@@ -134,7 +150,19 @@
                        if(userAnswers.getOptionType().equals(11)){
                            reserveSubId = userAnswers.getReserveSubId();
                            try {
                                userData.add(new URL(userAnswers.getAnswerContent()));
                                if(StringUtils.isNotEmpty(userAnswers.getAnswerContent())){
                                    if(userAnswers.getAnswerContent().contains("_compress")){
                                        userData.add(new URL(userAnswers.getAnswerContent()));
                                        log.info(userAnswers.getAnswerContent().substring(0,userAnswers.getAnswerContent().lastIndexOf("."))+"_compress.jpg");
                                    }
                                    else {
                                        userData.add(new URL(userAnswers.getAnswerContent().substring(0,userAnswers.getAnswerContent().lastIndexOf("."))+"_compress.jpg"));
                                    }
                                    //userData.add(new File("/workspace/minio/data/files/"+userAnswers.getAnswerContent().substring(userAnswers.getAnswerContent().indexOf("files/")+6)));
                                }
                                else {
                                    userData.add(" ");
                                }
                            }catch (Exception e){
                                userData.add(" ");
                                log.error("导出转换图片失败!");
@@ -179,19 +207,5 @@
            resultList.add(userData);
        }
        return resultList;
    }
    public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException {
        File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile);
        resultFile.deleteOnExit();
        FileUtils.copyToFile(inputStream, resultFile);
        return resultFile;
    }
    public static File bytesToFile(byte[] bytes, String fileType) throws IOException {
        return createTmpFile(new ByteArrayInputStream(bytes),
                UUID.randomUUID().toString(),
                fileType,
                Files.createTempDirectory("tempFile").toFile());
    }
}