Commit 0ddfb056 by weiss

Merge remote-tracking branch 'origin/master'

2 parents 5e7fa5ba 4cc8c55f
......@@ -3,12 +3,16 @@ package com.pipihelper.project.feishu.service;
import cn.hutool.core.collection.CollectionUtil;
import com.pipihelper.project.feishu.dao.PainDao;
import com.pipihelper.project.feishu.entity.Pain;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
public class PainService {
......@@ -16,6 +20,14 @@ public class PainService {
@Autowired
private PainDao painDao;
private final static List<PindexFloor> pindexFloors = new ArrayList<>();
static {
pindexFloors.add(new PindexFloor().setStartIndex(1).setEndIndex(12).setTimeRange("15:00-16:00").setFloor(14));
pindexFloors.add(new PindexFloor().setStartIndex(13).setEndIndex(24).setTimeRange("16:00-17:00").setFloor(14));
pindexFloors.add(new PindexFloor().setStartIndex(25).setEndIndex(30).setTimeRange("17:00-17:30").setFloor(14));
}
public void create(Pain pain) {
painDao.create(pain);
}
......@@ -40,13 +52,22 @@ public class PainService {
return painDao.findAll();
}
public List<Pain> findAllReorderByFloor(int floor) {
List<Pain> painList = painDao.findAllByFloor(floor);
if (CollectionUtil.isEmpty(painList)) {
return new ArrayList<>();
}
painList.stream().sorted(Comparator.comparing(Pain::getPindex));
return new ArrayList<>();
painList = painList.stream().sorted(Comparator.comparing(Pain::getPindex)).collect(Collectors.toList());
AtomicInteger atomicInteger = new AtomicInteger(1);
painList.forEach(pain -> {
int increment = atomicInteger.getAndIncrement();
pain.setPindex(increment);
String timeRange = pindexFloors.stream().filter(it -> it.floor != null && it.floor == floor)
.filter(it -> floor <= it.getEndIndex() && floor >= it.getStartIndex()).findFirst().get().timeRange;
pain.setTimeRange(timeRange);
});
return painList;
}
public void waitPain(String openId) {
......@@ -68,4 +89,13 @@ public class PainService {
public void deleteAllByFloor(int floor) {
painDao.deleteAllByFloor(floor);
}
@Data
@Accessors(chain = true)
public static class PindexFloor {
private Integer startIndex;
private Integer endIndex;
private String timeRange;
private Integer floor;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!