|
|
@@ -0,0 +1,253 @@
|
|
|
+/*
|
|
|
+ * Copyright [2022] [https://www.xiaonuo.vip]
|
|
|
+ *
|
|
|
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
|
+ *
|
|
|
+ * 1.请不要删除和修改根目录下的LICENSE文件。
|
|
|
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
|
|
|
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
|
|
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
|
|
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
|
|
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
|
|
+ */
|
|
|
+package vip.xiaonuo.disk.service.impl;
|
|
|
+
|
|
|
+import cn.afterturn.easypoi.cache.manager.POICacheManager;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollStreamUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import vip.xiaonuo.common.enums.CommonSortOrderEnum;
|
|
|
+import vip.xiaonuo.common.exception.CommonException;
|
|
|
+import vip.xiaonuo.common.page.CommonPageRequest;
|
|
|
+import vip.xiaonuo.common.util.CommonDownloadUtil;
|
|
|
+import vip.xiaonuo.common.util.CommonResponseUtil;
|
|
|
+import vip.xiaonuo.disk.domain.CourseStudentRelate;
|
|
|
+import vip.xiaonuo.disk.domain.ResourceRecordUserRelate;
|
|
|
+import vip.xiaonuo.disk.mapper.CourseStudentRelateMapper;
|
|
|
+import vip.xiaonuo.disk.param.coursestudentrelate.*;
|
|
|
+import vip.xiaonuo.disk.service.CourseStudentRelateService;
|
|
|
+import vip.xiaonuo.sys.modular.user.entity.SysUser;
|
|
|
+import vip.xiaonuo.sys.modular.user.param.SysUserImportParam;
|
|
|
+import vip.xiaonuo.sys.modular.user.param.SysUserPageParam;
|
|
|
+import vip.xiaonuo.sys.modular.user.service.SysUserService;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 课程学生关联表Service接口实现类
|
|
|
+ *
|
|
|
+ * @author honorfire
|
|
|
+ * @date 2025/07/12 11:04
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class CourseStudentRelateServiceImpl extends ServiceImpl<CourseStudentRelateMapper, CourseStudentRelate> implements CourseStudentRelateService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CourseStudentRelateMapper courseStudentRelateMapper;
|
|
|
+ @Resource
|
|
|
+ private SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<CourseStudentRelate> page(CourseStudentRelatePageParam courseStudentRelatePageParam) {
|
|
|
+ QueryWrapper<CourseStudentRelate> queryWrapper = new QueryWrapper<>();
|
|
|
+ if(ObjectUtil.isAllNotEmpty(courseStudentRelatePageParam.getSortField(), courseStudentRelatePageParam.getSortOrder())) {
|
|
|
+ CommonSortOrderEnum.validate(courseStudentRelatePageParam.getSortOrder());
|
|
|
+ queryWrapper.orderBy(true, courseStudentRelatePageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
|
|
|
+ StrUtil.toUnderlineCase(courseStudentRelatePageParam.getSortField()));
|
|
|
+ } else {
|
|
|
+ queryWrapper.lambda().orderByAsc(CourseStudentRelate::getId);
|
|
|
+ }
|
|
|
+ return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CourseStudentRelate> listWrapper(Map param) {
|
|
|
+ QueryWrapper<CourseStudentRelate> queryWrapper = new QueryWrapper<>();
|
|
|
+ if (ObjectUtil.isNotEmpty(param.get("userId"))) {
|
|
|
+ queryWrapper.lambda().eq(CourseStudentRelate::getUserId, param.get("userId"));
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(param.get("courseId"))) {
|
|
|
+ queryWrapper.lambda().eq(CourseStudentRelate::getCourseId, param.get("courseId"));
|
|
|
+ }
|
|
|
+ return this.list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(CourseStudentRelateAddParam courseStudentRelateAddParam) {
|
|
|
+ CourseStudentRelate courseStudentRelate = BeanUtil.toBean(courseStudentRelateAddParam, CourseStudentRelate.class);
|
|
|
+ this.save(courseStudentRelate);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public CourseStudentRelate addOne(CourseStudentRelate courseStudentRelate) {
|
|
|
+ this.save(courseStudentRelate);
|
|
|
+ return courseStudentRelate;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void addBatch(List<CourseStudentRelate> courseStudentRelateList)
|
|
|
+ {
|
|
|
+ this.saveBatch(courseStudentRelateList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(CourseStudentRelateEditParam courseStudentRelateEditParam) {
|
|
|
+ CourseStudentRelate courseStudentRelate = this.queryEntity(courseStudentRelateEditParam.getId());
|
|
|
+ BeanUtil.copyProperties(courseStudentRelateEditParam, courseStudentRelate);
|
|
|
+ this.updateById(courseStudentRelate);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public CourseStudentRelate editOne(CourseStudentRelate courseStudentRelate) {
|
|
|
+ this.updateById(courseStudentRelate);
|
|
|
+ return courseStudentRelate;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(List<CourseStudentRelateIdParam> courseStudentRelateIdParamList) {
|
|
|
+ // 执行删除
|
|
|
+ this.removeByIds(CollStreamUtil.toList(courseStudentRelateIdParamList, CourseStudentRelateIdParam::getId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CourseStudentRelate detail(CourseStudentRelateIdParam courseStudentRelateIdParam) {
|
|
|
+ return this.queryEntity(courseStudentRelateIdParam.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CourseStudentRelate queryEntity(String id) {
|
|
|
+ CourseStudentRelate courseStudentRelate = this.getById(id);
|
|
|
+ if(ObjectUtil.isEmpty(courseStudentRelate)) {
|
|
|
+ throw new CommonException("课程学生关联表不存在,id值为:{}", id);
|
|
|
+ }
|
|
|
+ return courseStudentRelate;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<Map<String,Object>> queryList(Map param)
|
|
|
+ {
|
|
|
+ return courseStudentRelateMapper.queryList(param,CommonPageRequest.defaultPage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String,Object> queryInfo(Map param)
|
|
|
+ {
|
|
|
+ return courseStudentRelateMapper.queryInfo(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public JSONObject importInfo(MultipartFile file,String courseId) {
|
|
|
+ try {
|
|
|
+ int successCount = 0;
|
|
|
+ int errorCount = 0;
|
|
|
+ JSONArray errorDetail = JSONUtil.createArray();
|
|
|
+ // 创建临时文件
|
|
|
+ File tempFile = FileUtil.writeBytes(file.getBytes(), FileUtil.file(FileUtil.getTmpDir() +
|
|
|
+ FileUtil.FILE_SEPARATOR + "CourseStudentRelateImportTemplate.xlsx"));
|
|
|
+ // 读取excel
|
|
|
+ List<CourseStudentRelateImportParam> relateImportParamList = EasyExcel.read(tempFile).head(CourseStudentRelateImportParam.class).sheet()
|
|
|
+ .headRowNumber(2).doReadSync();
|
|
|
+ QueryWrapper<CourseStudentRelate> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CourseStudentRelate::getCourseId, courseId);
|
|
|
+ List<CourseStudentRelate> allRelateList = this.list(queryWrapper);
|
|
|
+ for (int i = 0; i < relateImportParamList.size(); i++) {
|
|
|
+ JSONObject jsonObject = this.doImport(allRelateList, relateImportParamList.get(i), i,courseId);
|
|
|
+ if(jsonObject.getBool("success")) {
|
|
|
+ successCount += 1;
|
|
|
+ } else {
|
|
|
+ errorCount += 1;
|
|
|
+ errorDetail.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return JSONUtil.createObj()
|
|
|
+ .set("totalCount", relateImportParamList.size())
|
|
|
+ .set("successCount", successCount)
|
|
|
+ .set("errorCount", errorCount)
|
|
|
+ .set("errorDetail", errorDetail);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(">>> 用户导入失败:", e);
|
|
|
+ throw new CommonException("用户导入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行导入
|
|
|
+ **/
|
|
|
+ public JSONObject doImport(List<CourseStudentRelate> allRelateList, CourseStudentRelateImportParam courseStudentRelateImportParam, int i,String courseId) {
|
|
|
+ if(StringUtils.isEmpty(courseStudentRelateImportParam.getAcount()) || StringUtils.isEmpty(courseStudentRelateImportParam.getUserName()))
|
|
|
+ {
|
|
|
+ return JSONUtil.createObj().set("success", false)
|
|
|
+ .set("index", i + 1)
|
|
|
+ .set("message", "账号及姓名不能为空");
|
|
|
+ }
|
|
|
+ //用账号及姓名,查询人员信息
|
|
|
+ SysUserPageParam sysUserPageParam=new SysUserPageParam();
|
|
|
+ sysUserPageParam.setAccount(courseStudentRelateImportParam.getAcount());
|
|
|
+ sysUserPageParam.setName(courseStudentRelateImportParam.getUserName());
|
|
|
+ List<SysUser> sysUserList = sysUserService.queryAllList(sysUserPageParam);
|
|
|
+ if(sysUserList.size()==0)
|
|
|
+ {
|
|
|
+ return JSONUtil.createObj().set("success", false)
|
|
|
+ .set("index", i + 1)
|
|
|
+ .set("message", "账号或姓名在系统人员中不存在");
|
|
|
+ }
|
|
|
+ SysUser sysUser = sysUserList.get(0);
|
|
|
+ //查看该课程已关联的学生中有没有这个学生
|
|
|
+ List<String> relateUserIdList=CollStreamUtil.toList(allRelateList, CourseStudentRelate::getUserId);
|
|
|
+ if(relateUserIdList.contains(sysUser.getId()))
|
|
|
+ {
|
|
|
+ return JSONUtil.createObj().set("success", false)
|
|
|
+ .set("index", i + 1)
|
|
|
+ .set("message", "该学生已关联该课程");
|
|
|
+ }
|
|
|
+ CourseStudentRelate courseStudentRelate=new CourseStudentRelate();
|
|
|
+ courseStudentRelate.setUserId(sysUser.getId());
|
|
|
+ courseStudentRelate.setCourseId(courseId);
|
|
|
+ this.addOne(courseStudentRelate);
|
|
|
+
|
|
|
+ return JSONUtil.createObj().set("success", true);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downloadImportTemplate(HttpServletResponse response) throws IOException {
|
|
|
+ try {
|
|
|
+ InputStream inputStream = POICacheManager.getFile("CourseStudentRelateTemplate.xlsx");
|
|
|
+ byte[] bytes = IoUtil.readBytes(inputStream);
|
|
|
+ CommonDownloadUtil.download("课程关联学员导入模板.xlsx", bytes, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(">>> 下载用户导入模板失败:", e);
|
|
|
+ CommonResponseUtil.renderError(response, "下载用户导入模板失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|