新增导入电桩功能

This commit is contained in:
panshulin 2021-11-29 11:51:26 +08:00
parent 06ee6465e3
commit bc629d8e18
11 changed files with 397 additions and 3 deletions

View File

@ -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<XhpcChargingPile> util = new ExcelUtil<XhpcChargingPile>(XhpcChargingPile.class);
List<XhpcChargingPile> pileList = util.importExcel(file.getInputStream());
String operName = SecurityUtils.getUsername();
String message = xhpcChargingPileService.importPile(pileList, updateSupport, operName);
return AjaxResult.success(message);
}
}

View File

@ -27,6 +27,15 @@ public interface XhpcChargingStationMapper {
*/
XhpcChargingStation selectXhpcChargingStationById(Long chargingStationId);
/**
* 查询电站
*
* @param chargingStationName 电站名称
* @return 电站
*/
XhpcChargingStation selectXhpcChargingStationByName(String chargingStationName);
/**
* 查询电站列表
*

View File

@ -73,4 +73,7 @@ public interface IXhpcChargingPileService {
*/
List<Map<String,Object>> downloadsTerminalImgs(List<Integer> terminalIds);
String importPile(List<XhpcChargingPile> pileList, Boolean isUpdateSupport, String operName);
}

View File

@ -34,6 +34,16 @@ public interface IXhpcChargingStationService {
*/
XhpcChargingStation selectXhpcChargingStationById(Long chargingStationId);
/**
* 查询电站
*
* @param chargingStationName 电站名称
* @return 电站
*/
XhpcChargingStation selectXhpcChargingStationByName(String chargingStationName);
/**
* 查询电站列表
*

View File

@ -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<XhpcChargingPile> 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("<br/>电站名称: ").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("<br/>电站名称: ").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("<br/>电站名称: ").append(pile.getChargingStationName()).append(" ,电桩名称: ").append(pile.getName()).append(" 导入失败; 失败原因: ").append(result.get(AjaxResult.MSG_TAG));
} else {
successNum++;
}
}
catch (Exception e) {
failureNum++;
failureMsg.append("<br/>电站名称: ").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();
}
}

View File

@ -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);
}
/**
* 查询电站列表
*

View File

@ -96,6 +96,11 @@
where charging_station_id = #{chargingStationId}
</select>
<select id="selectXhpcChargingStationByName" resultMap="BaseResultMap">
<include refid="selectXhpcChargingStationVo"/>
where name = #{chargingStationName}
</select>
<insert id="insertXhpcChargingStation" parameterType="com.xhpc.common.domain.XhpcChargingStation">
insert into xhpc_charging_station
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

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

View File

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

View File

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

View File

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