package com.ktg.iscs.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.StringUtils;
import com.ktg.iscs.domain.IsMaterialsCabinet;
import com.ktg.iscs.domain.IsMaterialsLoanException;
import com.ktg.iscs.domain.vo.exception.IsMaterialsLoanExceptionPageVO;
import com.ktg.iscs.mapper.IsMaterialsLoanExceptionMapper;
import com.ktg.iscs.service.IIsMaterialsCabinetService;
import com.ktg.iscs.service.IIsMaterialsLoanExceptionService;
import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 物资归还异常Service业务层处理
 *
 * @author cgj
 * @date 2025-02-10
 */
@Service
public class IsMaterialsLoanExceptionServiceImpl extends ServiceImpl<IsMaterialsLoanExceptionMapper, IsMaterialsLoanException> implements IIsMaterialsLoanExceptionService {

    @Autowired
    private IsMaterialsLoanExceptionMapper isMaterialsLoanExceptionMapper;
    @Autowired
    private IIsMaterialsCabinetService iIsMaterialsCabinetService;

    @Override
    public Page<IsMaterialsLoanExceptionPageVO> getIsMaterialsLoanExceptionPage(Page<IsMaterialsLoanException> page, IsMaterialsLoanExceptionPageVO isMaterialsLoanException) {
        if (StringUtils.isNotBlank(isMaterialsLoanException.getLoanFromCode())) {
            IsMaterialsCabinet cabinetByCode = iIsMaterialsCabinetService.getCabinetByCode(isMaterialsLoanException.getLoanFromCode());
            Assert.isTrue(cabinetByCode != null, "物资柜code不存在");
            isMaterialsLoanException.setLoanFromId(cabinetByCode.getCabinetId());
        }
        Page<IsMaterialsLoanExceptionPageVO> result = isMaterialsLoanExceptionMapper.getIsMaterialsLoanExceptionPage(page, isMaterialsLoanException);
        return result;
    }

}
