Compare commits

...

12 Commits

Author SHA1 Message Date
李东佳 3b35565404 feat():删除远程调用方法 2024-10-06 14:17:59 +08:00
李东佳 846a03f75c fix(): 修改报文数据解析获取报文数据模版方法 2024-10-06 09:55:24 +08:00
李东佳 542a656dc6 fix(): 修改报文数据解析获取报文数据模版方法 2024-10-04 22:09:59 +08:00
李东佳 a834f9d1bd fix(): 修改报文数据的缓存方法 2024-10-04 20:46:16 +08:00
李东佳 960d68f72e fix(): 修改报文数据的缓存方法 2024-10-04 20:38:00 +08:00
李东佳 2c5387f048 feat(): 添加车辆类型缓存方法 2024-10-04 20:05:55 +08:00
sy200 f57deada17 Merge branch 'dev.server' into dev 2024-10-04 16:49:03 +08:00
sy200 ef0311d362 feat:()添加列表Redis方法 2024-10-04 16:43:47 +08:00
ywt 5bb0737c82 10.4新建分支 2024-10-04 09:33:54 +08:00
sy200 d1440fb706 feat:()优化代码 2024-10-04 09:13:30 +08:00
sy200 3ed255fe1e feat:()添加报文模版缓存 2024-10-02 14:33:01 +08:00
sy200 1d91e51199 feat:()添加报文模版缓存 2024-10-02 09:40:38 +08:00
51 changed files with 736 additions and 298 deletions

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# Spring
spring:
application:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# Spring
spring:

View File

@ -0,0 +1,23 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
/**
*
*/
public class AllFaultCacheService extends CacheAbsBacis {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "Allfault:info:";
}
@Override
public String decode(String key) {
return key.replace("Allfault:info:", "");
}
}

View File

@ -0,0 +1,26 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.Fence;
import com.muyu.domain.req.FenceReq;
/**
*
*/
public class AllFenceCahceService extends CacheAbsBacis<String, FenceReq> {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "Allfence:info:";
}
@Override
public String decode(String key) {
return key.replace("Allfence:info:", "");
}
}

View File

@ -0,0 +1,28 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.resp.MessageValueListResp;
import java.util.List;
/**
*
*/
public class AllMessageValueCacheService extends CacheAbsBacis<String, List<MessageValueListResp>> {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "allmessagevalue:info:";
}
@Override
public String decode(String key) {
return key.replace("allmessagevalue:info:", "");
}
}

View File

@ -0,0 +1,36 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.Vehicle;
import com.muyu.domain.req.VehicleAddReq;
import com.muyu.domain.req.VehicleManageReq;
import com.muyu.domain.resp.VehicleManageResp;
import java.util.List;
/**
*
*/
public class AllVehicleCacheService extends CacheAbsBacis<String, VehicleManageResp> {
@Override
public void clear() {
}
/**
* key
* @return
*/
@Override
public String keyPre() {
return "allvehicle:info:";
}
@Override
public String decode(String key) {
return key.replace("allvehicle:info:", "");
}
}

View File

@ -0,0 +1,24 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.VehicleType;
/**
*
*/
public class AllVehicleTypeCacheService extends CacheAbsBacis<String, VehicleType> {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "vehicleType:info:";
}
@Override
public String decode(String key) {
return key.replace("vehicleType:info:", "");
}
}

View File

@ -2,6 +2,9 @@ package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.Fence;
import com.muyu.domain.resp.FenceResp;
import java.util.List;
/**
*
@ -21,4 +24,5 @@ public class FenceCahceService extends CacheAbsBacis<String, Fence> {
public String decode(String key) {
return key.replace("fence:info:", "");
}
}

View File

@ -0,0 +1,26 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.MessageTemplate;
/**
*
*/
public class MessageTemplateCacheService extends CacheAbsBacis<String, MessageTemplate> {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "messageTemplate:info:";
}
@Override
public String decode(String key) {
return key.replace("messageTemplate:info:", "");
}
}

View File

@ -0,0 +1,26 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.MessageValue;
/**
*
*/
public class MessageValueCacheService extends CacheAbsBacis<String, MessageValue> {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "messagevalue:info:";
}
@Override
public String decode(String key) {
return key.replace("messagevalue:info:", "");
}
}

View File

@ -4,7 +4,7 @@ import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.Vehicle;
/**
*
*
*/
public class VehicleCacheService extends CacheAbsBacis<String, Vehicle> {

View File

@ -0,0 +1,24 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.VehicleType;
/**
*
*/
public class VehicleTypeCacheService extends CacheAbsBacis<String, VehicleType> {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "vehicleType:info:";
}
@Override
public String decode(String key) {
return key.replace("vehicleType:info:", "");
}
}

View File

@ -14,11 +14,11 @@ public class WarnRuleCacheService extends CacheAbsBacis<String, WarnRule> {
@Override
public String keyPre() {
return "warn:info:";
return "warnRule:info:";
}
@Override
public String decode(String key) {
return key.replace("warn:info:", "");
return key.replace("warnRule:info:", "");
}
}

View File

@ -5,7 +5,7 @@ import com.muyu.domain.WarnRule;
import com.muyu.domain.WarnStrategy;
/**
*
*
*/
public class WarnStrategyCacheService extends CacheAbsBacis<String, WarnStrategy> {
@Override
@ -15,11 +15,11 @@ public class WarnStrategyCacheService extends CacheAbsBacis<String, WarnStrategy
@Override
public String keyPre() {
return "warn:info:";
return "warnStrategy:info:";
}
@Override
public String decode(String key) {
return key.replace("warn:info:", "");
return key.replace("warnStrategy:info:", "");
}
}

View File

@ -1,5 +1,15 @@
com.muyu.enterprise.cache.VehicleCacheService
com.muyu.enterprise.cache.AllFaultCacheService
com.muyu.enterprise.cache.AllFenceCahceService
com.muyu.enterprise.cache.AllMessageValueCacheService
com.muyu.enterprise.cache.AllVehicleCacheService
com.muyu.enterprise.cache.AllVehicleTypeCacheService
com.muyu.enterprise.cache.FaultCacheService
com.muyu.enterprise.cache.FenceCahceService
com.muyu.enterprise.cache.MessageTemplateCacheService
com.muyu.enterprise.cache.MessageValueCacheService
com.muyu.enterprise.cache.VehicleCacheService
com.muyu.enterprise.cache.VehicleTypeCacheService
com.muyu.enterprise.cache.WarnRuleCacheService
com.muyu.enterprise.cache.WarnStrategyCacheService

View File

@ -3,9 +3,6 @@ package com.muyu.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@ -44,7 +41,16 @@ public class VehicleType extends BaseEntity {
*
*/
@Schema(type = "Integer",description = "报文模版外键")
private Integer messageTemplateId;
private Long messageTemplateId;
/**
*
*/
public static VehicleType addBuilder(VehicleType vehicleType) {
return VehicleType.builder().
vehicleTypeId(vehicleType.getVehicleTypeId()).
vehicleTypeName(vehicleType.getVehicleTypeName()).
build();
}
}

View File

@ -0,0 +1,30 @@
package com.muyu.domain.req;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
*
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Tag(name = "绑定围栏组参数")
public class BoundFenceGroupReq {
/**
* Id
*/
private Long vehicleId;
/**
* Ids
*/
private List<Long> fenceGroupIds;
}

View File

@ -28,7 +28,9 @@ import java.security.Security;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
*
*/
@RequestMapping("/elect")
@RestController
@Log4j2
@ -54,7 +56,7 @@ public class ElectController extends BaseController {
public Result<TableDataInfo<FenceResp>> showList(@RequestBody @Validated FenceReq req) {
startPage();
List<FenceResp> list = electService.selectFenceList(req);
fenceCahceService.get(String.valueOf(req));
//将列表存到Redis
return getDataTable(list);
}
@ -155,5 +157,4 @@ public class ElectController extends BaseController {
return Result.success(fences);
}
}

View File

@ -1,8 +1,11 @@
package com.muyu.enterprise.controller;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.domain.MessageTemplate;
import com.muyu.domain.req.MessageTemplateAddReq;
import com.muyu.domain.resp.MessageTemplateListResp;
import com.muyu.enterprise.cache.MessageTemplateCacheService;
import com.muyu.enterprise.service.MessageTemplateService;
import com.muyu.common.core.domain.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -30,6 +33,10 @@ public class MessageTemplateController {
@Autowired
private MessageTemplateService messageTemplateService;
//缓存
@Autowired
private MessageTemplateCacheService templateCacheService;
/**
*
*1
@ -55,8 +62,14 @@ public class MessageTemplateController {
*/
@PostMapping("/")
public Result<String> save(@RequestBody MessageTemplateAddReq messageTemplateAddReq) {
messageTemplateService.save(MessageTemplate.addBuild(messageTemplateAddReq));
return Result.success("添加成功");
boolean save = messageTemplateService.save(MessageTemplate.addBuild(messageTemplateAddReq));
//获取用户信息
LoginUser loginUser = SecurityUtils.getLoginUser();
//获取租户唯一标识
String databaseName = loginUser.getSysUser().getDatabaseName();
//添加到缓存
templateCacheService.put(databaseName+messageTemplateAddReq.getMessageTemplateName(), MessageTemplate.addBuild(messageTemplateAddReq));
return Result.success(save? "新增成功" : "新增失败");
}
/**

View File

@ -2,6 +2,8 @@ package com.muyu.enterprise.controller;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.enterprise.cache.AllVehicleCacheService;
import com.muyu.enterprise.cache.VehicleCacheService;
import com.muyu.enterprise.service.VehicleService;
import com.muyu.common.core.domain.Result;
@ -19,9 +21,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
/**
@ -41,11 +45,10 @@ public class VehicleController extends BaseController {
@Autowired
private VehicleService vehicleService;
//车辆缓存
//添加车辆缓存
@Autowired
private VehicleCacheService vehicleCacheService;
/**
*
*
@ -56,6 +59,11 @@ public class VehicleController extends BaseController {
public Result<TableDataInfo<VehicleManageResp>> getVehicleList(@RequestBody VehicleManageReq vehicleManageReq) {
startPage();
List<VehicleManageResp> list = vehicleService.getVehicleList(vehicleManageReq);
//将车辆信息存到Redis
List<Vehicle> vehicleList = vehicleService.list();
vehicleList.forEach(vehicle -> {
vehicleCacheService.put(vehicle.getVehicleVin(), vehicle);
});
return getDataTable(list);
}
@ -144,9 +152,10 @@ public class VehicleController extends BaseController {
*/
@GetMapping("/addBoundFenceGroup")
@Operation(description = "车辆绑定围栏组")
public Result<String> boundFenceGroup(
@Validated @RequestBody BoundMiddle boundMiddle){
return null;
public Result boundFenceGroup(
@Validated @RequestBody BoundFenceGroupReq boundFenceGroupReq){
vehicleService.boundFenceGroup(boundFenceGroupReq);
return Result.success("绑定成功");
}
/**

View File

@ -1,15 +1,20 @@
package com.muyu.enterprise.controller;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.domain.MessageValue;
import com.muyu.domain.VehicleType;
import com.muyu.domain.req.MessageValueAddReq;
import com.muyu.domain.req.VehicleAddReq;
import com.muyu.enterprise.cache.VehicleCacheService;
import com.muyu.enterprise.cache.VehicleTypeCacheService;
import com.muyu.enterprise.service.VehicleTypeService;
import com.muyu.common.core.domain.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -30,6 +35,9 @@ public class VehicleTypeController {
@Autowired
private VehicleTypeService vehicleTypeService;
@Autowired
private VehicleTypeCacheService vehicleTypeCacheService;
/**
*
* @return
@ -37,6 +45,29 @@ public class VehicleTypeController {
@RequestMapping(path = "/", method = RequestMethod.POST)
@Operation(summary = "车辆类型列表",description = "车辆类型列表")
public Result<List<VehicleType>> findAll(){
return Result.success(vehicleTypeService.list());
List<VehicleType> list = vehicleTypeService.list();
list.forEach(vehicleType -> {
vehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()), vehicleType);
});
return Result.success(list);
}
/**
*
* @param vehicleType
* @return
*/
@PostMapping("/add")
@Operation(summary = "添加报文数据", description = "新增报文数据")
public Result<String> save(@RequestBody VehicleType vehicleType) {
boolean save = vehicleTypeService.save(vehicleType);
// //获取用户信息
// LoginUser loginUser = SecurityUtils.getLoginUser();
// //获取租户唯一标识
// String databaseName = loginUser.getSysUser().getDatabaseName();
//存到redis
// vehicleTypeCacheService.put(databaseName+vehicleType.getVehicleTypeId(),vehicleType);
vehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType);
return Result.success(save? "添加成功" : "添加失败");
}
}

View File

@ -30,11 +30,6 @@ public interface ElectMapper extends MPJBaseMapper<Fence> {
@Select("select * from fence where fence_id=#{fenceId}")
List<Fence> mapShow(@Param("fenceId") Long fenceId);
// /**
// * 根据id查询车辆
// */
// Fence boundFence(@Param("fenceId") Long fenceId);
/**
* ()
*/

View File

@ -28,7 +28,16 @@ public interface FencegroupMapper extends MPJBaseMapper<FenceGroup> {
@Select("SELECT g.fence_group_id,g.group_type,g.priority,g.`status`,f.fence_id, group_CONCAT( f.fence_name ) AS fence_name FROM fence_group g LEFT JOIN middle m ON m.fence_group_id = g.fence_group_id LEFT JOIN fence f ON m.fence_id = f.fence_id GROUP BY g.fence_group_id")
List<FenceGroup> showGroupList(FenceGroupReq req);
@Insert("INSERT INTO `vehicle-basic`.`middle` (`fence_id`, `fence_group_id`) VALUES <foreach collection=\"fenceIds\" item=\"id\" separator=\",\"> (#{id},#{fenceGroupId}) </foreach>")
// @Insert("INSERT INTO `vehicle-basic`.`middle` (`fence_id`, `fence_group_id`) VALUES <foreach collection='fenceIds' item='id' separator=','> (#{id},#{fenceGroupId}) </foreach>")
// @Insert({ "<script>", "INSERT INTO user_role (user_id, role_id) VALUES ", "<foreach collection='roleIds' item='roleId' separator=','>", "(#{userId}, #{roleId})", "</foreach>", "</script>" })
@Insert({
"<script>",
"INSERT INTO `vehicle-basic`.`middle` (fence_id, fence_group_id) VALUES ",
"<foreach collection='fenceIds' item='id' separator=','>",
"(#{id}, #{fenceGroupId})",
"</foreach>",
"</script>"
})
void addMiddle(@Param("fenceIds") Integer[] fenceIds,@Param("fenceGroupId") Long fenceGroupId);
}

View File

@ -2,8 +2,10 @@ package com.muyu.enterprise.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.muyu.domain.Vehicle;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.domain.req.VehicleManageReq;
import com.muyu.domain.resp.VehicleManageResp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@ -28,11 +30,6 @@ public interface VehicleMapper extends MPJBaseMapper<Vehicle> {
*/
List<VehicleManageResp> findAll(VehicleManageReq vehicleManageReq);
/**
*
*/
void bindFenceGroup(@Param("fenceGroupIds") Integer[] fenceGroupIds, @Param("vehicleId") Long vehicleId);
/**
* vinid
* @param vehicleVin
@ -40,4 +37,20 @@ public interface VehicleMapper extends MPJBaseMapper<Vehicle> {
*/
@Select("SELECT t.message_template_id FROM vehicle v LEFT JOIN vehicle_type t ON v.vehicle_type_id = t.vehicle_type_id WHERE v.vehicle_vin = #{vehicleVin}")
Long findByVehicleVin(String vehicleVin);
/**
*
* @param boundFenceGroupReq
*/
// @Insert("INSERT INTO `vehicle-basic`.`bound_middle` (`fence_group_id`,`vehicle_id`) VALUES <foreach collection=\"fenceGroupIds\" item=\"id\" separator=\",\"> (#{id},#{vehicleId}) </foreach>")
@Insert({
"<script>",
"INSERT INTO `vehicle-basic`.`bound_middle` (fence_group_id,vehicle_id) VALUES ",
"<foreach collection='fenceGroupIds' item='id' separator=','>",
"(#{id}, #{vehicleId})",
"</foreach>",
"</script>"
})
void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq);
}

View File

@ -19,7 +19,5 @@ public interface IFencegroupService extends IService<FenceGroup> {
void addGroup(FenceGroupAddReq addReq);
// List<FenceGroup> haveFence(HaveFence haveFence);
//
}

View File

@ -2,8 +2,10 @@ package com.muyu.enterprise.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.domain.Vehicle;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.domain.req.VehicleManageReq;
import com.muyu.domain.resp.VehicleManageResp;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -31,4 +33,9 @@ public interface VehicleService extends IService<Vehicle> {
* @return
*/
Long findByVehicleVin(String vehicleVin);
/**
*
*/
void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq);
}

View File

@ -2,6 +2,7 @@ package com.muyu.enterprise.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.muyu.enterprise.cache.FenceCahceService;
import com.muyu.enterprise.mapper.ElectMapper;
import com.muyu.enterprise.mapper.WarnLogsMapper;
import com.muyu.enterprise.service.ElectService;
@ -25,6 +26,10 @@ public class ElectServiceImpl
@Autowired
private WarnLogsMapper warnLogsMapper;
@Autowired
private FenceCahceService fenceCahceService;
@Override
public List<FenceResp> selectFenceList(FenceReq req) {
@ -39,6 +44,11 @@ public class ElectServiceImpl
req.getFenceName()
);
List<FenceResp> list = electMapper.selectJoinList(FenceResp.class, wrapper);
String decode = fenceCahceService.decode(String.valueOf(list));
//将获取到的数据存到Redis
// fenceCahceService.put(String.valueOf(decode),d);
return list;
}
//

View File

@ -41,10 +41,5 @@ public class FencegroupServiceImpl
}
// @Override
// public List<FenceGroup> haveFence(HaveFence haveFence) {
// return null;
// }
}

View File

@ -2,11 +2,12 @@ package com.muyu.enterprise.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.enterprise.mapper.MessageValueMapper;
import com.muyu.enterprise.service.MessageValueService;
import com.muyu.domain.MessageValue;
import com.muyu.domain.req.MessageValueReq;
import com.muyu.domain.resp.MessageValueListResp;
import com.muyu.enterprise.cache.AllMessageValueCacheService;
import com.muyu.enterprise.mapper.MessageValueMapper;
import com.muyu.enterprise.service.MessageValueService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -31,6 +32,9 @@ public class MessageValueServiceImpl
@Autowired
private MessageValueMapper messageValueMapper;
@Autowired
private AllMessageValueCacheService allMessageValueCacheService;
public MessageValueServiceImpl(MessageValueMapper messageValueMapper) {
this.messageValueMapper = messageValueMapper;
}
@ -63,11 +67,13 @@ public class MessageValueServiceImpl
LambdaQueryWrapper<MessageValue> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MessageValue::getTemplateId, templateId);
List<MessageValue> list = this.list(queryWrapper);
return list.stream()
List<MessageValueListResp> collect = list.stream()
.map(messageValue -> MessageValueListResp.valueBuild(
messageValue
)
).collect(Collectors.toList());
allMessageValueCacheService.put(String.valueOf(templateId), collect);
return collect;
}

View File

@ -5,8 +5,10 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.domain.Vehicle;
import com.muyu.domain.VehicleType;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.domain.req.VehicleManageReq;
import com.muyu.domain.resp.VehicleManageResp;
import com.muyu.enterprise.cache.AllVehicleCacheService;
import com.muyu.enterprise.mapper.VehicleMapper;
import com.muyu.enterprise.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
@ -69,4 +71,11 @@ public class VehicleServiceImpl
return templateId;
}
@Override
public void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq) {
vehicleMapper.boundFenceGroup(boundFenceGroupReq);
}
}

View File

@ -8,7 +8,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# Spring
spring:

View File

@ -100,6 +100,13 @@
<artifactId>cloud-common-kafka</artifactId>
</dependency>
<!--缓存依赖-->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
<build>

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -116,6 +116,12 @@
<artifactId>cloud-common-kafka</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
<build>

View File

@ -1,40 +0,0 @@
package com.muyu.cloud.protocol.parsing.feign;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.resp.MessageValueListResp;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
/**
* @Author: LiDongJia
* @Package: com.muyu.cloud.protocol.parsing.feign
* @Project: 2112-car-cloud-server
* @name: RemoteServiceClient
* @Date: 2024/9/28 14:49
* @Description:
*/
@FeignClient(name = "cloud-car")
public interface RemoteServiceClient {
/**
* vinid
* @param vehicleVin
* @return
*/
@GetMapping("/vehicleManage/findByVehicleVin/{vehicleVin}")
@Operation(description = "通过车辆vin码查询模板id")
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin);
/**
* id
* @param templateId
* @return
*/
@GetMapping("/messageValue/findByTemplateId/{templateId}")
@Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId);
}

View File

@ -1,40 +0,0 @@
package com.muyu.cloud.protocol.parsing.feign.factory;
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.resp.MessageValueListResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import java.util.List;
/**
*
* @Author
* @Packagecom.muyu.analysis.parsing.remote.factory
* @Projectcloud-server
* @nameRemoteServiceClientFactory
* @Date2024/9/28 21:16
*/
public class RemoteServiceClientFactory implements FallbackFactory<RemoteServiceClient>
{
private static final Logger log = LoggerFactory.getLogger(com.muyu.cloud.protocol.parsing.feign.factory.RemoteServiceClientFactory.class);
@Override
public RemoteServiceClient create(Throwable throwable) {
log.error("报文模版传参调用失败:{}", throwable.getMessage());
return new RemoteServiceClient() {
@Override
public Result<Long> findByVehicleVin(String vehicleVin) {
return Result.success(Long.valueOf(vehicleVin));
}
@Override
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
return null;
}
};
}
}

View File

@ -1,16 +1,17 @@
package com.muyu.cloud.protocol.parsing.test;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.Vehicle;
import com.muyu.domain.VehicleType;
import com.muyu.domain.resp.MessageValueListResp;
import com.muyu.enterprise.cache.AllMessageValueCacheService;
import com.muyu.enterprise.cache.VehicleCacheService;
import com.muyu.enterprise.cache.VehicleTypeCacheService;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.eclipse.paho.client.mqttv3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@ -27,17 +28,20 @@ import java.util.List;
*/
@Log4j2
@Component
public class ParsingTest {
@Resource
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private RemoteServiceClient remoteServiceClient;
public class ParsingMessage {
@Resource
private KafkaProducer<String, String> kafkaProducer;
@Autowired
private VehicleCacheService vehicleCacheService;
@Autowired
private VehicleTypeCacheService vehicleTypeCacheService;
@Autowired
private AllMessageValueCacheService allMessageValueCacheService;
/**
*
*/
@ -92,32 +96,34 @@ public class ParsingTest {
String vehicleVin = result.substring(1, 18);
log.info("车辆VIN码: " + vehicleVin);
//根据车辆VIN码查询报文模板ID
Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
Long templateId = byVehicleVin.getData();
List<MessageValueListResp> templateList;
//从redis缓存中获取报文模板数据
try {
String redisKey = "messageTemplate" + templateId;
if (redisTemplate.hasKey(redisKey)) {
List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
templateList = list.stream()
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
.toList();
log.info("Redis缓存查询成功");
} else {
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
templateList = byTemplateId.getData();
templateList.forEach(
listResp ->
redisTemplate.opsForList().rightPush(
redisKey, JSON.toJSONString(listResp)
)
);
log.info("数据库查询成功");
}
} catch (Exception e) {
throw new RuntimeException("获取报文模板失败");
}
Vehicle vehicle = vehicleCacheService.get(vehicleVin);
Long vehicleTypeId = vehicle.getVehicleTypeId();
VehicleType vehicleType = vehicleTypeCacheService.get(String.valueOf(vehicleTypeId));
Long templateId = vehicleType.getMessageTemplateId();
List<MessageValueListResp> templateList = allMessageValueCacheService.get(String.valueOf(templateId));
// //从redis缓存中获取报文模板数据
// try {
// String redisKey = "messageTemplate" + templateId;
// if (redisTemplate.hasKey(redisKey)) {
// List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
// templateList = list.stream()
// .map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
// .toList();
// log.info("Redis缓存查询成功");
// } else {
// Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
// templateList = byTemplateId.getData();
// templateList.forEach(
// listResp ->
// redisTemplate.opsForList().rightPush(
// redisKey, JSON.toJSONString(listResp)
// )
// );
// log.info("数据库查询成功");
// }
// } catch (Exception e) {
// throw new RuntimeException("获取报文模板失败");
// }
//判断报文模板列表不为空
if (templateList.isEmpty()) {
throw new RuntimeException("报文模版为空");

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -115,6 +115,11 @@
<artifactId>tea-util</artifactId>
<version>0.2.21</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>darabonba-env</artifactId>
<version>0.1.1</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,17 @@
package com.muyu.cloud.vehicle.gateway.aliyun.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Instance {
private String instanceId;
private String ipAddress;
private String status;
}

View File

@ -1,23 +1,36 @@
// This file is auto-generated, don't edit it. Thanks.
package com.muyu.cloud.vehicle.gateway.test.example;
package com.muyu.cloud.vehicle.gateway.aliyun.ecs;
import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.DeleteInstancesRequest;
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
import com.aliyun.tea.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Log4j2
@Component
public class DelInstance implements DisposableBean{
public class DelInstance implements ApplicationListener<ContextClosedEvent> {
@Autowired
private StringRedisTemplate redisTemplate;
/**
* <b>description</b> :
@ -26,46 +39,48 @@ public class DelInstance implements DisposableBean{
*
* @throws Exception
*/
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
public static Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378657.html。
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
Config config = new Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5t7Fnx2QLTYLSu9357wP")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("3LOnydNZ25ytsTGczuSygElx0HJ6nN");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
return new com.aliyun.ecs20140526.Client(config);
return new Client(config);
}
public static void delInstance() throws Exception{
public void delInstance() throws Exception{
//创建ECS客户端对象用于后续调用ECS相关API
com.aliyun.ecs20140526.Client client = DelInstance.createClient();
Client client = DelInstance.createClient();
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
.setRegionId("cn-shanghai");
List<String> list = redisTemplate.opsForList().range("instanceIds",0,-1);
//创建运行时选择对象,用于配置运行时的选项参数
RuntimeOptions runtimeOptions = new RuntimeOptions();
// DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
// .setRegionId("cn-shanghai");
//获取实例列表
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
//提取实例ID集合
ArrayList<String> list = new ArrayList<>();
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
list.add(instance.getInstanceId());
}
System.out.println("Instance IDs"+list);
// //创建运行时选择对象,用于配置运行时的选项参数
// RuntimeOptions runtimeOptions = new RuntimeOptions();
//
// //获取实例列表
// DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
//
// //提取实例ID集合
// ArrayList<String> list = new ArrayList<>();
// DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
//
// for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
// list.add(instance.getInstanceId());
// }
//
// System.out.println("Instance IDs"+list);
// 创建删除实例请求对象,并设置请求参数
com.aliyun.ecs20140526.models.DeleteInstancesRequest deleteInstancesRequest = new com.aliyun.ecs20140526.models.DeleteInstancesRequest()
DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest()
// 设置地域ID指定要删除的实例所属的地域ID。
.setRegionId("cn-shanghai")
//设置DryRun为True用于验证请求是否可以成功但不实际执行删除操作
@ -77,32 +92,44 @@ public class DelInstance implements DisposableBean{
// 设置实例ID列表使用参数名称 instanceId参数类型为数组。
.setInstanceId(list);
// 创建运行时选项对象,用于配置运行时的选项参数
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
RuntimeOptions runtime = new RuntimeOptions();
try{
//复制代码运行请自行打印 API 的返回值
client.deleteInstancesWithOptions(deleteInstancesRequest,runtime);
} catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
log.error(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
log.error(error.getData().get("Recommend"));
Common.assertAsString(error.message);
} catch (Exception _error){
TeaException error = new TeaException(_error.getMessage(), _error);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
log.error(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
log.error(error.getData().get("Recommend"));
Common.assertAsString(error.message);
}
}
// @Override
// public void destroy() throws Exception {
// log.info("===============>开始执行删除实例方法");
// delInstance();
// }
@Override
public void destroy() throws Exception {
log.info("===============>开始执行删除实例方法");
public void onApplicationEvent(ContextClosedEvent event) {
try{
log.info("=======>删除实例");
delInstance();
redisTemplate.delete("instanceIds");
redisTemplate.delete("instanceList");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,59 @@
package com.muyu.cloud.vehicle.gateway.aliyun.ecs;
import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.darabonba.env.EnvClient;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;
import java.util.Arrays;
import java.util.List;
/**
*
*/
public class QueryInstance {
/**
* <b>description</b> :
* <p>使AK&amp;SKClient</p>
* @return Client
*
* @throws Exception
*/
public static Client createClient(String alibabaCloudAccessKeyId, String alibabaCloudAccessKeySecret) throws Exception{
Config config = new Config()
.setAccessKeyId("LTAI5t7Fnx2QLTYLSu9357wP")
.setAccessKeySecret("3LOnydNZ25ytsTGczuSygElx0HJ6nN");
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
return new Client(config);
}
public static Client createClientWithSTS() throws Exception {
Config config = new Config()
.setAccessKeyId("LTAI5t7Fnx2QLTYLSu9357wP")
.setAccessKeySecret("3LOnydNZ25ytsTGczuSygElx0HJ6nN")
.setSecurityToken("token")
.setType("sts");
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
return new Client(config);
}
public static void main(String[] args_) throws Exception{
List<String> list = Arrays.asList(args_);
Client client = QueryInstance.createClient(EnvClient.getEnv("LTAI5t7Fnx2QLTYLSu9357wP"), EnvClient.getEnv("3LOnydNZ25ytsTGczuSygElx0HJ6nN"));
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
.setRegionId("cn-shanghai")
.setInternetChargeType("PayByTraffic")
.setInstanceChargeType("PostPaid");
RuntimeOptions runtime = new RuntimeOptions();
DescribeInstancesResponse resp = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
com.aliyun.teaconsole.Client.log(Common.toJSONString(resp));
}
}

View File

@ -1,12 +1,25 @@
package com.muyu.cloud.vehicle.gateway.test.example;
package com.muyu.cloud.vehicle.gateway.aliyun.ecs;
import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.*;
import com.aliyun.tea.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import com.muyu.cloud.vehicle.gateway.aliyun.domain.Instance;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.CloseableThreadContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* ECS
*/
@ -14,6 +27,11 @@ import org.springframework.stereotype.Component;
@Component
public class Sample implements ApplicationRunner {
@Autowired
private StringRedisTemplate redisTemplate;
/**
* <b>description</b> :
* <p>使AK&amp;SKClient</p>
@ -21,44 +39,51 @@ public class Sample implements ApplicationRunner {
*
* @throws Exception
*/
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
public static Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
Config config = new Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5t7Fnx2QLTYLSu9357wP")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("3LOnydNZ25ytsTGczuSygElx0HJ6nN");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
return new com.aliyun.ecs20140526.Client(config);
return new Client(config);
}
public static void creatInstance() throws Exception {
public void creatInstance() throws Exception {
// 将命令行参数转换为字符串列表
java.util.List<String> args = java.util.Arrays.asList();
List<String> args = Arrays.asList();
// 创建阿里云ECS客户端
com.aliyun.ecs20140526.Client client = Sample.createClient();
Client client = Sample.createClient();
// 配置系统盘参数
com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk()
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk()
.setSize("20")// 设置系统盘大小为40GB
.setCategory("cloud_essd");// 设置系统盘类型为cloud_essd
// 创建创建实例请求对象并设置参数
com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
.setRegionId("cn-shanghai") // 设置地域ID
.setImageId("m-uf66taa8r57hvow8cxlj")// 设置镜像ID
.setImageId("m-uf63dnbv4od71jlezdne")// 设置镜像ID
.setInstanceType("ecs.e-c1m1.large")// 设置实例类型
.setSecurityGroupId("sg-uf6hyictocodexptlgiv")// 设置安全组ID
.setVSwitchId("vsw-uf6ags5luz17qd6ckn2tb")// 设置虚拟交换机ID
.setInstanceName("launch-advisor-20240928")// 设置实例名称
.setInstanceName("launch-advisor-20240929")// 设置实例名称
.setInstanceChargeType("PostPaid")// 设置实例付费类型为后付费按量付费
.setSystemDisk(systemDisk)// 设置系统盘配置
.setHostName("root")// 设置主机名
.setPassword("@ywt021900")// 设置实例密码
.setAmount(2);// 设置创建实例的数量
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
.setAmount(1)// 设置创建实例的数量
.setInternetChargeType("PayByTraffic")// 设置互联网计费类型为按流量计费
.setInternetMaxBandwidthOut(1);// 设置互联网最大出带宽为1 Mbps
RuntimeOptions runtime = new RuntimeOptions();
try {
// 复制代码运行请自行打印 API 的返回值
client.runInstancesWithOptions(runInstancesRequest, runtime);
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtime);
RunInstancesResponseBody body = runInstancesResponse.getBody();
ArrayList<String> list = new ArrayList<>(body.getInstanceIdSets().getInstanceIdSet());
log.info("实例ID{}", list);
} catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
@ -77,6 +102,13 @@ public class Sample implements ApplicationRunner {
}
}
// private static DescribeInstancesResponse queryInstanceDetails(Client client) {
//
// //创建查询实例请求对象并设置参数
// DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
// return null;
// }
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("===============>开始批量创建实例");

View File

@ -0,0 +1,56 @@
package com.muyu.cloud.vehicle.gateway.aliyun.ecs;//// This file is auto-generated, don't edit it. Thanks.
//package com.muyu.cloud.vehicle.gateway.aliyun.ecs;
//
//import com.aliyun.tea.*;
//
///**
// * 启动一台实例
// */
//public class StartInstance {
//
// /**
// * <b>description</b> :
// * <p>使用AK&amp;SK初始化账号Client</p>
// * @return Client
// *
// * @throws Exception
// */
// public static com.aliyun.ecs20140526.Client createClient() throws Exception {
// // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// // 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378657.html。
// com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
// .setAccessKeyId("LTAI5t7Fnx2QLTYLSu9357wP")
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// .setAccessKeySecret("3LOnydNZ25ytsTGczuSygElx0HJ6nN");
// // Endpoint 请参考 https://api.aliyun.com/product/Ecs
// config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
// return new com.aliyun.ecs20140526.Client(config);
// }
//
// public static void main(String[] args_) throws Exception {
// java.util.List<String> args = java.util.Arrays.asList(args_);
// com.aliyun.ecs20140526.Client client = StartInstance.createClient();
// com.aliyun.ecs20140526.models.StartInstanceRequest startInstanceRequest = new com.aliyun.ecs20140526.models.StartInstanceRequest();
// com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
// try {
// // 复制代码运行请自行打印 API 的返回值
// client.startInstanceWithOptions(startInstanceRequest, runtime);
// } catch (TeaException error) {
// // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// // 错误 message
// System.out.println(error.getMessage());
// // 诊断地址
// System.out.println(error.getData().get("Recommend"));
// com.aliyun.teautil.Common.assertAsString(error.message);
// } catch (Exception _error) {
// TeaException error = new TeaException(_error.getMessage(), _error);
// // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// // 错误 message
// System.out.println(error.getMessage());
// // 诊断地址
// System.out.println(error.getData().get("Recommend"));
// com.aliyun.teautil.Common.assertAsString(error.message);
// }
// }
//}

View File

@ -1,56 +0,0 @@
// This file is auto-generated, don't edit it. Thanks.
package com.muyu.cloud.vehicle.gateway.test.example;
import com.aliyun.tea.*;
/**
*
*/
public class StartInstance {
/**
* <b>description</b> :
* <p>使AK&amp;SKClient</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378657.html。
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5t7Fnx2QLTYLSu9357wP")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("3LOnydNZ25ytsTGczuSygElx0HJ6nN");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
return new com.aliyun.ecs20140526.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.ecs20140526.Client client = StartInstance.createClient();
com.aliyun.ecs20140526.models.StartInstanceRequest startInstanceRequest = new com.aliyun.ecs20140526.models.StartInstanceRequest();
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// 复制代码运行请自行打印 API 的返回值
client.startInstanceWithOptions(startInstanceRequest, runtime);
} catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.49.53:8848
user-name: nacos
password: nacos
namespace: seven
namespace: vehicle
# Spring
spring: