package com.zhongzheng.controller.inform;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.modules.inform.vo.InformUserVo;
import com.zhongzheng.modules.inform.bo.InformUserQueryBo;
import com.zhongzheng.modules.inform.bo.InformUserAddBo;
import com.zhongzheng.modules.inform.bo.InformUserEditBo;
import com.zhongzheng.modules.inform.service.IInformUserService;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 通知绑定学员Controller
 * 
 * @author ruoyi
 * @date 2021-12-16
 */
@Api(value = "我的消息", tags = {"我的消息"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/app/informUser")
public class InformUserController extends BaseController {

    private final IInformUserService iInformUserService;

    private final WxTokenService wxTokenService;

    /**
     * 查询通知绑定学员列表
     */
    @ApiOperation("查询通知学员列表")
    @GetMapping("/list")
    public TableDataInfo<InformUserVo> list(InformUserQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<InformUserVo> list = iInformUserService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 获取通知绑定学员详细信息
     */
    @ApiOperation("获取通知学员详细信息")
    @GetMapping("/{id}")
    public AjaxResult<InformUserVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iInformUserService.queryById(id));
    }


    /**
     * 修改通知绑定学员
     */
    @ApiOperation("修改通知学员")
    @Log(title = "通知学员", businessType = BusinessType.UPDATE)
    @PostMapping()
    public AjaxResult<Void> edit(@RequestBody InformUserEditBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(iInformUserService.updateByEditBo(bo) ? 1 : 0);
    }


}
