package com.uas.finance.erp.service.impl;

import com.uas.finance.dao.AccountApplyDao;
import com.uas.finance.dao.SellerQuotaDao;
import com.uas.finance.erp.service.AccountApplyDownService;
import com.uas.finance.model.AccountApply;
import com.uas.finance.model.SellerQuota;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.List;

/**
 * 应收账款转让接口实现类
 * created by shicr on 2018/1/29
 **/
@Service
public class AccountApplyDownServiceImpl implements AccountApplyDownService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private AccountApplyDao dao;

    @Autowired
    private SellerQuotaDao sellerQuotaDao;

    /**
     * 对应收账款转让表AccountApply进行封装
     *
     * @param accountApplies
     * @return
     */
    public ModelMap covert(List<AccountApply> accountApplies) {
        ModelMap modelMap = new ModelMap();
        modelMap.put("accountapply", accountApplies);
        for(AccountApply a : accountApplies){

            SellerQuota s = sellerQuotaDao.findOne(a.getCqId());
            //买方客户名
            modelMap.put("custname", s.getCq_custname());
            //客户UU
            modelMap.put("uu", s.getCq_uu());
            //买房额度对应的申请单id
            modelMap.put("faid", s.getFaid());
        }

        return modelMap;
    }

    /**
     * 更新accountapply的下载状态
     * @param id
     */
    public void updateErpStatus(Long id){
        String sql = "update accountapply set erpstatus = 203 where id = "+ id;
        jdbcTemplate.execute(sql);
    }
}
