|
@@ -0,0 +1,124 @@
|
|
|
+package com.ym.mec.student.controller.degree;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.microsvc.toolkit.common.response.paging.PageInfo;
|
|
|
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
|
|
|
+import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.biz.dal.enums.EDegreeStatus;
|
|
|
+import com.ym.mec.biz.dal.wrapper.DegreeWrapper;
|
|
|
+import com.ym.mec.biz.service.DegreeService;
|
|
|
+import com.ym.mec.common.controller.BaseController;
|
|
|
+import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
+import com.ym.mec.common.exception.BizException;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+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 java.util.Arrays;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@RequestMapping("/degree")
|
|
|
+@Api(tags = "考级信息")
|
|
|
+public class DegreeInfoController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DegreeService degreeService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "详情", notes = "考级信息-根据详情ID查询单条, 传入id")
|
|
|
+ @GetMapping("/detail/{id}")
|
|
|
+ public HttpResponseResult<DegreeWrapper.StudentDegreeInfo> detail(@PathVariable("id") Long id) {
|
|
|
+
|
|
|
+ // 登录用户信息
|
|
|
+ SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
+ if (Objects.isNull(user) || Objects.isNull(user.getId())){
|
|
|
+ return failed(HttpStatus.FORBIDDEN,"请登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 考级信息
|
|
|
+ DegreeWrapper.StudentDegreeInfo wrapper = degreeService.studentDegreeInfoById(id);
|
|
|
+
|
|
|
+ // 考级机构-暂未开放此活动
|
|
|
+ if (!user.getTenantId().equals(wrapper.getTenantId())) {
|
|
|
+ throw new BizException("暂未开放此活动");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 考级城市-暂未开放此活动
|
|
|
+ boolean noneMatch = Arrays.stream(wrapper.getOrganIds().split(","))
|
|
|
+ .mapToInt(Integer::parseInt).noneMatch(x -> x == user.getOrganId());
|
|
|
+ if (Objects.nonNull(user.getOrganId()) && noneMatch) {
|
|
|
+ throw new BizException("暂未开放此活动");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询机构信息
|
|
|
+ return succeed(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询分页", notes = "考级信息- 传入 DegreeWrapper.DegreeQuery")
|
|
|
+ @PostMapping("/page")
|
|
|
+ public HttpResponseResult<PageInfo<DegreeWrapper.Degree>> page(@RequestBody DegreeWrapper.DegreeQuery query) {
|
|
|
+
|
|
|
+ // 登录用户信息
|
|
|
+ SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
+ if (Objects.isNull(user) || Objects.isNull(user.getId())) {
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置用户机构ID和城市分部ID
|
|
|
+ query.tenantId(user.getTenantId()).organId(user.getOrganId()).setDegreeStatuses(Lists.newArrayList(EDegreeStatus.END));
|
|
|
+
|
|
|
+ IPage<DegreeWrapper.Degree> pages = degreeService.selectPage(QueryInfo.getPage(query), query);
|
|
|
+
|
|
|
+ // 首页查询时,默认查询进行中,未开始插入首页
|
|
|
+ if (query.getPage() == 1) {
|
|
|
+
|
|
|
+ // 设置分页查询参数
|
|
|
+ query.rows(1000).degreeStatuses(Lists.newArrayList(EDegreeStatus.NOT_START, EDegreeStatus.START));
|
|
|
+
|
|
|
+ // 考级信息
|
|
|
+ Map<EDegreeStatus, List<DegreeWrapper.Degree>> collect = degreeService.selectPage(QueryInfo.getPage(query), query).getRecords().stream()
|
|
|
+ .collect(Collectors.groupingBy(DegreeWrapper.Degree::getStatus));
|
|
|
+
|
|
|
+ List<DegreeWrapper.Degree> degrees = Lists.newArrayList();
|
|
|
+ // 进行中
|
|
|
+ if (collect.containsKey(EDegreeStatus.START)) {
|
|
|
+ degrees.addAll(collect.get(EDegreeStatus.START).stream()
|
|
|
+ .sorted(Comparator.comparing(DegreeWrapper.Degree::getStartTime))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 未开始
|
|
|
+ if (collect.containsKey(EDegreeStatus.NOT_START)) {
|
|
|
+ degrees.addAll(collect.get(EDegreeStatus.NOT_START).stream()
|
|
|
+ .sorted(Comparator.comparing(DegreeWrapper.Degree::getStartTime))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(degrees)) {
|
|
|
+ pages.getRecords().addAll(0, degrees);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return succeed(QueryInfo.pageInfo(pages));
|
|
|
+ }
|
|
|
+}
|