package com.jwipc.inquiry.controller.rest;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.jwipc.dto.ExportDataDTO;
import com.jwipc.inquiry.constant.ModuleConst;
import com.jwipc.inquiry.dto.InquiryMaterialDTO;
import com.jwipc.inquiry.dto.InquiryMaterialSupplierDTO;
import com.jwipc.inquiry.dto.InquiryParamDTO;
import com.jwipc.inquiry.dto.InquirySupplierQuoteLogDTO;
import com.jwipc.inquiry.logic.InquiryLogic;
import com.jwipc.inquiry.logic.InquiryMaterialLogic;
import com.jwipc.inquiry.model.query.InquiryMaterialQuery;
import com.jwipc.inquiry.model.query.InquiryQuery;
import com.jwipc.inquiry.model.query.InquiryQuoteQuery;
import com.jwipc.inquiry.model.query.InquirySupplierQuoteLogQuery;
import com.jwipc.page.PageView;
import com.jwipc.util.EasyExcelUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/2/18 15:35
 * @desc 询价
 */
@RestController
@RequestMapping(ModuleConst.MODULE_ROOT + "/material/rest")
@RequiredArgsConstructor
public class InquiryMaterialRestController {
    private final InquiryMaterialLogic inquiryMaterialLogic;
    /**
     * 列表
     */
    @RequestMapping("/listAll")
    public ResponseEntity<List<InquiryMaterialDTO>> listAll(InquiryMaterialQuery query) {
        return ResponseEntity.ok(inquiryMaterialLogic.listAll(query));
    }

    @RequestMapping("/copyListAll")
    public ResponseEntity<List<InquiryMaterialDTO>> copyListAll(InquiryMaterialQuery query) {
        return ResponseEntity.ok(inquiryMaterialLogic.copyListAll(query));
    }

    /**
     * 导出组件导出
     * @param exportFiled 导出的列信息
     * @param queryStr 查询条件
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, String exportFiled, String queryStr) throws IOException {
        // 查询数据列表，直接调用列表的查询，无需特殊改动
        final List<InquiryMaterialDTO> exportData = inquiryMaterialLogic.listAll(JSON.parseObject(queryStr, InquiryMaterialQuery.class));
        //动态导出工具类，只需要修改导出excel名称
        EasyExcelUtils.trendsModelWrite(response,"询价物料记录-" + DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN),"sheet", exportData, exportFiled);
    }
}
