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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.entity.dto.MessagepushDto;
import com.tofly.base.service.messge.MessagepushService;
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.Messagepush;
import com.tofly.pojo.message.Messagerecipient;
import lombok.AllArgsConstructor;
import org.springframework.util.StringUtils;
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.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 消息推送数据表:TF_YWPN_MESSAGEPUSH_W
 *
 * @author admin
 * @date Wed Mar 31 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/messagepush")
@Api(tags="消息推送数据接口")
public class MessagepushController {

    private final MessagepushService messagepushService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param dto 消息推送数据表:TF_YWPN_MESSAGEPUSH_W
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getMessagepushPage(Page page, @ModelAttribute MessagepushDto dto) {
      return ResultRespone.success(messagepushService.getPageInfo(page, dto));
    }


    /**
     * 通过id查询消息推送数据表:TF_YWPN_MESSAGEPUSH_W
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(messagepushService.getById(id));
    }

    /**
     * 新增消息推送数据表:TF_YWPN_MESSAGEPUSH_W
     * @param messagepush 消息推送数据表:TF_YWPN_MESSAGEPUSH_W
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增消息推送数据表:TF_YWPN_MESSAGEPUSH_W" )
    @ApiOperation(value = "新增消息推送数据表:TF_YWPN_MESSAGEPUSH_W")
    @PostMapping("/save")
    public ResultRespone<Long> save(@RequestBody Messagepush messagepush) {
        boolean save = messagepushService.save(messagepush);
        if(save){
            return ResultRespone.success(messagepush.getId());
        }else {
            return ResultRespone.failed(null);
        }

    }

    /**
     * 修改消息推送数据表:TF_YWPN_MESSAGEPUSH_W
     * @param messagepush 消息推送数据表:TF_YWPN_MESSAGEPUSH_W
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改消息推送数据表:TF_YWPN_MESSAGEPUSH_W" )
    @ApiOperation(value = "修改消息推送数据表:TF_YWPN_MESSAGEPUSH_W")
    @PutMapping("/updata")
    public ResultRespone updateById(@RequestBody Messagepush messagepush) {
      return ResultRespone.success(messagepushService.updateById(messagepush));
    }

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