package com.example.survey.util; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; import com.example.survey.dao.RecordDao; import com.example.survey.entity.Record; import com.example.survey.enumeration.RecordStateEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import lombok.Data; @Data @Component public class CaseQuestionnaireUtil implements Runnable { public static void main() { CaseQuestionnaireUtil c = new CaseQuestionnaireUtil(); // Record record = // c.setRecord(record); c.start(); } private Record record; private Thread t; private String threadName; @Value("${file.path}") private String path; @Value("${file.report}") private String report; @Value("${file.template}") private String template; @Autowired private RecordDao recordDao; @Override public void run() { if (record != null) { System.out.println("=========Start Export============"); String templatePath = this.template + record.getMetaData().getName() + ".docx"; String outputPath = this.report + record.getUuid() + ".docx"; try { Map values = record.getValues(); if (!values.containsKey("调查人")) values.put("调查人", record.getOperationList().get(0).getUser().getUsername()); if (!values.containsKey("调查日期")) values.put("调查日期", new SimpleDateFormat("yyyy年MM月dd日").format(new java.util.Date())); WordUtil wordUtil = new WordUtil(values, templatePath, outputPath); wordUtil.export2QuestionnaireWord(); record.setState(RecordStateEnum.REVIEWED.getValue()); recordDao.saveRecord(record); } catch (Exception e) { e.printStackTrace(); } } } public void start() { t = new Thread(this, threadName); t.start(); } }