From cef8129dd595e2d881592cb83dd302971665a085 Mon Sep 17 00:00:00 2001 From: jianjun Date: Sat, 19 Mar 2022 11:53:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=A0=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=B8=B4=E6=97=B6=E7=BC=93=E5=AD=98=20=E8=A6=81?= =?UTF-8?q?=E4=B8=8D=E7=84=B6=E5=89=8D=E7=AB=AF=E5=AE=B9=E6=98=93=E6=8C=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisUtils.java | 4 +++ .../govorg/impl/GovOrgServiceImpl.java | 36 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java index 32cba063c5..27636e435a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java @@ -440,4 +440,8 @@ public class RedisUtils { public Long bitCount(String key, int start, int end) { return redisTemplate.execute((RedisCallback) con -> con.bitCount(key.getBytes(), start, end)); } + + public Long getTTL(String treeCacheKey) { + return redisTemplate.getExpire(treeCacheKey); + } } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java index 00997c59cd..e943dd5894 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java @@ -12,8 +12,11 @@ import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.form.DingTextBriefNessFormDTO; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.redis.common.CustomerOrgRedis; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; @@ -60,6 +63,7 @@ import java.io.OutputStream; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; /** @@ -95,6 +99,10 @@ public class GovOrgServiceImpl implements GovOrgService { private EvaluationIndexService evaluationIndexService; @Autowired private IcBuildingDao icBuildingDao; + @Autowired + private RedisUtils redisUtils; + @Autowired + private ExecutorService executorService; /** * @param staffId @@ -583,12 +591,34 @@ public class GovOrgServiceImpl implements GovOrgService { @Override public List getAgencyTree(TokenDto tokenDto, SubOrgFormDTO formDTO) { CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); + if (staffInfo == null || StringUtils.isBlank(staffInfo.getAgencyId())){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"工作人员所属组织不存在"); + } + //组织缓存key + String treeCacheKey = RedisKeys.getOrgTreeCacheKey(formDTO.getAgencyId()).concat(StrConstant.COLON).concat(formDTO.getClient()); + Long expiryTime = redisUtils.getTTL(treeCacheKey); + List orgTreeResultDTOS = (List) redisUtils.get(treeCacheKey); + String agencyId = staffInfo.getAgencyId(); + String client = formDTO.getClient(); + //如果接近过期或已经过期且缓存数据不为空 则异步查询 + if ((expiryTime == null || expiryTime <= NumConstant.ONE_THOUSAND) && CollectionUtils.isNotEmpty(orgTreeResultDTOS)) { + executorService.submit(() -> { + List list = buildTempOrgTree(agencyId, client); + redisUtils.set(treeCacheKey, list, RedisUtils.HOUR_FOUR_EXPIRE); + }); + } else { + orgTreeResultDTOS = buildTempOrgTree(staffInfo.getAgencyId(), formDTO.getClient()); + redisUtils.set(treeCacheKey, orgTreeResultDTOS, RedisUtils.HOUR_FOUR_EXPIRE); + } + return orgTreeResultDTOS; + } + private List buildTempOrgTree(String agencyId, String client){ List list = new ArrayList<>(); - if ("resi".equals(formDTO.getClient())) { - list.add(customerAgencyDao.getResiOrgTree(staffInfo.getAgencyId())); + if ("resi".equals(client)) { + list.add(customerAgencyDao.getResiOrgTree(agencyId)); return list; } - list.add(customerAgencyDao.getOrgTree(staffInfo.getAgencyId())); + list.add(customerAgencyDao.getOrgTree(agencyId)); return list; } From f9ac6488493f2f01c1295d63a80fb2ab8de89854 Mon Sep 17 00:00:00 2001 From: jianjun Date: Sat, 19 Mar 2022 12:35:40 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=A0=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=B8=B4=E6=97=B6=E7=BC=93=E5=AD=98=20=E8=A6=81?= =?UTF-8?q?=E4=B8=8D=E7=84=B6=E5=89=8D=E7=AB=AF=E5=AE=B9=E6=98=93=E6=8C=82?= =?UTF-8?q?=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataaggre/service/govorg/impl/GovOrgServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java index e943dd5894..94cb0edb83 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java @@ -594,12 +594,12 @@ public class GovOrgServiceImpl implements GovOrgService { if (staffInfo == null || StringUtils.isBlank(staffInfo.getAgencyId())){ throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"工作人员所属组织不存在"); } + String agencyId = staffInfo.getAgencyId(); + String client = formDTO.getClient(); //组织缓存key - String treeCacheKey = RedisKeys.getOrgTreeCacheKey(formDTO.getAgencyId()).concat(StrConstant.COLON).concat(formDTO.getClient()); + String treeCacheKey = RedisKeys.getOrgTreeCacheKey(agencyId).concat(StrConstant.COLON).concat(client); Long expiryTime = redisUtils.getTTL(treeCacheKey); List orgTreeResultDTOS = (List) redisUtils.get(treeCacheKey); - String agencyId = staffInfo.getAgencyId(); - String client = formDTO.getClient(); //如果接近过期或已经过期且缓存数据不为空 则异步查询 if ((expiryTime == null || expiryTime <= NumConstant.ONE_THOUSAND) && CollectionUtils.isNotEmpty(orgTreeResultDTOS)) { executorService.submit(() -> { From f08678d3f1213301aa45e49d130d963b87c61e8c Mon Sep 17 00:00:00 2001 From: jianjun Date: Sat, 19 Mar 2022 12:52:08 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=A0=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=B8=B4=E6=97=B6=E7=BC=93=E5=AD=98=20=E8=A6=81?= =?UTF-8?q?=E4=B8=8D=E7=84=B6=E5=89=8D=E7=AB=AF=E5=AE=B9=E6=98=93=E6=8C=82?= =?UTF-8?q?=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java index 94cb0edb83..b10b6648fc 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java @@ -606,7 +606,7 @@ public class GovOrgServiceImpl implements GovOrgService { List list = buildTempOrgTree(agencyId, client); redisUtils.set(treeCacheKey, list, RedisUtils.HOUR_FOUR_EXPIRE); }); - } else { + } else if (CollectionUtils.isEmpty(orgTreeResultDTOS)){ orgTreeResultDTOS = buildTempOrgTree(staffInfo.getAgencyId(), formDTO.getClient()); redisUtils.set(treeCacheKey, orgTreeResultDTOS, RedisUtils.HOUR_FOUR_EXPIRE); } From 348c42452aaa7e403c63ce69c8d118eb32bc5781 Mon Sep 17 00:00:00 2001 From: jianjun Date: Sat, 19 Mar 2022 17:44:30 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=B8=BAopen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/tools/utils/BarcodeUtils.java | 2 +- .../com/epmet/controller/AgencyController.java | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java index ee5369b3af..a98c87a0a9 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java @@ -115,7 +115,7 @@ public class BarcodeUtils { String s = outStringByByte(pressText, maxSize); g.drawString(s, (WIDTH - (FONTSIZE * (WIDTH / FONTSIZE - 2))) / 2, startY); pressText = pressText.substring(s.length(), pressText.length()); - startY = startY + 30; + startY = startY + 35; } if (v != 0) { g.drawString(pressText, (WIDTH - (FONTSIZE * v)) / 2, startY); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index fa337b1fd2..0fd174dba9 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java @@ -17,7 +17,6 @@ package com.epmet.controller; -import com.alibaba.fastjson.JSONObject; import com.epmet.commons.rocketmq.messages.OrgOrStaffMQMsg; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.RequirePermission; @@ -43,12 +42,6 @@ import com.epmet.send.SendMqMsgUtil; import com.epmet.service.AgencyService; import com.epmet.service.CustomerAgencyService; import com.epmet.service.IcNeighborHoodService; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.EncodeHintType; -import com.google.zxing.MultiFormatWriter; -import com.google.zxing.WriterException; -import com.google.zxing.client.j2se.MatrixToImageWriter; -import com.google.zxing.common.BitMatrix; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -58,10 +51,11 @@ import javax.imageio.ImageIO; import javax.imageio.stream.ImageOutputStream; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URLEncoder; -import java.nio.file.FileSystems; -import java.nio.file.Path; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.HashMap; @@ -415,7 +409,9 @@ public class AgencyController { } //url组成:数字社区地址?小区id&用户id //String url = "https://demo.tduckapp.com/s/7314b64b3a26455ab793fb8c640856b6?id="+id; - String url = EnvEnum.getCurrentEnv().getUrl().replace("api/", StrConstant.EPMETY_STR) + String url = EnvEnum.getCurrentEnv().getUrl() + .replace("cloud","open") + .replace("api/", StrConstant.EPMETY_STR) .concat("epmet-oper-gov/#/caiji/") .concat(id).concat("?") .concat("name=").concat(URLEncoder.encode(name,StrConstant.UTF_8)).concat(StrConstant.AND_MARK) From 130f22d087075268519d004c2953fe460ecdfef8 Mon Sep 17 00:00:00 2001 From: jianjun Date: Sat, 19 Mar 2022 19:25:39 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E5=B9=B6=E8=AE=BE=E7=BD=AE=E6=96=87=E5=AD=97=E9=97=B4?= =?UTF-8?q?=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-commons/epmet-commons-tools/pom.xml | 4 +-- .../commons/tools/utils/BarcodeUtils.java | 2 +- .../epmet/controller/AgencyController.java | 28 +++++++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/pom.xml b/epmet-commons/epmet-commons-tools/pom.xml index 7542899ad0..7f1fb8e728 100644 --- a/epmet-commons/epmet-commons-tools/pom.xml +++ b/epmet-commons/epmet-commons-tools/pom.xml @@ -169,13 +169,13 @@ com.google.zxing core - 3.3.2 + 3.4.1 com.google.zxing javase - 3.3.2 + 3.4.1 diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java index ee5369b3af..07af293c07 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java @@ -95,7 +95,7 @@ public class BarcodeUtils { //x开始的位置:(图片宽度-字体大小*字的个数)/2 int startX = (WIDTH - (FONTSIZE * pressText.length())) / 2; //y开始的位置:图片高度-(图片高度-图片宽度)/2 - int startY = HEIGHT - (HEIGHT - WIDTH) / 2; + int startY = HEIGHT - (HEIGHT - WIDTH) / 2+ FONTSIZE; int imageW = outImage.getWidth(); int imageH = outImage.getHeight(); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index fa337b1fd2..e7396e96f8 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java @@ -17,7 +17,6 @@ package com.epmet.controller; -import com.alibaba.fastjson.JSONObject; import com.epmet.commons.rocketmq.messages.OrgOrStaffMQMsg; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.RequirePermission; @@ -43,12 +42,7 @@ import com.epmet.send.SendMqMsgUtil; import com.epmet.service.AgencyService; import com.epmet.service.CustomerAgencyService; import com.epmet.service.IcNeighborHoodService; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.EncodeHintType; -import com.google.zxing.MultiFormatWriter; -import com.google.zxing.WriterException; -import com.google.zxing.client.j2se.MatrixToImageWriter; -import com.google.zxing.common.BitMatrix; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -60,8 +54,6 @@ import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.*; import java.net.URLEncoder; -import java.nio.file.FileSystems; -import java.nio.file.Path; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.HashMap; @@ -450,4 +442,22 @@ public class AgencyController { } } + public static void main(String[] args) { + try { + BufferedImage image = BarcodeUtils.drawQRImage("小崽子社区中国国歌过过过过过所多对方水电费是的发生的", "https://epmet-cloud.elinkservice.cn/epmet-oper-gov/#/caiji/b058eb82d65d922fec9dc84f0348fc6a?name=%E5%B0%8F%E5%AF%A8%E5%AD%90%E7%A4%BE%E5%8C%BA&customerId=3fdd0380deff5b30f45376cdf995d1c1&type=community&userId=72d331139a5012b6bba18b40029a2755&123123123111"); + //BufferedImage image = BarcodeUtils.drawQRImage("小崽子社区", "erId=72d331139a5012b6bba18b40029a2755&123123123111"); + //BufferedImage image2 = BarcodeUtils.getQRCode("小崽子社区", "https://epmet-cloud.elinkservice.cn/epmet-oper-gov/#/caiji/b058eb82d65d922fec9dc84f0348fc6a?name=%E5%B0%8F%E5%AF%A8%E5%AD%90%E7%A4%BE%E5%8C%BA&customerId=3fdd0380deff5b30f45376cdf995d1c1&type=community&userId=72d331139a5012b6bba18b40029a2755&123123123111"); + //BufferedImage 转 InputStream + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageOutputStream imageOutput = ImageIO.createImageOutputStream(byteArrayOutputStream); + ImageIO.write(image, "png", imageOutput); + InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + String s = "/Users/liujianjun/Downloads/t.png"; + File file= new File(s); + FileUtils.copyInputStreamToFile(inputStream, file); + } catch (Exception e) { + e.printStackTrace(); + } + } + }