package com.uas.finance.service.Impl;

import com.uas.finance.dao.AttachDao;
import com.uas.finance.dao.FinancingApplyDao;
import com.uas.finance.model.Attach;
import com.uas.finance.model.FinancingApply;
import com.uas.finance.service.AttachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 附件接口实现层
 * created by shicr on 2017/12/25
 **/
@Service
public class AttachServiceImpl implements AttachService {

    @Autowired
    private AttachDao attachDao;

    @Autowired
    private FinancingApplyDao applyDao;

    /**
     * 附件上传
     *
     * @param attach
     * @return
     */
    @Override
    public Attach save(Attach attach) {
        return attachDao.save(attach);
    }

    /**
     * 查找某金融单下的所有附件
     *
     * @param applyId
     * @return
     */
    @Override
    public List<Attach> findAttaches(Long applyId) {
        return attachDao.findAttachesByApplyId(applyId);
    }


    /**
     * 找到保理申请需要下载的文件
     *
     * @param fauu
     * @return
     */
    @Override
    public Attach findDownload(Long fauu) {
        return attachDao.findAttachesByFauu(fauu);
    }

    /**
     * 删除附件
     * @param id
     * @return
     */
    @Override
    public void deleteOne(Long id) {
         attachDao.deleteOne(id);
    }

    /**
     * 查找某金融单下的所有附件
     *
     * @param cuId
     * @return
     */
    @Override
    public List<Attach> findAttachesByCuId(Long cuId) {
        FinancingApply financingApply = applyDao.findByCusId(cuId);
        if(!"".equals(financingApply) && financingApply != null){
        long applyId = financingApply.getId();
        List<Attach> attaches = attachDao.findAttachesByApplyId(applyId);
        return attaches;
        }else {
           return null;
        }
    }


}
