package com.srs.comprehensive.service.impl;

import java.util.HashMap;
import java.util.List;
import com.srs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.srs.comprehensive.mapper.CphRulesMapper;
import com.srs.comprehensive.domain.CphRules;
import com.srs.comprehensive.service.ICphRulesService;

/**
 * 规则Service业务层处理
 * 
 * @author srs
 * @date 2023-07-03
 */
@Service
public class CphRulesServiceImpl implements ICphRulesService 
{
    @Autowired
    private CphRulesMapper cphRulesMapper;

    @Override
    public List<CphRules> selectClassTwoChildType(){return cphRulesMapper.selectClassTwoChildType();}

    @Override
    public List<CphRules> listAllRules(){
        return cphRulesMapper.listAllRules();
    }

    @Override
    public List<CphRules> selectIamChildType(){return cphRulesMapper.selectIamChildType();}

    /**
     * 查询规则
     * 
     * @param ruleId 规则主键
     * @return 规则
     */
    @Override
    public CphRules selectCphRulesByRuleId(Long ruleId)
    {
        return cphRulesMapper.selectCphRulesByRuleId(ruleId);
    }

    /**
     * 查询规则列表
     * 
     * @param cphRules 规则
     * @return 规则
     */
    @Override
    public List<CphRules> selectCphRulesList(CphRules cphRules)
    {
        return cphRulesMapper.selectCphRulesList(cphRules);
    }

    /**
     * 查询规则列表
     *
     *
     * @return 规则 树形结构
     */
    @Override
    public List<CphRules> selectCphRulesListTree()
    {

        List<CphRules> rules = cphRulesMapper.selectCphRulesByParentId(0L);
        for (CphRules rule : rules) {
            List<CphRules> rules1 = cphRulesMapper.selectCphRulesByParentId(rule.getRuleId());
            if (rules1 !=null){
                rule.setChildren(rules1);
            }
        }
        return (rules);
    }

    /**
     * 新增规则
     * 
     * @param cphRules 规则
     * @return 结果
     */
    @Override
    public int insertCphRules(CphRules cphRules)
    {
        cphRules.setCreateTime(DateUtils.getNowDate());
        return cphRulesMapper.insertCphRules(cphRules);
    }

    /**
     * 修改规则
     * 
     * @param cphRules 规则
     * @return 结果
     */
    @Override
    public int updateCphRules(CphRules cphRules)
    {
        cphRules.setUpdateTime(DateUtils.getNowDate());
        return cphRulesMapper.updateCphRules(cphRules);
    }

    /**
     * 批量删除规则
     * 
     * @param ruleIds 需要删除的规则主键
     * @return 结果
     */
    @Override
    public int deleteCphRulesByRuleIds(Long[] ruleIds)
    {
        return cphRulesMapper.deleteCphRulesByRuleIds(ruleIds);
    }

    /**
     * 删除规则信息
     * 
     * @param ruleId 规则主键
     * @return 结果
     */
    @Override
    public int deleteCphRulesByRuleId(Long ruleId)
    {
        return cphRulesMapper.deleteCphRulesByRuleId(ruleId);
    }
}
