新增异常订单回调接口、运营商登陆接口
This commit is contained in:
parent
d265735c52
commit
36a67ce178
@ -1,86 +1,91 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-auth</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-auth认证授权中心
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Security-->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.yml</include>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-auth</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-auth认证授权中心
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Security-->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>xhpc-common</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.yml</include>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@ -2,18 +2,28 @@ package com.xhpc.auth.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xhpc.auth.form.LoginBody;
|
||||
import com.xhpc.auth.service.SysLoginService;
|
||||
import com.xhpc.common.api.SmsService;
|
||||
import com.xhpc.common.core.constant.HttpStatus;
|
||||
import com.xhpc.common.core.utils.HttpUtils;
|
||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||
import com.xhpc.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.xhpc.common.core.domain.R;
|
||||
import com.xhpc.common.core.utils.StringUtils;
|
||||
import com.xhpc.common.security.service.TokenService;
|
||||
import com.xhpc.system.api.model.LoginUser;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* token 控制
|
||||
*
|
||||
@ -28,15 +38,94 @@ public class TokenController
|
||||
@Autowired
|
||||
private SysLoginService sysLoginService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
public static final String URL = "http://sms.daiyicloud.com/sms/apiSend/add";
|
||||
public static final String ACCOUNT ="scxhkj";
|
||||
public static final String PASSWD ="6A9628548C4CBECCE80A2479CD77679F";
|
||||
public static final String PRODUCTLD ="20191130000001";
|
||||
|
||||
/**
|
||||
* 平台管理员登陆
|
||||
* @param form
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("login")
|
||||
public R<?> login(@RequestBody LoginBody form)
|
||||
{
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(),0);
|
||||
// 获取登录token
|
||||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 运营商登陆
|
||||
* @param form
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("operatorLogin")
|
||||
public R<?> operatorLogin(@RequestBody LoginBody form)
|
||||
{
|
||||
//验证 输入的验证码
|
||||
String captcha = redisService.getCacheObject("pcToken:" + form.getUsername());
|
||||
if (!form.getPassword().equalsIgnoreCase(captcha)) {
|
||||
R.fail(HttpStatus.ERROR_STATUS, "验证码错误");
|
||||
}
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), "123456",1);
|
||||
// 获取登录token
|
||||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("sms")
|
||||
public R<?> sms(@RequestParam String phone)
|
||||
{
|
||||
//验证 输入的验证码
|
||||
//调用接口
|
||||
String pattern = "^([1][0-9]{10})";
|
||||
Pattern compile = Pattern.compile(pattern);
|
||||
Matcher m = compile.matcher(phone);
|
||||
boolean isMatch = m.matches();
|
||||
if (!isMatch) {
|
||||
return R.fail("1003", "请输入正确的手机号");
|
||||
}
|
||||
String random = getRandom();
|
||||
String content ="【小华充电】您的验证码是:"+random+",有效期为5分钟。如非本人操作,可不用理会。";
|
||||
//添加短信记录
|
||||
try {
|
||||
//用户使用的Key
|
||||
String pvToken = "pcToken:"+phone;
|
||||
//用户频繁调用的判断的Key
|
||||
String token = "pCToken:"+phone;
|
||||
String cacheObject = redisService.getCacheObject(token);
|
||||
if(cacheObject !=null){
|
||||
return R.fail("1012","操作过于频繁,请于1分钟后重试");
|
||||
}
|
||||
String req = HttpUtils.postFormData(URL, null, assembleSmsReq(phone,content));
|
||||
JSONObject json = JSONObject.parseObject(req);
|
||||
|
||||
String ok = json.getString("ok");
|
||||
if("true".equals(ok)){
|
||||
redisService.setCacheObject(pvToken,random,300L, TimeUnit.SECONDS);
|
||||
//1分钟有效时间设置,防止用户频繁调用
|
||||
redisService.setCacheObject(token,random,60L, TimeUnit.SECONDS);
|
||||
return R.ok();
|
||||
}else{
|
||||
|
||||
return R.fail(1012,"服务器繁忙,请稍后再试");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
return R.fail(1010,"服务器繁忙,请稍后再试");
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("logout")
|
||||
public R<?> logout(HttpServletRequest request)
|
||||
{
|
||||
@ -64,4 +153,23 @@ public class TokenController
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
private static HashMap<String, String> assembleSmsReq(String phone, String content) {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("account", ACCOUNT);
|
||||
params.put("password", PASSWD);
|
||||
params.put("content", content);
|
||||
params.put("mobiles", phone);
|
||||
params.put("productId", PRODUCTLD);
|
||||
return params;
|
||||
}
|
||||
|
||||
private String getRandom(){
|
||||
Random rnd = new Random();
|
||||
int i = rnd.nextInt(999999);
|
||||
if(i<100000){
|
||||
i=i+100000;
|
||||
}
|
||||
return i+"";
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ public class SysLoginService
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public LoginUser login(String username, String password)
|
||||
public LoginUser login(String username, String password,Integer type)
|
||||
{
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password))
|
||||
@ -84,6 +84,20 @@ public class SysLoginService
|
||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
|
||||
throw new BaseException("用户不存在/密码错误");
|
||||
}
|
||||
|
||||
if(type==0){
|
||||
if(user.getDataPowerType()!=0){
|
||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "登陆地址错误");
|
||||
throw new BaseException("登陆地址错误,请在管理员界面登陆");
|
||||
}
|
||||
}else{
|
||||
if(user.getDataPowerType()!=1||user.getDataPowerType()!=2 ){
|
||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "登陆地址错误");
|
||||
throw new BaseException("登陆地址错误,请在管理员界面登陆");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
@ -54,4 +54,15 @@ public interface PileOrderService {
|
||||
*/
|
||||
@GetMapping("/chargeOrder/pileRimeOrder")
|
||||
R pileRimeOrder(@RequestParam(value = "orderNo") String orderNo);
|
||||
|
||||
|
||||
/**
|
||||
* 订单异常回调接口
|
||||
* @param orderNo 订单号
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/chargeOrder/abnormalOrder")
|
||||
R abnormalOrder(@RequestParam(value = "orderNo") String orderNo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -44,6 +44,12 @@ public class PileOrderFallbackFactory implements FallbackFactory<PileOrderServic
|
||||
|
||||
return R.fail("桩实时订单回调接口失败:" + cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R abnormalOrder(String orderNo) {
|
||||
|
||||
return R.fail("订单异常回调接口失败:" + cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -361,6 +361,82 @@ public class XhpcPileOrderController extends BaseController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单异常回调接口
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("/chargeOrder/abnormalOrder")
|
||||
public R abnormalOrder(@RequestParam(value = "orderNo") String orderNo) {
|
||||
|
||||
logger.info("订单异常回调接口>>>>>orderNo:" + orderNo);
|
||||
//获取实时订单
|
||||
CacheRealtimeData cacheRealtimeData = redisService.getCacheObject("order:" + orderNo + ".lord");
|
||||
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo);
|
||||
Long userId = xhpcChargeOrder.getUserId();
|
||||
try {
|
||||
long l = xhpcChargeOrder.getStartTime().getTime() + Long.parseLong(String.valueOf(cacheRealtimeData.getChargingTime()));
|
||||
//毫秒
|
||||
Date date = new Date(l);
|
||||
xhpcChargeOrder.setEndTime(date);
|
||||
xhpcChargeOrder.setUpdateTime(date);
|
||||
xhpcChargeOrder.setStatus(2);
|
||||
xhpcChargeOrder.setEndSoc(cacheRealtimeData.getSoc()+"");
|
||||
//充电时长
|
||||
Long tiem = Long.valueOf(cacheRealtimeData.getChargingTime() / 1000);
|
||||
if (tiem > 3600) {
|
||||
long hours = tiem / 3600;
|
||||
double mins = (double) ((tiem - (hours * 3600)) / 60);
|
||||
xhpcChargeOrder.setChargingTime(hours + "时" + new BigDecimal(mins).setScale(0) + "分");
|
||||
} else {
|
||||
double mins = (double) (tiem / 60);
|
||||
xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "分");
|
||||
}
|
||||
BigDecimal decimal = new BigDecimal(10000);
|
||||
xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal));
|
||||
xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal));
|
||||
xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime()));
|
||||
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
|
||||
|
||||
//结算
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", 500);
|
||||
map.put("userId", xhpcChargeOrder.getUserId());
|
||||
JSONObject json = new JSONObject(map);
|
||||
//消息对了内容
|
||||
webSocketService.getMessage(userId+"",json.toString());
|
||||
return R.fail(500,"无实时数据");
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", 500);
|
||||
map.put("userId", xhpcChargeOrder.getUserId());
|
||||
JSONObject json = new JSONObject(map);
|
||||
//消息对了内容
|
||||
webSocketService.getMessage(userId+"",json.toString());
|
||||
logger.info("桩实时数据发送WebSocket成功>>>>>orderNo:" + orderNo);
|
||||
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param status 状态
|
||||
* @param remark 备注
|
||||
@ -392,6 +468,13 @@ public class XhpcPileOrderController extends BaseController {
|
||||
return userId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// private void rabbimt(String message) {
|
||||
// //发送消息队列
|
||||
// try {
|
||||
|
||||
@ -47,6 +47,7 @@ public class XhpcOperatorController extends BaseController {
|
||||
SysUser sysUser = new SysUser();
|
||||
BigDecimal t3 =new BigDecimal(100);
|
||||
BigDecimal t4 =new BigDecimal(0);
|
||||
BigDecimal t5 =new BigDecimal(80);
|
||||
if(xhpcOperator.getPlatformCommissionRate() !=null && xhpcOperator.getMaintenanceCommissionRate() !=null){
|
||||
BigDecimal t1 =new BigDecimal(xhpcOperator.getPlatformCommissionRate());
|
||||
BigDecimal t2 =new BigDecimal(xhpcOperator.getMaintenanceCommissionRate());
|
||||
@ -68,8 +69,8 @@ public class XhpcOperatorController extends BaseController {
|
||||
if (t3.compareTo(t2) < 0) {
|
||||
return AjaxResult.error("充电终止的soc不能大于100");
|
||||
}
|
||||
if (t2.compareTo(t4) < 0) {
|
||||
return AjaxResult.error("充电终止的soc不能小于0");
|
||||
if (t2.compareTo(t5) < 0) {
|
||||
return AjaxResult.error("充电终止的soc不能小于80");
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,12 +179,12 @@ public class XhpcOperatorController extends BaseController {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
BigDecimal t1 =new BigDecimal(-1);
|
||||
BigDecimal t1 =new BigDecimal("79");
|
||||
BigDecimal t2 =new BigDecimal(13);
|
||||
BigDecimal t3 =new BigDecimal(100);
|
||||
BigDecimal t4 =new BigDecimal(0);
|
||||
|
||||
if (t1.compareTo(t4) < 0) {
|
||||
BigDecimal t5 =new BigDecimal(80);
|
||||
if (t1.compareTo(t5) < 0) {
|
||||
System.out.println("333");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user