haogh 1 năm trước cách đây
mục cha
commit
3e06ceb88f

+ 8 - 4
src/main/java/com/qmth/exam/reserve/bean/teaching/TeachingReq.java

@@ -2,22 +2,26 @@ package com.qmth.exam.reserve.bean.teaching;
 
 import com.qmth.exam.reserve.bean.IModel;
 
+import com.qmth.exam.reserve.bean.PagerReq;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
-public class TeachingReq implements IModel {
+public class TeachingReq extends PagerReq implements IModel {
 
     private static final long serialVersionUID = 2203050783813389251L;
 
-    @ApiModelProperty("教学点名称")
+    @ApiModelProperty(value = "教学点名称", required = false)
     private String name;
 
-    @ApiModelProperty("教学点名称")
+    @ApiModelProperty(value = "教学点代码", required = false)
     private String code;
 
-    @ApiModelProperty("状态")
+    @ApiModelProperty(value = "状态(true|false)",required = false)
     private Boolean enable;
+
+    @ApiModelProperty(value = "教学点所在层级(默认为2)",required = false)
+    private Integer level;
 }

+ 29 - 0
src/main/java/com/qmth/exam/reserve/bean/teaching/TeachingSaveReq.java

@@ -0,0 +1,29 @@
+package com.qmth.exam.reserve.bean.teaching;
+
+import com.qmth.exam.reserve.bean.IModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Setter
+@Getter
+public class TeachingSaveReq implements IModel {
+
+    @ApiModelProperty(value = "ID")
+    private Long id;
+
+    @ApiModelProperty(value="教学点代码", required = true)
+    private String code;
+
+    @ApiModelProperty(value="教学点名称", required = true)
+    private String name;
+
+    @ApiModelProperty(value="教学点所在城市", required = true)
+    private Long cityId;
+
+    @ApiModelProperty(value="教学点容量")
+    private Integer capacity;
+
+    @ApiModelProperty(value="教学点状态", required = true)
+    private Boolean enable;
+}

+ 2 - 4
src/main/java/com/qmth/exam/reserve/controller/admin/StudentApplyController.java

@@ -107,9 +107,6 @@ public class StudentApplyController extends BaseController {
         if (Role.TEACHING.equals(user.getRole())) {
             teachingId = user.getCategoryId();
         }
-        if(teachingId == null) {
-            throw new StatusException("请选择教学点");
-        }
         List<Map<String, Object>> failRecords = new ArrayList<Map<String, Object>>();
         try {
             failRecords = studentApplyService.importPreExam(user, teachingId, level, file.getInputStream());
@@ -124,7 +121,7 @@ public class StudentApplyController extends BaseController {
 
     @ApiOperation(value = "一键自动分配")
     @PostMapping(value = "/std/auto/assign")
-    public void autoAssign(@ApiParam("任务ID") @RequestParam Long taskId) {
+    public String autoAssign(@ApiParam("任务ID") @RequestParam Long taskId) {
         if (taskId == null) {
             throw new StatusException("请选择预约任务");
         }
@@ -133,6 +130,7 @@ public class StudentApplyController extends BaseController {
             throw new StatusException("没有权限");
         }
         studentApplyService.autoAssign(taskId, user.getId());
+        return "后台正在执行中,请耐心等待!";
     }
 
     @ApiOperation(value = "打印签到表")

+ 11 - 0
src/main/java/com/qmth/exam/reserve/controller/admin/TeachingController.java

@@ -1,5 +1,7 @@
 package com.qmth.exam.reserve.controller.admin;
 
+import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.bean.teaching.TeachingSaveReq;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -32,4 +34,13 @@ public class TeachingController extends BaseController {
         return categoryService.page(req);
     }
 
+    @ApiOperation(value = "教学点新增/编辑")
+    @PostMapping(value = "/save")
+    public void save(@RequestBody TeachingSaveReq req) {
+        LoginUser user = curLoginUser();
+        categoryService.saveTeaching(user, req);
+    }
+
+
+
 }

+ 7 - 0
src/main/java/com/qmth/exam/reserve/dao/CategoryDao.java

@@ -1,8 +1,15 @@
 package com.qmth.exam.reserve.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.exam.reserve.bean.teaching.TeachingReq;
+import com.qmth.exam.reserve.bean.teaching.TeachingVO;
 import com.qmth.exam.reserve.entity.CategoryEntity;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.web.bind.annotation.RequestParam;
 
 public interface CategoryDao extends BaseMapper<CategoryEntity> {
 
+    IPage<TeachingVO> page(Page<TeachingVO> page, @Param("req") TeachingReq req);
 }

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

@@ -8,6 +8,7 @@ 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.bean.teaching.TeachingReq;
+import com.qmth.exam.reserve.bean.teaching.TeachingSaveReq;
 import com.qmth.exam.reserve.bean.teaching.TeachingVO;
 import com.qmth.exam.reserve.entity.CategoryEntity;
 
@@ -19,4 +20,5 @@ public interface CategoryService extends IService<CategoryEntity> {
 
     PageResult<TeachingVO> page(TeachingReq req);
 
+    void saveTeaching(LoginUser user, TeachingSaveReq req);
 }

+ 46 - 1
src/main/java/com/qmth/exam/reserve/service/impl/CategoryServiceImpl.java

@@ -2,6 +2,8 @@ package com.qmth.exam.reserve.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+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;
@@ -10,7 +12,9 @@ import com.qmth.exam.reserve.bean.category.CategoryCacheBean;
 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.bean.task.ApplyTaskVO;
 import com.qmth.exam.reserve.bean.teaching.TeachingReq;
+import com.qmth.exam.reserve.bean.teaching.TeachingSaveReq;
 import com.qmth.exam.reserve.bean.teaching.TeachingVO;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.CategoryCacheService;
@@ -19,8 +23,12 @@ 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.CategoryService;
+import com.qmth.exam.reserve.util.PageUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -179,7 +187,44 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
 
     @Override
     public PageResult<TeachingVO> page(TeachingReq req) {
-        return null;
+        if(req.getLevel() == null){
+            req.setLevel(CategoryLevel.TEACHING.getValue());
+        }
+        IPage<TeachingVO> iPage = baseMapper.page(new Page<>(req.getPageNumber(), req.getPageSize()),
+                req);
+        return PageUtil.of(iPage);
+    }
+
+    @Transactional
+    @Override
+    public void saveTeaching(LoginUser user, TeachingSaveReq req) {
+        checkTeaching(req);
+        CategoryEntity category = new CategoryEntity();
+        BeanUtils.copyProperties(req, category);
+        category.setLevel(CategoryLevel.TEACHING.getValue());
+        category.setOrgId(user.getOrgId());
+        category.setParentId(getById(req.getCityId()).getId());
+        saveOrUpdate(category);
+    }
+
+    private void checkTeaching(TeachingSaveReq req) {
+        if(StringUtils.isBlank(req.getCode())) {
+            throw new StatusException("教学点代码不能为空");
+        }
+        if(StringUtils.isBlank(req.getName())) {
+            throw new StatusException("教学点名称不能为空");
+        }
+        if(req.getCityId() == null) {
+            throw new StatusException("请选择教学点所在城市");
+        }
+        if(req.getId() == null) {
+            LambdaQueryWrapper<CategoryEntity> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(CategoryEntity::getCode, req.getCode());
+            List<CategoryEntity> list = baseMapper.selectList(wrapper);
+            if(list.size() > 0) {
+                throw new StatusException("教学点代码已经存在");
+            }
+        }
     }
 
 }

+ 2 - 1
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -17,6 +17,7 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
+import com.qmth.exam.reserve.enums.Role;
 import com.qmth.exam.reserve.service.*;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateUtils;
@@ -257,7 +258,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             if (categoryId != null && !student.getCategoryId().equals(categoryId)) {
                 msg.append(" 导入的考生所属教学点和系统中的考生教学点不匹配");
             }
-            if (categoryId != null && !categoryId.equals(teachingId)) {
+            if (user.getRole().equals(Role.TEACHING) && categoryId != null && !categoryId.equals(teachingId)) {
                 msg.append(" 不是本教学点的考生");
              }
             String agentName1 = trimAndNullIfBlank(line.get(EXCEL_HEADER[4]));

+ 1 - 7
src/main/java/com/qmth/exam/reserve/service/impl/StudentAutoAssignServiceImpl.java

@@ -138,13 +138,7 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
             // 总考位数量
             Integer total = siteList.stream().mapToInt(ExamSiteEntity::getCapacity).sum() * timeList.size();
             // 已经预约的数量
-            Integer haveApplyNum = 0;
-            for (ExamSiteEntity site : siteList) {
-                haveApplyNum += cacheService.getApplyTotalCount(site.getId());
-            }
-            if (haveApplyNum == 0) {
-                haveApplyNum = baseMapper.getHaveApplyCount(siteList.stream().map(BaseEntity::getId).collect(Collectors.toList()), Boolean.FALSE);
-            }
+            Integer haveApplyNum =  baseMapper.getHaveApplyCount(siteList.stream().map(BaseEntity::getId).collect(Collectors.toList()), Boolean.FALSE);
             // 未预约的数量
             Integer noApplyNum = getNoApplyNum(map.get(key));
             if (noApplyNum > total - haveApplyNum) {

+ 27 - 1
src/main/resources/mapper/CategoryMapper.xml

@@ -1,5 +1,31 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.exam.reserve.dao.CategoryDao">
-
+    <select id="page" resultType="com.qmth.exam.reserve.bean.teaching.TeachingVO">
+        SELECT
+            c.id,
+            c.CODE,
+            c.NAME,
+            c.capacity,
+            c.ENABLE,
+            p.NAME cityName
+        FROM
+            t_category c,
+            t_category p
+        WHERE
+            c.parent_id = p.id
+        <if test="req.level != null">
+            and c.level=#{req.level}
+        </if>
+        <if test="req.name != null and req.name !=''">
+            and c.name like concat('%', #{req.name}, '%')
+        </if>
+        <if test="req.code != null and req.code !=''">
+            and c.code like concat('%', #{req.code}, '%')
+        </if>
+        <if test="req.enable != null">
+            and c.enable=#{req.enable}
+        </if>
+        order by c.code
+    </select>
 </mapper>