package com.srs.comprehensive.service.impl;

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

import com.srs.common.utils.DateUtils;
import com.srs.comprehensive.domain.SrsAspect;
import com.srs.comprehensive.domain.SrsBonusRules;
import com.srs.comprehensive.mapper.SrsAspectMapper;
import com.srs.comprehensive.mapper.StsBonusRulesMapper;
import com.srs.comprehensive.service.ISrsAspectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static org.apache.commons.lang3.SystemUtils.getUserName;

/**
 * 加分规则Service业务层处理
 * 
 * @author srs
 * @date 2023-06-19
 */
@Service
public class SrsAspectServiceImpl implements ISrsAspectService
{
    @Autowired
    private SrsAspectMapper srsAspectMapper;
    @Autowired
    private StsBonusRulesMapper stsBonusRulesMapper;

    /**
     * 查询加分规则
     * 
     * @param id 加分规则主键
     * @return 加分规则
     */
    @Override
    public SrsAspect selectSrsAspectById(Long id)
    {
        return srsAspectMapper.selectSrsAspectById(id);
    }

    /**
     * 查询加分规则列表
     * 
     * @param srsAspect 加分规则
     * @return 加分规则
     */
    @Override
    public List<SrsAspect> selectSrsAspectList(SrsAspect srsAspect)
    {
        return srsAspectMapper.selectSrsAspectListJoin(srsAspect);
    }
    /**
     * 查询加分规则列表
     *树形结构
     * @param srsAspect 加分规则
     * @return 加分规则
     */
    public List<Object> selectSrsAspectListTree(SrsAspect srsAspect)
    {
        ArrayList<Object> objects = new ArrayList<>();


        SrsBonusRules srsBonusRules = new SrsBonusRules();
        List<SrsBonusRules> list = stsBonusRulesMapper.selectStsBonusRulesList(srsBonusRules);
        for (SrsBonusRules bonusRules : list) {
            HashMap<String, Object> map = new HashMap<>();
            List<SrsAspect> srsAspects = srsAspectMapper.selectSrsAspectList(srsAspect);
            map.put("children",srsAspects);
            map.put("id",bonusRules.getId());
            map.put("name",bonusRules.getCategoryName());
            srsAspect.setCategoryId(bonusRules.getId());
            objects.add(map);
        }

        return objects;
    }






    /**
     * 新增加分规则
     * 
     * @param srsAspect 加分规则
     * @return 结果
     */
    @Override
    public int insertSrsAspect(SrsAspect srsAspect)
    {
        srsAspect.setCreateBy(getUserName());
        srsAspect.setCreateTime(DateUtils.getNowDate());
        return srsAspectMapper.insertSrsAspect(srsAspect);
    }

    /**
     * 修改加分规则
     * 
     * @param srsAspect 加分规则
     * @return 结果
     */
    @Override
    public int updateSrsAspect(SrsAspect srsAspect)
    {
        srsAspect.setUpdateBy(getUserName());
        srsAspect.setUpdateTime(DateUtils.getNowDate());
        return srsAspectMapper.updateSrsAspect(srsAspect);
    }

    /**
     * 批量删除加分规则
     * 
     * @param ids 需要删除的加分规则主键
     * @return 结果
     */
    @Override
    public int deleteSrsAspectByIds(Long[] ids)
    {
        return srsAspectMapper.deleteSrsAspectByIds(ids);
    }

    /**
     * 删除加分规则信息
     * 
     * @param id 加分规则主键
     * @return 结果
     */
    @Override
    public int deleteSrsAspectById(Long id)
    {
        return srsAspectMapper.deleteSrsAspectById(id);
    }
}
