新增更新包识别

segment2.0
linrf 2 years ago
parent c83101bfdf
commit ab9ea38e0a

@ -10,6 +10,7 @@ import com.docus.server.dto.scheduling.management.schcollector.DeleteSchCollecto
import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO;
import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO;
import com.docus.server.service.ISchCollectorService; import com.docus.server.service.ISchCollectorService;
import com.docus.server.vo.scheduling.management.schcollector.LoadSchCollectorVO;
import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO; import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -28,7 +29,7 @@ public class SchCollectorController implements SchCollectorApi {
private ISchCollectorService iSchCollectorService; private ISchCollectorService iSchCollectorService;
@Override @Override
public List<SchCollectorVO> findAll() { public List<LoadSchCollectorVO> findAll() {
return iSchCollectorService.findAll(); return iSchCollectorService.findAll();
} }

@ -7,6 +7,7 @@ import com.docus.server.dto.scheduling.management.schcollector.DeleteSchCollecto
import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO;
import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO;
import com.docus.server.entity.scheduling.management.SchCollector; import com.docus.server.entity.scheduling.management.SchCollector;
import com.docus.server.vo.scheduling.management.schcollector.LoadSchCollectorVO;
import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO; import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO;
import java.util.List; import java.util.List;
@ -67,6 +68,6 @@ public interface ISchCollectorService {
SchCollector findByCollectorId(String collectorId); SchCollector findByCollectorId(String collectorId);
List<SchCollectorVO> findAll(); List<LoadSchCollectorVO> findAll();
} }

@ -16,19 +16,28 @@ import com.docus.server.dto.scheduling.management.schcollector.DeleteSchCollecto
import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO;
import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO;
import com.docus.server.entity.scheduling.management.SchCollector; import com.docus.server.entity.scheduling.management.SchCollector;
import com.docus.server.entity.scheduling.management.SchCollectorVersion;
import com.docus.server.entity.scheduling.management.SchCollectorVersionFile;
import com.docus.server.entity.scheduling.management.SchSystemParams; import com.docus.server.entity.scheduling.management.SchSystemParams;
import com.docus.server.infrastructure.dao.ISchCollectorDao; import com.docus.server.infrastructure.dao.ISchCollectorDao;
import com.docus.server.infrastructure.dao.ISchCollectorVersionDao;
import com.docus.server.infrastructure.dao.ISchCollectorVersionFileDao;
import com.docus.server.service.ISchCollectorService; import com.docus.server.service.ISchCollectorService;
import com.docus.server.service.ISchSystemParamsService; import com.docus.server.service.ISchSystemParamsService;
import com.docus.server.vo.scheduling.management.schcollector.LoadSchCollectorVO;
import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO; import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO;
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.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* *
@ -41,6 +50,10 @@ public class SchCollectorServiceImpl implements ISchCollectorService {
@Resource @Resource
private ISchCollectorDao iSchCollectorDao; private ISchCollectorDao iSchCollectorDao;
@Resource @Resource
private ISchCollectorVersionDao iSchCollectorVersionDao;
@Resource
private ISchCollectorVersionFileDao iSchCollectorVersionFileDao;
@Resource
private ISchSystemParamsService iSchSystemParamsService; private ISchSystemParamsService iSchSystemParamsService;
@Resource @Resource
private IdService idService; private IdService idService;
@ -102,9 +115,66 @@ public class SchCollectorServiceImpl implements ISchCollectorService {
} }
@Override @Override
public List<SchCollectorVO> findAll() { public List<LoadSchCollectorVO> findAll() {
List<SchCollector> schCollectors = iSchCollectorDao.findAll(); List<SchCollector> schCollectors = iSchCollectorDao.findAll();
return SchCollectorConvert.INSTANCE.convertVO(schCollectors);
List<SchCollectorVersion> schCollectorVersionList = iSchCollectorVersionDao.findAll();
List<SchCollectorVersionFile> schCollectorVersionFileList = iSchCollectorVersionFileDao.findAll();
List<SchCollector> notEmptyVersionCollectors = schCollectors.stream().filter(p -> Func.isNotEmpty(p.getCollectorVersionId())).collect(Collectors.toList());
List<SchCollector> emptyVersionCollectors = schCollectors.stream().filter(p -> Func.isEmpty(p.getCollectorVersionId())).collect(Collectors.toList());
Map<String, SchCollectorVersionFile> stringSchCollectorVersionFileMap = ListUtils.toMap(schCollectorVersionFileList, schCollectorVersionFile -> String.format("%s%s", schCollectorVersionFile.getCollectorId(), schCollectorVersionFile.getCollectorVersionId()));
List<LoadSchCollectorVO> loadSchCollectorVOList = new ArrayList<>();
for (SchCollector schCollector : notEmptyVersionCollectors) {
String key = String.format("%s%s", schCollector.getCollectorId(), schCollector.getCollectorVersionId());
if (stringSchCollectorVersionFileMap.containsKey(key)) {
LoadSchCollectorVO loadSchCollectorVO = new LoadSchCollectorVO();
SchCollectorVersionFile schCollectorVersionFile = stringSchCollectorVersionFileMap.get(key);
loadSchCollectorVO.setCollectorId(schCollector.getCollectorId());
loadSchCollectorVO.setCollectorVersionId(schCollectorVersionFile.getCollectorVersionId());
loadSchCollectorVO.setFilePath(schCollectorVersionFile.getFilePath());
loadSchCollectorVO.setDeployPath(schCollectorVersionFile.getDeployPath());
loadSchCollectorVO.setProcessName(schCollectorVersionFile.getProcessName());
loadSchCollectorVOList.add(loadSchCollectorVO);
}
}
Map<Long, Optional<SchCollectorVersion>> collectorVersionMap = schCollectorVersionList.stream().collect(Collectors.groupingBy(SchCollectorVersion::getCollectorId, Collectors.maxBy(Comparator.comparing(SchCollectorVersion::getCollectVersion))));
for (SchCollector schCollector : emptyVersionCollectors) {
Long key = schCollector.getCollectorId();
if (collectorVersionMap.containsKey(key)) {
SchCollectorVersion schCollectorVersion = collectorVersionMap.get(key).get();
String versionKey = String.format("%s%s", schCollectorVersion.getCollectorId(), schCollectorVersion.getId());
if (stringSchCollectorVersionFileMap.containsKey(versionKey)) {
LoadSchCollectorVO loadSchCollectorVO = new LoadSchCollectorVO();
SchCollectorVersionFile schCollectorVersionFile = stringSchCollectorVersionFileMap.get(versionKey);
loadSchCollectorVO.setCollectorId(schCollector.getCollectorId());
loadSchCollectorVO.setCollectorVersionId(schCollectorVersionFile.getCollectorVersionId());
loadSchCollectorVO.setFilePath(schCollectorVersionFile.getFilePath());
loadSchCollectorVO.setDeployPath(schCollectorVersionFile.getDeployPath());
loadSchCollectorVO.setProcessName(schCollectorVersionFile.getProcessName());
loadSchCollectorVOList.add(loadSchCollectorVO);
}
}
}
return loadSchCollectorVOList;
} }
/** /**

@ -1,8 +1,9 @@
package com.docus.server.common; package com.docus.server.common;
import com.docus.server.api.scheduling.management.SchCollectorApi; import com.docus.server.api.scheduling.management.SchCollectorApi;
import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO; import com.docus.server.vo.scheduling.management.schcollector.LoadSchCollectorVO;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -10,16 +11,16 @@ import java.util.List;
/** /**
* load collector package and config * load collector package and config
*/ */
@Component
public class LoadPackageCommandLineRunner implements CommandLineRunner { public class LoadPackageCommandLineRunner implements CommandLineRunner {
@Resource @Resource
private SchCollectorApi schCollectorApi; private SchCollectorApi schCollectorApi;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
List<SchCollectorVO> schCollectorVOList = schCollectorApi.findAll(); List<LoadSchCollectorVO> loadSchCollectorVOList = schCollectorApi.findAll();
System.out.println(loadSchCollectorVOList);
} }
} }

@ -0,0 +1,51 @@
package com.docus.server.common.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.docus.infrastructure.web.exception.ApiException;
import feign.FeignException;
import feign.Response;
import feign.Util;
import feign.codec.Decoder;
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.util.Objects;
//feign处理统一输出和异常
public class FeignResponseDecoder extends ResponseEntityDecoder {
public FeignResponseDecoder(Decoder decoder) {
super(decoder);
}
@Override
public Object decode(Response response, Type type) throws IOException, FeignException {
String body;
//response. body默认是InputStreamBody , 加了Feign 1og之后转为ByteArrayBody
if (response.body().length() == null && response.body().asInputStream().available() == 0) {
byte[] bodyData = Util.toByteArray(response.body().asInputStream());
body = new String(bodyData);
} else {
body = response.body().toString();
}
if (!StringUtils.isEmpty(body)) {
JSONObject responseobject = JSON.parseObject(body);
if (responseobject.containsKey("code")) {
Integer code = responseobject.getInteger("code");
if (!Objects.equals(0, code)) {
String message = responseobject.getString("msg");
throw new ApiException(code, message);
}
String result = responseobject.getString("data");
if (result == null || "null".equalsIgnoreCase(result)) {
return null;
}
response = response.toBuilder().body(result, Charset.forName("UTF-8")).build();
}
}
return super.decode(response, type);
}
}

@ -0,0 +1,26 @@
package com.docus.server.common.config;
import feign.codec.Decoder;
import feign.optionals.OptionalDecoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringCloudConfig {
@Autowired(required = false)
private ObjectFactory<HttpMessageConverters> messageConverters;
//feign统一输出体响应拦截
@ConditionalOnMissingBean(value = Decoder.class)
@Bean
public Decoder feignResponseDecoder() {
return new OptionalDecoder(
new FeignResponseDecoder(new SpringDecoder(this.messageConverters)));
}
}

@ -6,6 +6,7 @@ import com.docus.server.dto.scheduling.management.schcollector.AddSchCollectorDT
import com.docus.server.dto.scheduling.management.schcollector.DeleteSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.DeleteSchCollectorDTO;
import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.EditSchCollectorDTO;
import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO; import com.docus.server.dto.scheduling.management.schcollector.UpdateSchCollectorDTO;
import com.docus.server.vo.scheduling.management.schcollector.LoadSchCollectorVO;
import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO; import com.docus.server.vo.scheduling.management.schcollector.SchCollectorVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -38,7 +39,7 @@ public interface SchCollectorApi {
*/ */
@ApiOperation("查询全部") @ApiOperation("查询全部")
@GetMapping("/find/all") @GetMapping("/find/all")
List<SchCollectorVO> findAll(); List<LoadSchCollectorVO> findAll();
/** /**
* *

@ -58,6 +58,14 @@ public class SchCollectorVersionFile implements Serializable {
@TableField("file_type") @TableField("file_type")
private String fileType; private String fileType;
@ApiModelProperty(value = "采集器部署路径")
@TableField("deploy_path")
private String deployPath;
@ApiModelProperty(value = "采集器进程名称")
@TableField("process_name")
private String processName;
@ApiModelProperty(value = "是否作废 10否") @ApiModelProperty(value = "是否作废 10否")
@TableField("state") @TableField("state")
private CancelEnum state; private CancelEnum state;

@ -0,0 +1,38 @@
package com.docus.server.vo.scheduling.management.schcollector;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* LoadSchCollectorVO VO
*
* @author AutoGenerator
* @since 2023-07-15
*/
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "LoadSchCollectorVO", description = "LoadSchCollectorVO")
public class LoadSchCollectorVO {
@ApiModelProperty(value = "采集器id")
private Long collectorId;
@ApiModelProperty(value = "采集器版本id")
private Long collectorVersionId;
@ApiModelProperty(value = "文件目录 单纯文件夹路径不带文件名F:\\嘉时\\新建文件夹\\")
private String filePath;
@ApiModelProperty(value = "采集器部署路径")
private String deployPath;
@ApiModelProperty(value = "采集器进程名称")
private String processName;
}

@ -43,6 +43,12 @@ public class SchCollectorVersionFileVO implements Serializable {
@ApiModelProperty(value = "文件类型") @ApiModelProperty(value = "文件类型")
private String fileType; private String fileType;
@ApiModelProperty(value = "采集器部署路径")
private String deployPath;
@ApiModelProperty(value = "采集器进程名称")
private String processName;
@ApiModelProperty(value = "是否作废 10否") @ApiModelProperty(value = "是否作废 10否")
private CancelEnum state; private CancelEnum state;

Loading…
Cancel
Save