diff --git a/src/main/java/cn/teammodel/controller/admin/controller/CommonController.java b/src/main/java/cn/teammodel/controller/admin/controller/CommonController.java new file mode 100644 index 0000000..672aa1c --- /dev/null +++ b/src/main/java/cn/teammodel/controller/admin/controller/CommonController.java @@ -0,0 +1,35 @@ +package cn.teammodel.controller.admin.controller; + +import cn.teammodel.common.R; +import cn.teammodel.controller.admin.service.ArtService; +import cn.teammodel.controller.admin.service.CommonService; +import cn.teammodel.model.dto.admin.art.ArtFindDto; +import cn.teammodel.model.dto.admin.common.GCDto; +import cn.teammodel.model.vo.admin.ArtElementsVo; +import cn.teammodel.model.vo.admin.GradeAndClassVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@RestController +@RequestMapping("admin/common") +@Api(tags = "管理员端-公共组件") +public class CommonController { + + @Resource + private CommonService commonService ; + @PostMapping("getGradeAndClass") + @ApiOperation("获取当前学校当前学段年级班级信息") + public R> findRecords(@Valid @RequestBody GCDto gcDto) { + List res = commonService.getGradeAndClass(gcDto); + return R.success(res); + } +} diff --git a/src/main/java/cn/teammodel/controller/admin/service/CommonService.java b/src/main/java/cn/teammodel/controller/admin/service/CommonService.java new file mode 100644 index 0000000..5322efa --- /dev/null +++ b/src/main/java/cn/teammodel/controller/admin/service/CommonService.java @@ -0,0 +1,10 @@ +package cn.teammodel.controller.admin.service; + +import cn.teammodel.model.dto.admin.common.GCDto; +import cn.teammodel.model.vo.admin.GradeAndClassVo; +import org.springframework.stereotype.Service; + +import java.util.List; +public interface CommonService { + List getGradeAndClass(GCDto gcDto); +} diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/CommonServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/CommonServiceImpl.java new file mode 100644 index 0000000..87f5769 --- /dev/null +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/CommonServiceImpl.java @@ -0,0 +1,83 @@ +package cn.teammodel.controller.admin.service.impl; + +import cn.teammodel.controller.admin.service.CommonService; +import cn.teammodel.model.dto.admin.common.GCDto; +import cn.teammodel.model.entity.school.ClassInfo; +import cn.teammodel.model.entity.school.School; +import cn.teammodel.model.vo.admin.GradeAndClassVo; +import cn.teammodel.repository.ClassRepository; +import cn.teammodel.repository.SchoolRepository; +import cn.teammodel.utils.MonthToNumberConverter; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.time.Month; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import static java.time.LocalDate.now; + +@Service +public class CommonServiceImpl implements CommonService { + @Resource + private SchoolRepository schoolRepository; + @Resource + private ClassRepository classRepository; + + @Override + public List getGradeAndClass(GCDto gcDto) { + List gradeAndClassVos = new ArrayList<>(); + try { + //获取当前学校该学段下详细信息 + List period = schoolRepository.findPeriodById(gcDto.getSchoolId(), gcDto.getPeriodId()); + List classes = classRepository.findClassBySchoolIdAndPeriodId(gcDto.getSchoolId(), gcDto.getPeriodId()); + int year = now().getYear(); + Month month = now().getMonth(); + int mon = MonthToNumberConverter.convertMonthToNumber(month.name()); + int day = now().getDayOfMonth(); + //处理年级ID + for (ClassInfo classInfo : classes) { + if(period.get(0).getId().equalsIgnoreCase(classInfo.getPeriodId())) { + for (School.Semester semester : period.get(0).getSemesters()) { + int time = 0; + if(semester.getStart() == 1) { + if (mon == semester.getMonth()) + { + time = day >= semester.getDay() ? 0 : 1; + } + else + { + time = mon > semester.getMonth() ? 0 : 1; + } + int eYear = year - time; + classInfo.setGrade(eYear- classInfo.getYear()); + } + } + + } + } + List grades = period.get(0).getGrades(); + int index = 0; + for (String grade : grades) { + GradeAndClassVo gradeAndClassVo = new GradeAndClassVo(); + gradeAndClassVo.setGradeId(index); + gradeAndClassVo.setGradeName(grade); + classes.stream().filter(classInfo -> classInfo.getGrade() == gradeAndClassVo.getGradeId()).forEach(classInfo -> { + GradeAndClassVo.CI ci = new GradeAndClassVo.CI(); + ci.setClassId(classInfo.getId()); + ci.setClassName(classInfo.getName()); + gradeAndClassVo.AddClass(ci); + }); + index ++; + gradeAndClassVos.add(gradeAndClassVo); + } + + return gradeAndClassVos; + }catch (Exception e) { + + throw new RuntimeException("获取当前学校当前学段年级班级信息失败"); + } + } +} diff --git a/src/main/java/cn/teammodel/model/dto/admin/common/GCDto.java b/src/main/java/cn/teammodel/model/dto/admin/common/GCDto.java new file mode 100644 index 0000000..d3afa41 --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/admin/common/GCDto.java @@ -0,0 +1,9 @@ +package cn.teammodel.model.dto.admin.common; + +import lombok.Data; + +@Data +public class GCDto { + private String schoolId; + private String periodId; +} diff --git a/src/main/java/cn/teammodel/model/entity/school/ClassInfo.java b/src/main/java/cn/teammodel/model/entity/school/ClassInfo.java index 277ced8..3ccf33a 100644 --- a/src/main/java/cn/teammodel/model/entity/school/ClassInfo.java +++ b/src/main/java/cn/teammodel/model/entity/school/ClassInfo.java @@ -19,6 +19,7 @@ public class ClassInfo extends BaseItem { private String room; private String school; private Integer graduate; + private Integer grade; private String pk; private Integer ttl; diff --git a/src/main/java/cn/teammodel/model/vo/admin/GradeAndClassVo.java b/src/main/java/cn/teammodel/model/vo/admin/GradeAndClassVo.java new file mode 100644 index 0000000..7ceafc2 --- /dev/null +++ b/src/main/java/cn/teammodel/model/vo/admin/GradeAndClassVo.java @@ -0,0 +1,23 @@ +package cn.teammodel.model.vo.admin; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class GradeAndClassVo { + private int gradeId; + private String gradeName; + private List classes = new ArrayList<>(); + + public void AddClass(CI ci) { + this.classes.add(ci); + } + + @Data + public static class CI { + private String classId; + private String className; + } +} diff --git a/src/main/java/cn/teammodel/repository/ClassRepository.java b/src/main/java/cn/teammodel/repository/ClassRepository.java index 9da6a4b..b69920b 100644 --- a/src/main/java/cn/teammodel/repository/ClassRepository.java +++ b/src/main/java/cn/teammodel/repository/ClassRepository.java @@ -18,4 +18,6 @@ public interface ClassRepository extends CosmosRepository { @Query("select c.id, c.name from School as c where c.code = @code and c.id in (@ids)") List findAllByCodeAndIdIn(String code, Collection ids); + @Query("select c.id, c.name,c.year,c.periodId from School as c where c.school = @school and c.periodId = @periodId and c.pk = 'Class'") + List findClassBySchoolIdAndPeriodId(String school, String periodId); } diff --git a/src/main/java/cn/teammodel/utils/MonthToNumberConverter.java b/src/main/java/cn/teammodel/utils/MonthToNumberConverter.java new file mode 100644 index 0000000..1a3a908 --- /dev/null +++ b/src/main/java/cn/teammodel/utils/MonthToNumberConverter.java @@ -0,0 +1,36 @@ +package cn.teammodel.utils; + +import java.util.HashMap; +import java.util.Map; + +public class MonthToNumberConverter { + + private static final Map monthMap = createMonthMap(); + + private static Map createMonthMap() { + Map map = new HashMap<>(); + map.put("JANUARY", 1); + map.put("FEBRUARY", 2); + map.put("MARCH", 3); + map.put("APRIL", 4); + map.put("MAY", 5); + map.put("JUNE", 6); + map.put("JULY", 7); + map.put("AUGUST", 8); + map.put("SEPTEMBER", 9); + map.put("OCTOBER", 10); + map.put("NOVEMBER", 11); + map.put("DECEMBER", 12); + return map; + } + + public static int convertMonthToNumber(String monthName) { + return monthMap.getOrDefault(monthName, -1); // 如果找不到对应月份,则返回 -1 + } + + /* public static void main(String[] args) { + String month = "August"; + int monthNumber = convertMonthToNumber(month); + System.out.println("The number for " + month + " is: " + monthNumber); + }*/ +} \ No newline at end of file