package com.sunxung.factoring.web.steelwaiter;

import com.sunxung.factoring.component.util.CollectionUtil;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.acceptance.AcceptanceGoodsInfo;
import com.sunxung.factoring.entity.steelwaiter.SearchVo;
import com.sunxung.factoring.entity.steelwaiter.SellBill;
import com.sunxung.factoring.entity.steelwaiter.SellBillItem;
import com.sunxung.factoring.entity.sys.FileStorage;
import com.sunxung.factoring.service.steelwaiter.SteelWaiterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 钢小二
 *
 * @author liutao
 * @date 2023-10-26
 */
@Controller
@RequestMapping("steel/waiter")
public class SteelWaiterController {

    @Autowired
    private SteelWaiterService steelWaiterService;

    @ResponseBody
    @RequestMapping("billNumbers")
    public ResponseJson findAllBillNumbers(String supplierName,String keyword) {
        List<String> list = steelWaiterService.findAllBillNumbers(supplierName,keyword);
        return new ResponseJson(list);
    }

    @ResponseBody
    @RequestMapping("goods")
    public ResponseJson getGoodsByBillNumber(SearchVo searchVo) {
//        List<String> billNumbers = searchVo.getBillNumbers();
//        String companyName = searchVo.getCompanyName();
//        List<AcceptanceGoodsInfo> goodsInfos = new ArrayList<>();
//        for (String billNumber : billNumbers) {
//            List<SellBillItem> list = steelWaiterService.getGoodsByBillNumber(billNumber,companyName);
//            SellBill sellBill = steelWaiterService.getSellBillByNumber(billNumber, companyName);
//            if(CollectionUtil.isNotEmpty(list)){
//                List<AcceptanceGoodsInfo> collect = list.stream().map(r -> {
//                    AcceptanceGoodsInfo acceptanceGoodsInfo = new AcceptanceGoodsInfo(r);
//                    acceptanceGoodsInfo.setAcceptanceDate(sellBill.getReceiptDate());
//                    return acceptanceGoodsInfo;
//                }).collect(Collectors.toList());
//                goodsInfos.addAll(collect);
//            }
//        }
//        return new ResponseJson(goodsInfos);
        return new ResponseJson();
    }

    @ResponseBody
    @RequestMapping("file")
    public ResponseJson getFileByBillNumber(SearchVo searchVo) {
        List<String> billNumbers = searchVo.getBillNumbers();
        String companyName = searchVo.getCompanyName();
        List<FileStorage> fileStorages = new ArrayList<>();
        for (String billNumber : billNumbers) {
            List<FileStorage> fileByBillNumber = steelWaiterService.getFileByBillNumber(billNumber, companyName);
            fileStorages.addAll(fileByBillNumber);
        }
        return new ResponseJson(fileStorages);
    }
}

