1. AttachmentSDK 增加了新的数据模型
2. Seata starter 调整了 seata包版本, 修改了统一配置文件
This commit is contained in:
64
mall-ebtp-cloud-attachment-sdk/bin/pom.xml
Normal file
64
mall-ebtp-cloud-attachment-sdk/bin/pom.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-attachment-sdk</artifactId>
|
||||
<version>0.0.1</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-mvc-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nexus-aliyun</id>
|
||||
<name>Nexus aliyun</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>ettp-host-release</id>
|
||||
<name>Install to ettp center</name>
|
||||
<url>http://zentao.jlcucc.com:60000/repository/ettp-releases/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
# AutoConfiguration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.chinaunicom.ebtp.mall.cloud.attachment.sdk.config.SDKAutoConfiguration
|
@ -0,0 +1,2 @@
|
||||
ribbon.ReadTimeout=1800000
|
||||
ribbon.SocketTimeout=1800000
|
@ -6,6 +6,7 @@ import java.util.Optional;
|
||||
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.DownloadEntity;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.UploadObject;
|
||||
|
||||
/**
|
||||
@ -44,6 +45,14 @@ public interface AttachmentClient {
|
||||
*/
|
||||
Optional<byte[]> downloadFilesByBusinessId(String businessId);
|
||||
|
||||
/**
|
||||
* 下载业务ID下的所有资源
|
||||
*
|
||||
* @param bid
|
||||
* @return
|
||||
*/
|
||||
Optional<DownloadEntity> downloadOriginalFilesByBusinessId(String businessId);
|
||||
|
||||
/**
|
||||
* 下载指定的资源数据
|
||||
*
|
||||
@ -53,6 +62,14 @@ public interface AttachmentClient {
|
||||
*/
|
||||
Optional<byte[]> downloadFileByObjectId(String objectId);
|
||||
|
||||
/**
|
||||
* 下载指定的资源数据
|
||||
*
|
||||
* @param bid
|
||||
* @param oid
|
||||
* @return
|
||||
*/
|
||||
Optional<DownloadEntity> downloadOriginalFileByObjectId(String objectId);
|
||||
|
||||
/**
|
||||
* 上传资源文件
|
||||
@ -63,8 +80,6 @@ public interface AttachmentClient {
|
||||
*/
|
||||
Optional<UploadObject> upload(String businessId, File file);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传资源文件
|
||||
*
|
||||
@ -74,4 +89,18 @@ public interface AttachmentClient {
|
||||
*/
|
||||
Optional<UploadObject> upload(String businessId, String filename, byte[] array);
|
||||
|
||||
/**
|
||||
* 根据业务id删除附件
|
||||
*
|
||||
* @param businessId
|
||||
*/
|
||||
boolean deleteByBid(String businessId);
|
||||
|
||||
/**
|
||||
* 根据对象id删除附件
|
||||
*
|
||||
* @param objectId
|
||||
*/
|
||||
String deleteByOid(String objectId);
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@ -17,6 +18,7 @@ import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.convertor.FileConvertor;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.convertor.ModelConvertor;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.DownloadEntity;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.UploadObject;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.service.DocumentCenterService;
|
||||
|
||||
@ -42,6 +44,16 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
/* 文件转换器 */
|
||||
private @Autowired FileConvertor fileConvertor;
|
||||
|
||||
/**
|
||||
* 生成业务id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> getBusinessId() {
|
||||
return Optional.of(String.format("{\"id\":\"%s\"}", IdUtil.getSnowflake(23, 16).nextIdStr()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务id列表查询详单
|
||||
*
|
||||
@ -66,16 +78,6 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
return Optional.ofNullable(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成业务id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> getBusinessId() {
|
||||
return Optional.of(String.format("{\"id\":\"%s\"}", IdUtil.getSnowflake(23, 16).nextIdStr()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定Id文件的详细信息
|
||||
*
|
||||
@ -121,7 +123,7 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
try (ZipOutputStream zout = new ZipOutputStream(out)) {
|
||||
list.stream().forEach(data -> {
|
||||
try {
|
||||
zout.putNextEntry(new ZipEntry(data.getId() + data.getFilename()));// 文件项名称
|
||||
zout.putNextEntry(new ZipEntry(data.getFilename()));// 文件项名称
|
||||
zout.write(downloadFileByObjectId(data.getId()).get());// 文件数据流
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
@ -137,6 +139,45 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DownloadEntity> downloadOriginalFilesByBusinessId(String businessId) {
|
||||
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
||||
|
||||
if (op.isPresent()) {
|
||||
List<AttachmentEntity> list = op.get().get(businessId);
|
||||
|
||||
// 如果业务id下只包含单独一个文件,则直接返回该文件数据
|
||||
if (list.size() == 1) {
|
||||
return downloadOriginalFileByObjectId(list.get(0).getId());
|
||||
}
|
||||
// 如果大于1个则下载返回压缩包数据流
|
||||
else if (list.size() > 1) {
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
try (ZipOutputStream zout = new ZipOutputStream(out)) {
|
||||
list.stream().forEach(data -> {
|
||||
try {
|
||||
zout.putNextEntry(new ZipEntry(data.getFilename()));// 文件项名称
|
||||
zout.write(downloadFileByObjectId(data.getId()).get());// 文件数据流
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
return Optional.ofNullable(new DownloadEntity()
|
||||
.setFilename(String.format("%s.zip", UUID.randomUUID())).setStream(out.toByteArray()));
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DownloadEntity> downloadOriginalFileByObjectId(String objectId) {
|
||||
return modelConvertor.toDownloadEntity(documentCenterService.getObjectDetail(objectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
@ -150,7 +191,7 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
|
||||
log.debug(res);
|
||||
|
||||
return Optional.empty();
|
||||
return modelConvertor.toUploadObject(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -160,7 +201,31 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
|
||||
log.debug(res);
|
||||
|
||||
return Optional.empty();
|
||||
return modelConvertor.toUploadObject(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByBid(String businessId) {
|
||||
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
||||
|
||||
/*
|
||||
* AttachmentDetail 是一个Map类型对象, key 业务id, value: List<AttachmentEntity>
|
||||
*/
|
||||
op.ifPresent(attachmentDetail -> {
|
||||
attachmentDetail.keySet().stream().forEach(key -> {
|
||||
List<AttachmentEntity> list = attachmentDetail.get(key);
|
||||
|
||||
list.stream().forEach(attachmentEntity -> {
|
||||
documentCenterService.deleteByOid(attachmentEntity.getId());
|
||||
});
|
||||
});
|
||||
});
|
||||
return op.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deleteByOid(String objectId) {
|
||||
return documentCenterService.deleteByOid(objectId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class FeignSupportConfig {
|
||||
|
||||
}
|
@ -1,16 +1,23 @@
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.convertor;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.DownloadEntity;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.UploadObject;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.SysStorageVO;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.down.DownStream;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.down.SysStorageVO;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.query.QueryResult;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.upload.UploadStream;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.upload.UploadStreamData;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@ -39,7 +46,7 @@ public class ModelConvertor {
|
||||
AttachmentEntity entity = null;
|
||||
|
||||
try {
|
||||
SysStorageVO vo = toSysStorageVO(json);
|
||||
SysStorageVO vo = tpDownPO(json);
|
||||
log.debug("convert to model: {}", vo);
|
||||
|
||||
entity = new AttachmentEntity();
|
||||
@ -72,13 +79,36 @@ public class ModelConvertor {
|
||||
byte[] array = null;
|
||||
|
||||
try {
|
||||
array = toSysStorageVO(json).getFileStream();
|
||||
array = tpDownPO(json).getFileStream();
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return Optional.ofNullable(array);
|
||||
}
|
||||
|
||||
public Optional<DownloadEntity> toDownloadEntity(String json) {
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
try {
|
||||
SysStorageVO vo = tpDownPO(json);
|
||||
entity.setFilename(URLEncoder.DEFAULT.encode(vo.getOriginalName(), Charset.forName("UTF-8")))
|
||||
.setStream(vo.getFileStream());
|
||||
} catch (JsonMappingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Optional.ofNullable(entity);
|
||||
}
|
||||
|
||||
public Optional<UploadObject> toUploadObject(String json) {
|
||||
try {
|
||||
return Optional.ofNullable(new UploadObject().setId(toUploadPO(json).getFileId()));
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////// private
|
||||
/////////////////////////////////////////////////////////////////////////// method
|
||||
/**
|
||||
@ -89,9 +119,18 @@ public class ModelConvertor {
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
private SysStorageVO toSysStorageVO(String json) throws JsonMappingException, JsonProcessingException {
|
||||
private SysStorageVO tpDownPO(String json) throws JsonMappingException, JsonProcessingException {
|
||||
log.debug("current convertor json is: {}", json);
|
||||
return objectMapper.readValue(json, DownStream.class).getData().getSysStorageVO();
|
||||
}
|
||||
|
||||
private SysStorageVO toUploadPO(String json) throws JsonMappingException, JsonProcessingException {
|
||||
log.debug("current convertor json is: {}", json);
|
||||
List<UploadStreamData> list = objectMapper.readValue(json, UploadStream.class).getData();
|
||||
|
||||
if (list.size() > 0) {
|
||||
return list.get(0).getSysStorageVO();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -25,4 +25,9 @@ public class DocumentCenterServiceFallback implements DocumentCenterService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deleteByOid(String fileId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DownloadEntity {
|
||||
|
||||
private String filename;
|
||||
private byte[] stream;
|
||||
|
||||
}
|
@ -27,7 +27,7 @@ public interface DocumentCenterService {
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/downloadAllStream")
|
||||
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/downloadFileAllStream")
|
||||
String getObjectDetail(@RequestParam("fileId") String fileId);
|
||||
|
||||
/**
|
||||
@ -48,4 +48,13 @@ public interface DocumentCenterService {
|
||||
String upload(@RequestPart("appCode") String appCode, @RequestPart("objectId") String objectId,
|
||||
@RequestPart("multipartFiles") MultipartFile multipartFiles);
|
||||
|
||||
/**
|
||||
* 删除附件信息
|
||||
*
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/disk")
|
||||
String deleteByOid(@RequestParam("fileId") String fileId);
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.config.FeignSupportConfig;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.fallback.QueryServiceFallback;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
|
||||
@ -17,7 +18,7 @@ import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.FeedbackMessage;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.Snowflake;
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.param.QueryParameter;
|
||||
|
||||
@FeignClient(value = "core-service-ebtp-updownload", fallback = QueryServiceFallback.class)
|
||||
@FeignClient(value = "core-service-ebtp-updownload", configuration = FeignSupportConfig.class, fallback = QueryServiceFallback.class)
|
||||
public interface QueryService {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "v1/business/id")
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.down;
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.down;
|
||||
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.SysStorageVO;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.upload;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UploadStream {
|
||||
|
||||
private Integer code;
|
||||
private Boolean success;
|
||||
private String message;
|
||||
private List<UploadStreamData> data;
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.upload;
|
||||
|
||||
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.SysStorageVO;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UploadStreamData {
|
||||
|
||||
private SysStorageVO sysStorageVO;
|
||||
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
<commons-pool2.version>2.7.0</commons-pool2.version>
|
||||
<jedis.version>3.1.0</jedis.version>
|
||||
<redisson.version>3.11.4</redisson.version>
|
||||
<hutool-json.version>4.6.10</hutool-json.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -47,10 +46,5 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-json</artifactId>
|
||||
<version>${hutool-json.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -22,24 +22,8 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-jpa-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-seata</artifactId>
|
||||
<version>2.1.0.RELEASE</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>seata-all</artifactId>
|
||||
<groupId>io.seata</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-all</artifactId>
|
||||
<version>${seata.version}</version>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -31,7 +31,7 @@ transport {
|
||||
|
||||
service {
|
||||
#transaction service group mapping
|
||||
vgroupMapping.biz-service-ebtp-archive-fescar-service-group = "default"
|
||||
vgroupMapping.biz-service-ebtp-project-service-group = "default"
|
||||
#only support when registry.type=file, please don't set multiple addresses
|
||||
default.grouplist = "10.242.31.158:18035"
|
||||
#degrade, current not support
|
||||
@ -64,4 +64,9 @@ client {
|
||||
log {
|
||||
exceptionRate = 100
|
||||
}
|
||||
support {
|
||||
spring {
|
||||
datasource-autoproxy = true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
seata.enabled=true
|
||||
seata.application-id=${spring.application.name}
|
||||
seata.tx-service-group=${spring.application.name}-service-group
|
||||
seata.service.vgroup-mapping.eshop-service-group=default
|
||||
seata.service.grouplist.default=10.242.31.158:18035
|
||||
|
@ -0,0 +1,152 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.security.starter.entity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 缓存用户实体映射类
|
||||
*
|
||||
* @author daixc
|
||||
* @date 2020/10/16
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class SecurityUser {
|
||||
|
||||
/**
|
||||
* PKID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String lastName;
|
||||
/**
|
||||
* 姓氏
|
||||
*/
|
||||
private String firstName;
|
||||
/**
|
||||
* 全名
|
||||
*/
|
||||
private String fullName;
|
||||
|
||||
/**
|
||||
* 电子邮件
|
||||
*/
|
||||
private String emailAddress;
|
||||
//
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String loginName;
|
||||
//
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobilePhone;
|
||||
/**
|
||||
* 办公号
|
||||
*/
|
||||
private String officePhone;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 员工类别
|
||||
*/
|
||||
private String employeeCategory;
|
||||
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
private Date dateOfBirth;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
private Integer age;
|
||||
|
||||
/**
|
||||
* 员工编号
|
||||
*/
|
||||
private String employeeNumber;
|
||||
|
||||
/**
|
||||
* 国籍ID
|
||||
*/
|
||||
private String nationalityId;
|
||||
|
||||
/**
|
||||
* 国籍
|
||||
*/
|
||||
private String nationality;
|
||||
|
||||
/**
|
||||
* 身份证号码
|
||||
*/
|
||||
private String nationalIdentifier;
|
||||
|
||||
/**
|
||||
* 主管ID
|
||||
*/
|
||||
private Integer supervisorId;
|
||||
|
||||
/**
|
||||
* 组织ID
|
||||
*/
|
||||
private String organizationId;
|
||||
|
||||
/**
|
||||
* 组织名称
|
||||
*/
|
||||
private String organizationName;
|
||||
//
|
||||
/**
|
||||
* 组织机构类别
|
||||
*/
|
||||
private String orgCategory;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private String deptId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private String roleIds;
|
||||
|
||||
/**
|
||||
* 业务组id
|
||||
*/
|
||||
private Integer bussiGroupId;
|
||||
|
||||
/**
|
||||
* 职位ID
|
||||
*/
|
||||
private Integer positionId;
|
||||
|
||||
/**
|
||||
* 用户角色列表
|
||||
*/
|
||||
private List<AuthorityEntity> authorityList;
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
package com.chinaunicom.mall.ebtp.common.base;
|
@ -1,18 +1,18 @@
|
||||
package com.chinaunicom.mall.ebtp.common.base.service.impl;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
||||
import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 缓存用户service实现层 获取缓存用户信息
|
||||
*
|
||||
@ -28,19 +28,20 @@ public class BaseCacheUserServiceImpl implements IBaseCacheUserService {
|
||||
|
||||
private static final Map<String, BaseCacheUser> USERS = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public BaseCacheUser getCacheUser() {
|
||||
try {
|
||||
SecurityEntity securityEntity = (SecurityEntity) SecurityContextHolder.getContext().getAuthentication()
|
||||
.getPrincipal();
|
||||
|
||||
log.debug("Current user principal: " + securityEntity);
|
||||
|
||||
return convertToBusinessModel(securityEntity);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
BaseCacheUser user = null;
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
String token = request.getHeader("JwtToken");
|
||||
if (token != null) {
|
||||
user = USERS.get(token);
|
||||
}
|
||||
return new BaseCacheUser();
|
||||
}
|
||||
log.info(" --------------- 当前用户信息:" + JsonUtils.objectToJson(user) + " ------------------------------");
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,15 +50,53 @@ public class BaseCacheUserServiceImpl implements IBaseCacheUserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建用户对象模型
|
||||
*
|
||||
* @param rawObject
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
private BaseCacheUser convertToBusinessModel(SecurityEntity raw) {
|
||||
return new BaseCacheUser().setUserId(raw.getStaffId()).setFullName(raw.getStaffName())
|
||||
.setLoginName(raw.getUsername()).setRoleIds(raw.getStaffId()).setOrganizationId(raw.getOu())
|
||||
.setOrganizationName(raw.getOuName()).setAuthorityList(raw.getAuthorityList());
|
||||
// TODO: 山东框架使用未使用雪花ID存放字符串,暂时使用该方法进行id转换
|
||||
private Long getUserId(String rawUid) {
|
||||
long id = ID_SEED;
|
||||
byte[] bytes = rawUid.getBytes();
|
||||
|
||||
for (byte b : bytes) {
|
||||
id += b;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
static {
|
||||
BaseCacheUser user = new BaseCacheUser().setUserId("1").setFullName("采购经理").setLoginName("caigou")
|
||||
.setRoleIds("caigou").setOrganizationId("100").setOrganizationName("中国联通吉林分公司");
|
||||
USERS.put(String.valueOf(user.getUserId()), user);
|
||||
|
||||
BaseCacheUser user0 = new BaseCacheUser().setUserId("2").setFullName("代理机构管理员").setLoginName("daili-admin")
|
||||
.setRoleIds("daili-admin").setOrganizationId("100100").setOrganizationName("中兴代理公司");
|
||||
USERS.put(String.valueOf(user0.getUserId()), user0);
|
||||
|
||||
BaseCacheUser user1 = new BaseCacheUser().setUserId("3").setFullName("代理机构子管理员").setLoginName("daili-subadmin")
|
||||
.setRoleIds("daili-subadmin").setOrganizationId("100100").setOrganizationName("中兴代理公司");
|
||||
USERS.put(String.valueOf(user1.getUserId()), user1);
|
||||
|
||||
BaseCacheUser user2 = new BaseCacheUser().setUserId("4").setFullName("项目经理1").setLoginName("daili1")
|
||||
.setRoleIds("daili").setOrganizationId("100100").setOrganizationName("中兴代理公司");
|
||||
USERS.put(String.valueOf(user2.getUserId()), user2);
|
||||
|
||||
BaseCacheUser user3 = new BaseCacheUser().setUserId("5").setFullName("项目经理2").setLoginName("daili2")
|
||||
.setRoleIds("daili").setOrganizationId("100100").setOrganizationName("中兴代理公司");
|
||||
USERS.put(String.valueOf(user3.getUserId()), user3);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
BaseCacheUser user4 = new BaseCacheUser().setUserId(String.valueOf(6 + i)).setFullName("专家" + (i + 1))
|
||||
.setLoginName("1300000000" + (i + 1)).setRoleIds("zhuanjia").setOrganizationId("666")
|
||||
.setOrganizationName("专家公司");
|
||||
USERS.put(String.valueOf(user4.getUserId()), user4);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
BaseCacheUser user4 = new BaseCacheUser().setUserId(String.valueOf(11 + i)).setFullName("供应商" + (i + 1))
|
||||
.setLoginName("gys" + (i + 1)).setRoleIds("gys").setOrganizationId("200" + (i + 1))
|
||||
.setOrganizationName("供应商公司" + (i + 1));
|
||||
USERS.put(String.valueOf(user4.getUserId()), user4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
package com.chinaunicom.mall.ebtp.common.config;
|
||||
|
||||
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.AUTHORIZATION_HEADER;
|
||||
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.TOKEN_PREFIX;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
@ -18,22 +15,14 @@ import feign.RequestTemplate;
|
||||
@Configuration
|
||||
public class FeignConfig implements RequestInterceptor {
|
||||
|
||||
/**
|
||||
* @param template
|
||||
*/
|
||||
@Override
|
||||
public void apply(RequestTemplate template) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
|
||||
if (null != attributes) {
|
||||
final String header = attributes.getRequest().getHeader(AUTHORIZATION_HEADER);// 提取request头信息
|
||||
|
||||
// 检查请求头是否包含 Bearer 前缀
|
||||
if (StringUtils.startsWith(header, TOKEN_PREFIX)) {
|
||||
String authToken = RegExUtils.replaceAll(header, TOKEN_PREFIX, "");// 提取 token 信息
|
||||
|
||||
template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, authToken));
|
||||
}
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
String token = request.getHeader("JwtToken");
|
||||
template.header("JwtToken", token);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,66 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = true
|
||||
# the client batch send request enable
|
||||
enableClientBatchSendRequest = true
|
||||
#thread factory for netty
|
||||
threadFactory {
|
||||
bossThreadPrefix = "NettyBoss"
|
||||
workerThreadPrefix = "NettyServerNIOWorker"
|
||||
serverExecutorThread-prefix = "NettyServerBizHandler"
|
||||
shareBossWorker = false
|
||||
clientSelectorThreadPrefix = "NettyClientSelector"
|
||||
clientSelectorThreadSize = 1
|
||||
clientWorkerThreadPrefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
bossThreadSize = 1
|
||||
#auto default pin or 8
|
||||
workerThreadSize = "default"
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#transaction service group mapping
|
||||
vgroupMapping.uboot-core-fescar-service-group = "default"
|
||||
#only support when registry.type=file, please don't set multiple addresses
|
||||
default.grouplist = "127.0.0.1:8091"
|
||||
#degrade, current not support
|
||||
enableDegrade = false
|
||||
#disable seata
|
||||
disableGlobalTransaction = false
|
||||
}
|
||||
|
||||
client {
|
||||
rm {
|
||||
asyncCommitBufferLimit = 10000
|
||||
lock {
|
||||
retryInterval = 10
|
||||
retryTimes = 30
|
||||
retryPolicyBranchRollbackOnConflict = true
|
||||
}
|
||||
reportRetryCount = 5
|
||||
tableMetaCheckEnable = false
|
||||
reportSuccessEnable = false
|
||||
}
|
||||
tm {
|
||||
commitRetryCount = 5
|
||||
rollbackRetryCount = 5
|
||||
}
|
||||
undo {
|
||||
dataValidation = true
|
||||
logSerialization = "jackson"
|
||||
logTable = "undo_log"
|
||||
}
|
||||
log {
|
||||
exceptionRate = 100
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
## ---------------------------------------------------------------------------
|
||||
## Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
## contributor license agreements. See the NOTICE file distributed with
|
||||
## this work for additional information regarding copyright ownership.
|
||||
## The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
## (the "License"); you may not use this file except in compliance with
|
||||
## the License. You may obtain a copy of the License at
|
||||
##
|
||||
## http://www.apache.org/licenses/LICENSE-2.0
|
||||
##
|
||||
## Unless required by applicable law or agreed to in writing, software
|
||||
## distributed under the License is distributed on an "AS IS" BASIS,
|
||||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
## See the License for the specific language governing permissions and
|
||||
## limitations under the License.
|
||||
## ---------------------------------------------------------------------------
|
||||
|
||||
client {
|
||||
application.id = uboot-core
|
||||
transaction.service.group = uboot-core-fescar-service-group
|
||||
}
|
Reference in New Issue
Block a user