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.PmAutoPdPositionService;
import com.xisc.pm.domain.entity.PmAutoPdPosition;
import com.xisc.pm.domain.repository.PmAutoPdPositionRepository;
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:34
 */
@Service
public class PmAutoPdPositionServiceImpl extends BaseAppService implements PmAutoPdPositionService {

    private final PmAutoPdPositionRepository pmAutoPdPositionRepository;

    @Autowired
    public PmAutoPdPositionServiceImpl(PmAutoPdPositionRepository pmAutoPdPositionRepository) {
        this.pmAutoPdPositionRepository = pmAutoPdPositionRepository;
    }

    @Override
    public Page<PmAutoPdPosition> list(Long tenantId, PmAutoPdPosition pmAutoPdPosition, PageRequest pageRequest) {
        return pmAutoPdPositionRepository.pageAndSort(pageRequest, pmAutoPdPosition);
    }

    @Override
    public PmAutoPdPosition detail(Long tenantId, Long positionId) {
        return pmAutoPdPositionRepository.selectByPrimaryKey(positionId);
    }

    @Override
    public PmAutoPdPosition create(Long tenantId, PmAutoPdPosition pmAutoPdPosition) {
        validObject(pmAutoPdPosition);
        pmAutoPdPositionRepository.insertSelective(pmAutoPdPosition);
        return pmAutoPdPosition;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public PmAutoPdPosition update(Long tenantId, PmAutoPdPosition pmAutoPdPosition) {
        SecurityTokenHelper.validToken(pmAutoPdPosition);
        pmAutoPdPositionRepository.updateByPrimaryKeySelective(pmAutoPdPosition);
        return pmAutoPdPosition;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void remove(PmAutoPdPosition pmAutoPdPosition) {
        SecurityTokenHelper.validToken(pmAutoPdPosition);
        pmAutoPdPositionRepository.deleteByPrimaryKey(pmAutoPdPosition);
    }
}
