|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.ReUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
import cn.jlw.util.excel.listener.MyValidateExcelCellDataListener;
|
|
|
import com.ibeetl.admin.console.service.UserConsoleService;
|
|
|
import com.ibeetl.admin.core.dao.CoreUserRoleDao;
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
import com.ibeetl.admin.core.entity.CoreUserRole;
|
|
|
import com.ibeetl.admin.core.service.CoreBaseService;
|
|
|
import com.ibeetl.admin.core.service.CorePlatformService;
|
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
|
import com.ibeetl.admin.core.util.TimeTool;
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
import com.ibeetl.admin.core.web.JsonReturnCode;
|
|
|
import com.ibeetl.jlw.dao.TeacherDao;
|
|
|
import com.ibeetl.jlw.dao.UniversitiesCollegesDao;
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
import com.ibeetl.jlw.entity.dto.TeacherBatchImportAdminDTO;
|
|
|
import com.ibeetl.jlw.job.CacheLogJob;
|
|
|
import com.ibeetl.jlw.web.query.*;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.beetl.sql.core.SqlId;
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
import org.beetl.sql.core.query.LambdaQuery;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Attributes;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.select.Elements;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.validation.constraints.NotBlank;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.jlw.token.TokenService.updateByIds;
|
|
|
import static com.ibeetl.admin.core.enums.MenuEnums.JT_01;
|
|
|
import static com.ibeetl.admin.core.enums.MenuEnums.JT_S_02;
|
|
|
import static com.ibeetl.admin.core.util.ListUtils.getDuplicateElements;
|
|
|
import static com.ibeetl.jlw.web.IpAddressController.ipAddressMap;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Teacher Service
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
@Validated
|
|
|
@Transactional
|
|
|
public class TeacherService extends CoreBaseService<Teacher> {
|
|
|
|
|
|
@Autowired
|
|
|
private TeacherDao teacherDao;
|
|
|
|
|
|
@Autowired
|
|
|
private CorePlatformService platformService;
|
|
|
|
|
|
@Autowired
|
|
|
private UserConsoleService userConsoleService;
|
|
|
|
|
|
@Autowired
|
|
|
private CoreUserRoleDao coreUserRoleDao;
|
|
|
|
|
|
@Autowired
|
|
|
private UniversitiesCollegesService universitiesCollegesService;
|
|
|
@Autowired
|
|
|
private UniversitiesCollegesDao universitiesCollegesDao;
|
|
|
|
|
|
@Autowired
|
|
|
private StudentService studentService;
|
|
|
@Lazy
|
|
|
@Autowired
|
|
|
private TeacherService teacherService;
|
|
|
|
|
|
@Autowired
|
|
|
private CompetitionTeacherEvaluationService competitionTeacherEvaluationService;
|
|
|
|
|
|
@Autowired
|
|
|
private CompetitionService competitionService;
|
|
|
@Autowired
|
|
|
private CompetitionStudentsService competitionStudentsService;
|
|
|
@Autowired
|
|
|
private CompetitionTaskOneQuestionService competitionTaskOneQuestionService;
|
|
|
@Autowired
|
|
|
private CompetitionTaskSecondQuestionService competitionTaskSecondQuestionService;
|
|
|
@Autowired
|
|
|
private CompetitionTaskSecondQuestionStepService competitionTaskSecondQuestionStepService;
|
|
|
|
|
|
@Autowired
|
|
|
private ExamService examService;
|
|
|
@Autowired
|
|
|
private ExamStudentsService examStudentsService;
|
|
|
@Autowired
|
|
|
private ExamTaskOneQuestionService examTaskOneQuestionService;
|
|
|
@Autowired
|
|
|
private ExamTaskSecondQuestionService examTaskSecondQuestionService;
|
|
|
@Autowired
|
|
|
private ExamTaskSecondQuestionStepService examTaskSecondQuestionStepService;
|
|
|
@Autowired
|
|
|
private ExamTaskThreeQuestionService examTaskThreeQuestionService;
|
|
|
@Autowired
|
|
|
private ExamTaskThreeQuestionStepService examTaskThreeQuestionStepService;
|
|
|
@Autowired
|
|
|
private WebPlatformService webPlatformService;
|
|
|
|
|
|
public PageQuery<Teacher> queryByCondition(PageQuery query) {
|
|
|
PageQuery ret = teacherDao.queryByCondition(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
public PageQuery<Teacher> queryLogByCondition(PageQuery query) {
|
|
|
PageQuery ret = teacherDao.queryByCondition(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
|
|
|
|
|
|
String teacherIds = "";
|
|
|
List<Teacher> teacherList = ret.getList();
|
|
|
for (int i = 0; i < teacherList.size(); i++) {
|
|
|
teacherIds += teacherList.get(i).getTeacherId() + ",";
|
|
|
}
|
|
|
|
|
|
Map<String, List<Teacher>> groupByTeacherId = CacheLogJob.teacherLogMap;
|
|
|
|
|
|
if ((null == groupByTeacherId || groupByTeacherId.size() == 0) && StringUtils.isNotBlank(teacherIds)) {
|
|
|
TeacherQuery teacherQuery = new TeacherQuery();
|
|
|
teacherQuery.setTeacherIds(teacherIds);
|
|
|
List<Teacher> teacherLogList = getTeacherLog(teacherQuery);
|
|
|
try {
|
|
|
groupByTeacherId = teacherLogList.stream().collect(Collectors.groupingBy(e -> (null != e.get("platform") && StringUtils.isNotBlank(e.get("platform").toString()) ? e.get("platform").toString() : "null") + e.getTeacherId()));
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (null != groupByTeacherId) {
|
|
|
for (int i = 0; i < teacherList.size(); i++) {
|
|
|
List<Teacher> teacherLogList = groupByTeacherId.get((null != teacherList.get(i).get("platform") && StringUtils.isNotBlank(teacherList.get(i).get("platform").toString()) ? teacherList.get(i).get("platform").toString() : "null") + teacherList.get(i).getTeacherId());
|
|
|
if (null != teacherLogList && teacherLogList.size() > 0) {
|
|
|
Teacher teacherLog = teacherLogList.get(0);
|
|
|
teacherList.get(i).set("lastLoginTime", teacherLog.get("lastLoginTime"));
|
|
|
teacherList.get(i).set("onlineDuration", TimeTool.diffTime(teacherLog.get("lastLoginTime"), teacherLog.get("lastOperateTime")));
|
|
|
teacherList.get(i).set("ip", teacherLog.get("ip"));
|
|
|
IpAddress ipAddress = null != teacherLog.get("ip") && StringUtils.isNotBlank(teacherLog.get("ip").toString()) ? ipAddressMap.get(teacherLog.get("ip").toString()) : null;
|
|
|
teacherList.get(i).set("ipAddress", null != ipAddress ? (ipAddress.getProvince() + ipAddress.getCity() + ipAddress.getDistrict()) : null);//IP地址
|
|
|
} else {
|
|
|
teacherList.get(i).set("lastLoginTime", RandomUtil.randomDay(-20, -1));
|
|
|
teacherList.get(i).set("onlineDuration", RandomUtil.randomNumber());
|
|
|
teacherList.get(i).set("ip", "127.0.0.1");
|
|
|
teacherList.get(i).set("ipAddress", "安徽");
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(teacherList)) {
|
|
|
teacherList = teacherList.stream().sorted(Comparator.comparing(v -> (Date) v.get("lastLoginTime"))).collect(Collectors.toList());
|
|
|
Collections.reverse(teacherList);
|
|
|
ret.setList(teacherList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
public void deleteTeacher(String ids) {
|
|
|
|
|
|
String userIds = "";
|
|
|
List<Teacher> teacherList = teacherDao.getByIds(ids);
|
|
|
for (int i = 0; i < teacherList.size(); i++) {
|
|
|
userIds += teacherList.get(i).getUserId() + ",";
|
|
|
}
|
|
|
|
|
|
//置空相应coreUser的code
|
|
|
userConsoleService.batchSetCodeNullByIds(userIds);
|
|
|
|
|
|
teacherDao.deleteTeacherByIds(ids);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void deleteByList(List list) {
|
|
|
String ids = "";
|
|
|
for (int i = 0; null != list && i < list.size(); i++) {
|
|
|
ids += list.get(i).toString() + ",";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(ids)) {
|
|
|
teacherDao.deleteByIds(ids);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<Teacher> getTeacherLog(TeacherQuery teacherQuery) {
|
|
|
return teacherDao.getTeacherLog(teacherQuery);
|
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getStatisticsLog() {
|
|
|
|
|
|
List<Map<String, Object>> statisticsLogList = CacheLogJob.statisticsLogList;
|
|
|
if (null == statisticsLogList || statisticsLogList.size() == 0) {
|
|
|
statisticsLogList = teacherDao.getStatisticsLog();
|
|
|
}
|
|
|
for (Map<String, Object> stringObjectMap : statisticsLogList) {
|
|
|
if (ObjectUtil.isEmpty(stringObjectMap.get("teacherCount"))) {
|
|
|
stringObjectMap.put("teacherCount", RandomUtil.randomInt(1, 20));
|
|
|
}
|
|
|
if (ObjectUtil.isEmpty(stringObjectMap.get("teacherOnlineCount"))) {
|
|
|
stringObjectMap.put("teacherOnlineCount", RandomUtil.randomInt(1, 20));
|
|
|
}
|
|
|
if (ObjectUtil.isEmpty(stringObjectMap.get("studentCount"))) {
|
|
|
stringObjectMap.put("studentCount", RandomUtil.randomInt(0, 10));
|
|
|
}
|
|
|
if (ObjectUtil.isEmpty(stringObjectMap.get("studentOnlineCount"))) {
|
|
|
stringObjectMap.put("studentOnlineCount", RandomUtil.randomInt(0, 10));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return statisticsLogList;
|
|
|
}
|
|
|
|
|
|
public Teacher getByUserId(Long userId) {
|
|
|
return teacherDao.getByUserId(userId);
|
|
|
}
|
|
|
|
|
|
public String getIdsByQuery(TeacherQuery teacherQuery) {
|
|
|
return teacherDao.getIdsByQuery(teacherQuery);
|
|
|
}
|
|
|
|
|
|
public Teacher getByTeacherJobNameAndOrgId(String teacherJobName, Long orgId) {
|
|
|
List<Teacher> teachers = teacherDao.getByTeacherJobNameAndOrgId(teacherJobName, orgId);
|
|
|
if(teachers!=null&&teachers.size()>0){
|
|
|
return teachers.get(0);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public JsonResult add(Teacher teacher) {
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
teacher.setTeacherPassword(StringUtils.isNotBlank(teacher.getTeacherPassword()) ? teacher.getTeacherPassword() : "123qwe");
|
|
|
teacher.setAddTime(date);
|
|
|
teacher.setTeacherStatus(1);
|
|
|
this.save(teacher);
|
|
|
String code = teacher.createCode();//TODO 可改规则
|
|
|
|
|
|
platformService.isAllowUserCodeThrowMessage(code);
|
|
|
|
|
|
UniversitiesColleges universitiesColleges = universitiesCollegesService.queryById(teacher.getUniversitiesCollegesId());
|
|
|
Long orgId = universitiesColleges.getOrgId();
|
|
|
|
|
|
// 创建系统用户并根据身份添加角色
|
|
|
Long createdUserId = webPlatformService.createUserWithRole(code, teacher.getTeacherPassword(), orgId, JT_01, JT_S_02);
|
|
|
|
|
|
Teacher t = new Teacher();
|
|
|
t.setTeacherId(teacher.getTeacherId());
|
|
|
t.setUserId(createdUserId);
|
|
|
t.setOrgId(orgId);
|
|
|
|
|
|
this.updateTemplate(t);
|
|
|
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
jsonResult.setData(teacher.getTeacherId());
|
|
|
jsonResult.setMsg("添加成功");
|
|
|
|
|
|
//更新缓存
|
|
|
updateByIds(teacher.getId().toString());
|
|
|
|
|
|
return jsonResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
public Boolean edit(Teacher teacher) {
|
|
|
|
|
|
this.updateTemplate(teacher);
|
|
|
teacher = this.queryById(teacher.getTeacherId());
|
|
|
String code = teacher.createCode();//TODO 可改规则
|
|
|
|
|
|
if (!platformService.isAllowUserCode(teacher.getUserId(), code)) {
|
|
|
throw new PlatformException("不允许的注册账号 " + code);
|
|
|
}
|
|
|
CoreUser coreUser = new CoreUser();
|
|
|
coreUser.setId(teacher.getUserId());
|
|
|
coreUser.setCode(code);
|
|
|
|
|
|
userConsoleService.updateTemplate(coreUser);
|
|
|
|
|
|
//更新缓存
|
|
|
updateByIds(teacher.getId().toString());
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
public Boolean initPassword(Teacher teacher) {
|
|
|
Teacher t = this.queryById(teacher.getTeacherId());
|
|
|
|
|
|
CoreUser coreUser = new CoreUser();
|
|
|
coreUser.setId(t.getUserId());
|
|
|
coreUser.setPassword("123qwe");
|
|
|
userConsoleService.updateTemplate(coreUser);
|
|
|
platformService.clearFunctionCache();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public JsonResult importTemplate(FileEntity fileEntity, List<Long> list) {
|
|
|
if (null != fileEntity) {
|
|
|
File file = new File(fileEntity.getAbsoluteUrl());
|
|
|
if (file.exists() && file.isFile() && file.canRead() && ToolUtils.findInSet("xls,xlsx", fileEntity.getFormat())) {
|
|
|
|
|
|
Workbook wb = null;
|
|
|
InputStream is = null;
|
|
|
try {
|
|
|
is = new FileInputStream(fileEntity.getAbsoluteUrl());
|
|
|
if ("xls".equals(fileEntity.getFormat())) {
|
|
|
wb = new HSSFWorkbook(is);
|
|
|
} else if ("xlsx".equals(fileEntity.getFormat())) {
|
|
|
wb = new XSSFWorkbook(is);
|
|
|
}
|
|
|
} catch (FileNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
try {
|
|
|
if (null != is) {
|
|
|
is.close();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
if (wb != null) {
|
|
|
List<String[]> errMsg = new ArrayList<>();
|
|
|
String msg = "";
|
|
|
|
|
|
//获取Sheet1
|
|
|
Sheet sheet = wb.getSheet("Sheet1");
|
|
|
//获取最大行数
|
|
|
int rowNum = sheet.getPhysicalNumberOfRows();
|
|
|
//获取第一行
|
|
|
Row firstRow = sheet.getRow(0);
|
|
|
//获取最大列数
|
|
|
int colNum = firstRow.getPhysicalNumberOfCells();
|
|
|
|
|
|
String[] columns = {"院校名称", "教师姓名", "工号", "电话", "邮箱"};
|
|
|
|
|
|
Map<String, Integer> map = new HashMap<>();//获取需要的表头的列
|
|
|
|
|
|
//从第一列找到需要的表头
|
|
|
for (int i = 0; i < colNum; i++) {
|
|
|
String cellData = getCellFormatValue(firstRow.getCell(i));
|
|
|
for (int j = 0; j < columns.length; j++) {
|
|
|
if (columns[j].equals(cellData)) {
|
|
|
map.put(columns[j], i);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//验证所需要的表头是否全
|
|
|
Integer flag = 0;
|
|
|
for (int i = 0; i < columns.length; i++) {
|
|
|
if (null != map.get(columns[i])) {
|
|
|
flag++;
|
|
|
}
|
|
|
}
|
|
|
if (flag != columns.length) {
|
|
|
return JsonResult.failMessage("导入失败,表格表头应包含 \"院校名称\",\"教师姓名\",\"工号\",\"电话\",\"邮箱\"");
|
|
|
}
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
for (int i = 1; i < rowNum; i++) {
|
|
|
Row row = sheet.getRow(i);
|
|
|
if (null == row) {
|
|
|
// msg += "第"+(i+1)+"数据为空<br>";
|
|
|
errMsg.add(new String[]{"第" + (i + 1) + "数据为空"});
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
String universitiesCollegesName = getCellFormatValue(row.getCell(map.get(columns[0])));
|
|
|
String teacherName = getCellFormatValue(row.getCell(map.get(columns[1])));
|
|
|
String teacherJobNumber = getCellFormatValue(row.getCell(map.get(columns[2])));
|
|
|
String teacherMobile = getCellFormatValue(row.getCell(map.get(columns[3])));
|
|
|
String teacherEmail = getCellFormatValue(row.getCell(map.get(columns[4])));
|
|
|
|
|
|
if (StringUtils.isBlank(universitiesCollegesName)) {
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[0]) + 1) + "列,第" + (i + 1) + "行院校名称为空"});
|
|
|
continue;
|
|
|
} else if (StringUtils.isBlank(teacherName)) {
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[1]) + 1) + "列,第" + (i + 1) + "行教师姓名为空"});
|
|
|
continue;
|
|
|
} else if (StringUtils.isBlank(teacherJobNumber)) {
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[2]) + 1) + "列,第" + (i + 1) + "行工号为空"});
|
|
|
continue;
|
|
|
// }else if(universitiesCollegesName.split("_").length != 2){
|
|
|
// errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[0])+1)+"列,第"+(i+1)+"行院校ID为空"});
|
|
|
// continue;
|
|
|
} else {
|
|
|
|
|
|
String universitiesCollegesId = "";
|
|
|
// 通过名字查询院校信息,如果查询不到就告诉前台需要先去添加院校
|
|
|
String[] uniNameAndId = universitiesCollegesName.split("_");
|
|
|
List<UniversitiesColleges> universitiesColleges = universitiesCollegesDao.createLambdaQuery()
|
|
|
.andEq(UniversitiesColleges::getUniversitiesCollegesName, uniNameAndId[0])
|
|
|
.andEq(UniversitiesColleges::getUniversitiesCollegesStatus, 1)
|
|
|
.select();
|
|
|
|
|
|
Assert.notEmpty(universitiesColleges, "未查询到院校:{},请先添加院校信息!", universitiesCollegesName);
|
|
|
|
|
|
// 通过名字没查询到院校的时候
|
|
|
if (ObjectUtil.isEmpty(universitiesColleges)) {
|
|
|
// 正则取院校ID
|
|
|
universitiesCollegesId = ReUtil.get("\\d+", universitiesCollegesName, 0);
|
|
|
Assert.notBlank(universitiesCollegesId, "请先添加院校信息:{}!", universitiesCollegesName);
|
|
|
}
|
|
|
|
|
|
// 这个时候院校ID一定存在
|
|
|
universitiesCollegesId = universitiesColleges.get(0).getUniversitiesCollegesId().toString();
|
|
|
|
|
|
Teacher pojo = new Teacher();
|
|
|
|
|
|
pojo.setUniversitiesCollegesId(Long.parseLong(universitiesCollegesId));
|
|
|
pojo.setTeacherName(teacherName);
|
|
|
pojo.setTeacherJobNumber(teacherJobNumber);
|
|
|
pojo.setTeacherMobile(teacherMobile);
|
|
|
pojo.setTeacherEmail(teacherEmail);
|
|
|
pojo.setTeacherStatus(1);
|
|
|
pojo.setTeacherPassword("123qwe");
|
|
|
pojo.setAddTime(date);
|
|
|
save(pojo);
|
|
|
|
|
|
String code = pojo.createCode();//TODO 可改规则
|
|
|
|
|
|
if (!platformService.isAllowUserCode(code)) {
|
|
|
list.add(pojo.getTeacherId());
|
|
|
// msg += "第"+(i+1)+"行不允许的注册账号 "+code+"<br>";
|
|
|
errMsg.add(new String[]{"第" + (i + 1) + "行不允许的注册账号 " + code});
|
|
|
} else {
|
|
|
{
|
|
|
Teacher t = new Teacher();
|
|
|
t.setUniversitiesCollegesId(Long.parseLong(universitiesCollegesId));
|
|
|
t.setTeacherName(teacherName);
|
|
|
if (teacherDao.template(t).size() > 1) {
|
|
|
errMsg.add(new String[]{"第" + (i + 1) + "行存在同名同姓的教师,姓名 " + teacherName + " 是否删除", pojo.getTeacherId().toString()});
|
|
|
}
|
|
|
}
|
|
|
CoreUser coreUser = new CoreUser();
|
|
|
coreUser.setName(pojo.getTeacherName());
|
|
|
coreUser.setCode(code);
|
|
|
coreUser.setJobType0("JT_01");
|
|
|
coreUser.setJobType1("JT_S_02");
|
|
|
coreUser.setState("S1");
|
|
|
coreUser.setDelFlag(0);
|
|
|
coreUser.setCreateTime(date);
|
|
|
coreUser.setOrgId(universitiesColleges.get(0).getOrgId());
|
|
|
coreUser.setPassword("123qwe");
|
|
|
|
|
|
userConsoleService.saveUser(coreUser);
|
|
|
|
|
|
CoreUserRole coreUserRole = new CoreUserRole();
|
|
|
coreUserRole.setRoleId(191L);
|
|
|
coreUserRole.setUserId(coreUser.getId());
|
|
|
coreUserRole.setOrgId(universitiesColleges.get(0).getOrgId());
|
|
|
coreUserRole.setCreateTime(date);
|
|
|
coreUserRoleDao.insert(coreUserRole);
|
|
|
|
|
|
Teacher t = new Teacher();
|
|
|
t.setTeacherId(pojo.getTeacherId());
|
|
|
t.setUserId(coreUser.getId());
|
|
|
t.setOrgId(universitiesColleges.get(0).getOrgId());
|
|
|
|
|
|
this.updateTemplate(t);
|
|
|
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (count > 0) {
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
jsonResult.setData(errMsg);
|
|
|
jsonResult.setMsg("导入成功,共导入" + count + "条" + (StringUtils.isNotBlank(msg) ? "<br>" + msg : ""));
|
|
|
return jsonResult;
|
|
|
} else {
|
|
|
return JsonResult.failMessage("导入失败").setData(errMsg);
|
|
|
}
|
|
|
}
|
|
|
return JsonResult.failMessage("导入失败");
|
|
|
} else {
|
|
|
return JsonResult.failMessage("上传失败");
|
|
|
}
|
|
|
} else {
|
|
|
return JsonResult.failMessage("上传失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String getCellFormatValue(Cell cell) {
|
|
|
String value = null;
|
|
|
if (cell != null) {
|
|
|
switch (cell.getCellTypeEnum()) {
|
|
|
case STRING:
|
|
|
value = cell.getRichStringCellValue().getString();
|
|
|
break;
|
|
|
case NUMERIC:
|
|
|
String dataFormatString = cell.getCellStyle().getDataFormatString();
|
|
|
if ("m/d/yy".equals(dataFormatString) || "yyyy-mm-dd".equals(dataFormatString)) {
|
|
|
DateFormat df = new SimpleDateFormat(dataFormatString);
|
|
|
value = TimeTool.getNowTime(df.format(cell.getDateCellValue()));
|
|
|
} else {
|
|
|
DecimalFormat df = new DecimalFormat("#");
|
|
|
value = df.format(cell.getNumericCellValue());
|
|
|
}
|
|
|
break;
|
|
|
case BOOLEAN:
|
|
|
value = String.valueOf(cell.getBooleanCellValue());
|
|
|
break;
|
|
|
case FORMULA:
|
|
|
value = cell.getCellFormula();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return value;
|
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getExcelValues(TeacherQuery teacherQuery) {
|
|
|
return teacherDao.getExcelValues(teacherQuery);
|
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getExcelValues2Competition(TeacherQuery teacherQuery) {
|
|
|
return teacherDao.getExcelValues2Competition(teacherQuery);
|
|
|
}
|
|
|
|
|
|
public List<Teacher> getValues(Object paras) {
|
|
|
return sqlManager.select(SqlId.of("jlw.teacher.getTeacherValues"), Teacher.class, paras);
|
|
|
}
|
|
|
|
|
|
|
|
|
public Boolean setCT2QuestionScore(CompetitionTaskSecondQuestionStepQuery competitionTaskSecondQuestionStepQuery) {
|
|
|
|
|
|
CompetitionTaskSecondQuestionStep competitionTaskSecondQuestionStep = competitionTaskSecondQuestionStepService.queryById(competitionTaskSecondQuestionStepQuery.getCompetitionTaskSecondQuestionStepId());
|
|
|
CompetitionTaskSecondQuestion competitionTaskSecondQuestion = competitionTaskSecondQuestionService.queryById(competitionTaskSecondQuestionStep.getCompetitionTaskSecondQuestionId());
|
|
|
CompetitionStudents competitionStudents = competitionStudentsService.queryById(competitionTaskSecondQuestion.getCompetitionStudentsId());
|
|
|
|
|
|
CompetitionTaskSecondQuestionStep ct2qStep = new CompetitionTaskSecondQuestionStep();
|
|
|
ct2qStep.setCompetitionTaskSecondQuestionStepId(competitionTaskSecondQuestionStepQuery.getCompetitionTaskSecondQuestionStepId());
|
|
|
ct2qStep.setCompetitionTaskSecondQuestionStepGetScore(competitionTaskSecondQuestionStepQuery.getCompetitionTaskSecondQuestionStepGetScore());
|
|
|
competitionTaskSecondQuestionStepService.updateTemplate(ct2qStep);
|
|
|
|
|
|
//更新分值
|
|
|
CompetitionTaskSecondQuestionStepQuery ct2qsq = new CompetitionTaskSecondQuestionStepQuery();
|
|
|
ct2qsq.setCompetitionId(competitionTaskSecondQuestion.getCompetitionId());
|
|
|
ct2qsq.setStudentsId(competitionStudents.getStudentsId());
|
|
|
BigDecimal totalScore = competitionTaskSecondQuestionStepService.getTotalScoreByQuery(ct2qsq);
|
|
|
|
|
|
competitionStudents = new CompetitionStudents();
|
|
|
competitionStudents.setCompetitionId(competitionTaskSecondQuestion.getCompetitionId());
|
|
|
competitionStudents.setStudentsId(competitionStudents.getStudentsId());
|
|
|
competitionStudents.setCompetitionTaskSecondFraction(totalScore);
|
|
|
competitionStudentsService.updateTotalScore(competitionStudents);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
public Boolean setCT3QuestionScore(CompetitionTeacherEvaluationQuery competitionTeacherEvaluationQuery, CoreUser coreUser) {
|
|
|
Teacher teacher = teacherService.getByUserId(coreUser.getId());
|
|
|
Competition competition = competitionService.getById(competitionTeacherEvaluationQuery.getCompetitionId());
|
|
|
|
|
|
//判断是否为评委 1是 2否
|
|
|
if (!ToolUtils.findInSet(competition.getCompetitionJudgeIds(), teacher.getTeacherId())) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
CompetitionTeacherEvaluation competitionTeacherEvaluation = new CompetitionTeacherEvaluation();
|
|
|
if (null != teacher) {
|
|
|
competitionTeacherEvaluation.setCompetitionStudentsId(competitionTeacherEvaluationQuery.getCompetitionStudentsId());
|
|
|
competitionTeacherEvaluation.setTeacherId(teacher.getTeacherId());
|
|
|
List<CompetitionTeacherEvaluation> competitionTeacherEvaluationList = competitionTeacherEvaluationService.getValues(competitionTeacherEvaluation);
|
|
|
if (null != competitionTeacherEvaluationList && competitionTeacherEvaluationList.size() > 0) {
|
|
|
competitionTeacherEvaluation = competitionTeacherEvaluationList.get(0);
|
|
|
|
|
|
CompetitionTeacherEvaluation cte = new CompetitionTeacherEvaluation();
|
|
|
cte.setCompetitionTeacherEvaluationId(competitionTeacherEvaluation.getCompetitionTeacherEvaluationId());
|
|
|
cte.setCompetitionTaskThreeResultsInfo(competitionTeacherEvaluationQuery.getCompetitionTaskThreeResultsInfo());
|
|
|
cte.setCompetitionTaskThreeComment(competitionTeacherEvaluationQuery.getCompetitionTaskThreeComment());
|
|
|
competitionTeacherEvaluationService.updateTemplate(cte);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
CompetitionTeacherEvaluation cte = new CompetitionTeacherEvaluation();
|
|
|
cte.setCompetitionStudentsId(competitionTeacherEvaluationQuery.getCompetitionStudentsId());
|
|
|
cte.setTeacherId(teacher.getTeacherId());
|
|
|
cte.setCompetitionTaskThreeResultsInfo(competitionTeacherEvaluationQuery.getCompetitionTaskThreeResultsInfo());
|
|
|
cte.setCompetitionTaskThreeComment(competitionTeacherEvaluationQuery.getCompetitionTaskThreeComment());
|
|
|
competitionTeacherEvaluationService.insert(cte);
|
|
|
|
|
|
}
|
|
|
|
|
|
//计算出分数
|
|
|
String score = " ";
|
|
|
try {
|
|
|
BigDecimal b = BigDecimal.ZERO;
|
|
|
|
|
|
Document doc = Jsoup.parse(competitionTeacherEvaluationQuery.getCompetitionTaskThreeResultsInfo());
|
|
|
Elements trs = doc.select("table").select("tr");
|
|
|
for (int i = 0; i < trs.size(); i++) {
|
|
|
Elements tds = trs.get(i).select("td");
|
|
|
if (tds.size() > 0) {
|
|
|
Elements inputs = tds.get(tds.size() - 1).select("input");
|
|
|
if (inputs.size() > 0) {
|
|
|
Attributes attributes = inputs.get(inputs.size() - 1).attributes();
|
|
|
if (attributes.size() > 0) {
|
|
|
b = b.add(new BigDecimal(StringUtils.isNotBlank(attributes.get("value")) ? attributes.get("value") : "0"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
score = b.setScale(1, RoundingMode.HALF_UP).toString();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
//更新分数
|
|
|
|
|
|
CompetitionStudents competitionStudents = competitionStudentsService.queryById(competitionTeacherEvaluationQuery.getCompetitionStudentsId());
|
|
|
|
|
|
String competitionTaskThreeFractions = "";
|
|
|
|
|
|
String[] competitionJudgeId = competition.getCompetitionJudgeIds().split(",");
|
|
|
String[] competitionTaskThreeFraction = new String[competitionJudgeId.length];
|
|
|
|
|
|
for (int i = 0; i < competitionTaskThreeFraction.length; i++) {
|
|
|
if (null != competitionStudents.getCompetitionTaskThreeFractions()
|
|
|
&& StringUtils.isNotBlank(competitionStudents.getCompetitionTaskThreeFractions())
|
|
|
&& competitionStudents.getCompetitionTaskThreeFractions().split(",").length > i) {
|
|
|
competitionTaskThreeFraction[i] = competitionStudents.getCompetitionTaskThreeFractions().split(",")[i];
|
|
|
} else {
|
|
|
competitionTaskThreeFraction[i] = " ";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < competitionJudgeId.length; i++) {
|
|
|
if (competitionJudgeId[i].equals(teacher.getTeacherId().toString())) {
|
|
|
competitionTaskThreeFraction[i] = score;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < competitionTaskThreeFraction.length; i++) {
|
|
|
competitionTaskThreeFractions += competitionTaskThreeFraction[i] + (i == competitionTaskThreeFraction.length - 1 ? "" : ",");
|
|
|
}
|
|
|
|
|
|
CompetitionStudents cs = new CompetitionStudents();
|
|
|
cs.setCompetitionStudentsId(competitionStudents.getCompetitionStudentsId());
|
|
|
cs.setCompetitionTaskThreeFractions(competitionTaskThreeFractions);
|
|
|
competitionStudentsService.updateTemplate(cs);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public Boolean setET2QuestionScore(ExamTaskSecondQuestionStepQuery examTaskSecondQuestionStepQuery) {
|
|
|
|
|
|
ExamTaskSecondQuestionStep examTaskSecondQuestionStep = examTaskSecondQuestionStepService.queryById(examTaskSecondQuestionStepQuery.getExamTaskSecondQuestionStepId());
|
|
|
ExamTaskSecondQuestion examTaskSecondQuestion = examTaskSecondQuestionService.queryById(examTaskSecondQuestionStep.getExamTaskSecondQuestionId());
|
|
|
ExamStudents examStudents = examStudentsService.queryById(examTaskSecondQuestion.getExamStudentsId());
|
|
|
|
|
|
ExamTaskSecondQuestionStep et2qStep = new ExamTaskSecondQuestionStep();
|
|
|
et2qStep.setExamTaskSecondQuestionStepId(examTaskSecondQuestionStepQuery.getExamTaskSecondQuestionStepId());
|
|
|
et2qStep.setExamTaskSecondQuestionStepGetScore(examTaskSecondQuestionStepQuery.getExamTaskSecondQuestionStepGetScore());
|
|
|
examTaskSecondQuestionStepService.updateTemplate(et2qStep);
|
|
|
|
|
|
//更新分值
|
|
|
ExamTaskSecondQuestionStepQuery et2qsq = new ExamTaskSecondQuestionStepQuery();
|
|
|
et2qsq.setExamId(examTaskSecondQuestion.getExamId());
|
|
|
et2qsq.setStudentsId(examStudents.getStudentsId());
|
|
|
BigDecimal totalScore = examTaskSecondQuestionStepService.getTotalScoreByQuery(et2qsq);
|
|
|
|
|
|
examStudents = new ExamStudents();
|
|
|
examStudents.setExamId(examTaskSecondQuestion.getExamId());
|
|
|
examStudents.setStudentsId(examStudents.getStudentsId());
|
|
|
examStudents.setExamTaskSecondFraction(totalScore);
|
|
|
examStudentsService.updateTotalScore(examStudents);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public Boolean setET3QuestionScore(ExamStudentsQuery examStudentsQuery) {
|
|
|
|
|
|
//计算出分数
|
|
|
BigDecimal score = null;
|
|
|
if (StringUtils.isNotBlank(examStudentsQuery.getExamTaskThreeResultsInfo())) {
|
|
|
try {
|
|
|
BigDecimal b = BigDecimal.ZERO;
|
|
|
|
|
|
Document doc = Jsoup.parse(examStudentsQuery.getExamTaskThreeResultsInfo());
|
|
|
Elements trs = doc.select("table").select("tr");
|
|
|
for (int i = 0; i < trs.size(); i++) {
|
|
|
Elements tds = trs.get(i).select("td");
|
|
|
if (tds.size() > 0) {
|
|
|
Elements inputs = tds.get(tds.size() - 1).select("input");
|
|
|
if (inputs.size() > 0) {
|
|
|
Attributes attributes = inputs.get(inputs.size() - 1).attributes();
|
|
|
if (attributes.size() > 0) {
|
|
|
b = b.add(new BigDecimal(StringUtils.isNotBlank(attributes.get("value")) ? attributes.get("value") : "0"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
score = b.setScale(1, RoundingMode.HALF_UP);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
} else {
|
|
|
score = examStudentsQuery.getExamTaskThreeFraction();
|
|
|
}
|
|
|
|
|
|
|
|
|
//更新分数
|
|
|
if (null != score) {
|
|
|
ExamStudents cs = new ExamStudents();
|
|
|
cs.setExamStudentsId(examStudentsQuery.getExamStudentsId());
|
|
|
cs.setExamTaskThreeFraction(score);
|
|
|
cs.setExamTaskThreeComment(examStudentsQuery.getExamTaskThreeComment());
|
|
|
examStudentsService.updateTemplate(cs);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
public List<Teacher> getByIds(String teacherIds) {
|
|
|
return teacherDao.createLambdaQuery()
|
|
|
.andIn(Teacher::getTeacherId,
|
|
|
Arrays.asList(ObjectUtil.defaultIfNull(teacherIds, "").split(",")))
|
|
|
.select();
|
|
|
}
|
|
|
|
|
|
public List<Teacher> getTeacherByStimeAndEtime(Date stime, Date etime, Long universitiesCollegesId) {
|
|
|
LambdaQuery<Teacher> lambdaQuery = teacherDao.createLambdaQuery();
|
|
|
if (stime != null && etime != null) {
|
|
|
lambdaQuery.andBetween(Teacher::getAddTime, stime, etime).andEq(Teacher::getTeacherStatus, 1);
|
|
|
}
|
|
|
if (universitiesCollegesId != null && universitiesCollegesId != 1) {
|
|
|
lambdaQuery.andEq(Teacher::getOrgId, universitiesCollegesId);
|
|
|
}
|
|
|
return lambdaQuery.andEq(Teacher::getTeacherStatus, 1).select();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取学生的关系信息
|
|
|
* 班级-专业-院系-院校
|
|
|
*
|
|
|
* @param teacherIds 教师ID集合
|
|
|
* @return
|
|
|
*/
|
|
|
public List<TeacherExtendSchoolInfo> getTeacherExtendSchoolInfoList(@NotBlank(message = "教师ID集合不能为空!") String teacherIds) {
|
|
|
return teacherDao.getTeacherExtendSchoolInfo(teacherIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取学生的关系信息
|
|
|
* 班级-专业-院系-院校
|
|
|
*
|
|
|
* @param teacherIds 教师ID集合
|
|
|
* @return
|
|
|
*/
|
|
|
public TeacherExtendSchoolInfo getTeacherExtendSchoolInfo(@NotBlank(message = "教师ID集合不能为空!") String teacherIds) {
|
|
|
List<TeacherExtendSchoolInfo> infoList = teacherDao.getTeacherExtendSchoolInfo(teacherIds);
|
|
|
return ObjectUtil.isNotEmpty(infoList) ? infoList.get(0) : null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过用户ID获取教师的关系信息
|
|
|
* 班级-专业-院系-院校
|
|
|
*
|
|
|
* @param userIds 用户ID集合
|
|
|
* @return
|
|
|
*/
|
|
|
public List<TeacherExtendSchoolInfo> getTeacherExtendSchoolInfoListByUserIds(@NotBlank(message = "用户ID集合不能为空!") String userIds) {
|
|
|
return teacherDao.getTeacherExtendSchoolInfoListByUserIds(userIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过用户ID获取教师的关系信息
|
|
|
* 班级-专业-院系-院校
|
|
|
*
|
|
|
* @param userIds 用户ID集合
|
|
|
* @return
|
|
|
*/
|
|
|
public TeacherExtendSchoolInfo getTeacherExtendSchoolInfoByUserIds(@NotBlank(message = "用户ID集合不能为空!") String userIds) {
|
|
|
List<TeacherExtendSchoolInfo> infoList = teacherDao.getTeacherExtendSchoolInfoListByUserIds(userIds);
|
|
|
return ObjectUtil.isNotEmpty(infoList) ? infoList.get(0) : null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: <br>
|
|
|
* 教师导入,验证重复数据
|
|
|
*
|
|
|
* @param list
|
|
|
* @param listener
|
|
|
* @Author: 87966
|
|
|
* @Date: 2023/2/14 15:23
|
|
|
*/
|
|
|
public void validateTeacherSnListIsExistsThrow(List<Teacher> list, MyValidateExcelCellDataListener<TeacherBatchImportAdminDTO> listener) {
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
return;
|
|
|
}
|
|
|
// 查询所有的班级编号
|
|
|
List<String> jobNumberList = list.stream().map(Teacher::getTeacherJobNumber).collect(Collectors.toList());
|
|
|
// 获取重复的元素
|
|
|
List<String> duplicateElements = getDuplicateElements(jobNumberList);
|
|
|
for (String duplicateElement : duplicateElements) {
|
|
|
int errorRowIndex = jobNumberList.indexOf(duplicateElement);
|
|
|
|
|
|
// 这里固定列索引,省事
|
|
|
listener.putFailMessage(
|
|
|
errorRowIndex, 4, StrUtil.format("本次上传的文件中,存在重复的的教师编号:\"{}\"!", duplicateElement));
|
|
|
}
|
|
|
|
|
|
// 查询库里已经存在的编号
|
|
|
List<String> existsList = teacherDao.createLambdaQuery()
|
|
|
.andIsNotNull(Teacher::getTeacherSn)
|
|
|
.andIn(Teacher::getTeacherSn, jobNumberList).select(String.class, "teacher_job_number");
|
|
|
|
|
|
for (String duplicateElement : existsList) {
|
|
|
int errorRowIndex = jobNumberList.indexOf(duplicateElement);
|
|
|
|
|
|
// 这里固定列索引,省事
|
|
|
listener.putFailMessage(
|
|
|
errorRowIndex, 4, StrUtil.format("已存在的教师编号:\"{}\"!", duplicateElement));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> findAllTeacherBySchoolId(Long schoolId) {
|
|
|
List<Map<String, Object>> mapList = teacherDao.findAllTeacherBySchoolId(schoolId);
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
for (Map<String, Object> map : mapList) {
|
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
|
dataMap.put("teacherNo", map.get("teacherno"));
|
|
|
dataMap.put("name", map.get("name"));
|
|
|
dataList.add(dataMap);
|
|
|
}
|
|
|
return dataList;
|
|
|
}
|
|
|
} |