文件上传接口实现
This commit is contained in:
@@ -6,10 +6,8 @@ import com.czg.account.dto.staff.ShopStaffAddDTO;
|
||||
import com.czg.account.dto.staff.ShopStaffEditDTO;
|
||||
import com.czg.account.dto.staff.ShopStaffRemoveDTO;
|
||||
import com.czg.account.entity.ShopStaff;
|
||||
import com.czg.account.entity.SysRole;
|
||||
import com.czg.account.entity.SysUser;
|
||||
import com.czg.account.service.ShopStaffService;
|
||||
import com.czg.account.service.SysRoleService;
|
||||
import com.czg.account.service.SysUserService;
|
||||
import com.czg.account.service.SysUsersRolesService;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
@@ -33,8 +31,6 @@ public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
@Resource
|
||||
private SysUsersRolesService sysUsersRolesService;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (c) 2018 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.czg.service.account.util;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 阿里云存储
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Component
|
||||
public class AliOssUtil{
|
||||
|
||||
private final String endPoint = "oss-cn-beijing.aliyuncs.com";
|
||||
private final String accessKey = "LTAI5tPdEfYSZcqHbjCrtPRD";
|
||||
private final String secretKey = "DZjyHBq3nTujF0NMLxnZgsecU8ZCvy";
|
||||
private final String bucketName = "cashier-oss";
|
||||
private final String url = "cashier-oss.oss-cn-beijing.aliyuncs.com";
|
||||
private final String prefix = "upload";
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
* @param prefix 前缀
|
||||
* @param suffix 后缀
|
||||
* @return 返回上传路径
|
||||
*/
|
||||
public String getPath(String prefix, String suffix) {
|
||||
//生成uuid
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
//文件路径
|
||||
String path = DateUtil.date().getDay() + "/" + uuid;
|
||||
|
||||
if(StrUtil.isNotBlank(prefix)){
|
||||
path = prefix + "/" + path;
|
||||
}
|
||||
|
||||
return path + "." + suffix;
|
||||
}
|
||||
|
||||
public String upload(InputStream inputStream, String path) throws Exception {
|
||||
OSSClient client = new OSSClient(endPoint, accessKey, secretKey);
|
||||
try {
|
||||
client.putObject(bucketName, path, inputStream);
|
||||
client.shutdown();
|
||||
} catch (Exception e){
|
||||
throw new Exception("上传异常");
|
||||
}
|
||||
|
||||
return "https://" + url + "/" + path;
|
||||
}
|
||||
|
||||
public String uploadSuffix(byte[] data, String suffix) throws Exception {
|
||||
return upload(new ByteArrayInputStream(data), getPath(prefix, suffix));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,8 @@
|
||||
<select id="selectByUserId" resultType="com.czg.account.entity.SysMenu">
|
||||
select c.*
|
||||
from sys_users_roles as a
|
||||
left join sys_roles_menus as b on a.role_id = b.role_id
|
||||
left join sys_menu as c on c.menu_id = b.menu_id
|
||||
left join sys_roles_menus as b on a.role_id = b.role_id
|
||||
left join sys_menu as c on c.menu_id = b.menu_id
|
||||
where a.user_id = #{userId}
|
||||
<if test="type != null">
|
||||
and c.type=#{type}
|
||||
|
||||
Reference in New Issue
Block a user