package com.bonus.material.lease.service.impl;

import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.material.lease.domain.LeaseAgreementRecord;
import com.bonus.material.lease.domain.LeaseAgreementSlt;
import com.bonus.material.lease.mapper.LeaseAgreementRecordMapper;
import com.bonus.material.lease.mapper.LeaseAgreementSltMapper;
import com.bonus.material.lease.service.ILeaseAgreementRecordService;
import com.bonus.material.lease.service.ILeaseAgreementSltService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目领退Service业务层处理
 *
 * @author xsheng
 * @date 2024-10-16
 */
@Service
public class LeaseAgreementSltServiceImpl implements ILeaseAgreementSltService {
    @Autowired
    private LeaseAgreementSltMapper leaseAgreementSltMapper;


    @Override
    public List<LeaseAgreementSlt> selectLeaseAgreementSltList(LeaseAgreementSlt leaseAgreementSlt) {
        return leaseAgreementSltMapper.selectLeaseAgreementSltList(leaseAgreementSlt);
    }

    @Override
    public LeaseAgreementSlt getInfo(LeaseAgreementSlt leaseAgreementSlt) {
        return leaseAgreementSltMapper.getInfo(leaseAgreementSlt);
    }

    @Override
    public int updateLeaseSltInfo(LeaseAgreementSlt leaseAgreementSlt) {
        try {
            String optFlag = leaseAgreementSlt.getOptFlag();
            if ("update".equals(optFlag)) {
                leaseAgreementSlt.setUpdateTime(DateUtils.getNowDate());
                return leaseAgreementSltMapper.updateLeaseSltInfo(leaseAgreementSlt);
            }
            if ("delete".equals(optFlag)) {
                leaseAgreementSlt.setUpdateTime(DateUtils.getNowDate());
                return leaseAgreementSltMapper.deleteLeaseSltInfo(leaseAgreementSlt);
            }
            if ("insert".equals(optFlag)) {
                leaseAgreementSlt.setCreateTime(DateUtils.getNowDate());
                return leaseAgreementSltMapper.insertLeaseSltInfo(leaseAgreementSlt);


            }

        } catch (Exception e) {
            throw new ServiceException("系统错误, " + e.getMessage());
        }
        return 0;
    }
}
