YinShiController.java 21.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
package com.sincre.springboot.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sincre.springboot.ApiModel.Page;
import com.sincre.springboot.ApiModel.YinShiResResult;
import com.sincre.springboot.ApiPlatform.YinShiServiceConfig;
import com.sincre.springboot.common.MD5;
import com.sincre.springboot.common.ResponseCode;
import com.sincre.springboot.common.ServerResponse;
import com.sincre.springboot.utils.ApiHelper;
import com.sincre.springboot.utils.CacheHelper;
import com.sincre.springboot.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/YinShi")
@Api(value = "YinShiController", tags = "用户管理和用户组权限管理以及设备管理接口")
public class YinShiController {

    @ApiOperation(value = "用于管理员获取accessToken")
    @GetMapping("/token")
    public ServerResponse GetYinShiToken() {

        CacheHelper.GetYinShiToken();

        return ServerResponse.createBySuccessMessage(ResponseCode.SUCCESS.getDesc());
    }

    @ApiOperation(value = "增加子账号")
    @GetMapping("/addChildAccount")
    public ServerResponse addChildAccount(@RequestParam String accountName, @RequestParam String password) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/create";
        Map<String, Object> map = new HashMap<>();
        //子账户密码,LowerCase(MD5(AppKey#密码明文))
        password = YinShiServiceConfig.appKey + "#" + password;
        try {
            password = MD5.md5(password, "").toLowerCase();
        } catch (Exception ex) {
            ex.getStackTrace();
        }
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountName", accountName);
        map.put("password", password);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        System.out.println(result);
        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "获取单个子账户信息")
    @ApiImplicitParam(name="accountId",value = "子账号标识",required = true,dataType = "String")
    @GetMapping("getChildAccount")
    public ServerResponse getChildAccount(@RequestParam String accountId) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountId", accountId);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "获取子账号信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true),
            @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50")
    })
    @GetMapping("getChildAccountList")
    public ServerResponse getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) {

        pageIndex = pageIndex - 1;
        String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("pageStart", pageIndex);
        map.put("pageSize", pageSize);
        String result = ApiHelper.doPost(url, new HashMap<String,String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "修改当前子账户密码")
    @GetMapping("updateChildPassword")
    public ServerResponse updateChildPassword(@RequestParam("accountId") String accountId, @RequestParam("newPassword") String newPassword, @RequestParam("oldPassword") String oldPassword) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword";
        Map<String, Object> map = new HashMap<>();

        oldPassword = YinShiServiceConfig.appKey + "#" + oldPassword;
        newPassword = YinShiServiceConfig.appKey + "#" + newPassword;
        try {
            oldPassword = MD5.md5(oldPassword, "").toLowerCase();
            newPassword = MD5.md5(newPassword, "").toLowerCase();
        } catch (Exception ex) {
            ex.getStackTrace();
        }
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountId", accountId);
        map.put("oldPassword", oldPassword);
        map.put("newPassword", newPassword);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "删除指定子账户")
    @GetMapping("deleteChildAccount")
    public ServerResponse deleteChildAccount(@RequestParam String accountId) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/delete";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountId", accountId);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }


    @ApiOperation(value = "设置子账户的授权策略")
    @GetMapping("policySet")
    public ServerResponse policySet(@RequestParam String accountId, @RequestParam String policy) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/policy/set";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountId", accountId);
        map.put("policy", policy);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "增加子账户授权策略中的授权语句")
    @GetMapping("policyAdd")
    public ServerResponse policyAdd(@RequestParam String accountId, @RequestParam String statement) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/add";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountId", accountId);
        map.put("statement", statement);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句")
    @GetMapping("policyDelete")
    public ServerResponse policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountId", accountId);
        map.put("deviceSerial", deviceSerial);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "获取B模式子账户accessToken")
    @GetMapping("getChildAccountToken")
    public ServerResponse getChildAccountToken(@RequestParam String accountId) {

        String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("accountId", accountId);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }



    @ApiOperation(value = "添加设备到账号下")
    @ApiImplicitParams({
            @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true),
            @ApiImplicitParam(name="validateCode",value = "备验证码,设备机身上的六位大写字母,如OLZKQU",required = true)
    })
    @GetMapping("addAccountDevice")
    public ServerResponse addAccountDevice(@RequestParam String deviceSerial,@RequestParam String validateCode) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/add";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("validateCode", validateCode);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "修改设备的名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true),
            @ApiImplicitParam(name="deviceName",value = "设备名称,长度不大于50字节,不能包含特殊字符",required = true)
    })
    @GetMapping("updateDeviceName")
    public ServerResponse updateDeviceName(@RequestParam String deviceName,@RequestParam String deviceSerial) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/name/update";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("deviceName", deviceName);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "删除设备")
    @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
    @GetMapping("deleteDevice")
    public ServerResponse deleteDevice(@RequestParam String deviceSerial) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/delete";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "设备抓拍图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name="channelNo",value = "通道号,IPC设备填写1",required = true),
            @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
    })
    @GetMapping("deviceCapture")
    public ServerResponse deviceCapture(@RequestParam Integer channelNo,@RequestParam String deviceSerial) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/capture";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("channelNo",channelNo);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }







    @ApiOperation(value = "获取设备列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true),
            @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50")
    })
    @GetMapping("getDeviceList")
    public ServerResponse getDeviceList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) {

        pageIndex = pageIndex - 1;
        String url = YinShiServiceConfig.HostUrl + "lapp/device/list";
        Map<String, Object> map = new HashMap<>();

        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("pageStart", pageIndex);
        map.put("pageSize", pageSize);
        String result = ApiHelper.doPost(url, new HashMap<String,String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "获取单个设备信息")
    @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
    @GetMapping("getDeviceInfo")
    public ServerResponse getDeviceInfo(@RequestParam String deviceSerial) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/info";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "获取摄像头列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true),
            @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50")
    })
    @GetMapping("getCameraList")
    public ServerResponse getCameraList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) {

        pageIndex = pageIndex - 1;
        String url = YinShiServiceConfig.HostUrl + "lapp/camera/list";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("pageStart", pageIndex);
        map.put("pageSize", pageSize);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "获取设备状态信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="channelNo",value = "通道号,IPC设备填写1",required = false),
            @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
    })
    @GetMapping("getDeviceStatus")
    public ServerResponse getDeviceStatus(@RequestParam(defaultValue = "1") Integer channelNo,@RequestParam String deviceSerial) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/status/get";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("channelNo",channelNo);

        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "获取设备的通道信息")
    @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
    @GetMapping("getDeviceChanNoInfo")
    public ServerResponse getDeviceChanNoInfo(@RequestParam String deviceSerial) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/camera/list";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "查询设备是否支持萤石协议")
    @ApiImplicitParams({
            @ApiImplicitParam(name="model",value = "设备型号",required = true),
            @ApiImplicitParam(name="version",value = "设备版本号",required = true)
    })
    @GetMapping("isSupportEZVIZ")
    public ServerResponse isSupportEZVIZ(@RequestParam String model,@RequestParam String version) {

        String url = YinShiServiceConfig.HostUrl + "lapp/device/support/ezviz";
        Map<String, Object> map = new HashMap<>();
        map.put("appKey", YinShiServiceConfig.appKey);
        map.put("model", model);
        map.put("version",version);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "根据设备序列号查询设备能力集")
    @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
    @GetMapping("getDeviceCapacity")
    public ServerResponse getDeviceCapacity(@RequestParam String deviceSerial) {

        System.out.println(YinShiServiceConfig.AccessToken);
        String url = YinShiServiceConfig.HostUrl + "lapp/device/capacity";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);

        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }

    @ApiOperation(value = "根据时间获取存储文件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true),
            @ApiImplicitParam(name="channelNo",value = "通道号,非必选,默认为1",dataType = "Integer"),
            @ApiImplicitParam(name= "startTime",value = "起始时间,时间格式为:1558950045000。非必选,默认为当天0点",dataType = "Integer",format = "int64",defaultValue = "0"),
            @ApiImplicitParam(name= "endTime",value = "结束时间,时间格式为:1558950045000。非必选,默认为当前时间",dataType = "Integer",format = "int64",defaultValue = "0"),
            @ApiImplicitParam(name = "recType",value = "回放源,0-系统自动选择,1-云存储,2-本地录像。非必选,默认为0")
    })
    @GetMapping("getVideoFileByTime")
    public ServerResponse getVideoFileByTime(@RequestParam String deviceSerial, @RequestParam(defaultValue = "1") Integer channelNo, @RequestParam(defaultValue = "0") Long startTime,@RequestParam(defaultValue = "0") Long endTime,@RequestParam(defaultValue = "0") Integer recType) {

        String url = YinShiServiceConfig.HostUrl + "lapp/video/by/time";
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", YinShiServiceConfig.AccessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("channelNo",channelNo);

        if(startTime > 0) {
            map.put("startTime", startTime);
        }
        if(endTime > 0 ){
            map.put("endTime",endTime);
        }

        map.put("recType",recType);
        String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
        YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);

        JSONArray jsonStr = (JSONArray)yinShiResResult.getData();

        if(jsonStr!=null&&jsonStr.size()>0){
            Page page = new Page();
            page.setTotal(jsonStr.size());
            yinShiResResult.setPage(page);
        }
        return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
    }
}