package com.ematou.wxservice.controller;

import com.ematou.wxservice.common.web.R;
import com.ematou.wxservice.entity.pojo.UserInfo;
import com.ematou.wxservice.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author lhm
 * @version 1.0
 * 2021-05-10 19:55
 */
@RestController
public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;

    @GetMapping("/user")
    public R<?> getUserInfo(String openId, String phoneNumber) {
        UserInfo userInfo = userInfoService.get(openId, phoneNumber);
        if (null != userInfo) {
            return new R<>().success(userInfo);
        } else {
            return new R<>().error("查询用户数据时，openId和phoneNumber必须要带有有其中一个！");
        }

    }

    @GetMapping("/user/send")
    public R<?> sendMsg(String phoneNumber,String openId) {
        String msg = userInfoService.sendMsg(phoneNumber,openId);
        return new R<>().success(msg);
    }

}
