/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.base.controller.message;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.base.service.messge.MessagerecipientService;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.pojo.message.Messagerecipient;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;
/**
 * 接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
 *
 * @author admin
 * @date Wed Mar 31 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/messagerecipient")
@Api(tags="接收人接收消息数据接口")
public class MessagerecipientController {

    private final MessagerecipientService messagerecipientService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param messagerecipient 接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getMessagerecipientPage(Page page, @ModelAttribute Messagerecipient messagerecipient) {
      return ResultRespone.success(messagerecipientService.page(page, Wrappers.query(messagerecipient)));
    }


    /**
     * 通过id查询接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone<Messagerecipient> getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(messagerecipientService.getById(id));
    }

    /**
     * 新增接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
     * @param messagerecipient 接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W" )
    @ApiOperation(value = "新增接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W")
    @PostMapping("/save")
    public ResultRespone<Boolean> save(@RequestBody Messagerecipient messagerecipient) {
      return ResultRespone.success(messagerecipientService.save(messagerecipient));
    }

    /**
     * 修改接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
     * @param messagerecipient 接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W" )
    @ApiOperation(value = "修改接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W")
    @PutMapping("/updata")
    public ResultRespone<Boolean> updateById(@RequestBody Messagerecipient messagerecipient) {
      return ResultRespone.success(messagerecipientService.update(messagerecipient,new QueryWrapper<Messagerecipient>().lambda().eq(Messagerecipient::getMessageId,messagerecipient.getMessageId())));
    }

    /**
     * 通过id删除接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W" )
    @ApiOperation(value = "通过ID删除接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(messagerecipientService.removeById(id));
    }

    /**
     * 通过id批量删除接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id批量删除接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W" )
    @ApiOperation(value = "通过ID批量删除接收人接收消息数据表：TF_YW_MESSAGERECIPIENT_W")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(messagerecipientService.removeByIds(Arrays.asList(ids.split(","))));
    }

    @ApiOperation(value = "批量修改对应消息信息的接收状态为已读")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageIds", value = "消息对象ID，多个id以逗号隔开", required = true, dataType = "String")
    })
    @GetMapping("/updateBatchMessageFlag")
    public ResultRespone<Boolean> updateBatchMessageFlag(String messageIds) {
        return ResultRespone.success(messagerecipientService.updateBatchMessageFlag(messageIds));
    }
}
