package com.jwipc.inquiry.controller;


import cn.hutool.core.util.ObjectUtil;
import com.jwipc.inquiry.dto.AssistantMaterialSupplierDTO;
import com.jwipc.inquiry.dto.AssistantSupplierDTO;
import com.jwipc.inquiry.dto.InquiryDTO;
import com.jwipc.inquiry.dto.PurchaseApplyBillDetailDTO;
import com.jwipc.inquiry.entity.PriceInfo;
import com.jwipc.inquiry.logic.InquiryLogic;
import com.jwipc.inquiry.logic.InquiryMaterialSupplierLogic;
import com.jwipc.inquiry.model.query.PurchaseApplyBillDetailQuery;
import com.jwipc.inquiry.service.IPriceInfoService;
import com.jwipc.security.LoginUtil;
import com.jwipc.sys.client.CompanyClient;
import com.jwipc.sys.client.dto.CompanyDTO;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static com.jwipc.inquiry.constant.ModuleConst.MODULE_ROOT;

/**
 * @author shenyang.ou
 * @date 2024/2/4 19:48
 * @desc 询价定价
 */
@Controller
@RequestMapping(MODULE_ROOT+ "/create/warning")
@RequiredArgsConstructor
public class PriceWarningPageController {
    private final InquiryLogic inquiryLogic;
    private final IPriceInfoService priceInfoService;

    @GetMapping("/index")
    public String index(Model model) {
        return MODULE_ROOT + "/create/warning/list";
    }


    @GetMapping("/transfer/inquiry")
    public String transferInquiry(Model model, String ids,Integer optType) {
        InquiryDTO inquiryDTO = new InquiryDTO();
        List<String> idList = Arrays.asList(StringUtils.split(ids, ","));
        PriceInfo priceInfo = priceInfoService.getById(idList.get(0));
        inquiryDTO.setDataSource(2);
        inquiryDTO.setPurchaseGroupCode(priceInfo.getPurchaseGroupCode());
        inquiryDTO.setCompanyCode(priceInfo.getCompanyCode());
        inquiryDTO.setPurchaseOrgCode(priceInfo.getPurchaseOrgCode());
        inquiryDTO.setPriceInfoIds(ids);
        inquiryDTO.setPurchaseType("0");
        inquiryDTO.setBeginTime(LocalDateTime.now());
        model.addAttribute("data", inquiryDTO);
        model.addAttribute("optType", optType);
        return MODULE_ROOT + "/hall/detail";
    }

}
