From bc629d8e188eff1d0a88afa015b090a9039e3aa9 Mon Sep 17 00:00:00 2001 From: panshulin Date: Mon, 29 Nov 2021 11:51:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=85=A5=E7=94=B5?= =?UTF-8?q?=E6=A1=A9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XhpcChargingPileController.java | 19 +++++ .../mapper/XhpcChargingStationMapper.java | 9 ++ .../service/IXhpcChargingPileService.java | 3 + .../service/IXhpcChargingStationService.java | 10 +++ .../service/XhpcChargingPileServiceImpl.java | 77 ++++++++++++++++- .../XhpcChargingStationServiceImpl.java | 13 +++ .../mapper/XhpcChargingStationMapper.xml | 5 ++ .../xhpc/common/domain/XhpcChargingPile.java | 83 ++++++++++++++++++- .../xhpc/common/enums/ConnectorTypeEnum.java | 67 +++++++++++++++ .../xhpc/common/enums/EquipmentTypeEnum.java | 63 ++++++++++++++ .../com/xhpc/common/enums/PowerTypeEnum.java | 51 ++++++++++++ 11 files changed, 397 insertions(+), 3 deletions(-) create mode 100644 xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/ConnectorTypeEnum.java create mode 100644 xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/EquipmentTypeEnum.java create mode 100644 xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/PowerTypeEnum.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 3882decb..47eb5d4c 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 @@ -1,12 +1,15 @@ package com.xhpc.charging.station.controller; import com.xhpc.charging.station.service.IXhpcChargingPileService; +import com.xhpc.common.core.utils.SecurityUtils; +import com.xhpc.common.core.utils.poi.ExcelUtil; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.page.TableDataInfo; import com.xhpc.common.domain.XhpcChargingPile; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; import java.util.Map; @@ -102,4 +105,20 @@ public class XhpcChargingPileController extends BaseController { } + /** + * 导入电桩 + * @param file + * @param updateSupport + * @return + * @throws Exception + */ + @PostMapping("/import") + 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(); + String message = xhpcChargingPileService.importPile(pileList, updateSupport, operName); + return AjaxResult.success(message); + } + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java index 12dceea7..650002f3 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java @@ -27,6 +27,15 @@ public interface XhpcChargingStationMapper { */ XhpcChargingStation selectXhpcChargingStationById(Long chargingStationId); + + + /** + * 查询电站 + * + * @param chargingStationName 电站名称 + * @return 电站 + */ + XhpcChargingStation selectXhpcChargingStationByName(String chargingStationName); /** * 查询电站列表 * 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 f5e22cb2..44386e4e 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 @@ -73,4 +73,7 @@ public interface IXhpcChargingPileService { */ List> downloadsTerminalImgs(List terminalIds); + + + String importPile(List pileList, Boolean isUpdateSupport, String operName); } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java index d3f8cdf6..0dbcb977 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcChargingStationService.java @@ -34,6 +34,16 @@ public interface IXhpcChargingStationService { */ XhpcChargingStation selectXhpcChargingStationById(Long chargingStationId); + + /** + * 查询电站 + * + * @param chargingStationName 电站名称 + * @return 电站 + */ + XhpcChargingStation selectXhpcChargingStationByName(String chargingStationName); + + /** * 查询电站列表 * 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 5e3f2304..971be3a6 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 @@ -8,11 +8,17 @@ import com.xhpc.charging.station.mapper.XhpcImgMapper; import com.xhpc.charging.station.mapper.XhpcTerminalMapper; import com.xhpc.charging.station.utils.img.QrImgUtils; import com.xhpc.common.api.PowerPileService; +import com.xhpc.common.core.constant.HttpStatus; +import com.xhpc.common.core.exception.CustomException; import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.utils.StringUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.domain.XhpcChargingPile; +import com.xhpc.common.domain.XhpcChargingStation; import com.xhpc.common.domain.XhpcTerminal; +import com.xhpc.common.enums.ConnectorTypeEnum; +import com.xhpc.common.enums.EquipmentTypeEnum; +import com.xhpc.common.enums.PowerTypeEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; @@ -155,7 +161,6 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal); //获取场站名称: - String chargingStationName = xhpcChargingStationService.selectXhpcChargingStationById(xhpcTerminal.getChargingStationId()).getName(); //生成最终的完整图片,并上传 QrImgUtils.uploadImg(xhpcTerminal, xhpcTerminal.getSerialNumber(),environment,xhpcImgMapper,chargingStationName,i,letterMap,name); @@ -302,4 +307,74 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService { System.out.println(DateUtil.now() + "==》图片冗余清理执行成功"); } + + @Override + public String importPile(List pileList, Boolean isUpdateSupport, String operName){ + if (pileList == null || pileList.size() == 0) + { + throw new CustomException("导入电桩数据不能为空!"); + } + + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + for (XhpcChargingPile pile : pileList) { + try { + // 所有表格字段数据必须非空且有效 + if("".equals(pile.getChargingStationName()) || "".equals(pile.getName()) + || "".equals(pile.getBrandModel()) || "".equals(pile.getNationalStandard()) + || pile.getPower() == null || pile.getPower()<=0 + || pile.getAuxiliaryPowerSupply() == null || pile.getAuxiliaryPowerSupply()<=0 + || pile.getInputVoltage() ==null || pile.getInputVoltage()<=0 + || pile.getMaxVoltage() ==null || pile.getMaxVoltage()<=0 + || pile.getMinVoltage() == null || pile.getMinVoltage() <= 0 + || pile.getMaxElectricCurrent() == null || pile.getMaxElectricCurrent() <= 0 + || pile.getMinElectriCurrent() == null || pile.getMinElectriCurrent() <=0 + || "".equals(pile.getSerialNumber()) + || "".equals(pile.getTypeName()) || "".equals(pile.getProgramVersion()) + || pile.getGunNumber() == null || pile.getGunNumber() <=0 + || "".equals(pile.getCommunicationProtocolVersion()) || "".equals(pile.getNetworkLinkType()) + || "".equals(pile.getCommunicationOperator()) || "".equals(pile.getSimCard()) + || "".equals(pile.getProductionDate()) || "".equals(pile.getManufactureName()) + || pile.getCurrent() == null || pile.getCurrent() <=0 + || "".equals(pile.getConnectorTypeName()) || "".equals(pile.getEquipmentTypeName())){ + failureNum ++; + failureMsg.append("
电站名称: ").append(pile.getChargingStationName()).append(" ,电桩名称: ").append(pile.getName()).append(" 导入失败; 失败原因: 必填字段为空。"); + continue; + } + + pile.setType(PowerTypeEnum.getCodeByName(pile.getTypeName())); + pile.setConnectorType(ConnectorTypeEnum.getCodeByName(pile.getConnectorTypeName())); + pile.setEquipmentType(EquipmentTypeEnum.getCodeByName(pile.getEquipmentTypeName())); + + XhpcChargingStation station = xhpcChargingStationService.selectXhpcChargingStationByName(pile.getChargingStationName()); + if(station == null){ + failureNum ++; + failureMsg.append("
电站名称: ").append(pile.getChargingStationName()).append(" ,电桩名称: ").append(pile.getName()).append(" 导入失败; 失败原因: 电站不存在。"); + continue; + } + pile.setChargingStationId(station.getChargingStationId()); + AjaxResult result = addXhpcChargingPile(pile); + if(!result.get(AjaxResult.CODE_TAG).equals(HttpStatus.SUCCESS)){ + failureNum ++; + failureMsg.append("
电站名称: ").append(pile.getChargingStationName()).append(" ,电桩名称: ").append(pile.getName()).append(" 导入失败; 失败原因: ").append(result.get(AjaxResult.MSG_TAG)); + } else { + successNum++; + } + } + catch (Exception e) { + failureNum++; + failureMsg.append("
电站名称: ").append(pile.getChargingStationName()).append(" ,电桩名称: ").append(pile.getName()).append(" 导入失败; 失败原因: ").append(e.getMessage()); + } + } + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new CustomException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java index c93ef1ff..2453df16 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java @@ -96,6 +96,19 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi return xhpcChargingStationMapper.selectXhpcChargingStationById(chargingStationId); } + + /** + * 查询电站 + * + * @param chargingStationName 电站名称 + * @return 电站 + */ + @Override + public XhpcChargingStation selectXhpcChargingStationByName(String chargingStationName) { + + return xhpcChargingStationMapper.selectXhpcChargingStationByName(chargingStationName); + } + /** * 查询电站列表 * diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml index d9e2f467..c0824143 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml @@ -96,6 +96,11 @@ where charging_station_id = #{chargingStationId} + + insert into xhpc_charging_station diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingPile.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingPile.java index d9a21842..4caa7ffb 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingPile.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingPile.java @@ -1,5 +1,6 @@ package com.xhpc.common.domain; +import com.xhpc.common.core.annotation.Excel; import com.xhpc.common.core.web.domain.BaseEntity; /** @@ -15,41 +16,66 @@ public class XhpcChargingPile extends BaseEntity { private Long chargingPileId; /** 场站id */ private Long chargingStationId; + + /** 场站名称 */ + @Excel(name = "电站", cellType = Excel.ColumnType.STRING) + private String chargingStationName; /** 名称 */ + @Excel(name = "电桩名称(号桩 )", cellType = Excel.ColumnType.STRING) private String name; /** 品牌型号 */ + @Excel(name = "品牌型号", cellType = Excel.ColumnType.STRING) private String brandModel; /** 国标 */ + @Excel(name = "电桩国际", cellType = Excel.ColumnType.STRING) private String nationalStandard; /** 功率 */ + @Excel(name = "电桩功率(KW)", cellType = Excel.ColumnType.STRING) private Double power; /** 辅助电源支持 */ + @Excel(name = "辅助电源支持(V)", cellType = Excel.ColumnType.STRING) private Double auxiliaryPowerSupply; /** 输入电压 */ + @Excel(name = "输入电压(V)", cellType = Excel.ColumnType.STRING) private Double inputVoltage; /** 最大电压 */ + @Excel(name = "最大电压(V)", cellType = Excel.ColumnType.STRING) private Double maxVoltage; /** 最小电压 */ + @Excel(name = "最小电压(V)", cellType = Excel.ColumnType.STRING) private Double minVoltage; /** 最大电流 */ + @Excel(name = "最大电流(A)", cellType = Excel.ColumnType.STRING) private Double maxElectricCurrent; /** 最小电流 */ + @Excel(name = "最小电流(A)", cellType = Excel.ColumnType.STRING) private Double minElectriCurrent; /** 桩编号 */ + @Excel(name = "桩编码", cellType = Excel.ColumnType.STRING) private String serialNumber; /** 桩类型 */ private Integer type; + + @Excel(name = "电桩类型", type= Excel.Type.IMPORT) + private String typeName; + /** 程序版本 */ + @Excel(name = "程序版本", cellType = Excel.ColumnType.STRING) private String programVersion; /** 网络链接类型 */ + @Excel(name = "网络连接类型", cellType = Excel.ColumnType.STRING) private String networkLinkType; /** 终端数量 */ + @Excel(name = "终端数量", cellType = Excel.ColumnType.STRING) private Integer gunNumber; /** 通讯协议版本 */ + @Excel(name = "通讯协议版本", cellType = Excel.ColumnType.STRING) private String communicationProtocolVersion; /** 通讯运营商 */ + @Excel(name = "通讯运营商", cellType = Excel.ColumnType.STRING) private String communicationOperator; /** Sim卡 */ + @Excel(name = "SIMK", cellType = Excel.ColumnType.STRING) private String simCard; /** 状态(0正常 1停用) */ private Integer status; @@ -60,11 +86,13 @@ public class XhpcChargingPile extends BaseEntity { /** * 设备生产日期(格式YYYY-MM-DD) */ + @Excel(name = "设备生产日期", cellType = Excel.ColumnType.STRING) private String productionDate; /** * 设备生产商名称 */ + @Excel(name = "设备生产商名称", cellType = Excel.ColumnType.STRING) private String manufactureName; /** @@ -72,9 +100,16 @@ public class XhpcChargingPile extends BaseEntity { */ private Integer connectorType; + + /** + * 充电设备接口类型,导入Excel使用 + */ + @Excel(name = "充电设备类型", cellType = Excel.ColumnType.STRING) + private String connectorTypeName; /** * 额定电流(单位A) */ + @Excel(name = "额定电流(A)", cellType = Excel.ColumnType.STRING) private Integer current; /** @@ -82,13 +117,47 @@ public class XhpcChargingPile extends BaseEntity { */ private Integer equipmentType; - public Integer getEquipmentType() { + /** + * 设备类型,导入Excel使用 + */ + @Excel(name = "设备类型", cellType = Excel.ColumnType.STRING, type = Excel.Type.IMPORT) + private String equipmentTypeName; + public String getTypeName() { + + return typeName; + } + + public void setTypeName(String typeName) { + + this.typeName = typeName; + } + + public String getConnectorTypeName() { + + return connectorTypeName; + } + + public void setConnectorTypeName(String connectorTypeName) { + + this.connectorTypeName = connectorTypeName; + } + + public String getEquipmentTypeName() { + + return equipmentTypeName; + } + + public void setEquipmentTypeName(String equipmentTypeName) { + + this.equipmentTypeName = equipmentTypeName; + } + + public Integer getEquipmentType() { return equipmentType; } public void setEquipmentType(Integer equipmentType) { - this.equipmentType = equipmentType; } @@ -362,4 +431,14 @@ public class XhpcChargingPile extends BaseEntity { this.brandModel = brandModel; } + public String getChargingStationName() { + + return chargingStationName; + } + + public void setChargingStationName(String chargingStationName) { + + this.chargingStationName = chargingStationName; + } + } diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/ConnectorTypeEnum.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/ConnectorTypeEnum.java new file mode 100644 index 00000000..91ed6118 --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/ConnectorTypeEnum.java @@ -0,0 +1,67 @@ +package com.xhpc.common.enums; + + +/** + * 充电设备类型 + */ +public enum ConnectorTypeEnum { + + // connectorTypeList: [ +// { dictLabel: "", value: 1 }, +// { dictLabel: "", value: 2 }, +// { dictLabel: "", value: 3 }, +// { dictLabel: "", value: 4 }, +// { dictLabel: "", value: 5 }, +// { dictLabel: "", value: 6 } +// ], + + + HOME_OUTLET(1, "家用插座"), + AC_OUTLET(2, "交流接口插座"), + AC_PLUG(3, "交流接口插头"), + DC_PLUG(4, "直流接口枪头"), + WIRELESS_OUTLET(5, "无线充电座"), + OTHER(6, "其他"), + ; + + private final int code; + private final String name; + + ConnectorTypeEnum(int code, String name){ + this.code = code; + this.name = name; + } + + //根据code获取name + public static String getNameByCode(int code) { + for (ConnectorTypeEnum typeEnum : ConnectorTypeEnum.values()) { + //移除交办 + if (typeEnum.code == code) { + return typeEnum.name; + } + } + return ""; + } + + //根据code获取name + public static Integer getCodeByName(String name) { + for (ConnectorTypeEnum typeEnum : ConnectorTypeEnum.values()) { + //移除交办 + if (typeEnum.name.equals(name)) { + return typeEnum.code; + } + } + return null; + } + + public int getCode() { + + return code; + } + + public String getName() { + + return name; + } + +} diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/EquipmentTypeEnum.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/EquipmentTypeEnum.java new file mode 100644 index 00000000..42500e8b --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/EquipmentTypeEnum.java @@ -0,0 +1,63 @@ +package com.xhpc.common.enums; + + +/** + * 设备类型 + */ +public enum EquipmentTypeEnum { + + // equipmentTypeList: [ +// { dictLabel: "", value: 1 }, +// { dictLabel: "", value: 2 }, +// { dictLabel: "", value: 3 }, +// { dictLabel: "", value: 4 }, +// { dictLabel: "", value: 5 } +// ], + + DC(1, "直流设备"), + AC(2, "交流设备"), + DC_AC(3, "交直流一体设备"), + WIRELESS(4, "无线设备"), + OTHER(5, "其他"), + ; + + private final int code; + private final String name; + + EquipmentTypeEnum(int code, String name){ + this.code = code; + this.name = name; + } + + //根据code获取name + public static String getNameByCode(int code) { + for (EquipmentTypeEnum typeEnum : EquipmentTypeEnum.values()) { + //移除交办 + if (typeEnum.code == code) { + return typeEnum.name; + } + } + return ""; + } + + //根据code获取name + public static Integer getCodeByName(String name) { + for (EquipmentTypeEnum typeEnum : EquipmentTypeEnum.values()) { + //移除交办 + if (typeEnum.name.equals(name)) { + return typeEnum.code; + } + } + return null; + } + + public int getCode() { + + return code; + } + + public String getName() { + + return name; + } +} diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/PowerTypeEnum.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/PowerTypeEnum.java new file mode 100644 index 00000000..09dca821 --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/enums/PowerTypeEnum.java @@ -0,0 +1,51 @@ +package com.xhpc.common.enums; + +/** + * 电桩类型 + */ +public enum PowerTypeEnum { + + DC(1, "直流"), + AC(2, "交流"), + ; + + private final int code; + private final String name; + + PowerTypeEnum(int code, String name){ + this.code = code; + this.name = name; + } + + //根据code获取name + public static String getNameByCode(int code) { + for (PowerTypeEnum typeEnum : PowerTypeEnum.values()) { + //移除交办 + if (typeEnum.code == code) { + return typeEnum.name; + } + } + return ""; + } + + //根据code获取name + public static Integer getCodeByName(String name) { + for (PowerTypeEnum typeEnum : PowerTypeEnum.values()) { + //移除交办 + if (typeEnum.name.equals(name)) { + return typeEnum.code; + } + } + return null; + } + + public int getCode() { + + return code; + } + + public String getName() { + + return name; + } +}