| | |
| | | |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | |
| | | */ |
| | | @Override |
| | | public void exportPersonnelCapacity(Integer id, HttpServletResponse response) { |
| | | if (id == null) { |
| | | throw new ErrorException("缺少人员能力记录id"); |
| | | } |
| | | PersonPersonnelCapacityExportDto capacityExportDto = baseMapper.selectExportPersonnelCapacity(id); |
| | | if (capacityExportDto == null) { |
| | | throw new ErrorException("人员能力记录不存在或已被删除"); |
| | | } |
| | | |
| | | // 确认人 |
| | | String confirmUrl = null; |
| | | if (capacityExportDto.getConfirmOperatingPersonnelId() != null) { |
| | | confirmUrl = userMapper.selectById(capacityExportDto.getConfirmOperatingPersonnelId()).getSignatureUrl(); |
| | | User confirmUser = userMapper.selectById(capacityExportDto.getConfirmOperatingPersonnelId()); |
| | | if (confirmUser == null) { |
| | | throw new ErrorException("确认人不存在或已被删除,无法导出"); |
| | | } |
| | | confirmUrl = confirmUser.getSignatureUrl(); |
| | | if (StringUtils.isBlank(confirmUrl)) { |
| | | throw new ErrorException("缺少确认人签名"); |
| | | throw new ErrorException("确认人还没有上传签名,无法导出"); |
| | | } |
| | | if (!new File(imgUrl + "/" + confirmUrl).exists()) { |
| | | throw new ErrorException("确认人签名文件不存在,请让确认人重新上传"); |
| | | } |
| | | } |
| | | |
| | | // 获取路径 |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/personnel-capacity.docx"); |
| | | if (inputStream == null) { |
| | | throw new ErrorException("人员能力导出模板不存在"); |
| | | } |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | String finalConfirmUrl = confirmUrl; |
| | |
| | | |
| | | try { |
| | | response.setContentType("application/msword"); |
| | | String fileName = URLEncoder.encode( |
| | | "人员能力", "UTF-8"); |
| | | String userName = StringUtils.isBlank(capacityExportDto.getUserName()) ? "人员能力" : capacityExportDto.getUserName() + "人员能力认定"; |
| | | String fileName = URLEncoder.encode(userName, "UTF-8"); |
| | | response.setHeader("Content-disposition", |
| | | "attachment;filename=" + fileName + ".docx"); |
| | | OutputStream os = response.getOutputStream(); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitConfirmPersonnelCapability(PersonPersonnelCapacity personPersonnelCapacity) { |
| | | if (personPersonnelCapacity.getUserId() == null) { |
| | | throw new ErrorException("缺少人员"); |
| | | } |
| | | if (personPersonnelCapacity.getConfirmOperatingPersonnelId() == null) { |
| | | throw new ErrorException("缺少确认人"); |
| | | } |
| | | User formUser = userMapper.selectById(personPersonnelCapacity.getUserId()); |
| | | if (formUser == null) { |
| | | throw new ErrorException("人员不存在或已被删除,无法提交"); |
| | | } |
| | | User confirmUser = userMapper.selectById(personPersonnelCapacity.getConfirmOperatingPersonnelId()); |
| | | if (confirmUser == null) { |
| | | throw new ErrorException("确认人不存在或已被删除,无法提交"); |
| | | } |
| | | if (personPersonnelCapacity.getId() != null) { |
| | | PersonPersonnelCapacity existing = this.getById(personPersonnelCapacity.getId()); |
| | | if (existing == null) { |
| | | throw new ErrorException("人员能力记录不存在或已被删除"); |
| | | } |
| | | if (existing.getConfirmDate() != null) { |
| | | throw new ErrorException("该记录已确认,不能重复提交"); |
| | | } |
| | | } |
| | | |
| | | Integer userId = SecurityUtils.getUserId().intValue(); |
| | | User user = userMapper.selectById(userId); |
| | | // 提交和确认日期分开:确认日期只在确认操作时由系统写入 |
| | | personPersonnelCapacity.setConfirmDate(null); |
| | | this.saveOrUpdate(personPersonnelCapacity); |
| | | |
| | | // 消息发送 |
| | | InformationNotification info = new InformationNotification(); |
| | | // 发送人 |
| | | info.setCreateUser(user.getName()); |
| | | info.setCreateUser(user != null ? user.getName() : ""); |
| | | info.setMessageType("6"); |
| | | info.setTheme("CNAS人员能力确认通知"); |
| | | info.setContent(formUser.getName() + "的人员能力待确认"); |
| | |
| | | info.setConsigneeId(personPersonnelCapacity.getConfirmOperatingPersonnelId()); |
| | | info.setJumpPath(MenuJumpPathConstants.PERSONNEL); |
| | | informationNotificationService.addInformationNotification(info); |
| | | this.saveOrUpdate(personPersonnelCapacity); |
| | | |
| | | // 发送企业微信通知 |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | // 查询接收人 |
| | | User personnel = userMapper.selectById(personPersonnelCapacity.getConfirmOperatingPersonnelId()); |
| | | |
| | | if (confirmUser.getAccount() == null || confirmUser.getAccount().trim().isEmpty()) { |
| | | return; |
| | | } |
| | | String message = ""; |
| | | message += "CNAS人员能力确认通知"; |
| | | message += "\n请去资源管理-人员-人员能力填写"; |
| | | message += "\n请去资源要求-人员-人员管理-人员能力填写"; |
| | | message += "\n" + formUser.getName() + "的人员能力待确认"; |
| | | //发送企业微信消息通知 |
| | | try { |
| | | WxCpUtils.inform(personnel.getAccount(), message, null); |
| | | WxCpUtils.inform(confirmUser.getAccount(), message, null); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |