package com.zd.base.message.controller;

import com.zd.base.message.service.IWechatMsgSendService;
import com.zd.common.core.domain.R;
import com.zd.common.core.template.TemplateResult;
import com.zd.common.core.web.domain.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@Api(tags = "微信模板消息发送")
@RequestMapping("/wx")
public class WechatMsgController {

    @Autowired
    private IWechatMsgSendService sendService;

    /**
     * 待办事项消息发送
     */
    @GetMapping("/list")
    @ApiOperation(value = "订阅列表查询")
    public ResultData<List<String>> list() {
        return ResultData.success(sendService.getList());
    }

    /**
     * 待办事项消息发送
     * @param backlogName 待办事项名称
     * @param remark 备注
     * @return TemplateResult
     */
    @GetMapping("/backlog")
    @ApiOperation(value = "待办事项消息发送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "backlogName",value = "待办事项名称"),
            @ApiImplicitParam(name = "remark",value = "备注")
    })
    public R<TemplateResult> backlog(Long userId, String backlogName, String remark) {
        return  R.ok(sendService.sendBacklogResult(userId,backlogName,remark));
    }

    /**
     * 资格申请、用气申请通知发送
     * @param checkType 审核类型 1：资格申请 2：用气申请
     * @param checkStatus 审核状态
     * @param checkTime 审核时间
     * @return TemplateResult 通知发送结果
     */
    @GetMapping("/check")
    @ApiOperation(value = "审核消息发送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "checkType",value = "审核类型 1：资格申请 2：用气申请"),
            @ApiImplicitParam(name = "checkStatus",value = "审核状态 1：通过 2：已驳回"),
            @ApiImplicitParam(name = "checkTime",value = "审核时间")
    })
    public R<TemplateResult> check(Long userId,Integer checkType, Integer checkStatus, Date checkTime,Long taskId) {
        return R.ok(sendService.sendCheckResult(userId,checkType,checkStatus,checkTime,taskId));
    }

    /**
     * 资格申请、用气申请通知发送
     * @param checkType 审核类型 1：资格申请 2：用气申请
     * @param checkStatus 审核状态
     * @param checkTime 审核时间
     * @return TemplateResult 通知发送结果
     */
    @GetMapping("stu/check")
    @ApiOperation(value = "学生端审核消息发送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "checkType",value = "审核类型 1：资格申请 2：用气申请"),
            @ApiImplicitParam(name = "checkStatus",value = "审核状态 1：通过 2：已驳回"),
            @ApiImplicitParam(name = "checkTime",value = "审核时间")
    })
    public R<TemplateResult> stuCheck(Long userId,Integer checkType, Integer checkStatus, Date checkTime,Long taskId) {
        return R.ok(sendService.sendStuCheckResult(userId,checkType,checkStatus,checkTime,taskId));
    }

    /**
     * 出库确认通知
     *
     * @param outType 出库类型
     * @param outTime   出库时间
     * @return TemplateResult 通知发送结果
     */
    @GetMapping("/storage/out")
    @ApiOperation(value = "出库确认通知")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outType",value = "出库类型"),
            @ApiImplicitParam(name = "outTime",value = "出库时间")
    })
    public R<TemplateResult> storageOut(Long userId,String outType, Date outTime) {
        return R.ok(sendService.sendStorageOutResult(userId,outType,outTime));
    }

    /**
     * 资格申请、用气申请待审核通知发送
     *
     * @param checkType   审核类型 1：资格申请 2：用气申请
     * @param name 申请人
     * @param applyTime   申请时间
     * @return TemplateResult 通知发送结果
     */
    @GetMapping("/wait/check")
    @ApiOperation(value = "待审核消息发送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "checkType",value = "审核类型 1：资格申请 2：用气申请"),
            @ApiImplicitParam(name = "name",value = "申请人"),
            @ApiImplicitParam(name = "applyTime",value = "申请时间")
    })
    public R<TemplateResult> waitCheck(Long userId,Integer checkType,String name, Date applyTime) {
        return R.ok(sendService.sendWaitCheckResult(userId,checkType,name,applyTime));
    }

    /**
     * 设备报警通知发送
     *
     * @param userIds   上报接收人
     * @param address 报警位置
     * @return TemplateResult 通知发送结果
     */
    @PostMapping("/send/alarm")
    @ApiOperation(value = "气瓶超出范围通知")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userIds",value = "上报接收人"),
            @ApiImplicitParam(name = "address",value = "报警位置")
    })
    public R<TemplateResult> sendAlarm(@RequestBody List<Long> userIds, @RequestParam("address") String address) {
        return R.ok(sendService.sendAlarm(userIds,address));
    }
}
