Parcourir la source

剩余座位数

ChenSir il y a 1 an
Parent
commit
3f44fc18f0

+ 7 - 6
aidex-controller/src/main/java/com/aidex/web/controller/app/AppController.java

@@ -16,6 +16,7 @@ import com.aidex.common.plush.domain.vo.SysShipExtendListResVO;
 import com.aidex.common.plush.domain.vo.SysShipExtendListVO;
 import com.aidex.common.plush.domain.vo.SysShipExtendVO;
 import com.aidex.common.plush.domain.vo.SysShipResVO;
+import com.aidex.common.utils.DateUtils;
 import com.aidex.common.utils.json.JSONObject;
 import com.aidex.common.utils.uuid.IdUtils;
 import com.aidex.quartz.task.RefreshAccessTokenTask;
@@ -253,15 +254,15 @@ public class AppController {
         if (null != extend) {
             logger.info("webhook消息推送,消息----extend-count--{}", extend.containsKey("count"));
             if (extend.containsKey("count")) {
-                ArrayList<Integer> alarm_count = (ArrayList<Integer>) extend.get("count");
+                ArrayList<Object> alarm_count = (ArrayList<Object>) extend.get("count");
                 logger.info("webhook消息推送,消息----extend-alarm_count--{}", alarm_count);
                 if (alarm_count.size() > 0){
                     logger.info("webhook消息推送,告警人数----人数---{}", alarm_count.get(0));
                     logger.info("webhook消息推送,请求头----时间戳---{}", message.getTimestamp());
                     logger.info("webhook消息推送,请求头----设备号---{}", message.getDevice_sn());
-                    /*String dateTime = DateUtil.s(DateUtil.timeToSecond(message.getTimestamp()));
-                    logger.info("webhook消息推送,请求头----时间戳转换---{}", dateTime);*/
-                    int row = iAppService.insertCameraAlarm(new SysCameraAlarm(IdUtils.fastSimpleUUID(), DateUtil.date(), message.getDevice_sn(), Integer.valueOf(alarm_count.get(0))));
+                    DateTime date = DateUtil.date(Long.valueOf(message.getTimestamp()) * 1000);
+                    logger.info("webhook消息推送,请求头----时间戳转换---{}", date);
+                    int row = iAppService.insertCameraAlarm(new SysCameraAlarm(IdUtils.fastSimpleUUID(), date, message.getDevice_sn(), String.valueOf(alarm_count.get(0))));
                     return R.status(row);
                 }
             }
@@ -270,12 +271,12 @@ public class AppController {
     }
 
 
-    /*@GetMapping("/test")
+    @GetMapping("/test")
     @ApiOperation(value = "获取信息类型", notes = "获取信息类型", produces = "application/json")
     public R test()
     {
         sysShipService.getShipSurplusSeat("261836442bbb48659d40f716feaa470d", 300);
         return R.status(true);
-    }*/
+    }
 
 }

+ 1 - 1
aidex-framework/src/main/java/com/aidex/framework/config/SecurityConfig.java

@@ -131,7 +131,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 发送短信 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage", "/sendSms").permitAll()
+                .antMatchers("/login", "/register", "/captchaImage", "/sendSms", "/monitor/job", "/monitor/job/**").permitAll()
                 .antMatchers(
                         HttpMethod.GET,
                         "/",

+ 17 - 4
aidex-quartz/src/main/java/com/aidex/quartz/controller/SysJobController.java

@@ -5,6 +5,7 @@ import com.aidex.common.constant.Constants;
 import com.aidex.common.core.controller.BaseController;
 import com.aidex.common.core.domain.AjaxResult;
 import com.aidex.common.core.domain.R;
+import com.aidex.common.core.domain.model.LoginUser;
 import com.aidex.common.core.page.TableDataInfo;
 import com.aidex.common.enums.BusinessType;
 import com.aidex.common.exception.job.TaskException;
@@ -69,9 +70,17 @@ public class SysJobController extends BaseController
     }
 
     /**
+     * 获取定时任务详细信息
+     */
+    @GetMapping(value = "/byName/{name}")
+    public AjaxResult getInfoByName(@PathVariable("name") String name)
+    {
+        return AjaxResult.success(jobService.selectJobByName(name));
+    }
+
+    /**
      * 新增定时任务
      */
-    @PreAuthorize("@ss.hasPermi('monitor:job:add')")
     @Log(title = "定时任务", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException
@@ -100,7 +109,12 @@ public class SysJobController extends BaseController
         {
             return error("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
         }
-        job.setCreateBy(getUsername());
+        LoginUser loginUser =  getLoginUser();
+        if (loginUser.getUser() == null) {
+            job.setCreateBy("system-default-camera");
+        } else {
+            job.setCreateBy(loginUser.getUser().getUserName());
+        }
         return toAjax(jobService.insertJob(job));
     }
 
@@ -143,7 +157,6 @@ public class SysJobController extends BaseController
     /**
      * 定时任务状态修改
      */
-    @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
     @Log(title = "定时任务", businessType = BusinessType.UPDATE)
     @PutMapping("/changeStatus")
     public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException
@@ -176,4 +189,4 @@ public class SysJobController extends BaseController
         jobService.deleteJobByIds(jobIds);
         return success();
     }
-}
+}

+ 16 - 8
aidex-quartz/src/main/java/com/aidex/quartz/mapper/SysJobMapper.java

@@ -5,14 +5,14 @@ import com.aidex.quartz.domain.SysJob;
 
 /**
  * 调度任务信息 数据层
- * 
+ *
  * @author ruoyi
  */
 public interface SysJobMapper
 {
     /**
      * 查询调度任务日志集合
-     * 
+     *
      * @param job 调度信息
      * @return 操作日志集合
      */
@@ -20,22 +20,30 @@ public interface SysJobMapper
 
     /**
      * 查询所有调度任务
-     * 
+     *
      * @return 调度任务列表
      */
     public List<SysJob> selectJobAll();
 
     /**
      * 通过调度ID查询调度任务信息
-     * 
+     *
      * @param jobId 调度ID
      * @return 角色对象信息
      */
     public SysJob selectJobById(Long jobId);
 
     /**
+     * 通过调度Name查询调度任务信息
+     *
+     * @param jobName 调度任务名称
+     * @return 角色对象信息
+     */
+    public SysJob selectJobByName(String jobName);
+
+    /**
      * 通过调度ID删除调度任务信息
-     * 
+     *
      * @param jobId 调度ID
      * @return 结果
      */
@@ -43,7 +51,7 @@ public interface SysJobMapper
 
     /**
      * 批量删除调度任务信息
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */
@@ -51,7 +59,7 @@ public interface SysJobMapper
 
     /**
      * 修改调度任务信息
-     * 
+     *
      * @param job 调度任务信息
      * @return 结果
      */
@@ -59,7 +67,7 @@ public interface SysJobMapper
 
     /**
      * 新增调度任务信息
-     * 
+     *
      * @param job 调度任务信息
      * @return 结果
      */

+ 20 - 12
aidex-quartz/src/main/java/com/aidex/quartz/service/ISysJobService.java

@@ -7,14 +7,14 @@ import com.aidex.quartz.domain.SysJob;
 
 /**
  * 定时任务调度信息信息 服务层
- * 
+ *
  * @author ruoyi
  */
 public interface ISysJobService
 {
     /**
      * 获取quartz调度器的计划任务
-     * 
+     *
      * @param job 调度信息
      * @return 调度任务集合
      */
@@ -22,15 +22,23 @@ public interface ISysJobService
 
     /**
      * 通过调度任务ID查询调度信息
-     * 
+     *
      * @param jobId 调度任务ID
      * @return 调度任务对象信息
      */
     public SysJob selectJobById(Long jobId);
 
     /**
+     * 通过调度任务Name查询调度信息
+     *
+     * @param jobName 调度任务名称
+     * @return 调度任务对象信息
+     */
+    public SysJob selectJobByName(String jobName);
+
+    /**
      * 暂停任务
-     * 
+     *
      * @param job 调度信息
      * @return 结果
      */
@@ -38,7 +46,7 @@ public interface ISysJobService
 
     /**
      * 恢复任务
-     * 
+     *
      * @param job 调度信息
      * @return 结果
      */
@@ -46,7 +54,7 @@ public interface ISysJobService
 
     /**
      * 删除任务后,所对应的trigger也将被删除
-     * 
+     *
      * @param job 调度信息
      * @return 结果
      */
@@ -54,7 +62,7 @@ public interface ISysJobService
 
     /**
      * 批量删除调度信息
-     * 
+     *
      * @param jobIds 需要删除的任务ID
      * @return 结果
      */
@@ -62,7 +70,7 @@ public interface ISysJobService
 
     /**
      * 任务调度状态修改
-     * 
+     *
      * @param job 调度信息
      * @return 结果
      */
@@ -70,7 +78,7 @@ public interface ISysJobService
 
     /**
      * 立即运行任务
-     * 
+     *
      * @param job 调度信息
      * @return 结果
      */
@@ -78,7 +86,7 @@ public interface ISysJobService
 
     /**
      * 新增任务
-     * 
+     *
      * @param job 调度信息
      * @return 结果
      */
@@ -86,7 +94,7 @@ public interface ISysJobService
 
     /**
      * 更新任务
-     * 
+     *
      * @param job 调度信息
      * @return 结果
      */
@@ -94,7 +102,7 @@ public interface ISysJobService
 
     /**
      * 校验cron表达式是否有效
-     * 
+     *
      * @param cronExpression 表达式
      * @return 结果
      */

+ 5 - 0
aidex-quartz/src/main/java/com/aidex/quartz/service/impl/SysJobServiceImpl.java

@@ -71,6 +71,11 @@ public class SysJobServiceImpl implements ISysJobService
         return jobMapper.selectJobById(jobId);
     }
 
+    @Override
+    public SysJob selectJobByName(String jobName) {
+        return jobMapper.selectJobByName(jobName);
+    }
+
     /**
      * 暂停任务
      *

+ 18 - 0
aidex-quartz/src/main/java/com/aidex/quartz/task/SystemRemoveLogTask.java

@@ -43,4 +43,22 @@ public class SystemRemoveLogTask
         }
         return message;
     }
+
+    /**
+     * 清除定时任务
+     * @return
+     */
+    public void removeJob(){
+        String message;
+        try{
+            Long startTime = System.currentTimeMillis();
+            operLogService.deleteCameraJob();
+            Long endTime = System.currentTimeMillis();
+            message = "清除定时任务成功耗时:("+(endTime-startTime)+")";
+            System.out.println(message);
+        }catch (Exception e){
+            message = e.getLocalizedMessage();
+            System.out.println(message);
+        }
+    }
 }

+ 0 - 1
aidex-quartz/src/main/java/com/aidex/quartz/task/cameraTask.java

@@ -45,7 +45,6 @@ public class cameraTask
             redisCache.setCacheObject(redisKey, (int)surplus, 5, TimeUnit.MINUTES);
             logger.info("执行摄像头剩余座位数定时任务----------结束,船只--{},剩余座位数---{}", sysShip.getShipNanme(), surplus);
         }
-
     }
 
 

+ 16 - 11
aidex-quartz/src/main/resources/mapper/quartz/SysJobMapper.xml

@@ -19,12 +19,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="updateTime"     column="update_time"     />
 		<result property="remark"         column="remark"          />
 	</resultMap>
-	
+
 	<sql id="selectJobVo">
-        select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark 
+        select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark
 		from sys_job
     </sql>
-	
+
 	<select id="selectJobList" parameterType="SysJob" resultMap="SysJobResult">
 		<include refid="selectJobVo"/>
 		<where>
@@ -42,27 +42,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			</if>
 		</where>
 	</select>
-	
+
 	<select id="selectJobAll" resultMap="SysJobResult">
 		<include refid="selectJobVo"/>
 	</select>
-	
+
 	<select id="selectJobById" parameterType="Long" resultMap="SysJobResult">
 		<include refid="selectJobVo"/>
 		where job_id = #{jobId}
 	</select>
-	
+
+	<select id="selectJobByName" parameterType="String" resultMap="SysJobResult">
+		<include refid="selectJobVo"/>
+		where job_name = #{jobName}
+	</select>
+
 	<delete id="deleteJobById" parameterType="Long">
  		delete from sys_job where job_id = #{jobId}
  	</delete>
- 	
+
  	<delete id="deleteJobByIds" parameterType="Long">
  		delete from sys_job where job_id in
  		<foreach collection="array" item="jobId" open="(" separator="," close=")">
  			#{jobId}
-        </foreach> 
+        </foreach>
  	</delete>
- 	
+
  	<update id="updateJob" parameterType="SysJob">
  		update sys_job
  		<set>
@@ -79,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  		</set>
  		where job_id = #{jobId}
 	</update>
- 	
+
  	<insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId">
  		insert into sys_job(
  			<if test="jobId != null and jobId != 0">job_id,</if>
@@ -108,4 +113,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  		)
 	</insert>
 
-</mapper> 
+</mapper>

+ 1 - 1
aidex-system/src/main/java/com/aidex/system/domain/SysCameraAlarm.java

@@ -29,7 +29,7 @@ public class SysCameraAlarm {
 	private String deviceSn;
 
 	@ApiModelProperty(value = "当前报警人数")
-	private int personNum;
+	private String personNum;
 
 
 }

+ 3 - 0
aidex-system/src/main/java/com/aidex/system/mapper/SysOperLogMapper.java

@@ -31,4 +31,7 @@ public interface SysOperLogMapper extends BaseMapper<SysOperLog>
     public int addOperlog(SysOperLog sysOperLog);
 
     public int deleteOperLogBySaveDay(@Param("saveDay") String saveDay );
+
+
+    public int deleteCameraJob();
 }

+ 5 - 1
aidex-system/src/main/java/com/aidex/system/mapper/SysOperLogMapper.xml

@@ -35,7 +35,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		order by a.oper_time desc
 	</sql>
 
-	<select id="get" resultType="SysOperLog">
+    <delete id="deleteCameraJob">
+		delete  from sys_job where create_by = 'system-default-camera'
+	</delete>
+
+    <select id="get" resultType="SysOperLog">
 		SELECT
 		<include refid="sysOperLogColumns"/>
 		FROM sys_oper_log a

+ 6 - 0
aidex-system/src/main/java/com/aidex/system/service/SysOperLogService.java

@@ -34,4 +34,10 @@ public interface SysOperLogService extends BaseService<SysOperLog>
      */
     public int deleteOperLogBySaveDay(String saveDay);
 
+    /**
+     * 清除摄像头余座定时任务日志
+     * @return
+     */
+    public int deleteCameraJob();
+
 }

+ 5 - 0
aidex-system/src/main/java/com/aidex/system/service/impl/SysOperLogServiceImpl.java

@@ -60,4 +60,9 @@ public class SysOperLogServiceImpl extends BaseServiceImpl<SysOperLogMapper, Sys
     {
         return mapper.deleteOperLogBySaveDay(saveDay);
     }
+    @Transactional(readOnly = false)
+	@Override
+	public int deleteCameraJob() {
+		return mapper.deleteCameraJob();
+	}
 }

+ 1 - 1
aidex-system/src/main/java/com/aidex/system/service/impl/SysReservationConfigServiceImpl.java

@@ -140,7 +140,7 @@ public class SysReservationConfigServiceImpl extends BaseServiceImpl<SysReservat
             Date endDate = sysReservationConfigReq.getEndDate();
             long days = DateUtil.between(startDate,endDate, DateUnit.DAY);
             if(days > 0){
-                for(int i = 0; i < days; i++){
+                for(int i = 0; i <= days; i++){
                     DateTime date = DateUtil.offsetDay(startDate, i);
                     DateTime dateTime = DateUtil.offsetDay(startDate, i);
                     String[] split = routeStart.split(":");

+ 17 - 2
aidex-system/src/main/java/com/aidex/system/service/impl/SysShipServiceImpl.java

@@ -203,8 +203,9 @@ public class SysShipServiceImpl extends BaseServiceImpl<SysShipMapper, SysShip>
             String corn = DateUtil.format(offset, "ss mm HH dd MM ? yyyy");
             log.info("生成corn 表达式为---{}", corn);
             // 构造带参定时任务
+            String name = "定时获取船只剩余座位-" + redisKey;
             Map<String, String> params = new HashMap<>();
-            params.put("jobName", "定时获取船只剩余座位");
+            params.put("jobName",  name);
             params.put("jobGroup", "DEFAULT");
             params.put("invokeTarget", "cameraTask.getShipSurplusSeat('"+shipId+"','"+DateUtil.now()+"','"+redisKey+"')");
             params.put("cronExpression",corn);
@@ -213,12 +214,26 @@ public class SysShipServiceImpl extends BaseServiceImpl<SysShipMapper, SysShip>
             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)){
+                String job = HttpRequest.get("http://127.0.0.1:18080/monitor/job/byName/"+ name)
+                        .timeout(10000)//超时,毫秒
+                        .execute().body();
+                JSONObject jobJson = JSONObject.parseObject(job);
+                if (jobJson.containsKey("code") && jobJson.get("code").equals(200)){
+                    JSONObject jobData = jobJson.getJSONObject("data");
+                    jobData.put("status", "0");
+                    if (jobData.containsKey("jobId")){
+                        // 修改任务状态
+                        HttpRequest.put("http://127.0.0.1:18080/monitor/job/changeStatus")
+                                .body(JSON.toJSONString(jobData))//表单内容
+                                .timeout(10000)//超时,毫秒
+                                .execute();
+                    }
+                }
                 return redisKey;
             }
 		}