自测问题修改
This commit is contained in:
parent
d7e6e6b321
commit
d2af147c7b
|
|
@ -131,6 +131,12 @@
|
|||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>6.0.18.Final</version>
|
||||
</dependency>
|
||||
<!--thumbnailator图片处理-->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,163 @@
|
|||
package com.bonus.common.core.utils;
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.Base64;
|
||||
|
||||
|
||||
/**
|
||||
* @author cwchen
|
||||
*/
|
||||
public class PicUtils {
|
||||
//以下是常量,按照阿里代码开发规范,不允许代码中出现魔法值
|
||||
private static final Logger logger = LoggerFactory.getLogger(PicUtils.class);
|
||||
private static final Integer ZERO = 0;
|
||||
private static final Integer ONE_ZERO_TWO_FOUR = 1024;
|
||||
private static final Integer NINE_ZERO_ZERO = 900;
|
||||
private static final Integer THREE_TWO_SEVEN_FIVE = 3275;
|
||||
private static final Integer TWO_ZERO_FOUR_SEVEN = 2047;
|
||||
private static final Double ZERO_EIGHT_FIVE = 0.85;
|
||||
private static final Double ZERO_SIX = 0.6;
|
||||
private static final Double ZERO_FOUR_FOUR = 0.44;
|
||||
private static final Double ZERO_FOUR = 0.4;
|
||||
|
||||
/**
|
||||
* 根据指定大小压缩图片
|
||||
*
|
||||
* @param imageBytes 源图片字节数组
|
||||
* @param desFileSize 指定图片大小,单位kb
|
||||
* @return 压缩质量后的图片字节数组
|
||||
*/
|
||||
public static byte[] compressPicForScale(byte[] imageBytes, long desFileSize) {
|
||||
if (imageBytes == null || imageBytes.length <= ZERO || imageBytes.length < desFileSize * ONE_ZERO_TWO_FOUR) {
|
||||
return imageBytes;
|
||||
}
|
||||
long srcSize = imageBytes.length;
|
||||
double accuracy = getAccuracy(srcSize / ONE_ZERO_TWO_FOUR);
|
||||
try {
|
||||
while (imageBytes.length > desFileSize * ONE_ZERO_TWO_FOUR) {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(imageBytes.length);
|
||||
Thumbnails.of(inputStream)
|
||||
.scale(accuracy)
|
||||
.outputQuality(accuracy)
|
||||
.toOutputStream(outputStream);
|
||||
imageBytes = outputStream.toByteArray();
|
||||
}
|
||||
logger.info("图片原大小={}kb | 压缩后大小={}kb",
|
||||
srcSize / ONE_ZERO_TWO_FOUR, imageBytes.length / ONE_ZERO_TWO_FOUR);
|
||||
} catch (Exception e) {
|
||||
logger.error("【图片压缩】msg=图片压缩失败!", e);
|
||||
}
|
||||
return imageBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动调节精度(经验数值)
|
||||
*
|
||||
* @param size 源图片大小
|
||||
* @return 图片压缩质量比
|
||||
*/
|
||||
private static double getAccuracy(long size) {
|
||||
double accuracy;
|
||||
if (size < NINE_ZERO_ZERO) {
|
||||
accuracy = ZERO_EIGHT_FIVE;
|
||||
} else if (size < TWO_ZERO_FOUR_SEVEN) {
|
||||
accuracy = ZERO_SIX;
|
||||
} else if (size < THREE_TWO_SEVEN_FIVE) {
|
||||
accuracy = ZERO_FOUR_FOUR;
|
||||
} else {
|
||||
accuracy = ZERO_FOUR;
|
||||
}
|
||||
return accuracy;
|
||||
}
|
||||
|
||||
public static byte[] FileTobyte(File file) {
|
||||
FileInputStream fileInputStream = null;
|
||||
byte[] imgData = null;
|
||||
|
||||
try {
|
||||
imgData = new byte[(int) file.length()];
|
||||
|
||||
//read file into bytes[]
|
||||
fileInputStream = new FileInputStream(file);
|
||||
fileInputStream.read(imgData);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
try {
|
||||
fileInputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return imgData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩base64编码图片,并返回base64
|
||||
*
|
||||
* @param base64Image 需要压缩的图片
|
||||
* @param compressSize 压缩大小,传入多少就压缩到该值范围内 (例:524,288 等于 512kb)
|
||||
* @return 返回base64编码
|
||||
* @throws Exception 异常处理
|
||||
*/
|
||||
public static String compressBase64Image(String base64Image, Integer compressSize) throws Exception {
|
||||
try {
|
||||
String newBase64;
|
||||
// 判断格式
|
||||
if (base64Image.startsWith("data:image")) {
|
||||
int index = base64Image.indexOf("base64,");
|
||||
if (index == -1) {
|
||||
throw new Exception("无效base64照片格式");
|
||||
}
|
||||
newBase64 = base64Image.substring(index + 7);
|
||||
} else {
|
||||
newBase64 = base64Image;
|
||||
}
|
||||
// replace(" ", "+")
|
||||
newBase64 = newBase64.replace(" ", "+");
|
||||
// 解码Base64字符串为字节数组
|
||||
byte[] imageBytes = Base64.getDecoder().decode(newBase64);
|
||||
// 缓冲图像
|
||||
BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageBytes));
|
||||
// 根据指定的图像及宽、高按比例缩放并进行压缩质量90%新建缓冲图像缩略图
|
||||
BufferedImage image = Thumbnails.of(bufferedImage).size(bufferedImage.getWidth() / 2,
|
||||
bufferedImage.getHeight() / 2).outputQuality(0.9).asBufferedImage();
|
||||
// 创建输出流对象
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
// 根据传入图像,图像类型,写入指定的输出流中
|
||||
ImageIO.write(image, "jpg", outputStream);
|
||||
// 输出流转换成字节数组
|
||||
imageBytes = outputStream.toByteArray();
|
||||
// 使用 Base64 编码方案将指定的字节数组转为 String
|
||||
String base64 = Base64.getEncoder().encodeToString(imageBytes);
|
||||
// 根据String对象长度判断是否需要进行压缩
|
||||
if (base64.length() - base64.length() / 8 * 2 > compressSize) {
|
||||
// 设置图像的缩放系数并创建图像 (默认1.0 代表缩略100%)
|
||||
image = Thumbnails.of(image).scale(1.0 / base64.length() / compressSize).asBufferedImage();
|
||||
// 根据传入图像,图像类型,写入指定的输出流中
|
||||
ImageIO.write(image, "jpg", outputStream);
|
||||
// 使用 Base64 编码方案将指定的字节数组转为 String
|
||||
base64 = Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
||||
}
|
||||
// 关闭流
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
// 返回Base64编码图片
|
||||
return "data:image/jpeg;base64," + base64;
|
||||
} catch (Exception e) {
|
||||
logger.error("图片压缩异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +1,21 @@
|
|||
package com.bonus.bracelet.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bonus.bracelet.mapper.PersonMgeMapper;
|
||||
import com.bonus.bracelet.service.IPersonMgeService;
|
||||
import com.bonus.common.core.constant.BusinessConstants;
|
||||
import com.bonus.common.core.constant.HttpStatus;
|
||||
import com.bonus.common.core.constant.SecurityConstants;
|
||||
import com.bonus.common.core.utils.DateTimeHelper;
|
||||
import com.bonus.common.core.utils.UploadCheckUtils;
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.entity.bracelet.BraceletParamsDto;
|
||||
import com.bonus.common.entity.bracelet.vo.BaseProject;
|
||||
import com.bonus.common.entity.bracelet.vo.PersonVo;
|
||||
import com.bonus.common.log.annotation.SysLog;
|
||||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.common.security.annotation.RequiresPermissions;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.system.api.RemoteFileService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -52,9 +51,11 @@ public class PersonMgeController extends BaseController {
|
|||
@GetMapping("list")
|
||||
@SysLog(title = "人员管理", businessType = OperaType.QUERY,logType = 0,module = "基础管理->人员管理",details ="查询人员列表")
|
||||
public TableDataInfo list(BraceletParamsDto dto) {
|
||||
System.err.println("开始"+DateTimeHelper.getNowTime());
|
||||
startPage();
|
||||
List<PersonVo> list = service.getPersonLists(dto);
|
||||
return getDataTable(list);
|
||||
TableDataInfo tableDataInfo = service.getPersonLists(dto);
|
||||
System.err.println("结束"+DateTimeHelper.getNowTime());
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
// @RequiresPermissions("basic:person:add")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.bracelet.service;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.entity.bracelet.BraceletParamsDto;
|
||||
import com.bonus.common.entity.bracelet.vo.PersonVo;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
|
@ -68,7 +69,7 @@ public interface IPersonMgeService {
|
|||
* @author cwchen
|
||||
* @date 2024/7/17 9:19
|
||||
*/
|
||||
List<PersonVo> getPersonLists(BraceletParamsDto dto);
|
||||
TableDataInfo getPersonLists(BraceletParamsDto dto);
|
||||
|
||||
/**
|
||||
* 人员导入
|
||||
|
|
|
|||
|
|
@ -12,14 +12,12 @@ import com.bonus.common.core.constant.BusinessConstants;
|
|||
import com.bonus.common.core.constant.HttpStatus;
|
||||
import com.bonus.common.core.constant.SecurityConstants;
|
||||
import com.bonus.common.core.domain.R;
|
||||
import com.bonus.common.core.utils.BytesToMultipartFileUtil;
|
||||
import com.bonus.common.core.utils.FaceCodeUtil;
|
||||
import com.bonus.common.core.utils.ImportExcelUtils;
|
||||
import com.bonus.common.core.utils.UploadCheckUtils;
|
||||
import com.bonus.common.core.utils.*;
|
||||
import com.bonus.common.core.utils.encryption.Sm4Utils;
|
||||
import com.bonus.common.core.utils.global.SystemGlobal;
|
||||
import com.bonus.common.core.utils.uuid.IdUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.entity.bracelet.BraceletParamsDto;
|
||||
import com.bonus.common.entity.bracelet.exportVo.PersonExportVo;
|
||||
import com.bonus.common.entity.bracelet.importVo.PersonImportVo;
|
||||
|
|
@ -30,6 +28,7 @@ import com.bonus.common.entity.file.ResourceFileVo;
|
|||
import com.bonus.common.security.utils.ValidatorsUtils;
|
||||
import com.bonus.system.api.RemoteFileService;
|
||||
import com.bonus.system.api.domain.SysFile;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -88,20 +87,42 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
|
|||
private String tempFilePath;
|
||||
|
||||
@Override
|
||||
public List<PersonVo> getPersonLists(BraceletParamsDto dto) {
|
||||
public TableDataInfo getPersonLists(BraceletParamsDto dto) {
|
||||
dto.setSourceType(BusinessConstants.RESOURCE_TYPE_USER);
|
||||
List<PersonVo> list = new ArrayList<>();
|
||||
List<Future> futureList = new ArrayList<>();
|
||||
List<PersonVo> newList = new ArrayList<>();
|
||||
try {
|
||||
list = mapper.getPersonLists(dto);
|
||||
for (PersonVo vo : list) {
|
||||
vo = handleData(vo);
|
||||
int num = mapper.getCertificateNum(vo.getId());
|
||||
vo.setCertificateNum(num);
|
||||
Future<PersonVo> future = testTaskExecutor.submit(new Callable<PersonVo>() {
|
||||
@Override
|
||||
public PersonVo call() throws Exception {
|
||||
System.err.println("执行了");
|
||||
vo.setIdCard(Sm4Utils.decode(vo.getIdCard()));
|
||||
vo.setPhone(Sm4Utils.decode(vo.getPhone()));
|
||||
String imageBase64 = getImageBase64(vo.getFilePath());
|
||||
vo.setBase64Url(imageBase64);
|
||||
int num = mapper.getCertificateNum(vo.getId());
|
||||
vo.setCertificateNum(num);
|
||||
return vo;
|
||||
}
|
||||
});
|
||||
futureList.add(future);
|
||||
}
|
||||
for (Future<PersonVo> future : futureList) {
|
||||
PersonVo vo = future.get();
|
||||
newList.add(vo);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("查询人员列表", e);
|
||||
}
|
||||
return list;
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setRows(newList);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setTotal(new PageInfo(list).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -632,16 +653,16 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
|
|||
public ResourceFileVo setCertificateResourceFileData(JSONObject item, CertificateVo vo) {
|
||||
ResourceFileVo fileVo = new ResourceFileVo();
|
||||
String fileType = null;
|
||||
if(item.get("suffix").equals(".pdf") || item.get("suffix").equals(".doc") || item.get("suffix").equals(".docx")){
|
||||
if (item.get("suffix").equals(".pdf") || item.get("suffix").equals(".doc") || item.get("suffix").equals(".docx")) {
|
||||
fileType = "0";
|
||||
}else{
|
||||
} else {
|
||||
fileType = String.valueOf(vo.getCertificateType() + 1);
|
||||
}
|
||||
String resourceId = IdUtils.simpleUUID();
|
||||
if(fileType.equals("0")){
|
||||
if (fileType.equals("0")) {
|
||||
fileVo.setFileType(0);
|
||||
fileVo.setSourceType(String.valueOf(vo.getCertificateType() + 1));
|
||||
}else{
|
||||
} else {
|
||||
fileVo.setFileType(1);
|
||||
fileVo.setSourceType(fileType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
<!--人员已分配班组,岗位限制修改 -->
|
||||
<select id="canItBeModified" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM tb_people tp WHERE id = #{id} AND team_id IS NOT NULL
|
||||
SELECT COUNT(*) FROM tb_people tp WHERE id = #{id} AND post != #{post} AND team_id IS NOT NULL
|
||||
</select>
|
||||
<!--获取所有已入库的安全帽编号-->
|
||||
<select id="aqmCodeIsExist" resultType="java.util.Map">
|
||||
|
|
|
|||
Loading…
Reference in New Issue