|  | @@ -1,25 +1,36 @@
 | 
	
		
			
				|  |  |  package com.aidex.system.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +import cn.hutool.core.date.DateField;
 | 
	
		
			
				|  |  | +import cn.hutool.core.date.DateTime;
 | 
	
		
			
				|  |  | +import cn.hutool.core.date.DateUtil;
 | 
	
		
			
				|  |  | +import cn.hutool.core.util.IdUtil;
 | 
	
		
			
				|  |  | +import cn.hutool.http.HttpRequest;
 | 
	
		
			
				|  |  | +import com.aidex.common.core.domain.BaseEntity;
 | 
	
		
			
				|  |  | +import com.aidex.common.core.service.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.aidex.common.plush.domain.SysShipExtend;
 | 
	
		
			
				|  |  |  import com.aidex.common.plush.service.SysShipExtendService;
 | 
	
		
			
				|  |  | +import com.aidex.common.utils.SecurityUtils;
 | 
	
		
			
				|  |  |  import com.aidex.common.utils.StringUtils;
 | 
	
		
			
				|  |  | +import com.aidex.system.domain.SysShip;
 | 
	
		
			
				|  |  | +import com.aidex.system.domain.SysShipCamera;
 | 
	
		
			
				|  |  |  import com.aidex.system.domain.vo.ShipVo;
 | 
	
		
			
				|  |  | +import com.aidex.system.mapper.SysShipMapper;
 | 
	
		
			
				|  |  | +import com.aidex.system.service.SysShipService;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson2.JSON;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson2.JSONObject;
 | 
	
		
			
				|  |  | +import com.github.pagehelper.PageInfo;
 | 
	
		
			
				|  |  | +import org.slf4j.Logger;
 | 
	
		
			
				|  |  | +import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | -import org.slf4j.Logger;
 | 
	
		
			
				|  |  | -import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | -import com.github.pagehelper.PageInfo;
 | 
	
		
			
				|  |  | -import com.aidex.common.core.domain.BaseEntity;
 | 
	
		
			
				|  |  | -import com.aidex.common.core.service.BaseServiceImpl;
 | 
	
		
			
				|  |  | -import com.aidex.system.mapper.SysShipMapper;
 | 
	
		
			
				|  |  | -import com.aidex.system.domain.SysShip;
 | 
	
		
			
				|  |  | -import com.aidex.system.service.SysShipService;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.HashMap;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 船只管理Service业务层处理
 | 
	
		
			
				|  |  |   * @author ChenSir
 | 
	
	
		
			
				|  | @@ -35,6 +46,7 @@ public class SysShipServiceImpl extends BaseServiceImpl<SysShipMapper, SysShip>
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysShipExtendService sysShipExtendService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 获取单条数据
 | 
	
		
			
				|  |  |       * @param sysShip 船只管理
 | 
	
	
		
			
				|  | @@ -157,4 +169,60 @@ public class SysShipServiceImpl extends BaseServiceImpl<SysShipMapper, SysShip>
 | 
	
		
			
				|  |  |          return mapper.updateStatusByMacId(macId,status);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public int countSysShipByStatus() {
 | 
	
		
			
				|  |  | +		return mapper.countSysShipByStatus();
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +    @Transactional(readOnly = false)
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public int bindCamera(SysShipCamera sysShipCamera) {
 | 
	
		
			
				|  |  | +        List<SysShipCamera> shipCameraList = getShipCameraList(sysShipCamera.getShipId());
 | 
	
		
			
				|  |  | +        if (shipCameraList.size() >= 2) {
 | 
	
		
			
				|  |  | +            return 0;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return mapper.bindCamera(sysShipCamera);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    @Transactional(readOnly = false)
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public int unbindCamera(SysShipCamera sysShipCamera) {
 | 
	
		
			
				|  |  | +        return mapper.unbindCamera(sysShipCamera);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<SysShipCamera> getShipCameraList(String shipId) {
 | 
	
		
			
				|  |  | +        return mapper.getShipCameraList(shipId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public String getShipSurplusSeat(String shipId, int duration) {
 | 
	
		
			
				|  |  | +        // 获取船只关联的摄像头
 | 
	
		
			
				|  |  | +        List<SysShipCamera> shipCameraList = getShipCameraList(shipId);
 | 
	
		
			
				|  |  | +        if (shipCameraList.size() > 0){
 | 
	
		
			
				|  |  | +            String redisKey = IdUtil.fastSimpleUUID();
 | 
	
		
			
				|  |  | +            DateTime offset = DateUtil.offset(new Date(), DateField.SECOND, duration);
 | 
	
		
			
				|  |  | +            String corn = DateUtil.format(offset, "ss mm HH dd MM ? yyyy");
 | 
	
		
			
				|  |  | +            log.info("生成corn 表达式为---{}", corn);
 | 
	
		
			
				|  |  | +            // 构造带参定时任务
 | 
	
		
			
				|  |  | +            Map<String, String> params = new HashMap<>();
 | 
	
		
			
				|  |  | +            params.put("jobName", "定时获取船只剩余座位");
 | 
	
		
			
				|  |  | +            params.put("jobGroup", "DEFAULT");
 | 
	
		
			
				|  |  | +            params.put("invokeTarget", "cameraTask.getShipSurplusSeat('"+shipId+"','"+DateUtil.now()+"','"+redisKey+"')");
 | 
	
		
			
				|  |  | +            params.put("cronExpression",corn);
 | 
	
		
			
				|  |  | +            params.put("misfirePolicy","2");
 | 
	
		
			
				|  |  | +            params.put("concurrent","0");
 | 
	
		
			
				|  |  | +            params.put("status","0");
 | 
	
		
			
				|  |  | +            //链式构建请求
 | 
	
		
			
				|  |  | +            String result = HttpRequest.post("http://127.0.0.1:18080/monitor/job")
 | 
	
		
			
				|  |  | +                    .header("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjRiZjE4ZDQwLWQ1ZjEtNDk1Ny1hNjA0LTQwZDM2YzIxMWVlMiJ9.zxyPe8oKTYah13AfqzeJebXENGAzJdhd0BJPddSuqVkjk8pRB1Bxf6dSJfEUI9kgjRg9yfSrsjyq439cJBSSBg")
 | 
	
		
			
				|  |  | +                    .body(JSON.toJSONString(params))//表单内容
 | 
	
		
			
				|  |  | +                    .timeout(10000)//超时,毫秒
 | 
	
		
			
				|  |  | +                    .execute().body();
 | 
	
		
			
				|  |  | +            JSONObject resultJson = JSONObject.parseObject(result);
 | 
	
		
			
				|  |  | +            if (resultJson.containsKey("code") && resultJson.get("code").equals(200)){
 | 
	
		
			
				|  |  | +                return redisKey;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +        return null;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |