package com.liang.service.impl;

import com.liang.entity.BaseProjecttype;
import com.liang.dao.BaseProjecttypeDao;
import com.liang.service.BaseProjecttypeService;
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;

/**
 * (BaseProjecttype)表服务实现类
 *
 * @author makejava
 * @since 2023-03-14 15:24:46
 */
@Service("baseProjecttypeService")
public class BaseProjecttypeServiceImpl implements BaseProjecttypeService {
    @Resource
    private BaseProjecttypeDao baseProjecttypeDao;

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

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

    /**
     * 新增数据
     *
     * @param baseProjecttype 实例对象
     * @return 实例对象
     */
    @Override
    public BaseProjecttype insert(BaseProjecttype baseProjecttype) {
        this.baseProjecttypeDao.insert(baseProjecttype);
        return baseProjecttype;
    }

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

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

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