| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.personnel.dto.PersonPostAuthorizationRecordDto; |
| | | import com.ruoyi.personnel.mapper.PersonBasicInfoMapper; |
| | | import com.ruoyi.personnel.mapper.PersonPostAuthorizationRecordMapper; |
| | | import com.ruoyi.personnel.pojo.PersonBasicInfo; |
| | | import com.ruoyi.personnel.pojo.PersonPostAuthorizationRecord; |
| | | import com.ruoyi.personnel.service.PersonPostAuthorizationRecordService; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | |
| | | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | private UserMapper userMapper; |
| | | @Resource |
| | | private PersonBasicInfoMapper personBasicInfoMapper; |
| | | |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | |
| | | |
| | | @Override |
| | | public void exportPersonPostAuthorizationRecord(Integer id, HttpServletResponse response) { |
| | | if (id == null) { |
| | | throw new ErrorException("缺少任职授权记录id"); |
| | | } |
| | | PersonPostAuthorizationRecord personPostAuthorizationRecord = baseMapper.selectById(id); |
| | | if (personPostAuthorizationRecord == null) { |
| | | throw new ErrorException("任职授权记录不存在或已被删除"); |
| | | } |
| | | Integer incumbentUserId; |
| | | try { |
| | | incumbentUserId = Integer.valueOf(personPostAuthorizationRecord.getUserId()); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("该记录没有选择被任职人员,无法导出上岗证"); |
| | | } |
| | | //姓名 |
| | | User user = userMapper.selectById(personPostAuthorizationRecord.getUserId()); |
| | | User user = userMapper.selectById(incumbentUserId); |
| | | if (user == null) { |
| | | throw new ErrorException("被任职人员不存在或已被删除,无法导出上岗证"); |
| | | } |
| | | String name = user.getName(); |
| | | //todo: 人员任职授权记录姓名英文 |
| | | // HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); |
| | | // format.setCaseType(HanyuPinyinCaseType.LOWERCASE); |
| | | // format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); |
| | | // StringBuilder pinyinBuilder = new StringBuilder(); |
| | | // for (int i = 0; i < name.length(); i++) { |
| | | // char c = name.charAt(i); |
| | | // // 判断是否是汉字 |
| | | // if (Character.toString(c).matches("[\\u4E00-\\u9FFF]")) { |
| | | // // 获取汉字的拼音数组 |
| | | // String[] pinyinArray = new String[0]; |
| | | // try { |
| | | // pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format); |
| | | // } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) { |
| | | // |
| | | // } |
| | | // if (pinyinArray!= null && pinyinArray.length > 0) { |
| | | // pinyinBuilder.append(pinyinArray[0]); |
| | | // } |
| | | // } else { |
| | | // pinyinBuilder.append(c); |
| | | // } |
| | | // } |
| | | // String nameEn = pinyinBuilder.toString(); |
| | | String nameEn = user.getNameEn(); |
| | | //理论知识考试成绩 |
| | | String num1=personPostAuthorizationRecord.getNum1(); |
| | | //操作技能考试成绩 |
| | | String num2=personPostAuthorizationRecord.getNum2(); |
| | | //身份证号 |
| | | PersonBasicInfo basicInfo = personBasicInfoMapper.selectOne(Wrappers.<PersonBasicInfo>lambdaQuery() |
| | | .eq(PersonBasicInfo::getUserId, incumbentUserId) |
| | | .last("limit 1")); |
| | | if (basicInfo == null || StringUtils.isBlank(basicInfo.getIdentityCard())) { |
| | | throw new ErrorException(name + "还没有在人员基本信息中填写身份证号,无法导出上岗证"); |
| | | } |
| | | String identityCard = basicInfo.getIdentityCard(); |
| | | //证书编号 |
| | | String code = personPostAuthorizationRecord.getCertificateNumber(); |
| | | if (StringUtils.isBlank(code)) { |
| | | throw new ErrorException("该记录还没有填写证书编号,无法导出上岗证"); |
| | | } |
| | | //任职岗位 |
| | | String post = personPostAuthorizationRecord.getPost(); |
| | | String finalPost = StringUtils.isBlank(post) ? "检测" : post; |
| | | //发证时间 |
| | | LocalDateTime createTime = personPostAuthorizationRecord.getCreateTime(); |
| | | if (createTime == null) { |
| | | createTime = LocalDateTime.now(); |
| | | } |
| | | String year = createTime.getYear() + ""; |
| | | String mon = createTime.getMonth().getValue() + ""; |
| | | String mon = createTime.getMonthValue() + ""; |
| | | String day = createTime.getDayOfMonth() + ""; |
| | | //个人照片 |
| | | if (ObjectUtils.isEmpty(user.getPictureUrl())) { |
| | | throw new ErrorException(name+"的个人照片没有上传"); |
| | | throw new ErrorException(name + "的个人照片没有上传,无法导出上岗证"); |
| | | } |
| | | String pictureUrl = user.getPictureUrl(); |
| | | |
| | | if (!new File(imgUrl + "/" + pictureUrl).exists()) { |
| | | throw new ErrorException(name + "的个人照片文件不存在,请重新上传"); |
| | | } |
| | | |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/credentials-deal.docx"); |
| | | if (inputStream == null) { |
| | | throw new ErrorException("上岗证导出模板不存在"); |
| | | } |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("name", name); |
| | | put("nameEn", nameEn); |
| | | put("num1", num1); |
| | | put("num2", num2); |
| | | put("identityCard", identityCard); |
| | | put("code", code); |
| | | put("post", finalPost); |
| | | put("year", year); |
| | | put("mon", mon); |
| | | put("day", day); |
| | | put("writeUrl", new FilePictureRenderData(100,50,imgUrl + "/" + pictureUrl)); |
| | | put("writeUrl", new FilePictureRenderData(100, 140, imgUrl + "/" + pictureUrl)); |
| | | }}); |
| | | |
| | | try { |
| | | response.setContentType("application/msword"); |
| | | String fileName = URLEncoder.encode( |
| | | name+"的岗位职业资格正式", "UTF-8"); |
| | | name + "的检测人员上岗证", "UTF-8"); |
| | | response.setHeader("Content-disposition", |
| | | "attachment;filename=" + fileName + ".docx"); |
| | | OutputStream os = response.getOutputStream(); |