package com.fufan.mtsaas.modules.base.sysmsg.controller;

import com.alibaba.fastjson.JSONObject;
import com.fufan.mtsaas.modules.base.sysmsg.bo.request.MsgQueryRequest;
import com.fufan.mtsaas.modules.base.sysmsg.bo.request.MsgSaveRequest;
import com.fufan.mtsaas.modules.base.sysmsg.bo.response.MsgResponse;
import com.fufan.mtsaas.modules.base.sysmsg.model.TSysMessage;
import com.fufan.mtsaas.modules.base.sysmsg.service.TSysMessageService;
import com.fufan.mtsaas.modules.common.bo.request.DataRequest;
import com.fufan.mtsaas.modules.common.bo.request.DataRequestT;
import com.fufan.mtsaas.modules.common.bo.request.ResultPack;
import com.fufan.mtsaas.modules.common.bo.response.RequestPojo;
import com.fufan.mtsaas.modules.common.bo.response.Result;
import com.fufan.mtsaas.util.JSonUtil;
import com.fufan.mtsaas.util.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * 系统消息表(TSysMessage)表控制层
 *
 * @author Liby
 * @since 2025-01-08 15:58:32
 */
@RestController
@Api(tags = "MTSaas：系统模块-系统消息相关接口", description = "tSysMessage对象接口")
@RequestMapping("/MTSaas/tSysMessage")
public class TSysMessageController {
    /**
     * 服务对象
     */
    @Resource
    private TSysMessageService targetService;

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询所有，根据需要传入分页参数：pageSize每页数量(默认为10)，currentPage当前页数(默认为1)", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doQueryPage")
    public Result<MsgResponse> doQueryPage(@RequestBody @ApiIgnore DataRequest dataRequest, MsgQueryRequest request) {
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();

        JSONObject mapdata = dataRequest.getData().getParam();
        MsgQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), MsgQueryRequest.class);

        return resultPack.doResultPack(targetService.doQueryPage(map), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 已读操作
     */
    @ApiOperation(value = "已读操作", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value = "/doRead", method = RequestMethod.POST)
    public Result<TSysMessage> doRead(@RequestBody @ApiIgnore @Valid DataRequestT<MsgSaveRequest> dataRequest, MsgSaveRequest request, @ApiIgnore HttpSession session) {
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();

        return resultPack.doResultPack(targetService.doRead(dataRequest.getData().getParam(), requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 获取未读数量操
     */
    @ApiOperation(value = "获取未读数量操作", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value = "/doUnReadNum", method = RequestMethod.POST)
    public Result<TSysMessage> doReadNum() {
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();

        return resultPack.doResultPack(targetService.doUnReadNum(requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

}

