package com.jwipc.tender.controller.pc;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.jwipc.page.PageView;
import com.jwipc.tender.dto.QuotaManagementDTO;
import com.jwipc.tender.logic.BidQuotaLogic;
import com.jwipc.tender.logic.QuotaManagementLogic;
import com.jwipc.tender.model.query.BidQuotaQuery;
import com.jwipc.tender.model.query.QuotaManagementQuery;
import com.jwipc.util.EasyExcelUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
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.Date;
import java.util.List;

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

/**
 * @author Al
 * @create 2024-01-31 10:53
 * @desc 模具
 */

@RestController
@RequestMapping(MODULE_ROOT + "/quotaManage/bidQuota/rest/")
@RequiredArgsConstructor
public class BidQuotaRestController {
    private final BidQuotaLogic bidQuotaLogic;
    private final QuotaManagementLogic quotaManagementLogic;
    /**
     * 列表
     *
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(BidQuotaQuery query) {
        return bidQuotaLogic.findByPage(query);
    }
    /**
     * 物料供应商列表导出
     * @param exportFiled 导出的列信息
     * @param queryStr 查询条件
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, String exportFiled, String queryStr) throws IOException {
        // 查询数据列表，直接调用列表的查询，无需特殊改动
        final List<QuotaManagementDTO> exportData = quotaManagementLogic.listAll(JSON.parseObject(queryStr, QuotaManagementQuery.class));
        //动态导出工具类，只需要修改导出excel名称
        EasyExcelUtils.trendsModelWrite(response,"配额记录-" + DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN),"sheet", exportData, exportFiled);
    }
//    /**
//     * 公司主数据
//     * @return 信息
//     */
//    @RequestMapping("/listAll")
//    public List<MoldFormDTO> listAll(){
//        return bidQuotaLogic.listAll();
//    }
}
