|
|
@@ -1,5 +1,6 @@
|
|
|
package com.template.scheduled;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -9,7 +10,9 @@ import com.template.common.utils.TimeExchange;
|
|
|
import com.template.common.utils.TimeExchange2;
|
|
|
import com.template.config.MySecurity;
|
|
|
import com.template.mapper.BookingMapper;
|
|
|
+import com.template.mapper.ParkingMapper;
|
|
|
import com.template.mapper.SmsCodeMapper;
|
|
|
+import com.template.mapper.ToiletBaseMapper;
|
|
|
import com.template.model.pojo.SmsCode;
|
|
|
import com.template.model.pojo.SystemUser;
|
|
|
import com.template.model.result.CommonResult;
|
|
|
@@ -19,11 +22,15 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -51,6 +58,15 @@ public class ScheduledService {
|
|
|
private BookingMapper bookingMapper;
|
|
|
|
|
|
@Autowired
|
|
|
+ private ParkingMapper parkingMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ToiletBaseMapper toiletBaseMapper;
|
|
|
+
|
|
|
+ @Value("${diseaseRightUrl}")
|
|
|
+ String url;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
MySecurity mySecurity;
|
|
|
|
|
|
private static final int MAX_JSON_STRING = 40;
|
|
|
@@ -63,7 +79,7 @@ public class ScheduledService {
|
|
|
return CommonResult.ok();
|
|
|
}
|
|
|
|
|
|
- //定时生成民宿定单假数据
|
|
|
+ //定时生成民宿定单假数据 每天1点
|
|
|
@Scheduled(cron="0 0 1 * * ? ")
|
|
|
public void createBooking() {
|
|
|
|
|
|
@@ -114,5 +130,43 @@ public class ScheduledService {
|
|
|
logger.info("定单生成结束,当前时间"+TimeExchange.getTime());
|
|
|
}
|
|
|
|
|
|
+ //定时保存停车场实时数据 每小时一次
|
|
|
+ @Scheduled(cron="0 1 * * * ? ")
|
|
|
+ public void getParkingInfoScheduled() {
|
|
|
+ SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH");
|
|
|
+ String dayId=sp.format(new Date());
|
|
|
+ int a= parkingMapper.getTrendByTime(dayId);
|
|
|
+ logger.info("停车场实时数据同步结束,当前账期"+dayId+" 更新了"+a+"条数据");
|
|
|
+ }
|
|
|
|
|
|
+ //定时保存停车场实时数据 每天23:58一次
|
|
|
+ @Scheduled(cron="0 58 23 * * ? ")
|
|
|
+ public void getToiletBaseScheduled() throws Exception {
|
|
|
+ RestTemplate client = new RestTemplate();
|
|
|
+ SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dayId=sp.format(new Date());
|
|
|
+ List<Map<String, String>> toiletBaseInfo = toiletBaseMapper.getToiletBaseInfo();
|
|
|
+ int intoNum=0;
|
|
|
+ if(!toiletBaseInfo.isEmpty()){
|
|
|
+ for (Map<String, String> infoMap:toiletBaseInfo) {
|
|
|
+ String id=String.valueOf(infoMap.get("id"));
|
|
|
+ ResponseEntity<String> responseEntity = client.getForEntity(url+id, String.class);
|
|
|
+ String body = responseEntity.getBody();
|
|
|
+ if (!responseEntity.getStatusCode().is2xxSuccessful()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ("false".equals(JSONObject.parseObject(body).getString("success"))) {
|
|
|
+ throw new Exception("请求实时数据异常:"+JSONObject.parseObject(body).getString("message"));
|
|
|
+ }
|
|
|
+ JSONObject jsonObject=JSONObject.parseObject(body).getJSONObject("data");
|
|
|
+ //入流量
|
|
|
+ int dataOfMan=jsonObject.getJSONObject("dataOfMan").getInteger("intoNum");
|
|
|
+ int dataOfWoman=jsonObject.getJSONObject("dataOfWoman").getInteger("intoNum");
|
|
|
+ int dataOfThird=jsonObject.getJSONObject("dataOfThird").getInteger("intoNum");
|
|
|
+ intoNum=intoNum+dataOfMan+dataOfWoman+dataOfThird;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int a=toiletBaseMapper.insertToiletBaseInfoHis(dayId,String.valueOf(intoNum));
|
|
|
+ logger.info("实时数据同步结束,当前账期"+dayId+" 更新了"+a+"条数据");
|
|
|
+ }
|
|
|
}
|