Browse Source

Merge branch 'dev_1.0.0' of http://git.qmth.com.cn/exam-reserve/server into dev_1.0.0

haogh 1 year ago
parent
commit
f81d899733

+ 5 - 3
install/mysql/init/exam_reserve_db.sql

@@ -183,12 +183,14 @@ create table t_operate_log
 
 -- 基础数据
 insert into t_org(id, name, enable, create_time, update_time)
-values (1, '广东开发大学', 1, now(), now());
+values (1, '广东开发大学', 1, unix_timestamp() * 1000, unix_timestamp() * 1000);
 
 insert into t_system_property(prop_key, prop_value, create_time, update_time)
-values ('CATEGORY_LEVEL', '[{"level":1,"title":"城市"},{"level":2,"title":"教学点"}]', now(), now());
+values ('CATEGORY_LEVEL', '[{"level":1,"title":"城市"},{"level":2,"title":"教学点"}]', unix_timestamp() * 1000,
+        unix_timestamp() * 1000);
 
 insert into t_user (role, name, login_name, password, mobile, category_id, org_id, enable, create_time, update_time)
-values ('ADMIN', '学校管理员', 'admin', UPPER(SHA2('123456', 256)), null, null, 1, 1, now(), now());
+values ('ADMIN', '学校管理员', 'admin', UPPER(SHA2('123456', 256)), null, null, 1, 1, unix_timestamp() * 1000,
+        unix_timestamp() * 1000);
 
 

+ 13 - 0
src/main/java/com/qmth/exam/reserve/bean/Constants.java

@@ -0,0 +1,13 @@
+package com.qmth.exam.reserve.bean;
+
+/**
+ * 常量
+ */
+public interface Constants {
+
+    /**
+     * 分类层级
+     */
+    String CATEGORY_LEVEL = "CATEGORY_LEVEL";
+
+}

+ 44 - 0
src/main/java/com/qmth/exam/reserve/bean/applytask/CurrentApplyTaskVO.java

@@ -0,0 +1,44 @@
+package com.qmth.exam.reserve.bean.applytask;
+
+import com.qmth.exam.reserve.bean.IModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class CurrentApplyTaskVO implements IModel {
+
+    private static final long serialVersionUID = -7196168241899887928L;
+
+    @ApiModelProperty("机构ID")
+    private Long orgId;
+
+    @ApiModelProperty("机构名称")
+    private String orgName;
+
+    @ApiModelProperty("任务ID")
+    private Long taskId;
+
+    @ApiModelProperty("任务名称")
+    private String taskName;
+
+    @ApiModelProperty("考前多少天,禁止考生自主预约")
+    private Long allowApplyDays;
+
+    @ApiModelProperty("考前多少天,禁止考生自主取消预约")
+    private Long allowApplyCancelDays;
+
+    @ApiModelProperty("自主预约起始时间")
+    private Long selfApplyStartTime;
+
+    @ApiModelProperty("自主预约截止时间")
+    private Long selfApplyEndTime;
+
+    @ApiModelProperty("开放式预约起始时间")
+    private Long openApplyStartTime;
+
+    @ApiModelProperty("开放式预约截止时间")
+    private Long openApplyEndTime;
+
+}

+ 2 - 1
src/main/java/com/qmth/exam/reserve/bean/SystemPropertyBean.java → src/main/java/com/qmth/exam/reserve/bean/systemproperty/SystemPropertyBean.java

@@ -1,5 +1,6 @@
-package com.qmth.exam.reserve.bean;
+package com.qmth.exam.reserve.bean.systemproperty;
 
+import com.qmth.exam.reserve.bean.IModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Getter;
 import lombok.Setter;

+ 29 - 6
src/main/java/com/qmth/exam/reserve/controller/admin/SystemPropertyController.java

@@ -2,12 +2,19 @@ package com.qmth.exam.reserve.controller.admin;
 
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
-import com.qmth.exam.reserve.bean.SystemPropertyBean;
+import com.qmth.boot.core.fss.store.FileStore;
+import com.qmth.exam.reserve.bean.Constants;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
+import com.qmth.exam.reserve.bean.systemproperty.SystemPropertyBean;
 import com.qmth.exam.reserve.controller.BaseController;
+import com.qmth.exam.reserve.entity.SystemPropertyEntity;
+import com.qmth.exam.reserve.service.ApplyTaskService;
+import com.qmth.exam.reserve.service.SystemPropertyService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -20,15 +27,31 @@ public class SystemPropertyController extends BaseController {
 
     private static final Logger log = LoggerFactory.getLogger(SystemPropertyController.class);
 
+    @Autowired
+    private FileStore fileStore;
+
+    @Autowired
+    private ApplyTaskService applyTaskService;
+
+    @Autowired
+    private SystemPropertyService systemPropertyService;
+
     @ApiOperation(value = "获取系统常用属性集合")
     @PostMapping(value = "/properties")
     public SystemPropertyBean properties() {
         SystemPropertyBean properties = new SystemPropertyBean();
-        properties.setFileUrlPrefix("https://xxx.com");
-        properties.setOrgTitle("XXX大学");
-        properties.setOrgTitle("yyyy年春季考试预约");
-        properties.setCategoryLevels("[{\"level\":1,\"title\":\"城市\"},{\"level\":2,\"title\":\"教学点\"}]");
-        // todo
+        properties.setFileUrlPrefix(fileStore.getServer());
+
+        CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask();
+        if (curApplyTask != null) {
+            properties.setOrgTitle(curApplyTask.getOrgName());
+            properties.setTaskTitle(curApplyTask.getTaskName());
+        }
+
+        SystemPropertyEntity systemProperty = systemPropertyService.findByPropKey(Constants.CATEGORY_LEVEL);
+        if (systemProperty != null) {
+            properties.setCategoryLevels(systemProperty.getPropValue());
+        }
 
         return properties;
     }

+ 7 - 6
src/main/java/com/qmth/exam/reserve/controller/student/CategoryController.java

@@ -4,17 +4,16 @@ import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.exam.reserve.bean.category.CategoryInfo;
 import com.qmth.exam.reserve.controller.BaseController;
+import com.qmth.exam.reserve.service.CategoryService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.ArrayList;
 import java.util.List;
 
 @RestController
@@ -25,11 +24,13 @@ public class CategoryController extends BaseController {
 
     private static final Logger log = LoggerFactory.getLogger(CategoryController.class);
 
+    @Autowired
+    private CategoryService categoryService;
+
     @ApiOperation(value = "获取数据分类列表(树结构)")
     @PostMapping(value = "/list")
-    public List<CategoryInfo> list(@ApiParam("父级ID") @RequestParam(required = false) Long parentId) {
-        //todo
-        return new ArrayList<>();
+    public List<CategoryInfo> list() {
+        return categoryService.getCategoryTreeForStudent(curLoginStudent());
     }
 
 }

+ 4 - 0
src/main/java/com/qmth/exam/reserve/dao/ApplyTaskDao.java

@@ -2,6 +2,7 @@ package com.qmth.exam.reserve.dao;
 
 import java.util.List;
 
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import org.apache.ibatis.annotations.Param;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -15,6 +16,8 @@ import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 
 public interface ApplyTaskDao extends BaseMapper<ApplyTaskEntity> {
 
+    CurrentApplyTaskVO currentApplyTask();
+
     IPage<ApplyTaskVO> page(Page<ApplyTaskVO> page, @Param(value = "req") ApplyTaskReq req);
 
     ApplyTaskRuleVO find(Long id);
@@ -22,4 +25,5 @@ public interface ApplyTaskDao extends BaseMapper<ApplyTaskEntity> {
     List<TimePeriodVO> getTimePeriodList(Long id);
 
     void updateRule(ApplyTaskReq req);
+
 }

+ 3 - 0
src/main/java/com/qmth/exam/reserve/service/ApplyTaskService.java

@@ -4,6 +4,7 @@ import java.util.List;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.boot.core.collection.PageResult;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.bean.task.ApplyTaskReq;
@@ -20,4 +21,6 @@ public interface ApplyTaskService extends IService<ApplyTaskEntity> {
 
     List<CategoryVO> listTask();
 
+    CurrentApplyTaskVO currentApplyTask();
+
 }

+ 6 - 2
src/main/java/com/qmth/exam/reserve/service/CategoryService.java

@@ -1,13 +1,17 @@
 package com.qmth.exam.reserve.service;
 
-import java.util.List;
-
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.exam.reserve.bean.category.CategoryInfo;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.entity.CategoryEntity;
 
+import java.util.List;
+
 public interface CategoryService extends IService<CategoryEntity> {
 
     List<CategoryVO> listTeaching(LoginUser user);
+
+    List<CategoryInfo> getCategoryTreeForStudent(LoginUser loginUser);
+
 }

+ 2 - 0
src/main/java/com/qmth/exam/reserve/service/SystemPropertyService.java

@@ -5,4 +5,6 @@ import com.qmth.exam.reserve.entity.SystemPropertyEntity;
 
 public interface SystemPropertyService extends IService<SystemPropertyEntity> {
 
+    SystemPropertyEntity findByPropKey(String propKey);
+
 }

+ 14 - 6
src/main/java/com/qmth/exam/reserve/service/impl/ApplyTaskServiceImpl.java

@@ -1,11 +1,5 @@
 package com.qmth.exam.reserve.service.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
-
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -13,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.collection.PageResult;
 import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.bean.task.ApplyTaskReq;
@@ -22,6 +17,11 @@ import com.qmth.exam.reserve.dao.ApplyTaskDao;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.service.ApplyTaskService;
 import com.qmth.exam.reserve.util.PageUtil;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
 
 @Service
 public class ApplyTaskServiceImpl extends ServiceImpl<ApplyTaskDao, ApplyTaskEntity> implements ApplyTaskService {
@@ -93,4 +93,12 @@ public class ApplyTaskServiceImpl extends ServiceImpl<ApplyTaskDao, ApplyTaskEnt
         return categoryList;
     }
 
+    /**
+     * 获取当前启用的预约任务
+     */
+    @Override
+    public CurrentApplyTaskVO currentApplyTask() {
+        return baseMapper.currentApplyTask();
+    }
+
 }

+ 122 - 5
src/main/java/com/qmth/exam/reserve/service/impl/CategoryServiceImpl.java

@@ -1,25 +1,33 @@
 package com.qmth.exam.reserve.service.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.stereotype.Service;
-
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
+import com.qmth.exam.reserve.bean.category.CategoryInfo;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.dao.CategoryDao;
 import com.qmth.exam.reserve.entity.CategoryEntity;
 import com.qmth.exam.reserve.enums.CategoryLevel;
 import com.qmth.exam.reserve.enums.Role;
+import com.qmth.exam.reserve.service.ApplyTaskService;
 import com.qmth.exam.reserve.service.CategoryService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {
 
+    @Autowired
+    private ApplyTaskService applyTaskService;
+
     @Override
     public List<CategoryVO> listTeaching(LoginUser user) {
         QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
@@ -47,4 +55,113 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
         return cgList;
     }
 
+    /**
+     * 获取数据分类列表(树结构)
+     */
+    @Override
+    public List<CategoryInfo> getCategoryTreeForStudent(LoginUser student) {
+        if (Role.STUDENT != student.getRole()) {
+            throw new StatusException("请使用学生账号登录!");
+        }
+
+        List<CategoryInfo> list = new ArrayList<>();
+
+        // 获取当前启用的预约任务
+        CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask();
+        if (curApplyTask.getSelfApplyEndTime() > System.currentTimeMillis()) {
+            // 自主预约截止时间 之前,只能预约本教学点下的考点
+
+            CategoryEntity curEntity = this.getById(student.getCategoryId());
+            if (curEntity == null) {
+                return list;
+            }
+
+            CategoryInfo curInfo = new CategoryInfo();
+            curInfo.setId(curEntity.getId());
+            curInfo.setName(curEntity.getName());
+            curInfo.setLevel(curEntity.getLevel());
+            curInfo.setParentId(curEntity.getParentId());
+            curInfo.setSubNodes(new ArrayList<>());
+
+            // 根节点
+            CategoryInfo root = this.fillParentCategory(curInfo);
+            list.add(root);
+
+            return list;
+        }
+
+        // 开放式预约时间,可以在不同教学点间预约
+        LambdaQueryWrapper<CategoryEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(CategoryEntity::getOrgId, student.getOrgId());
+        wrapper.eq(CategoryEntity::getEnable, Boolean.TRUE);
+        List<CategoryEntity> categoryList = baseMapper.selectList(wrapper);
+
+        Map<Long, List<CategoryEntity>> categoryMaps = categoryList.stream().collect(Collectors.groupingBy(CategoryEntity::getParentId));
+        for (CategoryEntity curEntity : categoryList) {
+            if (curEntity.getLevel() > 1) {
+                continue;
+            }
+
+            // 从根节点开始封装
+            CategoryInfo curInfo = new CategoryInfo();
+            curInfo.setId(curEntity.getId());
+            curInfo.setName(curEntity.getName());
+            curInfo.setLevel(curEntity.getLevel());
+            curInfo.setParentId(curEntity.getParentId());
+            this.fillSubCategory(curInfo, categoryMaps);
+
+            list.add(curInfo);
+        }
+
+        return list;
+    }
+
+    /**
+     * 递归封装子级分类
+     */
+    private void fillSubCategory(CategoryInfo cur, Map<Long, List<CategoryEntity>> categoryMaps) {
+        List<CategoryInfo> subNodes = new ArrayList<>();
+
+        if (categoryMaps.containsKey(cur.getId())) {
+            categoryMaps.get(cur.getId()).forEach(entity -> {
+                CategoryInfo info = new CategoryInfo();
+                info.setId(entity.getId());
+                info.setName(entity.getName());
+                info.setLevel(entity.getLevel());
+                info.setParentId(entity.getParentId());
+                this.fillSubCategory(info, categoryMaps);
+                subNodes.add(info);
+            });
+        }
+
+        cur.setSubNodes(subNodes);
+    }
+
+    /**
+     * 递归封装父级分类
+     */
+    private CategoryInfo fillParentCategory(CategoryInfo cur) {
+        if (cur.getLevel() <= 1) {
+            // 根节点,直接返回
+            return cur;
+        }
+
+        CategoryEntity parent = this.getById(cur.getParentId());
+        if (parent == null) {
+            return cur;
+        }
+
+        CategoryInfo info = new CategoryInfo();
+        info.setId(parent.getId());
+        info.setName(parent.getName());
+        info.setLevel(parent.getLevel());
+        info.setParentId(parent.getParentId());
+
+        List<CategoryInfo> subNodes = new ArrayList<>();
+        subNodes.add(cur);
+        info.setSubNodes(subNodes);
+
+        return fillParentCategory(info);
+    }
+
 }

+ 7 - 0
src/main/java/com/qmth/exam/reserve/service/impl/SystemPropertyServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.exam.reserve.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.exam.reserve.dao.SystemPropertyDao;
 import com.qmth.exam.reserve.entity.SystemPropertyEntity;
@@ -13,5 +14,11 @@ public class SystemPropertyServiceImpl extends ServiceImpl<SystemPropertyDao, Sy
 
     private static final Logger log = LoggerFactory.getLogger(SystemPropertyServiceImpl.class);
 
+    @Override
+    public SystemPropertyEntity findByPropKey(String propKey) {
+        LambdaQueryWrapper<SystemPropertyEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(SystemPropertyEntity::getPropKey, propKey);
+        return baseMapper.selectOne(wrapper);
+    }
 
 }

+ 1 - 1
src/main/resources/application.properties

@@ -34,7 +34,7 @@ com.qmth.redis.db=15
 # ********** file config **********
 #
 com.qmth.fss.config=/home/admin/project/exam-reserve/static
-com.qmth.fss.server=/file
+com.qmth.fss.server=http://192.168.10.41:8300/file
 #
 # ********** sys config **********
 #

+ 15 - 1
src/main/resources/mapper/ApplyTaskMapper.xml

@@ -5,6 +5,19 @@
 	<!-- <resultMap id="custMap" type="com.qmth.exam.reserve.bean.task.TimePeriodVO"> 
 		<result column="params" property="params" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"> 
 		</result> </resultMap> -->
+
+	<select id="currentApplyTask" resultType="com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO">
+		select t.id task_id,t.name task_name,t.org_id,org.name org_name,
+			   t.allow_apply_days,t.allow_apply_cancel_days,
+			   t.self_apply_start_time,t.self_apply_end_time,
+			   t.open_apply_start_time,t.open_apply_end_time
+		from t_apply_task t
+		left join t_org org on org.id=t.org_id
+		where t.`enable` = 1
+		order by t.id desc
+		limit 1
+	</select>
+
 	<select id="page"
 		resultType="com.qmth.exam.reserve.bean.task.ApplyTaskVO">
 		select id,name,self_apply_start_time selfApplyStartTime,
@@ -23,11 +36,12 @@
 		resultType="com.qmth.exam.reserve.bean.task.ApplyTaskRuleVO">
 		select * from t_apply_task where id=#{id}
 	</select>
+
 	<select id="getTimePeriodList"
 		resultType="com.qmth.exam.reserve.bean.task.TimePeriodVO">
 		select id,start_time startTime,end_time endTime from
 		t_time_period where apply_task_id=#{id}
 		order by start_time
 	</select>
-	
+
 </mapper>