Quellcode durchsuchen

Update AutoEquipmentPassengerPeople.java

jtoms vor 4 Jahren
Ursprung
Commit
e2ebc1bfad

+ 50 - 43
src/main/java/com/zhiqiyun/open/core/schedule/AutoEquipmentPassengerPeople.java

@@ -15,6 +15,7 @@ import com.zhiqiyun.open.utils.RandomUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.BoundListOperations;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -25,58 +26,64 @@ import java.util.List;
 @Slf4j
 @Component
 public class AutoEquipmentPassengerPeople {
-	@Autowired
-	private EquipmentPassengerService equipmentPassengerService;
+    @Autowired
+    private EquipmentPassengerService equipmentPassengerService;
 
-	@Autowired
-	private EquipmentPassengerPeopleService equipmentPassengerPeopleService;
+    @Autowired
+    private EquipmentPassengerPeopleService equipmentPassengerPeopleService;
 
-	@Autowired
-	private DictCityService dictCityService;
+    @Autowired
+    private DictCityService dictCityService;
 
-	@Autowired
-	private SequenceService sequenceService;
+    @Autowired
+    private SequenceService sequenceService;
 
-	@Autowired
-	private StringRedisTemplate stringRedisTemplate;
+    @Autowired
+    private StringRedisTemplate stringRedisTemplate;
 
-	@Scheduled(cron = "0/10 * * * * ?")
-	public void createPeople() {
-		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) {
+    @Value("${spring.profiles.active}")
+    private String active;
 
-			int r1 = RandomUtil.getInt(0, listDictCity.size() - 1);
-			int r2 = r1 % 2 + 1;
-			PassengerType type = PassengerType.valueOf(r2);
+    @Scheduled(cron = "0/10 * * * * ?")
+    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) {
 
-			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));
+            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());
 
+            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);
-			}
-		}
-	}
+
+            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);
+            }
+        }
+    }
 }