Browse Source

修改学校项目接口实现,发布学院项目接口,完善获得学生界面信息接口

houlai 6 months ago
parent
commit
3a5ebd4c32

+ 2 - 1
yudao-module-as/yudao-module-as-api/src/main/java/cn/iocoder/yudao/module/as/enums/ErrorCodeConstants.java

@@ -14,7 +14,8 @@ public interface ErrorCodeConstants {
     ErrorCode AIDING_STUDENTS_IMPORT_LIST_IS_NULL = new ErrorCode(2_009_000_006,  "excel表解析为空");
     ErrorCode AIDING_STUDENTS_IMPORT_LIST_STUDENT_EXISTS = new ErrorCode(2_009_000_007,  "自治区名单中该学生已存在");
     ErrorCode AIDING_STUDENTS_IMPORT_LIST_STUDENT_CODE_NOT_EXISTS = new ErrorCode(2_009_000_008,  "系统中不存在该学生学号");
-    ErrorCode AIDING_STUDENTS_IMPORT_LIST_FILE_IMPORT_ERROR = new ErrorCode(2_009_000_008,  "excel解析失败");
+    ErrorCode AIDING_STUDENTS_IMPORT_LIST_FILE_IMPORT_ERROR = new ErrorCode(2_009_000_009,  "excel解析失败");
+    ErrorCode AIDING_STUDENTS_IMPORT_LIST_FAILURE = new ErrorCode(2_009_000_010,  "自治区名单导入失败");
 
 
 }

+ 7 - 0
yudao-module-as/yudao-module-as-biz/src/main/java/cn/iocoder/yudao/module/as/controller/admin/aidingstudentscollegemanage/AidingStudentsCollegeManageController.java

@@ -50,6 +50,13 @@ public class AidingStudentsCollegeManageController {
         return success(aidingStudentsCollegeManageService.createAidingStudentsCollegeManage(createReqVO));
     }
 
+    @PutMapping("/publish")
+    @Operation(summary = "发布家庭困难认定项目学院管理")
+    @PreAuthorize("@ss.hasPermission('as:aiding-students-college-manage:update')")
+    public CommonResult<Boolean> publishAidingStudentsCollegeManage(@RequestParam("id") Long id) {
+        return success(aidingStudentsCollegeManageService.publishAidingStudentsCollegeManage(id));
+    }
+
     @PutMapping("/update")
     @Operation(summary = "更新家庭困难认定项目学院管理")
     @PreAuthorize("@ss.hasPermission('as:aiding-students-college-manage:update')")

+ 2 - 3
yudao-module-as/yudao-module-as-biz/src/main/java/cn/iocoder/yudao/module/as/controller/admin/aidingstudentsmanage/AidingStudentsManageController.java

@@ -49,9 +49,8 @@ public class AidingStudentsManageController {
     @PutMapping("/update")
     @Operation(summary = "更新家庭困难认定项目管理")
     @PreAuthorize("@ss.hasPermission('as:aiding-students-manage:update')")
-    public CommonResult<Boolean> updateAidingStudentsManage(@Valid @RequestBody AidingStudentsManageSaveReqVO updateReqVO) {
-        aidingStudentsManageService.updateAidingStudentsManage(updateReqVO);
-        return success(true);
+    public CommonResult<AidingStudentsImportExcelRespVO> updateAidingStudentsManage(@Valid @RequestBody AidingStudentsManageSaveReqVO updateReqVO) {
+        return success(aidingStudentsManageService.updateAidingStudentsManage(updateReqVO));
     }
 
     @DeleteMapping("/delete")

+ 2 - 0
yudao-module-as/yudao-module-as-biz/src/main/java/cn/iocoder/yudao/module/as/service/aidingstudentscollegemanage/AidingStudentsCollegeManageService.java

@@ -59,4 +59,6 @@ public interface AidingStudentsCollegeManageService {
     PageResult<AidingStudentsCollegeManageProjectInfoRespVO> getProjectInfoPage(AidingStudentsCollegeManageProjectInfoPageRespVO pageReqVO);
 
     List<AidingStudentsCollegeManageStudentRespVO> getStudentCollegeManageInfo();
+
+    Boolean publishAidingStudentsCollegeManage(Long id);
 }

+ 28 - 7
yudao-module-as/yudao-module-as-biz/src/main/java/cn/iocoder/yudao/module/as/service/aidingstudentscollegemanage/AidingStudentsCollegeManageServiceImpl.java

@@ -1,8 +1,12 @@
 package cn.iocoder.yudao.module.as.service.aidingstudentscollegemanage;
 
+import cn.iocoder.yudao.module.as.controller.admin.aidingstudentspersonmanage.vo.AidingStudentsPersonManageUploadRespVO;
 import cn.iocoder.yudao.module.as.dal.dataobject.aidingstudentscollegemanage.AidingStudentsCollegeManageProjectInfoPageRespDO;
 import cn.iocoder.yudao.module.as.dal.dataobject.aidingstudentsmanage.AidingStudentsManageDO;
 import cn.iocoder.yudao.module.as.dal.mysql.aidingstudentsmanage.AidingStudentsManageMapper;
+import cn.iocoder.yudao.module.as.service.aidingstudentsimportlist.AidingStudentsImportListService;
+import cn.iocoder.yudao.module.as.service.aidingstudentsimportlist.AidingStudentsImportListServiceImpl;
+import cn.iocoder.yudao.module.as.service.aidingstudentspersonmanage.AidingStudentsPersonManageServiceImpl;
 import cn.iocoder.yudao.module.system.api.dept.DeptApi;
 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
@@ -41,6 +45,10 @@ public class AidingStudentsCollegeManageServiceImpl implements AidingStudentsCol
     @Resource
     private AidingStudentsManageMapper aidingStudentsManageMapper;
     @Resource
+    private AidingStudentsPersonManageServiceImpl aidingStudentsPersonManageService;
+    @Resource
+    private AidingStudentsImportListServiceImpl aidingStudentsImportListService;
+    @Resource
     private AdminUserApi adminUserApi;
     @Resource
     private DeptApi deptApi;
@@ -135,18 +143,18 @@ public class AidingStudentsCollegeManageServiceImpl implements AidingStudentsCol
         //获得分页信息
         Integer pageNo = pageReqVO.getPageNo();
         Integer pageSize = pageReqVO.getPageSize();
-        Integer offset = (pageNo - 1) *pageSize;
-        List<AidingStudentsCollegeManageProjectInfoPageRespDO> aidingStudentsCollegeManageProjectInfoRespDOS = aidingStudentsCollegeManageMapper.selectProjectInfoPage(pageSize,offset);
+        Integer offset = (pageNo - 1) * pageSize;
+        List<AidingStudentsCollegeManageProjectInfoPageRespDO> aidingStudentsCollegeManageProjectInfoRespDOS = aidingStudentsCollegeManageMapper.selectProjectInfoPage(pageSize, offset);
         //转换
         List<AidingStudentsCollegeManageProjectInfoRespVO> aidingStudentsCollegeManageProjectInfoRespVOS = BeanUtils.toBean(aidingStudentsCollegeManageProjectInfoRespDOS, AidingStudentsCollegeManageProjectInfoRespVO.class);
         //判断
-        if (aidingStudentsCollegeManageProjectInfoRespVOS != null){
+        if (aidingStudentsCollegeManageProjectInfoRespVOS != null) {
             //获得学校项目创建人
             aidingStudentsCollegeManageProjectInfoRespVOS.forEach(aidingStudentsCollegeManageProjectInfoRespVO -> {
                 aidingStudentsCollegeManageProjectInfoRespVO.setCreator(adminUserApi.getUser(Long.valueOf(aidingStudentsManageMapper.selectById(aidingStudentsCollegeManageProjectInfoRespVO.getId()).getCreator())).getNickname());
             });
             //返回项目信息
-            return new PageResult<>(aidingStudentsCollegeManageProjectInfoRespVOS,aidingStudentsCollegeManageMapper.selectProjectInfoPageCount());
+            return new PageResult<>(aidingStudentsCollegeManageProjectInfoRespVOS, aidingStudentsCollegeManageMapper.selectProjectInfoPageCount());
         }
         return null;
 
@@ -156,19 +164,32 @@ public class AidingStudentsCollegeManageServiceImpl implements AidingStudentsCol
     public List<AidingStudentsCollegeManageStudentRespVO> getStudentCollegeManageInfo() {
         // 获得学院id
         Long deptId = adminUserApi.getUser(getLoginUserId()).getDeptId();
-        Long collegeId =  deptApi.getCollegeId(deptId);
+        Long collegeId = deptApi.getCollegeId(deptId);
         //获得学院的项目
         List<AidingStudentsCollegeManageDO> aidingStudentsCollegeManageDOS = aidingStudentsCollegeManageMapper.selectList(Wrappers.lambdaQuery(AidingStudentsCollegeManageDO.class)
-                    .eq(AidingStudentsCollegeManageDO::getCollegeId, collegeId));
+                .eq(AidingStudentsCollegeManageDO::getCollegeId, collegeId)
+                .orderByDesc(AidingStudentsCollegeManageDO::getCreateTime));
         List<AidingStudentsCollegeManageStudentRespVO> aidingStudentsCollegeManageStudentRespVOS = BeanUtils.toBean(aidingStudentsCollegeManageDOS, AidingStudentsCollegeManageStudentRespVO.class);
-        //获得项目名字
+        //获得项目名字以及是否在自治区名单
         aidingStudentsCollegeManageStudentRespVOS.forEach(aidingStudentsCollegeManageStudentRespVO -> {
             aidingStudentsCollegeManageStudentRespVO.setDiName(aidingStudentsManageMapper.selectById(aidingStudentsCollegeManageStudentRespVO.getManageId()).getDiName());
+            //通过身份证查询是否存在
+            AidingStudentsPersonManageUploadRespVO aidingStudentsPersonManageUploadRespVO = aidingStudentsPersonManageService.beforeuploadAidingStudentsManage();
+            aidingStudentsCollegeManageStudentRespVO.setInImportList(aidingStudentsImportListService.checkStudentIDNumberExists(aidingStudentsPersonManageUploadRespVO.getIdCard(), aidingStudentsCollegeManageStudentRespVO.getManageId()));
         });
 
         return aidingStudentsCollegeManageStudentRespVOS;
     }
 
+    @Override
+    public Boolean publishAidingStudentsCollegeManage(Long id) {
+        int update = aidingStudentsCollegeManageMapper.update(
+                Wrappers.lambdaUpdate(AidingStudentsCollegeManageDO.class)
+                        .eq(AidingStudentsCollegeManageDO::getId, id)
+                        .set(AidingStudentsCollegeManageDO::getComStatus, 1));
+        return true;
+    }
+
     /*private List<AidingStudentsCollegeManageProjectInfoRespVO> merge2AidingStudentsCollegeManageProjectInfoRespVO
             (List<AidingStudentsManageDO> aidingStudentsManageDOS, List<AidingStudentsCollegeManageDO> aidingStudentsCollegeManageDOS) {
         List<AidingStudentsCollegeManageProjectInfoRespVO> aidingStudentsCollegeManageProjectInfoRespVOS = new ArrayList<>();

+ 17 - 0
yudao-module-as/yudao-module-as-biz/src/main/java/cn/iocoder/yudao/module/as/service/aidingstudentsimportlist/AidingStudentsImportListServiceImpl.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
@@ -99,6 +100,18 @@ public class AidingStudentsImportListServiceImpl implements AidingStudentsImport
                 ) > 0;
 
 
+    }
+
+    //根据身份证号校验这次项目该学生是否已经导入
+    public Boolean checkStudentIDNumberExists(String studentIdNumber, Long asAidingStudentsManageId) {
+        //存在返回true,不存在返回false
+        return aidingStudentsImportListMapper.selectCount(
+                Wrappers.lambdaQuery(AidingStudentsImportExcelListDO.class)
+                        .eq(AidingStudentsImportExcelListDO::getStudentIdNumber, studentIdNumber)
+                        .eq(AidingStudentsImportExcelListDO::getAsAidingStudentsManageId, asAidingStudentsManageId)
+        ) > 0;
+
+
     }
 
     @Override
@@ -225,6 +238,10 @@ public class AidingStudentsImportListServiceImpl implements AidingStudentsImport
             aidingStudentsImportListMapper.insert(aidingStudentsImportEecleListDO);
             respVO.getCreateStudentNames().add(aidingStudentsImportEecleListDO.getStudentName());
         });
+        if (CollUtil.isNotEmpty(respVO.getFailureStudentNames())){
+            respVO.setCreateStudentNames(null);
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
         return respVO;
     }
 

+ 1 - 1
yudao-module-as/yudao-module-as-biz/src/main/java/cn/iocoder/yudao/module/as/service/aidingstudentsmanage/AidingStudentsManageService.java

@@ -29,7 +29,7 @@ public interface AidingStudentsManageService {
      *
      * @param updateReqVO 更新信息
      */
-    void updateAidingStudentsManage(@Valid AidingStudentsManageSaveReqVO updateReqVO);
+    AidingStudentsImportExcelRespVO updateAidingStudentsManage(@Valid AidingStudentsManageSaveReqVO updateReqVO);
 
     /**
      * 删除家庭困难认定项目管理

+ 86 - 13
yudao-module-as/yudao-module-as-biz/src/main/java/cn/iocoder/yudao/module/as/service/aidingstudentsmanage/AidingStudentsManageServiceImpl.java

@@ -58,7 +58,7 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
         //解析excel
 
         //创建temp.xlsx
-        String path = this.getClass().getResource("").getPath();//注意getResource("")里面是空字符串
+        /*String path = this.getClass().getResource("").getPath();//注意getResource("")里面是空字符串
         String path1=path+"importexcel";
         try {
             File dir = new File(path1);
@@ -66,17 +66,18 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
                 dir.mkdirs();//创建目录
             }
             File f = new File(path1,"temp.xlsx");
+            f.deleteOnExit();
             if(!f.exists()){
                 f.createNewFile();
             }
         } catch (Exception e) {
             e.printStackTrace();
-        }
+        }*/
 
 
 
-        //从url读取出文件到本地
-        URL website = null;
+        //从url读取出文件到已创建的文件中
+        /*URL website = null;
         ReadableByteChannel rbc = null;
         FileOutputStream fos = null;
         try {
@@ -102,13 +103,13 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
                 }
 
             }
-        }
+        }*/
 
 
 
 
         //导入名单
-        File file = new File(path1+"/temp.xlsx");
+        /*File file = new File(path1+"/temp.xlsx");
         AidingStudentsImportExcelRespVO aidingStudentsImportExcelRespVO=null;
         try {
             MultipartFile cMultiFile = new MockMultipartFile("file", file.getName(), null, new FileInputStream(file));
@@ -117,17 +118,17 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
 
         } catch (IOException e) {
             throw exception(AIDING_STUDENTS_IMPORT_LIST_FILE_IMPORT_ERROR);
-        }
+        }*/
 
 
 
 
-        //TODO 删除excel文件
-        file.delete();
+        // 删除excel文件
+        //file.deleteOnExit();
 
 
         // 返回
-        return aidingStudentsImportExcelRespVO;
+        return excelResolver(aidingStudentsManage.getDiImportListFile(), aidingStudentsManage.getId());
     }
 
 
@@ -137,12 +138,18 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
 
 
     @Override
-    public void updateAidingStudentsManage(AidingStudentsManageSaveReqVO updateReqVO) {
-        // 校验存在
-        validateAidingStudentsManageExists(updateReqVO.getId());
+    public AidingStudentsImportExcelRespVO updateAidingStudentsManage(AidingStudentsManageSaveReqVO updateReqVO) {
+        //根据id查找
+        AidingStudentsManageDO aidingStudentsManage = aidingStudentsManageMapper.selectById(updateReqVO.getId());
+        //判断名单是否重新导入
+        AidingStudentsImportExcelRespVO aidingStudentsImportExcelRespVO = null;
+        if (!aidingStudentsManage.getDiImportListFile().equals(updateReqVO.getDiImportListFile())) {
+            aidingStudentsImportExcelRespVO = excelResolver(updateReqVO.getDiImportListFile(), updateReqVO.getId());
+        }
         // 更新
         AidingStudentsManageDO updateObj = BeanUtils.toBean(updateReqVO, AidingStudentsManageDO.class);
         aidingStudentsManageMapper.updateById(updateObj);
+        return aidingStudentsImportExcelRespVO;
     }
 
     @Override
@@ -178,4 +185,70 @@ public class AidingStudentsManageServiceImpl implements AidingStudentsManageServ
         aidingStudentsManageMapper.updateById(aidingStudentsManageDO);
     }
 
+    public AidingStudentsImportExcelRespVO excelResolver(String url, Long aidingStudentsManageId){
+        //创建temp.xlsx
+        String path = this.getClass().getResource("").getPath();//注意getResource("")里面是空字符串
+        String path1=path+"importexcel";
+        try {
+            File dir = new File(path1);
+            if(!dir.exists()){
+                dir.mkdirs();//创建目录
+            }
+            File f = new File(path1,"temp.xlsx");
+            f.deleteOnExit();
+            if(!f.exists()){
+                f.createNewFile();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        //从url读取出文件到已创建的文件中
+        URL website = null;
+        ReadableByteChannel rbc = null;
+        FileOutputStream fos = null;
+        try {
+            website = new URL(url);
+            rbc = Channels.newChannel(website.openStream());
+            fos = new FileOutputStream(path1+"/temp.xlsx");//本地要存储的文件地址 例如:test.txt
+            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }finally{
+            if(fos!=null){
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if(rbc!=null){
+                try {
+                    rbc.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+
+            }
+        }
+        //导入名单
+        File file = new File(path1+"/temp.xlsx");
+        AidingStudentsImportExcelRespVO aidingStudentsImportExcelRespVO=null;
+        try {
+            MultipartFile cMultiFile = new MockMultipartFile("file", file.getName(), null, new FileInputStream(file));
+            List<AidingStudentsImportExcelVO> list = ExcelUtils.read(cMultiFile, AidingStudentsImportExcelVO.class);
+            aidingStudentsImportExcelRespVO = aidingStudentsImportListService.aidingStudentsImportExcelListFromCloud(aidingStudentsManageId, list);
+
+        } catch (IOException e) {
+            throw exception(AIDING_STUDENTS_IMPORT_LIST_FILE_IMPORT_ERROR);
+        }
+
+
+        // 删除excel文件
+        file.deleteOnExit();
+
+        // 返回
+        return aidingStudentsImportExcelRespVO;
+
+    }
+
 }