From dd0a4783569d5499df04f00eb2d9591bdc4d4895 Mon Sep 17 00:00:00 2001 From: wen <1455474577@qq.com> Date: Fri, 18 Feb 2022 13:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=A8=E5=B1=80=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=9B=BE=E7=89=87=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E7=94=9F=E6=88=90=E6=8C=87=E5=AE=9A=E5=9C=BA=E7=AB=99?= =?UTF-8?q?=E4=B8=8B=E7=9A=84=E6=89=80=E6=9C=89=E7=BB=88=E7=AB=AF=E7=9A=84?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=9B=BE=E7=89=87=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=95=99=E8=A8=80=E6=9D=BF=EF=BC=8C=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=B8=BApost=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XhpcChargingPileController.java | 4 +- .../service/XhpcChargingPileServiceImpl.java | 71 ++++++++++--------- .../src/main/resources/bootstrap.yml | 1 - .../main/resources/mapper/XhpcImgMapper.xml | 37 ++++------ .../XhpcMessageBoardController.java | 4 +- 5 files changed, 54 insertions(+), 63 deletions(-) diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java index fc9601af..18aa2d28 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingPileController.java @@ -136,8 +136,8 @@ public class XhpcChargingPileController extends BaseController { * @date 2022/2/17 10:14 * @since version-1.0 */ - @PostMapping("/all/qr-code") - public AjaxResult generateQrCode(@RequestParam Long chargingStationId, @RequestParam Long pileId) { + @GetMapping("/all/qr-code") + public AjaxResult generateQrCode(@RequestParam Long chargingStationId, @RequestParam(required = false) Long pileId) { return xhpcChargingPileService.generateQrCode(chargingStationId, pileId); } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java index 360a1c67..a831aa62 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java @@ -37,6 +37,9 @@ import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.*; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import static com.aliyun.oss.internal.OSSConstants.URL_ENCODING; @@ -230,7 +233,7 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha Long chargingStationId = xhpcChargingPile.getChargingStationId(); if (xhpcChargingPile.getGunNumber() > 0) { // 删除阿里云上面之前可能存在的桩图片文件夹 - clearRepetition(environment, serialNumber); + // clearRepetition(environment, serialNumber); for (int i = 1; i <= xhpcChargingPile.getGunNumber(); i++) { addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i, number + 1, xhpcChargingPile.getConnectorType()); } @@ -438,6 +441,7 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha } @Override + @Transactional(rollbackFor = Exception.class) public AjaxResult generateQrCode(Long chargingStationId, Long pileId) { //get tenant id LoginUser loginUser = tokenService.getLoginUser(); @@ -445,6 +449,9 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha String tenantId = sysUser.getTenantId(); //query effective pile List xhpcChargingPile = xhpcChargingPileMapper.selectXhpcChargingPilesBy(chargingStationId, pileId, tenantId); + if (xhpcChargingPile.isEmpty()) { + return AjaxResult.success(); + } ArrayList pileIds = new ArrayList<>(); for (XhpcChargingPile chargingPile : xhpcChargingPile) { Long chargingPileId = chargingPile.getChargingPileId(); @@ -463,46 +470,40 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha //delete old qrcode img url data in the database List xhpcImgList = xhpcImgMapper.selectByTerminalId(terminalIds); for (XhpcImg xhpcImg : xhpcImgList) { + //阿里云冗余二维码图片清理代码 + //String prefix = null; + //clearRepetition(environment, prefix); xhpcImgMapper.updateDelFlagByTerminalId(xhpcImg.getTerminalId()); } //开启多个线程,并行执行操作 - - - //删除阿里云上面之前可能存在的桩图片文件夹 - //拼接桩路径,直接删除该桩下所有二维码 - String prefix = null; - clearRepetition(environment, prefix); //generate qrcode for every terminal + ThreadPoolExecutor executor = + new ThreadPoolExecutor(5, 20, 200, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(5)); for (XhpcTerminal xhpcTerminal : xhpcTerminalList) { - //获取场站名称: - String chargingStationName = xhpcChargingStationService.selectXhpcChargingStationById(xhpcTerminal.getChargingStationId()).getName(); - //解析桩号和枪号 - String terminalSerialNumberStr = xhpcTerminal.getSerialNumber(); - String pileAndGunNumberStr = terminalSerialNumberStr.substring(12); - String pileNumberStr = pileAndGunNumberStr.substring(0, 2); - String gunNumberStr = pileAndGunNumberStr.substring(2, 4); - int gunNumber = Integer.parseInt(gunNumberStr); - //生成最终的完整图片,并上传 - /** - * * @param xhpcTerminal 终端实体类 ok - * * @param serialNumber 终端序列号 ok - * * @param environment nacos对象 ok - * * @param xhpcImgMapper xhpc_img表对象 ok - * * @param chargingStationName 场站名称 ok - * * @param forIndex 枪号,用于拿出letterMap中的字母 - * * @param letterMap 字母集合 - * * @param name 桩号(桩名称) - */ - QrImgUtils.uploadImg(xhpcTerminal, xhpcTerminal.getSerialNumber(), environment, xhpcImgMapper, chargingStationName, gunNumber, letterMap, pileNumberStr); + executor.execute(() -> { + //获取场站名称: + String chargingStationName = xhpcChargingStationService.selectXhpcChargingStationById(xhpcTerminal.getChargingStationId()).getName(); + //解析桩号和枪号 + String terminalSerialNumberStr = xhpcTerminal.getSerialNumber(); + String pileAndGunNumberStr = terminalSerialNumberStr.substring(12); + String pileNumberStr = pileAndGunNumberStr.substring(0, 2); + String gunNumberStr = pileAndGunNumberStr.substring(2, 4); + int gunNumber = Integer.parseInt(gunNumberStr); + Integer pileNumber = Integer.parseInt(pileNumberStr); + //生成最终的完整图片,并上传 + /** + * * @param xhpcTerminal 终端实体类 + * * @param serialNumber 终端序列号 + * * @param environment nacos对象 + * * @param xhpcImgMapper xhpc_img表对象 + * * @param chargingStationName 场站名称 + * * @param forIndex 枪号,用于拿出letterMap中的字母 + * * @param letterMap 字母集合 + * * @param name 桩号(桩名称) + */ + QrImgUtils.uploadImg(xhpcTerminal, xhpcTerminal.getSerialNumber(), environment, xhpcImgMapper, chargingStationName, gunNumber, letterMap, pileNumber.toString()); + }); } return AjaxResult.success(); } - - public static void main(String[] args) { - - String str1 = "01"; - Long figure = Long.valueOf(str1); - System.out.println(figure); - } - } diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml b/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml index 079b2239..0ddc673f 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml @@ -24,7 +24,6 @@ spring: shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - #二维码Logo图片获取位置: #imgPath: "D:\\Enterprise_Resources\\XiaoHuaMaterialImgs\\xhcd_logo.png" #imgPath: "/www/wwwroot/scxhua.cn/xhpc-charging-stion/logo.png" diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcImgMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcImgMapper.xml index 599581b5..fbbb42b6 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcImgMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcImgMapper.xml @@ -27,30 +27,21 @@