From f28557268974cb62e2128a9b1dea65d0fa0ec0a9 Mon Sep 17 00:00:00 2001 From: gaoben Date: Tue, 13 Jul 2021 16:50:50 +0800 Subject: [PATCH] =?UTF-8?q?v2.0.16=201.=E9=81=97=E6=BC=8F=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shapelight/common/utils/PrivacyUtil.java | 59 ++++++++ .../shapelight/modules/vo/CarImageCache.java | 12 ++ .../src/test/java/gb/CarImageRedisTest.java | 50 +++++++ .../src/test/java/gb/ImageUpdateTest.java | 131 ++++++++++++++++++ .../src/test/java/gb/NullTest.java | 44 ++++++ 5 files changed, 296 insertions(+) create mode 100644 shapelight-admin/src/main/java/net/shapelight/common/utils/PrivacyUtil.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/vo/CarImageCache.java create mode 100644 shapelight-admin/src/test/java/gb/CarImageRedisTest.java create mode 100644 shapelight-admin/src/test/java/gb/ImageUpdateTest.java create mode 100644 shapelight-admin/src/test/java/gb/NullTest.java diff --git a/shapelight-admin/src/main/java/net/shapelight/common/utils/PrivacyUtil.java b/shapelight-admin/src/main/java/net/shapelight/common/utils/PrivacyUtil.java new file mode 100644 index 0000000..256380e --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/common/utils/PrivacyUtil.java @@ -0,0 +1,59 @@ +package net.shapelight.common.utils; + + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Pattern; + +import com.google.common.base.Strings; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +/** + * 日志辅助类,用来处理敏感信息,进行脱敏 + * @author tyg + * @date 2018年5月5日下午4:01:22 + */ +public class PrivacyUtil { + + private static String desensitizedName(String fullName) { + if (!Strings.isNullOrEmpty(fullName)) { + String name = StringUtils.left(fullName, 1); + return StringUtils.rightPad(name, StringUtils.length(fullName), "*"); + } + return fullName; + } + + private static String desensitizedPhoneNumber(String phoneNumber) { + if (StringUtils.isNotEmpty(phoneNumber)) { + phoneNumber = phoneNumber.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2"); + } + return phoneNumber; + } + + + private static String desensitizedIdNumber(String idNumber) { + if (!Strings.isNullOrEmpty(idNumber)) { + if (idNumber.length() == 15) { + idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{4})", "$1******$2"); + } + if (idNumber.length() == 18) { + idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{4})", "$1*********$2"); + } + } + return idNumber; + } + + public static void main(String[] args) { + String id = "610124198825458"; + String ide = desensitizedIdNumber(id); + System.out.println(ide); + + String m = "1368898"; + String me = desensitizedPhoneNumber(m); + System.out.println(me); + + } +} \ No newline at end of file diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/vo/CarImageCache.java b/shapelight-admin/src/main/java/net/shapelight/modules/vo/CarImageCache.java new file mode 100644 index 0000000..ea22fe1 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/vo/CarImageCache.java @@ -0,0 +1,12 @@ +package net.shapelight.modules.vo; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class CarImageCache implements Serializable { + private static final long serialVersionUID = 1L; + private String fileName; + private String imgUrl; +} diff --git a/shapelight-admin/src/test/java/gb/CarImageRedisTest.java b/shapelight-admin/src/test/java/gb/CarImageRedisTest.java new file mode 100644 index 0000000..b1c7513 --- /dev/null +++ b/shapelight-admin/src/test/java/gb/CarImageRedisTest.java @@ -0,0 +1,50 @@ +package gb; + +import com.alibaba.fastjson.JSONObject; +import io.minio.MinioClient; +import lombok.extern.slf4j.Slf4j; +import net.shapelight.AdminApplication; +import net.shapelight.common.config.MinioConfig; +import net.shapelight.common.utils.DateUtils; +import net.shapelight.common.utils.RedisUtils; +import net.shapelight.modules.xian.service.XaApi; +import net.shapelight.modules.xian.utils.XaUtils; +import net.shapelight.modules.xian.vo.XaData; +import net.shapelight.modules.xian.vo.XaPages; +import net.shapelight.modules.xian.vo.XaRYRKPHOTO; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Date; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AdminApplication.class) +@Slf4j +public class CarImageRedisTest { + + @Autowired + private MinioClient minioClient; + @Autowired + private MinioConfig minioConfig; + @Autowired + private RedisUtils redisUtils; + + @Test + public void carRedisTest(){ + Object url = redisUtils.getPattern("CarImage"); + if(url!=null){ + String urlStr = (String)url; + + } + } + +} diff --git a/shapelight-admin/src/test/java/gb/ImageUpdateTest.java b/shapelight-admin/src/test/java/gb/ImageUpdateTest.java new file mode 100644 index 0000000..af819ac --- /dev/null +++ b/shapelight-admin/src/test/java/gb/ImageUpdateTest.java @@ -0,0 +1,131 @@ +package gb; + +import com.alibaba.fastjson.JSONObject; +import io.minio.MinioClient; +import lombok.extern.slf4j.Slf4j; +import net.shapelight.AdminApplication; +import net.shapelight.common.config.MinioConfig; +import net.shapelight.common.utils.DateUtils; +import net.shapelight.modules.ten.entity.TenTranEntity; +import net.shapelight.modules.xian.service.XaApi; +import net.shapelight.modules.xian.utils.XaUtils; +import net.shapelight.modules.xian.vo.XaData; +import net.shapelight.modules.xian.vo.XaPages; +import net.shapelight.modules.xian.vo.XaRYRKPHOTO; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Date; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AdminApplication.class) +@Slf4j +public class ImageUpdateTest { + + @Autowired + private MinioClient minioClient; + @Autowired + private MinioConfig minioConfig; + + @Test + public void upTest(){ + + String appId = "1297164778041095"; + String appSecret = "22971647780410956329716477804109"; + String xqid = ""; + String fwikUrl = XaApi.getFwikUrl(appId, appSecret); + + /* + {"LV_CASE_ID":"10622102195604059627000138841819", + "LV_DJSJ":"20210712061714", + "LV_GMSFHM":"622102195604059627", + "LV_SSXQBM":"A61011312479", + "LV_ZP":""} + */ + String lv_case_id = "10622102195604059627000138841819"; + String lv_djsj = "20210712061714"; + String lv_gmsfhm = "622102195604059627"; + String lv_ssxqbm = "A61011312479"; + + String faceImageUrl = "images/842043084869992448/849569914418102274/s_76cfb8b5c54e4995b2d93775aeab7e69.jpg"; + + + + List syncPersons = new ArrayList(); + + XaRYRKPHOTO realPerson = new XaRYRKPHOTO(); + realPerson.setLV_CASE_ID(lv_case_id); //实有人口编码 + realPerson.setLV_GMSFHM(lv_gmsfhm); //身份证号 + realPerson.setLV_DJSJ(DateUtils.format(new Date(), "yyyyMMddHHmmss")); + realPerson.setLV_SSXQBM(lv_ssxqbm); + + + String base64Image = ""; + InputStream inStream = null; + ByteArrayOutputStream outStream = null; + + try { + minioClient.statObject(minioConfig.getBucketName(), faceImageUrl); + + inStream = minioClient.getObject(minioConfig.getBucketName(), faceImageUrl); + outStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int length; + while ((length = inStream.read(buffer)) != -1) { + outStream.write(buffer, 0, length); + } + base64Image = Base64.getEncoder().encodeToString(outStream.toByteArray()); + } catch (Exception e) { + log.error("照片不存在:" + faceImageUrl); + e.printStackTrace(); + } finally { + if (inStream != null) { + try { + inStream.close(); + } catch (IOException e) { + log.error("inputStream close IOException:" + e.getMessage()); + } + } + if (outStream != null) { + try { + outStream.close(); + } catch (IOException e) { + log.error("outStream close IOException:" + e.getMessage()); + } + } + } + + if (base64Image.length() == 0) { + return; + } + + realPerson.setLV_ZP(base64Image); + syncPersons.add(realPerson); + + + XaData jsonData = new XaData(); + jsonData.setDatas(syncPersons); + + List listPages = new ArrayList<>(); + XaPages pages = new XaPages(); + pages.setPno("1"); + pages.setPsize("1"); + listPages.add(pages); + jsonData.setPages(listPages); + + String json = JSONObject.toJSONString(jsonData); + String enJson = XaUtils.encryptStr(json.trim(), appSecret); + String resJson = XaApi.httpPOSTJson(fwikUrl, enJson, "RYRKPHOTO", "RYRKPHOTO", appId, appSecret,"1000000001"); + log.debug("上传实有人口返回数据:" + resJson); + } + +} diff --git a/shapelight-admin/src/test/java/gb/NullTest.java b/shapelight-admin/src/test/java/gb/NullTest.java new file mode 100644 index 0000000..c8114e6 --- /dev/null +++ b/shapelight-admin/src/test/java/gb/NullTest.java @@ -0,0 +1,44 @@ +package gb; + +import io.minio.MinioClient; +import io.minio.PutObjectOptions; +import net.shapelight.AdminApplication; +import net.shapelight.common.config.MinioConfig; +import net.shapelight.common.utils.ImageUtils; +import net.shapelight.common.utils.StringUtils; +import net.shapelight.common.utils.ThumbnailsUtils; +import net.shapelight.common.utils.UUIDUtil; +import net.shapelight.modules.ten.entity.TenPackRecordEnterEntity; +import net.shapelight.modules.ten.service.TenPackRecordEnterService; +import net.shapelight.modules.ten.service.TenPackRecordService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AdminApplication.class) +public class NullTest { + + @Autowired + private TenPackRecordEnterService tenPackRecordEnterService; + + @Test + public void test1() { + + List records = this.tenPackRecordEnterService.getNotSync(836275079963738113L); + System.out.println(""); + + } +}