package com.dgtly.wxportal.controller;



import com.dgtly.common.annotation.Log;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.wxportal.domain.WxQyUser;
import com.dgtly.wxportal.service.IWxQyUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("/wxqyuser")
public class WxQyUserController extends BaseController {

    private String prefix = "wxportal";

    @Autowired
    private IWxQyUserService wxQyUserService;

    /**
     * 解除微信绑定
     */
    @Log(title = "解除微信绑定", businessType = BusinessType.DELETE)
    @RequiresPermissions("system:user:bonded")
    @PostMapping("/bonded/{sysUserId}")
    @ResponseBody
    public AjaxResult bonded(@PathVariable("sysUserId") Long sysUserId)
    {
        return toAjax(wxQyUserService.bondedSysUserBySysUserId(sysUserId));
    }

    /**
     * 查看用户微信信息
     */
    @GetMapping("/wxdetail/{sysUserId}")
    public String wxdetail(@PathVariable("sysUserId") Long sysUserId, ModelMap mmap)
    {
        WxQyUser wxQyUser = new WxQyUser();
        wxQyUser.setSysUserId(sysUserId);
        List<WxQyUser> wxQyUsers = wxQyUserService.selectWxQyUserList(wxQyUser);
        if(wxQyUsers.size()>0){
            mmap.put("wxQyUser",wxQyUsers.get(0));
        }else{
            mmap.put("wxQyUser", null);
        }
        return prefix + "/wxdetail";
    }
}
