package com.xhkjedu.suser.controller.system;

import com.alibaba.fastjson.JSON;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.suser.config.ConfigKey;
import com.xhkjedu.suser.model.system.TUser;
import com.xhkjedu.suser.model.system.TUserUsecret;
import com.xhkjedu.suser.service.system.LoginService;
import com.xhkjedu.suser.service.system.UserService;
import com.xhkjedu.suser.utils.UserUtil;
import com.xhkjedu.suser.vo.assess.AssessParams;
import com.xhkjedu.suser.vo.assess.SignParams;
import com.xhkjedu.utils.IpRegionUtil;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @ClassName UserController
 * Description
 * Author WN
 * Date 2020/5/29 16:29
 **/
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;
    @Resource
    private LoginService loginService;
    @Value("${ssourl}")
    private String ssourl;

    /**
     * 功能描述 登录接口
     *
     * @param * @param user
     * @return com.xhkjedu.vo.ResultVo
     * @author WN
     * @date 2020/6/1
     */
    @PostMapping("/login")
    public ResultVo login(@RequestBody TUser user, HttpServletRequest request) {
        String loginname = N_Utils.strTrim(user.getLoginname());
        String loginpwd = N_Utils.strTrim(user.getLoginpwd());

        N_Utils.validation(new Object[]{loginname, "登录名", 2, loginpwd, "登录密码", 2});
        if (loginname.length() > 16) return new ResultVo(1, "账号长度超过16个字符");

        user.setLoginpwd(loginpwd);
        user.setLoginname(loginname);
        return loginService.getUserByLoginnameAndPwd(user, request);
    }

    //教师登录
    @PostMapping("/login_teacher")
    public ResultVo loginTeacher(@RequestBody TUser user, HttpServletRequest request) {
        String loginname = N_Utils.strTrim(user.getLoginname());
        String loginpwd = N_Utils.strTrim(user.getLoginpwd());
        N_Utils.validation(new Object[]{loginname, "登录名", 2, loginpwd, "登录密码", 2});
        if (loginname.length() > 16) return new ResultVo(1, "账号长度超过16个字符");
        user.setLoginpwd(loginpwd);
        user.setLoginname(loginname);
        return loginService.loginTeacher(user, request);
    }

    /**
     * 功能描述  登录--学生登录
     *
     * @param * @param user
     * @return com.xhkjedu.vo.ResultVo
     * @author WN
     * @date 2020/6/1
     */
    @PostMapping("/loginstu")
    public ResultVo loginStudent(@RequestBody TUser user, HttpServletRequest request) {
        String loginname = N_Utils.strTrim(user.getLoginname());
        String loginpwd = N_Utils.strTrim(user.getLoginpwd());
        N_Utils.validation(new Object[]{loginname, "登录名", 2, loginpwd, "登录密码", 2});
        if (loginname.length() > 18) return new ResultVo(1, "账号长度超过16个字符");
        user.setLoginpwd(loginpwd);
        user.setLoginname(loginname);
        return loginService.loginStudent(user, request);
    }

    /**
     * 验证码登录
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/10/13 15:35
     **/
    @PostMapping("/login_byCode")
    public ResultVo loginByCode(@RequestBody TUser user, HttpServletRequest request) {
        /*if (N_Utils.isEmpty(user.getUltype())) return new ResultVo(1, "请更新新版本");*/
        String userphone = user.getUserphone();
        String msgcode = user.getMsgcode();
        N_Utils.validation(new Object[]{userphone, "手机号", 2, msgcode, "验证码", 2});
        return loginService.loginByCode(user, request);
    }

    /**
     * @Description 教师端验证码登录
     * @Param [user, request]
     * @Author ywx
     * @Date 2023/2/24 10:40
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/logint_byCode")
    public ResultVo loginTeacherByCode(@RequestBody TUser user, HttpServletRequest request) {
        String userphone = user.getUserphone();
        String msgcode = user.getMsgcode();
        N_Utils.validation(new Object[]{userphone, "手机号", 2, msgcode, "验证码", 2});
        user.setUsertype(1);
        return loginService.loginByCode(user, request);
    }

    /**
     * @Description 扫码登录：扫码保存用户信息
     * @Date 2023/2/2 14:21
     * @Author wn
     * @param user
     * @param request
     * @return ResultVo
     **/
    @PostMapping("/qrs")
    public ResultVo loginByQrCodeUserid(@RequestBody TUser user, HttpServletRequest request) {
        N_Utils.validation(new Object[]{user.getQrkey(), "二维码", 2, user.getUserid(), "用户id", 1});
        return loginService.loginByErcodeSave(user, request);
    }

    /**
     * @Description 扫码登录：获取用户信息
     * @Date 2023/2/2 14:22
     * @Author wn
     * @Param [user, request]
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/qrg")
    public ResultVo loginByQrCodeKey(@RequestBody TUser user, HttpServletRequest request) {
        N_Utils.validation(new Object[]{user.getQrkey(), "二维码", 2});
        return loginService.loginByErcodeGet(user, request);
    }

    /*
     * @Description 对接三方登录校验（郑州五十六中）
     * @Date 2024/1/5 11:10:39
     * @Author WN
     * @Param [signParams]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/autologin")
    public ResultVo autoLogin(@RequestBody SignParams signParams, HttpServletRequest request) {
        return loginService.signCheck(signParams,request);
    }

    /**
     * 添加用户信息
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 9:44
     **/
    @PostMapping("/add")
    @Action("用户管理-新增")
    public ResultVo add(@RequestBody TUser user) {
        return userService.save(user);
    }

    /**
     * 修改用户信息
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 9:51
     **/
    @PostMapping("/update")
    @Action("用户管理-修改")
    public ResultVo update(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{user.getUserid(), "用户id", 1});
        return userService.update(user);
    }

    /**
     * 删除用户
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 9:59
     **/
    @PostMapping("/delete")
    @Action("用户管理-删除")
    public ResultVo delete(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{user.getUserid(), "用户id", 1, user.getDeleteid(), "删除人id", 1});
        return userService.deleteById(user);
    }

    /**
     * 获取用户列表
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 10:06
     **/
    @PostMapping("/list")
    public ResultVo list(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{user.getPage(), "显示页码", 1, user.getPageSize(), "显示条数", 1, user.getSchoolid(), "学校id", 1});
        return userService.findAll(user);
    }

    /**
     * 获取用户详情
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 10:23
     **/
    @PostMapping("/detail")
    public ResultVo detail(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        String ultype = user.getUltype();
        N_Utils.validation(new Object[]{userid, "用户id", 1});
        return userService.findById(userid, ultype);
    }

    /**
     * 修改用户密码
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 10:30
     **/
    @PostMapping("/update_pwd")
    @Action("用户管理-修改密码")
    public ResultVo updatePwd(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{user.getUserid(), "用户id", 1, user.getOldpwd(), "原密码", 2, user.getLoginpwd(), "新密码", 2});
        return userService.updatePwd(user);
    }

    /**
     * 修改用户头像
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 10:37
     **/
    @PostMapping("/update_headpic")
    @Action("用户管理-修改头像")
    public ResultVo updateHeadPic(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{user.getUserid(), "用户id", 1});
        return userService.updateHeadPic(user);
    }

    /**
     * 检查登录账号是否存在
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/2 10:43
     **/
    @PostMapping("/check_loginname")
    public ResultVo checkLoginName(@RequestBody TUser user) {
        String loginname = N_Utils.strTrim(user.getLoginname());
        N_Utils.validation(new Object[]{loginname, "登录名", 2});
        return userService.checkLoginName(loginname);
    }

    /**
     * 导入教师
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [file, user]
     * @Author ywx
     * @Date 2020/6/5 8:42
     **/
    @PostMapping("/import_teacher")
    @Action("用户管理-导入教师")
    public ResultVo importTeacher(TUser user, MultipartFile file) {
        return userService.importTeacher(file, user);
    }

    /**
     * 功能描述  设置操作密码
     *
     * @param * @param user
     * @return com.xhkjedu.vo.ResultVo
     * @author WN
     * @date 2020/6/17
     */
    @PostMapping("/update_opepass")
    @Action("用户管理-修改操作密码")
    public ResultVo updateOpepass(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{
                user.getUserid(), "用户id", 1,
                user.getOpepassword(), "操作密码", 2
        });
        userService.updateOpepasswordByUserId(user);
        return new ResultVo(0, "设置操作密码成功");
    }

    /**
     * 功能描述  验证操作密码是否正确
     *
     * @param * @param user
     * @return com.xhkjedu.vo.ResultVo
     * @author WN
     * @date 2020/6/17
     */
    @PostMapping("/validate_opepass")
    public ResultVo validateOpepass(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{
                user.getUserid(), "用户id", 1,
                user.getOpepassword(), "操作密码", 2
        });
        Integer result = userService.getUserIdByOpepassword(user);
        if (result == 1) {
            return new ResultVo(0, "操作密码验证成功");
        } else {
            return new ResultVo(1, "操作密码输入有误");
        }

    }

    /**
     * 教师基本信息
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/6/29 16:23
     **/
    @PostMapping("/teacher_info")
    public ResultVo teacherInfo(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1, user.getSchoolid(), "学校id", 1});
        Map teacherVo = userService.getTeacherInfo(user.getSchoolid(), userid, user.getClasstype());
        return new ResultVo(0, "获取教师基本信息成功", teacherVo);
    }

    /**
     * 重置密码
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/7/30 14:25
     **/
    @PostMapping("/reset_pwd")
    @Action("用户管理-重置密码")
    public ResultVo resetPwd(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{user.getUserid(), "用户id", 1, user.getLoginpwd(), "密码", 2});
        return userService.resetPwd(user);
    }

    /**
     * 生成修改码
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/10/13 15:08
     **/
    @PostMapping("/update_code")
    public ResultVo updateCode(@RequestBody TUser user) {
        String userphone = user.getUserphone();
        N_Utils.validation(new Object[]{userphone, "手机号", 2});
        return userService.updateCode(userphone);
    }

    /**
     * 通过短信修改密码
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/10/13 15:12
     **/
    @PostMapping("/update_pwd_byCode")
    @Action("用户管理-修改密码")
    public ResultVo updatePwdByCode(@RequestBody TUser user) {
        String userphone = user.getUserphone();
        String loginpwd = user.getLoginpwd();
        String msgcode = user.getMsgcode();
        N_Utils.validation(new Object[]{userphone, "手机号", 2, loginpwd, "密码", 2, msgcode, "验证码", 1});
        return userService.updatePwdByCode(user);
    }

    /**
     * 生成登录确认码
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/10/13 15:18
     **/
    @PostMapping("/login_code")
    public ResultVo loginCode(@RequestBody TUser user) {
        String userphone = user.getUserphone();
        N_Utils.validation(new Object[]{userphone, "手机号", 2});
        return userService.loginCode(userphone);
    }

    /**
     * 批量修改用户密码
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user]
     * @Author ywx
     * @Date 2020/10/30 16:04
     **/
    @PostMapping("/batch_update_pwd")
    @Action("用户管理-批量修改密码")
    public ResultVo batchUpdatePwd(@RequestBody TUser user) {
        N_Utils.validation(new Object[]{user.getSchoolid(), "学校id", 1, user.getLoginpwd(), "新密码", 2});
        if (N_Utils.isListEmpty(user.getUsertypes())) return new ResultVo(1, "用户类型集合不能为空");
        return userService.batchUpdatePwd(user);
    }

    //校验登录状态成功
    @PostMapping("/check_login")
    public ResultVo checkLogin(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        String loginpwd = user.getLoginpwd();
        N_Utils.validation(new Object[]{userid, "用户id", 1, loginpwd, "登录密码", 2});
        return userService.checkLogin(userid, loginpwd,user.getDevice());
    }

    @PostMapping("/list_sel")
    public ResultVo listForSel(@RequestBody AssessParams user) {
        Integer schoolid = user.getSchoolid();
        N_Utils.validation(new Object[]{schoolid, "学校id", 1, user.getGradeid(), "年级id", 1
                , user.getClassid(), "班级id", 1, user.getSubjectid(), "科目id", 2});
        List<Map> list = userService.listForSel(user);
        return new ResultVo(0, "获取用户选择列表成功", list);
    }

    /**
     * 用户名登录
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [user, request]
     * @Author ywx
     * @Date 2021/11/18 9:52
     **/
    @PostMapping("/login_byName")
    public ResultVo loginByName(@RequestBody TUser user, HttpServletRequest request) {
        String loginname = N_Utils.strTrim(user.getLoginname());
        N_Utils.validation(new Object[]{loginname, "token", 2});
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("token", loginname);
        String str = UserUtil.sendFormData(ssourl, param);
        ResultVo result = JSON.parseObject(str, ResultVo.class);
        if (result.getCode() != 0) return result;
        Map map = JSON.parseObject(result.getObj().toString(), Map.class);
        user.setLoginname(map.get("loginname").toString());
        return loginService.loginByName(user, request);
    }

    @PostMapping("/get_headtime")
    public ResultVo getHeadTime(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1});
        Integer headtime = userService.getHeadTime(userid);
        return new ResultVo(0, "获取头像是否可以修改成功", headtime);
    }

    /**
     * 绑定密保
     *
     * @param [usecrets]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/3/30 12:47
     */
    @PostMapping("/bind_usecert")
    @Action("用户管理-绑定密保")
    public ResultVo bindUseCert(@RequestBody List<TUserUsecret> usecrets) {
        if (N_Utils.isListEmpty(usecrets)) {
            return new ResultVo(1, "密保问题不能为空");
        }
        userService.bindUseCert(usecrets);
        return new ResultVo(0, "绑定密保成功");
    }

    /**
     * 绑定手机
     *
     * @param [user]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/3/30 13:05
     */
    @PostMapping("/bind_userphone")
    @Action("用户管理-绑定手机号")
    public ResultVo bindUserPhone(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        String userphone = user.getUserphone();
        String msgcode = user.getMsgcode();
        N_Utils.validation(new Object[]{userid, "用户id", 1, userphone, "手机号", 2, msgcode, "短信验证码", 2});
        return userService.bindUserPhone(userid, userphone, msgcode);
    }

    /**
      * 验证身份
      * @param [user]
      * @author ywx
      * @date 2022/3/30 14:00
      * @return com.xhkjedu.vo.ResultVo
      */
    @PostMapping("/check_user")
    public ResultVo checkUser(@RequestBody TUser user) {
        String loginname = user.getLoginname();
        String username = user.getUsername();
        N_Utils.validation(new Object[]{loginname, "账号", 2, username, "姓名", 2});
        return userService.checkUser(loginname, username);
    }

    /**
      * 根据用户id获取关联密保
      * @param [user]
      * @author ywx
      * @date 2022/3/30 14:24
      * @return com.xhkjedu.vo.ResultVo
      */
    @PostMapping("/list_usecret")
    public ResultVo listUsecret(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1});
        List<Map> list = userService.listUsecret(userid);
        return new ResultVo(0, "获取关联密保列表成功", list);
    }

    /**
     * 根据用户id获取绑定方式
     *
     * @param [user]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/3/30 14:58
     */
    @PostMapping("/get_bind")
    public ResultVo getBind(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1});
        Map map = userService.getBind(userid);
        return new ResultVo(0, "根据用户id获取绑定方式成功", map);
    }

    /**
     * 生成绑定手机码
     *
     * @param [user]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/3/30 16:34
     */
    @PostMapping("/bind_code")
    public ResultVo bindCode(@RequestBody TUser user) {
        String userphone = user.getUserphone();
        N_Utils.validation(new Object[]{userphone, "手机号", 2});
        return userService.bindCode(userphone);
    }

    /**
     * 校验用户密保答案
     * @param [user]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/4/7 16:16
     */
    @PostMapping("/check_usecret")
    public ResultVo checkUsecret(@RequestBody TUserUsecret user) {
        Integer userid = user.getUserid();
        Integer usid = user.getUsid();
        String usanswer = user.getUsanswer();
        N_Utils.validation(new Object[]{userid, "用户id", 1, usid, "密保id", 1, usanswer, "密保答案", 2});
        return userService.checkUsecret(userid, usid, usanswer);
    }

    /**
     * 校验用户密码
     *
     * @param [user]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/4/8 15:05
     */
    @PostMapping("/check_pwd")
    public ResultVo checkPwd(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        String loginpwd = user.getLoginpwd();
        N_Utils.validation(new Object[]{userid, "用户id", 1, loginpwd, "密码", 2});
        return userService.checkPwd(user);
    }

    /**
     * 锁定用户
     *
     * @param [user]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/4/26 16:30
     */
    @PostMapping("/lock")
    @Action("用户管理-锁定用户")
    public ResultVo lock(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1});
        userService.lock(userid);
        return new ResultVo(0, "锁定成功");
    }

    /**
     * 解锁用户
     *
     * @param [user]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/4/26 16:35
     */
    @PostMapping("/unlock")
    @Action("用户管理-解锁用户")
    public ResultVo unLock(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1});
        userService.unLock(userid);
        return new ResultVo(0, "解锁成功");
    }

    /**
     * 批量修改密码
     *
     * @param [map]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/5/20 11:18
     */
    @PostMapping("/batch_update_pwd2")
    @Action("用户管理-批量修改密码")
    public ResultVo batchUpdatePwd2(@RequestBody Map map) {
        String loginpwd = map.get("loginpwd").toString();
        N_Utils.validation(new Object[]{loginpwd, "密码", 2});
        List<Integer> userids = (List<Integer>) map.get("userids");
        if (N_Utils.isListEmpty(userids)) return new ResultVo(1, "用户id集合不能为空");
        userService.batchUpdatePwd2(loginpwd, userids);
        return new ResultVo(0, "批量修改密码成功");
    }

    /**
     * 批量修有效期
     *
     * @param [map]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/5/20 11:23
     */
    @PostMapping("/batch_update_time")
    @Action("用户管理-批量修改效期")
    public ResultVo batchUpdateTime(@RequestBody Map map) {
        String usertime = map.get("usertime").toString();
        List<Integer> userids = (List<Integer>) map.get("userids");
        if (N_Utils.isListEmpty(userids)) return new ResultVo(1, "用户id集合不能为空");
        userService.batchUpdateTime(usertime, userids);
        return new ResultVo(0, "批量修有效期成功");
    }

    @PostMapping("/activate")
    @Action("用户管理-修改状态")
    public ResultVo activate(@RequestBody TUser user) {
        Integer userid = user.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1});
        userService.updateState(userid, 1);
        return new ResultVo(0, "激活成功");
    }

    @PostMapping("/batch_activate")
    @Action("用户管理-批量修改状态")
    public ResultVo batchActivate(@RequestBody Map map) {
        List<Integer> userids = (List<Integer>) map.get("userids");
        if (N_Utils.isListEmpty(userids)) return new ResultVo(1, "用户id集合不能为空");
        userService.batchActivate(userids);
        return new ResultVo(0, "批量激活成功");
    }

    @GetMapping("/ip")
    public ResultVo getIpRegion(){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        // 从获取RequestAttributes中获取HttpServletRequest的信息
        HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);

        String ip = N_Utils.getIpAddress(request);
        String region = "";
        if(N_Utils.isNotEmpty(ip)){
            IpRegionUtil ipRegionUtil = new IpRegionUtil();
            region = ipRegionUtil.getIpForAddress(ip, ConfigKey.ipregiondb);
        }
        Map map = new TreeMap();
        map.put("ip",ip);
        map.put("region",region);
        return new ResultVo(0,"获取成功",map);
    }
}
