Commit eb762354 authored by neo's avatar neo

[DEV] set stauts for all task

parent d10f97aa
package pwc.taxtech.atms.dto.vatdto;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import org.apache.commons.lang3.StringUtils;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.entity.Project;
import pwc.taxtech.atms.entity.Template;
......@@ -27,9 +31,8 @@ public class WrapPeriodJobDto {
job.setProjectId(projectId);
job.setPeriod(period);
job.setId(UUID.randomUUID().toString());
job.setStatus(STATUS_BEGIN);
job.setCurrentStep(STEP_UPDATE_CONFIG);
setStatus(job,STEP_UPDATE_CONFIG,STATUS_BEGIN);
StringBuilder builder = new StringBuilder(STEP_UPDATE_CONFIG);
templates.forEach(m -> {
builder.append(",").append(m.getCode());
......@@ -38,4 +41,51 @@ public class WrapPeriodJobDto {
job.setStepsCode(builder.toString());
return job;
}
public static class Task {
String code;
String status;
}
public static List<Task> fromJson(String taskJson) {
return JSONObject.parseArray(taskJson, Task.class);
}
public static String toJson(List<Task> tasks) {
return JSON.toJSONString(tasks);
}
public static void setStatus(PeriodJob periodJob, String code, String status) {
List<Task> list;
if (StringUtils.isBlank(periodJob.getStatus())) {
list = new ArrayList<>();
} else {
list = fromJson(periodJob.getStatus());
}
Task t = new Task();
t.code = code;
t.status = status;
boolean contains = false;
for (Task m : list) {
if (m.code.equals(t.code)) {
m.status = status;
contains = true;
break;
}
}
if(!contains)list.add(t);
periodJob.setStatus(toJson(list));
}
public static void setStatus(PeriodJob periodJob, String status) {
List<Task> list;
if (StringUtils.isBlank(periodJob.getStatus())) {
list = new ArrayList<>();
} else {
list = fromJson(periodJob.getStatus());
}
list.get(list.size()-1).status=status;
periodJob.setStatus(toJson(list));
}
}
......@@ -44,6 +44,7 @@ import java.util.stream.Collectors;
import static pwc.taxtech.atms.common.util.SpringContextUtil.reportMapper;
import static pwc.taxtech.atms.constant.Constant.EMPTY;
import static pwc.taxtech.atms.dto.vatdto.WrapPeriodJobDto.*;
@Component
public class ReportGeneratorImpl {
......@@ -93,7 +94,7 @@ public class ReportGeneratorImpl {
Sheet sheet = workbook.getSheetAt(i);
String code = sheet.getSheetName();
logger.info("-------------------------------------Begin Job [{}]------------------------------------------------------", code);
job.setCurrentStep(code);
setStatus(job,code,STATUS_BEGIN);
periodJobMapper.updateByPrimaryKey(job);
Optional<PeriodTemplate> periodTemplate = resources.getPeriodTemplates().stream()
......@@ -385,7 +386,8 @@ public class ReportGeneratorImpl {
}
}
}
setStatus(job,code,STATUS_END);
periodJobMapper.updateByPrimaryKey(job);
logger.info("-------------------------------------End Job [{}]------------------------------------------------------", code);
}
}
......
......@@ -42,6 +42,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static pwc.taxtech.atms.dto.vatdto.WrapPeriodJobDto.*;
@Component
public class ReportServiceImpl {
private final static Logger logger = LoggerFactory.getLogger(ReportServiceImpl.class);
......@@ -476,6 +478,7 @@ public class ReportServiceImpl {
try {
updateConfig(projectId, periodParam, isMergeManualData, templates, genJob);
setStatus(genJob,STEP_UPDATE_CONFIG,STATUS_END);
PeriodResources resources = reportGenerator.getPeriodResources(projectId, periodParam,
templates.stream().map(Template::getId).collect(Collectors.toList()));
......@@ -489,12 +492,8 @@ public class ReportServiceImpl {
evaluator.evaluateAll();
reportGenerator.updateWorkbookCaclsValueToDb(projectId, periodParam, workbook, resources, isMergeManualData, genJob);
genJob.setStatus(WrapPeriodJobDto.STATUS_END);
periodJobMapper.updateByPrimaryKey(genJob);
} catch (Exception e) {
genJob.setStatus(WrapPeriodJobDto.STATUS_ERROR);
setStatus(genJob,STATUS_ERROR);
genJob.setErrorMsg("Sever error "+e.getMessage());
periodJobMapper.updateByPrimaryKey(genJob);
e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment