From 09dc299e6782166049af8ef2b3a60ff0492861da Mon Sep 17 00:00:00 2001 From: wen <1455474577@qq.com> Date: Thu, 17 Feb 2022 17:10:23 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XhpcChargingPileController.java | 14 ++ .../mapper/XhpcChargingPileMapper.java | 12 +- .../station/mapper/XhpcImgMapper.java | 26 ++- .../station/mapper/XhpcTerminalMapper.java | 14 +- .../xhpc/charging/station/pojo/XhpcImg.java | 155 ++++++++++++++++++ .../service/IXhpcChargingPileService.java | 13 +- .../service/XhpcChargingPileServiceImpl.java | 100 ++++++++++- .../station/utils/img/QrImgUtils.java | 15 +- .../mapper/XhpcChargingPileMapper.xml | 15 +- .../main/resources/mapper/XhpcImgMapper.xml | 38 ++++- .../resources/mapper/XhpcTerminalMapper.xml | 20 ++- 11 files changed, 397 insertions(+), 25 deletions(-) create mode 100644 xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/pojo/XhpcImg.java 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 6d783c28..fc9601af 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 @@ -121,6 +121,7 @@ public class XhpcChargingPileController extends BaseController { @Log(title = "桩-导入电桩", businessType = BusinessType.IMPORT) @PostMapping("/importData") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil(XhpcChargingPile.class); List pileList = util.importExcel(file.getInputStream()); String operName = SecurityUtils.getUsername(); @@ -128,4 +129,17 @@ public class XhpcChargingPileController extends BaseController { return AjaxResult.success(message); } + /** + * generate all qrcode by id of charging station and id of charging pile + * + * @author WH + * @date 2022/2/17 10:14 + * @since version-1.0 + */ + @PostMapping("/all/qr-code") + public AjaxResult generateQrCode(@RequestParam Long chargingStationId, @RequestParam Long pileId) { + + return xhpcChargingPileService.generateQrCode(chargingStationId, pileId); + } + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java index 1a8739e5..609a0d23 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java @@ -98,12 +98,22 @@ public interface XhpcChargingPileMapper { /** * 对应场站的桩数量 + * * @param chargingStationId * @return */ int pileCount(@Param("chargingStationId") Long chargingStationId); - XhpcChargingPile getXhpcChargingPileBySerialNumber(@Param("serialNumber") String serialNumber); + + /** + * query list of xhpc charging pile by charging station id and charging pile id + * + * @author WH + * @date 2022/2/17 10:32 + * @since version-1.0 + */ + List selectXhpcChargingPilesBy(@Param("chargingStationId") Long chargingStationId, @Param("chargingPileId") Long chargingPileId, @Param("tenantId") String tenantId); + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcImgMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcImgMapper.java index 6c77e0f0..d24c38f0 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcImgMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcImgMapper.java @@ -1,7 +1,9 @@ package com.xhpc.charging.station.mapper; +import com.xhpc.charging.station.pojo.XhpcImg; import org.apache.ibatis.annotations.Param; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -20,12 +22,30 @@ public interface XhpcImgMapper { * @param terminalId 图片所对应的终端的id * @return */ - void insert(@Param("imgUrl") String imgUrl,@Param("terminalId") Long terminalId); + void insert(@Param("imgUrl") String imgUrl, @Param("terminalId") Long terminalId); /** - * * @param terminalIds 终端id集合 * @return 返回带有url和对应终端id编号的集合实体类 */ - List> selectImgUrlByTerminal_id(List terminalIds); + List> selectImgUrlByTerminal_id(List terminalIds); + + /** + * query XhpcTerminal by terminal id + * + * @author WH + * @date 2022/2/17 11:28 + * @since version-1.0 + */ + List selectByTerminalId(ArrayList terminalIds); + + /** + * Update del flag status of img record by terminal id + * + * @author WH + * @date 2022/2/17 12:56 + * @since version-1.0 + */ + void updateDelFlagByTerminalId(Long terminalId); + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java index 5ce98d96..97129efb 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java @@ -3,6 +3,7 @@ package com.xhpc.charging.station.mapper; import com.xhpc.common.domain.XhpcTerminal; import org.apache.ibatis.annotations.Param; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -111,8 +112,19 @@ public interface XhpcTerminalMapper { /** * 根据电站获取终端的编号 + * * @param chargingStationId * @return */ - List getTerminal(@Param("chargingStationId") Long chargingStationId,@Param("status") Integer status); + List getTerminal(@Param("chargingStationId") Long chargingStationId, @Param("status") Integer status); + + /** + * according pileIds query xhpcTerminalList + * + * @author WH + * @date 2022/2/17 11:13 + * @since version-1.0 + */ + List selectXhpcTerminalIdByPileIds(ArrayList pileIds); + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/pojo/XhpcImg.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/pojo/XhpcImg.java new file mode 100644 index 00000000..0043638c --- /dev/null +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/pojo/XhpcImg.java @@ -0,0 +1,155 @@ +package com.xhpc.charging.station.pojo; + +import javax.persistence.*; +import java.time.Instant; + +@Entity +@Table(name = "xhpc_img") +public class XhpcImg { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "img_id", nullable = false) + private Long id; + + @Column(name = "url") + private String url; + + @Column(name = "status") + private Integer status; + + @Column(name = "del_flag") + private Integer delFlag; + + @Column(name = "create_time") + private Instant createTime; + + @Column(name = "create_by", length = 30) + private String createBy; + + @Column(name = "update_time") + private Instant updateTime; + + @Column(name = "update_by", length = 30) + private String updateBy; + + @Column(name = "remark") + private String remark; + + @Column(name = "terminal_id") + private Long terminalId; + + @Column(name = "tenant_id", length = 12) + private String tenantId; + + public String getTenantId() { + + return tenantId; + } + + public void setTenantId(String tenantId) { + + this.tenantId = tenantId; + } + + public Long getTerminalId() { + + return terminalId; + } + + public void setTerminalId(Long terminalId) { + + this.terminalId = terminalId; + } + + public String getRemark() { + + return remark; + } + + public void setRemark(String remark) { + + this.remark = remark; + } + + public String getUpdateBy() { + + return updateBy; + } + + public void setUpdateBy(String updateBy) { + + this.updateBy = updateBy; + } + + public Instant getUpdateTime() { + + return updateTime; + } + + public void setUpdateTime(Instant updateTime) { + + this.updateTime = updateTime; + } + + public String getCreateBy() { + + return createBy; + } + + public void setCreateBy(String createBy) { + + this.createBy = createBy; + } + + public Instant getCreateTime() { + + return createTime; + } + + public void setCreateTime(Instant createTime) { + + this.createTime = createTime; + } + + public Integer getDelFlag() { + + return delFlag; + } + + public void setDelFlag(Integer delFlag) { + + this.delFlag = delFlag; + } + + public Integer getStatus() { + + return status; + } + + public void setStatus(Integer status) { + + this.status = status; + } + + public String getUrl() { + + return url; + } + + public void setUrl(String url) { + + this.url = url; + } + + public Long getId() { + + return id; + } + + public void setId(Long id) { + + this.id = id; + } + +} \ No newline at end of file diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java index d3457f96..d967b7b0 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingPileService.java @@ -72,9 +72,18 @@ public interface IXhpcChargingPileService { * @Return List * @Since version-1.0 */ - List> downloadsTerminalImgs(List terminalIds); + List> downloadsTerminalImgs(List terminalIds); + String importPile(List pileList, Boolean isUpdateSupport, String operName); + + /** + * generate all qrcode by id of charging station and id of charging pile + * + * @author WH + * @date 2022/2/17 10:20 + * @since version-1.0 + */ + AjaxResult generateQrCode(Long chargingStationId, Long pileId); - String importPile(List pileList, Boolean isUpdateSupport, String operName); } 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 799351a5..360a1c67 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 @@ -7,6 +7,7 @@ import com.aliyun.oss.model.*; import com.xhpc.charging.station.mapper.XhpcChargingPileMapper; import com.xhpc.charging.station.mapper.XhpcImgMapper; import com.xhpc.charging.station.mapper.XhpcTerminalMapper; +import com.xhpc.charging.station.pojo.XhpcImg; import com.xhpc.charging.station.utils.img.QrImgUtils; import com.xhpc.common.api.PowerPileService; import com.xhpc.common.core.constant.HttpStatus; @@ -22,7 +23,9 @@ import com.xhpc.common.domain.XhpcTerminal; import com.xhpc.common.enums.ConnectorTypeEnum; import com.xhpc.common.enums.PileEquipmentTypeEnum; import com.xhpc.common.enums.PowerTypeEnum; +import com.xhpc.common.security.service.TokenService; import com.xhpc.common.util.LogUserUtils; +import com.xhpc.system.api.domain.SysUser; import com.xhpc.system.api.model.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; @@ -59,12 +62,15 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha private IXhpcChargingStationService xhpcChargingStationService; @Autowired private LogUserUtils logUserUtils; + @Autowired + private TokenService tokenService; //字母集合 private static Map letterMap; - static{ + + static { Character letter = 'A'; - letterMap = new HashMap(); - for (int i = 1;i<=26;i++){ + letterMap = new HashMap(); + for (int i = 1; i <= 26; i++) { letterMap.put(i, letter); letter++; } @@ -150,11 +156,21 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha if (r.getCode() != 200) { //数据回滚-手动回滚 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - return AjaxResult.error("添加桩入缓存失败,请稍后在试"); + return AjaxResult.error("添加桩入缓存失败,请稍后在试"); } return AjaxResult.success(); } + /** + * @param name 桩名称 + * @param chargingPileId 场站id + * @param rateModelId 费率模型id + * @param i 枪号,索引,map映射 + * @pa + * @author Yu yang + * @date 2022/2/17 15:31 + * @since version-1.0 + */ private void addXhpcTerminal(String name, Long chargingStationId, Long rateModelId, String serialNumber, Long chargingPileId, int i, int number, int conType) { XhpcTerminal xhpcTerminal = new XhpcTerminal(); @@ -338,8 +354,8 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha @Override public String importPile(List pileList, Boolean isUpdateSupport, String operName){ - if (pileList == null || pileList.size() == 0) - { + + if (pileList == null || pileList.size() == 0) { throw new CustomException("导入电桩数据不能为空!"); } @@ -407,8 +423,7 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha } else { successNum++; } - } - catch (Exception e) { + } catch (Exception e) { failureNum++; failureMsg.append("
电站名称: ").append(pile.getChargingStationName()).append(" ,电桩名称: ").append(pile.getName()).append(" 导入失败; 失败原因: ").append(e.getMessage()); } @@ -421,4 +436,73 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha } return successMsg.toString(); } + + @Override + public AjaxResult generateQrCode(Long chargingStationId, Long pileId) { + //get tenant id + LoginUser loginUser = tokenService.getLoginUser(); + SysUser sysUser = loginUser.getSysUser(); + String tenantId = sysUser.getTenantId(); + //query effective pile + List xhpcChargingPile = xhpcChargingPileMapper.selectXhpcChargingPilesBy(chargingStationId, pileId, tenantId); + ArrayList pileIds = new ArrayList<>(); + for (XhpcChargingPile chargingPile : xhpcChargingPile) { + Long chargingPileId = chargingPile.getChargingPileId(); + pileIds.add(chargingPileId); + } + //get effective terminal + List xhpcTerminalList = xhpcTerminalMapper.selectXhpcTerminalIdByPileIds(pileIds); + if (xhpcTerminalList.isEmpty()) { + return AjaxResult.success(); + } + ArrayList terminalIds = new ArrayList<>(); + for (XhpcTerminal xhpcTerminal : xhpcTerminalList) { + Long terminalId = xhpcTerminal.getTerminalId(); + terminalIds.add(terminalId); + } + //delete old qrcode img url data in the database + List xhpcImgList = xhpcImgMapper.selectByTerminalId(terminalIds); + for (XhpcImg xhpcImg : xhpcImgList) { + xhpcImgMapper.updateDelFlagByTerminalId(xhpcImg.getTerminalId()); + } + //开启多个线程,并行执行操作 + + + //删除阿里云上面之前可能存在的桩图片文件夹 + //拼接桩路径,直接删除该桩下所有二维码 + String prefix = null; + clearRepetition(environment, prefix); + //generate qrcode for every terminal + 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); + } + 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/java/com/xhpc/charging/station/utils/img/QrImgUtils.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/QrImgUtils.java index 89e72702..0177d6fe 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/QrImgUtils.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/QrImgUtils.java @@ -13,10 +13,17 @@ import java.util.Map; public class QrImgUtils { /** + * @param xhpcTerminal 终端实体类 + * @param serialNumber 终端序列号 + * @param environment nacos对象 + * @param xhpcImgMapper xhpc_img表对象 + * @param chargingStationName 场站名称 + * @param forIndex 枪号,用于拿出letterMap中的字母 + * @param letterMap 字母集合 + * @param name 桩号(桩名称) * @Author WH * @Date 2021/9/8 15:55 * @Description upload images to Server - * @Param [xhpcTerminal, chargingPileId, environment, xhpcImgMapper] * @Return void * @Since version-1.0 */ @@ -48,12 +55,14 @@ public class QrImgUtils { // 创建OSSClient实例 OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key")); // 上传文件流 - ossClient.putObject(environment.getProperty("oss.bucket-name"), xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, new File(environment.getProperty("destPath") + File.separatorChar + finallyImgFileName)); + // 拼接阿里云文件上传路径 + String aLiYunUploadLocation = "QrCodeImg/" + xhpcTerminal.getChargingStationId() + "/" + xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName; + ossClient.putObject(environment.getProperty("oss.bucket-name"), aLiYunUploadLocation, new File(environment.getProperty("destPath") + File.separatorChar + finallyImgFileName)); ossClient.shutdown(); System.out.println("===================》将完整二维码上传至阿里云成功"); //5.将放在阿里云上的生成的图片的路径和图片所对应的终端的id放入数据库xhpc_img表中 Long terminalId = xhpcTerminal.getTerminalId(); - xhpcImgMapper.insert(xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, terminalId); + xhpcImgMapper.insert(aLiYunUploadLocation, terminalId); System.out.println("===================》将阿里云上的图片地址放入数据库"); //6.删除生成的二维码图片 File QrImg = new File(environment.getProperty("destPath") + File.separatorChar + qrFileName); diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml index 97e08fc5..8e00e396 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml @@ -485,12 +485,23 @@ remark, rate_model_id, brand_model, - production_date productionDate, + production_date productionDate, manufacture_name manufactureName, - connector_type connectorType, + connector_type connectorType, current, equipment_type equipmentType from xhpc_charging_pile where serial_number = #{serialNumber} + 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 a876f90b..599581b5 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 @@ -2,11 +2,18 @@ + - INSERT INTO xhpc_img(url,terminal_id) VALUES(#{imgUrl},#{terminalId}) + INSERT INTO xhpc_img(url, terminal_id) + VALUES (#{imgUrl}, #{terminalId}) + + UPDATE xhpc_img + SET del_flag = 2 + WHERE terminal_id = #{terminalId} + + diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml index 221e71e3..5bdbb73c 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml @@ -378,13 +378,25 @@ And terminal.serial_number like CONCAT('%',#{pileName},'%') - - And terminal.serial_number like CONCAT('%',#{stationName},'%') - + + And terminal.serial_number like CONCAT('%',#{stationName},'%') + +