package com.jwipc.finance.controller.rest;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.jwipc.finance.logic.ImgCodeLogic;
import com.jwipc.finance.model.po.ImgCodePO;
import com.jwipc.finance.model.query.ImgCodeQuery;
import com.jwipc.finance.model.query.PaymentNoticeQuery;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import com.jwipc.util.EasyExcelUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
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.finance.constant.ModuleConst.MODULE_ROOT;

/**
 * @author shenyang.ou
 * @date 2025/10/29 15:13
 * @desc
 */
@RestController
@RequestMapping(MODULE_ROOT + "/img/code/rest/")
@RequiredArgsConstructor
public class ImgCodeRestController {
    private final ImgCodeLogic imgCodeLogic;

    @PostMapping("/list")
    public PageView list(ImgCodeQuery query) {
        return imgCodeLogic.findByPage(query);
    }

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