提交 23782532 authored 作者: zgy's avatar zgy

修改评论

上级 d28e558e
...@@ -8,7 +8,7 @@ import java.util.Date; ...@@ -8,7 +8,7 @@ import java.util.Date;
* 表名 tb_cf_item_comment * 表名 tb_cf_item_comment
* *
* @author lipengjun * @author lipengjun
* @date 2019-11-18 14:31:39 * @date 2020-01-09 10:17:03
*/ */
public class TbCfItemCommentEntity implements Serializable { public class TbCfItemCommentEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -29,6 +29,14 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -29,6 +29,14 @@ public class TbCfItemCommentEntity implements Serializable {
* 商品ID * 商品ID
*/ */
private String itemId; private String itemId;
/**
* 类型 0: 只有文本内容 1:带图片
*/
private Integer type;
/**
* 图片或视频的url
*/
private String urls;
/** /**
* 商品评分 * 商品评分
*/ */
...@@ -62,18 +70,41 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -62,18 +70,41 @@ public class TbCfItemCommentEntity implements Serializable {
*/ */
private Date createTime; private Date createTime;
/** /**
* 回复时间 * 更新时间
*/ */
private Date updateTime; private Date updateTime;
private String username; private String userName;
private String orderNo;
private String itemName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getUsername() { public String getItemName() {
return username; return itemName;
} }
public void setUsername(String username) { public void setItemName(String itemName) {
this.username = username; this.itemName = itemName;
}
public static long getSerialVersionUID() {
return serialVersionUID;
} }
/** /**
...@@ -89,7 +120,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -89,7 +120,6 @@ public class TbCfItemCommentEntity implements Serializable {
public String getId() { public String getId() {
return id; return id;
} }
/** /**
* 设置:评论人 * 设置:评论人
*/ */
...@@ -103,7 +133,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -103,7 +133,6 @@ public class TbCfItemCommentEntity implements Serializable {
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
/** /**
* 设置:订单ID * 设置:订单ID
*/ */
...@@ -117,7 +146,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -117,7 +146,6 @@ public class TbCfItemCommentEntity implements Serializable {
public String getOrderId() { public String getOrderId() {
return orderId; return orderId;
} }
/** /**
* 设置:商品ID * 设置:商品ID
*/ */
...@@ -131,7 +159,32 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -131,7 +159,32 @@ public class TbCfItemCommentEntity implements Serializable {
public String getItemId() { public String getItemId() {
return itemId; return itemId;
} }
/**
* 设置:类型 0: 只有文本内容 1:带图片
*/
public void setType(Integer type) {
this.type = type;
}
/**
* 获取:类型 0: 只有文本内容 1:带图片
*/
public Integer getType() {
return type;
}
/**
* 设置:图片或视频的url
*/
public void setUrls(String urls) {
this.urls = urls;
}
/**
* 获取:图片或视频的url
*/
public String getUrls() {
return urls;
}
/** /**
* 设置:商品评分 * 设置:商品评分
*/ */
...@@ -145,7 +198,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -145,7 +198,6 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getItemScore() { public Integer getItemScore() {
return itemScore; return itemScore;
} }
/** /**
* 设置:服务评分 * 设置:服务评分
*/ */
...@@ -159,7 +211,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -159,7 +211,6 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getServiceScore() { public Integer getServiceScore() {
return serviceScore; return serviceScore;
} }
/** /**
* 设置:物流评分 * 设置:物流评分
*/ */
...@@ -173,7 +224,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -173,7 +224,6 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getLogisticsScore() { public Integer getLogisticsScore() {
return logisticsScore; return logisticsScore;
} }
/** /**
* 设置:价格评分 * 设置:价格评分
*/ */
...@@ -187,7 +237,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -187,7 +237,6 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getPriceScore() { public Integer getPriceScore() {
return priceScore; return priceScore;
} }
/** /**
* 设置:商品评论 * 设置:商品评论
*/ */
...@@ -201,7 +250,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -201,7 +250,6 @@ public class TbCfItemCommentEntity implements Serializable {
public String getItemReview() { public String getItemReview() {
return itemReview; return itemReview;
} }
/** /**
* 设置:点赞人数 * 设置:点赞人数
*/ */
...@@ -215,7 +263,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -215,7 +263,6 @@ public class TbCfItemCommentEntity implements Serializable {
public Long getLikeNum() { public Long getLikeNum() {
return likeNum; return likeNum;
} }
/** /**
* 设置:删除标志 0:正常 1:已删除 * 设置:删除标志 0:正常 1:已删除
*/ */
...@@ -229,7 +276,6 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -229,7 +276,6 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getDelFlag() { public Integer getDelFlag() {
return delFlag; return delFlag;
} }
/** /**
* 设置:创建时间 * 设置:创建时间
*/ */
...@@ -243,12 +289,17 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -243,12 +289,17 @@ public class TbCfItemCommentEntity implements Serializable {
public Date getCreateTime() { public Date getCreateTime() {
return createTime; return createTime;
} }
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() { public Date getUpdateTime() {
return updateTime; return updateTime;
} }
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
} }
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
<result property="userId" column="user_id"/> <result property="userId" column="user_id"/>
<result property="orderId" column="order_id"/> <result property="orderId" column="order_id"/>
<result property="itemId" column="item_id"/> <result property="itemId" column="item_id"/>
<result property="type" column="type"/>
<result property="urls" column="urls"/>
<result property="itemScore" column="item_score"/> <result property="itemScore" column="item_score"/>
<result property="serviceScore" column="service_score"/> <result property="serviceScore" column="service_score"/>
<result property="logisticsScore" column="logistics_score"/> <result property="logisticsScore" column="logistics_score"/>
...@@ -26,6 +28,8 @@ ...@@ -26,6 +28,8 @@
`user_id`, `user_id`,
`order_id`, `order_id`,
`item_id`, `item_id`,
`type`,
`urls`,
`item_score`, `item_score`,
`service_score`, `service_score`,
`logistics_score`, `logistics_score`,
...@@ -40,11 +44,13 @@ ...@@ -40,11 +44,13 @@
</select> </select>
<select id="queryList" resultMap="tbCfItemCommentMap"> <select id="queryList" resultMap="tbCfItemCommentMap">
select SELECT
c.id, c.id,
c.user_id, c.user_id,
c.order_id, c.order_id,
c.item_id, c.item_id,
c.type,
c.urls,
c.item_score, c.item_score,
c.service_score, c.service_score,
c.logistics_score, c.logistics_score,
...@@ -54,9 +60,16 @@ ...@@ -54,9 +60,16 @@
c.del_flag, c.del_flag,
c.create_time, c.create_time,
c.update_time, c.update_time,
u.nick username u.nick userName,
from tb_cf_item_comment c left join tb_cf_user_info u on c.user_id=u.user_id o.order_no orderNo,
where 1=1 i.item_name itemName
FROM
tb_cf_item_comment c
LEFT JOIN tb_cf_user_info u ON c.user_id = u.user_id
left join tb_cf_order o on c.order_id=o.order_id
left join tb_cf_station_item i on c.item_id=i.item_id
WHERE
1 =1
<if test="name != null and name.trim() != ''"> <if test="name != null and name.trim() != ''">
AND u.nick LIKE concat('%',#{name},'%') AND u.nick LIKE concat('%',#{name},'%')
</if> </if>
...@@ -87,6 +100,8 @@ ...@@ -87,6 +100,8 @@
`user_id`, `user_id`,
`order_id`, `order_id`,
`item_id`, `item_id`,
`type`,
`urls`,
`item_score`, `item_score`,
`service_score`, `service_score`,
`logistics_score`, `logistics_score`,
...@@ -101,6 +116,8 @@ ...@@ -101,6 +116,8 @@
#{userId}, #{userId},
#{orderId}, #{orderId},
#{itemId}, #{itemId},
#{type},
#{urls},
#{itemScore}, #{itemScore},
#{serviceScore}, #{serviceScore},
#{logisticsScore}, #{logisticsScore},
...@@ -118,6 +135,8 @@ ...@@ -118,6 +135,8 @@
<if test="userId != null">`user_id` = #{userId},</if> <if test="userId != null">`user_id` = #{userId},</if>
<if test="orderId != null">`order_id` = #{orderId},</if> <if test="orderId != null">`order_id` = #{orderId},</if>
<if test="itemId != null">`item_id` = #{itemId},</if> <if test="itemId != null">`item_id` = #{itemId},</if>
<if test="type != null">`type` = #{type},</if>
<if test="urls != null">`urls` = #{urls},</if>
<if test="itemScore != null">`item_score` = #{itemScore},</if> <if test="itemScore != null">`item_score` = #{itemScore},</if>
<if test="serviceScore != null">`service_score` = #{serviceScore},</if> <if test="serviceScore != null">`service_score` = #{serviceScore},</if>
<if test="logisticsScore != null">`logistics_score` = #{logisticsScore},</if> <if test="logisticsScore != null">`logistics_score` = #{logisticsScore},</if>
......
...@@ -118,6 +118,10 @@ ...@@ -118,6 +118,10 @@
<if test="status != null and status.trim() != ''"> <if test="status != null and status.trim() != ''">
AND enable_flag=#{status} AND enable_flag=#{status}
</if> </if>
<if test="itemCategory != null and itemCategory.trim() != ''">
AND item_category=#{itemCategory}
</if>
<choose> <choose>
<when test="sidx != null and sidx.trim() != ''"> <when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order} order by ${sidx} ${order}
...@@ -155,6 +159,9 @@ ...@@ -155,6 +159,9 @@
<if test="status != null and status.trim() != ''"> <if test="status != null and status.trim() != ''">
AND enable_flag=#{status} AND enable_flag=#{status}
</if> </if>
<if test="itemCategory != null and itemCategory.trim() != ''">
AND item_category=#{itemCategory}
</if>
</select> </select>
<insert id="save" parameterType="com.platform.entity.TbCfStationItemEntity"> <insert id="save" parameterType="com.platform.entity.TbCfStationItemEntity">
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
</style> </style>
</head> </head>
<body> <body>
<div id="rrapp" v-cloak style="width:1700px; <div id="rrapp" v-cloak style="width:100%;
height: -webkit-calc(100% - 15px); height: -webkit-calc(100% - 15px);
height: -moz-calc(100% - 15px); height: -moz-calc(100% - 15px);
height: calc(100% - 15px);"> height: calc(100% - 15px);">
......
...@@ -132,6 +132,7 @@ ...@@ -132,6 +132,7 @@
.query { .query {
float: right; float: right;
margin-right: 200px; margin-right: 200px;
} }
.default-price { .default-price {
...@@ -169,6 +170,16 @@ ...@@ -169,6 +170,16 @@
</span> </span>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
<span> <span>
一级分类:
<i-select v-model="q.itemCategory" @on-enter="query"
placeholder="一级分类" style="width:160px">
<i-option v-for="(el,i) in Goodstype" :key='i'
:value="el.goodstypeId">{{el.goodstypeTitle}}
</i-option>
</i-select>
</span>
&nbsp;&nbsp;&nbsp;&nbsp;
<span>
商品状态: 商品状态:
<i-select v-model="q.status" @on-enter="query" placeholder="商品状态" style="width:160px"> <i-select v-model="q.status" @on-enter="query" placeholder="商品状态" style="width:160px">
<i-option value="1">在线销售</i-option> <i-option value="1">在线销售</i-option>
......
...@@ -3,9 +3,9 @@ $(function () { ...@@ -3,9 +3,9 @@ $(function () {
url: '../tbcfitemcomment/list', url: '../tbcfitemcomment/list',
colModel: [ colModel: [
{label: 'id', name: 'id', index: 'id', key: true, hidden: true}, {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
{label: '评论人', name: 'username', index: 'username', width: 80}, {label: '评论人', name: 'userName', index: 'username', width: 80},
{label: '订单ID', name: 'orderId', index: 'order_id', width: 80}, {label: '订单号', name: 'orderNo', index: 'order_id', width: 80},
{label: '商品ID', name: 'itemId', index: 'item_id', width: 80}, {label: '商品名称', name: 'itemName', index: 'item_id', width: 80},
{label: '商品评分', name: 'itemScore', index: 'item_score', width: 80}, {label: '商品评分', name: 'itemScore', index: 'item_score', width: 80},
{label: '服务评分', name: 'serviceScore', index: 'service_score', width: 80}, {label: '服务评分', name: 'serviceScore', index: 'service_score', width: 80},
{label: '物流评分', name: 'logisticsScore', index: 'logistics_score', width: 80}, {label: '物流评分', name: 'logisticsScore', index: 'logistics_score', width: 80},
......
...@@ -43,12 +43,13 @@ let vm = new Vue({ ...@@ -43,12 +43,13 @@ let vm = new Vue({
q: { q: {
name: '', name: '',
code: '', code: '',
status: '' status: '',
itemCategory: ''
}, },
alertShow: false,//警告弹窗 alertShow: false,//警告弹窗
serverSkuAttr:[], serverSkuAttr: [],
attrItem: [{ attrItem: [{
categoryName: 'Size', categoryName: 'Size',
option: [], option: [],
...@@ -220,7 +221,7 @@ let vm = new Vue({ ...@@ -220,7 +221,7 @@ let vm = new Vue({
}) })
console.log(r) console.log(r)
})() })()
console.log(123321,_this.attrItem) console.log(123321, _this.attrItem)
vm.tbCfStationItem = r.tbCfStationItem.item; vm.tbCfStationItem = r.tbCfStationItem.item;
vm.uploadList[0] = vm.tbCfStationItem.itemImg; vm.uploadList[0] = vm.tbCfStationItem.itemImg;
let itemDesc = vm.tbCfStationItem.itemDesc; let itemDesc = vm.tbCfStationItem.itemDesc;
...@@ -230,28 +231,25 @@ let vm = new Vue({ ...@@ -230,28 +231,25 @@ let vm = new Vue({
vm.tbCfStationItem.enableFlag === 1 && (() => { vm.tbCfStationItem.enableFlag === 1 && (() => {
_this.putaway = true; _this.putaway = true;
})() })()
try{ try {
UE.getEditor('itemDesc').setContent(itemDesc); UE.getEditor('itemDesc').setContent(itemDesc);
}catch (e) { } catch (e) {
} }
setTimeout(()=>{ setTimeout(() => {
UE.getEditor('itemDesc').setContent(itemDesc); UE.getEditor('itemDesc').setContent(itemDesc);
},500) }, 500)
if (itemDesc == null || itemDesc == '') { if (itemDesc == null || itemDesc == '') {
UE.getEditor('itemDesc').setContent(""); UE.getEditor('itemDesc').setContent("");
} }
} }
}); });
}, },
importExcel: function () { importExcel: function () {
let itemIds = getSelectedRows("#jqGrid"); this.modal=''
if (itemIds == null) {
return;
}
}, },
exportExcel: function () { exportExcel: function () {
...@@ -261,8 +259,9 @@ let vm = new Vue({ ...@@ -261,8 +259,9 @@ let vm = new Vue({
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
successCallback: function (resultData) { successCallback: function (resultData) {
// console.log(resultData); alert('操作成功!导出位置:D:\\Afrishop', function (index) {
iview.Message.success(resultData.success); vm.reload();
});
} }
}); });
...@@ -274,7 +273,12 @@ let vm = new Vue({ ...@@ -274,7 +273,12 @@ let vm = new Vue({
vm.showList = true; vm.showList = true;
let page = $("#jqGrid").jqGrid('getGridParam', 'page'); let page = $("#jqGrid").jqGrid('getGridParam', 'page');
$("#jqGrid").jqGrid('setGridParam', { $("#jqGrid").jqGrid('setGridParam', {
postData: {'name': vm.q.name.trim(), 'code': vm.q.code.trim(), 'status': vm.q.status.trim()}, postData: {
'name': vm.q.name.trim(),
'code': vm.q.code.trim(),
'status': vm.q.status.trim(),
'itemCategory': vm.q.itemCategory.trim()
},
page: page page: page
}).trigger("reloadGrid"); }).trigger("reloadGrid");
vm.handleReset('formValidate'); vm.handleReset('formValidate');
...@@ -283,7 +287,8 @@ let vm = new Vue({ ...@@ -283,7 +287,8 @@ let vm = new Vue({
vm.q = { vm.q = {
name: '', name: '',
code: '', code: '',
status: '' status: '',
itemCategory: ''
}; };
vm.reload(); vm.reload();
}, },
...@@ -491,10 +496,11 @@ let vm = new Vue({ ...@@ -491,10 +496,11 @@ let vm = new Vue({
}) })
} }
}, },
ok(){ ok() {
this.reloadSearch(); this.reloadSearch();
}, },
cancel(){}, cancel() {
},
handleCreateSelect(val) { handleCreateSelect(val) {
let option = JSON.parse(localStorage.getItem('option')) let option = JSON.parse(localStorage.getItem('option'))
option.push(val) option.push(val)
...@@ -523,9 +529,9 @@ let vm = new Vue({ ...@@ -523,9 +529,9 @@ let vm = new Vue({
}) })
//获取默认规格 //获取默认规格
$.get('../tbcategorytemplate/queryAll',res=>{ $.get('../tbcategorytemplate/queryAll', res => {
let _res = JSON.parse(res) let _res = JSON.parse(res)
_res.list.forEach(item=>{ _res.list.forEach(item => {
this.attrItem[0].option.push(item.categoryDesc) this.attrItem[0].option.push(item.categoryDesc)
this.serverSkuAttr.push(item.categoryDesc) this.serverSkuAttr.push(item.categoryDesc)
}) })
......
...@@ -15,18 +15,18 @@ import com.aliyun.oss.model.PutObjectResult; ...@@ -15,18 +15,18 @@ import com.aliyun.oss.model.PutObjectResult;
import com.baidu.ueditor.define.State; import com.baidu.ueditor.define.State;
public class OssUtil { public class OssUtil {
////////// 阿里云要求jdom使用1.1版本!!!!!!!!!!!!! ////////// 阿里云要求jdom使用1.1版本!!!!!!!!!!!!!
//阿里云API的内或外网域名 //阿里云API的内或外网域名
private static final String ENDPOINT="oss-cn-shenzhen.aliyuncs.com"; private static final String ENDPOINT = "oss-cn-shenzhen.aliyuncs.com";
//阿里云API的密钥Access Key ID //阿里云API的密钥Access Key ID
private static final String ACCESS_KEY_ID="5d6h34keSd9K3l2x"; private static final String ACCESS_KEY_ID = "5d6h34keSd9K3l2x";
//阿里云API的密钥Access Key Secret //阿里云API的密钥Access Key Secret
private static final String ACCESS_KEY_SECRET="l2dJ4LpY6D6qV3jj3iQif7EPByoVQE"; private static final String ACCESS_KEY_SECRET = "l2dJ4LpY6D6qV3jj3iQif7EPByoVQE";
//阿里云API的bucket名称 //阿里云API的bucket名称
private static final String BACKET_NAME="diaosaas-prod"; private static final String BACKET_NAME = "diaosaas-prod";
//阿里云API的文件夹名称 //阿里云API的文件夹名称
private static final String FOLDER="africa-shop/"; private static final String FOLDER = "africa-shop/";
// // 阿里云API的内或外网域名 // // 阿里云API的内或外网域名
// private static final String ENDPOINT = "oss-cn-shenzhen.aliyuncs.com"; // private static final String ENDPOINT = "oss-cn-shenzhen.aliyuncs.com";
// // 阿里云API的密钥Access Key ID // // 阿里云API的密钥Access Key ID
...@@ -38,381 +38,374 @@ public class OssUtil { ...@@ -38,381 +38,374 @@ public class OssUtil {
// // 阿里云API的文件夹名称 // // 阿里云API的文件夹名称
// private static final String FOLDER = "wosenad/"; // private static final String FOLDER = "wosenad/";
/** /**
* 获取阿里云OSS客户端对象 * 获取阿里云OSS客户端对象
* *
* @return * @return
*/ */
public static OSSClient getOSSClient() { public static OSSClient getOSSClient() {
return new OSSClient(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET); return new OSSClient(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
} }
/** /**
* 创建存储空间 * 创建存储空间
* *
* @param ossClient * @param ossClient
* @param bucketName * @param bucketName
* @return * @return
*/ */
public static String createBucketName(OSSClient ossClient, String bucketName) { public static String createBucketName(OSSClient ossClient, String bucketName) {
// 存储空间 // 存储空间
final String bucketNames = bucketName; final String bucketNames = bucketName;
if (!ossClient.doesBucketExist(bucketName)) { if (!ossClient.doesBucketExist(bucketName)) {
// 创建存储空间 // 创建存储空间
Bucket bucket = ossClient.createBucket(bucketName); Bucket bucket = ossClient.createBucket(bucketName);
return bucket.getName(); return bucket.getName();
} }
return bucketNames; return bucketNames;
} }
/** /**
* 删除存储空间 * 删除存储空间
* *
* @param ossClient * @param ossClient
* @param bucketName * @param bucketName
*/ */
public static void deleteBucket(OSSClient ossClient, String bucketName) { public static void deleteBucket(OSSClient ossClient, String bucketName) {
ossClient.deleteBucket(bucketName); ossClient.deleteBucket(bucketName);
} }
/** /**
* 创建模拟文件夹 * 创建模拟文件夹
* *
* @param ossClient * @param ossClient oss连接
* oss连接 * @param bucketName 存储空间
* @param bucketName * @param folder 模拟文件夹名如"wenjianjia/"
* 存储空间 * @return
* @param folder */
* 模拟文件夹名如"wenjianjia/" public static String createFolder(OSSClient ossClient, String bucketName, String folder) {
* @return // 文件夹名
*/ final String keySuffixWithSlash = folder;
public static String createFolder(OSSClient ossClient, String bucketName, String folder) { // 判断文件夹是否存在,不存在则创建
// 文件夹名 if (!ossClient.doesObjectExist(bucketName, keySuffixWithSlash)) {
final String keySuffixWithSlash = folder; // 创建文件夹
// 判断文件夹是否存在,不存在则创建 ossClient.putObject(bucketName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0]));
if (!ossClient.doesObjectExist(bucketName, keySuffixWithSlash)) { ;
// 创建文件夹 // 得到文件夹名
ossClient.putObject(bucketName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0])); OSSObject object = ossClient.getObject(bucketName, keySuffixWithSlash);
; String fileDir = object.getKey();
// 得到文件夹名 return fileDir;
OSSObject object = ossClient.getObject(bucketName, keySuffixWithSlash); }
String fileDir = object.getKey(); return keySuffixWithSlash;
return fileDir; }
}
return keySuffixWithSlash;
}
/** /**
* 根据key和folder删除OSS服务器上的文件 * 根据key和folder删除OSS服务器上的文件
* *
* @param bucketName * @param bucketName bucketName存储空间
* bucketName存储空间 * @param folder folder模拟文件夹名 如"qj_nanjing/"
* @param folder * @param key Bucket下的文件的路径名+文件名 如:"upload/cake.jpg"
* folder模拟文件夹名 如"qj_nanjing/" */
* @param key public static String deleteFile(String bucketName, String folder, String key) {
* Bucket下的文件的路径名+文件名 如:"upload/cake.jpg" OSSClient ossClient = getOSSClient();
*/ try {
public static String deleteFile(String bucketName, String folder, String key) { ossClient.deleteObject(bucketName, folder + key);
OSSClient ossClient = getOSSClient(); return "success";
try { } catch (Exception e) {
ossClient.deleteObject(bucketName, folder + key); e.printStackTrace();
return "success"; return "error";
} catch (Exception e) { } finally {
e.printStackTrace(); ossClient.shutdown();
return "error"; }
} finally { }
ossClient.shutdown();
}
}
/** /**
* 根据key删除OSS服务器上的文件 * 根据key删除OSS服务器上的文件
* *
* @param bucketName * @param bucketName bucketName存储空间
* bucketName存储空间 * @param key Bucket下的文件的路径名+文件名 如:"upload/cake.jpg"
* @param key */
* Bucket下的文件的路径名+文件名 如:"upload/cake.jpg" public static String deleteFile(String bucketName, String key) {
*/ OSSClient ossClient = getOSSClient();
public static String deleteFile(String bucketName, String key) { try {
OSSClient ossClient = getOSSClient(); ossClient.deleteObject(bucketName, key);
try { return "success";
ossClient.deleteObject(bucketName, key); } catch (Exception e) {
return "success"; e.printStackTrace();
} catch (Exception e) { return "error";
e.printStackTrace(); } finally {
return "error"; ossClient.shutdown();
} finally { }
ossClient.shutdown(); }
}
}
/** /**
* 根据key删除OSS服务器上的文件 * 根据key删除OSS服务器上的文件
* *
* @param key * @param key Bucket下的文件的路径名+文件名 如:"upload/cake.jpg" "http://" + BACKET_NAME +
* Bucket下的文件的路径名+文件名 如:"upload/cake.jpg" "http://" + BACKET_NAME + * "." + ENDPOINT + "/" + FOLDER + secondaryFolderName + "/" +
* "." + ENDPOINT + "/" + FOLDER + secondaryFolderName + "/" + * fileNameNew
* fileNameNew */
*/ public static boolean deleteFile(String key) {
public static boolean deleteFile(String key) { OSSClient ossClient = getOSSClient();
OSSClient ossClient = getOSSClient(); try {
try { // 将图片路径前缀去除
// 将图片路径前缀去除 String pathPrefix = "https://" + BACKET_NAME + "." + ENDPOINT + "/";
String pathPrefix = "https://" + BACKET_NAME + "." + ENDPOINT + "/"; String filePath = key.startsWith(pathPrefix) ? key.substring(pathPrefix.length(), key.length()) : key;
String filePath = key.startsWith(pathPrefix) ? key.substring(pathPrefix.length(), key.length()) : key; ossClient.deleteObject(BACKET_NAME, filePath);
ossClient.deleteObject(BACKET_NAME, filePath); return true;
return true; } catch (Exception e) {
} catch (Exception e) { e.printStackTrace();
e.printStackTrace(); return false;
return false; } finally {
} finally { ossClient.shutdown();
ossClient.shutdown(); }
} }
}
/** /**
* 上传图片至OSS * 上传图片至OSS
* *
* @param file * @param file
* @param secondaryFolderName * @param secondaryFolderName 二级文件夹目录
* 二级文件夹目录 * @return
* @return */
*/ public static String uploadObject2OSS(File file, String secondaryFolderName) {
public static String uploadObject2OSS(File file, String secondaryFolderName) { OSSClient ossClient = getOSSClient();
OSSClient ossClient = getOSSClient(); try {
try { // 以输入流的形式上传文件
// 以输入流的形式上传文件 InputStream is = new FileInputStream(file);
InputStream is = new FileInputStream(file); String path = file.getName();
String path = file.getName(); String fileName = path.substring(path.lastIndexOf("//") + 1);
String fileName = path.substring(path.lastIndexOf("//") + 1); String type = path.substring(path.lastIndexOf(".") + 1);
String type = path.substring(path.lastIndexOf(".") + 1); int random = (int) (Math.random() * 900) + 10000;
int random = (int) (Math.random() * 900) + 10000; // 文件名
// 文件名 String fileNameNew = fileName.replace(fileName,
String fileNameNew = fileName.replace(fileName, String.valueOf(System.currentTimeMillis()) + String.valueOf(random) + "." + type);
String.valueOf(System.currentTimeMillis()) + String.valueOf(random) + "." + type); // 文件大小
// 文件大小 Long fileSize = file.length();
Long fileSize = file.length(); // 创建上传Object的Metadata
// 创建上传Object的Metadata ObjectMetadata metadata = new ObjectMetadata();
ObjectMetadata metadata = new ObjectMetadata(); // 上传的文件的长度
// 上传的文件的长度 metadata.setContentLength(is.available());
metadata.setContentLength(is.available()); // 指定该Object被下载时的网页的缓存行为
// 指定该Object被下载时的网页的缓存行为 metadata.setCacheControl("no-cache");
metadata.setCacheControl("no-cache"); // 指定该Object下设置Header
// 指定该Object下设置Header metadata.setHeader("Pragma", "no-cache");
metadata.setHeader("Pragma", "no-cache"); // 指定该Object被下载时的内容编码格式
// 指定该Object被下载时的内容编码格式 metadata.setContentEncoding("utf-8");
metadata.setContentEncoding("utf-8"); // 文件的MIME,定义文件的类型及网页编码,决定浏览器将以什么形式、什么编码读取文件。如果用户没有指定则根据Key或文件名的扩展名生成,
// 文件的MIME,定义文件的类型及网页编码,决定浏览器将以什么形式、什么编码读取文件。如果用户没有指定则根据Key或文件名的扩展名生成, // 如果没有扩展名则填默认值application/octet-stream
// 如果没有扩展名则填默认值application/octet-stream metadata.setContentType(getContentType(fileNameNew));
metadata.setContentType(getContentType(fileNameNew)); // 指定该Object被下载时的名称(指示MINME用户代理如何显示附加的文件,打开或下载,及文件名称)
// 指定该Object被下载时的名称(指示MINME用户代理如何显示附加的文件,打开或下载,及文件名称) metadata.setContentDisposition("filename/filesize=" + fileNameNew + "/" + fileSize + "Byte.");
metadata.setContentDisposition("filename/filesize=" + fileNameNew + "/" + fileSize + "Byte."); //System.out.println(FOLDER + fileNameNew);
//System.out.println(FOLDER + fileNameNew); // 上传文件 (上传文件流的形式)
// 上传文件 (上传文件流的形式) PutObjectResult putResult = ossClient.putObject(BACKET_NAME,
PutObjectResult putResult = ossClient.putObject(BACKET_NAME, FOLDER + secondaryFolderName + "/" + fileNameNew, is, metadata);
FOLDER + secondaryFolderName + "/" + fileNameNew, is, metadata); // 解析结果
// 解析结果 URL url = getUrl(ossClient, putResult.getETag());
URL url = getUrl(ossClient, putResult.getETag()); return "https://" + BACKET_NAME + "." + ENDPOINT + "/" + FOLDER + secondaryFolderName + "/" + fileNameNew;
return "https://" + BACKET_NAME + "." + ENDPOINT + "/" + FOLDER + secondaryFolderName + "/" + fileNameNew; } catch (Exception e) {
} catch (Exception e) { e.printStackTrace();
e.printStackTrace(); return "error";
return "error"; } finally {
} finally { ossClient.shutdown();
ossClient.shutdown(); }
} // return url;
// return url; }
}
/**
* 通过文件名判断并获取OSS服务文件上传时文件的contentType
*
* @param fileName
* @return
*/
public static String getContentType(String fileName) {
// 文件的后缀名
String fileExtension = fileName.substring(fileName.lastIndexOf("."));
if (".bmp".equalsIgnoreCase(fileExtension)) {
return "image/bmp";
}
if (".gif".equalsIgnoreCase(fileExtension)) {
return "image/gif";
}
if (".jpeg".equalsIgnoreCase(fileExtension) || ".jpg".equalsIgnoreCase(fileExtension)
|| ".png".equalsIgnoreCase(fileExtension)) {
return "image/jpeg";
}
if (".html".equalsIgnoreCase(fileExtension)) {
return "text/html";
}
if (".txt".equalsIgnoreCase(fileExtension)) {
return "text/plain";
}
if (".vsd".equalsIgnoreCase(fileExtension)) {
return "application/vnd.visio";
}
if (".ppt".equalsIgnoreCase(fileExtension) || "pptx".equalsIgnoreCase(fileExtension)) {
return "application/vnd.ms-powerpoint";
}
if (".doc".equalsIgnoreCase(fileExtension) || "docx".equalsIgnoreCase(fileExtension)) {
return "application/msword";
}
if (".xml".equalsIgnoreCase(fileExtension)) {
return "text/xml";
}
// 默认返回类型
return "image/jpeg";
}
/** /**
* 通过文件名判断并获取OSS服务文件上传时文件的contentType * @param ossClient
* * @param key
* @param fileName * @return
* @return */
*/ public static URL getUrl(OSSClient ossClient, String key) {
public static String getContentType(String fileName) { // 设置URL过期时间为10年
// 文件的后缀名 Date expiration = new Date(new Date().getTime() + 3600l * 1000 * 24 * 365 * 10);
String fileExtension = fileName.substring(fileName.lastIndexOf(".")); // 生成URL
if (".bmp".equalsIgnoreCase(fileExtension)) { URL url = ossClient.generatePresignedUrl(BACKET_NAME, key, expiration);
return "image/bmp"; return url;
} }
if (".gif".equalsIgnoreCase(fileExtension)) {
return "image/gif";
}
if (".jpeg".equalsIgnoreCase(fileExtension) || ".jpg".equalsIgnoreCase(fileExtension)
|| ".png".equalsIgnoreCase(fileExtension)) {
return "image/jpeg";
}
if (".html".equalsIgnoreCase(fileExtension)) {
return "text/html";
}
if (".txt".equalsIgnoreCase(fileExtension)) {
return "text/plain";
}
if (".vsd".equalsIgnoreCase(fileExtension)) {
return "application/vnd.visio";
}
if (".ppt".equalsIgnoreCase(fileExtension) || "pptx".equalsIgnoreCase(fileExtension)) {
return "application/vnd.ms-powerpoint";
}
if (".doc".equalsIgnoreCase(fileExtension) || "docx".equalsIgnoreCase(fileExtension)) {
return "application/msword";
}
if (".xml".equalsIgnoreCase(fileExtension)) {
return "text/xml";
}
// 默认返回类型
return "image/jpeg";
}
/** /**
* * MultipartFile 形式上传文件
* @param ossClient *
* @param key * @param file
* @return * @return
*/ * @throws Exception
public static URL getUrl(OSSClient ossClient, String key) { */
// 设置URL过期时间为10年 public static String upload(MultipartFile file) throws Exception {
Date expiration = new Date(new Date().getTime() + 3600l * 1000 * 24 * 365 * 10); String fileName = file.getOriginalFilename();
// 生成URL String prefix = fileName.substring(fileName.lastIndexOf("."));
URL url = ossClient.generatePresignedUrl(BACKET_NAME, key, expiration); final File realfile = File.createTempFile(IdUtil.createIdbyUUID(), prefix);
return url; file.transferTo(realfile);
} String url = OssUtil.uploadObject2OSS(realfile, "");
//System.out.println(url);
return url;
}
/** /**
* MultipartFile 形式上传文件 * MultipartFile 形式上传文件
* @param file *
* @return * @param file
* @throws Exception * @return
*/ * @throws Exception
public static String upload(MultipartFile file) throws Exception { */
String fileName = file.getOriginalFilename(); public static String upload(MultipartFile file, String secondaryFolderName) throws Exception {
String prefix = fileName.substring(fileName.lastIndexOf(".")); String fileName = file.getOriginalFilename();
final File realfile = File.createTempFile(IdUtil.createIdbyUUID(), prefix); String prefix = fileName.substring(fileName.lastIndexOf("."));
file.transferTo(realfile); final File realfile = File.createTempFile(IdUtil.createIdbyUUID(), prefix);
String url = OssUtil.uploadObject2OSS(realfile, ""); file.transferTo(realfile);
//System.out.println(url); String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName);
return url; //System.out.println(url);
} return url;
/** }
* MultipartFile 形式上传文件
* @param file
* @return
* @throws Exception
*/
public static String upload(MultipartFile file, String secondaryFolderName) throws Exception {
String fileName = file.getOriginalFilename();
String prefix = fileName.substring(fileName.lastIndexOf("."));
final File realfile = File.createTempFile(IdUtil.createIdbyUUID(), prefix);
file.transferTo(realfile);
String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName);
//System.out.println(url);
return url;
}
/**
* MultipartFile 形式上传文件
* @param file
* @return
* @throws Exception
*/
public static String upload(MultipartFile file, String fileName,String secondaryFolderName) throws Exception {
String prefix = fileName.substring( fileName.lastIndexOf( "." ) ).toLowerCase();
final File realfile = File.createTempFile(fileName, prefix);
file.transferTo(realfile);
String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName);
//System.out.println(url);
return url;
}
/** /**
* MultipartFile 形式上传文件 * MultipartFile 形式上传文件
* @param realfile *
* @return * @param file
* @throws Exception * @return
*/ * @throws Exception
public static String upload(File realfile,String secondaryFolderName) { */
String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName); public static String upload(MultipartFile file, String fileName, String secondaryFolderName) throws Exception {
return url; String prefix = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
} final File realfile = File.createTempFile(fileName, prefix);
file.transferTo(realfile);
String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName);
//System.out.println(url);
return url;
}
/**
* MultipartFile 形式上传文件
*
* @param realfile
* @return
* @throws Exception
*/
public static String upload(File realfile, String secondaryFolderName) {
String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName);
return url;
}
/**
* 以byte数组上传到oss /**
* @param fbytes byte数组 * 以byte数组上传到oss
* @param fileName 文件名称 *
* @param secondaryFolderName 二级文件夹目录 * @param fbytes byte数组
* @return * @param fileName 文件名称
* @throws Exception * @param secondaryFolderName 二级文件夹目录
*/ * @return
public static String upload(byte[] fbytes,String fileName,String secondaryFolderName) throws Exception { * @throws Exception
OSSClient ossClient = getOSSClient(); */
public static String upload(byte[] fbytes, String fileName, String secondaryFolderName) throws Exception {
OSSClient ossClient = getOSSClient();
// String fileNameNew = "1.jpg"; // String fileNameNew = "1.jpg";
// 上传Byte数组。 // 上传Byte数组。
PutObjectResult putResult = ossClient.putObject(BACKET_NAME, FOLDER + secondaryFolderName + "/" + fileName, new ByteArrayInputStream(fbytes)); PutObjectResult putResult = ossClient.putObject(BACKET_NAME, FOLDER + secondaryFolderName + "/" + fileName, new ByteArrayInputStream(fbytes));
// 解析结果 // 解析结果
URL url = getUrl(ossClient, putResult.getETag()); URL url = getUrl(ossClient, putResult.getETag());
// System.out.println(url); // System.out.println(url);
// 关闭OSSClient。 // 关闭OSSClient。
ossClient.shutdown(); ossClient.shutdown();
return "https://" + BACKET_NAME + "." + ENDPOINT + "/" + FOLDER + secondaryFolderName + "/" + fileName; return "https://" + BACKET_NAME + "." + ENDPOINT + "/" + FOLDER + secondaryFolderName + "/" + fileName;
} }
/**
* 将文件转换成byte数组
* @param tradeFile
* @return
*/
public static byte[] File2byte(File tradeFile){
byte[] buffer = null;
try
{
FileInputStream fis = new FileInputStream(tradeFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1)
{
bos.write(b, 0, n);
}
fis.close();
bos.close();
buffer = bos.toByteArray();
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
return buffer;
}
public static void main(String [] args) throws Exception { /**
boolean flag = deleteFile("http://guangzhou-douli.oss-cn-shenzhen.aliyuncs.com/shouli/qcrod/2.jpg"); * 将文件转换成byte数组
//System.out.println(flag); *
* @param tradeFile
* @return
*/
public static byte[] File2byte(File tradeFile) {
byte[] buffer = null;
try {
FileInputStream fis = new FileInputStream(tradeFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
fis.close();
bos.close();
buffer = bos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return buffer;
}
File file = new File("C:\\Users\\yangshanlin\\Desktop\\bg-sfxt.jpg"); public static void main(String[] args) throws Exception {
byte[] b = File2byte(file); File file = new File("D:\\123.mp4");
//System.out.println(b); byte[] b = File2byte(file);
//System.out.println(b);
// boolean flag = deleteFile("https://diaosaas-prod.oss-cn-shenzhen.aliyuncs.com/africa-shop/hello/hello.jpg");
String s = upload(b, "hello.mp4", "hello");
System.out.println(s);
// System.out.println(flag);
String s = upload(b,"3.jpg","qcrod"); }
//System.out.println(s);
}
public static State uploadToAliOss(byte[] data, String fileName, String secondaryFolderName) throws Exception { public static State uploadToAliOss(byte[] data, String fileName, String secondaryFolderName) throws Exception {
String path=upload(data,fileName,secondaryFolderName); String path = upload(data, fileName, secondaryFolderName);
State state = new BaseState(true, path); State state = new BaseState(true, path);
state.putInfo("size", data.length); state.putInfo("size", data.length);
state.putInfo("title",fileName); state.putInfo("title", fileName);
state.putInfo("url",path); state.putInfo("url", path);
return state; return state;
} }
public static State uploadFileToAliOss(File realfile, String secondaryFolderName) { public static State uploadFileToAliOss(File realfile, String secondaryFolderName) {
String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName); String url = OssUtil.uploadObject2OSS(realfile, secondaryFolderName);
State state = new BaseState(true, url); State state = new BaseState(true, url);
state.putInfo("title",realfile.getName()); state.putInfo("title", realfile.getName());
state.putInfo("url",url); state.putInfo("url", url);
return state; return state;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论