package com.iformall.service.impl;

import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.WxDataRuleTarget;
import com.iformall.mapper.WxDataRuleTargetMapper;
import com.iformall.service.WxDataRuleTargetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author gongbiao
 */
@Service
public class WxDataRuleTargetServiceImpl implements WxDataRuleTargetService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxDataRuleTargetMapper wxDataRuleTargetMapper;

    @Override
    public PageInfo<WxDataRuleTarget> listAsPage(WxDataRuleTarget record, Integer pageIndex, Integer pageSize) {
        return null;
    }

    @Override
    public List<WxDataRuleTarget> findList(WxDataRuleTarget record) {
        return null;
    }

    @Override
    public List<WxDataRuleTarget> getList() {
        List<WxDataRuleTarget> wxDataRuleTargets = wxDataRuleTargetMapper.selectList(null);
        List<WxDataRuleTarget> targets = wxDataRuleTargets.stream()
                .filter(t -> t.getParent().equals(0L)).collect(Collectors.toList());
        for (WxDataRuleTarget parentTarget : targets) {
            List<WxDataRuleTarget> children = wxDataRuleTargets.stream()
                    .filter(t -> t.getParent().equals(parentTarget.getId())).collect(Collectors.toList());
            parentTarget.setChildren(children);
        }
        return targets;
    }

}
