修改bug

This commit is contained in:
haozq 2025-08-18 13:59:11 +08:00
parent 60cda843c3
commit 5bf36f40a8
12 changed files with 333 additions and 22 deletions

View File

@ -24,7 +24,7 @@ public interface RemoteUrkUtilsService {
* @param update
* @param source
*/
@PostMapping(value = "/business/sendUserToDevice")
@PostMapping(value = "/sedTask/sendUserToDevice")
public void sendUserToDevice(@RequestParam(value = "userId") int userId, @RequestParam(value = "proId")int proId,
@RequestParam(value = "update")String update, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@ -34,7 +34,7 @@ public interface RemoteUrkUtilsService {
* @param proId
* @param source
*/
@PostMapping(value = "/business/getUserSendToDev")
@PostMapping(value = "/sedTask/getUserSendToDev")
public void getUserSendToDev(@RequestParam(value = "deviceCode") String deviceCode, @RequestParam(value = "proId")int proId,
@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@ -44,7 +44,7 @@ public interface RemoteUrkUtilsService {
* @param proId
* @param source
*/
@PostMapping(value = "/business/delDevByProId")
@PostMapping(value = "/sedTask/delDevByProId")
public void delDevByProId(@RequestParam(value = "deviceCode") String deviceCode, @RequestParam(value = "proId")int proId,
@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@ -54,7 +54,7 @@ public interface RemoteUrkUtilsService {
* @param proId
* @param source
*/
@PostMapping(value = "/business/delUserByDevice")
@PostMapping(value = "/sedTask/delUserByDevice")
public void delUserByDevice(@RequestParam(value = "userId") int userId, @RequestParam(value = "proId")int proId,
@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

View File

@ -9,9 +9,12 @@ import java.io.Serializable;
/**
* dto - 设备用户
* 主要用于和设备同步用户信息使用
* @author 黑子
*/
@Data
public class DeviceUserDto implements Serializable {
private String userId;
private String name;

View File

@ -0,0 +1,260 @@
package com.bonus.urk.config;
import com.bonus.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
@Slf4j
public class ImageResizer {
public static void main(String[] args) {
try {
String bast64=getFileBast64("F:\\files\\face\\test.jpg");
String bast642=transImageByJpg(bast64);
} catch (Exception e) {
e.printStackTrace();
}
}
public static List<String> fileType = new ArrayList<>();
/**
* 将bast64转成需要的图片格式
* @param filePath
* @param file
* @param
* @return
*/
public static String transImageByJpg(String filePath, File file ){
try{
String suffix=".png";
String path="/temp/";
File folder = new File(filePath+path);
if (folder.exists() && folder.isDirectory()) {
System.out.println("文件夹存在");
} else {
folder.mkdir();
System.out.println("文件夹不存在");
}
// 创建临时文件,将bast64转成字节流
// 创建临时文件确保文件名具有唯一性
// 将字节数据写入文件
String newJpgPath=null;
//不是jpg的先转成jpg的
getFileType();
if (!fileType.contains(suffix)){
String roundId2= StringUtils.randomUUID();
//jpg的路径
newJpgPath=filePath+path+roundId2+".jpg";
BufferedImage pngImage = ImageIO.read(file);
BufferedImage jpgImage = new BufferedImage(pngImage.getWidth(), pngImage.getHeight(), BufferedImage.TYPE_INT_RGB);
// 绘制PNG图片到jpgImage
jpgImage.createGraphics().drawImage(pngImage, 0, 0, Color.WHITE, null);
ImageIO.write(jpgImage, "jpg", new File(newJpgPath));
}
//
File inputFile;
//是jpg格式的
if(newJpgPath==null){
inputFile=file;
}else{
inputFile = new File(newJpgPath);
}
BufferedImage originalImage = ImageIO.read(inputFile);
BufferedImage resizedImage = resizeImage(originalImage, 1080, 800);
// 保存为PNG格式
String roundId3= StringUtils.randomUUID();
String lastPath=filePath+path+roundId3+".jpg";
saveImage(resizedImage, "jpg", lastPath);
if(newJpgPath!=null){
boolean isde=new File(newJpgPath).delete();
System.err.println("删除->"+isde);
}
// boolean delete=file.delete();
// System.err.println("删除->"+delete);
return lastPath;
}catch (Exception e){
log.error(e.toString(),e);
}
return null;
}
/**
* 将bast64转成需要的图片格式
* @param
* @param bast64
* @param
* @return
*/
public static String transImageByJpg( String bast64){
try{
String path="";
String suffix=".png";
String roundId=StringUtils.randomUUID();
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("win")) {
path="C:\\files\\temp\\";
} else if (osName.contains("nux") || osName.contains("nix")) {
path="\\opt\\files\\temp\\";
}
Path thisPath = Paths.get(path);
if (!Files.exists(thisPath)) {
Files.createDirectories(thisPath);
}
// 创建临时文件,将bast64转成字节流
byte[] bytes = Base64.getDecoder().decode(bast64);
File file = File.createTempFile(path, suffix);
// 将字节数据写入文件
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
fos.close();
String newJpgPath=null;
//不是jpg的先转成jpg的
getFileType();
if (!fileType.contains(suffix)){
String roundId2=StringUtils.randomUUID();
//jpg的路径
newJpgPath=path+roundId2+".jpg";
BufferedImage pngImage = ImageIO.read(file);
BufferedImage jpgImage = new BufferedImage(pngImage.getWidth(), pngImage.getHeight(), BufferedImage.TYPE_INT_RGB);
// 绘制PNG图片到jpgImage
jpgImage.createGraphics().drawImage(pngImage, 0, 0, Color.WHITE, null);
ImageIO.write(jpgImage, "jpg", new File(newJpgPath));
}
//
File inputFile;
//是jpg格式的
if(newJpgPath==null){
inputFile=file;
}else{
inputFile = new File(newJpgPath);
}
BufferedImage originalImage = ImageIO.read(inputFile);
BufferedImage resizedImage = resizeImage(originalImage, 480, 640);
// 保存为PNG格式
String roundId3=StringUtils.randomUUID();
String lastPath=path+roundId3+".jpg";
saveImage(resizedImage, "jpg", lastPath);
if(newJpgPath!=null){
boolean isde=new File(newJpgPath).delete();
}
boolean delete=file.delete();
String bast642=getFileBast64(lastPath);
File file2=new File(lastPath);
boolean delete2=file2.delete();
return bast642;
}catch (Exception e){
log.error(e.toString(),e);
}
return null;
}
public static String getFileBast64(String file) {
try{
Path path = Paths.get(file);
byte[] imageBytes = Files.readAllBytes(path);
return Base64.getEncoder().encodeToString(imageBytes);
}catch (Exception e){
log.error(e.toString(),e);
}
return null;
}
/**
* 获取文件->最终转成 本地临时文件使用完必须删除
* @param
* @return
*/
public static String transImageByJpg(String filePath,byte[] bytes,String suffix){
try{
String roundId=StringUtils.randomUUID();
String path="/temp/";
File folder = new File(filePath+path);
if (folder.exists() && folder.isDirectory()) {
System.out.println("文件夹存在");
} else {
folder.mkdir();
System.out.println("文件夹不存在");
}
// 创建临时文件确保文件名具有唯一性
File file = File.createTempFile(filePath+path+roundId, suffix);
// 将字节数据写入文件
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
fos.close();
String newJpgPath=null;
//不是jpg的先转成jpg的
getFileType();
if (!fileType.contains(suffix)){
String roundId2=StringUtils.randomUUID();
//jpg的路径
newJpgPath=filePath+path+roundId2+".jpg";
BufferedImage pngImage = ImageIO.read(file);
BufferedImage jpgImage = new BufferedImage(pngImage.getWidth(), pngImage.getHeight(), BufferedImage.TYPE_INT_RGB);
// 绘制PNG图片到jpgImage
jpgImage.createGraphics().drawImage(pngImage, 0, 0, Color.WHITE, null);
ImageIO.write(jpgImage, "jpg", new File(newJpgPath));
}
//
File inputFile;
//是jpg格式的
if(newJpgPath==null){
inputFile=file;
}else{
inputFile = new File(newJpgPath);
}
BufferedImage originalImage = ImageIO.read(inputFile);
BufferedImage resizedImage = resizeImage(originalImage, 1080, 800);
// 保存为PNG格式
String roundId3=StringUtils.randomUUID();
String lastPath=filePath+path+roundId3+".jpg";
saveImage(resizedImage, "jpg", lastPath);
if(newJpgPath!=null){
boolean isde=new File(newJpgPath).delete();
System.err.println("删除->"+isde);
}
boolean delete=file.delete();
System.err.println("删除->"+delete);
return lastPath;
}catch (Exception e){
log.error(e.toString(),e);
}
return null;
}
public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) {
BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, originalImage.getType());
Graphics2D graphics2D = resizedImage.createGraphics();
graphics2D.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
graphics2D.dispose();
return resizedImage;
}
public static void saveImage(BufferedImage resizedImage, String format, String outputPath) throws IOException {
File outputFile = new File(outputPath);
ImageIO.write(resizedImage, format, outputFile);
}
public static void getFileType(){
fileType.add("jpg");
fileType.add("JPG");
fileType.add(".JPG");
fileType.add(".jpg");
}
}

View File

@ -0,0 +1,24 @@
package com.bonus.urk.config;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 图片处理工具类
*
* @author ruoyi
*/
public class ImageUtils
{
private static final Logger log = LoggerFactory.getLogger(ImageUtils.class);
}

View File

@ -12,8 +12,8 @@ import org.springframework.web.bind.annotation.RestController;
* @author 黑子
*/
@Api(tags = "考勤机业务员指令接口-人员下发及删除")
@RestController("business")
@RequestMapping
@RestController
@RequestMapping("/sedTask")
@Slf4j
public class SendUserController {

View File

@ -46,5 +46,5 @@ public interface TaskMapper {
* @param taskVo
* @param userList
*/
void insertUserIssued(@Param("taskVo") DeviceTaskVo taskVo,@Param("list") List<DeviceUserDto> userList);
void insertUserIssued(@Param("taskVo") DeviceTaskVo taskVo,@Param("list") List<String> userList);
}

View File

@ -255,6 +255,23 @@ public class UrkMinioService {
return list;
}
/**
* 获取文件数据
* @param id
* @param sourceId
* @param sourceTable
* @param sourceType
* @return
* @throws Exception
*/
public List<UploadFileVo> getFileBast64List(String id, String sourceId, String sourceTable, String sourceType) throws Exception {
List<UploadFileVo> list=mapper.getFileList(id,sourceId,sourceType,sourceTable);
for (UploadFileVo vo:list){
String bast64=minioUtils.getMinioBast64(vo.getBucketName(),vo.getFilePath());
vo.setBast64(bast64);
}
return list;
}
/**
* 文件批量删除
* @param id

View File

@ -30,10 +30,11 @@ public class CmdLogService {
*/
public void logServerResponseLog(DeviceTaskVo taskVo, HttpServletResponse resp, String body) {
try{
if(body.length()>4000){
body=body.substring(0,4000);
}
mapper.insertCmdLogs(taskVo,body);
}catch (Exception e){
log.error(e.toString(),e);
}

View File

@ -15,6 +15,7 @@ import com.bonus.system.api.RemoteUploadUtilsService;
import com.bonus.system.api.model.UploadFileVo;
import com.bonus.urk.config.Constant;
import com.bonus.urk.config.DeviceUserDto;
import com.bonus.urk.config.ImageResizer;
import com.bonus.urk.config.TaskStatusEnum;
import com.bonus.urk.mapper.TaskMapper;
import com.bonus.urk.minio.UrkMinioService;
@ -339,7 +340,7 @@ public class TaskService {
}
//下方人员数据
public void insertPeople(DeviceTaskVo task, HttpServletRequest req, HttpServletResponse resp) {
public void insertPeople(DeviceTaskVo task, HttpServletRequest req, HttpServletResponse resp) throws Exception {
String body = "";
if(StringUtils.isEmpty(task.getCmdParam())) {
String msg = "无新增的用户信息,不能处理";
@ -373,10 +374,11 @@ public class TaskService {
}
user.setPrivilege(0);
if(StringUtils.isNotBlank(userVo.getPhoto())) {
String bast64=getFileBast64("pm_worker",userVo.getUserId(),"1");
List<UploadFileVo> fileList=fileService.getFileBast64List(null,user.getUserId(),"pm_worker","1");
if(fileList!=null && !fileList.isEmpty()) {
String bast64=fileList.get(0).getBast64();
if(StringUtils.isNotBlank(bast64)) {
user.setPhoto_base64(bast64);
user.setPhoto_base64(ImageResizer.transImageByJpg(bast64));
user.setPhotoEnroll(1);
}
}
@ -476,7 +478,11 @@ public class TaskService {
public void insertUserIssued(DeviceTaskVo taskVo, List<DeviceUserDto> userList) {
try{
taskVo.setCreateTime(DateUtils.getTime());
mapper.insertUserIssued(taskVo,userList);
List<String> userIds=new ArrayList<>();
for (DeviceUserDto vo:userList){
userIds.add(vo.getUserId());
}
mapper.insertUserIssued(taskVo,userIds);
}catch (Exception e){
log.error(e.toString(),e);

View File

@ -13,7 +13,7 @@
select device_code devCode,device_name deviceName, pro_id proId,
dev_model devModel,on_line onLine
from pm_att_device
where device_code=#{devId} and is_active=1
where device_code=#{devId}
limit 1
</select>

View File

@ -44,17 +44,17 @@
insert into kq_cmd_task (
cmd_code, cmd_param, device_code, trans_status, create_time, update_state, msg, pro_id
)values
<foreach collection="list" item="item" separator=",">(
<foreach collection="list" item="item" separator=",">
(#{item.cmdCode},#{item.cmdParam},#{item.deviceCode},#{item.transStatus},#{item.createTime},#{item.updateStatus},#{item.msg},#{item.proId}
)
</foreach>
</insert>
<!--任务 记录批量插入-->
<insert id="insertCmdTaskByDeviceHistory" >
insert into kq_cmd_task (
insert into kq_cmd_task_history (
id,cmd_code, cmd_param, device_code, trans_status,create_time, update_state, msg, pro_id
)values
<foreach collection="list" item="item" separator=",">(
<foreach collection="list" item="item" separator=",">
(#{item.id},#{item.cmdCode},#{item.cmdParam},#{item.deviceCode},#{item.transStatus},#{item.createTime},#{item.updateStatus},#{item.msg},#{item.proId}
)
</foreach>

View File

@ -9,10 +9,10 @@
insert into pm_worker_user_issued(
user_id, dev_id, create_time, task_id, result
)values
<foreach collection="list" index="item" separator=",">
(#{item.userId},#{taskVo.deviceCode},#{taskVo.createTime},#{taskVo.id},'-1'
)
</foreach>
<foreach collection="list" index="item" separator=",">
(#{item},#{taskVo.deviceCode},#{taskVo.createTime},#{taskVo.id},'-1'
)
</foreach>
</insert>
<select id="selectCmdTaskList" resultType="com.bonus.urk.vo.DeviceTaskVo">
select id, cmd_code cmdCode,