package cn.gov.customs.wxjy.ibmmq.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.gov.customs.cacp.sdks.core.result.Result;
import cn.gov.customs.cacp.sdks.core.user.trans.CacpTransUser;
import cn.gov.customs.cacp.sdks.core.user.trans.UserContextHolder;
import cn.gov.customs.wxjy.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import cn.gov.customs.wxjy.common.core.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.gov.customs.wxjy.ibmmq.pojo.PushLog;
import cn.gov.customs.wxjy.ibmmq.pojo.PushLogQuery;
import cn.gov.customs.wxjy.ibmmq.service.IPushLogService;
import cn.gov.customs.wxjy.common.utils.poi.ExcelUtil;
import cn.gov.customs.wxjy.common.core.page.TableDataInfo;

/**
 * 推送记录Controller
 *
 * @author xiong
 * @date 2025-12-22
 */
@RestController
@RequestMapping("/ibmmq/PushLog")
@RequiredArgsConstructor
public class PushLogController extends BaseController {

    private final IPushLogService pushLogService;

    /**
     * 查询推送记录列表
     */
    @PostMapping("/get-list")
    public Result<PageInfo<PushLog>> list(@RequestBody PushLogQuery query) {
        PageHelper.startPage(query.getPageIndex(), query.getPageSize());
        PageInfo<PushLog> list = pushLogService.selectPageList(query);
        return Result.success(list);
    }

    /**
     * 获取推送记录详细信息
     */
    @GetMapping(value = "/get-detail")
    public Result<PushLog> getInfo(@RequestParam String logId) {
        return Result.success(pushLogService.selectByLogId(logId));
    }

    /**
     * 新增推送记录
     */
    @PostMapping("/insert-pushLog")
    public Result<Integer> add(@RequestBody PushLog pushLog) {
        return Result.success(pushLogService.insert(pushLog));
    }

    /**
     * 修改推送记录
     */
    @PostMapping("/update-pushLog")
    public Result<Integer> edit(@RequestBody PushLog pushLog) {
        return Result.success(pushLogService.update(pushLog));
    }

    /**
     * 删除推送记录
     */
    @PostMapping("/delete-pushLog")
    public Result<Integer> remove(@RequestBody String[] ids) {
        return Result.success(pushLogService.deleteByLogIds(ids));
    }

    /**
    * 导入 推送记录
    * @param file
    * @param updateSupport
    * @return
    * @throws Exception
    */
    @PostMapping("/import-pushLog")
    public Result<String> importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        CacpTransUser user = UserContextHolder.currentUser();
        ExcelUtil<PushLog> util = new ExcelUtil<PushLog>(PushLog.class);
        List<PushLog> pushLogList = util.importExcel(file.getInputStream());
        String message = pushLogService.importPushLog(pushLogList, updateSupport, user);
        return Result.success(message);
    }

    /**
     * 导出推送记录列表
     */
    @PostMapping("/get-pushLog-export")
    public void export(HttpServletResponse response, @RequestBody PushLogQuery query) {
        List<PushLog> list = pushLogService.selectList(query);
        ExcelUtil<PushLog> util = new ExcelUtil<PushLog>(PushLog. class);
        util.exportExcel(response, list, "推送记录数据");
    }

    /**
    * 获取导入模板
    * @param response
    */
    @PostMapping("/template-pushLog")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<PushLog> util = new ExcelUtil<PushLog>(PushLog.class);
        util.importTemplateExcel(response, "推送记录");
    }
}
