|
|
@@ -1,18 +1,18 @@
|
|
|
package org.jeecg.modules.zjrs.careerguidancedocument.controller;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
+import java.io.*;
|
|
|
import java.net.URLDecoder;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.config.JeecgBaseConfig;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.zjrs.careerguidancedocument.entity.CareerGuidanceCategory;
|
|
|
import org.jeecg.modules.zjrs.careerguidancedocument.entity.CareerGuidanceDocument;
|
|
|
+import org.jeecg.modules.zjrs.careerguidancedocument.service.ICareerGuidanceCategoryService;
|
|
|
import org.jeecg.modules.zjrs.careerguidancedocument.service.ICareerGuidanceDocumentService;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -50,150 +50,213 @@ import java.net.URLEncoder;
|
|
|
@RequestMapping("/careerguidancedocument/careerGuidanceDocument")
|
|
|
@Slf4j
|
|
|
public class CareerGuidanceDocumentController extends JeecgController<CareerGuidanceDocument, ICareerGuidanceDocumentService> {
|
|
|
- @Autowired
|
|
|
- private ICareerGuidanceDocumentService careerGuidanceDocumentService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 分页列表查询
|
|
|
- *
|
|
|
- * @param careerGuidanceDocument
|
|
|
- * @param pageNo
|
|
|
- * @param pageSize
|
|
|
- * @param req
|
|
|
- * @return
|
|
|
- */
|
|
|
- @AutoLog(value = "职业指导文档-分页列表查询")
|
|
|
- @Operation(summary="职业指导文档-分页列表查询", description="职业指导文档-分页列表查询")
|
|
|
- @GetMapping(value = "/list")
|
|
|
- public Result<IPage<CareerGuidanceDocument>> queryPageList(CareerGuidanceDocument careerGuidanceDocument,
|
|
|
- @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
- HttpServletRequest req) {
|
|
|
- QueryWrapper<CareerGuidanceDocument> queryWrapper = QueryGenerator.initQueryWrapper(careerGuidanceDocument, req.getParameterMap());
|
|
|
- Page<CareerGuidanceDocument> page = new Page<CareerGuidanceDocument>(pageNo, pageSize);
|
|
|
- IPage<CareerGuidanceDocument> pageList = careerGuidanceDocumentService.page(page, queryWrapper);
|
|
|
- return Result.OK(pageList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加
|
|
|
- *
|
|
|
- * @param careerGuidanceDocument
|
|
|
- * @return
|
|
|
- */
|
|
|
- @AutoLog(value = "职业指导文档-添加")
|
|
|
- @Operation(summary="职业指导文档-添加", description="职业指导文档-添加")
|
|
|
- @PostMapping(value = "/add")
|
|
|
- public Result<String> add(@RequestBody CareerGuidanceDocument careerGuidanceDocument) {
|
|
|
- careerGuidanceDocumentService.save(careerGuidanceDocument);
|
|
|
- return Result.OK("添加成功!");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 编辑
|
|
|
- *
|
|
|
- * @param careerGuidanceDocument
|
|
|
- * @return
|
|
|
- */
|
|
|
- @AutoLog(value = "职业指导文档-编辑")
|
|
|
- @Operation(summary="职业指导文档-编辑", description="职业指导文档-编辑")
|
|
|
- @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
- public Result<String> edit(@RequestBody CareerGuidanceDocument careerGuidanceDocument) {
|
|
|
- careerGuidanceDocumentService.updateById(careerGuidanceDocument);
|
|
|
- return Result.OK("编辑成功!");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通过id删除
|
|
|
- *
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- @AutoLog(value = "职业指导文档-通过id删除")
|
|
|
- @Operation(summary="职业指导文档-通过id删除", description="职业指导文档-通过id删除")
|
|
|
- @DeleteMapping(value = "/delete")
|
|
|
- public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
- careerGuidanceDocumentService.removeById(id);
|
|
|
- return Result.OK("删除成功!");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量删除
|
|
|
- *
|
|
|
- * @param ids
|
|
|
- * @return
|
|
|
- */
|
|
|
- @AutoLog(value = "职业指导文档-批量删除")
|
|
|
- @Operation(summary="职业指导文档-批量删除", description="职业指导文档-批量删除")
|
|
|
- @DeleteMapping(value = "/deleteBatch")
|
|
|
- public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
- this.careerGuidanceDocumentService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
- return Result.OK("批量删除成功!");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通过id查询
|
|
|
- *
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Operation(summary="职业指导文档-通过id查询", description="职业指导文档-通过id查询")
|
|
|
- @GetMapping(value = "/queryById")
|
|
|
- public Result<CareerGuidanceDocument> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
- CareerGuidanceDocument careerGuidanceDocument = careerGuidanceDocumentService.getById(id);
|
|
|
- if(careerGuidanceDocument==null) {
|
|
|
- return Result.error("未找到对应数据");
|
|
|
+ @Autowired
|
|
|
+ private ICareerGuidanceDocumentService careerGuidanceDocumentService;
|
|
|
+
|
|
|
+ //update-begin---author:kk ---date:2026-06-11 for:【职业指导公开文件】注入目录service用于级联查询-----------
|
|
|
+ @Autowired
|
|
|
+ private ICareerGuidanceCategoryService careerGuidanceCategoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JeecgBaseConfig jeecgBaseConfig;
|
|
|
+ //update-end---author:kk ---date:2026-06-11 for:【职业指导公开文件】注入目录service用于级联查询-----------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ *
|
|
|
+ * @param careerGuidanceDocument
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "职业指导文档-分页列表查询")
|
|
|
+ @Operation(summary="职业指导文档-分页列表查询", description="职业指导文档-分页列表查询")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<IPage<CareerGuidanceDocument>> queryPageList(CareerGuidanceDocument careerGuidanceDocument,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ //update-begin---author:kk ---date:2026-06-11 for:【职业指导公开文件】目录级联查询+文件名搜索-----------
|
|
|
+ QueryWrapper<CareerGuidanceDocument> queryWrapper = new QueryWrapper<>();
|
|
|
+ String categoryId = req.getParameter("categoryId");
|
|
|
+ if (categoryId != null && !categoryId.isEmpty()) {
|
|
|
+ Set<String> allIds = getAllChildCategoryIds(categoryId);
|
|
|
+ queryWrapper.in("category_id", allIds);
|
|
|
+ }
|
|
|
+ String name = req.getParameter("name");
|
|
|
+ if (name != null && !name.isEmpty()) {
|
|
|
+ queryWrapper.like("name", name);
|
|
|
+ }
|
|
|
+ queryWrapper.orderByAsc("sort_no");
|
|
|
+ //update-end---author:kk ---date:2026-06-11 for:【职业指导公开文件】目录级联查询+文件名搜索-----------
|
|
|
+ Page<CareerGuidanceDocument> page = new Page<CareerGuidanceDocument>(pageNo, pageSize);
|
|
|
+ IPage<CareerGuidanceDocument> pageList = careerGuidanceDocumentService.page(page, queryWrapper);
|
|
|
+ return Result.OK(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //update-begin---author:kk ---date:2026-06-11 for:【职业指导公开文件】递归获取所有子目录ID-----------
|
|
|
+ private Set<String> getAllChildCategoryIds(String parentId) {
|
|
|
+ Set<String> ids = new LinkedHashSet<>();
|
|
|
+ ids.add(parentId);
|
|
|
+ List<CareerGuidanceCategory> all = careerGuidanceCategoryService.list();
|
|
|
+ collectChildren(parentId, all, ids);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void collectChildren(String parentId, List<CareerGuidanceCategory> all, Set<String> result) {
|
|
|
+ for (CareerGuidanceCategory cat : all) {
|
|
|
+ if (parentId.equals(cat.getParentId())) {
|
|
|
+ if (result.add(cat.getId())) {
|
|
|
+ collectChildren(cat.getId(), all, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //update-end---author:kk ---date:2026-06-11 for:【职业指导公开文件】递归获取所有子目录ID-----------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param careerGuidanceDocument
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "职业指导文档-添加")
|
|
|
+ @Operation(summary="职业指导文档-添加", description="职业指导文档-添加")
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<String> add(@RequestBody CareerGuidanceDocument careerGuidanceDocument) {
|
|
|
+ careerGuidanceDocumentService.save(careerGuidanceDocument);
|
|
|
+ return Result.OK("添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param careerGuidanceDocument
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "职业指导文档-编辑")
|
|
|
+ @Operation(summary="职业指导文档-编辑", description="职业指导文档-编辑")
|
|
|
+ @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
+ public Result<String> edit(@RequestBody CareerGuidanceDocument careerGuidanceDocument) {
|
|
|
+ careerGuidanceDocumentService.updateById(careerGuidanceDocument);
|
|
|
+ return Result.OK("编辑成功!");
|
|
|
}
|
|
|
- return Result.OK(careerGuidanceDocument);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 导出excel
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @param careerGuidanceDocument
|
|
|
- */
|
|
|
- @RequestMapping(value = "/exportXls")
|
|
|
- public ModelAndView exportXls(HttpServletRequest request, CareerGuidanceDocument careerGuidanceDocument) {
|
|
|
- return super.exportXls(request, careerGuidanceDocument, CareerGuidanceDocument.class, "职业指导文档");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通过excel导入数据
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @param response
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
- public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- return super.importExcel(request, response, CareerGuidanceDocument.class);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 下载文件
|
|
|
- */
|
|
|
- @Operation(summary = "职业指导文档-下载", description = "职业指导文档-下载")
|
|
|
- @GetMapping(value = "/download")
|
|
|
- public void download(@RequestParam(name = "id", required = true) String id, HttpServletResponse response) {
|
|
|
- CareerGuidanceDocument doc = careerGuidanceDocumentService.getById(id);
|
|
|
- if (doc == null || doc.getFileUrl() == null) {
|
|
|
- response.setStatus(404);
|
|
|
- return;
|
|
|
- }
|
|
|
- try {
|
|
|
- String fileUrl = doc.getFileUrl();
|
|
|
- java.io.File file = new java.io.File(fileUrl);
|
|
|
- if (!file.exists()) {
|
|
|
- response.setStatus(404);
|
|
|
- return;
|
|
|
- }
|
|
|
- response.setContentType("application/octet-stream");
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(doc.getName() + ".pdf", "UTF-8"));
|
|
|
- org.springframework.util.FileCopyUtils.copy(new java.io.FileInputStream(file), response.getOutputStream());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("文件下载失败", e);
|
|
|
- response.setStatus(500);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "职业指导文档-通过id删除")
|
|
|
+ @Operation(summary="职业指导文档-通过id删除", description="职业指导文档-通过id删除")
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
+ careerGuidanceDocumentService.removeById(id);
|
|
|
+ return Result.OK("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "职业指导文档-批量删除")
|
|
|
+ @Operation(summary="职业指导文档-批量删除", description="职业指导文档-批量删除")
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
+ this.careerGuidanceDocumentService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.OK("批量删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Operation(summary="职业指导文档-通过id查询", description="职业指导文档-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<CareerGuidanceDocument> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
+ CareerGuidanceDocument careerGuidanceDocument = careerGuidanceDocumentService.getById(id);
|
|
|
+ if(careerGuidanceDocument==null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ return Result.OK(careerGuidanceDocument);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param careerGuidanceDocument
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, CareerGuidanceDocument careerGuidanceDocument) {
|
|
|
+ return super.exportXls(request, careerGuidanceDocument, CareerGuidanceDocument.class, "职业指导文档");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ return super.importExcel(request, response, CareerGuidanceDocument.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ //update-begin---author:kk ---date:2026-06-11 for:【职业指导公开文件】文件在线查看-----------
|
|
|
+ @Operation(summary = "职业指导文档-在线查看", description = "职业指导文档-在线查看")
|
|
|
+ @GetMapping(value = "/view")
|
|
|
+ public void view(@RequestParam(name = "id", required = true) String id, HttpServletResponse response) {
|
|
|
+ serveFile(id, response, true);
|
|
|
+ }
|
|
|
+ //update-end---author:kk ---date:2026-06-11 for:【职业指导公开文件】文件在线查看-----------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载文件
|
|
|
+ */
|
|
|
+ @Operation(summary = "职业指导文档-下载", description = "职业指导文档-下载")
|
|
|
+ @GetMapping(value = "/download")
|
|
|
+ public void download(@RequestParam(name = "id", required = true) String id, HttpServletResponse response) {
|
|
|
+ serveFile(id, response, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ //update-begin---author:kk ---date:2026-06-11 for:【职业指导公开文件】统一文件读取,支持相对路径-----------
|
|
|
+ private void serveFile(String id, HttpServletResponse response, boolean inline) {
|
|
|
+ CareerGuidanceDocument doc = careerGuidanceDocumentService.getById(id);
|
|
|
+ if (doc == null || doc.getFileUrl() == null) {
|
|
|
+ response.setStatus(404);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String fileUrl = doc.getFileUrl();
|
|
|
+ java.io.File f = new java.io.File(fileUrl);
|
|
|
+ if (!f.isAbsolute()) {
|
|
|
+ String uploadPath = jeecgBaseConfig.getPath().getUpload();
|
|
|
+ f = new java.io.File(uploadPath, fileUrl);
|
|
|
+ }
|
|
|
+ if (!f.exists()) {
|
|
|
+ response.setStatus(404);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (inline) {
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(doc.getName() + ".pdf", "UTF-8"));
|
|
|
+ } else {
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(doc.getName() + ".pdf", "UTF-8"));
|
|
|
+ }
|
|
|
+ org.springframework.util.FileCopyUtils.copy(new java.io.FileInputStream(f), response.getOutputStream());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("文件操作失败", e);
|
|
|
+ response.setStatus(500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //update-end---author:kk ---date:2026-06-11 for:【职业指导公开文件】统一文件读取,支持相对路径-----------
|
|
|
}
|