2025-07-17 15:26:39 +08:00
|
|
|
package com.gunshi.project.hsz.controller;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
2024-08-15 17:27:27 +08:00
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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;
|
2024-08-15 17:27:27 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
2024-07-17 17:38:06 +08:00
|
|
|
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;
|
2025-07-17 15:26:39 +08:00
|
|
|
import com.gunshi.project.hsz.entity.so.AttCctvBasePage;
|
|
|
|
|
import com.gunshi.project.hsz.entity.vo.CctvControlVo;
|
|
|
|
|
import com.gunshi.project.hsz.model.AttCctvBase;
|
|
|
|
|
import com.gunshi.project.hsz.model.CctvBMenu;
|
|
|
|
|
import com.gunshi.project.hsz.service.AttCctvBaseService;
|
|
|
|
|
import com.gunshi.project.hsz.service.CctvBMenuService;
|
|
|
|
|
import com.gunshi.project.hsz.util.OkHttpUtil;
|
2025-11-04 16:14:38 +08:00
|
|
|
import com.gunshi.project.hsz.common.validate.markers.Insert;
|
|
|
|
|
import com.gunshi.project.hsz.common.validate.markers.Update;
|
2024-07-08 17:47:02 +08:00
|
|
|
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-08-20 13:59:43 +08:00
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
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-08-20 13:59:43 +08:00
|
|
|
import java.util.stream.Collectors;
|
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;
|
|
|
|
|
|
2024-08-20 13:59:43 +08:00
|
|
|
@Autowired
|
|
|
|
|
private CctvBMenuService menuService;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
|
|
|
|
@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-08-20 13:59:43 +08:00
|
|
|
if (StringUtils.isNotBlank(dto.getName()) && service.lambdaQuery().eq(AttCctvBase::getName,dto.getName())
|
|
|
|
|
.count() > 0){
|
|
|
|
|
throw new IllegalArgumentException("当前名称已存在");
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(dto.getMenuId()) && menuService.lambdaQuery().eq(CctvBMenu::getId,dto.getMenuId())
|
|
|
|
|
.count() == 0
|
|
|
|
|
){
|
|
|
|
|
throw new IllegalArgumentException("当前视频点目录不存在");
|
|
|
|
|
}
|
|
|
|
|
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-08-20 13:59:43 +08:00
|
|
|
|
2024-07-30 17:52:25 +08:00
|
|
|
if (Objects.isNull(service.getById(dto.getId()))){
|
|
|
|
|
throw new RuntimeException("当前数据不存在");
|
|
|
|
|
}
|
2024-08-20 13:59:43 +08:00
|
|
|
if (StringUtils.isNotBlank(dto.getName()) && service.lambdaQuery().eq(AttCctvBase::getName,dto.getName())
|
|
|
|
|
.ne(AttCctvBase::getId,dto.getId())
|
|
|
|
|
.count() > 0){
|
|
|
|
|
throw new IllegalArgumentException("当前名称已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(dto.getMenuId()) && menuService.lambdaQuery().eq(CctvBMenu::getId,dto.getMenuId())
|
|
|
|
|
.count() == 0
|
|
|
|
|
){
|
|
|
|
|
throw new IllegalArgumentException("当前视频点目录不存在");
|
|
|
|
|
}
|
|
|
|
|
dto.setCreateTime(null);
|
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() {
|
2025-11-04 10:05:15 +08:00
|
|
|
List<AttCctvBase> res = service.queryList();
|
|
|
|
|
return R.ok(res);
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "分页")
|
|
|
|
|
@PostMapping("/page")
|
2024-07-17 17:38:06 +08:00
|
|
|
public R<Page<AttCctvBase>> page(@RequestBody @Validated AttCctvBasePage page) {
|
2024-08-15 17:27:27 +08:00
|
|
|
LambdaQueryWrapper<AttCctvBase> query = Wrappers.lambdaQuery();
|
|
|
|
|
|
2024-07-17 17:38:06 +08:00
|
|
|
if (ObjectUtils.isNotNull(page.getCode())) {
|
|
|
|
|
query.like(AttCctvBase::getIndexCode, page.getCode());
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getMenuId())) {
|
2024-08-20 14:42:54 +08:00
|
|
|
query.eq(AttCctvBase::getMenuId, page.getMenuId());
|
2024-07-17 17:38:06 +08:00
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getName())) {
|
|
|
|
|
query.like(AttCctvBase::getName, page.getName());
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getType())) {
|
|
|
|
|
query.eq(AttCctvBase::getType, Integer.valueOf(page.getType()));
|
|
|
|
|
}
|
2024-08-20 13:59:43 +08:00
|
|
|
query.orderByDesc(AttCctvBase::getCreateTime);
|
|
|
|
|
Page<AttCctvBase> basePage = service.page(page.getPageSo().toPage(), query);
|
|
|
|
|
List<AttCctvBase> records = basePage.getRecords();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(records)){
|
|
|
|
|
List<CctvBMenu> list = menuService.list();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)){
|
|
|
|
|
Map<Long, List<String>> listMap = list.stream().
|
|
|
|
|
collect(Collectors.groupingBy(CctvBMenu::getId, Collectors.mapping(CctvBMenu::getName, Collectors.toList())));
|
|
|
|
|
|
|
|
|
|
records.forEach(item -> {
|
|
|
|
|
if (Objects.nonNull(item.getMenuId())){
|
|
|
|
|
item.setMenuName(listMap.get(item.getMenuId()).getFirst());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
basePage.setRecords(records);
|
|
|
|
|
}
|
|
|
|
|
return R.ok(basePage);
|
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();
|
2024-08-01 13:10:00 +08:00
|
|
|
ret = resp.body().string();
|
2024-07-29 13:23:23 +08:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
return R.ok(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|