stjdydayou 4 lat temu
rodzic
commit
d686975669

+ 90 - 77
src/main/java/com/zhiqiyun/open/core/schedule/AutoEquipmentPassengerPeople.java

@@ -28,81 +28,94 @@ import java.util.List;
 @Slf4j
 @Component
 public class AutoEquipmentPassengerPeople {
-    @Autowired
-    private EquipmentPassengerService equipmentPassengerService;
-
-    @Autowired
-    private EquipmentPassengerPeopleService equipmentPassengerPeopleService;
-
-    @Autowired
-    private DictCityService dictCityService;
-
-    @Autowired
-    private SequenceService sequenceService;
-
-    @Autowired
-    private StringRedisTemplate stringRedisTemplate;
-
-    @Value("${spring.profiles.active}")
-    private String active;
-
-    @Scheduled(cron = "0/20 * * * * ?")
-    public void createPeople() {
-        if ("dev".equals(active)) {
-            return;
-        }
-        QueryWrapper<DictCity> wrapper = new QueryWrapper<>();
-        wrapper.eq("parent_id", "0");
-        List<DictCity> listDictCity = this.dictCityService.list(wrapper);
-        List<EquipmentPassenger> listData = this.equipmentPassengerService.list();
-        for (EquipmentPassenger equipment : listData) {
-
-            int r1 = RandomUtil.getInt(0, listDictCity.size() - 1);
-            int r2 = r1 % 2 + 1;
-            PassengerType type = PassengerType.valueOf(r2);
-
-            EquipmentPassengerPeople people = new EquipmentPassengerPeople();
-            people.setId(this.sequenceService.nextId());
-            people.setPlaceBaseInfoId(equipment.getPlaceBaseInfoId());
-            people.setEquipmentId(equipment.getId());
-            people.setPassengerType(type);
-            people.setCreatedTime(DateUtil.current());
-            people.setGender(Gender.valueOf(r2));
-
-
-            people.setFromSource(listDictCity.get(r1).getFullName());
-
-
-            String redisKey = String.format("equipment%s", equipment.getId());
-            BoundListOperations<String, String> boundListOps = this.stringRedisTemplate.boundListOps(redisKey);
-            String faceId;
-            if (PassengerType.IN.equals(type)) {
-                faceId = RandomUtil.getuuid();
-                boundListOps.leftPush(faceId);
-            } else {
-                faceId = boundListOps.rightPop();
-            }
-            if (StringUtils.isNotBlank(faceId)) {
-                people.setFaceId(faceId);
-                this.equipmentPassengerPeopleService.save(people);
-            }
-        }
-    }
-
-    @Scheduled(cron = "0/10 * * * * ?")
-    public void deletePeople() {
-        QueryWrapper<EquipmentPassengerPeople> wrapper = new QueryWrapper<>();
-        wrapper.lt("created_time", DateUtils.addDays(DateUtil.current(), -15));
-
-        int current = 1;
-        boolean hasNext = true;
-        while (hasNext) {
-            Page<EquipmentPassengerPeople> page = this.equipmentPassengerPeopleService.page(new Page<>(current, 100), wrapper);
-
-            for (EquipmentPassengerPeople people : page.getRecords()) {
-                this.equipmentPassengerPeopleService.removeById(people.getId());
-            }
-            hasNext = page.hasNext();
-        }
-    }
+	@Autowired
+	private EquipmentPassengerService equipmentPassengerService;
+
+	@Autowired
+	private EquipmentPassengerPeopleService equipmentPassengerPeopleService;
+
+	@Autowired
+	private DictCityService dictCityService;
+
+	@Autowired
+	private SequenceService sequenceService;
+
+	@Autowired
+	private StringRedisTemplate stringRedisTemplate;
+
+	@Value("${spring.profiles.active}")
+	private String active;
+
+	@Scheduled(cron = "0/20 * * * * ?")
+	public void createPeople() {
+		if ("dev".equals(active)) {
+			return;
+		}
+		QueryWrapper<DictCity> wrapper = new QueryWrapper<>();
+		wrapper.eq("parent_id", "0");
+		List<DictCity> listDictCity = this.dictCityService.list(wrapper);
+		List<EquipmentPassenger> listData = this.equipmentPassengerService.list();
+		for (EquipmentPassenger equipment : listData) {
+
+			int r1 = RandomUtil.getInt(0, listDictCity.size() - 1);
+			int r2 = r1 % 2 + 1;
+			PassengerType type = PassengerType.valueOf(r2);
+
+			EquipmentPassengerPeople people = new EquipmentPassengerPeople();
+			people.setId(this.sequenceService.nextId());
+			people.setPlaceBaseInfoId(equipment.getPlaceBaseInfoId());
+			people.setEquipmentId(equipment.getId());
+			people.setPassengerType(type);
+			people.setCreatedTime(DateUtil.current());
+			people.setGender(Gender.valueOf(r2));
+
+
+			people.setFromSource(listDictCity.get(r1).getFullName());
+
+
+			String redisKey = String.format("equipment%s", equipment.getId());
+			BoundListOperations<String, String> boundListOps = this.stringRedisTemplate.boundListOps(redisKey);
+			String faceId;
+			if (PassengerType.IN.equals(type)) {
+				faceId = RandomUtil.getuuid();
+				boundListOps.leftPush(faceId);
+			} else {
+				faceId = boundListOps.rightPop();
+			}
+			if (StringUtils.isNotBlank(faceId)) {
+				people.setFaceId(faceId);
+				this.equipmentPassengerPeopleService.save(people);
+			}
+		}
+	}
+
+	@Scheduled(cron = "0/10 * * * * ?")
+	public void deletePeople() {
+		QueryWrapper<EquipmentPassengerPeople> wrapper = new QueryWrapper<>();
+		wrapper.lt("created_time", DateUtils.addDays(DateUtil.current(), -15));
+
+		int current = 1;
+		boolean hasNext = true;
+		while (hasNext) {
+			Page<EquipmentPassengerPeople> page = this.equipmentPassengerPeopleService.page(new Page<>(current, 100), wrapper);
+			log.info("deletePeople size>>>>{}", page.getTotal());
+
+			for (EquipmentPassengerPeople people : page.getRecords()) {
+				this.equipmentPassengerPeopleService.removeById(people.getId());
+			}
+			hasNext = page.hasNext();
+		}
+	}
+
+	@Scheduled(cron = "0/10 * * * * ?")
+	public void deletePeopleByFaceId() {
+		QueryWrapper<EquipmentPassengerPeople> wrapper = new QueryWrapper<>();
+		wrapper.inSql("face_id", "select face_id from equipment_passenger_people GROUP BY face_id HAVING count(face_id) = 1");
+
+		List<EquipmentPassengerPeople> list = this.equipmentPassengerPeopleService.list(wrapper);
+		log.info("deletePeopleByFaceId size>>>>{}", list.size());
+		for (EquipmentPassengerPeople people : list) {
+			this.equipmentPassengerPeopleService.removeById(people.getId());
+		}
+	}
 }