Survey/src/main/java/com/example/survey/util/CaseQuestionnaireUtil.java
2021-12-26 17:54:05 +08:00

80 lines
2.5 KiB
Java

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 com.google.common.collect.Multiset.Entry;
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<String, Object> values = record.getValues();
Map<String, Object> newValues = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : values.entrySet()) {
newValues.put(entry.getKey().trim(), entry.getValue());
}
if (!newValues.containsKey("调查人"))
newValues.put("调查人", record.getOperationList().get(0).getUser().getUsername());
if (!newValues.containsKey("调查日期"))
newValues.put("调查日期", new SimpleDateFormat("yyyy年MM月dd日").format(new java.util.Date()));
WordUtil wordUtil = new WordUtil(newValues, 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();
}
}