2024-07-08 17:47:02 +08:00
|
|
|
package com.gunshi.project.xyt.controller;
|
|
|
|
|
|
2024-07-30 17:52:25 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
2024-07-17 17:38:06 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
2024-07-23 09:48:51 +08:00
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2024-07-08 17:47:02 +08:00
|
|
|
import com.gunshi.core.result.R;
|
2024-07-17 17:38:06 +08:00
|
|
|
import com.gunshi.project.xyt.entity.so.AttCctvBasePage;
|
2024-07-29 13:23:23 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.CctvControlVo;
|
2024-07-08 17:47:02 +08:00
|
|
|
import com.gunshi.project.xyt.model.AttCctvBase;
|
|
|
|
|
import com.gunshi.project.xyt.service.AttCctvBaseService;
|
2024-07-23 09:48:51 +08:00
|
|
|
import com.gunshi.project.xyt.util.OkHttpUtil;
|
2024-07-08 17:47:02 +08:00
|
|
|
import com.gunshi.project.xyt.validate.markers.Insert;
|
|
|
|
|
import com.gunshi.project.xyt.validate.markers.Update;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2024-07-23 09:48:51 +08:00
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
|
import okhttp3.Request;
|
|
|
|
|
import okhttp3.Response;
|
2024-07-08 17:47:02 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
2024-07-23 09:48:51 +08:00
|
|
|
import java.io.IOException;
|
2024-07-08 17:47:02 +08:00
|
|
|
import java.io.Serializable;
|
2024-07-30 17:52:25 +08:00
|
|
|
import java.util.Date;
|
2024-07-08 17:47:02 +08:00
|
|
|
import java.util.List;
|
2024-07-23 09:48:51 +08:00
|
|
|
import java.util.Map;
|
2024-07-30 17:52:25 +08:00
|
|
|
import java.util.Objects;
|
2024-07-23 09:48:51 +08:00
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
/**
|
|
|
|
|
* 描述: 视频基本信息表
|
|
|
|
|
* author: xusan
|
|
|
|
|
* date: 2024-07-08 17:40:37
|
|
|
|
|
*/
|
|
|
|
|
@Tag(name = "视频基本信息表")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping(value="/attCctvBase")
|
|
|
|
|
public class AttCctvBaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AttCctvBaseService service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "新增")
|
|
|
|
|
@PostMapping("/insert")
|
|
|
|
|
public R<AttCctvBase> insert(@Validated(Insert.class) @RequestBody AttCctvBase dto) {
|
2024-07-30 17:52:25 +08:00
|
|
|
dto.setId(IdWorker.getId());
|
|
|
|
|
dto.setCreateTime(new Date());
|
2024-07-08 17:47:02 +08:00
|
|
|
boolean result = service.save(dto);
|
|
|
|
|
return R.ok(result ? dto : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "修改")
|
|
|
|
|
@PostMapping("/update")
|
|
|
|
|
public R<AttCctvBase> update(@Validated(Update.class) @RequestBody AttCctvBase dto) {
|
2024-07-30 17:52:25 +08:00
|
|
|
if (Objects.isNull(service.getById(dto.getId()))){
|
|
|
|
|
throw new RuntimeException("当前数据不存在");
|
|
|
|
|
}
|
2024-07-08 17:47:02 +08:00
|
|
|
boolean result = service.updateById(dto);
|
|
|
|
|
return R.ok(result ? dto : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除")
|
|
|
|
|
@GetMapping("/del/{id}")
|
|
|
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
2024-07-30 17:52:25 +08:00
|
|
|
if (Objects.isNull(service.getById(id))){
|
|
|
|
|
throw new RuntimeException("当前数据不存在");
|
|
|
|
|
}
|
2024-07-08 17:47:02 +08:00
|
|
|
return R.ok(service.removeById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "列表")
|
|
|
|
|
@PostMapping("/list")
|
|
|
|
|
public R<List<AttCctvBase>> list() {
|
|
|
|
|
return R.ok(service.lambdaQuery().list());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "分页")
|
|
|
|
|
@PostMapping("/page")
|
2024-07-17 17:38:06 +08:00
|
|
|
public R<Page<AttCctvBase>> page(@RequestBody @Validated AttCctvBasePage page) {
|
|
|
|
|
LambdaQueryChainWrapper<AttCctvBase> query = service.lambdaQuery();
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getCode())) {
|
|
|
|
|
query.like(AttCctvBase::getIndexCode, page.getCode());
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getMenuId())) {
|
|
|
|
|
query.like(AttCctvBase::getMenuId, page.getMenuId());
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getName())) {
|
|
|
|
|
query.like(AttCctvBase::getName, page.getName());
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getType())) {
|
|
|
|
|
query.eq(AttCctvBase::getType, Integer.valueOf(page.getType()));
|
|
|
|
|
}
|
|
|
|
|
return R.ok(service.page(page.getPageSo().toPage(), query));
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 09:48:51 +08:00
|
|
|
@Operation(summary = "获取预览地址")
|
|
|
|
|
@GetMapping("/preview/{indexCode}")
|
|
|
|
|
public R<String> preview(@PathVariable("indexCode") String indexCode) {
|
|
|
|
|
String api = "http://223.75.53.141:81/isc/liveAddressLimited?cameraIndexCode=%s&protocol=ws&token=111";
|
|
|
|
|
OkHttpClient client = OkHttpUtil.build();
|
|
|
|
|
String ret = null;
|
|
|
|
|
try {
|
|
|
|
|
Response resp = client.newCall(new Request.Builder().url(String.format(api, indexCode)).build()).execute();
|
|
|
|
|
String respStr = resp.body().string();
|
|
|
|
|
ObjectMapper om = new ObjectMapper();
|
|
|
|
|
Map map = om.readValue(respStr, Map.class);
|
|
|
|
|
ret = map.get("data").toString();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
return R.ok(ret);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-29 13:23:23 +08:00
|
|
|
@Operation(summary = "云台控制")
|
|
|
|
|
@PostMapping("/control")
|
|
|
|
|
public R<String> control(@RequestBody CctvControlVo vo) {
|
|
|
|
|
String indexCode = vo.getIndexCode();
|
|
|
|
|
Integer action = vo.getAction();
|
|
|
|
|
Integer speed = vo.getSpeed();
|
|
|
|
|
String command = vo.getCommand();
|
|
|
|
|
String api = "http://223.75.53.141:81/isc/controlling?cameraIndexCode="+indexCode+"&action="+action+"&speed="+speed+"&command="+command+"&token=111";
|
|
|
|
|
OkHttpClient client = OkHttpUtil.build();
|
|
|
|
|
String ret = null;
|
|
|
|
|
try {
|
|
|
|
|
Response resp = client.newCall(new Request.Builder().url(api).build()).execute();
|
|
|
|
|
String respStr = resp.body().string();
|
|
|
|
|
ObjectMapper om = new ObjectMapper();
|
|
|
|
|
Map map = om.readValue(respStr, Map.class);
|
|
|
|
|
ret = map.get("data").toString();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
return R.ok(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|