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 @@