Merge branch 'server_five_liuyunhu' into server_five_dongxiaodong
commit
e59a8b3300
|
@ -3,8 +3,6 @@ package com.couplet.mqtt;
|
|||
import com.couplet.common.security.annotation.EnableCustomConfig;
|
||||
import com.couplet.common.security.annotation.EnableMyFeignClients;
|
||||
import com.couplet.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import com.couplet.mqtt.service.impl.MqttListen;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
@ -12,15 +10,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
* @ProjectName: Default (Template) Project
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description:
|
||||
* @Description: 获取报文模块启动类
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class LyhMqttxApplatcaion {
|
||||
public class CoupletMqttxApplatcaion {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LyhMqttxApplatcaion.class, args);
|
||||
SpringApplication.run(CoupletMqttxApplatcaion.class, args);
|
||||
System.out.println("获取报文模块启动成功");
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.couplet.mqtt.controller;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
String broker = "tcp://115.159.47.13:1883";
|
||||
String clientId = "JavaMqttSubscriber";
|
||||
String topic = "test"; // 替换成您要订阅的主题
|
||||
|
||||
try {
|
||||
MqttClient client = new MqttClient(broker, clientId, new MemoryPersistence());
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
|
||||
System.out.println("Connecting to broker: " + broker);
|
||||
client.connect(connOpts);
|
||||
System.out.println("Connected");
|
||||
|
||||
client.setCallback(new MqttCallback() {
|
||||
@Override
|
||||
public void connectionLost(Throwable cause) {
|
||||
System.out.println("Connection lost");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||
System.out.println("Received message: " + new String(message.getPayload()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||
}
|
||||
});
|
||||
|
||||
client.subscribe(topic);
|
||||
System.out.println("Subscribed to topic: " + topic);
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ package com.couplet.mqtt.service;
|
|||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description:
|
||||
* @Description: MQTT服务接口
|
||||
*/
|
||||
|
||||
public interface MqttService {
|
||||
|
|
|
@ -84,7 +84,7 @@ public class MqttListen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||
public void messageArrived(String topic, MqttMessage message) {
|
||||
log.info("消息到达");
|
||||
log.info("接收消息主题:" + topic);
|
||||
log.info("接收消息Qos:" + message.getQos());
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.stereotype.Service;
|
|||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description:
|
||||
* @Description: MQTT服务实现类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
* @ProjectName: Default (Template) Project
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/26
|
||||
* @Description:
|
||||
* @Description: 车辆管理模块启动类
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.couplet.vehicle.domain.req.VehicleInsertParams;
|
|||
import com.couplet.vehicle.domain.req.VehicleListParams;
|
||||
import com.couplet.vehicle.service.VehicleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -18,13 +19,13 @@ import java.util.List;
|
|||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/26
|
||||
* @Description:
|
||||
* @Description: 车辆管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/vehicle")
|
||||
public class VehicleController extends BaseController {
|
||||
@Autowired
|
||||
private VehicleService lyhVehicleService;
|
||||
private VehicleService vehicleService;
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
|
@ -37,7 +38,7 @@ public class VehicleController extends BaseController {
|
|||
@Log(title = "车辆列表")
|
||||
public Result list(@RequestBody VehicleListParams listParams) {
|
||||
|
||||
List<LyhVehicle> List = lyhVehicleService.list(listParams);
|
||||
List<LyhVehicle> List = vehicleService.list(listParams);
|
||||
|
||||
return Result.success(List);
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ public class VehicleController extends BaseController {
|
|||
@GetMapping("/deleteById/{vehicleId}")
|
||||
@Log(title = "删除车辆", businessType = BusinessType.DELETE)
|
||||
public Result deleteById(@PathVariable Long vehicleId) {
|
||||
String result = lyhVehicleService.deleteById(vehicleId);
|
||||
String result = vehicleService.deleteById(vehicleId);
|
||||
|
||||
return Result.success(result);
|
||||
}
|
||||
|
@ -69,7 +70,7 @@ public class VehicleController extends BaseController {
|
|||
@Log(title = "编辑车辆", businessType = BusinessType.UPDATE)
|
||||
public Result editById(@RequestBody VehicleEditParams editParams) {
|
||||
|
||||
String result = lyhVehicleService.editById(editParams);
|
||||
String result = vehicleService.editById(editParams);
|
||||
|
||||
return Result.success(result);
|
||||
}
|
||||
|
@ -83,9 +84,9 @@ public class VehicleController extends BaseController {
|
|||
**/
|
||||
@PostMapping("/insert")
|
||||
@Log(title = "新增车辆", businessType = BusinessType.INSERT)
|
||||
public Result insert(@RequestBody VehicleInsertParams insertParams) {
|
||||
public Result insert(@RequestBody @Validated VehicleInsertParams insertParams) {
|
||||
|
||||
String result = lyhVehicleService.insert(insertParams);
|
||||
String result = vehicleService.insert(insertParams);
|
||||
|
||||
return Result.success(result);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull;
|
|||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/27
|
||||
* @Description: 车辆编辑入参
|
||||
* @Description: 车辆插入入参
|
||||
*/
|
||||
|
||||
@Data
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
|
|||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/26
|
||||
* @Description:
|
||||
* @Description: 车辆Mapper
|
||||
*/
|
||||
@Mapper
|
||||
@Component
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/26
|
||||
* @Description:
|
||||
* @Description: 车辆服务
|
||||
*/
|
||||
|
||||
public interface VehicleService extends IService<LyhVehicle> {
|
||||
|
|
|
@ -21,14 +21,14 @@ import java.util.List;
|
|||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/26
|
||||
* @Description:
|
||||
* @Description: 车辆服务实现类
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, LyhVehicle> implements VehicleService {
|
||||
@Autowired
|
||||
private VehicleMapper lyhVehicleMapper;
|
||||
private VehicleMapper vehicleMapper;
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
|
@ -143,11 +143,13 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, LyhVehicle> i
|
|||
public String insert(VehicleInsertParams insertParams) {
|
||||
String result = "";
|
||||
|
||||
//雪花算法生成随机数
|
||||
SnowflakeIdGenerator idGenerator = new SnowflakeIdGenerator(1, 1);
|
||||
long randomId = idGenerator.nextId();
|
||||
String vin = "VIN" + randomId;
|
||||
|
||||
int insert = lyhVehicleMapper.insert(new LyhVehicle(null, insertParams.getVehicleType(), insertParams.getMotorManufacturer(), insertParams.getBatteryManufacturer(), insertParams.getMotorNumber(), insertParams.getBatteryNumber(), vin, 0, 0));
|
||||
//执行插入操作
|
||||
int insert = vehicleMapper.insert(new LyhVehicle(null, insertParams.getVehicleType(), insertParams.getMotorManufacturer(), insertParams.getBatteryManufacturer(), insertParams.getMotorNumber(), insertParams.getBatteryNumber(), vin, 0, 0));
|
||||
|
||||
if (insert == 0) {
|
||||
result = "新增失败";
|
||||
|
|
Loading…
Reference in New Issue