diff --git a/src/main/java/com/ydool/common/utils/UploadUtils.java b/src/main/java/com/ydool/common/utils/UploadUtils.java index fb66843..9156621 100644 --- a/src/main/java/com/ydool/common/utils/UploadUtils.java +++ b/src/main/java/com/ydool/common/utils/UploadUtils.java @@ -2,10 +2,15 @@ package com.ydool.common.utils; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Date; public class UploadUtils { @@ -31,4 +36,33 @@ public class UploadUtils { return System.getProperty("user.dir"); } + public static void download(HttpServletResponse response, String fullFilePath, String fileName) { + response.reset(); + response.setContentType("application/octet-stream; charset=utf-8"); + response.setCharacterEncoding("utf-8"); + response.addHeader("Content-Disposition", "attachment; filename*=utf-8'zh_cn'" + encodeUrl(StrUtil.isNotBlank(fileName) ? fileName : FileUtil.getName(fullFilePath))); + try { + IoUtil.copy(FileUtil.getInputStream(fullFilePath), response.getOutputStream()); + response.flushBuffer(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String encodeUrl(String part) { + return encodeUrl(part, "UTF-8"); + } + + public static String encodeUrl(String part, String encoding) { + if (part == null) { + return null; + } else { + try { + return URLEncoder.encode(part, encoding); + } catch (UnsupportedEncodingException ex) { + ex.printStackTrace(); + } + return null; + } + } } diff --git a/src/main/java/com/ydool/staff/controller/OrganizationController.java b/src/main/java/com/ydool/staff/controller/OrganizationController.java index 721956f..c57e7b1 100644 --- a/src/main/java/com/ydool/staff/controller/OrganizationController.java +++ b/src/main/java/com/ydool/staff/controller/OrganizationController.java @@ -21,6 +21,12 @@ public class OrganizationController extends BaseController { @Autowired IOrganizationService organizationService; + @GetMapping("/selectOrganization") + @ApiOperation(value = "企业名称列表") + public AjaxResult selectOrganization() { + return organizationService.selectOrganization(); + } + @GetMapping("/selectOrganizationByName") @ApiOperation(value = "企业名称查企业信息") @ApiImplicitParams({@ApiImplicitParam(name = "companyName", value = "企业名称", required = true)}) diff --git a/src/main/java/com/ydool/staff/controller/PersonnelController.java b/src/main/java/com/ydool/staff/controller/PersonnelController.java index ac4a64d..8a9b780 100644 --- a/src/main/java/com/ydool/staff/controller/PersonnelController.java +++ b/src/main/java/com/ydool/staff/controller/PersonnelController.java @@ -1,13 +1,17 @@ package com.ydool.staff.controller; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.ydool.common.base.BaseController; import com.ydool.common.constant.UrlConstant; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.utils.UploadUtils; import com.ydool.staff.dto.PersonnelDto; +import com.ydool.staff.entity.Attachment; import com.ydool.staff.request.PersonnelDeleteRequest; import com.ydool.staff.request.PersonnelRequest; import com.ydool.staff.request.PersonnelUpdateRequest; +import com.ydool.staff.service.IAttachmentService; import com.ydool.staff.service.IPersonnelService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -15,11 +19,7 @@ import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @@ -36,6 +36,8 @@ import java.util.List; public class PersonnelController extends BaseController { @Resource private IPersonnelService personnelService; + @Autowired + IAttachmentService attachmentService; @GetMapping( "personnelList") @ApiOperation(value = "人员列表,传id查一条",response = PersonnelDto.class) @@ -63,4 +65,18 @@ public class PersonnelController extends BaseController { return personnelService.updatePersonnel(personnelDeleteRequest); } + @GetMapping("/download") + @ApiOperation(value = "下载文件") + @ApiImplicitParams({@ApiImplicitParam(name = "path", value = "文件路径"), @ApiImplicitParam(name = "fileName", value = "文件名")}) + public void download(String path, String fileName) { + String fullFilePath = UploadUtils.getWebRoot() + path; + UploadUtils.download(response, fullFilePath, fileName); + } + + @GetMapping("/fileList") + @ApiOperation(value = "文件列表") + @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页"), @ApiImplicitParam(name = "size", value = "每页条数"), @ApiImplicitParam(name = "id", value = "人员id", required = true)}) + public AjaxResult fileList(String id) { + return attachmentService.fileList(new Page(getPageNum(), getPageSize()), id); + } } diff --git a/src/main/java/com/ydool/staff/entity/Personnel.java b/src/main/java/com/ydool/staff/entity/Personnel.java index d20c508..6047652 100644 --- a/src/main/java/com/ydool/staff/entity/Personnel.java +++ b/src/main/java/com/ydool/staff/entity/Personnel.java @@ -67,7 +67,7 @@ public class Personnel extends BaseEntity { private String education; @ApiModelProperty(value = "是否应届毕业生") - private boolean freshGraduate; + private Boolean freshGraduate; @ApiModelProperty(value = "毕业院校") private String academy; diff --git a/src/main/java/com/ydool/staff/service/IAttachmentService.java b/src/main/java/com/ydool/staff/service/IAttachmentService.java index 746a009..33c2564 100644 --- a/src/main/java/com/ydool/staff/service/IAttachmentService.java +++ b/src/main/java/com/ydool/staff/service/IAttachmentService.java @@ -1,5 +1,7 @@ package com.ydool.staff.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ydool.common.data.dto.AjaxResult; import com.ydool.staff.entity.Attachment; import com.ydool.staff.request.AttachmentRequest; @@ -18,5 +20,7 @@ public interface IAttachmentService { boolean deleteById(String targetType,String id); Attachment selectFile(String path, String id); + + AjaxResult fileList(Page page, String id); } diff --git a/src/main/java/com/ydool/staff/service/IOrganizationService.java b/src/main/java/com/ydool/staff/service/IOrganizationService.java index 4a5fc3c..f4c946d 100644 --- a/src/main/java/com/ydool/staff/service/IOrganizationService.java +++ b/src/main/java/com/ydool/staff/service/IOrganizationService.java @@ -22,5 +22,7 @@ public interface IOrganizationService { AjaxResult deleteOrganization(IdsRequest id); AjaxResult selectOrganizationByName(String companyName); + + AjaxResult selectOrganization(); } diff --git a/src/main/java/com/ydool/staff/service/impl/AttachmentServiceImpl.java b/src/main/java/com/ydool/staff/service/impl/AttachmentServiceImpl.java index c91c89b..f6b599d 100644 --- a/src/main/java/com/ydool/staff/service/impl/AttachmentServiceImpl.java +++ b/src/main/java/com/ydool/staff/service/impl/AttachmentServiceImpl.java @@ -1,13 +1,18 @@ package com.ydool.staff.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ydool.common.base.BaseService; +import com.ydool.common.data.dto.AjaxResult; import com.ydool.staff.entity.Attachment; import com.ydool.staff.mapper.AttachmentMapper; import com.ydool.staff.request.AttachmentRequest; import com.ydool.staff.service.IAttachmentService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + /** *

* 附件表 服务类 @@ -20,6 +25,9 @@ import org.springframework.stereotype.Service; public class AttachmentServiceImpl extends BaseService implements IAttachmentService { + @Autowired + AttachmentMapper attachmentMapper; + @Override public boolean savePersonnel(Attachment entity) { return save(entity); @@ -32,9 +40,12 @@ public class AttachmentServiceImpl extends BaseService().eq(Attachment::getPath, path).eq(Attachment::getTargetId,id)); - + return getOne(new LambdaQueryWrapper().eq(Attachment::getPath, path).eq(Attachment::getTargetId, id)); + } + @Override + public AjaxResult fileList(Page page, String id) { + return AjaxResult.ok().data(attachmentMapper.selectPage(page, new LambdaQueryWrapper().eq(Attachment::getTargetId, id))); } } diff --git a/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java b/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java index e68b5b1..c82e50a 100644 --- a/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java +++ b/src/main/java/com/ydool/staff/service/impl/OrganizationServiceImpl.java @@ -45,9 +45,9 @@ public class OrganizationServiceImpl extends BaseService organizationLambdaQueryWrapper = new LambdaQueryWrapper<>(); organizationLambdaQueryWrapper.eq(StrUtil.isNotBlank(companyName), Organization::getCompanyName, companyName); Page selectPage = organizationMapper.selectPage(page, organizationLambdaQueryWrapper); - for (Organization record : selectPage.getRecords()) { - record.setUpdatedId(userMapper.selectById(record.getUpdatedId()).getUserName()); - } + // for (Organization record : selectPage.getRecords()) { + // record.setUpdatedId(userMapper.selectById(record.getUpdatedId()).getUserName()); + // } return AjaxResult.ok().data(selectPage); } @@ -80,5 +80,10 @@ public class OrganizationServiceImpl extends BaseService().eq(Organization::getCompanyName, companyName))); } + + @Override + public AjaxResult selectOrganization() { + return AjaxResult.ok().data(organizationMapper.selectList(null)); + } }