yshop1.7发布,后台升級eladmin2.4(前端,后台权限,代码生成器等重构),修复商品分类等一些问题
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>yshop</artifactId>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<version>1.6</version>
|
||||
<version>1.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
<dependency>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<artifactId>yshop-logging</artifactId>
|
||||
<version>1.6</version>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
|
||||
<!--邮件依赖-->
|
||||
@ -46,18 +46,5 @@
|
||||
<artifactId>alipay-sdk-java</artifactId>
|
||||
<version>${alipay.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.redisson</groupId>-->
|
||||
<!-- <artifactId>redisson</artifactId>-->
|
||||
<!-- <version>3.11.2</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@ -19,7 +19,7 @@ public class MultipartConfig {
|
||||
@Bean
|
||||
MultipartConfigElement multipartConfigElement() {
|
||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
String location = System.getProperty("user.home") + "/.eladmin/file/tmp";
|
||||
String location = System.getProperty("user.home") + "/.yshop/file/tmp";
|
||||
File tmpFile = new File(location);
|
||||
if (!tmpFile.exists()) {
|
||||
tmpFile.mkdirs();
|
||||
|
@ -18,66 +18,46 @@ public class AlipayConfig implements Serializable {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 应用ID,APPID,收款账号既是APPID对应支付宝账号
|
||||
*/
|
||||
/** 应用ID,APPID,收款账号既是APPID对应支付宝账号 */
|
||||
@NotBlank
|
||||
@Column(name = "app_id")
|
||||
private String appID;
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 商户私钥,您的PKCS8格式RSA2私钥
|
||||
*/
|
||||
/** 商户私钥,您的PKCS8格式RSA2私钥 */
|
||||
@NotBlank
|
||||
@Column(name = "private_key", columnDefinition = "text")
|
||||
private String privateKey;
|
||||
|
||||
/**
|
||||
* 支付宝公钥
|
||||
*/
|
||||
/** 支付宝公钥 */
|
||||
@NotBlank
|
||||
@Column(name = "public_key", columnDefinition = "text")
|
||||
private String publicKey;
|
||||
|
||||
/**
|
||||
* 签名方式,固定格式
|
||||
*/
|
||||
/** 签名方式,固定格式 */
|
||||
@Column(name = "sign_type")
|
||||
private String signType="RSA2";
|
||||
|
||||
/**
|
||||
* 支付宝开放安全地址,一般不会变
|
||||
*/
|
||||
/** 支付宝开放安全地址,一般不会变 */
|
||||
@Column(name = "gateway_url")
|
||||
private String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";
|
||||
|
||||
/**
|
||||
* 编码,固定格式
|
||||
*/
|
||||
/** 编码,固定格式 */
|
||||
private String charset= "utf-8";
|
||||
|
||||
/**
|
||||
* 异步通知地址
|
||||
*/
|
||||
/** 异步通知地址 */
|
||||
@NotBlank
|
||||
@Column(name = "notify_url")
|
||||
private String notifyUrl;
|
||||
|
||||
/**
|
||||
* 订单完成后返回的页面
|
||||
*/
|
||||
/** 订单完成后返回的页面 */
|
||||
@NotBlank
|
||||
@Column(name = "return_url")
|
||||
private String returnUrl;
|
||||
|
||||
/**
|
||||
* 类型,固定格式
|
||||
*/
|
||||
/** 类型,固定格式 */
|
||||
private String format="JSON";
|
||||
|
||||
/**
|
||||
* 商户号
|
||||
*/
|
||||
/** 商户号 */
|
||||
@NotBlank
|
||||
@Column(name = "sys_service_provider_id")
|
||||
private String sysServiceProviderId;
|
||||
|
@ -19,30 +19,22 @@ public class EmailConfig implements Serializable {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
*邮件服务器SMTP地址
|
||||
*/
|
||||
/** 邮件服务器SMTP地址 */
|
||||
@NotBlank
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 邮件服务器SMTP端口
|
||||
*/
|
||||
/** 邮件服务器 SMTP 端口 */
|
||||
@NotBlank
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* 发件者用户名,默认为发件人邮箱前缀
|
||||
*/
|
||||
/** 发件者用户名,默认为发件人邮箱前缀 */
|
||||
@NotBlank
|
||||
private String user;
|
||||
|
||||
@NotBlank
|
||||
private String pass;
|
||||
|
||||
/**
|
||||
* 收件人
|
||||
*/
|
||||
/** 收件人 */
|
||||
@NotBlank
|
||||
@Column(name = "from_user")
|
||||
private String fromUser;
|
||||
|
@ -1,72 +1,62 @@
|
||||
package co.yixiang.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="local_storage")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LocalStorage implements Serializable {
|
||||
public class LocalStorage implements Serializable {
|
||||
|
||||
// ID
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
// 真实文件名
|
||||
/** 真实文件名 */
|
||||
@Column(name = "real_name")
|
||||
private String realName;
|
||||
|
||||
// 文件名
|
||||
/**文件名 */
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
// 后缀
|
||||
/**后缀 */
|
||||
@Column(name = "suffix")
|
||||
private String suffix;
|
||||
|
||||
// 路径
|
||||
/** 路径 */
|
||||
@Column(name = "path")
|
||||
private String path;
|
||||
|
||||
// 类型
|
||||
/** 类型 */
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
// 大小
|
||||
/** 大小 */
|
||||
@Column(name = "size")
|
||||
private String size;
|
||||
|
||||
// 操作人
|
||||
/** 操作人 */
|
||||
@Column(name = "operate")
|
||||
private String operate;
|
||||
|
||||
// 创建日期
|
||||
@Column(name = "create_time")
|
||||
@CreationTimestamp
|
||||
private Timestamp createTime;
|
||||
|
||||
// 修改日期
|
||||
@Column(name = "update_time")
|
||||
@UpdateTimestamp
|
||||
private Timestamp updateTime;
|
||||
|
||||
public LocalStorage(String realName,String name, String suffix, String path, String type, String size, String operate) {
|
||||
this.realName = realName;
|
||||
this.name = name;
|
||||
|
@ -32,9 +32,6 @@ public class Picture implements Serializable {
|
||||
|
||||
private String width;
|
||||
|
||||
/**
|
||||
* delete URl
|
||||
*/
|
||||
@Column(name = "delete_url")
|
||||
private String delete;
|
||||
|
||||
@ -44,6 +41,9 @@ public class Picture implements Serializable {
|
||||
@Column(name = "create_time")
|
||||
private Timestamp createTime;
|
||||
|
||||
/** 用于检测文件是否重复 */
|
||||
private String md5Code;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Picture{" +
|
||||
|
@ -18,23 +18,17 @@ public class QiniuConfig implements Serializable {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 一个账号最多拥有两对密钥(Access/Secret Key)
|
||||
*/
|
||||
/** 一个账号最多拥有两对密钥(Access/Secret Key) */
|
||||
@NotBlank
|
||||
@Column(name = "access_key", columnDefinition = "text")
|
||||
private String accessKey;
|
||||
|
||||
/**
|
||||
* 一个账号最多拥有两对密钥(Access/Secret Key)
|
||||
*/
|
||||
/** 一个账号最多拥有两对密钥(Access/Secret Key) */
|
||||
@NotBlank
|
||||
@Column(name = "secret_key", columnDefinition = "text")
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* 存储空间名称作为唯一的 Bucket 识别符
|
||||
*/
|
||||
/** 存储空间名称作为唯一的 Bucket 识别符 */
|
||||
@NotBlank
|
||||
private String bucket;
|
||||
|
||||
@ -49,14 +43,10 @@ public class QiniuConfig implements Serializable {
|
||||
@NotBlank
|
||||
private String zone;
|
||||
|
||||
/**
|
||||
* 外链域名,可自定义,需在七牛云绑定
|
||||
*/
|
||||
/** 外链域名,可自定义,需在七牛云绑定 */
|
||||
@NotBlank
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 空间类型:公开/私有
|
||||
*/
|
||||
/** 空间类型:公开/私有 */
|
||||
private String type = "公开";
|
||||
}
|
||||
|
@ -21,37 +21,24 @@ public class QiniuContent implements Serializable {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 文件名,如qiniu.jpg
|
||||
*/
|
||||
@Column(name = "name",unique = false)
|
||||
/** 文件名 */
|
||||
@Column(name = "name")
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 空间名
|
||||
*/
|
||||
/** 空间名 */
|
||||
private String bucket;
|
||||
|
||||
/**
|
||||
* 大小
|
||||
*/
|
||||
/** 大小 */
|
||||
private String size;
|
||||
|
||||
/**
|
||||
* 文件地址
|
||||
*/
|
||||
/** 文件地址 */
|
||||
private String url;
|
||||
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 空间类型:公开/私有
|
||||
*/
|
||||
/** 空间类型:公开/私有 */
|
||||
private String type = "公开";
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@UpdateTimestamp
|
||||
@Column(name = "update_time")
|
||||
private Timestamp updateTime;
|
||||
|
@ -7,6 +7,7 @@ import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
@ -18,7 +19,7 @@ import java.sql.Timestamp;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Table(name = "verification_code")
|
||||
public class VerificationCode {
|
||||
public class VerificationCode implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@ -26,32 +27,21 @@ public class VerificationCode {
|
||||
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 使用场景,自己定义
|
||||
*/
|
||||
/** 使用场景,自己定义 */
|
||||
private String scenes;
|
||||
|
||||
/**
|
||||
* true 为有效,false 为无效,验证时状态+时间+具体的邮箱或者手机号
|
||||
*/
|
||||
/** true 为有效,false 为无效,验证时状态+时间+具体的邮箱或者手机号 */
|
||||
private Boolean status = true;
|
||||
|
||||
|
||||
/**
|
||||
* 类型 :phone 和 email
|
||||
*/
|
||||
/** 类型 :phone 和 email */
|
||||
@NotBlank
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 具体的phone与email
|
||||
*/
|
||||
/** 具体的phone与email */
|
||||
@NotBlank
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
/** 创建日期 */
|
||||
@CreationTimestamp
|
||||
@Column(name = "create_time")
|
||||
private Timestamp createTime;
|
||||
|
@ -18,9 +18,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
public class EmailVo {
|
||||
|
||||
/**
|
||||
* 收件人,支持多个收件人,用逗号分隔
|
||||
*/
|
||||
/** 收件人,支持多个收件人 */
|
||||
@NotEmpty
|
||||
private List<String> tos;
|
||||
|
||||
|
@ -15,51 +15,35 @@ import java.sql.Timestamp;
|
||||
@Data
|
||||
public class TradeVo {
|
||||
|
||||
/**
|
||||
* (必填)商品描述
|
||||
*/
|
||||
/** (必填)商品描述 */
|
||||
@NotBlank
|
||||
private String body;
|
||||
|
||||
/**
|
||||
* (必填)商品名称
|
||||
*/
|
||||
/** (必填)商品名称 */
|
||||
@NotBlank
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* (必填)商户订单号,应该由后台生成
|
||||
*/
|
||||
/** (必填)商户订单号,应该由后台生成 */
|
||||
@ApiModelProperty(hidden = true)
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* (必填)第三方订单号
|
||||
*/
|
||||
/** (必填)第三方订单号 */
|
||||
@ApiModelProperty(hidden = true)
|
||||
private String tradeNo;
|
||||
|
||||
/**
|
||||
* (必填)价格
|
||||
*/
|
||||
/** (必填)价格 */
|
||||
@NotBlank
|
||||
private String totalAmount;
|
||||
|
||||
/**
|
||||
* 订单状态,已支付,未支付,作废
|
||||
*/
|
||||
/** 订单状态,已支付,未支付,作废 */
|
||||
@ApiModelProperty(hidden = true)
|
||||
private String state;
|
||||
|
||||
/**
|
||||
* 创建时间,存入数据库时需要
|
||||
*/
|
||||
/** 创建时间,存入数据库时需要 */
|
||||
@ApiModelProperty(hidden = true)
|
||||
private Timestamp createTime;
|
||||
|
||||
/**
|
||||
* 作废时间,存入数据库时需要
|
||||
*/
|
||||
/** 作废时间,存入数据库时需要 */
|
||||
@ApiModelProperty(hidden = true)
|
||||
private Date cancelTime;
|
||||
}
|
||||
|
@ -1,145 +1,145 @@
|
||||
package co.yixiang.express;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import co.yixiang.express.config.ExpressProperties;
|
||||
import co.yixiang.express.dao.ExpressInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物流查询服务
|
||||
* <p>
|
||||
* 快递鸟即时查询API http://www.kdniao.com/api-track
|
||||
*/
|
||||
public class ExpressService {
|
||||
|
||||
private final Log logger = LogFactory.getLog(ExpressService.class);
|
||||
//请求url
|
||||
private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
|
||||
|
||||
private ExpressProperties properties;
|
||||
|
||||
public ExpressProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(ExpressProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流供应商名
|
||||
*
|
||||
* @param vendorCode
|
||||
* @return
|
||||
*/
|
||||
public String getVendorName(String vendorCode) {
|
||||
for (Map<String, String> item : properties.getVendors()) {
|
||||
if (item.get("code").equals(vendorCode))
|
||||
return item.get("name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流信息
|
||||
*
|
||||
* @param OrderCode
|
||||
* @param ShipperCode
|
||||
* @return
|
||||
*/
|
||||
public ExpressInfo getExpressInfo(String OrderCode,String ShipperCode, String LogisticCode) {
|
||||
try {
|
||||
String result = getOrderTracesByJson(OrderCode,ShipperCode, LogisticCode);
|
||||
ObjectMapper objMap = new ObjectMapper();
|
||||
ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
|
||||
ei.setShipperName(getVendorName(ShipperCode));
|
||||
return ei;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Json方式 查询订单物流轨迹
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private String getOrderTracesByJson(String OrderCode,String ShipperCode, String LogisticCode) throws Exception {
|
||||
if (!properties.isEnable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String requestData = "{'OrderCode':'"+OrderCode+"','ShipperCode':'" + ShipperCode + "','LogisticCode':'" + LogisticCode + "'}";
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("RequestData", URLEncoder.encode(requestData, "UTF-8"));
|
||||
params.put("EBusinessID", properties.getAppId());
|
||||
params.put("RequestType", "1002");
|
||||
String dataSign = encrypt(requestData, properties.getAppKey(), "UTF-8");
|
||||
params.put("DataSign", URLEncoder.encode(dataSign, "UTF-8"));
|
||||
params.put("DataType", "2");
|
||||
|
||||
String result = HttpUtil.post(ReqURL, params);
|
||||
|
||||
//根据公司业务处理返回的信息......
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*
|
||||
* @param str 内容
|
||||
* @param charset 编码方式
|
||||
* @throws Exception
|
||||
*/
|
||||
private String MD5(String str, String charset) throws Exception {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(str.getBytes(charset));
|
||||
byte[] result = md.digest();
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
int val = result[i] & 0xff;
|
||||
if (val <= 0xf) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(Integer.toHexString(val));
|
||||
}
|
||||
return sb.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign签名生成
|
||||
*
|
||||
* @param content 内容
|
||||
* @param keyValue Appkey
|
||||
* @param charset 编码方式
|
||||
* @return DataSign签名
|
||||
*/
|
||||
private String encrypt(String content, String keyValue, String charset) {
|
||||
if (keyValue != null) {
|
||||
content = content + keyValue;
|
||||
}
|
||||
byte[] src;
|
||||
try {
|
||||
src = MD5(content, charset).getBytes(charset);
|
||||
return Base64Utils.encodeToString(src);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package co.yixiang.express;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import co.yixiang.express.config.ExpressProperties;
|
||||
import co.yixiang.express.dao.ExpressInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物流查询服务
|
||||
* <p>
|
||||
* 快递鸟即时查询API http://www.kdniao.com/api-track
|
||||
*/
|
||||
public class ExpressService {
|
||||
|
||||
private final Log logger = LogFactory.getLog(ExpressService.class);
|
||||
//请求url
|
||||
private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
|
||||
|
||||
private ExpressProperties properties;
|
||||
|
||||
public ExpressProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(ExpressProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流供应商名
|
||||
*
|
||||
* @param vendorCode
|
||||
* @return
|
||||
*/
|
||||
public String getVendorName(String vendorCode) {
|
||||
for (Map<String, String> item : properties.getVendors()) {
|
||||
if (item.get("code").equals(vendorCode))
|
||||
return item.get("name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流信息
|
||||
*
|
||||
* @param OrderCode
|
||||
* @param ShipperCode
|
||||
* @return
|
||||
*/
|
||||
public ExpressInfo getExpressInfo(String OrderCode,String ShipperCode, String LogisticCode) {
|
||||
try {
|
||||
String result = getOrderTracesByJson(OrderCode,ShipperCode, LogisticCode);
|
||||
ObjectMapper objMap = new ObjectMapper();
|
||||
ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
|
||||
ei.setShipperName(getVendorName(ShipperCode));
|
||||
return ei;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Json方式 查询订单物流轨迹
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private String getOrderTracesByJson(String OrderCode,String ShipperCode, String LogisticCode) throws Exception {
|
||||
if (!properties.isEnable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String requestData = "{'OrderCode':'"+OrderCode+"','ShipperCode':'" + ShipperCode + "','LogisticCode':'" + LogisticCode + "'}";
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("RequestData", URLEncoder.encode(requestData, "UTF-8"));
|
||||
params.put("EBusinessID", properties.getAppId());
|
||||
params.put("RequestType", "1002");
|
||||
String dataSign = encrypt(requestData, properties.getAppKey(), "UTF-8");
|
||||
params.put("DataSign", URLEncoder.encode(dataSign, "UTF-8"));
|
||||
params.put("DataType", "2");
|
||||
|
||||
String result = HttpUtil.post(ReqURL, params);
|
||||
|
||||
//根据公司业务处理返回的信息......
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*
|
||||
* @param str 内容
|
||||
* @param charset 编码方式
|
||||
* @throws Exception
|
||||
*/
|
||||
private String MD5(String str, String charset) throws Exception {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(str.getBytes(charset));
|
||||
byte[] result = md.digest();
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
int val = result[i] & 0xff;
|
||||
if (val <= 0xf) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(Integer.toHexString(val));
|
||||
}
|
||||
return sb.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign签名生成
|
||||
*
|
||||
* @param content 内容
|
||||
* @param keyValue Appkey
|
||||
* @param charset 编码方式
|
||||
* @return DataSign签名
|
||||
*/
|
||||
private String encrypt(String content, String keyValue, String charset) {
|
||||
if (keyValue != null) {
|
||||
content = content + keyValue;
|
||||
}
|
||||
byte[] src;
|
||||
try {
|
||||
src = MD5(content, charset).getBytes(charset);
|
||||
return Base64Utils.encodeToString(src);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
public interface LocalStorageRepository extends JpaRepository<LocalStorage, Long>, JpaSpecificationExecutor {
|
||||
public interface LocalStorageRepository extends JpaRepository<LocalStorage, Long>, JpaSpecificationExecutor<LocalStorage> {
|
||||
}
|
@ -8,5 +8,19 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-27
|
||||
*/
|
||||
public interface PictureRepository extends JpaRepository<Picture,Long>, JpaSpecificationExecutor {
|
||||
public interface PictureRepository extends JpaRepository<Picture,Long>, JpaSpecificationExecutor<Picture> {
|
||||
|
||||
/**
|
||||
* 根据 Mds 值查询文件
|
||||
* @param code 值
|
||||
* @return /
|
||||
*/
|
||||
Picture findByMd5Code(String code);
|
||||
|
||||
/**
|
||||
* 根据连接地址查询
|
||||
* @param url /
|
||||
* @return /
|
||||
*/
|
||||
boolean existsByUrl(String url);
|
||||
}
|
||||
|
@ -11,7 +11,11 @@ import org.springframework.data.jpa.repository.Query;
|
||||
*/
|
||||
public interface QiNiuConfigRepository extends JpaRepository<QiniuConfig,Long> {
|
||||
|
||||
/**
|
||||
* 编辑类型
|
||||
* @param type
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "update qiniu_content set type = ?1", nativeQuery = true)
|
||||
@Query(value = "update QiniuConfig set type = ?1")
|
||||
void update(String type);
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-31
|
||||
*/
|
||||
public interface QiniuContentRepository extends JpaRepository<QiniuContent,Long>, JpaSpecificationExecutor {
|
||||
public interface QiniuContentRepository extends JpaRepository<QiniuContent,Long>, JpaSpecificationExecutor<QiniuContent> {
|
||||
|
||||
/**
|
||||
* 根据key查询
|
||||
* @param key
|
||||
* @return
|
||||
* @param key 文件名
|
||||
* @return QiniuContent
|
||||
*/
|
||||
QiniuContent findByKey(String key);
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ public interface VerificationCodeRepository extends JpaRepository<VerificationCo
|
||||
/**
|
||||
* 获取有效的验证码
|
||||
* @param scenes 业务场景,如重置密码,重置邮箱等等
|
||||
* @param type
|
||||
* @param value
|
||||
* @return
|
||||
* @param type 类型
|
||||
* @param value 值
|
||||
* @return VerificationCode
|
||||
*/
|
||||
VerificationCode findByScenesAndTypeAndValueAndStatusIsTrue(String scenes, String type, String value);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package co.yixiang.rest;
|
||||
|
||||
import co.yixiang.aop.log.Log;
|
||||
import co.yixiang.utils.AliPayStatusEnum;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.aop.log.Log;
|
||||
import co.yixiang.domain.AlipayConfig;
|
||||
import co.yixiang.annotation.AnonymousAccess;
|
||||
import co.yixiang.domain.vo.TradeVo;
|
||||
import co.yixiang.service.AlipayService;
|
||||
import co.yixiang.utils.AliPayStatusEnum;
|
||||
import co.yixiang.domain.AlipayConfig;
|
||||
import co.yixiang.utils.AlipayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import co.yixiang.service.AlipayService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -25,42 +26,46 @@ import java.util.Map;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@Api(tags = "支付宝支付")
|
||||
@RequestMapping("/api/aliPay")
|
||||
@Api(tags = "工具:支付宝管理")
|
||||
public class AliPayController {
|
||||
|
||||
@Autowired
|
||||
AlipayUtils alipayUtils;
|
||||
private final AlipayUtils alipayUtils;
|
||||
|
||||
@Autowired
|
||||
private AlipayService alipayService;
|
||||
private final AlipayService alipayService;
|
||||
|
||||
@GetMapping(value = "/aliPay")
|
||||
public AliPayController(AlipayUtils alipayUtils, AlipayService alipayService) {
|
||||
this.alipayUtils = alipayUtils;
|
||||
this.alipayService = alipayService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<AlipayConfig> get(){
|
||||
return new ResponseEntity<>(alipayService.find(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("配置支付宝")
|
||||
@PutMapping(value = "/aliPay")
|
||||
public ResponseEntity payConfig(@Validated @RequestBody AlipayConfig alipayConfig){
|
||||
@ApiOperation("配置支付宝")
|
||||
@PutMapping
|
||||
public ResponseEntity<Object> payConfig(@Validated @RequestBody AlipayConfig alipayConfig){
|
||||
alipayConfig.setId(1L);
|
||||
alipayService.update(alipayConfig);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("支付宝PC网页支付")
|
||||
@ApiOperation(value = "PC网页支付")
|
||||
@PostMapping(value = "/aliPay/toPayAsPC")
|
||||
public ResponseEntity<String> toPayAsPC(@Validated@RequestBody TradeVo trade) throws Exception{
|
||||
AlipayConfig alipay = alipayService.find();
|
||||
@ApiOperation("PC网页支付")
|
||||
@PostMapping(value = "/toPayAsPC")
|
||||
public ResponseEntity<String> toPayAsPc(@Validated@RequestBody TradeVo trade) throws Exception{
|
||||
AlipayConfig aliPay = alipayService.find();
|
||||
trade.setOutTradeNo(alipayUtils.getOrderCode());
|
||||
String payUrl = alipayService.toPayAsPC(alipay,trade);
|
||||
String payUrl = alipayService.toPayAsPc(aliPay,trade);
|
||||
return ResponseEntity.ok(payUrl);
|
||||
}
|
||||
|
||||
@Log("支付宝手机网页支付")
|
||||
@ApiOperation(value = "手机网页支付")
|
||||
@PostMapping(value = "/aliPay/toPayAsWeb")
|
||||
@ApiOperation("手机网页支付")
|
||||
@PostMapping(value = "/toPayAsWeb")
|
||||
public ResponseEntity<String> toPayAsWeb(@Validated @RequestBody TradeVo trade) throws Exception{
|
||||
AlipayConfig alipay = alipayService.find();
|
||||
trade.setOutTradeNo(alipayUtils.getOrderCode());
|
||||
@ -69,57 +74,52 @@ public class AliPayController {
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/aliPay/return")
|
||||
@ApiOperation(value = "支付之后跳转的链接")
|
||||
public ResponseEntity<String> returnPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
@GetMapping("/return")
|
||||
@AnonymousAccess
|
||||
@ApiOperation("支付之后跳转的链接")
|
||||
public ResponseEntity<String> returnPage(HttpServletRequest request, HttpServletResponse response){
|
||||
AlipayConfig alipay = alipayService.find();
|
||||
response.setContentType("text/html;charset=" + alipay.getCharset());
|
||||
//内容验签,防止黑客篡改参数
|
||||
if(alipayUtils.rsaCheck(request,alipay)){
|
||||
//商户订单号
|
||||
String outTradeNo = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
|
||||
String outTradeNo = new String(request.getParameter("out_trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
//支付宝交易号
|
||||
String tradeNo = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
|
||||
String tradeNo = new String(request.getParameter("trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
System.out.println("商户订单号"+outTradeNo+" "+"第三方交易号"+tradeNo);
|
||||
|
||||
/**
|
||||
* 根据业务需要返回数据,这里统一返回OK
|
||||
*/
|
||||
// 根据业务需要返回数据,这里统一返回OK
|
||||
return new ResponseEntity<>("payment successful",HttpStatus.OK);
|
||||
}else{
|
||||
/**
|
||||
* 根据业务需要返回数据
|
||||
*/
|
||||
// 根据业务需要返回数据
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@RequestMapping("/aliPay/notify")
|
||||
@ApiOperation(value = "支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理")
|
||||
public ResponseEntity notify(HttpServletRequest request) throws Exception{
|
||||
@RequestMapping("/notify")
|
||||
@AnonymousAccess
|
||||
@SuppressWarnings("all")
|
||||
@ApiOperation("支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理")
|
||||
public ResponseEntity<Object> notify(HttpServletRequest request){
|
||||
AlipayConfig alipay = alipayService.find();
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
StringBuilder notifyBuild = new StringBuilder("/****************************** pay notify ******************************/\n");
|
||||
parameterMap.forEach((key, value) -> notifyBuild.append(key + "=" + value[0] + "\n") );
|
||||
//内容验签,防止黑客篡改参数
|
||||
if (alipayUtils.rsaCheck(request,alipay)) {
|
||||
//交易状态
|
||||
String tradeStatus = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"),"UTF-8");
|
||||
String tradeStatus = new String(request.getParameter("trade_status").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
// 商户订单号
|
||||
String outTradeNo = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
|
||||
String outTradeNo = new String(request.getParameter("out_trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
//支付宝交易号
|
||||
String tradeNo = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
|
||||
String tradeNo = new String(request.getParameter("trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
//付款金额
|
||||
String totalAmount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"),"UTF-8");
|
||||
String totalAmount = new String(request.getParameter("total_amount").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
//验证
|
||||
if(tradeStatus.equals(AliPayStatusEnum.SUCCESS.getValue())||tradeStatus.equals(AliPayStatusEnum.FINISHED.getValue())){
|
||||
/**
|
||||
* 验证通过后应该根据业务需要处理订单
|
||||
*/
|
||||
// 验证通过后应该根据业务需要处理订单
|
||||
}
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity(HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package co.yixiang.rest;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.aop.log.Log;
|
||||
import co.yixiang.domain.EmailConfig;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
import co.yixiang.domain.EmailConfig;
|
||||
import co.yixiang.service.EmailService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -17,32 +16,35 @@ import org.springframework.web.bind.annotation.*;
|
||||
* @author 郑杰
|
||||
* @date 2018/09/28 6:55:53
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
@Api(tags = "邮件")
|
||||
@RequestMapping("api/email")
|
||||
@Api(tags = "工具:邮件管理")
|
||||
public class EmailController {
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
private final EmailService emailService;
|
||||
|
||||
@GetMapping(value = "/email")
|
||||
public ResponseEntity get(){
|
||||
return new ResponseEntity(emailService.find(),HttpStatus.OK);
|
||||
public EmailController(EmailService emailService) {
|
||||
this.emailService = emailService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> get(){
|
||||
return new ResponseEntity<>(emailService.find(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("配置邮件")
|
||||
@PutMapping(value = "/email")
|
||||
public ResponseEntity emailConfig(@Validated @RequestBody EmailConfig emailConfig){
|
||||
@PutMapping
|
||||
@ApiOperation("配置邮件")
|
||||
public ResponseEntity<Object> emailConfig(@Validated @RequestBody EmailConfig emailConfig){
|
||||
emailService.update(emailConfig,emailService.find());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("发送邮件")
|
||||
@PostMapping(value = "/email")
|
||||
public ResponseEntity send(@Validated @RequestBody EmailVo emailVo) throws Exception {
|
||||
log.warn("REST request to send Email : {}" +emailVo);
|
||||
@PostMapping
|
||||
@ApiOperation("发送邮件")
|
||||
public ResponseEntity<Object> send(@Validated @RequestBody EmailVo emailVo) throws Exception {
|
||||
emailService.send(emailVo,emailService.find());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,8 @@ package co.yixiang.rest;
|
||||
|
||||
import co.yixiang.aop.log.Log;
|
||||
import co.yixiang.domain.LocalStorage;
|
||||
import co.yixiang.domain.Picture;
|
||||
import co.yixiang.service.LocalStorageService;
|
||||
import co.yixiang.service.dto.LocalStorageDTO;
|
||||
import co.yixiang.service.dto.LocalStorageQueryCriteria;
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -18,69 +13,59 @@ import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Api(tags = "本地存储管理")
|
||||
@Api(tags = "工具:本地存储管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
@RequestMapping("/api/localStorage")
|
||||
public class LocalStorageController {
|
||||
|
||||
@Autowired
|
||||
private LocalStorageService localStorageService;
|
||||
private final LocalStorageService localStorageService;
|
||||
|
||||
@Value("${file.localUrl}")
|
||||
private String localUrl;
|
||||
|
||||
|
||||
@ApiOperation(value = "查询文件")
|
||||
@GetMapping(value = "/localStorage")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_SELECT')")
|
||||
public ResponseEntity getLocalStorages(LocalStorageQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(localStorageService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
public LocalStorageController(LocalStorageService localStorageService) {
|
||||
this.localStorageService = localStorageService;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传文件")
|
||||
@PostMapping(value = "/localStorage")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_CREATE')")
|
||||
public ResponseEntity create(@RequestParam(value = "name",defaultValue = "") String name , @RequestParam("file") MultipartFile file){
|
||||
LocalStorageDTO storageDTO = localStorageService.create(name, file);
|
||||
String url = localUrl+"/file/"+storageDTO.getType()+"/"+storageDTO.getRealName();
|
||||
Map<String,Object> map = new HashMap<>(3);
|
||||
map.put("errno",0);
|
||||
map.put("data",new String[]{url});
|
||||
return new ResponseEntity(map,HttpStatus.CREATED);
|
||||
@ApiOperation("查询文件")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public ResponseEntity<Object> getLocalStorages(LocalStorageQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(localStorageService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改文件")
|
||||
@PutMapping(value = "/localStorage")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody LocalStorage resources){
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
public void download(HttpServletResponse response, LocalStorageQueryCriteria criteria) throws IOException {
|
||||
localStorageService.download(localStorageService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("上传文件")
|
||||
@PostMapping
|
||||
@PreAuthorize("@el.check('storage:add')")
|
||||
public ResponseEntity<Object> create(@RequestParam String name, @RequestParam("file") MultipartFile file){
|
||||
return new ResponseEntity<>(localStorageService.create(name, file),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ApiOperation("修改文件")
|
||||
@PutMapping
|
||||
@PreAuthorize("@el.check('storage:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody LocalStorage resources){
|
||||
localStorageService.update(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除文件")
|
||||
@DeleteMapping(value = "/localStorage/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
localStorageService.delete(id);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多张图片
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Log("删除图片")
|
||||
@DeleteMapping(value = "/localStorage")
|
||||
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
|
||||
@Log("多选删除")
|
||||
@DeleteMapping
|
||||
@ApiOperation("多选删除")
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
|
||||
localStorageService.deleteAll(ids);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -1,82 +1,76 @@
|
||||
package co.yixiang.rest;
|
||||
|
||||
import co.yixiang.aop.log.Log;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import co.yixiang.domain.Picture;
|
||||
import co.yixiang.service.PictureService;
|
||||
import co.yixiang.service.dto.PictureQueryCriteria;
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author 郑杰
|
||||
* @date 2018/09/20 14:13:32
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@Api(tags = "图床")
|
||||
@RequestMapping("/api/pictures")
|
||||
@Api(tags = "工具:免费图床管理")
|
||||
public class PictureController {
|
||||
|
||||
@Autowired
|
||||
private PictureService pictureService;
|
||||
private final PictureService pictureService;
|
||||
|
||||
public PictureController(PictureService pictureService) {
|
||||
this.pictureService = pictureService;
|
||||
}
|
||||
|
||||
@Log("查询图片")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_SELECT')")
|
||||
@GetMapping(value = "/pictures")
|
||||
public ResponseEntity getRoles(PictureQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(pictureService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
@PreAuthorize("@el.check('pictures:list')")
|
||||
@GetMapping
|
||||
@ApiOperation("查询图片")
|
||||
public ResponseEntity<Object> getRoles(PictureQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(pictureService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('pictures:list')")
|
||||
public void download(HttpServletResponse response, PictureQueryCriteria criteria) throws IOException {
|
||||
pictureService.download(pictureService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @param file
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Log("上传图片")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_UPLOAD')")
|
||||
@PostMapping(value = "/pictures")
|
||||
public ResponseEntity upload(@RequestParam MultipartFile file){
|
||||
@PreAuthorize("@el.check('pictures:add')")
|
||||
@PostMapping
|
||||
@ApiOperation("上传图片")
|
||||
public ResponseEntity<Object> upload(@RequestParam MultipartFile file){
|
||||
String userName = SecurityUtils.getUsername();
|
||||
Picture picture = pictureService.upload(file,userName);
|
||||
Map<String,Object> map = new HashMap<>(3);
|
||||
map.put("errno",0);
|
||||
map.put("id",picture.getId());
|
||||
map.put("data",new String[]{picture.getUrl()});
|
||||
return new ResponseEntity(map,HttpStatus.OK);
|
||||
return new ResponseEntity<>(picture,HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Log("删除图片")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')")
|
||||
@DeleteMapping(value = "/pictures/{id}")
|
||||
public ResponseEntity delete(@PathVariable Long id) {
|
||||
pictureService.delete(pictureService.findById(id));
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
@Log("同步图床数据")
|
||||
@ApiOperation("同步图床数据")
|
||||
@PostMapping(value = "/synchronize")
|
||||
public ResponseEntity<Object> synchronize(){
|
||||
pictureService.synchronize();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多张图片
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Log("删除图片")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')")
|
||||
@DeleteMapping(value = "/pictures")
|
||||
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
|
||||
@Log("多选删除图片")
|
||||
@ApiOperation("多选删除图片")
|
||||
@PreAuthorize("@el.check('pictures:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
|
||||
pictureService.deleteAll(ids);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
package co.yixiang.rest;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.aop.log.Log;
|
||||
import co.yixiang.domain.QiniuConfig;
|
||||
import co.yixiang.domain.QiniuContent;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.service.QiNiuService;
|
||||
import co.yixiang.service.dto.QiniuQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -28,101 +29,91 @@ import java.util.Map;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
@Api(tags = "七牛")
|
||||
@RequestMapping("/api/qiNiuContent")
|
||||
@Api(tags = "工具:七牛云存储管理")
|
||||
public class QiniuController {
|
||||
|
||||
@Autowired
|
||||
private QiNiuService qiNiuService;
|
||||
private final QiNiuService qiNiuService;
|
||||
|
||||
@GetMapping(value = "/qiNiuConfig")
|
||||
public ResponseEntity get(){
|
||||
return new ResponseEntity(qiNiuService.find(), HttpStatus.OK);
|
||||
public QiniuController(QiNiuService qiNiuService) {
|
||||
this.qiNiuService = qiNiuService;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/config")
|
||||
public ResponseEntity<Object> get(){
|
||||
return new ResponseEntity<>(qiNiuService.find(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("配置七牛云存储")
|
||||
@PutMapping(value = "/qiNiuConfig")
|
||||
public ResponseEntity emailConfig(@Validated @RequestBody QiniuConfig qiniuConfig){
|
||||
@ApiOperation("配置七牛云存储")
|
||||
@PutMapping(value = "/config")
|
||||
public ResponseEntity<Object> emailConfig(@Validated @RequestBody QiniuConfig qiniuConfig){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
qiNiuService.update(qiniuConfig);
|
||||
qiNiuService.update(qiniuConfig.getType());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
public void download(HttpServletResponse response, QiniuQueryCriteria criteria) throws IOException {
|
||||
qiNiuService.downloadList(qiNiuService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询文件")
|
||||
@GetMapping(value = "/qiNiuContent")
|
||||
public ResponseEntity getRoles(QiniuQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(qiNiuService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
@ApiOperation("查询文件")
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> getRoles(QiniuQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(qiNiuService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到七牛云
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@Log("上传文件")
|
||||
@PostMapping(value = "/qiNiuContent")
|
||||
public ResponseEntity upload(@RequestParam MultipartFile file){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
@ApiOperation("上传文件")
|
||||
@PostMapping
|
||||
public ResponseEntity<Object> upload(@RequestParam MultipartFile file){
|
||||
QiniuContent qiniuContent = qiNiuService.upload(file,qiNiuService.find());
|
||||
Map map = new HashMap(3);
|
||||
Map<String,Object> map = new HashMap<>(3);
|
||||
map.put("id",qiniuContent.getId());
|
||||
map.put("errno",0);
|
||||
map.put("data",new String[]{qiniuContent.getUrl()});
|
||||
return new ResponseEntity(map,HttpStatus.OK);
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步七牛云数据到数据库
|
||||
* @return
|
||||
*/
|
||||
@Log("同步七牛云数据")
|
||||
@PostMapping(value = "/qiNiuContent/synchronize")
|
||||
public ResponseEntity synchronize(){
|
||||
log.warn("REST request to synchronize qiNiu : {}");
|
||||
qiNiuService.synchronize(qiNiuService.find());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载七牛云文件
|
||||
* @param id
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Log("下载文件")
|
||||
@GetMapping(value = "/qiNiuContent/download/{id}")
|
||||
public ResponseEntity download(@PathVariable Long id){
|
||||
@ApiOperation("同步七牛云数据")
|
||||
@PostMapping(value = "/synchronize")
|
||||
public ResponseEntity<Object> synchronize(){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
Map map = new HashMap(1);
|
||||
map.put("url", qiNiuService.download(qiNiuService.findByContentId(id),qiNiuService.find()));
|
||||
return new ResponseEntity(map,HttpStatus.OK);
|
||||
qiNiuService.synchronize(qiNiuService.find());
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("下载文件")
|
||||
@ApiOperation("下载文件")
|
||||
@GetMapping(value = "/download/{id}")
|
||||
public ResponseEntity<Object> download(@PathVariable Long id){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
Map<String,Object> map = new HashMap<>(1);
|
||||
map.put("url", qiNiuService.download(qiNiuService.findByContentId(id),qiNiuService.find()));
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除七牛云文件
|
||||
* @param id
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Log("删除文件")
|
||||
@DeleteMapping(value = "/qiNiuContent/{id}")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
@ApiOperation("删除文件")
|
||||
@DeleteMapping(value = "/{id}")
|
||||
public ResponseEntity<Object> delete(@PathVariable Long id){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
qiNiuService.delete(qiNiuService.findByContentId(id),qiNiuService.find());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多张图片
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Log("删除图片")
|
||||
@DeleteMapping(value = "/qiNiuContent")
|
||||
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
|
||||
@Log("删除多张图片")
|
||||
@ApiOperation("删除多张图片")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
qiNiuService.deleteAll(ids, qiNiuService.find());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package co.yixiang.rest;
|
||||
|
||||
import co.yixiang.utils.YshopConstant;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import co.yixiang.domain.VerificationCode;
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
import co.yixiang.service.EmailService;
|
||||
import co.yixiang.service.VerificationCodeService;
|
||||
import co.yixiang.utils.ElAdminConstant;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
@ -18,42 +16,44 @@ import org.springframework.web.bind.annotation.*;
|
||||
* @date 2018-12-26
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
@Api(tags = "验证")
|
||||
@RequestMapping("/api/code")
|
||||
@Api(tags = "工具:验证码管理")
|
||||
public class VerificationCodeController {
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeService verificationCodeService;
|
||||
private final VerificationCodeService verificationCodeService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("jwtUserDetailsService")
|
||||
private UserDetailsService userDetailsService;
|
||||
private final EmailService emailService;
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
@PostMapping(value = "/code/resetEmail")
|
||||
public ResponseEntity resetEmail(@RequestBody VerificationCode code) throws Exception {
|
||||
code.setScenes(ElAdminConstant.RESET_MAIL);
|
||||
EmailVo emailVo = verificationCodeService.sendEmail(code);
|
||||
emailService.send(emailVo,emailService.find());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
public VerificationCodeController(VerificationCodeService verificationCodeService, EmailService emailService) {
|
||||
this.verificationCodeService = verificationCodeService;
|
||||
this.emailService = emailService;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/code/email/resetPass")
|
||||
public ResponseEntity resetPass(@RequestParam String email) throws Exception {
|
||||
@PostMapping(value = "/resetEmail")
|
||||
@ApiOperation("重置邮箱,发送验证码")
|
||||
public ResponseEntity<Object> resetEmail(@RequestBody VerificationCode code) throws Exception {
|
||||
code.setScenes(YshopConstant.RESET_MAIL);
|
||||
EmailVo emailVo = verificationCodeService.sendEmail(code);
|
||||
emailService.send(emailVo,emailService.find());
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/email/resetPass")
|
||||
@ApiOperation("重置密码,发送验证码")
|
||||
public ResponseEntity<Object> resetPass(@RequestParam String email) throws Exception {
|
||||
VerificationCode code = new VerificationCode();
|
||||
code.setType("email");
|
||||
code.setValue(email);
|
||||
code.setScenes(ElAdminConstant.RESET_MAIL);
|
||||
code.setScenes(YshopConstant.RESET_MAIL);
|
||||
EmailVo emailVo = verificationCodeService.sendEmail(code);
|
||||
emailService.send(emailVo,emailService.find());
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/code/validated")
|
||||
public ResponseEntity validated(VerificationCode code){
|
||||
@GetMapping(value = "/validated")
|
||||
@ApiOperation("验证码验证")
|
||||
public ResponseEntity<Object> validated(VerificationCode code){
|
||||
verificationCodeService.validated(code);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -2,47 +2,41 @@ package co.yixiang.service;
|
||||
|
||||
import co.yixiang.domain.AlipayConfig;
|
||||
import co.yixiang.domain.vo.TradeVo;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-31
|
||||
*/
|
||||
@CacheConfig(cacheNames = "alipay")
|
||||
public interface AlipayService {
|
||||
|
||||
/**
|
||||
* 处理来自PC的交易请求
|
||||
* @param alipay
|
||||
* @param trade
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @param alipay 支付宝配置
|
||||
* @param trade 交易详情
|
||||
* @return String
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
String toPayAsPC(AlipayConfig alipay, TradeVo trade) throws Exception;
|
||||
String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception;
|
||||
|
||||
/**
|
||||
* 处理来自手机网页的交易请求
|
||||
* @param alipay
|
||||
* @param trade
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @param alipay 支付宝配置
|
||||
* @param trade 交易详情
|
||||
* @return String
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
String toPayAsWeb(AlipayConfig alipay, TradeVo trade) throws Exception;
|
||||
|
||||
/**
|
||||
* 查询配置
|
||||
* @return
|
||||
* @return AlipayConfig
|
||||
*/
|
||||
@Cacheable(key = "'1'")
|
||||
AlipayConfig find();
|
||||
|
||||
/**
|
||||
* 更新配置
|
||||
* @param alipayConfig
|
||||
* @return
|
||||
* @param alipayConfig 支付宝配置
|
||||
* @return AlipayConfig
|
||||
*/
|
||||
@CachePut(key = "'1'")
|
||||
AlipayConfig update(AlipayConfig alipayConfig);
|
||||
}
|
||||
|
@ -1,40 +1,34 @@
|
||||
package co.yixiang.service;
|
||||
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
import co.yixiang.domain.EmailConfig;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-26
|
||||
*/
|
||||
@CacheConfig(cacheNames = "email")
|
||||
public interface EmailService {
|
||||
|
||||
/**
|
||||
* 更新邮件配置
|
||||
* @param emailConfig
|
||||
* @param old
|
||||
* @return
|
||||
* @param emailConfig 邮件配置
|
||||
* @param old 旧的配置
|
||||
* @return EmailConfig
|
||||
*/
|
||||
@CachePut(key = "'1'")
|
||||
EmailConfig update(EmailConfig emailConfig, EmailConfig old);
|
||||
|
||||
/**
|
||||
* 查询配置
|
||||
* @return
|
||||
* @return EmailConfig 邮件配置
|
||||
*/
|
||||
@Cacheable(key = "'1'")
|
||||
EmailConfig find();
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
* @param emailVo
|
||||
* @param emailConfig
|
||||
* @throws Exception
|
||||
* @param emailVo 邮件发送的内容
|
||||
* @param emailConfig 邮件配置
|
||||
* @throws Exception /
|
||||
*/
|
||||
@Async
|
||||
void send(EmailVo emailVo, EmailConfig emailConfig) throws Exception;
|
||||
|
@ -3,67 +3,65 @@ package co.yixiang.service;
|
||||
import co.yixiang.domain.LocalStorage;
|
||||
import co.yixiang.service.dto.LocalStorageDTO;
|
||||
import co.yixiang.service.dto.LocalStorageQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@CacheConfig(cacheNames = "localStorage")
|
||||
public interface LocalStorageService {
|
||||
|
||||
/**
|
||||
* queryAll 分页
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll 不分页
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable
|
||||
public Object queryAll(LocalStorageQueryCriteria criteria);
|
||||
* 查询全部数据
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<LocalStorageDTO> queryAll(LocalStorageQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* findById
|
||||
* @param id
|
||||
* @return
|
||||
* 根据ID查询
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
@Cacheable(key = "#p0")
|
||||
LocalStorageDTO findById(Long id);
|
||||
|
||||
/**
|
||||
* create
|
||||
* @param name
|
||||
* @param file
|
||||
* @return
|
||||
* 上传
|
||||
* @param name 文件名称
|
||||
* @param file 文件
|
||||
* @return /
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
LocalStorageDTO create(String name, MultipartFile file);
|
||||
|
||||
/**
|
||||
* update
|
||||
* @param resources
|
||||
* 编辑
|
||||
* @param resources 文件信息
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void update(LocalStorage resources);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* @param id
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
|
||||
@CacheEvict(allEntries = true)
|
||||
void deleteAll(Long[] ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param localStorageDtos 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<LocalStorageDTO> localStorageDtos, HttpServletResponse response) throws IOException;
|
||||
}
|
@ -2,55 +2,65 @@ package co.yixiang.service;
|
||||
|
||||
import co.yixiang.domain.Picture;
|
||||
import co.yixiang.service.dto.PictureQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-27
|
||||
*/
|
||||
@CacheConfig(cacheNames = "picture")
|
||||
public interface PictureService {
|
||||
|
||||
/**
|
||||
* 查询图片
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
@Cacheable
|
||||
Object queryAll(PictureQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @param file
|
||||
* @param username
|
||||
* @return
|
||||
* 查询全部数据
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<Picture> queryAll(PictureQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file /
|
||||
* @param username /
|
||||
* @return /
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
Picture upload(MultipartFile file, String username);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id
|
||||
* @return
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
@Cacheable(key = "#p0")
|
||||
Picture findById(Long id);
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
* @param picture
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Picture picture);
|
||||
void deleteAll(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
* @param ids
|
||||
* 导出
|
||||
* @param queryAll 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void deleteAll(Long[] ids);
|
||||
void download(List<Picture> queryAll, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
*/
|
||||
void synchronize();
|
||||
}
|
||||
|
@ -3,93 +3,101 @@ package co.yixiang.service;
|
||||
import co.yixiang.domain.QiniuConfig;
|
||||
import co.yixiang.domain.QiniuContent;
|
||||
import co.yixiang.service.dto.QiniuQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-31
|
||||
*/
|
||||
@CacheConfig(cacheNames = "qiNiu")
|
||||
public interface QiNiuService {
|
||||
|
||||
/**
|
||||
* 查询文件
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
@Cacheable
|
||||
Object queryAll(QiniuQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查配置
|
||||
* @return
|
||||
* 查询全部
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<QiniuContent> queryAll(QiniuQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 查配置
|
||||
* @return QiniuConfig
|
||||
*/
|
||||
@Cacheable(cacheNames = "qiNiuConfig", key = "'1'")
|
||||
QiniuConfig find();
|
||||
|
||||
/**
|
||||
* 修改配置
|
||||
* @param qiniuConfig
|
||||
* @return
|
||||
* @param qiniuConfig 配置
|
||||
* @return QiniuConfig
|
||||
*/
|
||||
@CachePut(cacheNames = "qiNiuConfig", key = "'1'")
|
||||
QiniuConfig update(QiniuConfig qiniuConfig);
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file
|
||||
* @param qiniuConfig
|
||||
* @return
|
||||
* @param file 文件
|
||||
* @param qiniuConfig 配置
|
||||
* @return QiniuContent
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig);
|
||||
|
||||
/**
|
||||
* 查询文件
|
||||
* @param id
|
||||
* @return
|
||||
* @param id 文件ID
|
||||
* @return QiniuContent
|
||||
*/
|
||||
@Cacheable(key = "'content:'+#p0")
|
||||
QiniuContent findByContentId(Long id);
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param content
|
||||
* @param config
|
||||
* @return
|
||||
* @param content 文件信息
|
||||
* @param config 配置
|
||||
* @return String
|
||||
*/
|
||||
String download(QiniuContent content, QiniuConfig config);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param content
|
||||
* @param config
|
||||
* @return
|
||||
* @param content 文件
|
||||
* @param config 配置
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(QiniuContent content, QiniuConfig config);
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
* @param config
|
||||
* @param config 配置
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void synchronize(QiniuConfig config);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param ids
|
||||
* @param config
|
||||
* @param ids 文件ID数组
|
||||
* @param config 配置
|
||||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void deleteAll(Long[] ids, QiniuConfig config);
|
||||
|
||||
@CacheEvict(allEntries = true)
|
||||
/**
|
||||
* 更新数据
|
||||
* @param type 类型
|
||||
*/
|
||||
void update(String type);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param queryAll /
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadList(List<QiniuContent> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package co.yixiang.service;
|
||||
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
import co.yixiang.domain.VerificationCode;
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@ -11,13 +11,14 @@ public interface VerificationCodeService {
|
||||
|
||||
/**
|
||||
* 发送邮件验证码
|
||||
* @param code
|
||||
* @param code 验证码
|
||||
* @return EmailVo
|
||||
*/
|
||||
EmailVo sendEmail(VerificationCode code);
|
||||
|
||||
/**
|
||||
* 验证
|
||||
* @param code
|
||||
* @param code 验证码
|
||||
*/
|
||||
void validated(VerificationCode code);
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package co.yixiang.service.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@ -13,29 +11,19 @@ import java.io.Serializable;
|
||||
@Data
|
||||
public class LocalStorageDTO implements Serializable {
|
||||
|
||||
// ID
|
||||
private Long id;
|
||||
|
||||
private String realName;
|
||||
|
||||
// 文件名
|
||||
private String name;
|
||||
|
||||
// 后缀
|
||||
private String suffix;
|
||||
|
||||
// 类型
|
||||
private String type;
|
||||
|
||||
// 大小
|
||||
private String size;
|
||||
|
||||
// 操作人
|
||||
private String operate;
|
||||
|
||||
// 创建日期
|
||||
private Timestamp createTime;
|
||||
|
||||
// 修改日期
|
||||
private Timestamp updateTime;
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package co.yixiang.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import co.yixiang.annotation.Query;
|
||||
|
||||
/**
|
||||
@ -10,7 +13,9 @@ import co.yixiang.annotation.Query;
|
||||
@Data
|
||||
public class LocalStorageQueryCriteria{
|
||||
|
||||
// 模糊
|
||||
@Query(blurry = "name,suffix,type,operate,size")
|
||||
private String blurry;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
@ -3,6 +3,9 @@ package co.yixiang.service.dto;
|
||||
import lombok.Data;
|
||||
import co.yixiang.annotation.Query;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* sm.ms图床
|
||||
*
|
||||
@ -17,4 +20,7 @@ public class PictureQueryCriteria{
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String username;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ package co.yixiang.service.dto;
|
||||
import lombok.Data;
|
||||
import co.yixiang.annotation.Query;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-6-4 09:54:37
|
||||
@ -12,4 +15,7 @@ public class QiniuQueryCriteria{
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String key;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
||||
|
@ -2,18 +2,20 @@ package co.yixiang.service.impl;
|
||||
|
||||
import co.yixiang.domain.AlipayConfig;
|
||||
import co.yixiang.domain.vo.TradeVo;
|
||||
import co.yixiang.utils.AlipayUtils;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.repository.AlipayRepository;
|
||||
import co.yixiang.service.AlipayService;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipayTradePagePayRequest;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.repository.AlipayRepository;
|
||||
import co.yixiang.service.AlipayService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -21,38 +23,32 @@ import java.util.Optional;
|
||||
* @date 2018-12-31
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "alipay")
|
||||
@SuppressWarnings("all")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class AlipayServiceImpl implements AlipayService {
|
||||
|
||||
@Autowired
|
||||
AlipayUtils alipayUtils;
|
||||
private final AlipayRepository alipayRepository;
|
||||
|
||||
@Autowired
|
||||
private AlipayRepository alipayRepository;
|
||||
public AlipayServiceImpl(AlipayRepository alipayRepository) {
|
||||
this.alipayRepository = alipayRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toPayAsPC(AlipayConfig alipay, TradeVo trade) throws Exception {
|
||||
public String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception {
|
||||
|
||||
if(alipay.getId() == null){
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppID(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
|
||||
|
||||
double money = Double.parseDouble(trade.getTotalAmount());
|
||||
|
||||
/**
|
||||
* 创建API对应的request(电脑网页版)
|
||||
*/
|
||||
// 创建API对应的request(电脑网页版)
|
||||
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
||||
|
||||
/**
|
||||
* 订单完成后返回的页面和异步通知地址
|
||||
*/
|
||||
// 订单完成后返回的页面和异步通知地址
|
||||
request.setReturnUrl(alipay.getReturnUrl());
|
||||
request.setNotifyUrl(alipay.getNotifyUrl());
|
||||
/**
|
||||
* 填充订单参数
|
||||
*/
|
||||
// 填充订单参数
|
||||
request.setBizContent("{" +
|
||||
" \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," +
|
||||
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
|
||||
@ -63,10 +59,7 @@ public class AlipayServiceImpl implements AlipayService {
|
||||
" \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" +
|
||||
" }"+
|
||||
" }");//填充业务参数
|
||||
/**
|
||||
* 调用SDK生成表单
|
||||
* 通过GET方式,口可以获取url
|
||||
*/
|
||||
// 调用SDK生成表单, 通过GET方式,口可以获取url
|
||||
return alipayClient.pageExecute(request, "GET").getBody();
|
||||
|
||||
}
|
||||
@ -76,26 +69,17 @@ public class AlipayServiceImpl implements AlipayService {
|
||||
if(alipay.getId() == null){
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppID(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
|
||||
|
||||
double money = Double.parseDouble(trade.getTotalAmount());
|
||||
if(money <= 0 || money >= 5000){
|
||||
double maxMoney = 5000;
|
||||
if(money <= 0 || money >= maxMoney){
|
||||
throw new BadRequestException("测试金额过大");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建API对应的request(手机网页版)
|
||||
*/
|
||||
// 创建API对应的request(手机网页版)
|
||||
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
|
||||
|
||||
/**
|
||||
* 订单完成后返回的页面和异步通知地址
|
||||
*/
|
||||
request.setReturnUrl(alipay.getReturnUrl());
|
||||
request.setNotifyUrl(alipay.getNotifyUrl());
|
||||
/**
|
||||
* 填充订单参数
|
||||
*/
|
||||
request.setBizContent("{" +
|
||||
" \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," +
|
||||
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
|
||||
@ -105,25 +89,19 @@ public class AlipayServiceImpl implements AlipayService {
|
||||
" \"extend_params\":{" +
|
||||
" \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" +
|
||||
" }"+
|
||||
" }");//填充业务参数
|
||||
/**
|
||||
* 调用SDK生成表单
|
||||
* 通过GET方式,口可以获取url
|
||||
*/
|
||||
" }");
|
||||
return alipayClient.pageExecute(request, "GET").getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "'1'")
|
||||
public AlipayConfig find() {
|
||||
Optional<AlipayConfig> alipayConfig = alipayRepository.findById(1L);
|
||||
if (alipayConfig.isPresent()){
|
||||
return alipayConfig.get();
|
||||
} else {
|
||||
return new AlipayConfig();
|
||||
}
|
||||
return alipayConfig.orElseGet(AlipayConfig::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(key = "'1'")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AlipayConfig update(AlipayConfig alipayConfig) {
|
||||
return alipayRepository.save(alipayConfig);
|
||||
|
@ -4,11 +4,13 @@ import cn.hutool.extra.mail.Mail;
|
||||
import cn.hutool.extra.mail.MailAccount;
|
||||
import co.yixiang.domain.EmailConfig;
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
import co.yixiang.repository.EmailRepository;
|
||||
import co.yixiang.service.EmailService;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.repository.EmailRepository;
|
||||
import co.yixiang.utils.EncryptUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -19,13 +21,18 @@ import java.util.Optional;
|
||||
* @date 2018-12-26
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "email")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class EmailServiceImpl implements EmailService {
|
||||
|
||||
@Autowired
|
||||
private EmailRepository emailRepository;
|
||||
private final EmailRepository emailRepository;
|
||||
|
||||
public EmailServiceImpl(EmailRepository emailRepository) {
|
||||
this.emailRepository = emailRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(key = "'1'")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public EmailConfig update(EmailConfig emailConfig, EmailConfig old) {
|
||||
try {
|
||||
@ -40,13 +47,10 @@ public class EmailServiceImpl implements EmailService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "'1'")
|
||||
public EmailConfig find() {
|
||||
Optional<EmailConfig> emailConfig = emailRepository.findById(1L);
|
||||
if(emailConfig.isPresent()){
|
||||
return emailConfig.get();
|
||||
} else {
|
||||
return new EmailConfig();
|
||||
}
|
||||
return emailConfig.orElseGet(EmailConfig::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,9 +59,7 @@ public class EmailServiceImpl implements EmailService {
|
||||
if(emailConfig == null){
|
||||
throw new BadRequestException("请先配置,再操作");
|
||||
}
|
||||
/**
|
||||
* 封装
|
||||
*/
|
||||
// 封装
|
||||
MailAccount account = new MailAccount();
|
||||
account.setHost(emailConfig.getHost());
|
||||
account.setPort(Integer.parseInt(emailConfig.getPort()));
|
||||
@ -69,15 +71,14 @@ public class EmailServiceImpl implements EmailService {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
account.setFrom(emailConfig.getUser()+"<"+emailConfig.getFromUser()+">");
|
||||
//ssl方式发送
|
||||
// ssl方式发送
|
||||
account.setSslEnable(true);
|
||||
String content = emailVo.getContent();
|
||||
/**
|
||||
* 发送
|
||||
*/
|
||||
// 发送
|
||||
try {
|
||||
int size = emailVo.getTos().size();
|
||||
Mail.create(account)
|
||||
.setTos(emailVo.getTos().toArray(new String[emailVo.getTos().size()]))
|
||||
.setTos(emailVo.getTos().toArray(new String[size]))
|
||||
.setTitle(emailVo.getSubject())
|
||||
.setContent(content)
|
||||
.setHtml(true)
|
||||
|
@ -1,39 +1,45 @@
|
||||
package co.yixiang.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import co.yixiang.domain.LocalStorage;
|
||||
import co.yixiang.service.LocalStorageService;
|
||||
import co.yixiang.utils.*;
|
||||
import co.yixiang.utils.*;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.repository.LocalStorageRepository;
|
||||
import co.yixiang.service.LocalStorageService;
|
||||
import co.yixiang.service.dto.LocalStorageDTO;
|
||||
import co.yixiang.service.dto.LocalStorageQueryCriteria;
|
||||
import co.yixiang.service.mapper.LocalStorageMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import co.yixiang.utils.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "localStorage")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class LocalStorageServiceImpl implements LocalStorageService {
|
||||
|
||||
@Autowired
|
||||
private LocalStorageRepository localStorageRepository;
|
||||
|
||||
@Autowired
|
||||
private LocalStorageMapper localStorageMapper;
|
||||
private final LocalStorageRepository localStorageRepository;
|
||||
|
||||
private final LocalStorageMapper localStorageMapper;
|
||||
|
||||
@Value("${file.path}")
|
||||
private String path;
|
||||
@ -41,33 +47,43 @@ public class LocalStorageServiceImpl implements LocalStorageService {
|
||||
@Value("${file.maxSize}")
|
||||
private long maxSize;
|
||||
|
||||
public LocalStorageServiceImpl(LocalStorageRepository localStorageRepository, LocalStorageMapper localStorageMapper) {
|
||||
this.localStorageRepository = localStorageRepository;
|
||||
this.localStorageMapper = localStorageMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable
|
||||
public Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable){
|
||||
Page<LocalStorage> page = localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(localStorageMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(LocalStorageQueryCriteria criteria){
|
||||
@Cacheable
|
||||
public List<LocalStorageDTO> queryAll(LocalStorageQueryCriteria criteria){
|
||||
return localStorageMapper.toDto(localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalStorageDTO findById(Long id) {
|
||||
Optional<LocalStorage> localStorage = localStorageRepository.findById(id);
|
||||
ValidationUtil.isNull(localStorage,"LocalStorage","id",id);
|
||||
return localStorageMapper.toDto(localStorage.get());
|
||||
@Cacheable(key = "#p0")
|
||||
public LocalStorageDTO findById(Long id){
|
||||
LocalStorage localStorage = localStorageRepository.findById(id).orElseGet(LocalStorage::new);
|
||||
ValidationUtil.isNull(localStorage.getId(),"LocalStorage","id",id);
|
||||
return localStorageMapper.toDto(localStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public LocalStorageDTO create(String name, MultipartFile multipartFile) {
|
||||
FileUtil.checkSize(maxSize, multipartFile.getSize());
|
||||
String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
|
||||
// 可自行选择方式
|
||||
// String type = FileUtil.getFileTypeByMimeType(suffix);
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
File file = FileUtil.upload(multipartFile, path + type + File.separator);
|
||||
if(ObjectUtil.isNull(file)){
|
||||
throw new BadRequestException("上传失败");
|
||||
}
|
||||
try {
|
||||
name = StringUtils.isBlank(name) ? FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) : name;
|
||||
LocalStorage localStorage = new LocalStorage(
|
||||
@ -86,36 +102,40 @@ public class LocalStorageServiceImpl implements LocalStorageService {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
File file = new File("C:\\Users\\Jie\\Pictures\\Saved Pictures\\demo1.jpg");
|
||||
System.out.println(FileUtil.getType(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(LocalStorage resources) {
|
||||
Optional<LocalStorage> optionalLocalStorage = localStorageRepository.findById(resources.getId());
|
||||
ValidationUtil.isNull( optionalLocalStorage,"LocalStorage","id",resources.getId());
|
||||
LocalStorage localStorage = optionalLocalStorage.get();
|
||||
LocalStorage localStorage = localStorageRepository.findById(resources.getId()).orElseGet(LocalStorage::new);
|
||||
ValidationUtil.isNull( localStorage.getId(),"LocalStorage","id",resources.getId());
|
||||
localStorage.copy(resources);
|
||||
localStorageRepository.save(localStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
LocalStorage storage = localStorageRepository.findById(id).get();
|
||||
FileUtil.del(storage.getPath());
|
||||
localStorageRepository.delete(storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
LocalStorage storage = localStorageRepository.findById(id).get();
|
||||
LocalStorage storage = localStorageRepository.findById(id).orElseGet(LocalStorage::new);
|
||||
FileUtil.del(storage.getPath());
|
||||
localStorageRepository.delete(storage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<LocalStorageDTO> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (LocalStorageDTO localStorageDTO : queryAll) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("文件名", localStorageDTO.getRealName());
|
||||
map.put("备注名", localStorageDTO.getName());
|
||||
map.put("文件类型", localStorageDTO.getType());
|
||||
map.put("文件大小", localStorageDTO.getSize());
|
||||
map.put("操作人", localStorageDTO.getOperate());
|
||||
map.put("创建日期", localStorageDTO.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package co.yixiang.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@ -8,19 +9,20 @@ import co.yixiang.service.dto.PictureQueryCriteria;
|
||||
import co.yixiang.utils.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.repository.PictureRepository;
|
||||
import co.yixiang.service.PictureService;
|
||||
import co.yixiang.utils.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@ -28,41 +30,60 @@ import java.util.Optional;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service(value = "pictureService")
|
||||
@CacheConfig(cacheNames = "picture")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class PictureServiceImpl implements PictureService {
|
||||
|
||||
@Autowired
|
||||
private PictureRepository pictureRepository;
|
||||
@Value("${smms.token}")
|
||||
private String token;
|
||||
|
||||
public static final String SUCCESS = "success";
|
||||
private final PictureRepository pictureRepository;
|
||||
|
||||
public static final String CODE = "code";
|
||||
private static final String SUCCESS = "success";
|
||||
|
||||
public static final String MSG = "message";
|
||||
private static final String CODE = "code";
|
||||
|
||||
private static final String MSG = "message";
|
||||
|
||||
public PictureServiceImpl(PictureRepository pictureRepository) {
|
||||
this.pictureRepository = pictureRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(PictureQueryCriteria criteria, Pageable pageable){
|
||||
return PageUtil.toPage(pictureRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Picture> queryAll(PictureQueryCriteria criteria) {
|
||||
return pictureRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public Picture upload(MultipartFile multipartFile, String username) {
|
||||
File file = FileUtil.toFile(multipartFile);
|
||||
// 验证是否重复上传
|
||||
Picture picture = pictureRepository.findByMd5Code(FileUtil.getMd5(file));
|
||||
if(picture != null){
|
||||
return picture;
|
||||
}
|
||||
HashMap<String, Object> paramMap = new HashMap<>(1);
|
||||
|
||||
paramMap.put("smfile", file);
|
||||
String result= HttpUtil.post(ElAdminConstant.Url.SM_MS_URL, paramMap);
|
||||
|
||||
// 上传文件
|
||||
String result= HttpRequest.post(YshopConstant.Url.SM_MS_URL + "/v2/upload")
|
||||
.header("Authorization", token)
|
||||
.form(paramMap)
|
||||
.timeout(20000)
|
||||
.execute().body();
|
||||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||
Picture picture = null;
|
||||
if(!jsonObject.get(CODE).toString().equals(SUCCESS)){
|
||||
throw new BadRequestException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
|
||||
}
|
||||
//转成实体类
|
||||
picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
|
||||
picture.setSize(FileUtil.getSize(Integer.valueOf(picture.getSize())));
|
||||
picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
|
||||
picture.setUsername(username);
|
||||
picture.setMd5Code(FileUtil.getMd5(file));
|
||||
picture.setFilename(FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename())+"."+FileUtil.getExtensionName(multipartFile.getOriginalFilename()));
|
||||
pictureRepository.save(picture);
|
||||
//删除临时文件
|
||||
@ -73,27 +94,59 @@ public class PictureServiceImpl implements PictureService {
|
||||
|
||||
@Override
|
||||
public Picture findById(Long id) {
|
||||
Optional<Picture> picture = pictureRepository.findById(id);
|
||||
ValidationUtil.isNull(picture,"Picture","id",id);
|
||||
return picture.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Picture picture) {
|
||||
try {
|
||||
String result= HttpUtil.get(picture.getDelete());
|
||||
pictureRepository.delete(picture);
|
||||
} catch(Exception e){
|
||||
pictureRepository.delete(picture);
|
||||
}
|
||||
|
||||
Picture picture = pictureRepository.findById(id).orElseGet(Picture::new);
|
||||
ValidationUtil.isNull(picture.getId(),"Picture","id",id);
|
||||
return picture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
delete(findById(id));
|
||||
Picture picture = findById(id);
|
||||
try {
|
||||
HttpUtil.get(picture.getDelete());
|
||||
pictureRepository.delete(picture);
|
||||
} catch(Exception e){
|
||||
pictureRepository.delete(picture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void synchronize() {
|
||||
//链式构建请求
|
||||
String result = HttpRequest.get(YshopConstant.Url.SM_MS_URL + "/v2/upload_history")
|
||||
//头信息,多个头信息多次调用此方法即可
|
||||
.header("Authorization", token)
|
||||
.timeout(20000)
|
||||
.execute().body();
|
||||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||
List<Picture> pictures = JSON.parseArray(jsonObject.get("data").toString(), Picture.class);
|
||||
for (Picture picture : pictures) {
|
||||
if(!pictureRepository.existsByUrl(picture.getUrl())){
|
||||
picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
|
||||
picture.setUsername("System Sync");
|
||||
picture.setMd5Code("");
|
||||
pictureRepository.save(picture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<Picture> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Picture picture : queryAll) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("文件名", picture.getFilename());
|
||||
map.put("图片地址", picture.getUrl());
|
||||
map.put("文件大小", picture.getSize());
|
||||
map.put("操作人", picture.getUsername());
|
||||
map.put("高度", picture.getHeight());
|
||||
map.put("宽度", picture.getWidth());
|
||||
map.put("删除地址", picture.getDelete());
|
||||
map.put("创建日期", picture.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,9 @@ package co.yixiang.service.impl;
|
||||
|
||||
import co.yixiang.domain.QiniuConfig;
|
||||
import co.yixiang.domain.QiniuContent;
|
||||
import co.yixiang.repository.QiniuContentRepository;
|
||||
import co.yixiang.service.QiNiuService;
|
||||
import co.yixiang.service.dto.QiniuQueryCriteria;
|
||||
import co.yixiang.utils.*;
|
||||
import co.yixiang.utils.QiNiuUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.Gson;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
@ -16,56 +13,73 @@ import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.util.Auth;
|
||||
import co.yixiang.repository.QiniuContentRepository;
|
||||
import co.yixiang.service.dto.QiniuQueryCriteria;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.repository.QiNiuConfigRepository;
|
||||
import co.yixiang.utils.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import co.yixiang.utils.FileUtil;
|
||||
import co.yixiang.utils.PageUtil;
|
||||
import co.yixiang.utils.QueryHelp;
|
||||
import co.yixiang.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.Optional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-31
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "qiNiu")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class QiNiuServiceImpl implements QiNiuService {
|
||||
|
||||
@Autowired
|
||||
private QiNiuConfigRepository qiNiuConfigRepository;
|
||||
private final QiNiuConfigRepository qiNiuConfigRepository;
|
||||
|
||||
@Autowired
|
||||
private QiniuContentRepository qiniuContentRepository;
|
||||
private final QiniuContentRepository qiniuContentRepository;
|
||||
|
||||
public QiNiuServiceImpl(QiNiuConfigRepository qiNiuConfigRepository, QiniuContentRepository qiniuContentRepository) {
|
||||
this.qiNiuConfigRepository = qiNiuConfigRepository;
|
||||
this.qiniuContentRepository = qiniuContentRepository;
|
||||
}
|
||||
|
||||
@Value("${qiniu.max-size}")
|
||||
private Long maxSize;
|
||||
|
||||
private final String TYPE = "公开";
|
||||
|
||||
@Override
|
||||
@Cacheable
|
||||
public Object queryAll(QiniuQueryCriteria criteria, Pageable pageable){
|
||||
return PageUtil.toPage(qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public QiniuConfig find() {
|
||||
Optional<QiniuConfig> qiniuConfig = qiNiuConfigRepository.findById(1L);
|
||||
if(qiniuConfig.isPresent()){
|
||||
return qiniuConfig.get();
|
||||
} else {
|
||||
return new QiniuConfig();
|
||||
}
|
||||
public List<QiniuContent> queryAll(QiniuQueryCriteria criteria) {
|
||||
return qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "'1'")
|
||||
public QiniuConfig find() {
|
||||
Optional<QiniuConfig> qiniuConfig = qiNiuConfigRepository.findById(1L);
|
||||
return qiniuConfig.orElseGet(QiniuConfig::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(cacheNames = "qiNiuConfig", key = "'1'")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public QiniuConfig update(QiniuConfig qiniuConfig) {
|
||||
if (!(qiniuConfig.getHost().toLowerCase().startsWith("http://")||qiniuConfig.getHost().toLowerCase().startsWith("https://"))) {
|
||||
String http = "http://", https = "https://";
|
||||
if (!(qiniuConfig.getHost().toLowerCase().startsWith(http)||qiniuConfig.getHost().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链域名必须以http://或者https://开头");
|
||||
}
|
||||
qiniuConfig.setId(1L);
|
||||
@ -73,7 +87,7 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
//@CacheEvict(allEntries = true)
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
|
||||
FileUtil.checkSize(maxSize, file.getSize());
|
||||
@ -104,77 +118,28 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||
qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(file.getSize()+"")));
|
||||
return qiniuContentRepository.save(qiniuContent);
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
throw new BadRequestException(e.getMessage());
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
|
||||
// FileUtil.checkSize(maxSize, file.getSize());
|
||||
// if(qiniuConfig.getId() == null){
|
||||
// throw new BadRequestException("请先添加相应配置,再操作");
|
||||
// }
|
||||
// /**
|
||||
// * 构造一个带指定Zone对象的配置类
|
||||
// */
|
||||
// Configuration cfg = new Configuration(QiNiuUtil.getRegion(qiniuConfig.getZone()));
|
||||
// UploadManager uploadManager = new UploadManager(cfg);
|
||||
// System.out.println(uploadManager);
|
||||
// Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
|
||||
// String upToken = auth.uploadToken(qiniuConfig.getBucket());
|
||||
// try {
|
||||
// String key = file.getOriginalFilename();
|
||||
//
|
||||
// System.out.println("key:"+key);
|
||||
// if(qiniuContentRepository.findByKey(key) != null) {
|
||||
// key = QiNiuUtil.getKey(key);
|
||||
// }
|
||||
//
|
||||
// System.out.println("key1:"+key);
|
||||
// System.out.println("upToken:"+upToken);
|
||||
// System.out.println(file.getBytes());
|
||||
// Response response = uploadManager.put(file.getBytes(), key, upToken);
|
||||
//
|
||||
// System.out.println("333333333");
|
||||
// System.out.println("response:"+response);
|
||||
// //解析上传成功的结果
|
||||
// DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||
//
|
||||
// System.out.println("putRet:"+putRet);
|
||||
//
|
||||
// //存入数据库
|
||||
// QiniuContent qiniuContent = new QiniuContent();
|
||||
// qiniuContent.setSuffix(FileUtil.getExtensionName(putRet.key));
|
||||
// qiniuContent.setBucket(qiniuConfig.getBucket());
|
||||
// qiniuContent.setType(qiniuConfig.getType());
|
||||
// qiniuContent.setKey(FileUtil.getFileNameNoEx(putRet.key));
|
||||
// qiniuContent.setUrl(qiniuConfig.getHost()+"/"+putRet.key);
|
||||
// qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(file.getSize()+"")));
|
||||
// return qiniuContentRepository.save(qiniuContent);
|
||||
// } catch (Exception e) {
|
||||
// throw new BadRequestException(e.getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
@Cacheable
|
||||
public QiniuContent findByContentId(Long id) {
|
||||
Optional<QiniuContent> qiniuContent = qiniuContentRepository.findById(id);
|
||||
ValidationUtil.isNull(qiniuContent,"QiniuContent", "id",id);
|
||||
return qiniuContent.get();
|
||||
QiniuContent qiniuContent = qiniuContentRepository.findById(id).orElseGet(QiniuContent::new);
|
||||
ValidationUtil.isNull(qiniuContent.getId(),"QiniuContent", "id",id);
|
||||
return qiniuContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable
|
||||
public String download(QiniuContent content,QiniuConfig config){
|
||||
String finalUrl = null;
|
||||
if(TYPE.equals(content.getType())){
|
||||
String finalUrl;
|
||||
String type = "公开";
|
||||
if(type.equals(content.getType())){
|
||||
finalUrl = content.getUrl();
|
||||
} else {
|
||||
Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
|
||||
/**
|
||||
* 1小时,可以自定义链接过期时间
|
||||
*/
|
||||
// 1小时,可以自定义链接过期时间
|
||||
long expireInSeconds = 3600;
|
||||
finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
|
||||
}
|
||||
@ -182,6 +147,7 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(QiniuContent content, QiniuConfig config) {
|
||||
//构造一个带指定Zone对象的配置类
|
||||
@ -197,6 +163,7 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void synchronize(QiniuConfig config) {
|
||||
if(config.getId() == null){
|
||||
@ -216,7 +183,7 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(config.getBucket(), prefix, limit, delimiter);
|
||||
while (fileListIterator.hasNext()) {
|
||||
//处理获取的file list结果
|
||||
QiniuContent qiniuContent = null;
|
||||
QiniuContent qiniuContent;
|
||||
FileInfo[] items = fileListIterator.next();
|
||||
for (FileInfo item : items) {
|
||||
if(qiniuContentRepository.findByKey(FileUtil.getFileNameNoEx(item.key)) == null){
|
||||
@ -234,6 +201,7 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
public void deleteAll(Long[] ids, QiniuConfig config) {
|
||||
for (Long id : ids) {
|
||||
delete(findByContentId(id), config);
|
||||
@ -241,8 +209,25 @@ public class QiNiuServiceImpl implements QiNiuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(String type) {
|
||||
qiNiuConfigRepository.update(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadList(List<QiniuContent> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (QiniuContent content : queryAll) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("文件名", content.getKey());
|
||||
map.put("文件类型", content.getSuffix());
|
||||
map.put("空间名称", content.getBucket());
|
||||
map.put("文件大小", content.getSize());
|
||||
map.put("空间类型", content.getType());
|
||||
map.put("创建日期", content.getUpdateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
}
|
||||
|
@ -8,15 +8,14 @@ import cn.hutool.extra.template.TemplateEngine;
|
||||
import cn.hutool.extra.template.TemplateUtil;
|
||||
import co.yixiang.domain.VerificationCode;
|
||||
import co.yixiang.domain.vo.EmailVo;
|
||||
import co.yixiang.repository.VerificationCodeRepository;
|
||||
import co.yixiang.service.VerificationCodeService;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import co.yixiang.repository.VerificationCodeRepository;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
@ -27,17 +26,20 @@ import java.util.concurrent.*;
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class VerificationCodeServiceImpl implements VerificationCodeService {
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeRepository verificationCodeRepository;
|
||||
private final VerificationCodeRepository verificationCodeRepository;
|
||||
|
||||
@Value("${code.expiration}")
|
||||
private Integer expiration;
|
||||
|
||||
public VerificationCodeServiceImpl(VerificationCodeRepository verificationCodeRepository) {
|
||||
this.verificationCodeRepository = verificationCodeRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public EmailVo sendEmail(VerificationCode code) {
|
||||
EmailVo emailVo = null;
|
||||
String content = "";
|
||||
EmailVo emailVo;
|
||||
String content;
|
||||
VerificationCode verificationCode = verificationCodeRepository.findByScenesAndTypeAndValueAndStatusIsTrue(code.getScenes(),code.getType(),code.getValue());
|
||||
// 如果不存在有效的验证码,就创建一个新的
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
@ -45,12 +47,12 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
|
||||
if(verificationCode == null){
|
||||
code.setCode(RandomUtil.randomNumbers (6));
|
||||
content = template.render(Dict.create().set("code",code.getCode()));
|
||||
emailVo = new EmailVo(Arrays.asList(code.getValue()),"eladmin后台管理系统",content);
|
||||
emailVo = new EmailVo(Collections.singletonList(code.getValue()),"yshop后台管理系统",content);
|
||||
timedDestruction(verificationCodeRepository.save(code));
|
||||
// 存在就再次发送原来的验证码
|
||||
} else {
|
||||
content = template.render(Dict.create().set("code",verificationCode.getCode()));
|
||||
emailVo = new EmailVo(Arrays.asList(verificationCode.getValue()),"eladmin后台管理系统",content);
|
||||
emailVo = new EmailVo(Collections.singletonList(verificationCode.getValue()),"yshop后台管理系统",content);
|
||||
}
|
||||
return emailVo;
|
||||
}
|
||||
@ -68,7 +70,7 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
|
||||
|
||||
/**
|
||||
* 定时任务,指定分钟后改变验证码状态
|
||||
* @param verifyCode
|
||||
* @param verifyCode 验证码
|
||||
*/
|
||||
private void timedDestruction(VerificationCode verifyCode) {
|
||||
//以下示例为程序调用结束继续运行
|
||||
|
@ -2,7 +2,7 @@ package co.yixiang.service.mapper;
|
||||
|
||||
import co.yixiang.domain.LocalStorage;
|
||||
import co.yixiang.service.dto.LocalStorageDTO;
|
||||
import co.yixiang.mapper.EntityMapper;
|
||||
import co.yixiang.base.BaseMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
|
||||
* @author Zheng Jie
|
||||
* @date 2019-09-05
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LocalStorageMapper extends EntityMapper<LocalStorageDTO, LocalStorage> {
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LocalStorageMapper extends BaseMapper<LocalStorageDTO, LocalStorage> {
|
||||
|
||||
}
|
@ -7,31 +7,21 @@ package co.yixiang.utils;
|
||||
*/
|
||||
public enum AliPayStatusEnum {
|
||||
|
||||
/**
|
||||
* 交易成功
|
||||
*/
|
||||
/** 交易成功 */
|
||||
FINISHED("交易成功", "TRADE_FINISHED"),
|
||||
|
||||
/**
|
||||
* 支付成功
|
||||
*/
|
||||
/** 支付成功 */
|
||||
SUCCESS("支付成功", "TRADE_SUCCESS"),
|
||||
|
||||
/**
|
||||
* 交易创建
|
||||
*/
|
||||
/** 交易创建 */
|
||||
BUYER_PAY("交易创建", "WAIT_BUYER_PAY"),
|
||||
|
||||
/**
|
||||
* 交易关闭
|
||||
*/
|
||||
/** 交易关闭 */
|
||||
CLOSED("交易关闭", "TRADE_CLOSED");
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
AliPayStatusEnum(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package co.yixiang.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import co.yixiang.domain.AlipayConfig;
|
||||
@ -9,7 +8,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -22,7 +20,7 @@ public class AlipayUtils {
|
||||
|
||||
/**
|
||||
* 生成订单号
|
||||
* @return
|
||||
* @return String
|
||||
*/
|
||||
public String getOrderCode() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
@ -35,24 +33,22 @@ public class AlipayUtils {
|
||||
String[] split1 = s.split(" ");
|
||||
String s1 = split1[0] + split1[1];
|
||||
String[] split2 = s1.split(":");
|
||||
String s2 = split2[0] + split2[1] + split2[2] + a;
|
||||
return s2;
|
||||
return split2[0] + split2[1] + split2[2] + a;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验签名
|
||||
* @param request
|
||||
* @return
|
||||
* @param request HttpServletRequest
|
||||
* @param alipay 阿里云配置
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean rsaCheck(HttpServletRequest request, AlipayConfig alipay){
|
||||
|
||||
/**
|
||||
* 获取支付宝POST过来反馈信息
|
||||
*/
|
||||
// 获取支付宝POST过来反馈信息
|
||||
Map<String,String> params = new HashMap<>(1);
|
||||
Map requestParams = request.getParameterMap();
|
||||
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
for (Object o : requestParams.keySet()) {
|
||||
String name = (String) o;
|
||||
String[] values = (String[]) requestParams.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
@ -63,17 +59,12 @@ public class AlipayUtils {
|
||||
}
|
||||
|
||||
try {
|
||||
boolean verifyResult = AlipaySignature.rsaCheckV1(params,
|
||||
return AlipaySignature.rsaCheckV1(params,
|
||||
alipay.getPublicKey(),
|
||||
alipay.getCharset(),
|
||||
alipay.getSignType());
|
||||
return verifyResult;
|
||||
} catch (AlipayApiException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty(String str){
|
||||
return StrUtil.isEmpty(str);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package co.yixiang.utils;
|
||||
|
||||
import com.qiniu.storage.Region;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@ -11,18 +12,18 @@ import java.util.Date;
|
||||
*/
|
||||
public class QiNiuUtil {
|
||||
|
||||
public static final String HUAD = "华东";
|
||||
private static final String HUAD = "华东";
|
||||
|
||||
public static final String HUAB = "华北";
|
||||
private static final String HUAB = "华北";
|
||||
|
||||
public static final String HUAN = "华南";
|
||||
private static final String HUAN = "华南";
|
||||
|
||||
public static final String BEIM = "北美";
|
||||
private static final String BEIM = "北美";
|
||||
|
||||
/**
|
||||
* 得到机房的对应关系
|
||||
* @param zone
|
||||
* @return
|
||||
* @param zone 机房名称
|
||||
* @return Region
|
||||
*/
|
||||
public static Region getRegion(String zone){
|
||||
|
||||
@ -42,17 +43,15 @@ public class QiNiuUtil {
|
||||
|
||||
/**
|
||||
* 默认不指定key的情况下,以文件内容的hash值作为文件名
|
||||
* @param file
|
||||
* @return
|
||||
* @param file 文件名
|
||||
* @return String
|
||||
*/
|
||||
public static String getKey(String file){
|
||||
StringBuffer key = new StringBuffer(FileUtil.getFileNameNoEx(file));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
Date date = new Date();
|
||||
key.append("-");
|
||||
key.append(sdf.format(date));
|
||||
key.append(".");
|
||||
key.append(FileUtil.getExtensionName(file));
|
||||
return key.toString();
|
||||
return FileUtil.getFileNameNoEx(file) + "-" +
|
||||
sdf.format(date) +
|
||||
"." +
|
||||
FileUtil.getExtensionName(file);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user