package com.sifang.modules.releorder.service;

import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.releorder.dao.CrmInvoiceFileDao;
import com.sifang.modules.releorder.dao.CrmInvoiceInfoDao;
import com.sifang.modules.releorder.dao.CrmReleOrderDao;
import com.sifang.modules.releorder.dao.CrmReleOrderDetailDao;
import com.sifang.modules.sys.common.service.BaseService;
import com.sifang.modules.sys.util.LayuiPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CrmReleOrderService extends BaseService {

    @Autowired
    private CrmReleOrderDao releOrderDao;

    @Autowired
    private CrmReleOrderDetailDao releOrderDetailDao;

    @Autowired
    private CrmInvoiceInfoDao invoiceInfoDao;

    @Autowired
    private CrmInvoiceFileDao invoiceFileDao;

    public void getReleOrderList(LayuiPage<Record> page, Map<String, String> map) {
        List<Record> list = releOrderDao.getReleOrderList(page, map);
        page.setData(list);
        page.setCount(releOrderDao.countgetReleOrderList(map));
    }

    public Record getRectificationOrderStationList(String releCode) {
        Record order = releOrderDao.getReleOrderList(releCode);
        List<Record> deList = releOrderDetailDao.getReleOrderDetailList(order.getStr("rele_code"));
        List<Record> invoiceList = invoiceInfoDao.getInvoiceInfoList(order.getStr("rele_code"));
        for(Record re : invoiceList){
            List<Record> fileList = invoiceFileDao.getInvoiceInfoList(re.getStr("invoice_number"));
            re.set("fileList",fileList);
        }
        order.set("deList",deList);
        order.set("invoiceList",invoiceList);
        return order;
    }

}