package com.ycwl.basic.service.pc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycwl.basic.mapper.BrokerMapper;
import com.ycwl.basic.model.pc.broker.entity.BrokerEntity;
import com.ycwl.basic.model.pc.broker.req.BrokerReqQuery;
import com.ycwl.basic.model.pc.broker.resp.BrokerRespVO;
import com.ycwl.basic.service.pc.BrokerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：longbinbin
 * @Date：2024/12/2 15:55
 */
@Service
public class BrokerServiceImpl implements BrokerService {

    @Autowired
    private BrokerMapper brokerMapper;

    @Override
    public PageInfo<BrokerRespVO> pageQuery(BrokerReqQuery brokerReqQuery) {
        PageHelper.startPage(brokerReqQuery.getPageNum(),brokerReqQuery.getPageSize());
        List<BrokerRespVO> list = brokerMapper.list(brokerReqQuery);
        PageInfo<BrokerRespVO> pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<BrokerRespVO> list(BrokerReqQuery brokerReqQuery) {
        return brokerMapper.list(brokerReqQuery);
    }

    @Override
    public BrokerRespVO getById(Long id) {
        return brokerMapper.getById(id);
    }

    @Override
    public int addOrUpdate(BrokerEntity broker) {
        Long id = broker.getId();
        if(id==null){
            return brokerMapper.add(broker);
        }else {
            return brokerMapper.update(broker);
        }
    }

    @Override
    public int delete(Long id) {
        return brokerMapper.deleteById(id);
    }

    @Override
    public int updateStatus(Long id) {
        return brokerMapper.updateStatus(id);
    }

    @Override
    public int updateBrokerEnable(Long id) {
        return brokerMapper.updateBrokerEnable(id);
    }
}
