1.低电量不得骑行判断

2.低电量自动生成换电工单,逻辑移到心跳逻辑中
This commit is contained in:
邱贞招 2024-05-28 17:33:11 +08:00
parent eba790b3e0
commit 1abf528d60
5 changed files with 75 additions and 68 deletions

View File

@ -148,6 +148,10 @@ public class AppVerifyController extends BaseController
if(!asUserService.checkIsDeposit(order.getUserId())){
return error("您还未充值押金,请先充值押金");
}
//低电量不得骑行判断
if(asDeviceService.isLowBattery(order.getSn())){
return error("低电量不得骑行");
}
OrderResponse orderResponse =asDeviceService.snSwitch(order);
return success(orderResponse);
}

View File

@ -4,16 +4,17 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.IotConstants;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.onenet.Token;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.AsDevice;
import com.ruoyi.system.domain.EtAdminOrder;
import com.ruoyi.system.domain.EtModel;
import com.ruoyi.system.domain.EtOperatingArea;
import com.ruoyi.system.mapper.AsDeviceMapper;
import com.ruoyi.system.service.IAsDeviceService;
import com.ruoyi.system.service.IEtModelService;
import com.ruoyi.system.service.IEtOperatingAreaService;
import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.iot.domain.BodyObj;
import com.ruoyi.web.controller.iot.domain.LogEntry;
import com.ruoyi.web.controller.iot.util.Util;
@ -52,6 +53,13 @@ public class ReceiveController {
@Resource
private IEtOperatingAreaService etOperatingAreaService;
@Autowired
private IEtAdminOrderService etAdminOrderService;
@Autowired
private ISysUserService sysUserService;
/**
* 功能描述第三方平台数据接收<p>
* <ul>:
@ -105,7 +113,9 @@ public class ReceiveController {
// 根据电压计算续航里程
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
Integer remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance());
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString());
int i = asDeviceService.updateAsDeviceBySn(device);
if(i>0){
log.info("更新定位成功:" +logEntry.getDevName());
@ -138,13 +148,46 @@ public class ReceiveController {
/** todo 4.行程线路添加更新订单中的trip_route字段 */
/** 5.低电量不能骑行,如果电量低则声音播报 */
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());
if(electricQuantity <=model.getLowBatteryReminder()){
/** 5.低于电量(%)不得骑行,声音播报 */
if(electricQuantity <= model.getLowBatteryReminder()){
//发送低电量播报指令
asDeviceService.sendCommand(device.getMac(), Token.getToken(),IotConstants.COMMAND_PLAY6,"低电量播报");
log.info("低电量播报:" +logEntry.getDevName());
}
/** 6.低电量 生成换电工单*/
Integer replacementOrder = area.getAutoReplacementOrder();
Boolean aBoolean = etAdminOrderService.checkOrderUnique(device.getSn());
if (Integer.parseInt(device.getRemainingPower()) < replacementOrder && !aBoolean) {
/** 生成换电工单 */
EtAdminOrder adminOrder = new EtAdminOrder();
adminOrder.setDeviceMac(device.getMac());
adminOrder.setSn(device.getSn());
adminOrder.setBeforeElectric(Integer.parseInt(device.getRemainingPower()));
adminOrder.setOrderNo(IdUtils.randomUUID2());
adminOrder.setStatus(ServiceConstants.REPLACEMENT_ELECTRICITY_STATUS_UNDER_WAY);
adminOrder.setIsEffective(ServiceConstants.REPLACEMENT_ELECTRICITY_IS_EFFECTIVE_YES);
SysUser sysUser = sysUserService.selectUserByUserName("wx");//获取用户名为wx的维修人员
adminOrder.setAdminId(sysUser.getUserId());
adminOrder.setAdminName(sysUser.getUserName());
adminOrder.setLatitude(device.getLatitude());
adminOrder.setLongitude(device.getLongitude());
adminOrder.setType("2");
String location = device.getLongitude() + ","+device.getLatitude();
adminOrder.setAddress(CommonUtil.getAddressByGeo(location));
int i1 = etAdminOrderService.insertEtAdminOrder(adminOrder);
if (i1 > 0) {
log.info("生成换电工单成功");
}else{
throw new ServiceException("生成换电工单失败");
}
/** 改变车辆状态 */
device.setStatus(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE);
if (asDeviceService.updateAsDevice(device) > 0) {
log.info("车辆状态改成换电中");
}else{
throw new ServiceException("车辆状态更新失败");
}
}
}else{
log.info("更新定位失败:" +logEntry.getDevName());
}

View File

@ -25,7 +25,6 @@ public class SendAliSmsUtil {
// 产品域名,开发者无需替换
static final String domain = "dysmsapi.aliyuncs.com";
// TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
private static final String accessKeyId = "LTAI5tR5PUDLcBxZskXhYaar";//需要替换
private static final String accessKeySecret = "qCziuzsKPwCY6SD0cTr1Gau5dOjHnb";//需要替换

View File

@ -204,4 +204,9 @@ public interface IAsDeviceService extends IService<AsDevice>
* 判断是否在禁行区内
*/
public boolean isNoRidingArea(String sn,Long areaId);
/**
* 低电量不得骑行判断
*/
boolean isLowBattery(String sn);
}

View File

@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.constant.IotConstants;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.DateUtils;
@ -79,9 +78,6 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
@Autowired
private IEtParkingAreaService parkingAreaService;
@Autowired
private ISysUserService userService;
@Resource
private ISysDictDataService sysDictDataService;
@ -138,16 +134,6 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
if (ObjectUtil.isNull(asDevice)) {
throw new ServiceException("设备不存在");
}
/** TODO 获取车辆实时信息 电量、定位、状态*/
// if (ObjectUtil.isNotNull(asDevice)) {
// /** 获取车辆实时信息 */
// String url = iotUrl + "/v1.0/devices/" + asDevice.getMac() + "/datapoints?product_id=" + productId + "&timeout=" + timeout;
// String result = HttpUtils.sendGet(url, Token.getToken());
// JSONObject jsonObject = JSON.parseObject(result);
// if (jsonObject.getInteger("code") == 200) {
// JSONObject data =jsonObject.getJSONObject("data");
// }
// }
Long areaId = asDevice.getAreaId();
EtOperatingArea etOperatingArea;
if (ObjectUtil.isNotNull(areaId)) {
@ -155,51 +141,6 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}else{
throw new ServiceException("区域信息不存在");
}
/** TODO 电量低于系统设置值时,自动生成换电工单 唯一 */
Integer replacementOrder = etOperatingArea.getAutoReplacementOrder();
Boolean aBoolean = etAdminOrderService.checkOrderUnique(asDevice.getSn());
if (Integer.parseInt(asDevice.getRemainingPower()) < replacementOrder && !aBoolean) {
Boolean execute = transactionTemplate.execute(e -> {
/** 生成换电工单 */
EtAdminOrder adminOrder = new EtAdminOrder();
adminOrder.setDeviceMac(asDevice.getMac());
adminOrder.setSn(asDevice.getSn());
adminOrder.setBeforeElectric(Integer.parseInt(asDevice.getRemainingPower()));
adminOrder.setOrderNo(IdUtils.randomUUID2());
adminOrder.setStatus(ServiceConstants.REPLACEMENT_ELECTRICITY_STATUS_UNDER_WAY);
adminOrder.setIsEffective(ServiceConstants.REPLACEMENT_ELECTRICITY_IS_EFFECTIVE_YES);
SysUser sysUser = userService.selectUserByUserName("wx");//获取用户名为wx的维修人员
adminOrder.setAdminId(sysUser.getUserId());
adminOrder.setAdminName(sysUser.getUserName());
adminOrder.setLatitude(asDevice.getLatitude());
adminOrder.setLongitude(asDevice.getLongitude());
adminOrder.setType("2");
String location = asDevice.getLongitude() + ","+asDevice.getLatitude();
adminOrder.setAddress(CommonUtil.getAddressByGeo(location));
int i = etAdminOrderService.insertEtAdminOrder(adminOrder);
if (i > 0) {
log.info("生成换电工单成功");
}else{
return Boolean.FALSE;
}
/** 改变车辆状态 */
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE);
int i1 = asDeviceMapper.updateAsDevice(asDevice);
if (i1 > 0) {
log.info("车辆状态改成换电中");
}else{
return Boolean.FALSE;
}
return Boolean.TRUE;
});
if (!execute)throw new ServiceException("生成换电工单失败");
}
String vehicleMileage = sysConfigService.selectConfigByKey("vehicle.mileage");//车辆里程数
Integer mileage = Integer.parseInt(vehicleMileage);
Integer remainingPower = Integer.parseInt(asDevice.getRemainingPower());
// mileage与remainingPower相乘
asDevice.setRemainingMileage(mileage * remainingPower/100);//剩余里程
if(ObjectUtil.isNotNull(etOperatingArea)){
asDevice.setAreaName(etOperatingArea.getAreaName());
}
@ -458,7 +399,6 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
String sessionId = IdUtils.randomUUIDByDigit(8);
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(orderVo.getSn());
/** TODO 远程开锁*/
/** 1.获取token*/
String token = Token.getToken();
String finalOrderNo = orderNo;
@ -1301,4 +1241,20 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
}
return isNoRiding;
}
/**
* 是否低电量
*/
@Override
public boolean isLowBattery(String sn) {
AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
String remainingPower = device.getRemainingPower();
log.info("车辆【{}】电量为【{}】",sn,remainingPower);
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(device.getAreaId());
if(Integer.parseInt(remainingPower) < Integer.parseInt(area.getUndercharge())){
log.info("车辆【{}】电量为【{}】低于【{}】",sn,remainingPower,area.getUndercharge());
return true;
}
return false;
}
}