package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.BcAgentMapper;
import com.gxwebsoft.apps.service.BcAgentService;
import com.gxwebsoft.apps.entity.BcAgent;
import com.gxwebsoft.apps.param.BcAgentParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 代报餐管理Service实现
 *
 * @author 科技小王子
 * @since 2023-04-24 19:25:59
 */
@Service
public class BcAgentServiceImpl extends ServiceImpl<BcAgentMapper, BcAgent> implements BcAgentService {

    @Resource
    private UserService userService;

    @Override
    public PageResult<BcAgent> pageRel(BcAgentParam param) {
        PageParam<BcAgent, BcAgentParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<BcAgent> list = baseMapper.selectPageRel(page, param);
//        list.forEach( d-> {
//          d.setUser(userService.getById(d.getUserId()));
//          d.setParentUser(userService.getById(d.getParentId()));
//        });
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<BcAgent> listRel(BcAgentParam param) {
        List<BcAgent> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<BcAgent, BcAgentParam> page = new PageParam<>();
        //page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public BcAgent getByIdRel(Integer agentId) {
        BcAgentParam param = new BcAgentParam();
        param.setAgentId(agentId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
