package com.yanzhu.jh.wxsetting.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.yanzhu.jh.wxsetting.domain.SurMenuConfigRole;
import com.yanzhu.jh.wxsetting.mapper.SurMenuConfigMapper;
import com.yanzhu.jh.wxsetting.domain.SurMenuConfig;
import com.yanzhu.jh.wxsetting.service.ISurMenuConfigService;
import com.ruoyi.common.utils.SecurityUtils;
/**
 * 菜单配置Service业务层处理
 * 
 * @author JiangYuQi
 * @date 2023-08-24
 */
@Service
public class SurMenuConfigServiceImpl implements ISurMenuConfigService 
{
    @Autowired
    private SurMenuConfigMapper surMenuConfigMapper;

    /**
     * 查询菜单配置
     * 
     * @param id 菜单配置主键
     * @return 菜单配置
     */
    @Override
    public SurMenuConfig selectSurMenuConfigById(Long id)
    {
        return surMenuConfigMapper.selectSurMenuConfigById(id);
    }

    /**
     * 查询菜单配置列表
     * 
     * @param surMenuConfig 菜单配置
     * @return 菜单配置
     */
    @Override
    public List<SurMenuConfig> selectSurMenuConfigList(SurMenuConfig surMenuConfig)
    {
        return surMenuConfigMapper.selectSurMenuConfigList(surMenuConfig);
    }

    /**
     * 新增菜单配置
     * 
     * @param surMenuConfig 菜单配置
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSurMenuConfig(SurMenuConfig surMenuConfig)
    {
        surMenuConfig.setCreateTime(DateUtils.getNowDate());
        int rows = surMenuConfigMapper.insertSurMenuConfig(surMenuConfig);
        insertSurMenuConfigRole(surMenuConfig);
        return rows;
    }

    /**
     * 修改菜单配置
     * 
     * @param surMenuConfig 菜单配置
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSurMenuConfig(SurMenuConfig surMenuConfig)
    {
        surMenuConfigMapper.deleteSurMenuConfigRoleBySmcid(surMenuConfig.getId());
        insertSurMenuConfigRole(surMenuConfig);
        return surMenuConfigMapper.updateSurMenuConfig(surMenuConfig);
    }

    /**
     * 批量删除菜单配置
     * 
     * @param ids 需要删除的菜单配置主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSurMenuConfigByIds(Long[] ids)
    {
        surMenuConfigMapper.deleteSurMenuConfigRoleBySmcids(ids);
        return surMenuConfigMapper.deleteSurMenuConfigByIds(ids);
    }

    /**
     * 删除菜单配置信息
     * 
     * @param id 菜单配置主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSurMenuConfigById(Long id)
    {
        surMenuConfigMapper.deleteSurMenuConfigRoleBySmcid(id);
        return surMenuConfigMapper.deleteSurMenuConfigById(id);
    }

    /**
     * 新增菜单配置角色信息
     * 
     * @param surMenuConfig 菜单配置对象
     */
    public void insertSurMenuConfigRole(SurMenuConfig surMenuConfig)
    {
        List<SurMenuConfigRole> surMenuConfigRoleList = surMenuConfig.getSurMenuConfigRoleList();
        Long id = surMenuConfig.getId();
        if (StringUtils.isNotNull(surMenuConfigRoleList))
        {
            List<SurMenuConfigRole> list = new ArrayList<SurMenuConfigRole>();
            for (SurMenuConfigRole surMenuConfigRole : surMenuConfigRoleList)
            {
                surMenuConfigRole.setSmcid(id);
                list.add(surMenuConfigRole);
            }
            if (list.size() > 0)
            {
                surMenuConfigMapper.batchSurMenuConfigRole(list);
            }
        }
    }
}
