package org.jeecg.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags="项目通用-修改个人信息")
@RestController
@RequestMapping("/info_common")
@Slf4j
public class AppletMyInfoController {

    @Resource
    private IHanHaiMemberService hanHaiMemberService;
    //权限验证
    @Resource
    private ShiroRealm shiroRealm;

    //修改个人信息
    @PostMapping(value = "/updateInfo")
    @ApiOperation(value="修改个人信息", notes="修改个人信息")
    public Result<?> updateInfo(@RequestHeader("X-Access-Token") String token, String nickName, String avatarUrl){
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);
        HanHaiMember member = new HanHaiMember();
        member.setId(hanHaiMember.getId());
        member.setNickName(nickName);
        member.setHeadImage(avatarUrl);
    	hanHaiMemberService.updateById(member);
    	return Result.ok("修改成功");
    }

    //获取个人信息
    @GetMapping(value = "/getInfo")
    @ApiOperation(value="获取个人信息", notes="获取个人信息")
    public Result<?> getInfo(@RequestHeader("X-Access-Token") String token){
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);
        HanHaiMember byId = hanHaiMemberService.getById(hanHaiMember.getId());
        return Result.OK(byId);
    }



}
