|
@@ -2,21 +2,44 @@ package com.qmth.exam.reserve.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.qmth.boot.core.collection.PageResult;
|
|
|
|
+import com.qmth.boot.core.exception.StatusException;
|
|
|
|
+import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
|
+import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
|
+import com.qmth.boot.tools.excel.model.DataMap;
|
|
import com.qmth.exam.reserve.bean.examsite.ExamSiteInfo;
|
|
import com.qmth.exam.reserve.bean.examsite.ExamSiteInfo;
|
|
|
|
+import com.qmth.exam.reserve.bean.examsite.ExamSiteReq;
|
|
|
|
+import com.qmth.exam.reserve.bean.examsite.ExamSiteSaveReq;
|
|
|
|
+import com.qmth.exam.reserve.bean.examsite.ExamSiteVO;
|
|
|
|
+import com.qmth.exam.reserve.bean.login.LoginUser;
|
|
import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
|
|
import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
|
|
import com.qmth.exam.reserve.dao.ExamSiteDao;
|
|
import com.qmth.exam.reserve.dao.ExamSiteDao;
|
|
|
|
+import com.qmth.exam.reserve.entity.CategoryEntity;
|
|
import com.qmth.exam.reserve.entity.ExamSiteEntity;
|
|
import com.qmth.exam.reserve.entity.ExamSiteEntity;
|
|
|
|
+import com.qmth.exam.reserve.service.CategoryService;
|
|
import com.qmth.exam.reserve.service.ExamSiteService;
|
|
import com.qmth.exam.reserve.service.ExamSiteService;
|
|
|
|
+import com.qmth.exam.reserve.util.PageUtil;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+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.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class ExamSiteServiceImpl extends ServiceImpl<ExamSiteDao, ExamSiteEntity> implements ExamSiteService {
|
|
public class ExamSiteServiceImpl extends ServiceImpl<ExamSiteDao, ExamSiteEntity> implements ExamSiteService {
|
|
|
|
|
|
|
|
+ private static final String[] EXCEL_HEADER = new String[]{"考点代码", "考点名称", "所属教学点", "考点地址"};
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CategoryService categoryService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<CategoryVO> listExamSite(Long teachingId) {
|
|
public List<CategoryVO> listExamSite(Long teachingId) {
|
|
QueryWrapper<ExamSiteEntity> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<ExamSiteEntity> wrapper = new QueryWrapper<>();
|
|
@@ -66,4 +89,166 @@ public class ExamSiteServiceImpl extends ServiceImpl<ExamSiteDao, ExamSiteEntity
|
|
return capacity != null ? capacity : 0;
|
|
return capacity != null ? capacity : 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public PageResult<ExamSiteVO> page(ExamSiteReq req) {
|
|
|
|
+ IPage<ExamSiteVO> iPage = baseMapper.page(new Page<>(req.getPageNumber(), req.getPageSize()),
|
|
|
|
+ req);
|
|
|
|
+ return PageUtil.of(iPage);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveExamSite(LoginUser user, ExamSiteSaveReq req) {
|
|
|
|
+ checkExamSite(req);
|
|
|
|
+ ExamSiteEntity site = new ExamSiteEntity();
|
|
|
|
+ BeanUtils.copyProperties(req, site);
|
|
|
|
+ if(req.getId() == null) {
|
|
|
|
+ LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(ExamSiteEntity::getCategoryId, req.getCategoryId());
|
|
|
|
+ wrapper.eq(ExamSiteEntity::getCode, req.getCode());
|
|
|
|
+ ExamSiteEntity existSite = baseMapper.selectOne(wrapper);
|
|
|
|
+ if (existSite != null) {
|
|
|
|
+ throw new StatusException("code:" + req.getCode() + "已经存在");
|
|
|
|
+ }
|
|
|
|
+ save(site);
|
|
|
|
+ } else {
|
|
|
|
+ updateById(site);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void enable(Long id, Boolean enable) {
|
|
|
|
+ ExamSiteEntity examSite = getById(id);
|
|
|
|
+ examSite.setEnable(enable);
|
|
|
|
+ baseMapper.updateById(examSite);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map<String, Object>> importExamSite(LoginUser user, InputStream inputStream) {
|
|
|
|
+ List<DataMap> lineList = null;
|
|
|
|
+ ExcelReader reader = ExcelReader.create(ExcelType.XLSX, inputStream, 0);
|
|
|
|
+ try {
|
|
|
|
+ lineList = reader.getDataMapList();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new StatusException("Excel 解析失败");
|
|
|
|
+ }
|
|
|
|
+ if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(lineList)) {
|
|
|
|
+ throw new StatusException("Excel无内容");
|
|
|
|
+ }
|
|
|
|
+ List<Map<String, Object>> failRecords = new ArrayList<Map<String, Object>>();
|
|
|
|
+ List<ExamSiteEntity> examSiteList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < lineList.size(); i++) {
|
|
|
|
+ DataMap line = lineList.get(i);
|
|
|
|
+ ExamSiteEntity site = new ExamSiteEntity();
|
|
|
|
+ StringBuilder msg = new StringBuilder();
|
|
|
|
+ String code = trimAndNullIfBlank(line.get(EXCEL_HEADER[0]));
|
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
|
+ msg.append(" 考点代码不能为空");
|
|
|
|
+ } else {
|
|
|
|
+ site.setCode(code);
|
|
|
|
+ }
|
|
|
|
+ String name = trimAndNullIfBlank(line.get(EXCEL_HEADER[1]));
|
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
|
+ msg.append(" 考点名称不能为空");
|
|
|
|
+ } else {
|
|
|
|
+ site.setName(name);
|
|
|
|
+ }
|
|
|
|
+ String teachingName = trimAndNullIfBlank(line.get(EXCEL_HEADER[2]));
|
|
|
|
+ if (StringUtils.isBlank(teachingName)) {
|
|
|
|
+ msg.append(" 所属教学点不能为空");
|
|
|
|
+ } else {
|
|
|
|
+ LambdaQueryWrapper<CategoryEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(CategoryEntity::getName, teachingName);
|
|
|
|
+ wrapper.eq(CategoryEntity::getEnable, Boolean.TRUE);
|
|
|
|
+ wrapper.eq(CategoryEntity::getOrgId, user.getOrgId());
|
|
|
|
+ List<CategoryEntity> list = categoryService.list(wrapper);
|
|
|
|
+ if(list.isEmpty()) {
|
|
|
|
+ msg.append(" 所属教学点不存在");
|
|
|
|
+ } else if(list.size() > 1) {
|
|
|
|
+ msg.append(" 所属教学点,查询到多条相同名称的数据");
|
|
|
|
+ } else {
|
|
|
|
+ site.setCategoryId(list.get(0).getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String address = trimAndNullIfBlank(line.get(EXCEL_HEADER[3]));
|
|
|
|
+ if (StringUtils.isBlank(address)) {
|
|
|
|
+ msg.append(" 考点地址不能为空");
|
|
|
|
+ } else {
|
|
|
|
+ site.setAddress(address);
|
|
|
|
+ }
|
|
|
|
+ if (msg.length() > 0) {
|
|
|
|
+ failRecords.add(newError(i + 1, msg.toString()));
|
|
|
|
+ } else {
|
|
|
|
+ site.setEnable(Boolean.TRUE);
|
|
|
|
+ examSiteList.add(site);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
|
+ return failRecords;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < examSiteList.size(); i++) {
|
|
|
|
+ ExamSiteEntity examSite = examSiteList.get(i);
|
|
|
|
+ try {
|
|
|
|
+ saveExamSite(examSite);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ failRecords.add(newError(i + 1, " 系统异常"));
|
|
|
|
+ log.error("导入异常", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return failRecords;
|
|
|
|
+ }
|
|
|
|
+ return failRecords;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void saveExamSite(ExamSiteEntity examSite) {
|
|
|
|
+ LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(ExamSiteEntity::getCode, examSite.getCode());
|
|
|
|
+ wrapper.eq(ExamSiteEntity::getCategoryId, examSite.getCategoryId());
|
|
|
|
+ ExamSiteEntity existSite = baseMapper.selectOne(wrapper);
|
|
|
|
+ if (existSite != null) {
|
|
|
|
+ existSite.setEnable(Boolean.TRUE);
|
|
|
|
+ existSite.setName(examSite.getName());
|
|
|
|
+ existSite.setAddress(examSite.getAddress());
|
|
|
|
+ baseMapper.updateById(existSite);
|
|
|
|
+ } else {
|
|
|
|
+ baseMapper.insert(examSite);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkExamSite(ExamSiteSaveReq req) {
|
|
|
|
+ if(StringUtils.isEmpty(req.getCode())) {
|
|
|
|
+ throw new StatusException("考点代码不能为空");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isEmpty(req.getName())) {
|
|
|
|
+ throw new StatusException("考点名称不能为空");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isEmpty(req.getAddress())) {
|
|
|
|
+ throw new StatusException("考点地址不能为空");
|
|
|
|
+ }
|
|
|
|
+ if(req.getCategoryId() == null) {
|
|
|
|
+ throw new StatusException("请选择考点所属教学点");
|
|
|
|
+ }
|
|
|
|
+ if(req.getEnable() == null) {
|
|
|
|
+ throw new StatusException("请选择考点状态");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String trimAndNullIfBlank(String s) {
|
|
|
|
+ if (StringUtils.isBlank(s)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return s.trim();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Map<String, Object> newError(int lineNum, String msg) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("lineNum", lineNum);
|
|
|
|
+ map.put("msg", msg);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|