Commit f0ac346f authored by Ryan Loong's avatar Ryan Loong

update 学生删 && 改

parent c7438bfe
......@@ -9,39 +9,41 @@ import cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportResultVo;
import cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportVo;
import cn.exploring.engine.server.db.domain.vo.StudentVo;
import cn.exploring.engine.server.db.util.SqlUtil;
import cn.exploring.engine.server.db.util.StrUtil;
import cn.exploring.engine.server.db.util.excel.ExcelReaderListener;
import cn.exploring.engine.server.db.util.excel.StudentInfoExcelReaderListener;
import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.SearchResult;
import cn.zhxu.bs.operator.*;
import cn.zhxu.bs.operator.Between;
import cn.zhxu.bs.operator.Contain;
import cn.zhxu.bs.operator.Equal;
import cn.zhxu.bs.operator.InList;
import cn.zhxu.bs.util.MapBuilder;
import cn.zhxu.bs.util.MapUtils;
import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOError;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public class StudentInfoService {
private static final Log log = LogFactory.getLog(StudentInfoService.class);
@Resource
StudentInfoMapper studentInfoMapper;
......@@ -92,13 +94,42 @@ public class StudentInfoService {
* @return
*/
public String updateStudentInfo(StudentInfo studentInfo) {
String logPrefix = StrUtil.format("[sessionId:{}]【更新学生信息】", UUID.randomUUID().toString().replace("-", ""));
log.info(StrUtil.format("{} 请求: '{}'", logPrefix, JSON.toJSONString(studentInfo)));
StudentInfo record = selectByPrimaryKey(studentInfo.getId());
if (Objects.isNull(record)) {
log.error(StrUtil.format("{} 查询失败"));
return "记录不存在";
}
StudentInfo studentInfo1 = selectStudentInfoByUniqueId(studentInfo.getStudentUniqueId());
if (studentInfo1 != null && !studentInfo1.getId().equals(studentInfo.getId())) {
return "Fail 学号重复! 请重新输入学号";
log.error(StrUtil.format("{} 学号重复 学号:'{}' 重复学生对象: '{}'",
logPrefix, studentInfo.getStudentUniqueId(), JSON.toJSONString(studentInfo1)));
return "学号重复! 请重新输入学号";
}
studentInfo.setUpdateTime(LocalDateTime.now());
studentInfoMapper.updateByPrimaryKey(studentInfo);
return "OK 修改成功";
if (StringUtils.isBlank(studentInfo.getHead())
|| StringUtils.equalsIgnoreCase(studentInfo.getHead().trim(), URL_DEFAULT_HEAD)
||StringUtils.equalsIgnoreCase(studentInfo.getHead().trim(), STRING_DEFAULT_HEAD)) {
studentInfo.setHead(STRING_DEFAULT_HEAD);
log.info(StrUtil.format("{} 配置为默认头像", logPrefix));
}
BeanUtils.copyProperties(studentInfo, record,
StudentInfo.Column.id.getJavaProperty(),
StudentInfo.Column.addTime.getJavaProperty(),
StudentInfo.Column.updateTime.getJavaProperty(),
StudentInfo.Column.deleted.getJavaProperty());
record.setUpdateTime(LocalDateTime.now());
studentInfoMapper.updateByPrimaryKey(record);
log.info(StrUtil.format("{} 更新完成: '{}'", logPrefix, JSON.toJSONString(record)));
return null;
}
/**
......@@ -107,14 +138,25 @@ public class StudentInfoService {
* @return
*/
@Transactional(rollbackFor = Exception.class)
public Object batchDeleted(List<Integer> idList) {
public String batchDeleted(List<Integer> idList) {
String logPrefix = StrUtil.format("[sessionId:{}]【删除学生】", UUID.randomUUID().toString().replace("-", ""));
log.info(StrUtil.format("{} 请求: {}", logPrefix, JSON.toJSONString(idList)));
List<StudentInfo> studentInfoList = selectStudentInfo(null, null, idList);
studentInfoList.forEach(x -> {
log.info(StrUtil.format("{} 查询到的学生记录: {}", logPrefix, JSON.toJSONString(studentInfoList)));
List<Integer> notExist = idList.stream().filter(i -> studentInfoList.stream().noneMatch(s -> Objects.equals(s.getId(), i))).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(notExist)) {
log.info(StrUtil.format("{} 存在无效学生 学生ID: {}", logPrefix, JSON.toJSONString(notExist)));
return "学生不存在";
}
LocalDateTime now = LocalDateTime.now();
int update = studentInfoMapper.batchUpsert(studentInfoList.stream().peek(x -> {
x.setUpdateTime(now);
x.setDeleted(null);
updateStudentInfo(x);
studentPointService.removeByStudentId(x.getId());
});
return "batch deleted OK";
}).collect(Collectors.toList()));
log.info(StrUtil.format("{} 删除成功 条目数量: '{}'", logPrefix, update));
return null;
}
/**
......@@ -300,7 +342,13 @@ public class StudentInfoService {
}).collect(Collectors.toList());
}
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public StudentInfo selectByPrimaryKey(Integer id) {
return Objects.nonNull(id) ? studentInfoMapper.selectOneByExample(new StudentInfoExample().createCriteria()
.andDeletedEqualTo(StudentInfo.NOT_DELETED)
.andIdEqualTo(id)
.example()) : null;
}
public List<StudentInfo> selectByPrimaryKey(Collection<Integer> idList) {
return CollectionUtils.isEmpty(idList) ? Collections.emptyList()
: studentInfoMapper.selectByExample(new StudentInfoExample().createCriteria()
......
package cn.exploring.engine.server.wx.web;
import cn.exploring.engine.server.core.util.ResponseUtil;
import cn.exploring.engine.server.db.domain.ClassInfo;
import cn.exploring.engine.server.db.domain.StudentInfo;
import cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportResultVo;
import cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportVo;
import cn.exploring.engine.server.db.service.ClassService;
import cn.exploring.engine.server.db.service.StudentInfoService;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -15,7 +15,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
......@@ -53,13 +52,14 @@ public class StudentController {
@PostMapping("update")
public Object update(@RequestBody StudentInfo studentInfo) {
String status = studentInfoService.updateStudentInfo(studentInfo);
return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(301, status);
String err = studentInfoService.updateStudentInfo(studentInfo);
return StringUtils.isNotBlank(err) ? ResponseUtil.fail(301, err) : ResponseUtil.ok("修改成功");
}
@PostMapping("batchDeleted")
public Object batchDeleted(@RequestBody List<Integer> idList) {
return ResponseUtil.ok(studentInfoService.batchDeleted(idList));
String err = studentInfoService.batchDeleted(idList);
return StringUtils.isNotBlank(err) ? ResponseUtil.fail(301, err) : ResponseUtil.ok("删除成功");
}
@PostMapping("import")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment