cos配置 id配置
This commit is contained in:
parent
bf62105bc7
commit
29c6f7f24d
@ -36,7 +36,7 @@ private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** id */
|
||||
@TableId(value = "id")
|
||||
@TableId(value = "id",type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
/** 状态 */
|
||||
|
@ -33,8 +33,8 @@ private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** 规格ID */
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
@TableId(value = "id",type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
/** 部门ID */
|
||||
@Excel(name = "部门ID")
|
||||
|
@ -33,8 +33,8 @@ private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** 商品ID */
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
@TableId(value = "id",type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
/** 部门ID */
|
||||
@Excel(name = "部门ID")
|
||||
|
@ -33,8 +33,8 @@ private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** 规格ID */
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
@TableId(value = "id",type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
/** 部门ID */
|
||||
@Excel(name = "部门ID")
|
||||
|
@ -37,8 +37,8 @@ public class WineryOrders implements Serializable {
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
@TableId(value = "id",type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
|
@ -33,8 +33,8 @@ private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** 规格ID */
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
@TableId(value = "id",type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
/** 部门ID */
|
||||
@Excel(name = "部门ID")
|
||||
|
@ -67,7 +67,7 @@ public class CommonController {
|
||||
* 通用上传请求
|
||||
*/
|
||||
@PostMapping("/common/upload")
|
||||
public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
||||
public AjaxResult uploadFile(String type, MultipartFile file) throws Exception {
|
||||
try {
|
||||
|
||||
// 上传文件路径
|
||||
@ -75,9 +75,13 @@ public class CommonController {
|
||||
// 上传并返回新文件名称
|
||||
// String fileName = FileUploadUtils.upload(filePath, file);
|
||||
|
||||
if (StringUtils.isEmpty(type)) {
|
||||
type = "defalut";
|
||||
}
|
||||
|
||||
String fileName = cosUtils.upload(file);
|
||||
String url = serverConfig.getUrl() + "/common/file?fileName=" + fileName;
|
||||
|
||||
String fileName = cosUtils.upload(type, file);
|
||||
String url = serverConfig.getUrl() + "/common/file?fileName=" + fileName;
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("fileName", fileName);
|
||||
ajax.put("url", url);
|
||||
|
@ -2,6 +2,7 @@ package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ruoyi.common.config.CosProperties;
|
||||
import com.ruoyi.common.utils.file.CosUtils;
|
||||
import com.ruoyi.framework.config.ServerConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -28,13 +29,12 @@ import com.ruoyi.system.service.ISysUserService;
|
||||
|
||||
/**
|
||||
* 个人信息 业务处理
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/user/profile")
|
||||
public class SysProfileController extends BaseController
|
||||
{
|
||||
public class SysProfileController extends BaseController {
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@ -45,15 +45,15 @@ public class SysProfileController extends BaseController
|
||||
@Autowired
|
||||
private CosUtils cosUtils;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ServerConfig serverConfig;
|
||||
private CosProperties cosProperties;
|
||||
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
@GetMapping
|
||||
public AjaxResult profile()
|
||||
{
|
||||
public AjaxResult profile() {
|
||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
SysUser user = loginUser.getUser();
|
||||
AjaxResult ajax = AjaxResult.success(user);
|
||||
@ -67,10 +67,8 @@ public class SysProfileController extends BaseController
|
||||
*/
|
||||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult updateProfile(@RequestBody SysUser user)
|
||||
{
|
||||
if (userService.updateUserProfile(user) > 0)
|
||||
{
|
||||
public AjaxResult updateProfile(@RequestBody SysUser user) {
|
||||
if (userService.updateUserProfile(user) > 0) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// 更新缓存用户信息
|
||||
loginUser.getUser().setNickName(user.getNickName());
|
||||
@ -88,21 +86,17 @@ public class SysProfileController extends BaseController
|
||||
*/
|
||||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/updatePwd")
|
||||
public AjaxResult updatePwd(String oldPassword, String newPassword)
|
||||
{
|
||||
public AjaxResult updatePwd(String oldPassword, String newPassword) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
String userName = loginUser.getUsername();
|
||||
String password = loginUser.getPassword();
|
||||
if (!SecurityUtils.matchesPassword(oldPassword, password))
|
||||
{
|
||||
if (!SecurityUtils.matchesPassword(oldPassword, password)) {
|
||||
return AjaxResult.error("修改密码失败,旧密码错误");
|
||||
}
|
||||
if (SecurityUtils.matchesPassword(newPassword, password))
|
||||
{
|
||||
if (SecurityUtils.matchesPassword(newPassword, password)) {
|
||||
return AjaxResult.error("新密码不能与旧密码相同");
|
||||
}
|
||||
if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0)
|
||||
{
|
||||
if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0) {
|
||||
// 更新缓存用户密码
|
||||
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
||||
tokenService.setLoginUser(loginUser);
|
||||
@ -116,18 +110,15 @@ public class SysProfileController extends BaseController
|
||||
*/
|
||||
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/avatar")
|
||||
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException
|
||||
{
|
||||
if (!file.isEmpty())
|
||||
{
|
||||
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
|
||||
if (!file.isEmpty()) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
|
||||
String fileName = cosUtils.upload(file);
|
||||
String avatar = "/common/file?fileName=" + fileName;
|
||||
String fileName = cosUtils.upload("avatar", file);
|
||||
String avatar = cosProperties.getBucketUrl() + fileName;
|
||||
|
||||
// String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
||||
if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
||||
{
|
||||
if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("imgUrl", avatar);
|
||||
// 更新缓存用户头像
|
||||
|
@ -205,4 +205,12 @@ wxmini:
|
||||
secret: 94ee42c0899a6ceccf353e1e729c50d4 #微信小程序的Secret
|
||||
token: xiao4r #微信小程序消息服务器配置的token
|
||||
aesKey: jNXajd2sQSMYQNg3rcdMF9HraUJxXF0iswgdMxVik9W #微信小程序消息服务器配置的EncodingAESKey
|
||||
msgDataFormat: JSON
|
||||
msgDataFormat: JSON
|
||||
|
||||
# cos存储配置
|
||||
tencent-cos:
|
||||
bucketName: winery-1257413599
|
||||
bucketUrl: https://winery-1257413599.cos.ap-beijing.myqcloud.com/
|
||||
secretId: AKIDovztW8x0DpQnunSw2uXUDhw3IH0fQC75
|
||||
secretKey: rCH8tOfjX5XjegYBXfkZWc2E75nJq9Dx
|
||||
region: ap-beijing
|
||||
|
@ -5,6 +5,9 @@ import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@ -13,14 +16,17 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @since 2020-12-28
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({CosProperties.class})
|
||||
public class CosConfig {
|
||||
|
||||
@Autowired
|
||||
private CosProperties properties;
|
||||
|
||||
@Bean(name = "cosCredentials")
|
||||
public COSCredentials cosCredentials() {
|
||||
// 1 初始化用户身份信息(secretId, secretKey)。
|
||||
String secretId = "AKIDovztW8x0DpQnunSw2uXUDhw3IH0fQC75";
|
||||
String secretKey = "rCH8tOfjX5XjegYBXfkZWc2E75nJq9Dx";
|
||||
String secretId = properties.secretId;
|
||||
String secretKey = properties.secretKey;
|
||||
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
|
||||
return cred;
|
||||
}
|
||||
@ -31,7 +37,7 @@ public class CosConfig {
|
||||
public ClientConfig cosClientConfig() {
|
||||
// 2 设置 bucket 的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
|
||||
// clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
|
||||
Region region = new Region("ap-beijing");
|
||||
Region region = new Region(properties.region);
|
||||
ClientConfig clientConfig = new ClientConfig(region);
|
||||
return clientConfig;
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.ruoyi.common.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "tencent-cos")
|
||||
public class CosProperties {
|
||||
|
||||
String bucketName;
|
||||
String bucketUrl;
|
||||
String secretId;
|
||||
String secretKey;
|
||||
String region;
|
||||
}
|
@ -7,6 +7,7 @@ import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.model.*;
|
||||
import com.qcloud.cos.transfer.Download;
|
||||
import com.ruoyi.common.config.CosProperties;
|
||||
import com.ruoyi.common.utils.uuid.UUID;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -37,13 +38,13 @@ public class CosUtils {
|
||||
@Autowired
|
||||
ClientConfig clientConfig;
|
||||
|
||||
@Autowired
|
||||
private CosProperties properties;
|
||||
|
||||
// 指定要上传到的存储桶
|
||||
|
||||
final String bucketName = "winery-1257413599";
|
||||
String SPECIAL_CHARACTERS = "[`~! @#$%^&*()+=|{}':;',//[//]<>/?~!@#¥%……&*()_——+|{}【】‘;:”“’。,、?]";
|
||||
|
||||
public String upload(MultipartFile file) {
|
||||
public String upload(String type, MultipartFile file) {
|
||||
|
||||
|
||||
// 指定要上传到 COS 上对象键
|
||||
@ -55,7 +56,7 @@ public class CosUtils {
|
||||
metadata.setContentLength(file.getSize());
|
||||
file.getContentType();
|
||||
try {
|
||||
PutObjectResult putObjectResult = cosClient.putObject(bucketName, key, file.getInputStream(), metadata);
|
||||
PutObjectResult putObjectResult = cosClient.putObject(properties.getBucketName(), type + "/" + key, file.getInputStream(), metadata);
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -63,14 +64,14 @@ public class CosUtils {
|
||||
|
||||
cosClient.shutdown();
|
||||
}
|
||||
return key;
|
||||
return type + "/" + key;
|
||||
|
||||
}
|
||||
|
||||
public void getFile(String fileName, HttpServletResponse response) {
|
||||
|
||||
COSClient cosClient = new COSClient(cosCredentials, clientConfig);
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, fileName);
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(properties.getBucketName(), fileName);
|
||||
// 限流使用的单位是bit/s, 这里设置下载带宽限制为 10MB/s
|
||||
getObjectRequest.setTrafficLimit(80 * 1024 * 1024);
|
||||
|
||||
@ -104,5 +105,4 @@ public class CosUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
11
ruoyi-ui/src/mixin/common.js
Normal file
11
ruoyi-ui/src/mixin/common.js
Normal file
@ -0,0 +1,11 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
|
||||
Vue.filter('getImageForKey', val => {
|
||||
return "https://winery-1257413599.cos.ap-beijing.myqcloud.com/" + val
|
||||
})
|
||||
|
||||
Vue.filter('getImage200', val => {
|
||||
return "https://winery-1257413599.cos.ap-beijing.myqcloud.com/" + val + "?imageMogr2/thumbnail/!200x200r/|imageMogr2/gravity/center/crop/200x200/interlace/0"
|
||||
})
|
||||
|
@ -51,7 +51,8 @@ const user = {
|
||||
return new Promise((resolve, reject) => {
|
||||
getInfo(state.token).then(res => {
|
||||
const user = res.user
|
||||
const avatar = user.avatar == "" ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar;
|
||||
const avatar = user.avatar == "" ? require("@/assets/images/profile.jpg") : user.avatar;
|
||||
|
||||
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
|
||||
commit('SET_ROLES', res.roles)
|
||||
commit('SET_PERMISSIONS', res.permissions)
|
||||
|
@ -126,7 +126,7 @@ export default {
|
||||
formData.append("avatarfile", data);
|
||||
uploadAvatar(formData).then(response => {
|
||||
this.open = false;
|
||||
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
|
||||
this.options.img = response.imgUrl;
|
||||
store.commit('SET_AVATAR', this.options.img);
|
||||
this.msgSuccess("修改成功");
|
||||
this.visible = false;
|
||||
@ -164,4 +164,4 @@ export default {
|
||||
line-height: 110px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
@ -19,24 +19,17 @@
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
<el-form-item label="商品类型" prop="goodsType">
|
||||
<el-select v-model="queryParams.goodsType" placeholder="请选择商品类型" clearable size="small">
|
||||
<el-option label="请选择字典生成" value=""/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品说明" prop="goodsDesc">
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input
|
||||
v-model="queryParams.goodsDesc"
|
||||
placeholder="请输入商品说明"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品封面" prop="goodsFaceImg">
|
||||
<el-input
|
||||
v-model="queryParams.goodsFaceImg"
|
||||
placeholder="请输入商品封面"
|
||||
v-model="queryParams.remark"
|
||||
placeholder="请输入商品简称"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
@ -100,10 +93,14 @@
|
||||
<el-table-column label="商品名称" align="center" prop="goodsName"/>
|
||||
<el-table-column label="商品简称" align="center" prop="goodsAlias"/>
|
||||
<el-table-column label="商品类型" align="center" prop="goodsType"/>
|
||||
<el-table-column label="关联规格" align="center" prop="goodsSpec"/>
|
||||
<!-- <el-table-column label="关联规格" align="center" prop="goodsSpec"/>-->
|
||||
<el-table-column label="商品说明" align="center" prop="goodsDesc"/>
|
||||
<el-table-column label="商品封面" align="center" prop="goodsFaceImg"/>
|
||||
<el-table-column label="商品图片" align="center" prop="goodsImg"/>
|
||||
<el-table-column label="商品封面" align="center" prop="goodsFaceImg">
|
||||
<template slot-scope="scope">
|
||||
<el-image :src="scope.row.goodsFaceImg|getImageForKey" style="width: 60px; height: 60px" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- <el-table-column label="商品图片" align="center" prop="goodsImg"/>-->
|
||||
<el-table-column label="备注" align="center" prop="remark"/>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
@ -190,8 +187,11 @@ import {
|
||||
import UploadImage from '@/components/UploadImage/index'
|
||||
import UploadImageMultiple from '@/components/UploadImageMultiple/index'
|
||||
|
||||
import CommonMixin from "@/mixin/common";
|
||||
|
||||
export default {
|
||||
name: "Winery_goods",
|
||||
mixins:[CommonMixin],
|
||||
components: {
|
||||
UploadImage,
|
||||
UploadImageMultiple,
|
||||
|
Loading…
x
Reference in New Issue
Block a user