Commit 967a2382 by aye

代码提交

parent 9383e24a
......@@ -41,6 +41,11 @@
<artifactId>hibernate-core</artifactId>
<version>5.3.10.Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
......
......@@ -54,6 +54,7 @@
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.1" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.4.Final" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-test:2.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.0.6.RELEASE" level="project" />
......
package com.jty.wsxt.application;
import com.jty.wsxt.application.feign.UserFeign;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* 应用Service组件注册
*
* @author Manjiajie
* @since 2019-6-21 09:39:08
*/
@Component
public class ApplicationRegistry implements ApplicationContextAware {
private static ApplicationContext applicationContext;
public static UserFeign userFeign(){
return applicationContext.getBean(UserFeign.class);
}
@Override
public synchronized void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if(ApplicationRegistry.applicationContext==null) {
ApplicationRegistry.applicationContext = applicationContext;
}
}
}
package com.jty.wsxt.application.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author Manjiajie
* @since 2019-6-21 09:39:29
*/
@Component
@FeignClient(value = "auth-server",primary = false)
public interface UserFeign {
/**
* 得到登录用户的名称
* @return String
*/
@GetMapping("/manage/user/name")
String getLoginName();
/**
* 得到登录用户的ID
* @return Integer
*/
@GetMapping("/manage/user/id")
Integer getLoginId();
}
/**
* DDD: application 应用层
* 相对于领域层,应用层是很薄的一层,应用层定义了软件要完成的任务,要尽量简单.
* 它不包含任务业务规则或知识, 为下一层的领域对象协助任务、委托工作。
* 它没有反映业务情况的状态,但它可以具有反映用户或程序的某个任务的进展状态。
* 对外 为展现层提供各种应用功能(service)。
* 对内 调用领域层(领域对象或领域服务)完成各种业务逻辑任务(task)。
* 这一层也很适合写一些任务处理,日志监控
**/
package com.jty.wsxt.application;
package com.jty.wsxt.domain;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* 组件注册
*
* @author Manjiajie
* @since 2019-6-21 09:46:48
*/
@Component
public class DomainRegistry implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public synchronized void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if(DomainRegistry.applicationContext==null) {
DomainRegistry.applicationContext = applicationContext;
}
}
}
/**
* DDD: domain 领域层
* 领域层主要负责表达业务概念,业务状态信息和业务规则。
* Domain层是整个系统的核心层,几乎全部的业务逻辑会在该层实现。
* 领域模型层主要包含以下的内容:
* 实体(Entities):具有唯一标识的对象
* 值对象(Value Objects): 无需唯一标识的对象
* 领域服务(Domain Services): 一些行为无法归类到实体对象或值对象上,本质是一些操作,而非事物
* 聚合/聚合根(Aggregates,Aggregate Roots):
聚合是指一组具有内聚关系的相关对象的集合,每个聚合都有一个root和boundary
* 工厂(Factories): 创建复杂对象,隐藏创建细节
* 仓储(Repository): 提供查找和持久化对象的方法
*/
package com.jty.wsxt.domain;
\ No newline at end of file
package com.jty.wsxt.domain.shared;
import java.io.Serializable;
/**
* 标记实体对象
*
* @author Jason
* @since 2019/4/17 10:53
*/
public interface EntityObject<T> extends Serializable {
/**
* 实体对象的比较,通过唯一标识比较
* @param other 其它实体
* @return 如果唯一标识一样就标识一样,返回true,其它false
*/
boolean sameIdentityAs(T other);
}
package com.jty.wsxt.domain.shared;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
/**
* 层超类型(第一层)
* 委派身份标识(主键)
*
* @author Jason
* @since 2019/4/17 11:00
*/
@MappedSuperclass
public abstract class IdentifiedDomainObject implements Serializable {
@Id
private int id;
protected int getId(){
return this.id;
}
protected void setId(int id){
this.id=id;
}
public IdentifiedDomainObject(){
super();
}
}
package com.jty.wsxt.domain.shared;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;
/**
* 实体生成主键的父类
*
* @author Jason
* @since 2019/4/17 14:26
*/
@MappedSuperclass
@Data
public abstract class IdentifiedEntityObject<T> implements EntityObject<T> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/***
* 数据创建时间
*/
@CreationTimestamp
private LocalDateTime createdTime;
/***
* 数据修改时间
*/
@UpdateTimestamp
private LocalDateTime modifiedTime;
public Integer getId() {
return id;
}
protected void setId(Integer id) {
this.id = id;
}
}
package com.jty.wsxt.domain.shared;
import lombok.Data;
/**
* 层超类型(第二层)
* 委派身份标识(主键)
*
* @author Jason
* @since 2019/4/17 11:05
*/
@Data
public abstract class IdentifiedValueObject<T> implements ValueObject<T> {
private Integer id=-1;
}
package com.jty.wsxt.domain.shared;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
import java.io.IOException;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Map;
import java.util.Objects;
/**
* Hibernate自定义类型转化
* Map与Json的相互转化
*
* @author Jason
* @since 2019/4/17 17:17
*/
@Slf4j
public class MapJson implements UserType {
static ObjectMapper objectMapper=new ObjectMapper();
@Override
public int[] sqlTypes() {
return new int[]{Types.VARCHAR};
}
@Override
public Class returnedClass() {
return Map.class;
}
@Override
public boolean equals(Object x, Object y) throws HibernateException {
return Objects.equals(x, y);
}
@Override
public int hashCode(Object x) throws HibernateException {
return Objects.hashCode(x);
}
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException {
String s = rs.getString(names[0]);
if (s != null) {
try {
return objectMapper.readValue(s,Map.class);
} catch (IOException e) {
log.error(e.getMessage());
return null;
}
}
return null;
}
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.VARCHAR);
} else {
try {
String v = objectMapper.writeValueAsString(value);
st.setString(index, v);
} catch (IOException e) {
throw new HibernateException("Exception serializing value " + value, e);
}
}
}
@Override
public Object deepCopy(Object value) throws HibernateException {
if (value == null) return null;
return value;
}
@Override
public boolean isMutable() {
return false;
}
@Override
public Serializable disassemble(Object value) throws HibernateException {
return null;
}
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return null;
}
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return null;
}
}
package com.jty.wsxt.domain.shared;
import java.io.Serializable;
/**
* 值对象
*
* @author Jason
* @since 2019/4/17 10:56
*/
public interface ValueObject<T> extends Serializable {
/**
* 值对象比较是通过属性比较,他们没有唯一标识
* @param other 其它值对象
* @return 如果属性一致表示一致,返回true,其它false
*/
boolean sameValueAs(T other);
}
package com.jty.wsxt.infrastructure;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;
/**
* 数据同步
*
* @author jason
* @since 2019/5/20
*/
@Component
@Slf4j
public class ApplicationCloseListener implements ApplicationListener<ContextClosedEvent> {
@Override
public void onApplicationEvent(ContextClosedEvent event) {
}
}
package com.jty.wsxt.infrastructure;
/**
* 领域事件超级父类
*
* @author jason
* @since 2019/5/5
*/
public interface DomainEvent {
}
package com.jty.wsxt.infrastructure;
import java.util.ArrayList;
import java.util.List;
/**
* 领域事件发布者
*
* @author jason
* @since 2019/5/5
*/
public class DomainEventPublisher {
private static final ThreadLocal<List> subscribers=new ThreadLocal<>();
private static final ThreadLocal<Boolean> publishing=
new ThreadLocal<Boolean>(){
protected Boolean initialValue(){
return Boolean.FALSE;
}
};
public static DomainEventPublisher instance(){
return new DomainEventPublisher();
}
public DomainEventPublisher(){
super();
}
public <T> void publish(final T domainEvent){
if(publishing.get()){
return;
}
try{
publishing.set(Boolean.TRUE);
List<DomainEventSubscriber<T>> registeredSubscribers=subscribers.get();
if(registeredSubscribers!=null){
Class<?> eventType=domainEvent.getClass();
for(DomainEventSubscriber<T> subscriber:registeredSubscribers){
Class<?> subscribedTo=subscriber.subscribedToEventType();
if(subscribedTo==eventType||subscribedTo== DomainEvent.class){
subscriber.handleEvent(domainEvent);
}
}
}
}finally {
publishing.set(Boolean.FALSE);
}
}
public DomainEventPublisher reset(){
if(!publishing.get()){
subscribers.set(null);
}
return this;
}
public <T> void subscriber(DomainEventSubscriber<T> subscriber){
if(publishing.get()){
return;
}
List<DomainEventSubscriber<T>> registeredSubscribers=subscribers.get();
if(registeredSubscribers==null){
registeredSubscribers=new ArrayList<>();
subscribers.set(registeredSubscribers);
}
registeredSubscribers.add(subscriber);
}
}
package com.jty.wsxt.infrastructure;
/**
* 领域事件订阅者
*
* @author jason
* @since 2019/5/5
*/
public abstract class DomainEventSubscriber<T> {
public abstract Class<?> subscribedToEventType();
public abstract void handleEvent(T domainEvent);
}
package com.jty.wsxt.infrastructure.config;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* Feign调用配置Token转发
*
* @author Jason
* @since 2018/12/29 13:08
*/
@Configuration
public class FeignConfig implements RequestInterceptor {
@Override
public void apply(RequestTemplate template) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//添加token
template.header("Access-Token", request.getHeader("Access-Token"));
template.header("Authorization", request.getHeader("Authorization"));
}
}
/**
* DDD: infrastructure 基础实施层 最底层(但与所有层进行交互)
* 向其他层提供 通用的 技术能力(比如工具类,第三方库类支持,常用基本配置,数据访问底层实现)
* 基础实施层主要包含以下的内容:
* 为应用层 传递消息(比如通知)
* 为领域层 提供持久化机制(最底层的实现)
* 为用户界面层 提供组件配置
* 基础设施层还能够通过架构框架来支持四个层次间的交互模式。
*/
package com.jty.wsxt.infrastructure;
\ No newline at end of file
package com.jty.wsxt.infrastructure.support;
/**
* 阿里产品常量
* @author Zhongwentao
* @since 2019/2/21 10:32
*/
public class AlibabaConstants {
public final static String accessKeyId = "LTAINPdmg9GsW51l";
public final static String accessKeySecret = "vXm1u7WrIMrvru8EvBkZpkYSurrh9C";
//oss 中 试题文档文档bucket
public final static String OSS_paper_bucket_name = "jty-question-document";
//oss 的 endpoint
public final static String OSS_endpoint = "http://oss-cn-beijing.aliyuncs.com";
}
package com.jty.wsxt.infrastructure.support;
import lombok.Data;
/**
* 统一抛出异常
*
* @author Jason
* @since 2018/12/18 10:31
*/
@Data
public class BusinessException extends RuntimeException{
private ResultCode code;
public BusinessException(ResultCode code){
this.code=code;
}
/**
* 处理动态传参
* @param code
* @param message
*/
public BusinessException(ResultCode code,String... message){
String meg=code.message();
code.setMessage(String.format(meg,message));
this.code=code;
}
}
package com.jty.wsxt.infrastructure.support;
/**
* 通常常量
*
* @author Jason
* @since 2019/1/2 14:47
*/
public class CommonConstants {
public static final String SESSION_KEY_VALIDATE_CODE="session_key_validate_code";
//小题数量限制
public static final int children_limit = 9;
public static final String TEST_HOST = "http://192.168.2.240:1025";
public static final String LOCAL_HOST = "http://localhost:9003";
}
package com.jty.wsxt.infrastructure.support;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
@Configuration
public class DateConfig {
/** 默认日期时间格式 */
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/** 默认日期格式 */
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
/**
* LocalDateTime转换器,用于转换RequestParam和PathVariable参数
*/
@Bean
public Converter<String, LocalDateTime> localDateTimeConverter() {
return new Converter<String, LocalDateTime>() {
@Override
public LocalDateTime convert(String source) {
SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT);
try {
Date date=sdf.parse(source);
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
};
}
}
package com.jty.wsxt.infrastructure.support;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindException;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* TODO
*
* @author Jason
* @since 2018/12/18 13:59
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
/**
* 处理自定义异常
* @param ex
* @return //
*/
@ExceptionHandler({MissingServletRequestParameterException.class,BusinessException.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result handleRuntimeException(BusinessException ex) {
//logger.info("catch BusinessException:"+ ex.toString());
//不适合查询问题所在位置,所以必须打出所有堆栈
ex.printStackTrace();
return Result.failure(ex.getCode());
}
@ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST) //400
protected Result addValidationError(Exception e){
List errorList=new ArrayList();
List<ObjectError> errors = new LinkedList();
if(e instanceof MethodArgumentNotValidException){
MethodArgumentNotValidException validException = (MethodArgumentNotValidException)e;
errors = validException.getBindingResult().getAllErrors();
}else{
BindException validException = (BindException)e;
errors = validException.getBindingResult().getAllErrors();
}
for(ObjectError fieldError:errors){
errorList.add(fieldError.getDefaultMessage());
}
return Result.failure( ResultCode.DATA_IS_WRONG,errorList);
}
}
package com.jty.wsxt.infrastructure.support;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
return new RestTemplate(factory);
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(15000);
factory.setReadTimeout(50000);
return factory;
}
}
package com.jty.wsxt.infrastructure.support;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
/**
* API统一返回结果
*
* @author Jason
* @since 2018/12/17 13:18
*/
@Data
public class Result<T> {
interface ResultInterface{}
@JsonView(ResultInterface.class)
private Integer code;
@JsonView(ResultInterface.class)
private String msg;
@JsonView(ResultInterface.class)
private T data;
public Result() {}
public Result(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public static Result success() {
Result result = new Result();
result.setResultCode(ResultCode.SUCCESS);
return result;
}
public static <T> Result success(T data) {
Result result = new Result();
result.setResultCode(ResultCode.SUCCESS);
result.setData(data);
return result;
}
public static Result failure(ResultCode resultCode) {
Result result = new Result();
result.setResultCode(resultCode);
return result;
}
public static <T> Result failure(ResultCode resultCode, T data) {
Result result = new Result();
result.setResultCode(resultCode);
result.setData(data);
return result;
}
public void setResultCode(ResultCode code) {
this.code = code.code();
this.msg = code.message();
}
}
package com.jty.wsxt.infrastructure.support;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
/**
* 返回结果枚举类
*
* @author Jason
* @since 2018/12/17 13:18
*/
@Getter
public enum ResultCode {
/* 成功状态码 */
SUCCESS(1, "成功"),
CODE_ERROR(2,"代码逻辑错误"),
/* 参数错误:10001-19999 */
PARAM_IS_INVALID(10001, "参数无效"),
PARAM_IS_BLANK(10002, "参数为空"),
PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
PARAM_NOT_COMPLETE(10004, "参数缺失"),
/* 用户错误:20001-29999*/
USER_NOT_LOGGED_IN(20001, "用户未登录"),
USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
USER_NOT_EXIST(20004, "用户不存在"),
USER_HAS_EXISTED(20005, "用户已存在"),
USER_HAS_NOT_PERMISSION(20006, "用户没有权限"),
ORGANIZATION_IS_DIFFERENT(20007,"用户没有权限管理另一个机构的内容"),
PHONE_CODE_ERROR(20008,"手机验证码错误"),
VALIDATE_CODE_ERROR(20009,"验证码错误"),
/* 系统错误:40001-49999 */
SYSTEM_INNER_ERROR(40001, "系统繁忙,请稍后重试"),
/* 数据错误:50001-599999 */
RESULT_DATA_NONE(50001, "数据未找到"),
DATA_IS_WRONG(50002, "数据有误"),
DATA_ALREADY_EXISTED(50003, "数据已存在"),
DATA_IS_COMPRESS(50004,"数据是压缩文件"),
TYPE_IS_WRONG(50005,"类型错误"),
/* 文档审核错误:60001-69999 */
IS_NOT_PROOFREAD(60001,"试题还未校对"),
IS_NOT_SIGN(60002,"试题还未打标"),
IS_NOT_CHECK(60003,"试题还未审核"),
/* 文档解析上传错误:60001-69999 */
FILE_READ_WRONG(70001,"读取文件异常"),
FILE_UPLOAD_WRONG(70002,"上传文件失败"),
FILE_ANALYSIS_WRONG(70003,"文档解析失败"),
/* 小题操作错误:80001-89999 */
SMALL_ADD_WRONG(80001,"小题数量超标");
private Integer code;
private String message;
ResultCode(Integer code, String message) {
this.code = code;
this.message = message;
}
public Integer code() {
return this.code;
}
public String message() {
return this.message;
}
public static String getMessage(String name) {
for (ResultCode item : ResultCode.values()) {
if (item.name().equals(name)) {
return item.message;
}
}
return name;
}
public static Integer getCode(String name) {
for (ResultCode item : ResultCode.values()) {
if (item.name().equals(name)) {
return item.code;
}
}
return null;
}
public void setMessage(String message){
this.message=message;
}
@Override
public String toString() {
return this.name();
}
//校验重复的code值
public static void main(String[] args) {
ResultCode[] apiResultCodes = ResultCode.values();
List<Integer> codeList = new ArrayList<>();
for (ResultCode apiResultCode : apiResultCodes) {
if (codeList.contains(apiResultCode.code)) {
System.out.println(apiResultCode.code);
} else {
codeList.add(apiResultCode.code());
}
}
}
}
package com.jty.wsxt.infrastructure.util;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.ResponseHeaderOverrides;
import com.jty.wsxt.infrastructure.support.AlibabaConstants;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
/**
* TODO
*
* @author Jason
* @since 2019/1/7 14:50
*/
public class OssUtil {
public static String uploadMultipartFile(MultipartFile file,String bucket) throws IOException {
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType("text/plain");
meta.setContentDisposition("attachment;filename=\""+file.getOriginalFilename()+"\"");
OSSClient ossClient = new OSSClient(AlibabaConstants.OSS_endpoint, AlibabaConstants.accessKeyId, AlibabaConstants.accessKeySecret);
String objectName= LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli() + RandomStringUtils.randomNumeric(8);
ossClient.putObject(bucket,objectName,file.getInputStream(), meta);
ossClient.shutdown();
return "http://" + bucket + ".oss-cn-beijing.aliyuncs.com/"+objectName;
}
public static String getAgingUrl(String bucketName,String key){
OSSClient ossClient = new OSSClient( AlibabaConstants.OSS_endpoint, AlibabaConstants.accessKeyId, AlibabaConstants.accessKeySecret );
// 5 minute to expire
Date expires = new Date( System.currentTimeMillis() + 1000 * 60*60);
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setExpiration( expires );
return ossClient.generatePresignedUrl(generatePresignedUrlRequest).toString();
}
/**
* 设置下载文件名
* @param bucketName
* @param key
* @param fileName
* @return
*/
public static String getAgingUrl(String bucketName,String key,String fileName){
OSSClient ossClient = new OSSClient( AlibabaConstants.OSS_endpoint, AlibabaConstants.accessKeyId, AlibabaConstants.accessKeySecret );
// 5 minute to expire
Date expires = new Date( System.currentTimeMillis() + 1000 * 60*60);
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, key);
generatePresignedUrlRequest.setExpiration( expires );
//设置现在文件名和文件标题名一致
if(StringUtils.isNotBlank(fileName)){
ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
responseHeaders.setContentDisposition(" attachment; filename=" + fileName);
generatePresignedUrlRequest.setResponseHeaders(responseHeaders);
}
return ossClient.generatePresignedUrl(generatePresignedUrlRequest).toString();
}
public static Boolean checkDocumentExist(String bucketName,String key){
OSSClient ossClient = new OSSClient(AlibabaConstants.OSS_endpoint, AlibabaConstants.accessKeyId, AlibabaConstants.accessKeySecret);
// 判断文件是否存在。doesObjectExist还有一个参数isOnlyInOSS,如果为true则忽略302重定向或镜像;如果 为false,则考虑302重定向或镜像。
return ossClient.doesObjectExist(bucketName, key);
}
}
package com.jty.wsxt.infrastructure.util;
/**
* TODO
*
* @param
* @Author qinjiaxin
* @return
*/
public class TransferCharactor {
public static String transfer(String oldStr){
return oldStr.replace("%","\\%").replace("_","\\_");
}
}
/**
* DDD: interfaces 用户界面层(或表示层) 最顶层
* 负责向用户显示信息和解释用户命令
* 请求应用层以获取用户所需要展现的数据(比如获取首页的商品数据)
* 发送命令给应用层要求其执行某个用户命令(实现某个业务逻辑,比如用户要进行转账)
* 用户界面层应该包含以下的内容:
* 数据传输对象(Data Transfer Object): DTO也常被称作值对象,VO,实质上与领域层的VO并不相同
DTO是数据传输的载体,内部不应该存在任何业务逻辑,通过DTO把内部的领域对象与外界隔离。
* 装配(Assembler): 实现DTO与领域对象之间的相互转换,数据交换,因此Assembler几乎总是同DTO一起出现。
* 表面,门面(Facade): Facade的用意在于为远程客户端提供粗粒度的调用接口
它的主要工作就是将一个用户请求委派给一个或多个Service进行处理,也就是我们常说的Controller。
*/
package com.jty.wsxt.interfaces;
\ No newline at end of file
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