package com.brilliance.isc.esb;

import com.alibaba.fastjson2.JSON;
import com.brilliance.isc.common.counter.service.CounterService;
import com.brilliance.isc.esb.newmodel.tasks.BaseParam;
import com.brilliance.isc.esb.newmodel.tasks.Task;
import com.brilliance.isc.esb.newmodel.tasks.Taskmod;
import com.brilliance.isc.mda.dao.ExtorMapper;
import com.brilliance.isc.mda.dao.TaskMapper;
import com.brilliance.isc.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class TaskRigister implements ITaskRegister {
    @Resource
    private TaskMapper taskMapper;
    @Autowired
    private ExtorMapper extorMapper;
    @Resource
    private CounterService counterService;

    @Override
    public void registTask(String taskTyp, BaseParam param) {
        Taskmod taskmod=new Taskmod();
        taskmod.reset();
        taskmod.getTask().setTasktyp(taskTyp);
        taskmod.setParam(param);
        saveTask(taskmod);
    }
    public void saveTask(Taskmod taskmod){
        Task task=taskmod.getTask();
        task.setCretime(DateUtils.dateTimeNow());
        task.setCnt("0");
        task.setInr(counterService.dbCounterFormat("TASK"));
        task.setObjinr(taskmod.getParam().getObjinr());
        task.setObjtyp(taskmod.getParam().getObjtyp());
        task.setSta("W");
        task.setExtorinr(taskmod.getParam().getExtorinr());
        task.setParamodel(JSON.toJSONString(taskmod.getParam()));
        task.setTaskinfo(WAITING);
        taskMapper.insert(task);
    }
}
