febs-common/febs-common-core/src/main/java/cc/mrbird/febs/common/core/utils/MyUtil.java
@@ -6,6 +6,8 @@ import cn.hutool.core.lang.Dict; import lombok.extern.slf4j.Slf4j; import org.springframework.web.multipart.MultipartFile; import sun.misc.BASE64Decoder; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -124,6 +126,80 @@ //上传 file.transferTo(new File(uploadPpath + newName)); return Dict.create().set("fileName",fileName).set("suffix",suffix).set("newName",newName); } /** * 对字节数组字符串进行Base64解码并生成图片 */ public static boolean generateImage(String imgStr,String url) { if (imgStr == null) { // 图像数据为空 return false; } imgStr = imgStr.split(",")[1]; BASE64Decoder decoder = new BASE64Decoder(); try { // Base64解码 byte[] b = decoder.decodeBuffer(imgStr); for (int i = 0; i < b.length; ++i) { // 调整异常数据 if (b[i] < 0) { b[i] += 256; } } // 生成jpeg图片 String imgFilePath = url; OutputStream out = new FileOutputStream(imgFilePath); out.write(b); out.flush(); out.close(); return true; } catch (Exception e) { return false; } } /** * 将base64字符串,生成文件 */ public static File convertBase64ToFile(String fileBase64String, String filePath, String fileName) { BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try { File dir = new File(filePath); if (!dir.exists() && dir.isDirectory()) {//判断文件目录是否存在 dir.mkdirs(); } BASE64Decoder decoder = new BASE64Decoder(); byte[] bfile = decoder.decodeBuffer(fileBase64String); file = new File(filePath + File.separator + fileName); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(bfile); return file; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (bos != null) { try { bos.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e1) { e1.printStackTrace(); } } } } } febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/controller/EmpBaseInfoController.java
@@ -111,12 +111,11 @@ @ApiOperation(value = "人员基本信息增加") @PostMapping @PreAuthorize("hasAuthority('empBaseinfo:add')") public void addEmpBaseInfo( MultipartFile file,@Valid EmpBaseInfo empBaseinfo) throws FebsException { public void addEmpBaseInfo(@Valid EmpBaseInfo empBaseinfo) throws FebsException { if(this.empBaseInfoService.verifyEmpNumb(empBaseinfo)){ throw new FebsException("已存在此员工编号"); } try { //EmpBaseInfo tempInfo = this.empBaseInfoService. this.empBaseInfoService.createEmpBaseInfo(empBaseinfo); } catch (Exception e) { String message = "新增员工基本信息失败"; @@ -154,7 +153,7 @@ @ApiOperation(value = "人员基本信息修改") @PutMapping @PreAuthorize("hasAuthority('empBaseinfo:update')") public void updateEmpBaseInfo(MultipartFile file,@Valid EmpBaseInfo empBaseinfo) throws FebsException { public void updateEmpBaseInfo(@Valid EmpBaseInfo empBaseinfo) throws FebsException { if(this.empBaseInfoService.verifyEmpNumb(empBaseinfo)){ throw new FebsException("已存在此员工编号:" + empBaseinfo.getEmpNumb()); } @@ -248,4 +247,16 @@ throw new FebsException(message); } } @GetMapping("image/{empId}") public void getImage(@PathVariable String empId, HttpServletResponse response) throws FebsException { try { this.empBaseInfoService.getImage(empId,response); } catch (Exception e) { String message = "获取员工图片异常"; log.error(message, e); throw new FebsException(message); } } } febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/entity/EmpBaseInfo.java
@@ -291,12 +291,12 @@ @TableField(exist = false) @ExcelField(value = "相关证件") private String certificateListName = ""; @FieldInfo(name = "empStatus", type = "varchar", explain = "员工状态") @TableField("empStatus") @ExcelField(value = "员工状态",writeConverterExp = "0=在职,1=离职,2=退休" ) private String empStatus = ""; @FieldInfo(name = "dimissionType", type = "varchar", explain = "离职类型") @@ -342,10 +342,10 @@ @TableField(exist = false) private String ageStr = ""; @TableField(exist = false) private String entryDateStr= ""; @TableField(exist = false) private String dimissionDateStr= ""; @@ -397,4 +397,8 @@ @TableField(exist = false) private String reporter; } @FieldInfo(name = "imagePath", type = "varchar", explain = "图片路径") @TableField("imagePath") private String imagePath = ""; } febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/properties/FebsServerHrProperties.java
@@ -20,4 +20,6 @@ private String uploadSinglePath = "C:/upload/hr/singlefile/"; private String empBaseInfoPath = "C:/upload/hr/empBaseInfo/"; } febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/IEmpBaseInfoService.java
@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import javax.servlet.http.HttpServletResponse; import java.io.FileNotFoundException; import java.util.List; import java.util.Map; @@ -29,7 +31,7 @@ * @return IPage<EmpBaseinfo> */ IPage<EmpBaseInfo> findEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo); /** *智搜 查询(分页) * @@ -174,4 +176,6 @@ * @param listObject */ void importEmpBaseInfo(List<List<Object>> listObject); void getImage(String empId, HttpServletResponse response) throws Exception; } febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java
@@ -1,15 +1,22 @@ package cc.mrbird.febs.server.hr.service.impl; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.OutputStream; import java.util.*; import cc.mrbird.febs.common.core.entity.system.SysConfig; import cc.mrbird.febs.common.core.utils.MyUtil; import cc.mrbird.febs.server.hr.entity.EmpDimissionLog; import cc.mrbird.febs.server.hr.entity.EmpJobChange; import cc.mrbird.febs.server.hr.properties.FebsServerHrProperties; import cc.mrbird.febs.server.hr.service.IEmpDimissionLogService; import cc.mrbird.febs.server.hr.service.IEmpJobChangeService; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cc.mrbird.febs.server.hr.entity.*; import cn.hutool.core.util.StrUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -35,6 +42,9 @@ import cc.mrbird.febs.server.hr.mapper.EmpBaseInfoMapper; import cc.mrbird.febs.server.hr.service.IEmpBaseInfoService; import lombok.RequiredArgsConstructor; import org.springframework.util.FileSystemUtils; import javax.servlet.http.HttpServletResponse; /** * name:EmpBaseinfo @@ -54,7 +64,7 @@ private final EmpBaseInfoMapper empBaseInfoMapper; private final IEmpDimissionLogService dimissionLogService; private final IEmpJobChangeService jobChangeService; private final FebsServerHrProperties properties; private final String operatorId = Optional.ofNullable(FebsUtil.getCurrentUser()) .map(u -> u.getUserId().toString()) .orElse("1"); @@ -152,7 +162,7 @@ iPage.setRecords(list); return iPage; } @Override public IPage<EmpBaseInfo> findZsEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) { LambdaQueryWrapper<EmpBaseInfo> queryWrapper = new LambdaQueryWrapper<>(); @@ -261,6 +271,12 @@ } else{ empBaseInfo.setEmpId(dbInfo.getEmpId()); } if (StrUtil.isNotBlank(empBaseInfo.getImagePath())){ String path = properties.getEmpBaseInfoPath()+empBaseInfo.getEmpId()+".png"; if ( MyUtil.generateImage(empBaseInfo.getImagePath(),path)) { empBaseInfo.setImagePath(empBaseInfo.getEmpId()+".png"); }; } empBaseInfo.setCreator(operatorId); empBaseInfo.setModifier(operatorId); this.saveOrUpdate(empBaseInfo); @@ -269,6 +285,13 @@ @Override @Transactional(rollbackFor = Exception.class) public void updateEmpBaseInfo(EmpBaseInfo empBaseInfo) { if (StrUtil.isNotBlank(empBaseInfo.getImagePath())){ String path = properties.getEmpBaseInfoPath()+empBaseInfo.getEmpId()+".png"; if ( MyUtil.generateImage(empBaseInfo.getImagePath(),path)) { empBaseInfo.setImagePath(empBaseInfo.getEmpId()+".png"); } } EmpBaseInfo dbData = this.getById(empBaseInfo.getEmpId()); empBaseInfo.setCreateTime(dbData.getCreateTime()); empBaseInfo.setCreator(dbData.getCreator()); @@ -333,7 +356,7 @@ if (tempEmpBaseInfo == null) { return false; } return !empBaseInfo.getEmpId().equals(tempEmpBaseInfo.getEmpId()); return !empBaseInfo.getEmpNumb().equals(tempEmpBaseInfo.getEmpNumb()); } @Override @@ -485,6 +508,28 @@ this.save(empBaseInfo); } } @Override public void getImage(String empId, HttpServletResponse response) throws Exception { EmpBaseInfo empBaseInfo = this.getById(empId); if (StrUtil.isBlank(empBaseInfo.getImagePath())){ return; } String path = properties.getEmpBaseInfoPath()+empBaseInfo.getEmpId()+".png"; try (InputStream inputStream = new FileInputStream(path); OutputStream out = response.getOutputStream()) { //byte数组用于存放图片字节数据 byte[] buff = new byte[inputStream.available()]; inputStream.read(buff); inputStream.close(); //设置发送到客户端的响应内容类型 response.setContentType("image/png"); out.write(buff); } } @Override @@ -809,4 +854,4 @@ } return stringObjectMap; } } } febs-server/febs-server-hr/src/main/resources/febs-server-hr.properties
@@ -1,2 +1,3 @@ febs.server.hr.uploadCommonPath=C:/upload/hr/commonfile/ febs.server.hr.uploadSinglePath=C:/upload/hr/singlefile/ febs.server.hr.empBaseInfoPath=C:/upload/hr/empBaseInfo/ images/1.pngBinary files differ
images/2.pngBinary files differ
images/3.pngBinary files differ
images/4.pngBinary files differ
images/5.pngBinary files differ
images/6.pngBinary files differ
images/7.pngBinary files differ
images/PrometheusAPM.svg
File was deleted images/QQ.jpgBinary files differ
images/SkywalkingAPM.svg
File was deleted images/docker_container_monitor.pngBinary files differ
images/febs-cloud.pngBinary files differ
images/febs-cloud.svg
File was deleted images/febs-k8s.pngBinary files differ
images/jvm_monitor.pngBinary files differ
images/mysql_monitor.pngBinary files differ
images/prometheus_apm.pngBinary files differ
images/redis_monitor.pngBinary files differ
images/skywalking_apm.pngBinary files differ
images/skywalking_global.pngBinary files differ
images/skywalking_service.pngBinary files differ
images/skywalking_topology.pngBinary files differ
images/skywalking_trace.pngBinary files differ