package com.liang.service.impl;

import com.liang.dao.PrjPayplanDao;
import com.liang.entity.PrjContract;
import com.liang.dao.PrjContractDao;
import com.liang.service.PrjContractService;
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;

/**
 * (PrjContract)表服务实现类
 *
 * @author makejava
 * @since 2023-06-06 12:50:45
 */
@Service("prjContractService")
public class PrjContractServiceImpl implements PrjContractService {
    @Resource
    private PrjContractDao prjContractDao;
    @Resource
    private PrjPayplanDao prjPayplanDao;

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

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

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

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

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

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

    @Override
    public List<PrjContract> getContractList(Map map) {
        return this.prjContractDao.getContractList(map);
    }

    @Override
    public int updateSpzt(PrjContract prjContract) {
        PrjContract prjContract1 = prjContractDao.queryById(prjContract.getId());
            if (prjContract1.getSpzt().equals("已锁定")){
        //避免状态回退
            return 1;
        }else {
            return this.prjContractDao.updateSpzt(prjContract);
        }
    }

    @Override
    public int updateZt(Map map) {
        return this.prjContractDao.updateZt(map);
    }

    @Override
    public int updateSpzt(Map map) {
        return this.prjContractDao.updateSpzt(map);
    }

    @Override
    public List<PrjContract> selectByMcAndHtjr(PrjContract prjContract) {
        return this.prjContractDao.selectByMcAndHtjr(prjContract);
    }
}
