package com.liang.service.impl;

import com.liang.entity.BaseCompany;
import com.liang.dao.BaseCompanyDao;
import com.liang.service.BaseCompanyService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

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

/**
 * (BaseCompany)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 23:13:18
 */
@Service("baseCompanyService")
public class BaseCompanyServiceImpl implements BaseCompanyService {
    @Resource
    private BaseCompanyDao baseCompanyDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BaseCompany queryById(Integer id) {
        return this.baseCompanyDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param baseCompany 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<BaseCompany> queryByPage(BaseCompany baseCompany, PageRequest pageRequest) {
        long total = this.baseCompanyDao.count(baseCompany);
        return new PageImpl<>(this.baseCompanyDao.queryAllByLimit(baseCompany, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param baseCompany 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(BaseCompany baseCompany) {
        return this.baseCompanyDao.insert(baseCompany);
    }

    /**
     * 修改数据
     *
     * @param baseCompany 实例对象
     * @return 实例对象
     */
    @Override
    public int update(BaseCompany baseCompany) {
        return this.baseCompanyDao.update(baseCompany);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.baseCompanyDao.deleteById(id) > 0;
    }

    /**
     * 分页查询
     *
     * @param map
     * @return
     */
    @Override
    public List<BaseCompany> getBaseCompanyList(Map map) {
        return this.baseCompanyDao.getBaseCompanyList(map);
    }

    /**
     * 新建单位
     *
     * @param baseCompany
     * @return
     */
    @Override
    public int doAdd(BaseCompany baseCompany) {
        return this.baseCompanyDao.doAdd(baseCompany);
    }

    /**
     * 校验单位全称是否唯一
     *
     * @param dwqc
     * @return
     */
    @Override
    public int checkCompanyUnique(String dwqc) {
        return this.baseCompanyDao.checkCompanyUnique(dwqc);
    }

    @Override
    public int batchDelete(List<Integer> idList) {
        return this.baseCompanyDao.batchDelete(idList);
    }
}
