Commit eeceab63 by 向延琳

定时关闭

1 parent b74971b6
......@@ -32,17 +32,24 @@ public class DeviceFreqController implements DeviceFreqClient {
return R.ok();
}
@PostMapping(value = "/activeDeviceFreq")
@PostMapping(value = "/active")
@Override
public R<Void> activeDeviceFreq(ActiveAdjFreqBO activeAdjFreqBO) {
deviceFreqService.activeDeviceFreq(activeAdjFreqBO);
return R.ok();
}
@PostMapping(value = "/closeDeviceFreq")
@PostMapping(value = "/close")
@Override
public R<Void> toCloseDeviceFreq() {
deviceFreqService.toCloseDeviceFreq();
public R<Void> closeDeviceFreq() {
deviceFreqService.closeDeviceFreqFromCache();
return R.ok();
}
@PostMapping(value = "/closeFromDB")
@Override
public R<Void> closeDeviceFreqFromDB() {
deviceFreqService.closeDeviceFreqFromDB();
return R.ok();
}
}
......@@ -5,6 +5,8 @@ import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface DeviceFreqMapper extends CommonBaseMapper<DeviceFreq> {
......@@ -14,4 +16,10 @@ public interface DeviceFreqMapper extends CommonBaseMapper<DeviceFreq> {
* @return 生效的调频记录
*/
DeviceFreq selectEffectFreqBySn(@Param("sn") String sn);
/**
* 获取待关闭的调频记录
* @return 生效的调频记录
*/
List<String> listToCloseFreq();
}
\ No newline at end of file
......@@ -25,6 +25,7 @@ import org.springframework.util.CollectionUtils;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -160,13 +161,27 @@ public class DeviceFreqService {
/**
* 关闭到期的调频
*/
public void toCloseDeviceFreq() {
public void closeDeviceFreqFromCache() {
Collection<String> snList = redisDelayQueue.getAndRemoveBusinessNo(TASK_KEY_FREQ_TIMING_CLOSE);
if (CollectionUtils.isEmpty(snList)) {
log.info(DateUtil.getNowDateTimeFormat() + "没有需要福关闭的调频");
return;
}
log.info(DateUtil.getNowDateTimeFormat() + "需要福关闭的调频数量:" + snList.size());
log.info(DateUtil.getNowDateTimeFormat() + "需要关闭的调频数量:" + snList.size());
snList.forEach(sn -> this.resetAdjFreq(new ResetAdjFreqBO(sn, 1L)));
}
/**
* 关闭到期的调频
*/
public void closeDeviceFreqFromDB() {
List<String> snList = deviceFreqMapper.listToCloseFreq();
if (CollectionUtils.isEmpty(snList)) {
log.info(DateUtil.getNowDateTimeFormat() + "没有需要福关闭的调频");
return;
}
log.info(DateUtil.getNowDateTimeFormat() + "需要关闭的调频数量:" + snList.size());
snList.forEach(sn -> this.resetAdjFreq(new ResetAdjFreqBO(sn, 1L)));
}
......
......@@ -30,8 +30,8 @@
<!--
WARNING - @mbg.generated
-->
id, vehicle_id, sn, freq_type, `status`, battery_level, channel, catching_timer,
timer, week, week_timer, support_freq, user_type, response_status, duration, del_flag,
id, vehicle_id, sn, freq_type, `status`, battery_level, channel, catching_timer,
timer, week, week_timer, support_freq, user_type, response_status, duration, del_flag,
created_date, created_by, updated_date, updated_by
</sql>
......@@ -46,4 +46,17 @@
</where>
limit 1
</select>
<select id="listToCloseFreq" resultType="java.lang.String">
select sn
from t_device_freq
<where>
and status=1
and del_flag = 0
and duration is not null
and duration != -1
and now() <![CDATA[ >= ]]> adddate(created_date, interval duration minute)
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -31,7 +31,7 @@ public class DeviceFreqServiceTest {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
deviceFreqService.toCloseDeviceFreq();
deviceFreqService.closeDeviceFreqFromCache();
}
@Test
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!