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

import org.hzero.mybatis.helper.SecurityTokenHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xisc.pm.app.service.PmPdRecCfgService;
import com.xisc.pm.domain.entity.PmPdRecCfg;
import com.xisc.pm.domain.repository.PmPdRecCfgRepository;

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

/**
 * 组板履历事件配置表应用服务默认实现
 *
 * @author 曾俊 jun.zeng@hand-china.com 2024-07-31 08:01:12
 */
@Service
public class PmPdRecCfgServiceImpl implements PmPdRecCfgService {

    private final PmPdRecCfgRepository pmPdRecCfgRepository;

    @Autowired
    public PmPdRecCfgServiceImpl(PmPdRecCfgRepository pmPdRecCfgRepository) {
        this.pmPdRecCfgRepository = pmPdRecCfgRepository;
    }

    @Override
    public Page<PmPdRecCfg> list(Long tenantId, PmPdRecCfg pmPdRecCfg, PageRequest pageRequest) {
        return pmPdRecCfgRepository.pageAndSort(pageRequest, pmPdRecCfg);
    }

    @Override
    public PmPdRecCfg detail(Long tenantId, Long pprcId) {
        return pmPdRecCfgRepository.selectByPrimaryKey(pprcId);
    }

    @Override
    public PmPdRecCfg create(Long tenantId, PmPdRecCfg pmPdRecCfg) {
        pmPdRecCfgRepository.insertSelective(pmPdRecCfg);
        return pmPdRecCfg;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public PmPdRecCfg update(Long tenantId, PmPdRecCfg pmPdRecCfg) {
        SecurityTokenHelper.validToken(pmPdRecCfg);
        pmPdRecCfgRepository.updateByPrimaryKeySelective(pmPdRecCfg);
        return pmPdRecCfg;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void remove(PmPdRecCfg pmPdRecCfg) {
        SecurityTokenHelper.validToken(pmPdRecCfg);
        pmPdRecCfgRepository.deleteByPrimaryKey(pmPdRecCfg);
    }
}
