Commit b307b1c9 by ljb

数据汇聚接口拆分

parent e8c7a7bc
package com.zq.datacollect.controller; package com.zq.datacollect.controller;
import com.zq.common.exception.BusinessException;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.datacollect.service.DataCollectService; import com.zq.datacollect.service.DataCollectService;
...@@ -8,10 +7,8 @@ import com.zq.datacollect.vo.*; ...@@ -8,10 +7,8 @@ import com.zq.datacollect.vo.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.List; import java.util.List;
...@@ -26,71 +23,18 @@ public class DataCollectController { ...@@ -26,71 +23,18 @@ public class DataCollectController {
@ApiOperation("分页获取数据汇聚任务列表") @ApiOperation("分页获取数据汇聚任务列表")
@PostMapping(value = "/list") @PostMapping(value = "/list")
public ResultVo getList(@RequestBody DataCollectReq req) { public ResultVo list(@RequestBody DataCollectReq req) {
return ResultVo.success(dataCollectService.getList(req)); return ResultVo.success(dataCollectService.list(req));
} }
@ApiOperation("根据ID获取数据汇聚任务") // @ApiOperation("修改数据汇聚设置")
@GetMapping(value = "/get/{id}") // @PutMapping(value = "/update")
public ResultVo get(@PathVariable Integer id) { // public ResultVo update(@RequestBody DataCollectSettingAddReq dataCollectSettingAddReq) {
return ResultVo.success(dataCollectService.get(id)); // AssertUtils.notNull(dataCollectSettingAddReq.getId(), "修改失败,id不能为空");
} // dataCollectService.update(dataCollectSettingAddReq);
// return ResultVo.success("修改成功");
// @ApiOperation("新增数据汇聚设置")
// @PostMapping(value = "/add")
// public ResultVo add(@RequestBody DataCollectSettingAddReq dataCollectSettingAddReq) {
// switch (dataCollectSettingAddReq.getDataType()){
// case 1:
// dataCollectService.addDbSetting(dataCollectSettingAddReq);
// break;
// case 2:
// break;
// case 3:
// break;
// case 4:
// break;
// default:
// throw new BusinessException("汇聚类型错误");
// }
// return ResultVo.success("添加成功");
// } // }
@ApiOperation("新增数据库数据汇聚设置")
@PostMapping(value = "/add/db")
public ResultVo addDbSetting(@RequestBody DataCollectDbAddReq dataCollectDbAddReq) {
dataCollectService.addDbSetting(dataCollectDbAddReq);
return ResultVo.success("添加成功");
}
@ApiOperation("新增文件数据汇聚设置")
@PostMapping(value = "/add/file")
public ResultVo addFileSetting(@RequestBody DataCollectFileAddReq dataCollectFileAddReq) {
dataCollectService.addFileSetting(dataCollectFileAddReq);
return ResultVo.success("添加成功");
}
@ApiOperation("新增接口数据汇聚设置")
@PostMapping(value = "/add/api")
public ResultVo addApiSetting(@RequestBody DataCollectApiAddReq dataCollectApiAddReq) {
dataCollectService.addApiSetting(dataCollectApiAddReq);
return ResultVo.success("添加成功");
}
@ApiOperation("新增网站数据汇聚设置")
@PostMapping(value = "/add/site")
public ResultVo addSiteSetting(@RequestBody DataCollectSiteAddReq dataCollectSiteAddReq) {
dataCollectService.addSiteSetting(dataCollectSiteAddReq);
return ResultVo.success("添加成功");
}
@ApiOperation("修改数据汇聚设置")
@PutMapping(value = "/update")
public ResultVo update(@RequestBody DataCollectSettingAddReq dataCollectSettingAddReq) {
AssertUtils.notNull(dataCollectSettingAddReq.getId(), "修改失败,id不能为空");
dataCollectService.update(dataCollectSettingAddReq);
return ResultVo.success("修改成功");
}
@ApiOperation("删除数据汇聚设置") @ApiOperation("删除数据汇聚设置")
@DeleteMapping(value = "/delete/{id}") @DeleteMapping(value = "/delete/{id}")
public ResultVo delete(@PathVariable Integer id) { public ResultVo delete(@PathVariable Integer id) {
...@@ -104,10 +48,4 @@ public class DataCollectController { ...@@ -104,10 +48,4 @@ public class DataCollectController {
dataCollectService.batchDelete(ids); dataCollectService.batchDelete(ids);
return ResultVo.success("操作成功"); return ResultVo.success("操作成功");
} }
@ApiOperation("解析Excel文件")
@PostMapping(value = "/analysis/excel")
public ResultVo analysisExcel(MultipartFile file) throws IOException {
return ResultVo.success(dataCollectService.analysisExcel(file));
}
} }
\ No newline at end of file
...@@ -3,33 +3,16 @@ package com.zq.datacollect.service; ...@@ -3,33 +3,16 @@ package com.zq.datacollect.service;
import com.zq.common.vo.PageVo; import com.zq.common.vo.PageVo;
import com.zq.datacollect.entity.DataCollectSetting; import com.zq.datacollect.entity.DataCollectSetting;
import com.zq.datacollect.vo.*; import com.zq.datacollect.vo.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map;
public interface DataCollectService { public interface DataCollectService {
PageVo<DataCollectSetting> getList(DataCollectReq req); PageVo<DataCollectSetting> list(DataCollectReq req);
DataCollectSettingResp get(Integer id); // void update(DataCollectSettingAddReq dataCollectSettingAddReq);
// void add(DataCollectSettingAddReq dataCollectSettingAddReq);
void addDbSetting(DataCollectDbAddReq dataCollectDbAddReq);
void addFileSetting(DataCollectFileAddReq dataCollectFileAddReq);
void addApiSetting(DataCollectApiAddReq dataCollectApiAddReq);
void addSiteSetting(DataCollectSiteAddReq dataCollectSiteAddReq);
void update(DataCollectSettingAddReq dataCollectSettingAddReq);
void delete(Integer id); void delete(Integer id);
void batchDelete(List<Integer> ids); void batchDelete(List<Integer> ids);
List<Map<String, Object>> analysisExcel(MultipartFile multipartFile) throws IOException;
} }
package com.zq.datacollect.service.impl; package com.zq.datacollect.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.common.exception.BusinessException; import com.zq.common.exception.BusinessException;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.utils.EasyExcelUtil;
import com.zq.common.utils.PagingUtils; import com.zq.common.utils.PagingUtils;
import com.zq.common.vo.PageVo; import com.zq.common.vo.PageVo;
import com.zq.datacollect.entity.*; import com.zq.datacollect.entity.*;
...@@ -20,10 +16,8 @@ import lombok.RequiredArgsConstructor; ...@@ -20,10 +16,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.*; import java.util.*;
@Slf4j @Slf4j
...@@ -49,123 +43,26 @@ public class DataCollectServiceImpl extends ServiceImpl<DataCollectMapper, DataC ...@@ -49,123 +43,26 @@ public class DataCollectServiceImpl extends ServiceImpl<DataCollectMapper, DataC
@Resource @Resource
private DataCollectSettingApiParaMapper dataCollectSettingApiParaMapper; private DataCollectSettingApiParaMapper dataCollectSettingApiParaMapper;
@Resource
private QueryDbMapper queryDbMapper;
@Override
public PageVo<DataCollectSetting> getList(DataCollectReq req) {
return PagingUtils.paging(req, dataCollectMapper, new LambdaQueryWrapper<>(), DataCollectSetting.class);
}
@Override @Override
public DataCollectSettingResp get(Integer id){ public PageVo<DataCollectSetting> list(DataCollectReq req) {
DataCollectSetting dataCollectSetting = getById(id); return PagingUtils.paging(req, dataCollectMapper, new LambdaQueryWrapper<DataCollectSetting>().orderByDesc(DataCollectSetting::getId), DataCollectSetting.class);
DataCollectSettingResp resp = new DataCollectSettingResp();
BeanUtil.copyProperties(dataCollectSetting, resp);
if(dataCollectSetting.getDataType() != 3){
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("data_collect_setting_id", resp.getId());
List list = getDao(dataCollectSetting.getDataType()).selectList(wrapper);
resp.setDataFromSetting(list);
}else {
List<DataCollectSettingApi> apis = dataCollectSettingApiMapper.selectList(new LambdaQueryWrapper<DataCollectSettingApi>().eq(DataCollectSettingApi::getDataCollectSettingId, dataCollectSetting.getId()));
List<DataCollectSettingApiAddReq> vos = BeanUtil.copyToList(apis, DataCollectSettingApiAddReq.class);
for (DataCollectSettingApiAddReq vo : vos) {
List<DataCollectSettingApiPara> apiParas = dataCollectSettingApiParaMapper.selectList(new LambdaQueryWrapper<DataCollectSettingApiPara>().eq(DataCollectSettingApiPara::getDataCollectSettingApiId, vo.getId()));
vo.setApiParas(apiParas);
}
resp.setDataFromSetting(vos);
}
return resp;
} }
// @Override // @Override
// @Transactional // @Transactional
// public void add(DataCollectSettingAddReq dataCollectSettingAddReq){ // public void update(DataCollectSettingAddReq dataCollectSettingAddReq){
// boolean b = save(dataCollectSettingAddReq); // DataCollectSetting dataCollectSetting = getById(dataCollectSettingAddReq.getId());
// AssertUtils.isTrue(b, "添加失败"); // AssertUtils.isTrue(dataCollectSetting.getDataType()==dataCollectSettingAddReq.getDataType(), "修改失败,数据来源不允许修改");
// if(dataCollectSettingAddReq.getDataType() != 3){ // Object dataFromSetting = dataCollectSettingAddReq.getDataFromSetting();
// HashMap<String, Object> map = new HashMap(); // if(null != dataFromSetting){
// BeanUtil.copyProperties(dataCollectSettingAddReq.getDataFromSetting(), map); // UpdateWrapper wrapper = new UpdateWrapper();
// if(dataCollectSettingAddReq.getDataType() == 1){ // wrapper.eq("data_collect_setting_id", dataCollectSetting.getId());
// QueryDb db = queryDbMapper.selectById((Integer) map.get("databaseId")); // getDao(dataCollectSetting.getDataType()).update(dataFromSetting, wrapper);
// map.put("dbName", db.getDbName());
// map.put("dbIp", db.getDbIp());
// map.put("dbPort", db.getDbPort());
// map.put("username", db.getUsername());
// map.put("password", db.getPassword());
// map.put("dbType", db.getDbType());
// map.remove("databaseId");
// }
// map.put("dataCollectSettingId", dataCollectSettingAddReq.getId());
// AssertUtils.isTrue(getDao(dataCollectSettingAddReq.getDataType()).insert(map)==1, "添加失败");
// }else {
// DataCollectSettingApiAddReq apiAddReq = new DataCollectSettingApiAddReq();
// BeanUtil.copyProperties(dataCollectSettingAddReq.getDataFromSetting(), apiAddReq);
// apiAddReq.setDataCollectSettingId(dataCollectSettingAddReq.getId());
// AssertUtils.isTrue(dataCollectSettingApiMapper.insert(apiAddReq)==1, "添加失败");
// for (DataCollectSettingApiPara apiPara : apiAddReq.getApiParas()) {
// apiPara.setDataCollectSettingApiId(apiAddReq.getId());
// AssertUtils.isTrue(dataCollectSettingApiParaMapper.insert(apiPara)==1, "添加失败");
// }
// } // }
// AssertUtils.isTrue(updateById(dataCollectSettingAddReq), "修改失败");
// } // }
@Override @Override
@Transactional
public void addDbSetting(DataCollectDbAddReq dataCollectDbAddReq) {
AssertUtils.isTrue(save(dataCollectDbAddReq.getDataCollectSetting()), "添加失败");
DataCollectSettingDb settingDb = dataCollectDbAddReq.getDataCollectSettingDb();
settingDb.setDataCollectSettingId(dataCollectDbAddReq.getDataCollectSetting().getId());
AssertUtils.isTrue(dataCollectSettingDbMapper.insert(settingDb)==1, "添加失败");
}
@Override
@Transactional
public void addFileSetting(DataCollectFileAddReq dataCollectFileAddReq) {
AssertUtils.isTrue(save(dataCollectFileAddReq.getDataCollectSetting()), "添加失败");
DataCollectSettingFile settingFile = dataCollectFileAddReq.getDataCollectSettingFile();
settingFile.setDataCollectSettingId(dataCollectFileAddReq.getDataCollectSetting().getId());
AssertUtils.isTrue(dataCollectSettingFileMapper.insert(settingFile)==1, "添加失败");
}
@Override
@Transactional
public void addApiSetting(DataCollectApiAddReq dataCollectApiAddReq) {
AssertUtils.isTrue(save(dataCollectApiAddReq.getDataCollectSetting()), "添加失败");
DataCollectSettingApi settingApi = dataCollectApiAddReq.getDataCollectSettingApi();
settingApi.setDataCollectSettingId(dataCollectApiAddReq.getDataCollectSetting().getId());
AssertUtils.isTrue(dataCollectSettingApiMapper.insert(settingApi)==1, "添加失败");
for (DataCollectSettingApiPara settingApiPara : dataCollectApiAddReq.getDataCollectSettingApiParas()) {
settingApiPara.setDataCollectSettingApiId(settingApi.getId());
AssertUtils.isTrue(dataCollectSettingApiParaMapper.insert(settingApiPara)==1, "添加失败");
}
}
@Override
@Transactional
public void addSiteSetting(DataCollectSiteAddReq dataCollectSiteAddReq) {
AssertUtils.isTrue(save(dataCollectSiteAddReq.getDataCollectSetting()), "添加失败");
DataCollectSettingSite settingSite = dataCollectSiteAddReq.getDataCollectSettingSite();
settingSite.setDataCollectSettingId(dataCollectSiteAddReq.getDataCollectSetting().getId());
AssertUtils.isTrue(dataCollectSettingSiteMapper.insert(settingSite)==1, "添加失败");
}
@Override
@Transactional
public void update(DataCollectSettingAddReq dataCollectSettingAddReq){
DataCollectSetting dataCollectSetting = getById(dataCollectSettingAddReq.getId());
AssertUtils.isTrue(dataCollectSetting.getDataType()==dataCollectSettingAddReq.getDataType(), "修改失败,数据来源不允许修改");
Object dataFromSetting = dataCollectSettingAddReq.getDataFromSetting();
if(null != dataFromSetting){
UpdateWrapper wrapper = new UpdateWrapper();
wrapper.eq("data_collect_setting_id", dataCollectSetting.getId());
getDao(dataCollectSetting.getDataType()).update(dataFromSetting, wrapper);
}
AssertUtils.isTrue(updateById(dataCollectSettingAddReq), "修改失败");
}
@Override
public void delete(Integer id){ public void delete(Integer id){
DataCollectSetting dataCollectSetting = getById(id); DataCollectSetting dataCollectSetting = getById(id);
UpdateWrapper wrapper = new UpdateWrapper(); UpdateWrapper wrapper = new UpdateWrapper();
...@@ -182,13 +79,6 @@ public class DataCollectServiceImpl extends ServiceImpl<DataCollectMapper, DataC ...@@ -182,13 +79,6 @@ public class DataCollectServiceImpl extends ServiceImpl<DataCollectMapper, DataC
} }
} }
@Override
public List<Map<String, Object>> analysisExcel(MultipartFile file) throws IOException {
String suffix = FileUtil.extName(file.getOriginalFilename());
AssertUtils.isTrue(suffix.equals("xls") || suffix.equals("xlsx") || suffix.equals("et"), "不支持的文件类型");
return EasyExcelUtil.read(file.getInputStream());
}
public BaseMapper getDao(int dataType){ public BaseMapper getDao(int dataType){
switch (dataType) { switch (dataType) {
case 1: case 1:
......
...@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor; ...@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class DataCollectReq extends PageReqVo { public class DataCollectReq extends PageReqVo {
/** /**
* 数据类型 * 数据类型
* 1.数据库 2.文件 3.接口 4网站 * 1.数据库 2.文件 3.接口 4网站
...@@ -32,6 +33,12 @@ public class DataCollectReq extends PageReqVo { ...@@ -32,6 +33,12 @@ public class DataCollectReq extends PageReqVo {
private Boolean isManually; private Boolean isManually;
/** /**
* 汇聚到的数据库名
* 如果是非结构化文件,可以不存入数据表
*/
private Integer toDbId;
/**
* 汇聚到的数据表名 * 汇聚到的数据表名
* 如果是非结构化文件,可以不存入数据表 * 如果是非结构化文件,可以不存入数据表
*/ */
...@@ -47,7 +54,7 @@ public class DataCollectReq extends PageReqVo { ...@@ -47,7 +54,7 @@ public class DataCollectReq extends PageReqVo {
* id * id
*/ */
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Integer id;
/** /**
* 执行计划的corn表达式 * 执行计划的corn表达式
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment