package com.jwipc.order.controller.pc;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.jwipc.order.dto.DeliveryOrderDetailListDTO;
import com.jwipc.order.dto.PurchaseOrderDetailUnlockLogListDTO;
import com.jwipc.order.logic.PurchaseOrderDetailUnlockLogLogic;
import com.jwipc.order.model.query.DeliveryOrderDetailQuery;
import com.jwipc.order.model.query.PcnManagerQuery;
import com.jwipc.order.model.query.PurchaseOrderUnlockLogQuery;
import com.jwipc.page.PageView;
import com.jwipc.util.EasyExcelUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
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.order.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>
 * 采购订单明细 数据查询
 * </p>
 *
 * @author qzc
 * @since 2024-09-24
 */

@Slf4j
@RestController
@RequestMapping(MODULE_ROOT + "/purchaseOrderDetailUnlockLog/rest")
@RequiredArgsConstructor
public class PurchaseOrderDetailUnlockLogRestController {
    private final PurchaseOrderDetailUnlockLogLogic purchaseOrderDetailUnlockLogLogic;
    @RequestMapping("/queryUnlockLogPage")
    public PageView queryPcnByPage(PurchaseOrderUnlockLogQuery query) {
        return purchaseOrderDetailUnlockLogLogic.queryUnlockLogByPage(query);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, String exportFiled, String queryStr) throws IOException {
        // 查询数据列表，直接调用列表的查询，无需特殊改动
        final List<PurchaseOrderDetailUnlockLogListDTO> exportData = purchaseOrderDetailUnlockLogLogic.getListAll(
                JSON.parseObject(queryStr, PurchaseOrderUnlockLogQuery.class));


        //动态导出工具类，只需要修改导出excel名称
        EasyExcelUtils.trendsModelWrite(response,
                "送货单明细解锁操作记录明细表-" + DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN), "sheet", exportData,
                exportFiled);
    }

}
