package com.yihu.hos.resource.service;

import com.yihu.hos.resource.dao.RsDemensionCategoryDaoImpl;
import com.yihu.hos.resource.dao.RsDimensionDaoImpl;
import com.yihu.hos.resource.dao.RsResourceDimensionDaoImpl;
import com.yihu.hos.resource.model.RsDemensionCategory;
import com.yihu.hos.resource.model.RsDimension;
import com.yihu.hos.web.framework.model.ActionResult;
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/26.
 */
@Service("rsDimensionService")
public class RsDimensionServiceImpl {

    public static final String BEAN_ID = "rsDimensionService";

    @Resource(name = RsResourceDimensionDaoImpl.BEAN_ID)
    private RsResourceDimensionDaoImpl resourceDimensionDao;
    @Resource(name = RsDemensionCategoryDaoImpl.BEAN_ID)
    private RsDemensionCategoryDaoImpl demensionCategoryDao;
    @Resource(name = RsDimensionDaoImpl.BEAN_ID)
    private RsDimensionDaoImpl dimensionDao;

  
    public Result getDimensionCategoryList() throws Exception {
        ActionResult actionResult = new ActionResult();
        actionResult.setData(demensionCategoryDao.getDimensionCategoryList());
        return actionResult;
    }

  
    public Result getDimensionList(Map<String, Object> conditionMap) throws Exception {
        return resourceDimensionDao.getDimensionList(conditionMap);
    }

  
    public RsDimension getDimensionById(String id) throws Exception {
        return dimensionDao.getEntity(RsDimension.class, id);
    }

    @Transactional
    public Result updateDimension(RsDimension rsDimension) throws Exception {
        RsDimension dimensionTemp = dimensionDao.getEntity(RsDimension.class, rsDimension.getId());
        dimensionTemp.setCategory(rsDimension.getCategory());
        dimensionTemp.setDictCode(rsDimension.getDictCode());
        dimensionTemp.setType(rsDimension.getType());
        dimensionTemp.setName(rsDimension.getName());
        return Result.success("修改成功");
    }

    @Transactional
    public Result addDimension(RsDimension rsDimension) throws Exception {
        dimensionDao.saveEntity(rsDimension);

        return Result.success("保存成功");
    }

    @Transactional
    public Result deleteDimensionById(String id) throws Exception {
        dimensionDao.deleteEntity(dimensionDao.getEntity(RsDimension.class, id));

        return Result.success("删除成功");
    }

  
    public Result getDimensionCatecoryList(Map<String, Object> conditionMap) throws Exception {
        return demensionCategoryDao.getDimensionCatecoryList(conditionMap);
    }

    @Transactional
    public Result deleteDimensionCatetory(String id) throws Exception {
        demensionCategoryDao.deleteEntity(demensionCategoryDao.getEntity(RsDemensionCategory.class, id));
        return Result.success("删除成功");
    }

  
    public RsDemensionCategory getDimensionCatetoryById(String id) throws Exception {
        return demensionCategoryDao.getEntity(RsDemensionCategory.class, id);
    }

    @Transactional
    public Result addDimensionCatetroy(RsDemensionCategory r) throws Exception {
        demensionCategoryDao.saveEntity(r);
        return Result.success("保存成功");
    }

    @Transactional
    public Result updateDimensionCatetroy(RsDemensionCategory r) throws Exception {
        RsDemensionCategory tsDemensionCategoryTemp = demensionCategoryDao.getEntity(RsDemensionCategory.class, r.getId());
        tsDemensionCategoryTemp.setName(r.getName());
        return Result.success("修改成功");
    }
}
