* 成功 | * 成功 | ||||
*/ | */ | ||||
public static final int SUCCESS = 0; | public static final int SUCCESS = 0; | ||||
/** | |||||
* 专用 | |||||
*/ | |||||
public static final int OIDC_ERROR = -2; | |||||
/** | /** | ||||
* 失败 | * 失败 | ||||
*/ | */ |
public static String token() { | public static String token() { | ||||
// header中获取用户token | // header中获取用户token | ||||
check(); | |||||
String token = ServletUtils.getRequest().getHeader("th-token"); | String token = ServletUtils.getRequest().getHeader("th-token"); | ||||
if (StringUtils.isEmpty(token)) { | if (StringUtils.isEmpty(token)) { | ||||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "token不能为空"); | throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "token不能为空"); | ||||
*/ | */ | ||||
public static String username() { | public static String username() { | ||||
// header中获取用户token | // header中获取用户token | ||||
check(); | |||||
String oUserJson = ServletUtils.getRequest().getHeader("o-user-json"); | String oUserJson = ServletUtils.getRequest().getHeader("o-user-json"); | ||||
if (StringUtils.isEmpty(oUserJson)) { | if (StringUtils.isEmpty(oUserJson)) { | ||||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "oUserJson不能为空"); | throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "oUserJson不能为空"); | ||||
return username; | return username; | ||||
} | } | ||||
public static void check() { | |||||
String oUserJson = ServletUtils.getRequest().getHeader("o-user-json"); | |||||
String json = EncryptUtil.decodeUTF8StringBase64(oUserJson); | |||||
JSONObject jsonObject = JSON.parseObject(json); | |||||
Integer isAble = jsonObject.getInteger("isAble"); | |||||
Integer isExpire = jsonObject.getInteger("isExpire"); | |||||
if (StringUtils.isNotNull(isAble) && StringUtils.isNotNull(isExpire)) { | |||||
if (0 == isAble) { | |||||
throw new ServiceException(JsonResult.OIDC_ERROR, "该账号已被禁用,请联系系统管理员"); | |||||
} | |||||
if (0 == isExpire) { | |||||
throw new ServiceException(JsonResult.OIDC_ERROR, "系统有效期已过,请联系系统管理员"); | |||||
} | |||||
} | |||||
} | |||||
} | } |
if (type == 1) { | if (type == 1) { | ||||
//解析srt文件经纬度和时间戳 | //解析srt文件经纬度和时间戳 | ||||
flightDataList = SrtDataUtil.getByM300(txtContent, inspectionId, tenantId); | flightDataList = SrtDataUtil.getByM300(txtContent, inspectionId, tenantId); | ||||
} else if(type == 2){ | |||||
flightDataList = SrtDataUtil.getByYu2(txtContent, inspectionId, tenantId); | |||||
} else if(type == 3){ | |||||
flightDataList = SrtDataUtil.getByYu3e(txtContent, inspectionId, tenantId); | |||||
} else { | } else { | ||||
log.info("srt文件上传, type不等于1,异常"); | |||||
log.info("srt文件上传, type={}, type不等于1,2,3,异常", type); | |||||
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); | throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); | ||||
} | } | ||||
if (ObjectUtils.isEmpty(flightDataList)) { | |||||
log.info("srt文件上传, 上传文件数据错误,请检查文件!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_IS_ERROR); | |||||
} | |||||
flightDataMapper.delete(new LambdaQueryWrapper<FlightData>() | flightDataMapper.delete(new LambdaQueryWrapper<FlightData>() | ||||
.eq(FlightData::getInspectionId, inspectionId) | .eq(FlightData::getInspectionId, inspectionId) | ||||
.eq(FlightData::getTenantId, tenantId) | .eq(FlightData::getTenantId, tenantId) |
package com.tuoheng.admin.service.third.oidc; | package com.tuoheng.admin.service.third.oidc; | ||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||||
import com.tuoheng.admin.entity.domain.Role; | |||||
import com.tuoheng.admin.entity.dto.RolePermissionDto; | import com.tuoheng.admin.entity.dto.RolePermissionDto; | ||||
import com.tuoheng.admin.entity.domain.Tenant; | import com.tuoheng.admin.entity.domain.Tenant; | ||||
import com.tuoheng.admin.entity.domain.User; | import com.tuoheng.admin.entity.domain.User; | ||||
import com.tuoheng.admin.entity.request.third.oidc.CreateOidcTenantRequest; | import com.tuoheng.admin.entity.request.third.oidc.CreateOidcTenantRequest; | ||||
import com.tuoheng.admin.entity.request.third.oidc.DeletedOidcTenantRequest; | import com.tuoheng.admin.entity.request.third.oidc.DeletedOidcTenantRequest; | ||||
import com.tuoheng.admin.entity.request.third.oidc.EditOidcTenantRequest; | import com.tuoheng.admin.entity.request.third.oidc.EditOidcTenantRequest; | ||||
import com.tuoheng.admin.mapper.RoleMapper; | |||||
import com.tuoheng.admin.service.system.role.IRoleService; | import com.tuoheng.admin.service.system.role.IRoleService; | ||||
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import java.util.List; | |||||
@Slf4j | @Slf4j | ||||
@Service | @Service | ||||
public class OidcServiceImpl implements OidcService { | public class OidcServiceImpl implements OidcService { | ||||
@Autowired | @Autowired | ||||
private MenuMapper menuMapper; | private MenuMapper menuMapper; | ||||
@Autowired | |||||
private RoleMapper roleMapper; | |||||
public JsonResult addUser(User user, String password, Tenant tenant) { | public JsonResult addUser(User user, String password, Tenant tenant) { | ||||
return addOidcUserService.add(user, password, tenant); | return addOidcUserService.add(user, password, tenant); | ||||
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult getRoleList() { | public JsonResult getRoleList() { | ||||
//返回角色列表 | |||||
List<Role> roles = roleMapper.selectList(new LambdaQueryWrapper<Role>() | |||||
.eq(Role::getMark, 1) | |||||
.eq(Role::getTenantId, "1") | |||||
.eq(Role::getStatus, 1)); | |||||
return JsonResult.success(roles); | |||||
// JsonResult jsonResult = roleService.getRoles(); | |||||
JsonResult jsonResult = roleService.getRoles(); | |||||
return jsonResult; | |||||
} | } | ||||
/** | /** |
import java.util.regex.Matcher; | import java.util.regex.Matcher; | ||||
import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||
/** | /** | ||||
* SRT文件经纬度解析工具 | * SRT文件经纬度解析工具 | ||||
* | * | ||||
@Slf4j | @Slf4j | ||||
public class SrtDataUtil { | public class SrtDataUtil { | ||||
/** | |||||
* 机型为御3E拍摄的SRT文件 | |||||
*/ | |||||
public static List<FlightData> getByYu3e(String srtMsg, String inspectionId, String tenantId) throws Exception { | |||||
List<FlightData> flightDataList = new ArrayList<>(); | |||||
//将全部字符串按照每个font分割 | |||||
List<String> msgList = new ArrayList<>(); | |||||
Matcher msg = Pattern.compile( | |||||
Pattern.quote("HOME(") | |||||
+ "(.*?)" | |||||
+ Pattern.quote("ISO:") | |||||
).matcher(srtMsg); | |||||
while (msg.find()) { | |||||
String match = msg.group(1); | |||||
msgList.add(match); | |||||
} | |||||
//解析每组数据 | |||||
for (String str : msgList) { | |||||
FlightData flightData = new FlightData(); | |||||
flightData.setIsSrt(1); | |||||
flightData.setInspectionId(inspectionId); | |||||
flightData.setTenantId(tenantId); | |||||
//找出时间,格式为2023.02.27 15:32:19 | |||||
Matcher time = Pattern.compile(Pattern.quote(") ") | |||||
+ "(.*?)" | |||||
+ Pattern.quote("GPS(") | |||||
).matcher(str); | |||||
if (time.find()) { | |||||
String match = time.group(1); | |||||
//截取时间,转为时间戳 | |||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); | |||||
Date date = simpleDateFormat.parse(match); | |||||
String timeStamp = String.valueOf(date.getTime()); | |||||
flightData.setTimestamp(timeStamp); | |||||
} else { | |||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); | |||||
} | |||||
//找出经度 | |||||
Matcher longitude = Pattern.compile( | |||||
Pattern.quote("GPS(") | |||||
+ "(.*?)" | |||||
+ Pattern.quote(",") | |||||
).matcher(str); | |||||
if (longitude.find()) { | |||||
String match = longitude.group(1); | |||||
flightData.setLng(match); | |||||
} else { | |||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR); | |||||
} | |||||
//找出数据 格式为 GPS(120.909168,32.596070,141.100000) | |||||
Matcher latitude = Pattern.compile( | |||||
Pattern.quote("GPS(") | |||||
+ "(.*?)" | |||||
+ Pattern.quote(")") | |||||
).matcher(str); | |||||
if (latitude.find()) { | |||||
String match = latitude.group(1); | |||||
//找出纬度 | |||||
String lat = match.split(",")[1]; | |||||
flightData.setLat(lat); | |||||
} else { | |||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LAT_IS_ERROR); | |||||
} | |||||
flightDataList.add(flightData); | |||||
} | |||||
return flightDataList; | |||||
} | |||||
/** | /** | ||||
* 机型为御二拍摄的SRT文件 | * 机型为御二拍摄的SRT文件 | ||||
*/ | */ | ||||
public static List<FlightData> getByYu2(String srtMsg, String inspectionId) throws Exception { | |||||
public static List<FlightData> getByYu2(String srtMsg, String inspectionId, String tenantId) throws Exception { | |||||
List<FlightData> flightDataList = new ArrayList<>(); | List<FlightData> flightDataList = new ArrayList<>(); | ||||
//将全部字符串按照每个font分割 | //将全部字符串按照每个font分割 | ||||
List<String> msgList = new ArrayList<>(); | List<String> msgList = new ArrayList<>(); | ||||
FlightData flightData = new FlightData(); | FlightData flightData = new FlightData(); | ||||
flightData.setIsSrt(1); | flightData.setIsSrt(1); | ||||
flightData.setInspectionId(inspectionId); | flightData.setInspectionId(inspectionId); | ||||
flightData.setTenantId(tenantId); | |||||
//找出时间,格式为2021-08-24 09:33:15,848,518 | //找出时间,格式为2021-08-24 09:33:15,848,518 | ||||
Matcher time = Pattern.compile(Pattern.quote("ms") | Matcher time = Pattern.compile(Pattern.quote("ms") | ||||
+ "(.*?)" | + "(.*?)" | ||||
String timeStamp = String.valueOf(date.getTime()); | String timeStamp = String.valueOf(date.getTime()); | ||||
flightData.setTimestamp(timeStamp); | flightData.setTimestamp(timeStamp); | ||||
} else { | } else { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); | ||||
} | } | ||||
String match = longitude.group(1); | String match = longitude.group(1); | ||||
flightData.setLng(match); | flightData.setLng(match); | ||||
} else { | } else { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR); | ||||
} | } | ||||
//找出纬度 | //找出纬度 | ||||
String match = latitude.group(1); | String match = latitude.group(1); | ||||
flightData.setLat(match); | flightData.setLat(match); | ||||
} else { | } else { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LAT_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LAT_IS_ERROR); | ||||
} | } | ||||
flightDataList.add(flightData); | flightDataList.add(flightData); | ||||
String match = longitude.group(1); | String match = longitude.group(1); | ||||
flightData.setLng(match); | flightData.setLng(match); | ||||
} else { | } else { | ||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!"); | |||||
log.info("获取机型为M300拍摄的SRT文件数据, 上传文件数据错误,请检查文件!!!"); | |||||
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR); | throw new ServiceException(ServiceExceptionEnum.FILE_DATA_LNG_IS_ERROR); | ||||
} | } | ||||
//找出纬度 | //找出纬度 |