parent
80a61baea9
commit
7f5e71aeea
12 changed files with 399 additions and 30 deletions
@ -0,0 +1,51 @@ |
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.hospital.controller; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.excel.util.ExcelUtil; |
||||
import org.springblade.core.tenant.annotation.NonDS; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.hospital.entity.HikvisionCamera; |
||||
import org.springblade.hospital.service.IHikvisionCameraService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 接口权限控制器 |
||||
* @author BladeX |
||||
*/ |
||||
@NonDS |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/hikvisionCamera") |
||||
public class HikvisionCameraController extends BladeController { |
||||
|
||||
private final IHikvisionCameraService hikvisionCameraService; |
||||
|
||||
@PostMapping("/import-user") |
||||
public R importUser(MultipartFile file) { |
||||
List<HikvisionCamera> read = ExcelUtil.read(file, HikvisionCamera.class); |
||||
for (HikvisionCamera hikvisionCamera : read) { |
||||
hikvisionCamera.setName(hikvisionCamera.getName().split(" ")[0]); |
||||
} |
||||
return R.status(hikvisionCameraService.saveBatch(read)); |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.hospital.entity; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
|
||||
import java.sql.Time; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 布防撤防记录 |
||||
* @author BladeX |
||||
*/ |
||||
@Data |
||||
@TableName("ho_hikvision_camera") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class HikvisionCamera extends BaseEntity { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 任务标题 |
||||
*/ |
||||
@ExcelProperty("设备名称") |
||||
private String name; |
||||
|
||||
/** |
||||
* 任务执行时间 |
||||
*/ |
||||
@ExcelProperty("设备编号") |
||||
private String code; |
||||
} |
||||
@ -0,0 +1,29 @@ |
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.hospital.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.springblade.hospital.entity.HikvisionCamera; |
||||
|
||||
/** |
||||
* Mapper 接口 |
||||
* |
||||
* @author BladeX |
||||
*/ |
||||
public interface HikvisionCameraMapper extends BaseMapper<HikvisionCamera> { |
||||
|
||||
} |
||||
@ -0,0 +1,5 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="org.springblade.hospital.mapper.HikvisionCameraMapper"> |
||||
|
||||
</mapper> |
||||
@ -0,0 +1,28 @@ |
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.hospital.service; |
||||
|
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.hospital.entity.HikvisionCamera; |
||||
|
||||
/** |
||||
* 服务类 |
||||
* @author BladeX |
||||
*/ |
||||
public interface IHikvisionCameraService extends BaseService<HikvisionCamera> { |
||||
|
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.hospital.service.impl; |
||||
|
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.hospital.entity.HikvisionCamera; |
||||
import org.springblade.hospital.mapper.HikvisionCameraMapper; |
||||
import org.springblade.hospital.service.IHikvisionCameraService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* 服务实现类 |
||||
* |
||||
* @author BladeX |
||||
*/ |
||||
@Service |
||||
public class HikvisionCameraServiceImpl extends BaseServiceImpl<HikvisionCameraMapper, HikvisionCamera> implements IHikvisionCameraService { |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,144 @@ |
||||
package org.springblade.hospital.utils; |
||||
|
||||
import org.apache.commons.codec.binary.Base64; |
||||
import sun.misc.BASE64Decoder; |
||||
import sun.misc.BASE64Encoder; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.*; |
||||
import java.net.MalformedURLException; |
||||
import java.net.URL; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class ImageBase64Util { |
||||
|
||||
/** |
||||
* 将网络图片进行Base64位编码 |
||||
* @param imageUrl 图片的url路径,如http://.....xx.jpg
|
||||
* @return |
||||
*/ |
||||
public static String encodeImgageToBase64(String imageUrl) { |
||||
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
|
||||
ByteArrayOutputStream outputStream = null; |
||||
try { |
||||
String substring = imageUrl.substring(imageUrl.lastIndexOf(".") + 1); |
||||
BufferedImage bufferedImage = ImageIO.read(new URL(imageUrl)); |
||||
outputStream = new ByteArrayOutputStream(); |
||||
ImageIO.write(bufferedImage, substring, outputStream); |
||||
} catch (MalformedURLException e1) { |
||||
e1.printStackTrace(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
// 对字节数组Base64编码
|
||||
BASE64Encoder encoder = new BASE64Encoder(); |
||||
// 返回Base64编码过的字节数组字符串
|
||||
return encoder.encode(outputStream.toByteArray()); |
||||
} |
||||
|
||||
/** |
||||
* 将本地图片进行Base64位编码 |
||||
*/ |
||||
public static String encodeImgageToBase64(File imageFile) { |
||||
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
|
||||
ByteArrayOutputStream outputStream = null; |
||||
try { |
||||
BufferedImage bufferedImage = ImageIO.read(imageFile); |
||||
outputStream = new ByteArrayOutputStream(); |
||||
ImageIO.write(bufferedImage, "jpg", outputStream); |
||||
} catch (MalformedURLException e1) { |
||||
e1.printStackTrace(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
// 对字节数组Base64编码
|
||||
BASE64Encoder encoder = new BASE64Encoder(); |
||||
// 返回Base64编码过的字节数组字符串
|
||||
return encoder.encode(outputStream.toByteArray()); |
||||
} |
||||
|
||||
/** |
||||
* 将Base64位编码进行转本地图片 |
||||
*/ |
||||
public static void decodeBase64ToImage(String base64, String path, String imgName) { |
||||
BASE64Decoder decoder = new BASE64Decoder(); |
||||
try { |
||||
FileOutputStream write = new FileOutputStream(new File(path |
||||
+ imgName)); |
||||
byte[] decoderBytes = decoder.decodeBuffer(base64); |
||||
write.write(decoderBytes); |
||||
write.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
public static String getBase64(String imageUrl) { |
||||
File file = null; |
||||
String fileName = imageUrl.substring(imageUrl.lastIndexOf("."),imageUrl.length()); |
||||
URL urlfile; |
||||
InputStream inputStream = null; |
||||
OutputStream outputStream= null; |
||||
try { |
||||
file = File.createTempFile("wx_image", fileName); |
||||
//下载
|
||||
urlfile = new URL(imageUrl); |
||||
inputStream = urlfile.openStream(); |
||||
outputStream= new FileOutputStream(file); |
||||
|
||||
int bytesRead = 0; |
||||
byte[] buffer = new byte[8192]; |
||||
while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) { |
||||
outputStream.write(buffer, 0, bytesRead); |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
}finally { |
||||
try { |
||||
if (null != outputStream) { |
||||
outputStream.close(); |
||||
} |
||||
if (null != inputStream) { |
||||
inputStream.close(); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return getBase64ceshi(file); |
||||
} |
||||
|
||||
|
||||
public static String getBase64ceshi(File file) { |
||||
String base64Str = null; |
||||
FileInputStream inputStream = null; |
||||
try { |
||||
java.util.Base64.Encoder encoder = java.util.Base64.getEncoder(); |
||||
inputStream = new FileInputStream(file); |
||||
int available = inputStream.available(); |
||||
byte[] bytes = new byte[available]; |
||||
inputStream.read(bytes); |
||||
base64Str = encoder.encodeToString(bytes); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
}finally { |
||||
try { |
||||
inputStream.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return replaceEnter(base64Str); |
||||
} |
||||
|
||||
public static String replaceEnter(String str){ |
||||
String reg ="[\n-\r]"; |
||||
Pattern p = Pattern.compile(reg); |
||||
Matcher m = p.matcher(str); |
||||
return m.replaceAll(""); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue