package com.ghy.payment.service.impl;

import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.text.Convert;
import com.ghy.payment.domain.FinancialDetail;
import com.ghy.payment.mapper.FinancialDetailMapper;
import com.ghy.payment.service.FinancialDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FinancialDetailServiceImpl implements FinancialDetailService {

    @Resource
    private FinancialDetailMapper financialDetailMapper;

    @Override
    public int insertFinancialDetail(FinancialDetail financialDetail) {
        return financialDetailMapper.insertFinancialDetail(financialDetail);
    }

    @Override
    public int updateFinancialDetail(FinancialDetail financialDetail) {
        return financialDetailMapper.updateFinancialDetail(financialDetail);
    }

    @Override
    public List<FinancialDetail> selectFinancialDetailList(FinancialDetail financialDetail) {
        return financialDetailMapper.selectFinancialDetailList(financialDetail);
    }

    @Override
    public FinancialDetail selectById(Long financialDetailId) {
        return financialDetailMapper.selectById(financialDetailId);
    }

    @Override
    public int deleteFinancialDetailByIds(String ids) {
        Long[] financialDetailIds = Convert.toLongArray(ids);
        return financialDetailMapper.deleteFinancialDetailByIds(financialDetailIds);
    }

    @Override
    public String checkFinancialDetailCodeUnique(FinancialDetail financialDetail) {
        long financialDetailId = financialDetail.getId() == null ? -1L : financialDetail.getId();
        FinancialDetail info = financialDetailMapper.checkFinancialDetailCodeUnique(financialDetail.getCode());
        if (info != null && info.getId() != financialDetailId) {
            return UserConstants.FINANCIAL_CODE_NOT_UNIQUE;
        }
        return UserConstants.FINANCIAL_CODE_UNIQUE;
    }
}
