Ver código fonte

初始化数据 任务 完成

master
PoffyZhang 1 ano atrás
pai
commit
7a2af3931d
1 arquivos alterados com 76 adições e 36 exclusões
  1. +76
    -36
      pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java

+ 76
- 36
pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java Ver arquivo

@@ -1,9 +1,12 @@
package com.ningdatech.pmapi.scheduler.task;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Maps;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.pmapi.scheduler.contants.TaskContant;
import com.ningdatech.pmapi.sys.contants.RegionContant;
@@ -12,6 +15,9 @@ import com.ningdatech.pmapi.sys.service.IRegionService;
import com.wflow.bean.entity.WflowForms;
import com.wflow.bean.entity.WflowModelHistorys;
import com.wflow.bean.entity.WflowModels;
import com.wflow.contants.WflowContant;
import com.wflow.mapper.WflowModelHistorysMapper;
import com.wflow.mapper.WflowModelsMapper;
import com.wflow.workflow.service.ProcessModelService;
import com.wflow.workflow.service.WflowFormsService;
import lombok.RequiredArgsConstructor;
@@ -20,10 +26,12 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.LocalDateTime;
import java.util.List;
import java.time.ZoneOffset;
import java.util.*;

/**
* @author ZPF
@@ -41,8 +49,12 @@ public class InitProcessTask {

private final ProcessModelService processModelService;

private final WflowModelHistorysMapper modelHistoriesMapper;

private final WflowModelsMapper modelsMapper;

// 定时更新车辆状态
@Scheduled(cron = "0 52 15 18 1 ?")
@Scheduled(cron = "0 47 15 28 1 ?")
public void doTask() throws UnknownHostException {
if (TaskContant.Host.HOST_ZPF.equals(InetAddress.getLocalHost().getHostName())) {
log.info("=========== 初始化丽水二期 系统表单和流程配置 ======== 任务开始");
@@ -57,30 +69,34 @@ public class InitProcessTask {
throw new BizException("丽水地区数据为空 任务结束!");
}

//2.首先插入表单默认配置
for(Region region : regions){
log.info("当前初始化的是 【{}】 表单信息",region.getName());


if(formsService.count(Wrappers.lambdaQuery(WflowForms.class)
.eq(WflowForms::getRegionCode,region.getRegionCode())) > 0){
log.info("当前区域 【{}】 已经有表单数据 不需要初始化",region.getName());
continue;
}

WflowForms wflowForms = new WflowForms();
wflowForms.setFormId("fm" + IdUtil.objectId());
wflowForms.setCreateOn(LocalDateTime.now());
wflowForms.setUpdateOn(LocalDateTime.now());
wflowForms.setFormName(TaskContant.Wflow.DEFAULT_FORM_NAME);
wflowForms.setRegionCode(region.getRegionCode());
wflowForms.setRegionName(region.getName());
if(formsService.save(wflowForms)){
log.info("当前区域 【{}】 已经有表单数据已经保存成功",region.getName());
}else{
log.info("当前区域 【{}】 已经有表单数据已经保存失败",region.getName());
}
}
// Map<String,WflowForms> formsMap = Maps.newConcurrentMap();
// //2.首先插入表单默认配置
// for(Region region : regions){
// log.info("当前初始化的是 【{}】 表单信息",region.getName());
//
// WflowForms existsForm = formsService.getOne(Wrappers.lambdaQuery(WflowForms.class)
// .eq(WflowForms::getRegionCode, region.getRegionCode())
// .last("limit 1"));
// if(Objects.nonNull(existsForm)){
// log.info("当前区域 【{}】 已经有表单数据 不需要初始化",region.getName());
// formsMap.put(existsForm.getRegionCode(),existsForm);
// continue;
// }
//
// WflowForms wflowForms = new WflowForms();
// wflowForms.setFormId("fm" + IdUtil.objectId());
// wflowForms.setCreateOn(LocalDateTime.now());
// wflowForms.setUpdateOn(LocalDateTime.now());
// wflowForms.setFormName(TaskContant.Wflow.DEFAULT_FORM_NAME);
// wflowForms.setRegionCode(region.getRegionCode());
// wflowForms.setRegionName(region.getName());
// if(formsService.save(wflowForms)){
// log.info("当前区域 【{}】 表单数据已经保存成功",region.getName());
// formsMap.put(wflowForms.getRegionCode(),wflowForms);
// }else{
// log.info("当前区域 【{}】 表单数据已经保存失败",region.getName());
// }
// }

//3.接着插入流程默认配置
for(Region region : regions){
@@ -92,17 +108,41 @@ public class InitProcessTask {
continue;
}

WflowForms form = formsService.getOne(Wrappers.lambdaQuery(WflowForms.class)
.eq(WflowForms::getRegionCode, region.getRegionCode())
.last("limit 1"));

WflowModelHistorys model = new WflowModelHistorys();
model.setFormId(form.getFormId());
// model.setProcess(LocalDateTime.now());
if(StringUtils.isNotBlank(processModelService.saveProcess(model))){
log.info("当前区域 【{}】 已经有流程数据已经保存成功",region.getName());
// WflowForms form = formsMap.get(region.getRegionCode());
// if(Objects.isNull(form)){
// log.info("此区域 【{}】 没有对应form 不进行 流程配置初始化",region.getName());
// continue;
// }

WflowModelHistorys models = new WflowModelHistorys();
models.setCreated(GregorianCalendar.getInstance().getTime());
models.setFormId("wf" + IdUtil.objectId());
models.setVersion(1);
models.setGroupId(1);
models.setProcessDefId("pd" + IdUtil.objectId());
models.setRegionCode(region.getRegionCode());
models.setFormName(TaskContant.Wflow.DEFAULT_FORM_NAME);

WflowModels wflowModels = new WflowModels();
BeanUtil.copyProperties(models, wflowModels);
wflowModels.setFormId(models.getFormId());
wflowModels.setIsDelete(false);
wflowModels.setIsStop(false);
wflowModels.setUpdated(new Date());
wflowModels.setSort(0);
wflowModels.setProcessDefId(models.getProcessDefId());
wflowModels.setFormName(models.getFormName());
// wflowModels.setFormItems(JSON.toJSONString(form));
wflowModels.setGroupId(models.getGroupId());
wflowModels.setRegionCode(models.getRegionCode());
// model.setProcess();
// model.setSettings();
if(modelHistoriesMapper.insert(models) > 0){
//初始的流程在部署表也存一份,用来查询
modelsMapper.insert(wflowModels);
log.info("当前区域 【{}】 流程数据已经保存成功",region.getName());
}else{
log.info("当前区域 【{}】 已经有流程数据已经保存失败",region.getName());
log.info("当前区域 【{}】 流程数据已经保存失败",region.getName());
}
}



Carregando…
Cancelar
Salvar