package com.fs.app.controller;

import java.util.List;

import com.fs.app.annotation.Login;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.R;
import com.fs.gtPush.service.UniPushLogService;
import com.fs.gtPush.vo.UniPushLogAppVo;
import com.fs.gtPush.vo.UniPushLogLastAndReadStatusVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.gtPush.domain.UniPushLog;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * uni推送消息记录Controller
 *
 * @author fs
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/app/uniPushLog")
public class UniPushLogController extends  AppBaseController
{
    @Autowired
    private UniPushLogService uniPushLogService;

    /**
     * 查询uni推送消息记录最新记录,及未读条数
     */
    @Login
    @GetMapping("/getLastAndReadStatus")
    public AjaxResult getLastAndReadStatus()
    {
        String userId = getUserId();
        UniPushLogLastAndReadStatusVo vo = uniPushLogService.getLastAndReadStatus(Long.parseLong(userId));
        return AjaxResult.success(vo);
    }

    /**
     * 查询uni推送消息记录列表
     */
    @Login
    @GetMapping("/list")
    public TableDataInfo list(UniPushLog uniPushLog)
    {
        startPage();
        uniPushLog.setUserId(Long.parseLong(getUserId()));
        uniPushLog.setPushRes(1); //推送成功的
        List<UniPushLogAppVo> list = uniPushLogService.selectUniPushLogListApp(uniPushLog);
        return getDataTable(list);
    }


    /**
     * 获取uni推送消息记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('gtPush:uniPushlog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(uniPushLogService.selectUniPushLogById(id));
    }

    /**
     * 一键已读
     */
    @Login
    @PostMapping(value = "/setIsRead")
    public AjaxResult setIsRead(@RequestBody List<Long> logIds)
    {
        return AjaxResult.success(uniPushLogService.setIsRead(logIds,Long.valueOf(getUserId())));
    }



}
