增加全局生成二维码图片接口,使其可以直接生成指定场站下的所有终端的二维码图片

This commit is contained in:
wen 2022-02-17 17:10:23 +08:00
parent 1f41d92b8c
commit 09dc299e67
11 changed files with 397 additions and 25 deletions

View File

@ -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<XhpcChargingPile> util = new ExcelUtil<XhpcChargingPile>(XhpcChargingPile.class);
List<XhpcChargingPile> 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);
}
}

View File

@ -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<XhpcChargingPile> selectXhpcChargingPilesBy(@Param("chargingStationId") Long chargingStationId, @Param("chargingPileId") Long chargingPileId, @Param("tenantId") String tenantId);
}

View File

@ -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;
@ -23,9 +25,27 @@ public interface XhpcImgMapper {
void insert(@Param("imgUrl") String imgUrl, @Param("terminalId") Long terminalId);
/**
*
* @param terminalIds 终端id集合
* @return 返回带有url和对应终端id编号的集合实体类
*/
List<Map<String, Object>> selectImgUrlByTerminal_id(List<Integer> terminalIds);
/**
* query XhpcTerminal by terminal id
*
* @author WH
* @date 2022/2/17 11:28
* @since version-1.0
*/
List<XhpcImg> selectByTerminalId(ArrayList<Long> 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);
}

View File

@ -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<String> 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<XhpcTerminal> selectXhpcTerminalIdByPileIds(ArrayList<Long> pileIds);
}

View File

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

View File

@ -75,6 +75,15 @@ public interface IXhpcChargingPileService {
List<Map<String, Object>> downloadsTerminalImgs(List<Integer> terminalIds);
String importPile(List<XhpcChargingPile> 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);
}

View File

@ -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,8 +62,11 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha
private IXhpcChargingStationService xhpcChargingStationService;
@Autowired
private LogUserUtils logUserUtils;
@Autowired
private TokenService tokenService;
//字母集合
private static Map letterMap;
static {
Character letter = 'A';
letterMap = new HashMap<Integer, Character>();
@ -155,6 +161,16 @@ public class XhpcChargingPileServiceImpl extends BaseService implements IXhpcCha
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<XhpcChargingPile> 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("<br/>电站名称: ").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> xhpcChargingPile = xhpcChargingPileMapper.selectXhpcChargingPilesBy(chargingStationId, pileId, tenantId);
ArrayList<Long> pileIds = new ArrayList<>();
for (XhpcChargingPile chargingPile : xhpcChargingPile) {
Long chargingPileId = chargingPile.getChargingPileId();
pileIds.add(chargingPileId);
}
//get effective terminal
List<XhpcTerminal> xhpcTerminalList = xhpcTerminalMapper.selectXhpcTerminalIdByPileIds(pileIds);
if (xhpcTerminalList.isEmpty()) {
return AjaxResult.success();
}
ArrayList<Long> terminalIds = new ArrayList<>();
for (XhpcTerminal xhpcTerminal : xhpcTerminalList) {
Long terminalId = xhpcTerminal.getTerminalId();
terminalIds.add(terminalId);
}
//delete old qrcode img url data in the database
List<XhpcImg> 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);
}
}

View File

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

View File

@ -493,4 +493,15 @@
from xhpc_charging_pile
where serial_number = #{serialNumber}
</select>
<select id="selectXhpcChargingPilesBy" resultMap="BaseResultMap">
<include refid="selectXhpcChargingPileVo"/>
<where>
charging_station_id = #{chargingStationId}
and tenant_id = #{tenantId}
and del_flag = 0
<if test="chargingPileId!=null">
and charging_pile_id = #{chargingPileId}
</if>
</where>
</select>
</mapper>

View File

@ -2,11 +2,18 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--suppress SqlDialectInspection -->
<mapper namespace="com.xhpc.charging.station.mapper.XhpcImgMapper">
<insert id="insert">
INSERT INTO xhpc_img(url,terminal_id) VALUES(#{imgUrl},#{terminalId})
INSERT INTO xhpc_img(url, terminal_id)
VALUES (#{imgUrl}, #{terminalId})
</insert>
<update id="updateDelFlagByTerminalId">
UPDATE xhpc_img
SET del_flag = 2
WHERE terminal_id = #{terminalId}
</update>
<select id="selectImgUrlByTerminal_id" resultType="map">
SELECT url,terminal_id as terminalId
@ -19,5 +26,34 @@
</foreach>
</if>
</select>
<select id="selectByTerminalId" resultType="com.xhpc.charging.station.pojo.XhpcImg">
terminal_id
charging_pile_id
charging_station_id
name
serial_number
pile_serial_number
gun_status
work_status
status
del_flag
create_time
create_by
update_time
update_by
remark
rate_model_id
operator_id_evcs
number
connector_type
search_value
del_falg
tenant_id
from xhpc_img
where terminal_id in
<foreach collection="list" separator="," item="terminalId" open="(" close=")">
#{terminalId}
</foreach>
</select>
</mapper>

View File

@ -385,6 +385,18 @@
<select id="getTerminal" resultType="String">
select serial_number as serialNumber from xhpc_terminal where charging_station_id=#{chargingStationId} and status=#{status} and del_flag=0
select serial_number as serialNumber
from xhpc_terminal
where charging_station_id = #{chargingStationId}
and status = #{status}
and del_flag = 0
</select>
<select id="selectXhpcTerminalIdByPileIds" resultMap="BaseResultMap">
<include refid="selectXhpcTerminalVo"/>
WHERE
charging_pile_id IN
<foreach collection="list" separator="," item="pileId" close=")" open="(">
#{pileId}
</foreach>
</select>
</mapper>