package com.younike.store;

import com.alibaba.fastjson.JSONObject;
import com.younike.common.annotation.RestAuth;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import com.younike.common.core.controller.BaseController;
import com.younike.common.utils.network.HttpClientUtils;
import com.younike.service.pojo.TAppUser;
import com.younike.service.service.ISysUserService;
import com.younike.service.service.ITAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * logback日志Controller
 *
 * @author dail
 * @date 2022-05-19
 */
@RestController
@RequestMapping()
public class TestController extends BaseController {

    @Autowired
    ISysUserService sysUserService;

    @Autowired
    ITAppUserService appUserService;


    /**
     * 查询logback日志列表
     */
    @GetMapping("/test")
    @RestAuth(isPublic = true)
    @Transactional
    public APIResult list() {

        // 测试1 事务二发生异常  同时回滚    √

//        SysUser sysUser1 = new SysUser();
//        sysUser1.setLoginName("sdfasdf");
//
//

        // 测试2 业务发生异常  同时回滚     √
//        SysUser sysUser1 = new SysUser();
//        sysUser1.setLoginName("sdfasdf");
//
//        System.out.println("用户查询结果:" + sysUserService.insertUser(sysUser1));
//
        TAppUser byId = appUserService.getById("92427161557832704");
        return ResultGenerator.getSuccessResult(byId);
//        String str = null;
//        str.split(",");

    }


    public static void main(String[] args) {
        String s = HttpClientUtils.executeGet("https://restapi.amap.com/v3/geocode/regeo?key=fb568b9d4822bc48573be33b16333965&location=120.72946,31.243607");
        JSONObject jsonObject = JSONObject.parseObject(s);
        if(jsonObject.get("infocode").equals("10000")){
            JSONObject regeocode = jsonObject.getJSONObject("regeocode");
            JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
            JSONObject neighborhood = addressComponent.getJSONObject("neighborhood");
            Object name = neighborhood.get("name");
            System.out.println(name);
        }
    }


}
