package com.pj.tb_people_profit;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Service: tb_people_profit -- 边民收益设置
 *
 * @author qzyReal
 */
@Service
public class TbPeopleProfitService extends ServiceImpl<TbPeopleProfitMapper, TbPeopleProfit> implements IService<TbPeopleProfit> {

    /**
     * 底层 Mapper 对象
     */
    @Autowired
    TbPeopleProfitMapper tbPeopleProfitMapper;

    /**
     * 增
     */
    int add(TbPeopleProfit t) {
        return tbPeopleProfitMapper.add(t);
    }

    /**
     * 删
     */
    int delete(Long id) {
        return tbPeopleProfitMapper.delete(id);
    }

    /**
     * 改
     */
    int update(TbPeopleProfit t) {
        return tbPeopleProfitMapper.update(t);
    }

    /**
     * 查
     */
    TbPeopleProfit getById(Long id) {
        return tbPeopleProfitMapper.getById(id);
    }

    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    List<TbPeopleProfit> getList(SoMap so) {
        return tbPeopleProfitMapper.getList(so);
    }

    public TbPeopleProfit getActiveOne() {
        QueryWrapper<TbPeopleProfit> ew = new QueryWrapper<>();
        ew.eq("status", 1);
        return this.getOne(ew);
    }

    public TbPeopleProfit getOne() {
        SoMap so = SoMap.getRequestSoMap();
        List<TbPeopleProfit> list = tbPeopleProfitMapper.getList(so);
        return  list.isEmpty() ? null : list.get(0);
    }
}
