共享钥匙

This commit is contained in:
邱贞招 2024-12-26 20:54:10 +08:00
parent c3ce7302a7
commit 7ddf6ebd1e
18 changed files with 346 additions and 24 deletions

View File

@ -54,6 +54,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import static com.ruoyi.common.constant.ServiceConstants.USER_TYPE_INDIVIDUAL;
@ -741,6 +742,15 @@ public class AppVerifyController extends BaseController
return toAjax(shareKeyService.insertEShareKey(eShareKey));
}
/**
* 获取共享钥匙详细信息
*/
@GetMapping(value = "/key/{keyId}")
public AjaxResult getKeyInfo(@PathVariable("keyId") Long keyId)
{
return success(shareKeyService.selectEShareKeyByKeyId(keyId));
}
private boolean assign(EShareKey eShareKey) {
EUserVO eUserVO = userService.selectUserByUserName(eShareKey.getSharePhone());
if(eUserVO == null){
@ -829,9 +839,22 @@ public class AppVerifyController extends BaseController
deviceQuery.setUserId(getUserId());
deviceQuery.setKeywords(keywords);
List<EDeviceVO> list = deviceService.selectEDeviceListWithIsolate(deviceQuery);
// 拼接分享的车辆
if(list.isEmpty()){
list = new ArrayList<>();
}
assembleShareDevice(list,userVO);
return success(list);
}
private void assembleShareDevice(List<EDeviceVO> list,EUserVO userVO) {
List<String> sns = shareKeyService.selectEShareSnListByShareUserId(userVO.getUserId());
if(!sns.isEmpty()){
List<EDeviceVO> devices = deviceService.selectBySns(sns);
list.addAll(devices);
}
}
/**
* 管理员提现
*/

View File

@ -168,16 +168,16 @@ public class EDeviceController extends BaseController
// return toAjax(eDeviceService.oneClickWarehousing(deviceIds));
// }
//
// /**
// * 更新设备
// */
// @PreAuthorize("@ss.hasPermi('system:device:refresh')")
// @Log(title = "更新设备", businessType = BusinessType.REFRESH)
// @PostMapping("/refreshDevice/{deviceIds}")
// public AjaxResult refreshDevice(@PathVariable Long[] deviceIds)
// {
// return toAjax(eDeviceService.refreshDevice(deviceIds));
// }
/**
* 更新设备
*/
@PreAuthorize("@ss.hasPermi('system:device:refresh')")
@Log(title = "更新设备", businessType = BusinessType.REFRESH)
@PostMapping("/refreshDevice/{deviceIds}")
public AjaxResult refreshDevice(@PathVariable Long[] deviceIds)
{
return toAjax(eDeviceService.refreshDevice(deviceIds));
}
/**
* 响铃寻车

View File

@ -0,0 +1,21 @@
package com.ruoyi.common.utils.onenet;
import lombok.Data;
@Data
public class LocationVo {
private String lon;//经度
private String lat;//纬度
private Integer status;//电动车状态 0断电1上电运行 2轮动抱死 3超出区域断电远程下发了qlose 解析参数
private Integer bat;//电池电压 "bat":571 ==> 57.1V
private Integer csq;//信号强度
private Integer s;//卫星数量
private Integer q;//质量
}

View File

@ -61,9 +61,12 @@ public class EShareKey extends BaseEntity
/** 有效时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "有效时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date expirationTime;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 删除标志0代表存在 2代表删除 */
private String delFlag;

View File

@ -193,4 +193,9 @@ public interface EDeviceMapper extends BaseMapper<EDevice>
* 根据店铺id查询所有车辆数
*/
Integer selectAllDeviceCountByStoreId(Long storeId);
/**
* 根据sn数组查询车辆数
*/
List<EDeviceVO> selectBySns(@Param("sns") List<String> sns);
}

View File

@ -85,4 +85,14 @@ public interface EShareKeyMapper
* @return 共享钥匙集合
*/
List<EShareKey> selectEShareKeyListByShareUserId(Long shareUserId);
/**
* 根据分享用户id查询未过期车辆sn
*/
List<String> selectEShareSnListByShareUserId(Long shareUserId);
/**
* 查询已过期但改变状态的共享钥匙列表
*/
List<EShareKey> selectExpiredShareKeyList();
}

View File

@ -67,4 +67,12 @@ public interface EUserWithdrawMapper
* @return 用户提现渠道集合
*/
List<EUserWithdraw> selectRlUserWithdrawListByUserId(Long userId);
/**
* 根据userId删除用户提现渠道信息
*
* @param userId 用户id
* @return 结果
*/
int deleteRlUserWithdrawByUserId(Long userId);
}

View File

@ -166,6 +166,11 @@ public interface IEDeviceService extends IService<EDevice>
* @return 结果
*/
int refreshDevice(Long[] deviceIds);
/**
* 更新最新的位置信息
*/
boolean updateLatestLocation(String sn);
//
// /**
// * 删除设备信息
@ -417,4 +422,9 @@ public interface IEDeviceService extends IService<EDevice>
* 根据店铺id查询所有车辆数
*/
Integer selectAllDeviceCountByStoreId(Long storeId);
/**
* 根据sn数组查询车辆数
*/
List<EDeviceVO> selectBySns(List<String> sns);
}

View File

@ -35,6 +35,14 @@ public interface IEShareKeyService
*/
public List<EShareKey> selectEShareKeyListByOwnerId(Long ownerId);
/**
* 根据归属用户id查询未过期车辆sn
*
* @param ownerId 归属用户id
* @return 共享钥匙集合
*/
public List<String> selectEShareSnListByShareUserId(Long ownerId);
/**
* 根据归属用户id查询共享钥匙列表(已失效)
*
@ -82,4 +90,9 @@ public interface IEShareKeyService
* @return 结果
*/
public int deleteEShareKeyByKeyId(Long keyId);
/**
* 查询已过期但改变状态的共享钥匙列表
*/
public List<EShareKey> selectExpiredShareKeyList();
}

View File

@ -67,4 +67,12 @@ public interface IEUserWithdrawService
* @return 结果
*/
public int deleteRlUserWithdrawByUserChannelId(Long userChannelId);
/**
* 根据userId删除用户提现渠道信息
*
* @param userId 用户id
* @return 结果
*/
public int deleteRlUserWithdrawByUserId(Long userId);
}

View File

@ -25,6 +25,7 @@ import com.ruoyi.system.domain.device.EDevice;
import com.ruoyi.system.domain.EOnlineLog;
import com.ruoyi.system.domain.device.EDeviceQuery;
import com.ruoyi.system.domain.device.EDeviceVO;
import com.ruoyi.system.domain.model.EModel;
import com.ruoyi.system.domain.model.EModelVO;
import com.ruoyi.e.order.domain.order.EOrder;
import com.ruoyi.e.order.domain.order.EOrderQuery;
@ -44,6 +45,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
@ -489,19 +491,136 @@ public class EDeviceServiceImpl extends ServiceImpl<EDeviceMapper, EDevice> impl
EDevice device = deviceMapper.selectEDeviceByDeviceId(deviceId);
//设备是否在线
if(isOnline(device.getSn())){
log.info("设备【"+device.getSn()+"】在线");
log.info("设备【{}】在线", device.getSn());
}else{
log.info("设备【"+device.getSn()+"】不在线");
log.info("设备【{}】不在线", device.getSn());
}
if(updateVersion(device.getSn())){
log.info("设备【"+device.getSn()+"】更新版本成功");
log.info("设备【{}】更新版本成功", device.getSn());
}else{
log.info("设备【"+device.getSn()+"】更新版本失败");
log.info("设备【{}】更新版本失败", device.getSn());
}
// 最新位置信息
if(updateLatestLocation(device.getSn())){
log.info("设备【{}】更新位置成功", device.getSn());
}else{
log.info("设备【{}】更新位置失败", device.getSn());
}
}
return 1;
}
/**
* 更新最新的位置信息
*/
@Override
@SneakyThrows
public boolean updateLatestLocation(String sn) {
EDevice device = deviceMapper.selectEDeviceBySn(sn);
if(device!=null){
String token = Token.getToken();
DataPointRes datapoints = historyDatapoints(device.getMac(), token);
if(datapoints.getCode() == 0){
Data data = datapoints.getData();
List<Datastream> datastreams = data.getDevices();
for (Datastream datastream: datastreams) {
List<Datapoint> datapointList = datastream.getDatastreams();
if(ObjectUtil.isNotNull(datapointList)){
for (Datapoint datapoint:datapointList) {
if(datapoint.getId().equals(IotConstants.ONENET_LOCATION)){
String string = JSON.toJSONString(datapoint.getValue());
String at = datapoint.getAt();
if(StrUtil.isNotBlank(string)){
LocationVo locationVo = JSONObject.parseObject(string, LocationVo.class);
log.info("【手动更新】: locationVo---【{}】" , JSON.toJSONString(locationVo));
double[] doubles = CommonUtil.coordinateConvert(locationVo.getLon(), locationVo.getLat());
BigDecimal lat = BigDecimal.valueOf(doubles[0]).setScale(8, RoundingMode.HALF_UP);
BigDecimal lon = BigDecimal.valueOf(doubles[1]).setScale(8, RoundingMode.HALF_UP);
log.info("转换后的GCJ02经纬度{}---{}", lon, lat);
if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){
/** 计算电量和里程后更新设备*/
int i = updateDevice(at,locationVo, device, lon, lat);
if(i > 0){
log.info("【手动更新】===>更新设备成功");
return true;
}else{
log.info("【手动更新】===>更新设备失败");
return false;
}
}else{
noLocationUpdateDevice(at,locationVo,device);
}
}
}
}
}
}
}
}
return false;
}
/** 无定位更新设备 */
private void noLocationUpdateDevice(String at,LocationVo locationVo, EDevice device) {
BigDecimal bat = new BigDecimal(locationVo.getBat());
if(bat.compareTo(new BigDecimal(100)) > 0){
bat = bat.divide(new BigDecimal(10));
}
log.info("保存电压:{}", bat);
device.setVoltage(bat.toString());//电压
EModel model = modelService.selectEModelByModelId(device.getModelId());
// 根据电压计算续航里程
if(ObjectUtil.isNotNull(model)){
Integer remainingMileage = 0;
if(StrUtil.isNotBlank(device.getVoltage())){
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());
}
device.setLastTime(DateUtils.parseDate(at));
device.setGps("0");
device.setSignalStrength(locationVo.getCsq());
device.setSatellites(0);
device.setQuality(locationVo.getQ());
int i = updateLocation(device);
if(i>0){
log.info("未获取到定位===============保存电压等数值成功===========>{}", device.getSn());
}
}
/** 计算电量和里程后更新设备*/
public int updateDevice(String at,LocationVo locationVo, EDevice device, BigDecimal lon, BigDecimal lat) {
device.setLatitude(lat.toString());
device.setLongitude(lon.toString());
BigDecimal bat = new BigDecimal(locationVo.getBat());
if(bat.compareTo(new BigDecimal(100)) > 0){
bat = bat.divide(new BigDecimal(10));
}
log.info("保存电压:{}", bat);
device.setVoltage(bat.toString());//电压
// 根据电压计算续航里程
EModel model = modelService.selectEModelByModelId(device.getModelId());
if(ObjectUtil.isNotNull(model)){
Integer remainingMileage = 0;
if(StrUtil.isNotBlank(device.getVoltage())){
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());
}
device.setLastTime(DateUtils.parseDate(at));
device.setLastLocationTime(DateUtils.parseDate(at));
device.setGps("1");
// 信号强度
device.setSignalStrength(locationVo.getCsq());
device.setSatellites(locationVo.getS());
device.setQuality(locationVo.getQ());
return updateLocation(device);
}
// /**
// * 删除设备信息
// *
@ -1365,6 +1484,14 @@ public class EDeviceServiceImpl extends ServiceImpl<EDeviceMapper, EDevice> impl
public Integer selectAllDeviceCountByStoreId(Long storeId) {
return deviceMapper.selectAllDeviceCountByStoreId(storeId);
}
/**
* 根据sn数组查询车辆数
*/
@Override
public List<EDeviceVO> selectBySns(List<String> sns) {
return deviceMapper.selectBySns(sns);
}
// /**
// * 判断是否在运营时间内
// */

View File

@ -62,6 +62,17 @@ public class EShareKeyServiceImpl implements IEShareKeyService
return eShareKeyMapper.selectEShareKeyListByOwnerId(ownerId);
}
/**
* 根据归属用户id查询未过期车辆sn
*
* @param shareUserId 分享用户id
* @return 共享钥匙集合
*/
@Override
public List<String> selectEShareSnListByShareUserId(Long shareUserId){
return eShareKeyMapper.selectEShareSnListByShareUserId(shareUserId);
}
/**
* 根据归属用户id查询共享钥匙列表
*
@ -135,4 +146,12 @@ public class EShareKeyServiceImpl implements IEShareKeyService
{
return eShareKeyMapper.deleteEShareKeyByKeyId(keyId);
}
/**
* 查询已过期但改变状态的共享钥匙列表
*/
@Override
public List<EShareKey> selectExpiredShareKeyList() {
return eShareKeyMapper.selectExpiredShareKeyList();
}
}

View File

@ -387,6 +387,7 @@ public class EUserServiceImpl implements IEUserService{
public int updateUser(EUser user)
{
if (!ObjectUtil.isNull(user.getUserType()) && user.getUserType().equals(ServiceConstants.USER_TYPE_MERCHANT)) {
userWithdrawalChannel(user.getUserId());
}
// 删除用户与角色关联
@ -400,6 +401,11 @@ public class EUserServiceImpl implements IEUserService{
private void userWithdrawalChannel(Long userId) {
List<ChannelWithdrawVO> channelWithdrawVOS = channelWithdrawService.selectAllChannelWithdrawList();
int i1 = userWithdrawService.deleteRlUserWithdrawByUserId(userId);
createUserWithdrawal(userId, channelWithdrawVOS);
}
private void createUserWithdrawal(Long userId, List<ChannelWithdrawVO> channelWithdrawVOS) {
for (ChannelWithdrawVO channelWithdrawVO : channelWithdrawVOS) {
EUserWithdraw rlUserWithdraw = new EUserWithdraw();
rlUserWithdraw.setHandlingChargeType(channelWithdrawVO.getHandlingChargeType());
@ -413,9 +419,7 @@ public class EUserServiceImpl implements IEUserService{
rlUserWithdraw.setPicture(channelWithdrawVO.getPicture());
rlUserWithdraw.setIsNeedCode(channelWithdrawVO.getIsNeedCode());
int i = userWithdrawService.insertRlUserWithdraw(rlUserWithdraw);
if(i>0){
log.info("【微信登录/wxlogin】用户【{}】创建用户提现渠道【{}】", userId, JSON.toJSON(rlUserWithdraw));
}
ServiceUtil.assertion(i==0,"创建用户提现渠道失败userId:"+ userId);
}
}

View File

@ -104,4 +104,15 @@ public class EUserWithdrawServiceImpl implements IEUserWithdrawService
{
return rlUserWithdrawMapper.deleteRlUserWithdrawByUserChannelId(userChannelId);
}
/**
* 根据userId删除用户提现渠道信息
*
* @param userId 用户id
* @return 结果
*/
@Override
public int deleteRlUserWithdrawByUserId(Long userId) {
return rlUserWithdrawMapper.deleteRlUserWithdrawByUserId(userId);
}
}

View File

@ -8,7 +8,9 @@ import com.ruoyi.e.order.domain.order.EOrder;
import com.ruoyi.e.order.domain.order.EOrderQuery;
import com.ruoyi.e.order.domain.order.EOrderVO;
import com.ruoyi.e.order.service.IEOrderService;
import com.ruoyi.system.domain.EShareKey;
import com.ruoyi.system.service.IEOrderOperService;
import com.ruoyi.system.service.IEShareKeyService;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -39,6 +41,9 @@ public class RlTask {
@Autowired
private ISysConfigService configService;
@Autowired
private IEShareKeyService shareKeyService;
/**
@ -124,4 +129,19 @@ public class RlTask {
log.info("-------------------【定时任务】超时标记---结束----------------");
}
/**
* 分享key过期状态处理
*/
public void expiredKeyHandler(){
log.info("-------------------【定时任务】分享key过期状态处理---开始----------------");
List<EShareKey> eShareKeys = shareKeyService.selectExpiredShareKeyList();
for (EShareKey eShareKey:eShareKeys) {
EShareKey updateKey = new EShareKey();
updateKey.setKeyId(eShareKey.getKeyId());
updateKey.setStatus(ServiceConstants.KEY_STATUS_EXPIRED);
int i = shareKeyService.updateEShareKey(updateKey);
}
log.info("-------------------【定时任务】分享key过期状态处理---结束----------------");
}
}

View File

@ -430,4 +430,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by create_time desc
limit 1
</select>
<select id="selectBySns" resultMap="EDeviceResult">
<include refid="selectEDeviceVo"/>
where sn in
<foreach collection="sns" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</select>
</mapper>

View File

@ -16,15 +16,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="sn" column="sn" />
<result property="status" column="status" />
<result property="expirationTime" column="expiration_time" />
<result property="createTime" column="create_time" />
</resultMap>
<sql id="selectEShareKeyVo">
select k.key_id, k.key_name, k.share_id,k.share_phone, k.share_user_name, k.owner_id, k.owner_name, k.owner_phone, k.sn, k.status, k.expiration_time from e_share_key k
select k.key_id, k.key_name, k.share_id,k.share_phone, k.share_user_name, k.owner_id, k.owner_name, k.owner_phone, k.sn, k.status, k.expiration_time, k.create_time from e_share_key k
</sql>
<select id="selectEShareKeyList" parameterType="EShareKey" resultMap="EShareKeyResult">
select k.key_id, k.key_name, k.share_id, k.share_phone, k.share_user_name, k.owner_id, k.owner_name, k.owner_phone,
k.sn, k.status, k.expiration_time from e_share_key k
k.sn, k.status, k.expiration_time, k.create_time from e_share_key k
left join e_user u on u.user_id = k.share_id
left join e_user m on m.user_id = k.owner_id
where 1=1 and k.del_flag = '0'
@ -42,22 +43,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectEShareKeyByKeyId" parameterType="Long" resultMap="EShareKeyResult">
<include refid="selectEShareKeyVo"/>
where key_id = #{keyId}
where key_id = #{keyId} and k.del_flag = '0'
</select>
<select id="selectEShareKeyListByOwnerId" parameterType="Long" resultMap="EShareKeyResult">
<include refid="selectEShareKeyVo"/>
where k.owner_id = #{ownerId} and k.status != '3'
where k.owner_id = #{ownerId} and k.status != '3' and k.del_flag = '0'
</select>
<select id="selectExpiredEShareKeyListByOwnerId" parameterType="Long" resultMap="EShareKeyResult">
<include refid="selectEShareKeyVo"/>
where k.owner_id = #{ownerId} and k.status = '3'
where k.owner_id = #{ownerId} and k.status = '3' and k.del_flag = '0'
</select>
<select id="selectEShareKeyListByShareUserId" parameterType="Long" resultMap="EShareKeyResult">
<include refid="selectEShareKeyVo"/>
where k.share_id = #{shareUserId}
where k.share_id = #{shareUserId} and k.del_flag = '0'
</select>
<select id="selectEShareSnListByShareUserId" parameterType="Long" resultType="java.lang.String">
SELECT
k.sn
FROM
e_share_key k
WHERE
k.share_id = #{shareUserId}
AND k.del_flag = '0'
AND k.status = '2'
GROUP BY
k.sn
</select>
<select id="selectExpiredShareKeyList" resultMap="EShareKeyResult">
SELECT
k.key_id
FROM
e_share_key k
WHERE
k.del_flag = '0'
AND k.STATUS != '3'
AND k.expiration_time &lt; CURDATE()
</select>
<insert id="insertEShareKey" parameterType="EShareKey" useGeneratedKeys="true" keyProperty="keyId">
@ -73,6 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sn != null">sn,</if>
<if test="status != null">status,</if>
<if test="expirationTime != null">expiration_time,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="keyName != null">#{keyName},</if>
@ -85,6 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sn != null">#{sn},</if>
<if test="status != null">#{status},</if>
<if test="expirationTime != null">#{expirationTime},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
@ -102,6 +129,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null">status = #{status},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="expirationTime != null">expiration_time = #{expirationTime},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where key_id = #{keyId}
</update>

View File

@ -99,4 +99,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{userChannelId}
</foreach>
</delete>
<delete id="deleteRlUserWithdrawByUserId">
delete from e_user_withdraw where user_id = #{userId}
</delete>
</mapper>