package org.jeecg.modules.alUser.controller;

import com.alibaba.fastjson.JSONObject;
import com.xkcoding.http.HttpUtil;
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.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.alUser.service.UserService;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.postBean.SuggestReq;
import org.jeecg.modules.tbSuggest.entity.TbSuggest;
import org.jeecg.modules.tbSuggest.service.ITbSuggestService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author scott
 * @since 2018-12-17
 */
@RestController
@RequestMapping("/index")
@Api(tags = "首页等展示接口")
@Slf4j
public class IndexController {
    @Autowired
    private ITbSuggestService tbSuggestService;
    @Autowired
    private IHanHaiMemberService hanHaiMemberService;
    @Autowired
    private ShiroRealm shiroRealm;


    @ApiOperation(value = "铝价接口")
    @RequestMapping(value = "/alprice", method = RequestMethod.POST)
    public Result<JSONObject> alprice() {
        String s = HttpUtil.get("https://www.alphavantage.co/query?function=ALUMINUM&interval=monthly&apikey=AH6NDLVPBHJ8K7OM");
        JSONObject jsonObject = JSONObject.parseObject(s);
        return Result.ok(jsonObject);
    }

    @ApiOperation(value = "我的头像昵称，平台客户电话等信息")
    @RequestMapping(value = "/index", method = RequestMethod.POST)
    public Result<JSONObject> index(@RequestHeader("X-Access-Token") String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        hanHaiMember.setPasswordSalt(null);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("phone","123456");
        jsonObject.put("my",hanHaiMember);

        return Result.ok(jsonObject);
    }

    @ApiOperation(value="帮助与反馈", notes="帮助与反馈")
    @PostMapping(value = "/addSuggest")
    public Result<String> addSuggest(@RequestBody SuggestReq tbSuggest, @RequestHeader("X-Access-Token") String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        TbSuggest tbSuggest1 = new TbSuggest();
        BeanUtils.copyProperties(tbSuggest, tbSuggest1);
        tbSuggest1.setUserId(hanHaiMember.getId());
        tbSuggestService.save(tbSuggest1);
        return Result.OK("添加成功！");
    }


}
