| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.haikang.model.HKConstants; |
| | | import com.doumee.core.haikang.model.param.BaseResponse; |
| | | import com.doumee.core.haikang.model.param.request.*; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.haikang.model.param.request.CustomBroadcastRequest; |
| | | import com.doumee.core.haikang.model.param.request.TransparentChannelSingleRequest; |
| | | import com.doumee.core.haikang.service.HKService; |
| | | import com.doumee.core.utils.HttpsUtil; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.service.business.third.model.LoginUserInfo; |
| | | import com.doumee.service.business.third.model.PageData; |
| | | import com.doumee.service.business.third.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.DeviceMapper; |
| | | import com.doumee.dao.business.PlatformBroadcastLogMapper; |
| | | import com.doumee.dao.business.model.Device; |
| | | import com.doumee.dao.business.model.PlatformBroadcastLog; |
| | | import com.doumee.service.business.DeviceService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.service.business.impl.hksync.HkSyncPushServiceImpl; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 设备信息表Service实现 |
| | |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class DeviceServiceImpl implements DeviceService { |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | @Autowired |
| | | private PlatformMapper platformMapper; |
| | | @Autowired |
| | | private PlatformDeviceMapper platformDeviceMapper; |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | |
| | | |
| | | |
| | | @Override |
| | | public Integer create(Device device) { |
| | | deviceMapper.insert(device); |
| | | return device.getId(); |
| | | public Integer create(Device model) { |
| | | model.setCreator(model.getLoginUserInfo().getId()+""); |
| | | model.setEdirot(model.getCreator()); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setEditDate(new Date()); |
| | | model.setCreateDate(model.getEditDate()); |
| | | deviceMapper.insert(model); |
| | | return model.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | deviceMapper.deleteById(id); |
| | | public void deleteById(Integer id, LoginUserInfo userInfo) { |
| | | Device update = new Device(); |
| | | update.setEdirot(userInfo.getId()+""); |
| | | update.setEditDate(new Date()); |
| | | update.setIsdeleted(Constants.ONE); |
| | | update.setId(id); |
| | | deviceMapper.updateById(update); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByIdInBatch(List<Integer> ids) { |
| | | public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo userInfo) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | deviceMapper.deleteBatchIds(ids); |
| | | for(Integer id :ids){ |
| | | deleteById(id,userInfo); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateById(Device device) { |
| | | device.setEdirot(device.getLoginUserInfo().getId()+""); |
| | | device.setEditDate(new Date()); |
| | | deviceMapper.updateById(device); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void setBroadcaseBobao(Device model){ |
| | | List<String> ids = new ArrayList<>(); |
| | | ids.add(model.getHkId()); |
| | | CustomBroadcastRequest request = new CustomBroadcastRequest(); |
| | | request.setAudioPointIndexCode(ids); |
| | | request.setPlayDuration(15);//单位秒 |
| | | request.setBroadCastMode("tts"); |
| | | request.setPriority(1); |
| | | request.setState(1);//播放/停止标识 1-播放,0-停止 |
| | | request.setPlayTtsContent(model.getSendInfo()); |
| | | BaseResponse response = HKService.customBroadcast(request); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"发送失败:"+ JSONObject.toJSONString(response)); |
| | | } |
| | | } |
| | | @Override |
| | | public String setBroadcaseBobaoHttp(Device param){ |
| | | /* Device model = deviceMapper.selectById(param.getId()); |
| | | if(model ==null && Constants.equalsInteger(param.getType(),Constants.FOUR)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | String input = ""; |
| | | JSONObject objext = new JSONObject(); |
| | | |
| | | //重新下发计划 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //第一层 |
| | | JSONArray firstJsonArray = new JSONArray(); |
| | | JSONObject downJson = new JSONObject(); |
| | | downJson.put("terminalID",1); |
| | | //不填默认对所有通道下发 |
| | | JSONArray audioJsonArray = new JSONArray(); |
| | | audioJsonArray.add(1); |
| | | downJson.put("audioOutID",audioJsonArray); |
| | | firstJsonArray.add(downJson); |
| | | jsonObject.put("TerminalInfoList",firstJsonArray); |
| | | //第一层数组 |
| | | JSONArray allJsonArray = new JSONArray(); |
| | | //数组中对象 |
| | | for (WaterTimingBroadcastDO waterTimingBroadcastDO : searchList) { |
| | | JSONObject downArrayData = new JSONObject(); |
| | | downArrayData.put("audioOutID",audioJsonArray); |
| | | downArrayData.put("enabled",true); |
| | | downArrayData.put("planSchemeID",waterTimingBroadcastDO.getName()); |
| | | JSONObject executeJson = new JSONObject(); |
| | | executeJson.put("startTime", getDateStringByZones(waterTimingBroadcastDO.getStartDate())); |
| | | executeJson.put("stopTime",getDateStringByZones(waterTimingBroadcastDO.getEndDate())); |
| | | if (Constant.ONE.equals(waterTimingBroadcastDO.getPeriodType())){ |
| | | //日计划 |
| | | JSONArray executeJsonArray = new JSONArray(); |
| | | JSONObject executeJsonDataItem = new JSONObject(); |
| | | executeJsonDataItem.put("beginTime",waterTimingBroadcastDO.getStartTime()+"+08:00"); |
| | | executeJsonDataItem.put("endTime",waterTimingBroadcastDO.getEndTime()+"+08:00"); |
| | | executeJsonDataItem.put("playMode","loop"); |
| | | executeJsonDataItem.put("playNowTime",""); |
| | | executeJsonDataItem.put("planSchemeExecID",0); |
| | | JSONObject secondDownOperationJson = new JSONObject(); |
| | | if (Constant.ONE.equals(waterTimingBroadcastDO.getContentType())){ |
| | | //文本 |
| | | secondDownOperationJson.put("audioSource","speechSynthesis"); |
| | | secondDownOperationJson.put("speechSynthesisContent",waterTimingBroadcastDO.getContent()); |
| | | }else if (Constant.TWO.equals(waterTimingBroadcastDO.getContentType())){ |
| | | //音频 |
| | | secondDownOperationJson.put("audioSource","customAudio"); |
| | | String json = waterTimingBroadcastDO.getJson(); |
| | | JSONObject jsonData = JSONObject.parseObject(json); |
| | | List<Integer> hkAudioIds = new ArrayList<>(); |
| | | hkAudioIds.add(jsonData.getIntValue(waterDeviceDO.getIp())); |
| | | secondDownOperationJson.put("customAudioID",hkAudioIds); |
| | | } |
| | | secondDownOperationJson.put("audioLevel",5); |
| | | //语言类型 |
| | | secondDownOperationJson.put("TTSLanguageType","chinese"); |
| | | secondDownOperationJson.put("voiceType","female"); |
| | | secondDownOperationJson.put("audioVolume",100); |
| | | executeJsonDataItem.put("Operation",secondDownOperationJson); |
| | | executeJsonArray.add(executeJsonDataItem); |
| | | executeJson.put("dailyScheduleList",executeJsonArray); |
| | | }else { |
| | | //周计划 |
| | | JSONArray executeJsonArray = new JSONArray(); |
| | | List<String> executeTime = new ArrayList<>(); |
| | | if (Constant.ONE.equals(waterTimingBroadcastDO.getPeriodType())){ |
| | | //日计划 循环一次 |
| | | executeTime.add("1"); |
| | | }else if (Constant.TWO.equals(waterTimingBroadcastDO.getPeriodType())){ |
| | | //周计划多一个周几 |
| | | executeTime = Arrays.asList(waterTimingBroadcastDO.getExecuteTime().split(",")); |
| | | } |
| | | for (String s : executeTime) { |
| | | JSONObject executeJsonData = new JSONObject(); |
| | | if (Constant.TWO.equals(waterTimingBroadcastDO.getPeriodType())){ |
| | | //周计划多一个周几 |
| | | executeJsonData.put("dayOfWeek",Integer.parseInt(s)); |
| | | } |
| | | JSONArray executeJsonDataArray = new JSONArray(); |
| | | JSONObject executeJsonDataItem = new JSONObject(); |
| | | executeJsonDataItem.put("beginTime",waterTimingBroadcastDO.getStartTime()+"+08:00"); |
| | | executeJsonDataItem.put("endTime",waterTimingBroadcastDO.getEndTime()+"+08:00"); |
| | | executeJsonDataItem.put("playMode","loop"); |
| | | executeJsonDataItem.put("playNowTime",""); |
| | | executeJsonDataItem.put("planSchemeExecID",0); |
| | | JSONObject secondDownOperationJson = new JSONObject(); |
| | | if (Constant.ONE.equals(waterTimingBroadcastDO.getContentType())){ |
| | | //文本 |
| | | secondDownOperationJson.put("audioSource","speechSynthesis"); |
| | | secondDownOperationJson.put("speechSynthesisContent",waterTimingBroadcastDO.getContent()); |
| | | }else if (Constant.TWO.equals(waterTimingBroadcastDO.getContentType())){ |
| | | //音频 |
| | | secondDownOperationJson.put("audioSource","customAudio"); |
| | | String json = waterTimingBroadcastDO.getJson(); |
| | | JSONObject jsonData = JSONObject.parseObject(json); |
| | | List<Integer> hkAudioIds = new ArrayList<>(); |
| | | hkAudioIds.add(jsonData.getIntValue(waterDeviceDO.getIp())); |
| | | secondDownOperationJson.put("customAudioID",hkAudioIds); |
| | | } |
| | | secondDownOperationJson.put("audioLevel",5); |
| | | //语言类型 |
| | | secondDownOperationJson.put("TTSLanguageType","chinese"); |
| | | secondDownOperationJson.put("voiceType","female"); |
| | | secondDownOperationJson.put("audioVolume",10); |
| | | executeJsonDataItem.put("Operation",secondDownOperationJson); |
| | | executeJsonDataArray.add(executeJsonDataItem); |
| | | executeJsonData.put("scheduleList",executeJsonDataArray); |
| | | executeJsonArray.add(executeJsonData); |
| | | |
| | | } |
| | | executeJson.put("weeklyScheduleList",executeJsonArray); |
| | | } |
| | | |
| | | if (Constant.ONE.equals(waterTimingBroadcastDO.getPeriodType())){ |
| | | //日计划 |
| | | downArrayData.put("dailyScheduleInfo",executeJson); |
| | | }else { |
| | | //周计划 |
| | | downArrayData.put("weklyScheduleInfo",executeJson); |
| | | } |
| | | allJsonArray.add(downArrayData); |
| | | } |
| | | jsonObject.put("broadcastPlanSchemeList",allJsonArray); |
| | | log.info("海康播放计划下发入参内容 : " + jsonObject); |
| | | |
| | | String result = HttpsUtil.doPostHk(param.getIp(),Integer.parseInt(StringUtils.defaultString(param.getPort(),"80")) |
| | | ,"/ISAPI/VideoIntercom/broadcast/AddPlanScheme?format=json",param.getDoorId(), param.getDoorName(),jsonObject.toJSONString()); |
| | | return result;*/ |
| | | return null; |
| | | } |
| | | @Override |
| | | public void setLedContent(TransparentChannelSingleRequest model) { |
| | | Device device = findById(model.getDeviceId()); |
| | | if(device == null |
| | |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,屏幕内容设置失败"+(log!=null?log.getHkInfo():"")); |
| | | } |
| | | } |
| | | @Override |
| | | public void allLedDefualtContent() { |
| | | log.error( "屏幕内容设置=======================开始========" ); |
| | | int speed = 13; |
| | | try { |
| | | speed = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.LED_CONTENT_SPEED).getCode()); |
| | | }catch (Exception e){ |
| | | } |
| | | //所有月台关联设备信息 |
| | | List<PlatformDevice> list = platformDeviceMapper.selectList(new MPJLambdaWrapper<PlatformDevice>(). |
| | | selectAll(PlatformDevice.class) |
| | | .selectAs(Platform::getLedContent,PlatformDevice::getLedContent) |
| | | .leftJoin(Platform.class,Platform::getId,PlatformDevice::getPlatformId) |
| | | .eq(PlatformDevice::getType,Constants.ZERO) |
| | | .eq(PlatformDevice::getIsdeleted,Constants.ZERO) |
| | | .eq(Platform::getIsdeleted,Constants.ZERO) |
| | | ); |
| | | if(list==null || list.size()==0){ |
| | | return; |
| | | } |
| | | for(PlatformDevice device :list){ |
| | | try { |
| | | String content = device.getLedContent(); |
| | | if(StringUtils.isBlank(content)){ |
| | | continue; |
| | | } |
| | | PlatformBroadcastLog log1 = HkSyncPushServiceImpl.dealLedContentBiz(0,device.getHkNo(),device.getName(),content,speed,1); |
| | | platformBroadcastLogMapper.insert(log1); |
| | | if(log1.getHkStatus() == null || !Constants.equalsInteger(log1.getHkStatus(), Constants.TWO)){ |
| | | log.error( "对不起,屏幕内容设置失败"+(log1!=null?log1.getHkInfo():"")); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error( "对不起,屏幕内容设置异常"+ device.getName()); |
| | | } |
| | | |
| | | } |
| | | log.error( "屏幕内容设置=======================结束========" ); |
| | | } |
| | | } |