package com.yihu.jw.base.service.system;

import com.yihu.jw.base.dao.system.SystemDictEntryDao;
import com.yihu.jw.entity.base.system.SystemDictEntryDO;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * Service - 系统字典项
 * Created by LiTaohong on 2017/12/01.
 */
@Service
public class SystemDictEntryService extends BaseJpaService<SystemDictEntryDO, SystemDictEntryDao> {

    @Autowired
    private SystemDictEntryDao systemDictEntryDao;

    public SystemDictEntryDO findById(String id) {
        return systemDictEntryDao.findOne(id);
    }

    public void deleteByDictCode(String dictCode) {
        systemDictEntryDao.deleteByDictCode(dictCode);
    }

    /**
     * 字典项代码是否存在，某一个租户下的字典项代码不可重复
     * @param saasid
     * @param code
     * @return
     */
    public Boolean existCode(String saasid,String code){
        if(StringUtils.isEmpty(saasid) || StringUtils.isEmpty(code)){
            return null;
        }
        return systemDictEntryDao.existsBySaasIdAndCode(saasid,code);
    }

    /**
     * 字典项代码更新时，代码的修改值不可重复
     * @param saasid
     * @param code
     * @return
     */
    public Integer countByCodeNot(String saasid,String code){
        if(StringUtils.isEmpty(saasid) || StringUtils.isEmpty(code)){
            return null;
        }
        return systemDictEntryDao.countBySaasIdAndCodeNot(saasid,code);
    }
}
