|  |  |  | 
|---|
|  |  |  | package com.doumee.cloud.admin; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.doumee.api.BaseController; | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.config.annotation.CloudRequiredPermission; | 
|---|
|  |  |  | import com.doumee.config.annotation.LoginNoRequired; | 
|---|
|  |  |  | import com.doumee.config.jwt.JwtProperties; | 
|---|
|  |  |  | import com.doumee.core.annotation.pr.PreventRepeat; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.BaseResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.request.*; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.request.event.acs.EventAcsRequest; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.request.event.parks.EventParkRequest; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.request.event.parks.EventPlatformRequest; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.request.event.visit.EventVisitIccmRequest; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.request.event.visit.EventVisitRequest; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.respose.PageRegionInfoResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.service.HKService; | 
|---|
|  |  |  | import com.doumee.core.model.ApiResponse; | 
|---|
|  |  |  | import com.doumee.core.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.dao.web.response.platformReport.CarmeraListVO; | 
|---|
|  |  |  | import com.doumee.service.business.third.BoardService; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.ApiResponse; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.DESUtil; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Device; | 
|---|
|  |  |  | import com.doumee.service.business.DeviceService; | 
|---|
|  |  |  | import com.doumee.service.business.impl.hksync.*; | 
|---|
|  |  |  | import com.doumee.service.business.impl.hksync.ferp.HkSyncOrgUserToHKServiceImpl; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParam; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParams; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import org.apache.shiro.authz.annotation.RequiresPermissions; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.BufferedReader; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author 江蹄蹄 | 
|---|
|  |  |  | * @date 2023/11/30 15:33 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Api(tags = "海康数据同步接口") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX+"/business/hksync") | 
|---|
|  |  |  | public class HkSyncCloudController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HkSyncDeviceServiceImpl hkSyncDeviceService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BoardService boardService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HkSyncParkServiceImpl hkSyncParkService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HkSyncPrivilegeServiceImpl hkSyncPrivilegeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HkSyncPushServiceImpl hkSyncPushService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HkSyncOrgUserToHKServiceImpl hkSyncOrgUserToHKService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HkSyncNoticeServiceImpl hkSyncNoticeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HkSyncLoginAuthServiceImpl hkSyncLoginAuthService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemDictDataBiz systemDictDataBiz; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceService deviceService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisTemplate<String,Object> redisTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private JwtProperties jwtProperties; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreventRepeat | 
|---|
|  |  |  | @ApiOperation("【海康】全量同步月台信息接口") | 
|---|
|  |  |  | 
|---|
|  |  |  | //同步广播 | 
|---|
|  |  |  | result = hkSyncDeviceService.syncHkBroadcast(param); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ApiResponse.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PreventRepeat | 
|---|
|  |  |  | @ApiOperation("【海康】保存海康用户绑定openid") | 
|---|
|  |  |  | @PostMapping("/saveHkUserOpenid") | 
|---|
|  |  |  | public ApiResponse syncHkUserOpenid( @RequestHeader(Constants.HEADER_USER_TOKEN) String token){ | 
|---|
|  |  |  | String result     = hkSyncOrgUserToHKService.syncHkUserOpenid(this.getLoginUser(token).getId()); | 
|---|
|  |  |  | return ApiResponse.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PreventRepeat | 
|---|
|  |  |  | @ApiOperation("【海康】清空海康用户绑定openid") | 
|---|
|  |  |  | @PostMapping("/delHkUserOpenid") | 
|---|
|  |  |  | @LoginNoRequired | 
|---|
|  |  |  | public ApiResponse delHkUserOpenid( @RequestBody UserOpenidSaveRequest param){ | 
|---|
|  |  |  | String result     = hkSyncOrgUserToHKService.delHkUserOpenid(param); | 
|---|
|  |  |  | return ApiResponse.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PreventRepeat | 
|---|
|  |  |  | 
|---|
|  |  |  | String result = hkSyncPushService.dealVisitEventIccm(param,response); | 
|---|
|  |  |  | return ApiResponse.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @ApiOperation("【海康】测试LED显示屏") | 
|---|
|  |  |  | @PostMapping("/testLed") | 
|---|
|  |  |  | @LoginNoRequired | 
|---|
|  |  |  | public ApiResponse<BaseResponse> testLed(@RequestBody TransparentChannelBodyRequest request, HttpServletResponse response) { | 
|---|
|  |  |  | TransparentChannelHeadRequest head = new TransparentChannelHeadRequest(); | 
|---|
|  |  |  | head.setAbility("cld");//固定值 | 
|---|
|  |  |  | head.setTreatyType("haixuan_led_net");//固定值 | 
|---|
|  |  |  | head.setDeviceIndexCode("6a5498e9df924befbb9530e467e5e809"); | 
|---|
|  |  |  | return ApiResponse.success(HKService.transparentchannel(head,request)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @ApiOperation("【海康】测试广播播报") | 
|---|
|  |  |  | @PostMapping("/testBroadcast") | 
|---|
|  |  |  | @LoginNoRequired | 
|---|
|  |  |  | public ApiResponse<BaseResponse> testBroadcast(@RequestBody CustomBroadcastRequest request, HttpServletResponse response) { | 
|---|
|  |  |  | return ApiResponse.success(  HKService.customBroadcast(request)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    @PreventRepeat | 
|---|
|  |  |  | @ApiOperation("【海康】停车场事件订阅推送对接处理接口") | 
|---|
|  |  |  | @PostMapping("/push/parks") | 
|---|
|  |  |  | 
|---|
|  |  |  | String result = hkSyncPushService.dealPlatformCarsEvent(param,response); | 
|---|
|  |  |  | return ApiResponse.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @ApiOperation("【海康test】月台车辆状态事件订阅推送对接处理接口") | 
|---|
|  |  |  | @PostMapping("/push/platform/carstatusTest") | 
|---|
|  |  |  | @LoginNoRequired | 
|---|
|  |  |  | public ApiResponse pushPlatformCarStatus(HttpServletRequest request, HttpServletResponse response ){ | 
|---|
|  |  |  | doPringParam(request,"【海康test】月台车辆状态事件订阅推送对接处理接口:\n"); | 
|---|
|  |  |  | return ApiResponse.success(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public   void doPringParam(HttpServletRequest request,String name) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | StringBuilder data =new StringBuilder(); | 
|---|
|  |  |  | String line; | 
|---|
|  |  |  | BufferedReader reader =request.getReader(); | 
|---|
|  |  |  | while(null !=(line = reader.readLine())) { | 
|---|
|  |  |  | data.append(line); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(StringUtils.isNotBlank( data.toString())){ | 
|---|
|  |  |  | log.info(name+"=================参数:"+ data.toString()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | log.info(name+"=================:参数为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info(name+"================= 参数异常:"+e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PreventRepeat | 
|---|
|  |  |  | @ApiOperation("【海康】取消订阅事件") | 
|---|
|  |  |  | @PostMapping("/cancelEventSub") | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "获取安防平台系统免密菜单调整地址" ) | 
|---|
|  |  |  | @GetMapping("/getHkMenuLink") | 
|---|
|  |  |  | @PostMapping("/getHkMenuLink/{type}") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "type",example = "0",value = "菜单类型", required = true), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public ApiResponse<String> getHkMenuLink(Integer type,@RequestHeader(Constants.HEADER_USER_TOKEN) String token){ | 
|---|
|  |  |  | public ApiResponse<String> getHkMenuLink(@PathVariable Integer type,@RequestHeader(Constants.HEADER_USER_TOKEN) String token){ | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = this.getLoginUser(token); | 
|---|
|  |  |  | String hkToken = DESUtil.generateTokenToHk(loginUserInfo.getUsername(),Integer.valueOf( | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_TOKEN_VALIDITY).getCode() | 
|---|
|  |  |  | ),redisTemplate); | 
|---|
|  |  |  | return ApiResponse.success( HKService.getMenuUrl(type,hkToken)); | 
|---|
|  |  |  | String url = (systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_HTTPS).getCode() + | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_HOST).getCode()) | 
|---|
|  |  |  | + HKService.getMenuUrl(type,hkToken); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if(redisTemplate!=null&& jwtProperties!=null){ | 
|---|
|  |  |  | loginUserInfo.setHkMenuToken(hkToken); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(Constants.REDIS_TOKEN_KEY+token, JSONObject.toJSONString(loginUserInfo),jwtProperties.getExpiration(), TimeUnit.MILLISECONDS); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ApiResponse.success( url); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取安防平台系统免密菜单配置" ) | 
|---|
|  |  |  | @GetMapping("/getHkMenuConfig") | 
|---|
|  |  |  | public ApiResponse<List<Integer>> getHkMenuConfig(@RequestHeader(Constants.HEADER_USER_TOKEN) String token){ | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = getLoginUser(token); | 
|---|
|  |  |  | List<Integer> menuConfigList = new ArrayList<>(); | 
|---|
|  |  |  | if(Objects.nonNull(loginUserInfo) && StringUtils.isNotBlank(loginUserInfo.getUsername())){ | 
|---|
|  |  |  | menuConfigList = hkSyncPlatformsService.getMenuConfig(loginUserInfo.getUsername()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ApiResponse.success(menuConfigList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation("【海康】代办消息数据集合对接处理接口") | 
|---|
|  |  |  | @PostMapping("/notice/getList") | 
|---|
|  |  |  | public ApiResponse getNoticeList( HttpServletResponse response,@RequestHeader(Constants.HEADER_USER_TOKEN) String token ){ | 
|---|
|  |  |  | String result = hkSyncNoticeService.syncHkNotices(this.getLoginUser(token).getUsername()); | 
|---|
|  |  |  | return ApiResponse.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation("【海康】获取全部监控区域树形结构") | 
|---|
|  |  |  | @PostMapping("/regionList") | 
|---|
|  |  |  | public ApiResponse<List<PageRegionInfoResponse> > getRegionList(HttpServletResponse response, @RequestHeader(Constants.HEADER_USER_TOKEN) String token ){ | 
|---|
|  |  |  | CarmeraListVO param  =new CarmeraListVO(); | 
|---|
|  |  |  | param.setWithCameras(0); | 
|---|
|  |  |  | List<PageRegionInfoResponse>  result = new ArrayList<>(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //            result = boardService.getRegionTree( param); | 
|---|
|  |  |  | //------TODO---------测试模拟数据----start----- | 
|---|
|  |  |  | for (int i = 0; i < 5; i++) { | 
|---|
|  |  |  | PageRegionInfoResponse t = new PageRegionInfoResponse(); | 
|---|
|  |  |  | t.setName("总区域_"+i); | 
|---|
|  |  |  | t.setIndexCode(i+"_code"); | 
|---|
|  |  |  | t.setChildList(new ArrayList<>()); | 
|---|
|  |  |  | for (int j = 0; j < 5; j++) { | 
|---|
|  |  |  | PageRegionInfoResponse t1 = new PageRegionInfoResponse(); | 
|---|
|  |  |  | t1.setName("子区域_"+i+"_"+j); | 
|---|
|  |  |  | t1.setIndexCode(i+"_"+j+"_ChildCode"); | 
|---|
|  |  |  | t1.setParentIndexCode(t.getIndexCode()); | 
|---|
|  |  |  | t.getChildList().add(t1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | result.add(t); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //------TODO---------测试模拟数据----end----- | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ApiResponse.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation("【海康】设置LED屏文案") | 
|---|
|  |  |  | @PostMapping("/setLedContent") | 
|---|
|  |  |  | public ApiResponse<List<Map<String,Object>>> setLedContent(@RequestBody TransparentChannelSingleRequest body  , HttpServletResponse response) { | 
|---|
|  |  |  | deviceService.setLedContent(body); | 
|---|
|  |  |  | return ApiResponse.success(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|