接口优化
parent
9713efaf23
commit
dcdf51f4e2
File diff suppressed because one or more lines are too long
|
@ -31,7 +31,7 @@ public class PlaceController {
|
|||
*/
|
||||
@PostMapping("/showPlacePage")
|
||||
public Result showPlacePage(@RequestBody PlaceRequest placeRequest){
|
||||
Map<Long, List<DataPlace>> longListMap = placeService.showPlacePage(placeRequest);
|
||||
return Result.success(longListMap);
|
||||
Map<String, Object> stringObjectMap = placeService.showPlacePage(placeRequest);
|
||||
return Result.success(stringObjectMap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.etl.cleaning.controller;
|
||||
|
||||
import com.etl.cleaning.domian.pojo.DateType;
|
||||
import com.etl.cleaning.service.TypeService;
|
||||
import com.etl.common.result.Result;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
|
@ -9,11 +10,13 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/type")
|
||||
public class TypeController {
|
||||
private final TypeService typeService;
|
||||
|
||||
public TypeController(TypeService typeService) {
|
||||
this.typeService = typeService;
|
||||
}
|
||||
|
@ -24,7 +27,16 @@ public class TypeController {
|
|||
*/
|
||||
@GetMapping("/showTypeList")
|
||||
public Result showTypeList(){
|
||||
List<DataType> dataTypes = typeService.list();
|
||||
return Result.success(dataTypes);
|
||||
List<DateType> list = typeService.list();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试mysql链接
|
||||
* @return
|
||||
*/
|
||||
// @GetMapping("/testMysql")
|
||||
// public Result testMysql(){
|
||||
// ServerTest.testDatabaseConnection()
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.etl.cleaning.domian.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -44,4 +45,9 @@ public class DataPlace {
|
|||
* 链接状态
|
||||
*/
|
||||
private Boolean statue;
|
||||
/**
|
||||
* 连接类型
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String typeName;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.etl.cleaning.domian.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
@ -13,11 +15,12 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@TableName("date_type")
|
||||
@TableName("data_type")
|
||||
public class DateType {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
/**
|
||||
* 名称
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.etl.cleaning.enums;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 枚举常量类
|
||||
*/
|
||||
@Getter
|
||||
public enum EnumMsg {
|
||||
// 定义一个带有错误码和描述性字符串的枚举常量
|
||||
NO_TYPE(401, "暂无类型");
|
||||
|
||||
|
||||
private final int errorCode;
|
||||
private final String errorMessage;
|
||||
|
||||
private EnumMsg(int errorCode, String errorMessage) {
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package com.etl.cleaning.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import com.etl.cleaning.domian.pojo.DateType;
|
||||
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
public interface TypeMapper extends BaseMapper<DataType> {
|
||||
public interface TypeMapper extends BaseMapper<DateType> {
|
||||
}
|
||||
|
|
|
@ -1,26 +1,15 @@
|
|||
package com.etl.cleaning.controller;
|
||||
package com.etl.cleaning.server;
|
||||
|
||||
import com.etl.cleaning.config.DatabaseConfig;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 动态链接mysql数据源
|
||||
* 测试连接
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/data")
|
||||
public class DatabaseController {
|
||||
/**
|
||||
* jdbc连接
|
||||
* @param databaseConfig
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/test-database-connection")
|
||||
public String testDatabaseConnection(@RequestBody DatabaseConfig databaseConfig) {
|
||||
public class ServerTest {
|
||||
public static String testDatabaseConnection(@RequestBody DatabaseConfig databaseConfig) {
|
||||
try {
|
||||
//创建数据源
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
|
@ -32,7 +21,7 @@ public class DatabaseController {
|
|||
//创建数据源
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
//sql测试
|
||||
jdbcTemplate.execute("select * from user");
|
||||
jdbcTemplate.execute("select 1");
|
||||
return "ok";
|
||||
}catch (Exception e){
|
||||
//如果发生异常,打印异常信息
|
|
@ -11,5 +11,5 @@ import java.util.Map;
|
|||
* 数据源管理
|
||||
*/
|
||||
public interface PlaceService extends IService<DataPlace> {
|
||||
Map<Long,List<DataPlace>> showPlacePage(PlaceRequest placeRequest);
|
||||
Map<String,Object> showPlacePage(PlaceRequest placeRequest);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.etl.cleaning.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import com.etl.cleaning.domian.pojo.DateType;
|
||||
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
public interface TypeService extends IService<DataType> {
|
||||
public interface TypeService extends IService<DateType> {
|
||||
}
|
||||
|
|
|
@ -4,16 +4,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.etl.cleaning.domian.pojo.DataPlace;
|
||||
import com.etl.cleaning.domian.pojo.DateType;
|
||||
import com.etl.cleaning.domian.request.PlaceRequest;
|
||||
import com.etl.cleaning.enums.EnumMsg;
|
||||
import com.etl.cleaning.mapper.PlaceMapper;
|
||||
import com.etl.cleaning.service.PlaceService;
|
||||
import com.etl.cleaning.service.TypeService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据源管理
|
||||
|
@ -21,13 +24,15 @@ import java.util.Map;
|
|||
@Service
|
||||
public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implements PlaceService {
|
||||
|
||||
private final TypeService typeService;
|
||||
private final PlaceMapper placeMapper;
|
||||
public PlaceServiceImpl(PlaceMapper placeMapper) {
|
||||
public PlaceServiceImpl(TypeService typeService, PlaceMapper placeMapper) {
|
||||
this.typeService = typeService;
|
||||
this.placeMapper = placeMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long,List<DataPlace>> showPlacePage(PlaceRequest placeRequest) {
|
||||
public Map<String,Object> showPlacePage(PlaceRequest placeRequest) {
|
||||
LambdaQueryWrapper<DataPlace> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
if(StringUtils.isNotBlank(placeRequest.getBank())){
|
||||
lambdaQueryWrapper.like(DataPlace::getName, placeRequest.getBank());
|
||||
|
@ -38,6 +43,22 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
|
|||
Page<DataPlace> page = new Page<>(placeRequest.getPageNum(), placeRequest.getPageSize());
|
||||
Page<DataPlace> dataPlacePage = placeMapper.selectPage(page, lambdaQueryWrapper);
|
||||
List<DataPlace> records = dataPlacePage.getRecords();
|
||||
if(CollectionUtils.isEmpty(records)){
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<Long> typeIds = records.stream().map(DataPlace::getTypeId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
List<DateType> dateTypes = typeService.listByIds(typeIds);
|
||||
Map<Long, DateType> typeMap = dateTypes.stream().collect(Collectors.toMap(DateType::getId, Function.identity()));
|
||||
List<DataPlace> dataPlaceList = records.stream().map(item -> {
|
||||
Long typeId = item.getTypeId();
|
||||
DateType dateType = typeMap.get(typeId);
|
||||
if (dateType == null) {
|
||||
item.setTypeName(EnumMsg.NO_TYPE.getErrorMessage());
|
||||
}else{
|
||||
item.setTypeName(dateType.getName());
|
||||
}
|
||||
return item;
|
||||
}).collect(Collectors.toList());
|
||||
//查询总条数
|
||||
long total = dataPlacePage.getTotal();
|
||||
//查询当前页的总条数
|
||||
|
@ -50,8 +71,9 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
|
|||
System.out.println(size);
|
||||
System.out.println(pages);
|
||||
System.out.println(current);
|
||||
HashMap<Long, List<DataPlace>> map = new HashMap<>();
|
||||
map.put(total, records);
|
||||
HashMap<String,Object> map = new HashMap<>();
|
||||
map.put("total", total);
|
||||
map.put("data", dataPlaceList);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package com.etl.cleaning.serviceimpl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.etl.cleaning.domian.pojo.DateType;
|
||||
import com.etl.cleaning.mapper.TypeMapper;
|
||||
import com.etl.cleaning.service.TypeService;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
@Service
|
||||
public class TypeServiceImpl extends ServiceImpl<TypeMapper,DataType> implements TypeService {
|
||||
public class TypeServiceImpl extends ServiceImpl<TypeMapper, DateType> implements TypeService {
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
server.port=8080
|
||||
server.port=10001
|
||||
spring.redis.host=47.101.130.221
|
||||
spring.redis.port=6379
|
||||
spring.redis.password=123456
|
||||
|
|
Loading…
Reference in New Issue