package com.xisc.pm.app.service.impl;

import org.hzero.core.base.BaseAppService;

import org.hzero.mybatis.helper.SecurityTokenHelper;
import com.xisc.pm.app.service.PmAutoPdContractService;
import com.xisc.pm.domain.entity.PmAutoPdContract;
import com.xisc.pm.domain.repository.PmAutoPdContractRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;

/**
 * 自动组板合同总量表应用服务默认实现
 *
 * @author jun.zeng 2024-11-21 11:05:32
 */
@Service
public class PmAutoPdContractServiceImpl extends BaseAppService implements PmAutoPdContractService {

    private final PmAutoPdContractRepository pmAutoPdContractRepository;

    @Autowired
    public PmAutoPdContractServiceImpl(PmAutoPdContractRepository pmAutoPdContractRepository) {
        this.pmAutoPdContractRepository = pmAutoPdContractRepository;
    }

    @Override
    public Page<PmAutoPdContract> list(Long tenantId, PmAutoPdContract pmAutoPdContract, PageRequest pageRequest) {
        return pmAutoPdContractRepository.pageAndSort(pageRequest, pmAutoPdContract);
    }

    @Override
    public PmAutoPdContract detail(Long tenantId, Long papcId) {
        return pmAutoPdContractRepository.selectByPrimaryKey(papcId);
    }

    @Override
    public PmAutoPdContract create(Long tenantId, PmAutoPdContract pmAutoPdContract) {
        validObject(pmAutoPdContract);
        pmAutoPdContractRepository.insertSelective(pmAutoPdContract);
        return pmAutoPdContract;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public PmAutoPdContract update(Long tenantId, PmAutoPdContract pmAutoPdContract) {
        SecurityTokenHelper.validToken(pmAutoPdContract);
        pmAutoPdContractRepository.updateByPrimaryKeySelective(pmAutoPdContract);
        return pmAutoPdContract;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void remove(PmAutoPdContract pmAutoPdContract) {
        SecurityTokenHelper.validToken(pmAutoPdContract);
        pmAutoPdContractRepository.deleteByPrimaryKey(pmAutoPdContract);
    }
}
