增加短信通用接口,修改订单

This commit is contained in:
yuyang 2021-08-09 12:15:00 +08:00
parent c1b585936e
commit a94677d5b1
13 changed files with 304 additions and 55 deletions

View File

@ -20,4 +20,15 @@ public interface IXhpcSmsService {
AjaxResult getLogonPhoneCode(String phone);
List<Map<String, Object>> getList(Integer status,String phone);
/**
* 公共调用方法
* @param phone 手机号
* @param content 内容
* @param random 验证码6位
* @return
*/
AjaxResult getPhoneCode(String phone,String content,String random);
}

View File

@ -42,6 +42,19 @@ public class XhpcSmsServiceImpl implements IXhpcSmsService{
@Override
public AjaxResult getLogonPhoneCode(String phone) {
String random = getRandom();
String conten ="【小华充电】您的验证码是:"+random+"有效期为5分钟。如非本人操作可不用理会。";
return getPhoneCode(phone,conten,random);
}
@Override
public List<Map<String, Object>> getList(Integer status, String phone) {
return xhpcSmsMapper.getList(status,phone);
}
@Override
public AjaxResult getPhoneCode(String phone, String content,String random) {
//调用接口
String pattern ="^([1][0-9]{10})";
@ -62,13 +75,11 @@ public class XhpcSmsServiceImpl implements IXhpcSmsService{
if(cacheObject !=null){
return AjaxResult.error("1012","操作过于频繁请于1分钟后重试");
}
String random = getRandom();
String conten ="【小华充电】您的验证码是:"+random+"有效期为5分钟。如非本人操作可不用理会。";
String req = HttpUtils.postFormData(URL, null, assembleSmsReq(phone,conten));
String req = HttpUtils.postFormData(URL, null, assembleSmsReq(phone,content));
JSONObject json = JSONObject.parseObject(req);
xhpcSms.setCode(random);
xhpcSms.setPhone(phone);
xhpcSms.setContent(conten);
xhpcSms.setContent(content);
xhpcSms.setCreateTime(new Date());
xhpcSms.setRemark(req);
String ok = json.getString("ok");
@ -90,14 +101,8 @@ public class XhpcSmsServiceImpl implements IXhpcSmsService{
xhpcSmsMapper.addXhpcSms(xhpcSms);
return AjaxResult.error(1010,"服务器繁忙,请稍后再试");
}
}
@Override
public List<Map<String, Object>> getList(Integer status, String phone) {
return xhpcSmsMapper.getList(status,phone);
}
private static HashMap<String, String> assembleSmsReq(String phone, String content) {
HashMap<String, String> params = new HashMap<>();

View File

@ -78,6 +78,12 @@
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@ -46,11 +46,12 @@ public class HxpcChargeOrderController extends BaseController {
* 启动充电
* @param userId
* @param serialNumber 终端编码
* @param type 1 微信 2支付宝
* @return
*/
@GetMapping("/startUp")
public AjaxResult startUp(@RequestParam Long userId,@RequestParam String serialNumber){
return iHxpcChargeOrderService.startUp(userId, serialNumber);
public AjaxResult startUp(@RequestParam Long userId,@RequestParam String serialNumber,Integer type){
return iHxpcChargeOrderService.startUp(userId, serialNumber,type);
}

View File

@ -1,6 +1,10 @@
package com.xhpc.order.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xhpc.common.core.web.domain.BaseEntity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* 充电订单
@ -37,6 +41,12 @@ public class HxpcChargeOrder extends BaseEntity {
* 充电启始soc
*/
private String startSoc;
/**
* 结束soc
*/
private String endSoc;
/**
* 订单来源0C端用户 1流量用户
*/
@ -54,6 +64,30 @@ public class HxpcChargeOrder extends BaseEntity {
*/
private Long rateModelId;
/**
* 充电方式
*/
private String chargingMode;
/** 开始充电时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date startTime;
/** 结束充电时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endTime;
/** 充电时长 */
private String chargingTime;
/** 充电度数 */
private String chargingDegree;
/** 0桩停止充电 1 远程停止充电 */
private Integer type;
public Long getChargeOrderId() {
return chargeOrderId;
@ -164,4 +198,74 @@ public class HxpcChargeOrder extends BaseEntity {
this.rateModelId = rateModelId;
}
public String getChargingMode() {
return chargingMode;
}
public void setChargingMode(String chargingMode) {
this.chargingMode = chargingMode;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public String getChargingTime() {
return chargingTime;
}
public void setChargingTime(String chargingTime) {
this.chargingTime = chargingTime;
}
public String getChargingDegree() {
return chargingDegree;
}
public void setChargingDegree(String chargingDegree) {
this.chargingDegree = chargingDegree;
}
public String getEndSoc() {
return endSoc;
}
public void setEndSoc(String endSoc) {
this.endSoc = endSoc;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
}

View File

@ -100,10 +100,7 @@ public class XhpcRealTimeOrder extends BaseEntity {
* 场站id
*/
private Long chargingStationId;
/**
* 0桩停止充电 1 远程停止充电 2充电中
*/
private Integer type;
public Long getChargingOrderId() {
@ -317,16 +314,6 @@ public class XhpcRealTimeOrder extends BaseEntity {
this.chargingStationId = chargingStationId;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Long getRealTimeOrderId() {
return realTimeOrderId;

View File

@ -49,6 +49,17 @@ public interface HxpcChargeOrderMapper {
*/
XhpcTerminal getXhpcTerminalSerialNumber(@Param("serialNumber")String serialNumber);
//添加充电订单
/**
* 添加充电订单
* @param hxpcChargeOrder
* @return
*/
int addXhpcTerminalSerial(HxpcChargeOrder hxpcChargeOrder);
/**
* 修改充电订单
* @param hxpcChargeOrder
* @return
*/
int updateXhpcTerminalSerial(HxpcChargeOrder hxpcChargeOrder);
}

View File

@ -28,7 +28,7 @@ public interface IHxpcChargeOrderService {
* @param serialNumber 终端编码
* @return
*/
AjaxResult startUp(Long userId,String serialNumber);
AjaxResult startUp(Long userId,String serialNumber,Integer type);
/**
* 停止充电

View File

@ -1,20 +1,24 @@
package com.xhpc.order.service.impl;
import cn.hutool.core.date.DateUtil;
import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.common.data.redis.SeqUtil;
import com.xhpc.common.domain.XhpcTerminal;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.order.domain.HxpcChargeOrder;
import com.xhpc.order.domain.XhpcHistoryOrder;
import com.xhpc.order.mapper.HxpcChargeOrderMapper;
import com.xhpc.order.service.IHxpcChargeOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -25,10 +29,18 @@ import java.util.regex.Pattern;
@Service
public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
public static RedisService REDIS;
@Autowired
private HxpcChargeOrderMapper hxpcChargeOrderMapper;
@Autowired
private PowerPileService powerPileService;
@Autowired
private RedisService redisService;
@PostConstruct
public void init(){
REDIS =redisService;
}
@Override
public AjaxResult getHistotyChargeOrderMessage(Long userId) {
@ -43,7 +55,7 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
}
@Override
public AjaxResult startUp(Long userId, String serialNumber) {
public AjaxResult startUp(Long userId, String serialNumber,Integer type) {
String pattern = "^([0-9]{16})";
Pattern compile = Pattern.compile(pattern);
Matcher m = compile.matcher(serialNumber);
@ -85,16 +97,22 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
String balance = userMessage.get("balance").toString();
//启动充电
StartChargingData startChargingData = new StartChargingData();
//订单流水号
String orderNo = SeqUtil.seqDec("gun:" + serialNumber + ".seqdec");
//订单流水号 终端号+年月日时分秒+自增4位 共32位
Date date = new Date();
String format = DateUtil.format(date, "yyMMddHHmmss");
//自增
String number = "number:" + serialNumber;
String cacheObject = REDIS.getCacheObject(number);
String gunSerialNumber=serialNumber+format;
gunSerialNumber = getString(number, cacheObject, gunSerialNumber);
String orderNo = SeqUtil.seqDec("gun:" + gunSerialNumber + ".seqdec");
startChargingData.setOrderNo(orderNo);
startChargingData.setPileNo(xhpcTerminal.getPileSerialNumber());
startChargingData.setGunId(xhpcTerminal.getSerialNumber());
startChargingData.setBalance(Double.valueOf(balance).intValue());
startChargingData.setVersion("0A");
R r1 = powerPileService.startCharging(startChargingData);
System.out.println("<<<<<<<"+r1.getCode());
System.out.println("<<<<<<<"+r1.getMsg());
if(r1.getCode() !=200){
return AjaxResult.error(r1.getMsg());
}
@ -104,15 +122,68 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
hxpcChargeOrder.setChargingStationId(xhpcTerminal.getChargingStationId());
hxpcChargeOrder.setUserId(userId);
hxpcChargeOrder.setTerminalId(xhpcTerminal.getTerminalId());
hxpcChargeOrder.setSerialNumber(orderNo);
hxpcChargeOrder.setSerialNumber(gunSerialNumber);
hxpcChargeOrder.setSource(0);
hxpcChargeOrder.setStatus(0);
hxpcChargeOrder.setRateModelId(xhpcTerminal.getRateModelId());
if(type ==1){
hxpcChargeOrder.setChargingMode("小华充电微信");
}else{
hxpcChargeOrder.setChargingMode("小华充电支付宝");
}
hxpcChargeOrder.setStartTime(date);
hxpcChargeOrderMapper.addXhpcTerminalSerial(hxpcChargeOrder);
return AjaxResult.success();
}
private String getString(String number, String cacheObject, String gunSerialNumber) {
if(cacheObject !=null){
if(cacheObject.length()==4){
if("9999".equals(cacheObject)){
REDIS.setCacheObject(number,1,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +"0001";
}else{
int value = Integer.parseInt(cacheObject)+1;
REDIS.setCacheObject(number,value,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +value;
}
}else if(cacheObject.length()==3){
if("999".equals(cacheObject)){
REDIS.setCacheObject(number,1000,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +"1000";
}else{
int value = Integer.parseInt(cacheObject)+1;
REDIS.setCacheObject(number,value,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +value;
}
}else if(cacheObject.length()==2){
if("99".equals(cacheObject)){
REDIS.setCacheObject(number,100,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +"100";
}else{
int value = Integer.parseInt(cacheObject)+1;
REDIS.setCacheObject(number,value,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +value;
}
}else{
if("9".equals(cacheObject)){
REDIS.setCacheObject(number,10,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +"10";
}else{
int value = Integer.parseInt(cacheObject)+1;
REDIS.setCacheObject(number,value,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +value;
}
}
}else{
REDIS.setCacheObject(number,1,24L, TimeUnit.HOURS);
gunSerialNumber = gunSerialNumber +"0001";
}
return gunSerialNumber;
}
@Override
public AjaxResult stopUp(Long userId, String serialNumber,Long chargingOrderId) {

View File

@ -23,6 +23,17 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
@Override
public void addXhpcRealTimeOrder(String orderNo, Integer status) {
//记录电流电压soc实时记录
//当状态为status =1 订单结束
//用户是否第一单,享受折扣
//获取运营商 平台抽成运维抽成
//结算订单
//添加历史订单
}
}

View File

@ -12,6 +12,7 @@
<result column="internet_serial_number" property="internetSerialNumber"/>
<result column="serial_number" property="serialNumber"/>
<result column="start_soc" property="startSoc"/>
<result column="end_soc" property="endSoc"/>
<result column="source" property="source"/>
<result column="status" property="status"/>
<result column="del_flag" property="delFlag"/>
@ -21,6 +22,12 @@
<result column="update_by" property="updateBy"/>
<result column="remark" property="remark"/>
<result column="rate_model_id" property="rateModelId"/>
<result column="charging_mode" property="chargingMode"/>
<result column="start_time" property="startTime"/>
<result column="end_time" property="endTime"/>
<result column="charging_time" property="chargingTime"/>
<result column="charging_degree" property="chargingDegree"/>
<result column="type" property="type"/>
</resultMap>
<resultMap id="BaseResultMap" type="com.xhpc.common.domain.XhpcTerminal">
@ -118,7 +125,22 @@
del_flag,
</if>
<if test="null != rateModelId ">
rate_model_id
rate_model_id,
</if>
<if test="null != chargingMode ">
charging_mode,
</if>
<if test="null != startTime ">
start_time,
</if>
<if test="null != endTime ">
end_time,
</if>
<if test="null != chargingTime ">
charging_time,
</if>
<if test="null != chargingDegree ">
charging_degree
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@ -150,12 +172,38 @@
#{delFlag},
</if>
<if test="null != rateModelId ">
#{rateModelId}
#{rateModelId},
</if>
<if test="null != chargingMode ">
#{chargingMode},
</if>
<if test="null != startTime ">
#{startTime},
</if>
<if test="null != endTime ">
#{endTime},
</if>
<if test="null != chargingTime ">
#{chargingTime},
</if>
<if test="null != chargingDegree ">
#{chargingDegree}
</if>
</trim>
</insert>
<update id="updateXhpcTerminalSerial" parameterType="com.xhpc.order.domain.HxpcChargeOrder">
update xhpc_charge_order
<trim prefix="SET" suffixOverrides=",">
<if test="chargingStationId != null">end_soc = #{chargingStationId},</if>
<if test="status != null">status = #{status},</if>
<if test="endTime != null">end_time = #{endTime},</if>
<if test="chargingTime != null">charging_time = #{chargingTime},</if>
<if test="chargingDegree != null">charging_degree = #{chargingDegree},</if>
<if test="type != null">type = #{type},</if>
</trim>
where charge_order_id = #{chargingStationId}
</update>
<select id="getHistotyChargeOrderStatusList" resultType="map">

View File

@ -304,11 +304,12 @@
cs.name as chargingStationName,
te.name as terminalName,
ho.act_price as actPrice,
(select charging_degree from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time desc LIMIT 1) as chargingDegree,
(select charging_time from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time desc LIMIT 1) as chargingTime
co.charging_degree as chargingDegree,
co.charging_time as chargingTime
FROM xhpc_history_order as ho
LEFT JOIN xhpc_charging_station as cs on cs.charging_station_id = ho.charging_station_id
LEFT JOIN xhpc_terminal as te on te.terminal_id = ho.terminal_id
left join xhpc_charge_order as co on co.charging_order_id =ho.charging_order_id
where ho.status=0 and ho.del_flag=0 and ho.user_id =#{userId}
</select>
@ -321,17 +322,17 @@
te.name as terminalName,
ho.act_price as actPrice,
ho.act_power_price as actPowerPrice,
(select charging_time from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY
create_time desc LIMIT 1) as chargingTime,
(select charging_degree from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time desc LIMIT 1) as chargingDegree,
(select DATE_FORMAT(create_time,'%m月%d日') from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time asc LIMIT 1) as daysOne,
(select DATE_FORMAT(create_time,'%H:%m') from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time asc LIMIT 1) as timeOne,
(select DATE_FORMAT(create_time,'%m月%d日') from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time desc LIMIT 1) as daysTwo,
(select DATE_FORMAT(create_time,'%H:%m') from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time desc LIMIT 1) as timeTwo,
(select type from xhpc_real_time_order where charging_order_id=ho.charging_order_id ORDER BY create_time desc LIMIT 1) as type
co.charging_time as chargingTime,
co.charging_degree as chargingDegree,
DATE_FORMAT(co.start_time,'%m月%d日') as daysOne,
DATE_FORMAT(co.start_time,'%H:%m') as timeOne,
DATE_FORMAT(co.end_time,'%m月%d日') as daysTwo,
DATE_FORMAT(co.end_time,'%H:%m') as timeTwo,
co.type as type
FROM xhpc_history_order as ho
LEFT JOIN xhpc_charging_station as cs on cs.charging_station_id = ho.charging_station_id
LEFT JOIN xhpc_terminal as te on te.terminal_id = ho.terminal_id
left join xhpc_charge_order as co on co.charging_order_id =ho.charging_order_id
where ho.status=0 and ho.del_flag=0 and ho.history_order_id =#{historyOrderId}
<if test="userId !=null">
and ho.user_id =#{userId}

View File

@ -31,7 +31,6 @@
<result column="update_by" property="updateBy"/>
<result column="remark" property="remark"/>
<result column="user_id" property="userId"/>
<result column="type" property="type"/>
<result column="charging_station_id" property="chargingStationId"/>
</resultMap>
@ -114,9 +113,6 @@
<if test="null != userId ">
user_id,
</if>
<if test="null != type ">
type,
</if>
<if test="null != chargingStationId ">
charging_station_id
</if>
@ -197,9 +193,6 @@
<if test="null != userId ">
#{userId},
</if>
<if test="null != type ">
#{type},
</if>
<if test="null != chargingStationId ">
#{chargingStationId}
</if>