package com.liang.service.impl;

import com.liang.entity.BaseParty;
import com.liang.dao.BasePartyDao;
import com.liang.service.BasePartyService;
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;

/**
 * (BaseParty)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 23:13:15
 */
@Service("basePartyService")
public class BasePartyServiceImpl implements BasePartyService {
    @Resource
    private BasePartyDao basePartyDao;

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

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

    /**
     * 新增数据
     *
     * @param baseParty 实例对象
     * @return 实例对象
     */
    @Override
    public BaseParty insert(BaseParty baseParty) {
        this.basePartyDao.insert(baseParty);
        return baseParty;
    }

    /**
     * 修改数据
     *
     * @param baseParty 实例对象
     * @return 实例对象
     */
    @Override
    public BaseParty update(BaseParty baseParty) {
        this.basePartyDao.update(baseParty);
        return this.queryById(baseParty.getId());
    }

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

    @Override
    public List<Map<String, String>> getParty() {
        return this.basePartyDao.getParty();
    }
}
