优化生成二维码,生成桩代码

This commit is contained in:
yuyang 2021-09-15 15:56:59 +08:00
parent 0a3d6802bc
commit 53c1af51d2
17 changed files with 176 additions and 80 deletions

View File

@ -1,13 +1,10 @@
package com.xhpc.charging.station.controller;
import com.xhpc.charging.station.pojo.XhpcImg;
import com.xhpc.charging.station.service.IXhpcChargingPileService;
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.charging.station.service.IXhpcChargingPileService;
import com.xhpc.common.domain.XhpcChargingPile;
import com.xhpc.common.domain.XhpcTerminal;
import org.apache.poi.hssf.record.DVALRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -33,7 +30,6 @@ public class XhpcChargingPileController extends BaseController {
* @param name 桩名称
* @return
*/
//@PreAuthorize(hasPermi = "system:station:list")
@GetMapping("/list")
public TableDataInfo list(String name, Integer type, String serialNumber, Long chargingStationId) {

View File

@ -88,4 +88,11 @@ public interface XhpcChargingPileMapper {
*/
int updateXhpcTerminal(@Param("chargingPileId") Long chargingPileId);
/**
* 统计改场站的终端
* @param chargingStationId
* @return
*/
int countXhpcTerminal(@Param("chargingStationId") Long chargingStationId);
}

View File

@ -1,6 +1,5 @@
package com.xhpc.charging.station.mapper;
import com.xhpc.charging.station.pojo.XhpcImg;
import org.apache.ibatis.annotations.Param;
import java.util.List;

View File

@ -1,9 +1,7 @@
package com.xhpc.charging.station.service;
import com.xhpc.charging.station.pojo.XhpcImg;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.domain.XhpcChargingPile;
import com.xhpc.common.domain.XhpcTerminal;
import java.util.List;
import java.util.Map;

View File

@ -1,6 +1,5 @@
package com.xhpc.charging.station.service;
import com.alibaba.druid.sql.visitor.functions.Char;
import com.xhpc.charging.station.mapper.XhpcChargingPileMapper;
import com.xhpc.charging.station.mapper.XhpcChargingStationMapper;
import com.xhpc.charging.station.mapper.XhpcImgMapper;
@ -32,14 +31,12 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
@Autowired
private PowerPileService powerPileService;
//上传图片全局变量
@Autowired
private Environment environment;
//上传图片Mapper
@Autowired
private XhpcImgMapper xhpcImgMapper;
@Autowired
XhpcChargingStationMapper xhpcChargingStationMapper;
private XhpcChargingStationMapper xhpcChargingStationMapper;
//字母集合
private static Map letterMap;
@ -75,7 +72,9 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
if(xhpcChargingPile.getGunNumber() ==null || xhpcChargingPile.getGunNumber()>26){
return AjaxResult.error("终端数量不能大于26");
}
if(xhpcChargingPile.getSerialNumber() ==null || xhpcChargingPile.getSerialNumber().length()!=14){
return AjaxResult.error("桩编号14");
}
Long chargingStationId = xhpcChargingPile.getChargingStationId();
//获取计费模型id
Map<String, Object> stringObjectMap = xhpcChargingPileMapper.selectXhpcChargingStationById(chargingStationId);
@ -93,35 +92,45 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
Long chargingPileId = xhpcChargingPile.getChargingPileId();
if (xhpcChargingPile.getGunNumber() > 0) {
int number = xhpcChargingPileMapper.countXhpcTerminal(chargingStationId);
for (int i = 1; i <= xhpcChargingPile.getGunNumber(); i++) {
XhpcTerminal xhpcTerminal = new XhpcTerminal();
xhpcTerminal.setChargingStationId(chargingStationId);
xhpcTerminal.setChargingPileId(chargingPileId);
xhpcTerminal.setName(xhpcChargingPile.getName() + "-" + (i));
xhpcTerminal.setSerialNumber(serialNumber + "0" + i);
xhpcTerminal.setPileSerialNumber(serialNumber);
xhpcTerminal.setWorkStatus(2);
xhpcTerminal.setStatus(0);
xhpcTerminal.setRateModelId(rateModelId);
xhpcTerminal.setNumber(99);
xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal);
//获取场站名称
String chargingStationName = xhpcChargingStationMapper.selectXhpcChargingStationById(xhpcTerminal.getChargingStationId()).getName();
//生成最终的完整图片并上传
QrImgUtils.uploadImg(xhpcTerminal, xhpcTerminal.getSerialNumber(),environment,xhpcImgMapper,chargingStationName,i,letterMap);
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i,number+1);
}
}
//插入redis 桩的编号
// HashSet<String> noSet = new HashSet<>();
// noSet.add(serialNumber);
// powerPileService.addPileWhitelist(chargingStationId, noSet);
HashSet<String> noSet = new HashSet<>();
noSet.add(serialNumber);
powerPileService.addPileWhitelist(chargingStationId, noSet);
return AjaxResult.success();
}
private void addXhpcTerminal(String name, Long chargingStationId, Long rateModelId, String serialNumber, Long chargingPileId, int i, int number) {
XhpcTerminal xhpcTerminal = new XhpcTerminal();
xhpcTerminal.setChargingStationId(chargingStationId);
xhpcTerminal.setChargingPileId(chargingPileId);
xhpcTerminal.setName(name + "-" + (i));
if(i>9){
xhpcTerminal.setSerialNumber(serialNumber + i);
}else{
xhpcTerminal.setSerialNumber(serialNumber + "0" + i);
}
xhpcTerminal.setPileSerialNumber(serialNumber);
xhpcTerminal.setWorkStatus(2);
xhpcTerminal.setStatus(0);
xhpcTerminal.setRateModelId(rateModelId);
xhpcTerminal.setNumber(number);
xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal);
//获取场站名称
String chargingStationName = xhpcChargingStationMapper.selectXhpcChargingStationById(xhpcTerminal.getChargingStationId()).getName();
//生成最终的完整图片并上传
QrImgUtils.uploadImg(xhpcTerminal, xhpcTerminal.getSerialNumber(),environment,xhpcImgMapper,chargingStationName,i,letterMap);
}
@Override
@Transactional
public AjaxResult updateXhpcChargingPile(XhpcChargingPile xhpcChargingPile) {
Long chargingPileId = xhpcChargingPile.getChargingPileId();
@ -139,33 +148,19 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
if (!xhpcChargingPile.getGunNumber().equals(xhpc.getGunNumber())) {
//删除之前的终端
xhpcChargingPileMapper.updateXhpcTerminal(chargingPileId);
int number = xhpcChargingPileMapper.countXhpcTerminal(xhpcChargingPile.getChargingStationId());
String serialNumber = xhpcChargingPile.getSerialNumber();
Long rateModelId = xhpcChargingPile.getRateModelId();
Long chargingStationId = xhpcChargingPile.getChargingStationId();
if (xhpcChargingPile.getGunNumber() > 0) {
for (int i = 1; i <= xhpcChargingPile.getGunNumber(); i++) {
XhpcTerminal xhpcTerminal = new XhpcTerminal();
xhpcTerminal.setChargingStationId(chargingStationId);
xhpcTerminal.setChargingPileId(chargingPileId);
xhpcTerminal.setName(serialNumber + "-" + (i));
String num = serialNumber + "0" + i;
xhpcTerminal.setSerialNumber(num);
xhpcTerminal.setPileSerialNumber(serialNumber);
xhpcTerminal.setWorkStatus(2);
xhpcTerminal.setStatus(0);
xhpcTerminal.setRateModelId(rateModelId);
xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal);
// //生成二维码图片并上传
// QrImgUtils.uploadImg(xhpcTerminal,num,environment,xhpcImgMapper);
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i,number+1);
}
}
//插入redis 桩的编号
// HashSet<String> noSet = new HashSet<>();
// noSet.add(serialNumber);
// powerPileService.addPileWhitelist(chargingStationId, noSet);
HashSet<String> noSet = new HashSet<>();
noSet.add(serialNumber);
powerPileService.addPileWhitelist(chargingStationId, noSet);
}
xhpcChargingPileMapper.updaeXhpcChargingPile(xhpcChargingPile);
return AjaxResult.success();
@ -185,8 +180,8 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
@Override
@Transactional
public AjaxResult updateStatus(Long chargingPileId, Integer status) {
XhpcChargingPile xhpc = xhpcChargingPileMapper.selectXhpcChargingPileById(chargingPileId);
xhpc.setStatus(status);
xhpcChargingPileMapper.updaeXhpcChargingPile(xhpc);
@ -194,6 +189,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
}
@Override
@Transactional
public int updateXhpcChargingPileById(Long chargingPileId) {
XhpcChargingPile xhpc = xhpcChargingPileMapper.selectXhpcChargingPileById(chargingPileId);

View File

@ -712,6 +712,7 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
}
@Override
@Transactional
public AjaxResult updateXhpcRateTime(XhpcChargingStationDto xhpcChargingStationDto) {
//电站id不能为空
if (xhpcChargingStationDto.getChargingStationId() == null) {

View File

@ -354,4 +354,7 @@
where charging_pile_id = #{chargingPileId}
</update>
<select id="countXhpcTerminal" resultType="int">
select count(id) from xhpc_charging_pile where charging_station_id = #{chargingStationId}
</select>
</mapper>

View File

@ -8,7 +8,7 @@
INSERT INTO xhpc_img(url,terminal_id) VALUES(#{imgUrl},#{terminalId})
</insert>
<select id="selectImgUrlByTerminal_id" parameterType="int" resultType="map">
<select id="selectImgUrlByTerminal_id" resultType="map">
SELECT url,terminal_id as terminalId
FROM xhpc_img
where 1=1

View File

@ -177,7 +177,10 @@
remark,
</if>
<if test="null != rateModelId">
rate_model_id
rate_model_id,
</if>
<if test="null != number">
number
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@ -224,7 +227,10 @@
#{remark},
</if>
<if test="null != rateModelId">
#{rateModelId}
#{rateModelId},
</if>
<if test="null != number">
#{number}
</if>
</trim>
</insert>

View File

@ -1,12 +1,5 @@
package com.xhpc.test;
import cn.hutool.core.date.DateUtil;
import com.aliyun.oss.OSSClient;
import com.xhpc.charging.station.utils.QRCodeUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import java.io.File;
import java.util.Date;

View File

@ -380,4 +380,45 @@ public class CacheOrderData extends BaseData {
this.status = status;
}
@Override
public String toString() {
return "CacheOrderData{" +
"orderNo='" + orderNo + '\'' +
", pileNo='" + pileNo + '\'' +
", gunId='" + gunId + '\'' +
", startTime='" + startTime + '\'' +
", endTime='" + endTime + '\'' +
", t1Price=" + t1Price +
", t1PowerQuantity=" + t1PowerQuantity +
", t1LossQuantity=" + t1LossQuantity +
", t1Cost=" + t1Cost +
", t2Price=" + t2Price +
", t2PowerQuantity=" + t2PowerQuantity +
", t2LossQuantity=" + t2LossQuantity +
", t2Cost=" + t2Cost +
", t3Price=" + t3Price +
", t3PowerQuantity=" + t3PowerQuantity +
", t3LossQuantity=" + t3LossQuantity +
", t3Cost=" + t3Cost +
", t4Price=" + t4Price +
", t4PowerQuantity=" + t4PowerQuantity +
", t4LossQuantity=" + t4LossQuantity +
", t4Cost=" + t4Cost +
", electricMeterStart=" + electricMeterStart +
", electricMeterEnd=" + electricMeterEnd +
", totalPowerQuantity=" + totalPowerQuantity +
", totalLossPowerQuantity=" + totalLossPowerQuantity +
", cost=" + cost +
", vinNormal='" + vinNormal + '\'' +
", transactionFlag='" + transactionFlag + '\'' +
", transactionDatetime='" + transactionDatetime + '\'' +
", stopReason='" + stopReason + '\'' +
", cardNo='" + cardNo + '\'' +
", startSoc=" + startSoc +
", endSoc=" + endSoc +
", status=" + status +
'}';
}
}

View File

@ -21,6 +21,17 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>

View File

@ -6,6 +6,7 @@ import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.order.api.XhpcChargeOrderController;
import com.xhpc.order.service.IXhpcStopChargingOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -29,7 +30,6 @@ public class XhpcStopChargingOrderController extends BaseController {
@GetMapping("/list")
public TableDataInfo list(Long userId, Long chargingStationId, Long terminalId){
startPage();
return getDataTable(iXhpcStopChargingOrderService.list(userId, chargingStationId, terminalId));
}
@ -37,10 +37,11 @@ public class XhpcStopChargingOrderController extends BaseController {
/**
* 停止充电
* @param userId
* @param serialNumber 终端编码
* @param terminalSerialNumber 终端编码
* @param chargingOrderId 充电id
* @return
*/
@Scheduled(cron = "0 59 23 * * ?")
@GetMapping("/stopUp")
public AjaxResult stopUp(@RequestParam Long userId, @RequestParam String terminalSerialNumber, @RequestParam Long chargingOrderId){

View File

@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.xhpc.common.api.SmsService;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.order.domain.*;
@ -473,7 +474,8 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
xhpcOrderRedisRecord.setLt5alerted(cacheMap.get("lt5alerted").toString());
}
if(cacheMap.get("orderData") !=null){
xhpcOrderRedisRecord.setOrderData(cacheMap.get("orderData").toString());
CacheOrderData cacheOrderData = (CacheOrderData)cacheMap.get("orderData");
xhpcOrderRedisRecord.setOrderData(cacheOrderData.toString());
}
xhpcOrderRedisRecord.setCreateTime(date);
xhpcChargeOrderService.addXhpcOrderRedisRecord(xhpcOrderRedisRecord);

View File

@ -23,6 +23,6 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
#logging:
# level:
# com.xhpc.order.mapper: debug
logging:
level:
com.xhpc.order.mapper: debug

View File

@ -0,0 +1,41 @@
package com.xhpc.order.service;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
/**
* @author yuyang
* @date 2021/9/14 16:42
* @Version 1.0
*/
@SpringBootTest
public class ServiceTest {
@Autowired
private IXhpcChargeOrderService xhpcChargeOrderService;
@Before
public void setUp() throws Exception {
System.out.println("+++++++++++++++++初始化+++++++++++++");
}
@Test
public void test(){
Map<String, Object> orderMessage = xhpcChargeOrderService.getPromotion();
System.out.println("orderMessage :"+orderMessage.toString());
System.out.println("111111111111111111111111");
}
@After
public void tearDown() throws Exception {
System.out.println("释放资源,执行当前测试类的每个测试方法后执行");
}
}

View File

@ -14,7 +14,8 @@ import org.springframework.boot.test.context.SpringBootTest;
public class NormalTest {
@Autowired
XhpcMessageMapper xhpcMessageMapper;
private XhpcMessageMapper xhpcMessageMapper;
@Test
public void test02(){
@ -24,15 +25,15 @@ public class NormalTest {
@Test
public void test03(){
XhpcMessage xhpcMessage = new XhpcMessage();
xhpcMessage.setContent("hello world");
int result = xhpcMessageMapper.insertItemsBy(xhpcMessage);
if(result != 0){
System.out.println("insert successfully!!");
}else {
System.out.println("insert failed!!");
}
System.out.println("latch successfully!!");
// XhpcMessage xhpcMessage = new XhpcMessage();
// xhpcMessage.setContent("hello world");
// int result = xhpcMessageMapper.insertItemsBy(xhpcMessage);
// if(result != 0){
// System.out.println("insert successfully!!");
// }else {
// System.out.println("insert failed!!");
// }
// System.out.println("latch successfully!!");
}
}