class UpgradeDao extends AbstractBaseDao {

    protected void updateProcessDefinitionJsonWorkerGroup(){
        WorkerGroupDao workerGroupDao = new WorkerGroupDao();
        ProcessDefinitionDao processDefinitionDao = new ProcessDefinitionDao();
        Map<Integer,String> replaceProcessDefinitionMap = new HashMap<>();
        try {
            Map<Integer, String> oldWorkerGroupMap = workerGroupDao.queryAllOldWorkerGroup(dataSource.getConnection());
            Map<Integer,String> processDefinitionJsonMap = processDefinitionDao.queryAllProcessDefinition(dataSource.getConnection());

            for (Map.Entry<Integer,String> entry : processDefinitionJsonMap.entrySet()){
                ObjectNode jsonObject = JSONUtils.parseObject(entry.getValue());
                ArrayNode tasks = JSONUtils.parseArray(jsonObject.get("tasks").toString());

                for (int i = 0 ;i < tasks.size() ; i++){
                    ObjectNode task = (ObjectNode) tasks.path(i);
                    ObjectNode workerGroupNode = (ObjectNode) task.path("workerGroupId");
                    Integer workerGroupId = -1;
                    if(workerGroupNode != null && workerGroupNode.canConvertToInt()){
                        workerGroupId = workerGroupNode.asInt(-1);
                    }
                    if (workerGroupId == -1) {
                        task.put("workerGroup", "default");
                    }else {
                        task.put("workerGroup", oldWorkerGroupMap.get(workerGroupId));
                    }
                }

                jsonObject.remove("task");

                jsonObject.put("tasks",tasks);

                replaceProcessDefinitionMap.put(entry.getKey(),jsonObject.toString());
            }
            if (replaceProcessDefinitionMap.size() > 0){
                processDefinitionDao.updateProcessDefinitionJson(dataSource.getConnection(),replaceProcessDefinitionMap);
            }
        }catch (Exception e){
            logger.error("update process definition json workergroup error",e);
        }

    }

}