package org.dromara.common.web.core;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import lombok.Data;
import org.dromara.common.core.domain.BaseBO;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.List;

/**
 * @author wangqx
 * @description TODO
 * @date 2022/6/16
 */
@Data
public class BusinessImpl<S extends IService<T>, C extends BaseConverter<V,B,T>,V,B extends BaseBO,T> implements IBusiness<V, B> {
    @Autowired
    protected  S service;
    @Autowired
    protected  C converter;

    public BusinessImpl() {
    }
    public BusinessImpl(S service, C converter) {
        this.service = service;
        this.converter = converter;
    }

    @Override
    public boolean save(B bo) {
        T t=converter.toPo(bo);
        return service.save(t);
    }

    @Override
    public V info(Serializable id) {
        T t= service.getById(id);
        return converter.toVO(t);
    }

    @Override
    public List<V> list(B b) {
        List<T> tList=service.list(b.toWrapper());

        return converter.toVO(tList);
    }

    @Override
    public Page<V> page(B b) {
        return converter.toVO(service.page(b.getPage(),b.toWrapper()));
    }

    @Override
    public boolean delete(Serializable id) {
        service.removeById(id);
        return true;
    }


}
