package com.easyproject.system.service.guide.impl;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.easyproject.common.core.domain.AjaxResult;
import com.easyproject.common.core.domain.TreeSelect;
import com.easyproject.common.utils.DateUtils;
import com.easyproject.service.domain.guide.ServiceGuideCategory;
import com.easyproject.service.domain.guide.ServiceGuideItem;
import com.easyproject.service.mapper.guide.ServiceGuideCategoryMapper;
import com.easyproject.service.mapper.guide.ServiceGuideItemMapper;
import com.easyproject.system.service.guide.IServiceGuideItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 指南栏目Service业务层处理
 *
 * @author easyproject
 * @date 2025-03-21
 */
@Service
public class ServiceGuideItemServiceImpl implements IServiceGuideItemService {
    @Autowired
    private ServiceGuideItemMapper serviceGuideItemMapper;
    @Autowired
    private ServiceGuideCategoryMapper serviceGuideCategoryMapper;

    /**
     * 查询指南栏目
     *
     * @param id 指南栏目主键
     * @return 指南栏目
     */
    @Override
    public ServiceGuideItem selectServiceGuideItemById(Long id) {
        return serviceGuideItemMapper.selectServiceGuideItemById(id);
    }

    /**
     * 查询指南栏目列表
     *
     * @param serviceGuideItem 指南栏目
     * @return 指南栏目
     */
    @Override
    public List<ServiceGuideItem> selectServiceGuideItemList(ServiceGuideItem serviceGuideItem) {
        return serviceGuideItemMapper.selectServiceGuideItemList(serviceGuideItem);
    }

    /**
     * 新增指南栏目
     *
     * @param serviceGuideItem 指南栏目
     * @return 结果
     */
    @Override
    public int insertServiceGuideItem(ServiceGuideItem serviceGuideItem) {
        serviceGuideItem.setCreateTime(DateUtils.getNowDate());
        return serviceGuideItemMapper.insertServiceGuideItem(serviceGuideItem);
    }

    /**
     * 修改指南栏目
     *
     * @param serviceGuideItem 指南栏目
     * @return 结果
     */
    @Override
    public int updateServiceGuideItem(ServiceGuideItem serviceGuideItem) {
        serviceGuideItem.setUpdateTime(DateUtils.getNowDate());
        return serviceGuideItemMapper.updateServiceGuideItem(serviceGuideItem);
    }

    /**
     * 批量删除指南栏目
     *
     * @param ids 需要删除的指南栏目主键
     * @return 结果
     */
    @Override
    public int deleteServiceGuideItemByIds(Long[] ids) {
        return serviceGuideItemMapper.deleteServiceGuideItemByIds(ids);
    }

    /**
     * 方法说明: 查询所有有效分类列表
     * @param
     * @return
     * @author java-101
     * @date 2025-03-21 15:36:50
     */
    @Override
    public AjaxResult selGategorTree() {
        List<ServiceGuideCategory> list = serviceGuideCategoryMapper.selectList(Wrappers.<ServiceGuideCategory>lambdaQuery().eq(ServiceGuideCategory::getStatus, 1).orderByAsc(ServiceGuideCategory::getSort));
        List<TreeSelect> treeSelectList = new ArrayList<>();
        if(ObjectUtil.isNotEmpty(list)){
            TreeSelect treeSelect = null;
            for (ServiceGuideCategory category : list) {
                treeSelect = new TreeSelect();
                treeSelect.setId(category.getId());
                treeSelect.setLabel(category.getCategoryName());
                treeSelect.setIconUrl(category.getImgUrl());
                treeSelect.setChildren(null);
                treeSelectList.add(treeSelect);
            }
        }
        return AjaxResult.success(treeSelectList);
    }

}
