parent
5200ec6f8c
commit
523dfa47b6
@ -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<List<GradeAndClassVo>> findRecords(@Valid @RequestBody GCDto gcDto) {
|
||||
List<GradeAndClassVo> res = commonService.getGradeAndClass(gcDto);
|
||||
return R.success(res);
|
||||
}
|
||||
}
|
@ -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<GradeAndClassVo> getGradeAndClass(GCDto gcDto);
|
||||
}
|
@ -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<GradeAndClassVo> getGradeAndClass(GCDto gcDto) {
|
||||
List<GradeAndClassVo> gradeAndClassVos = new ArrayList<>();
|
||||
try {
|
||||
//获取当前学校该学段下详细信息
|
||||
List<School.Period> period = schoolRepository.findPeriodById(gcDto.getSchoolId(), gcDto.getPeriodId());
|
||||
List<ClassInfo> 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<String> 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("获取当前学校当前学段年级班级信息失败");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package cn.teammodel.model.dto.admin.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GCDto {
|
||||
private String schoolId;
|
||||
private String periodId;
|
||||
}
|
@ -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<CI> classes = new ArrayList<>();
|
||||
|
||||
public void AddClass(CI ci) {
|
||||
this.classes.add(ci);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class CI {
|
||||
private String classId;
|
||||
private String className;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cn.teammodel.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MonthToNumberConverter {
|
||||
|
||||
private static final Map<String, Integer> monthMap = createMonthMap();
|
||||
|
||||
private static Map<String, Integer> createMonthMap() {
|
||||
Map<String, Integer> 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);
|
||||
}*/
|
||||
}
|
Loading…
Reference in new issue