package com.yihu.hos.system.service;

import com.yihu.hos.system.dao.ProcessorDao;
import com.yihu.hos.system.model.SystemServiceFlowProcessor;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service("ProcessorManager")
public class ProcessorManager {

    public static final String BEAN_ID = "ProcessorManager";
    @Autowired
    private ProcessorDao processorDao;

    public Result getProcessorList(Map<String, Object> params) throws Exception {
        return processorDao.getProcessorList(params);
    }


    public SystemServiceFlowProcessor getProcessorById(String id) throws Exception {
        SystemServiceFlowProcessor serviceFlowProcessor = processorDao.getEntity(SystemServiceFlowProcessor.class, Integer.parseInt(id));
        return serviceFlowProcessor;
    }

    @Transactional
    public Result addProcessor(SystemServiceFlowProcessor obj) throws Exception {
        processorDao.saveEntity(obj);
        return Result.success("保存成功");
    }

    @Transactional
    public Result updateProcessor(SystemServiceFlowProcessor obj) throws Exception {
        processorDao.updateEntity(obj);
        return Result.success("更新成功");
    }

    @Transactional
    public Result deleteProcessor(String id) throws Exception {
        SystemServiceFlowProcessor serviceFlowProcessor = processorDao.getEntity(SystemServiceFlowProcessor.class, Integer.parseInt(id));
        processorDao.deleteEntity(serviceFlowProcessor);
        return Result.success("删除成功");
    }
}
