Browse Source

更新服务实例多选及其返回相关

tags/v2.4.1
xiaoying 1 year ago
parent
commit
400e02cdf4
4 changed files with 74 additions and 44 deletions
  1. +22
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/AlgorithmDto.java
  2. +9
    -8
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/ClientRoleDto.java
  3. +35
    -17
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java
  4. +8
    -19
      tuoheng_oidc_admin/src/main/java/com/tuoheng/until/MapUtils.java

+ 22
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/AlgorithmDto.java View File

@@ -0,0 +1,22 @@
package com.tuoheng.model.dto;

import lombok.Data;

/**
* 算法实例dto
* @Author xiaoying
* @Date 2023/3/15 16:13
*/
@Data
public class AlgorithmDto {
/**
* 该平台对应服务实例id
*/
private String serviceId;
/**
* 识别详情
*/
private String description;


}

+ 9
- 8
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/ClientRoleDto.java View File

@@ -1,7 +1,10 @@
package com.tuoheng.model.param;

import com.tuoheng.model.dto.AlgorithmDto;
import lombok.Data;

import java.util.List;

/**
* @author chenjiandong
* @description: TODO
@@ -14,17 +17,15 @@ public class ClientRoleDto {
*/
private String clientId;
/**
* 该平台对应角色id
*/
private Integer roleId;
/**
* 该平台对应服务实例id
* 算法实例对象集合
*/
private String serviceId;
private List<AlgorithmDto> algorithmList;

/**
* 识别详情
* 该平台对应角色id
*/
private String description;
private Integer roleId;

/**
* 角色名
*/

+ 35
- 17
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java View File

@@ -84,7 +84,6 @@ public class TenantServiceImpl implements TenantService {
@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser) {

if (clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0) {
return JsonResult.error("该用户名称已存在!");
}
@@ -105,7 +104,7 @@ public class TenantServiceImpl implements TenantService {
clientUserMapper.insertClientUser(userPo);
log.info("用户表添加完毕");
//调用高德将地址转换经纬度
Map lonAndLat = MapUtils.getLonAndLat(createClientTenantDto.getAdress(), CommonConfig.gaodeKey);
Map<String, String> lonAndLat = MapUtils.getLonAndLat(createClientTenantDto.getAdress(), CommonConfig.gaodeKey);
//租户表
TenantPo tenantPo = new TenantPo();
BeanUtils.copyProperties(createClientTenantDto, tenantPo);
@@ -138,12 +137,17 @@ public class TenantServiceImpl implements TenantService {
PlatformName.append(platform.getPlatformName());
PlatformName.append(CommonConstant.SIGN);
//添加租户对应服务的相关表数据
TenantEmploy tenantEmploy = new TenantEmploy();
tenantEmploy.setTenantId(tenantPo.getId());
tenantEmploy.setServiceId(clientRoleDto.getServiceId());
tenantEmploy.setDescription(clientRoleDto.getDescription());
tenantEmploy.setPlatformCode(platform.getPlatformCode());
tenantEmployMapper.insert(tenantEmploy);
List<AlgorithmDto> algorithmList = clientRoleDto.getAlgorithmList();
if (ObjectUtil.isNotEmpty(algorithmList)) {
for (AlgorithmDto algorithmDto : algorithmList) {
TenantEmploy tenantEmploy = new TenantEmploy();
tenantEmploy.setTenantId(tenantPo.getId());
tenantEmploy.setPlatformCode(platform.getPlatformCode());
tenantEmploy.setServiceId(algorithmDto.getServiceId());
tenantEmploy.setDescription(algorithmDto.getDescription());
tenantEmployMapper.insert(tenantEmploy);
}
}
}
//拼接
vo.setPlatformName(PlatformName.substring(CommonConstant.ZERO, PlatformName.lastIndexOf(CommonConstant.SIGN)));
@@ -405,12 +409,21 @@ public class TenantServiceImpl implements TenantService {
//此处 暂时格式都为 tuoheng-hhz-web 等格式 如后续维护需要变更形式则此处代码需要更改
clientRoleDto.setRoleId(clientUserRolePo.getRoleId());
clientRoleDto.setRoleName(clientUserRolePo.getRoleName());
List<AlgorithmDto> algorithmDtos = new ArrayList<>();
clientRoleDto.setClientId(clientUserRolePo.getClientId().substring(CommonConstant.ZERO, clientUserRolePo.getClientId().lastIndexOf(CommonConstant.BARS)));
TenantEmploy tenantEmploy = tenantEmployMapper.selectOne(Wrappers.<TenantEmploy>lambdaQuery()
List<TenantEmploy> tenantEmploys = tenantEmployMapper.selectList(Wrappers.<TenantEmploy>lambdaQuery()
.eq(TenantEmploy::getTenantId, tenantId)
.eq(TenantEmploy::getPlatformCode, clientRoleDto.getClientId()));
Optional.ofNullable(tenantEmploy).ifPresent(t -> clientRoleDto.setServiceId(t.getServiceId()));
Optional.ofNullable(tenantEmploy).ifPresent(t -> clientRoleDto.setDescription(t.getDescription()));
if (ObjectUtil.isNotEmpty(tenantEmploys)) {
for (TenantEmploy tenantEmploy : tenantEmploys) {
AlgorithmDto algorithmDto = new AlgorithmDto();
algorithmDto.setServiceId(tenantEmploy.getServiceId());
algorithmDto.setDescription(tenantEmploy.getDescription());
algorithmDtos.add(algorithmDto);
}
clientRoleDto.setAlgorithmList(algorithmDtos);
}

list.add(clientRoleDto);
}
dto.setClientRoleDtoList(list.stream().distinct().collect(Collectors.toList()));
@@ -510,12 +523,17 @@ public class TenantServiceImpl implements TenantService {
List<ClientRoleDto> list = dto.getClientRoleDtoList();
//新增租户关联业务服务实例相关
for (ClientRoleDto clientRoleDto : list) {
TenantEmploy tenantEmploy = new TenantEmploy();
tenantEmploy.setDescription(clientRoleDto.getDescription());
tenantEmploy.setTenantId(dto.getId());
tenantEmploy.setServiceId(clientRoleDto.getServiceId());
tenantEmploy.setPlatformCode(clientRoleDto.getClientId());
tenantEmployMapper.insert(tenantEmploy);
List<AlgorithmDto> algorithmList = clientRoleDto.getAlgorithmList();
if (ObjectUtil.isNotEmpty(algorithmList)) {
for (AlgorithmDto algorithmDto : algorithmList) {
TenantEmploy tenantEmploy = new TenantEmploy();
tenantEmploy.setTenantId(dto.getId());
tenantEmploy.setPlatformCode(clientRoleDto.getClientId());
tenantEmploy.setServiceId(algorithmDto.getServiceId());
tenantEmploy.setDescription(algorithmDto.getDescription());
tenantEmployMapper.insert(tenantEmploy);
}
}
}
log.info("租户更新的业务服务实例表更新完毕");
//更新租户原有数据基本

+ 8
- 19
tuoheng_oidc_admin/src/main/java/com/tuoheng/until/MapUtils.java View File

@@ -1,8 +1,10 @@
package com.tuoheng.until;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tuoheng.common.CommonConfig;
import com.tuoheng.constant.CommonConstant;

import java.io.BufferedReader;
import java.io.InputStreamReader;
@@ -12,19 +14,6 @@ import java.util.HashMap;
import java.util.Map;

public class MapUtils {
public static void main(String[] args) {
try {
// 1、根据地址获取经纬度
Map<String, String> lonAndLat = getLonAndLat("浙江省杭州市滨江区江汉路1515号", CommonConfig.gaodeKey);
System.out.println("转换后经纬度为:" + lonAndLat);

// 2、根据经纬度获取地址
String formattedAddress = getAMapByLngAndLat("120.204798", "30.201000", CommonConfig.gaodeKey);
System.out.println("转换后地址为:" + formattedAddress);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 地址转换为经纬度
@@ -33,26 +22,26 @@ public class MapUtils {
* @param key 高德地图应用key
* @return 经纬度
*/
public static Map getLonAndLat(String address, String key) {
public static Map<String, String> getLonAndLat(String address, String key) {
// 返回输入地址address的经纬度信息, 格式是 经度,纬度
String queryUrl = "http://restapi.amap.com/v3/geocode/geo?key=" + key + "&address=" + address;
// 高德接口返回的是JSON格式的字符串
String queryResult = getResponse(queryUrl);
Map<String, String> map = new HashMap<String, String>();
JSONObject obj = JSONObject.parseObject(queryResult);
if (obj.get("status").toString().equals("1")) {
JSONObject jobJSON = JSONObject.parseObject(obj.get("geocodes").toString().substring(1, obj.get("geocodes").toString().length() - 1));
String location = jobJSON.get("location").toString();
if (CommonConstant.ONE.toString().equals(obj.get("status").toString())) {
JSONObject jsonObject = JSONObject.parseObject(obj.get("geocodes").toString().substring(1, obj.get("geocodes").toString().length() - 1));
String location = jsonObject.get("location").toString();
System.out.println("经纬度:" + location);
String[] lonAndLat = location.split(",");
if (lonAndLat != null && lonAndLat.length == 2) {
if (ObjectUtil.isNotEmpty(lonAndLat) && lonAndLat.length == 2) {
map.put("lng", lonAndLat[0]);
map.put("lat", lonAndLat[1]);
}
System.out.println(map);
return map;
} else {
throw new RuntimeException("地址转换经纬度失败,错误码:" + obj.get("infocode"));
throw new RuntimeException("地址转换经纬度失败,请重新输入详细地址");
}
}


Loading…
Cancel
Save