车辆上线,返回主题,添加sql验证数据
parent
eec1033f73
commit
cfe6805a0d
|
@ -133,6 +133,11 @@ public class Car {
|
|||
*/
|
||||
private String carTypeName;
|
||||
|
||||
/**
|
||||
* 车辆绑定的主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
public static Car carBuildAdd(CarRequest carRequest){
|
||||
return Car.builder()
|
||||
.carVinId(carRequest.getCarVinId())
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.god.base.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description: 根据终端4个参数返回对应车辆主题
|
||||
* @Author fst
|
||||
* @date 2023/11/28 23:02
|
||||
*/
|
||||
@Data
|
||||
public class GetTopicReq {
|
||||
/**
|
||||
* 车辆VIN
|
||||
*/
|
||||
private String carVin;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private String timeString;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String randomStr;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.god.base.server.controller;
|
||||
|
||||
import com.god.base.domain.request.GetTopicReq;
|
||||
import com.god.base.server.service.TopLineService;
|
||||
import com.god.base.server.service.impl.TopLineServiceImpl;
|
||||
import com.god.common.core.domain.Result;
|
||||
import com.god.common.log.annotation.Log;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @description: 车辆上线控制层
|
||||
* @Author fst
|
||||
* @date 2023/11/28 23:38
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/topLine")
|
||||
public class TopLineController {
|
||||
|
||||
@Autowired
|
||||
private TopLineServiceImpl topLineService;
|
||||
|
||||
/**
|
||||
* 获取主题
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getTopic")
|
||||
@Log(title = "获取主题")
|
||||
public Result<String> getTopic(@RequestBody GetTopicReq getTopicReq){
|
||||
String topic = topLineService.getTopic(getTopicReq);
|
||||
return Result.success(topic);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.god.base.server.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.god.base.domain.Car;
|
||||
import com.god.base.domain.request.GetTopicReq;
|
||||
|
||||
/**
|
||||
* 车辆上线
|
||||
* @Author fst
|
||||
* @date 2023/11/28 23:41
|
||||
*/
|
||||
public interface TopLineService extends IService<Car> {
|
||||
|
||||
|
||||
/**
|
||||
* 车辆上线,同时返回主题
|
||||
* @param getTopicReq
|
||||
* @return
|
||||
*/
|
||||
String getTopic(GetTopicReq getTopicReq);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.god.base.server.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.god.base.domain.Car;
|
||||
import com.god.base.domain.request.GetTopicReq;
|
||||
import com.god.base.server.mapper.CarMapper;
|
||||
import com.god.base.server.service.TopLineService;
|
||||
import com.god.common.core.exception.ServiceException;
|
||||
import com.god.common.core.utils.StringUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description: 车辆上线实现
|
||||
* @Author fst
|
||||
* @date 2023/11/28 23:42
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class TopLineServiceImpl extends ServiceImpl<CarMapper, Car> implements TopLineService {
|
||||
|
||||
@Autowired
|
||||
private CarMapper carMapper;
|
||||
|
||||
/**
|
||||
* 车辆上线,同时返回主题
|
||||
* @param getTopicReq
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getTopic(GetTopicReq getTopicReq) {
|
||||
try {
|
||||
if (StringUtils.isEmpty(getTopicReq.getCarVin())){
|
||||
throw new ServiceException("车辆vin不能为空");
|
||||
}
|
||||
//根据车辆vinId查询车辆信息
|
||||
QueryWrapper<Car> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("carVinId",getTopicReq.getCarVin());
|
||||
Car car = (Car) carMapper.selectObjs(wrapper);
|
||||
if (StringUtils.isEmpty(new Car[]{car})){
|
||||
throw new ServiceException("车辆信息不存在");
|
||||
}
|
||||
//把车辆状态修改为上线 1
|
||||
car.setStatus(1);
|
||||
carMapper.update(car,new QueryWrapper<Car>().eq("carVinId",getTopicReq.getCarVin()));
|
||||
return car.getTopic();
|
||||
}catch (Exception e){
|
||||
log.info(e.getMessage());
|
||||
return "god";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.god.base.server.util;
|
||||
|
||||
import com.god.base.domain.request.GetTopicReq;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
/**
|
||||
* @description: md5加密工具类
|
||||
* @Author fst
|
||||
* @date 2023/11/29 14:16
|
||||
*/
|
||||
@Log4j2
|
||||
public class Md5Util {
|
||||
|
||||
public static String md5(GetTopicReq getTopicReq) {
|
||||
try {
|
||||
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
|
||||
String str = getTopicReq.getTimeString() + getTopicReq.getUserName() + getTopicReq.getRandomStr() + getTopicReq.getCarVin();
|
||||
byte[] array = md.digest(str.getBytes());
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
catch (java.security.NoSuchAlgorithmException e) {
|
||||
log.error("MD5加密出现异常", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue