package com.yihu.hos.system.service;

import com.yihu.hos.system.dao.SystemParamDao;
import com.yihu.hos.system.model.SystemParam;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by chenweida on 2016/1/19.
 */
@Service("systemParamManager")
public class SystemParamManager {

    public static final String BEAN_ID = "systemParamManager";

    @Resource(name = SystemParamDao.BEAN_ID)
    private SystemParamDao systemParamDao;


  
    public Result getParamList(Map<String, Object> params) throws Exception {

        return systemParamDao.getParamList(params);
    }

  
    public SystemParam getParamById(String id) throws Exception {
        return systemParamDao.getEntity(SystemParam.class, id);
    }

    @Transactional
    public Result addParam(SystemParam obj) throws Exception {
        systemParamDao.saveEntity(obj);
        return Result.success("保存成功");
    }

    @Transactional
    public Result updateParam(SystemParam obj) throws Exception {
        SystemParam systemParam = systemParamDao.getEntity(SystemParam.class, obj.getId());
        systemParam.setRemark(obj.getRemark());
        systemParam.setParamKey(obj.getParamKey());
        systemParam.setParamValue(obj.getParamValue());
        return Result.success("更新成功");
    }

    @Transactional
    public Result deleteParam(String id) throws Exception {
        SystemParam systemParam = systemParamDao.getEntity(SystemParam.class, id);
        systemParamDao.deleteEntity(systemParam);
        return Result.success("删除成功");
    }
}
