package cn.besteam.modules.medical.controller; import cn.besteam.common.api.vo.Result; import cn.besteam.common.aspect.annotation.AutoLog; import cn.besteam.common.aspect.annotation.OpenApi; import cn.besteam.common.constant.ErrorCode; import cn.besteam.common.exception.BusinessException; import cn.besteam.modules.medical.biz.MonitorDeviceApiNewService; import cn.besteam.modules.medical.dto.MwDeviceAgentDeviceDTO; import cn.besteam.modules.medical.dto.MwDeviceAgentDeviceSaveDTO; import cn.besteam.modules.medical.entity.MwDeviceAgent; import cn.besteam.modules.medical.entity.MwDeviceAgentDevice; import cn.besteam.modules.medical.service.IMwDeviceAgentDeviceService; import cn.besteam.modules.medical.service.IMwDeviceAgentService; import cn.besteam.modules.medical.vo.MwDeviceAgentDeviceAddBatchVO; import cn.besteam.modules.medical.vo.MwDeviceAgentDeviceExcelVO; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.*; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import java.io.IOException; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Arrays; import java.util.List; import java.util.Map; /** * @Title: Controller * @Description: 设备代理商-设备 * @author: besteam * @date: 2020-04-25 * @version: V1.0 */ @RestController @RequestMapping("/medical/mwDeviceAgentDevice") @Slf4j @Api(description = "设备代理商-设备") public class MwDeviceAgentDeviceController { @Autowired private IMwDeviceAgentService mwDeviceAgentService; @Autowired private IMwDeviceAgentDeviceService mwDeviceAgentDeviceService; /** * 视频设备 */ @Autowired private MonitorDeviceApiNewService monitorDeviceApiNewService; /** * 分页列表查询 * * @param name * @param pageNo * @param pageSize * @return */ @GetMapping(value = "/list") @ApiOperation(value = "获取设备代理商-设备数据列表", notes = "获取所有设备代理商-设备数据列表", produces = "application/json") public Result> queryPageList(String name, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { return Result.ok(mwDeviceAgentDeviceService.getDeviceList(name, pageNo, pageSize)); } @PostMapping("/addBatch") @ApiOperation(value = "批量添加设备", notes = "批量添加设备", produces = "application/json") public Result addBatch(@RequestBody MwDeviceAgentDeviceSaveDTO dto) { MwDeviceAgent mwDeviceAgent = mwDeviceAgentService.getById(dto.getDeviceAgentId()); if (mwDeviceAgent == null) { throw new BusinessException(ErrorCode.MW_DEVICE_AGENT_NOT_FOUND); } return Result.ok(mwDeviceAgentDeviceService.addBatch(dto.getDeviceAgentId(), dto.getSns())); } /** * 编辑 * * @param mwDeviceAgentDevice * @return */ @PostMapping(value = "/edit") @AutoLog(value = "编辑设备代理商-设备") @ApiOperation(value = "编辑设备代理商-设备", notes = "编辑设备代理商-设备", produces = "application/json") public Result edit(@RequestBody MwDeviceAgentDevice mwDeviceAgentDevice) { Result result = new Result(); MwDeviceAgentDevice mwDeviceAgentDeviceEntity = mwDeviceAgentDeviceService.getById(mwDeviceAgentDevice.getId()); if (mwDeviceAgentDeviceEntity == null) { result.error500("未找到对应实体"); } else { boolean ok = mwDeviceAgentDeviceService.updateById(mwDeviceAgentDeviceEntity); if (ok) { result.success("修改成功!"); } } return result; } /** * 通过id删除 * * @param dto * @return */ @PostMapping(value = "/delete") @AutoLog(value = "删除设备代理商-设备") @ApiOperation(value = "删除设备代理商-设备", notes = "删除设备代理商-设备", produces = "application/json") public Result delete(@RequestBody MwDeviceAgentDeviceDTO dto) { Result result = new Result(); MwDeviceAgentDevice mwDeviceAgentDevice = mwDeviceAgentDeviceService.getById(dto.getId()); if (mwDeviceAgentDevice == null) { result.error500("未找到对应实体"); } else { boolean ok = mwDeviceAgentDeviceService.removeById(dto.getId()); if (ok) { result.success("删除成功!"); } } return result; } /** * 批量删除 * * @param dto * @return */ @PostMapping(value = "/deleteBatch") @AutoLog(value = "批量删除设备代理商-设备") @ApiOperation(value = "批量删除设备代理商-设备", notes = "批量删除设备代理商-设备", produces = "application/json") public Result deleteBatch(@RequestBody MwDeviceAgentDeviceDTO dto) { Result result = new Result(); if (dto.getIds() == null || "".equals(dto.getIds().trim())) { result.error500("参数不识别!"); } else { this.mwDeviceAgentDeviceService.removeByIds(Arrays.asList(dto.getIds().split(","))); result.success("删除成功!"); } return result; } /** * 移动 * * @param dto * @return */ @PostMapping(value = "/move") @AutoLog(value = "移动设备代理商-设备") @ApiOperation(value = "移动设备代理商-设备", notes = "移动设备代理商-设备", produces = "application/json") public Result move(@RequestBody MwDeviceAgentDeviceDTO dto) { MwDeviceAgent mwDeviceAgent = mwDeviceAgentService.getById(dto.getDeviceAgentId()); if (mwDeviceAgent == null) { throw new BusinessException(ErrorCode.MW_DEVICE_AGENT_NOT_FOUND); } return Result.ok(mwDeviceAgentDeviceService.move(dto.getId(), dto.getDeviceAgentId())); } /** * 批量移动 * * @param dto * @return */ @PostMapping(value = "/moveBatch") @AutoLog(value = "批量移动设备代理商-设备") @ApiOperation(value = "批量移动设备代理商-设备", notes = "批量移动设备代理商-设备", produces = "application/json") public Result moveBatch(@RequestBody MwDeviceAgentDeviceDTO dto) { MwDeviceAgent mwDeviceAgent = mwDeviceAgentService.getById(dto.getDeviceAgentId()); if (mwDeviceAgent == null) { throw new BusinessException(ErrorCode.MW_DEVICE_AGENT_NOT_FOUND); } Result result = new Result(); if (dto.getIds() == null || "".equals(dto.getIds().trim()) || dto.getDeviceAgentId() == null) { result.error500("参数不识别!"); } else { this.mwDeviceAgentDeviceService.moveBatch(dto.getIds(), dto.getDeviceAgentId()); result.success("移动成功!"); } return result; } /** * 启用、禁用 * * @param dto * @return */ @PostMapping(value = "/updateStatus") @AutoLog(value = "启用、禁用设备代理商-设备") @ApiOperation(value = "启用、禁用设备代理商-设备", notes = "启用、禁用设备代理商-设备", produces = "application/json") public Result updateState(@RequestBody MwDeviceAgentDeviceDTO dto) { return Result.ok(mwDeviceAgentDeviceService.updateStatus(dto.getId(), dto.getStatus())); } /** * 批量启用、禁用 * * @param dto * @return */ @PostMapping(value = "/updateStatusBatch") @AutoLog(value = "批量启用、禁用设备代理商-设备") @ApiOperation(value = "批量启用、禁用设备代理商-设备", notes = "批量启用、禁用设备代理商-设备", produces = "application/json") public Result updateStatusBatch(@RequestBody MwDeviceAgentDeviceDTO dto) { Result result = new Result(); if (dto.getIds() == null || "".equals(dto.getIds().trim()) || dto.getStatus() == null) { result.error500("参数不识别!"); } else { this.mwDeviceAgentDeviceService.updateStatusBatch(dto.getIds(), dto.getStatus()); result.success("修改成功!"); } return result; } @OpenApi @GetMapping("/export") @ApiOperation(value = "导出", notes = "导出") public void export(HttpServletResponse response, Integer deviceAgentId) throws UnsupportedEncodingException { List list = mwDeviceAgentDeviceService.getDeviceExcelList(deviceAgentId); // ExcelWriter excelWriter = ExcelUtil.getWriter(true); excelWriter.renameSheet("硬件特征码导出"); excelWriter.setColumnWidth(0, 20); excelWriter.setColumnWidth(1, 20); excelWriter.setColumnWidth(2, 20); excelWriter.setColumnWidth(3, 20); excelWriter.addHeaderAlias("name", "厂商"); excelWriter.addHeaderAlias("sn", "特征码"); excelWriter.addHeaderAlias("statusStr", "状态"); excelWriter.addHeaderAlias("createTime", "创建时间"); excelWriter.write(list, true); // response.setContentType("application/octet-stream;charset=utf-8"); String fileName = "硬件特征码导出"; response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx"); // response.setHeader("Content-Disposition", "attachment;"); ServletOutputStream out = null; try { out = response.getOutputStream(); excelWriter.flush(out, true); } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } excelWriter.close(); } } @GetMapping("/getDeviceValidateStatus") @ApiOperation(value = "获取特征码校验开关", notes = "获取特征码校验开关") public Result getDeviceValidateStatus() { return Result.ok(mwDeviceAgentDeviceService.getDeviceValidateStatus()); } @PostMapping("/setDeviceValidateStatus") @ApiOperation(value = "设置特征码校验开关", notes = "设置特征码校验开关") public Result setDeviceValidateStatus(@RequestBody MwDeviceAgentDeviceValidateStatusDTO dto) { return Result.ok(mwDeviceAgentDeviceService.setDeviceValidateStatus(dto.getStatus())); } @Data @ApiModel private static class MwDeviceAgentDeviceValidateStatusDTO implements Serializable { @NotNull(message = "状态不能为空") @Min(value = 0, message = "状态区间[0,1]") @Max(value = 1, message = "状态区间[0,1]") @ApiModelProperty("1启动0禁用") private Integer status; } @GetMapping("/getToken") @ApiOperation(value = "获取视频服务器token", notes = "获取视频服务器token") public Result getToken() { return Result.ok(monitorDeviceApiNewService.getJSession(1)); } @GetMapping("/getDeviceList") @ApiOperation(value = "获取视频服务器设备列表", notes = "获取视频服务器设备列表") public Result> getDeviceList() { return Result.ok(monitorDeviceApiNewService.getDeviceList()); } @GetMapping("/getDeviceUrl") @ApiOperation(value = "获取视频服务器设备播放路径", notes = "获取视频服务器设备播放路径") public Result> getDeviceUrl(String id,Integer channelNum) { return Result.ok(monitorDeviceApiNewService.getDeviceUrl(id,channelNum)); } @GetMapping("/getChannelList") @ApiOperation(value = "查询设备通道列表(新)", notes = "查询设备通道列表(新)") @ApiImplicitParams({ @ApiImplicitParam(name = "serial", value = "设备编号", required = true, dataType = "String", format = "query") }) public Result>> getChannelList(String serial) { return Result.ok(monitorDeviceApiNewService.getChannelList(serial)); } @GetMapping("/getPlaybackRecordlist") @ApiOperation(value = "查询通道录像列表(新)", notes = "查询通道录像列表(新)") @ApiImplicitParams({ @ApiImplicitParam(name = "serial", value = "设备编号", required = true, dataType = "String", format = "query"), @ApiImplicitParam(name = "channel", value = "通道号", required = true, dataType = "Integer", format = "query"), @ApiImplicitParam(name = "starttime", value = "开始时间(格式:YYYY-MM-DDTHH:mm:ss 如:2023-04-25T08:00:00)", required = true, dataType = "String", format = "query"), @ApiImplicitParam(name = "endtime", value = "结束时间(格式:YYYY-MM-DDTHH:mm:ss 如:2023-04-25T08:00:00)", required = false, dataType = "String", format = "query") }) public Result>> getPlaybackRecordlist(String serial,Integer channel,String starttime,String endtime) { return Result.ok(monitorDeviceApiNewService.getPlaybackRecordlist(serial,channel,starttime,endtime)); } @GetMapping("/playbackStart") @ApiOperation(value = "开始回放(新)", notes = "开始回放(新)") @ApiImplicitParams({ @ApiImplicitParam(name = "serial", value = "设备编号", required = true, dataType = "String", format = "query"), @ApiImplicitParam(name = "channel", value = "通道号", required = true, dataType = "Integer", format = "query"), @ApiImplicitParam(name = "starttime", value = "开始时间(格式:YYYY-MM-DDTHH:mm:ss 如:2023-04-25T08:00:00)", required = true, dataType = "String", format = "query"), @ApiImplicitParam(name = "endtime", value = "结束时间(格式:YYYY-MM-DDTHH:mm:ss 如:2023-04-25T08:00:00)", required = false, dataType = "String", format = "query") }) public Result> playbackStart(String serial,Integer channel,String starttime,String endtime) { return Result.ok(monitorDeviceApiNewService.playbackStart(serial,channel,starttime,endtime)); } @GetMapping("/playbackStop") @ApiOperation(value = "回放流停止(新)", notes = "回放流停止(新)") @ApiImplicitParams({ @ApiImplicitParam(name = "streamID", value = "流ID", required = true, dataType = "String", format = "query") }) public Result> playbackStop(String streamID) { return Result.ok(monitorDeviceApiNewService.playbackStop(streamID)); } }