Commit c35e6a40 by liushuangwu

PainService

1 parent d4682615
...@@ -3,12 +3,16 @@ package com.pipihelper.project.feishu.service; ...@@ -3,12 +3,16 @@ package com.pipihelper.project.feishu.service;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.pipihelper.project.feishu.dao.PainDao; import com.pipihelper.project.feishu.dao.PainDao;
import com.pipihelper.project.feishu.entity.Pain; import com.pipihelper.project.feishu.entity.Pain;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service @Service
public class PainService { public class PainService {
...@@ -16,6 +20,14 @@ public class PainService { ...@@ -16,6 +20,14 @@ public class PainService {
@Autowired @Autowired
private PainDao painDao; 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) { public void create(Pain pain) {
painDao.create(pain); painDao.create(pain);
} }
...@@ -40,13 +52,22 @@ public class PainService { ...@@ -40,13 +52,22 @@ public class PainService {
return painDao.findAll(); return painDao.findAll();
} }
public List<Pain> findAllReorderByFloor(int floor) { public List<Pain> findAllReorderByFloor(int floor) {
List<Pain> painList = painDao.findAllByFloor(floor); List<Pain> painList = painDao.findAllByFloor(floor);
if (CollectionUtil.isEmpty(painList)) { if (CollectionUtil.isEmpty(painList)) {
return new ArrayList<>(); return new ArrayList<>();
} }
painList.stream().sorted(Comparator.comparing(Pain::getIndex)); painList = painList.stream().sorted(Comparator.comparing(Pain::getPindex)).collect(Collectors.toList());
return new ArrayList<>(); 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) { public void waitPain(String openId) {
...@@ -68,4 +89,13 @@ public class PainService { ...@@ -68,4 +89,13 @@ public class PainService {
public void deleteAllByFloor(int floor) { public void deleteAllByFloor(int floor) {
painDao.deleteAllByFloor(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!