package com.boman.web.core.controller;

import com.boman.domain.dto.AjaxResult;
import com.boman.domain.dto.FormDataDto;
import com.boman.domain.dto.QueryBySqlDto;
import com.boman.web.core.domain.MessageDto;
import com.boman.web.core.service.message.MessageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shiqian
 * @Date: 2021/07/08/
 */
@RestController
@RequestMapping("/message")
public class MessageController {

    @Resource
    private MessageService service;

    /**
     * 功能描述: 撤回
     *
     * @param id id
     * @return com.boman.domain.dto.AjaxResult
     */
    @GetMapping("withdraw/{id}")
    public AjaxResult withdraw(@PathVariable("id") Long id) {
        boolean withdraw = service.withdraw(id);
        return withdraw ? AjaxResult.success("撤回成功") : AjaxResult.error("撤回失败");
    }

    /**
     * 功能描述: 可以下载：超过30分钟 true，不能下载：30分钟以内 false
     *
     * @param id id
     * @return com.boman.domain.dto.AjaxResult
     */
    @GetMapping("canDownload/{id}")
    public AjaxResult canDownload(@PathVariable("id") Long id) {
        boolean withdraw = service.canDownload(id);
        return withdraw ? AjaxResult.success("可以下载") : AjaxResult.success("无法下载");
    }

    /**
     * 功能描述:
     * <>{
     *     "primaryTableName": "boman_message",
     *     "deputyTableName": "boman_message_receive",
     *     "primaryTableNameRelKey": "id",
     *     "deputyTableNameRelKey": "message_id",
     *     "pageNo": 1,
     *     "pageSize": 10,
     *     "orderBy": "boman_message.create_time desc",
     *     "condition": {
     *         "boman_message_receive.status": "N",
     *         "boman_message_receive.visible": "Y"
     *     }
     * }</>
     *
     * @param queryBySql queryBySql
     * @return com.boman.domain.dto.AjaxResult
     */
    @PostMapping("/notFinishMessages")
    public AjaxResult notFinishMessages(@RequestBody QueryBySqlDto queryBySql) {
        return service.notFinishMessages(queryBySql);
    }

    @PostMapping("/toDoMessage")
    public AjaxResult toDoMessage(@RequestBody FormDataDto dto) {
        return service.toDoMessage(dto);
    }

    @PostMapping("/receiveMessage")
    public AjaxResult receiveMessage(@RequestBody MessageDto dto) {
        return service.receiveMessage(dto);
    }

}
