商品管理的图片编辑和用户管理的图片编辑功能优化,配置文件的优化
This commit is contained in:
@@ -280,6 +280,33 @@ export interface PermissionVO {
|
|||||||
updateTime: string
|
updateTime: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ObjectStorageFileVO {
|
||||||
|
id: number
|
||||||
|
fileName: string
|
||||||
|
fileUrl: string
|
||||||
|
status: number
|
||||||
|
createTime: string
|
||||||
|
updateTime: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const adminFileApi = {
|
||||||
|
uploadFile: (file: File) => {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('file', file)
|
||||||
|
return adminApi.post<ObjectStorageFileVO>('/admin/object-storage-file/upload', formData, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getSignedUrl: (fileId: number, expiryTimeInMinutes?: number) => {
|
||||||
|
return adminApi.get<string>(`/admin/object-storage-file/get-signed-url/${fileId}`, {
|
||||||
|
params: { expiryTimeInMinutes }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const permissionApi = {
|
export const permissionApi = {
|
||||||
listAllPermissions: () => {
|
listAllPermissions: () => {
|
||||||
return adminApi.get<PermissionVO[]>('/admin/permission/list/all')
|
return adminApi.get<PermissionVO[]>('/admin/permission/list/all')
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<a-image
|
<a-image
|
||||||
:width="60"
|
:width="60"
|
||||||
:height="60"
|
:height="60"
|
||||||
:src="record.imageFileIds ? record.imageFileIds.split(',')[0] : DEFAULT_PRODUCT_IMAGE"
|
:src="imageUrls[record.id] || DEFAULT_PRODUCT_IMAGE"
|
||||||
style="object-fit: cover; border-radius: 4px;"
|
style="object-fit: cover; border-radius: 4px;"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
<a-modal
|
<a-modal
|
||||||
v-model:open="modalVisible"
|
v-model:open="modalVisible"
|
||||||
:title="isEdit ? '编辑商品' : '新增商品'"
|
:title="isEdit ? '编辑商品' : '新增商品'"
|
||||||
width="600px"
|
width="700px"
|
||||||
@ok="handleModalOk"
|
@ok="handleModalOk"
|
||||||
@cancel="handleModalCancel"
|
@cancel="handleModalCancel"
|
||||||
:confirmLoading="modalLoading"
|
:confirmLoading="modalLoading"
|
||||||
@@ -87,8 +87,24 @@
|
|||||||
:rows="3"
|
:rows="3"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="图片ID" name="imageFileIds">
|
<a-form-item label="商品图片">
|
||||||
<a-input v-model:value="formState.imageFileIds" placeholder="请输入图片文件ID,多个用逗号分隔" />
|
<a-upload
|
||||||
|
v-model:file-list="imageFileList"
|
||||||
|
list-type="picture-card"
|
||||||
|
:custom-request="handleUploadImage"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
|
@preview="handlePreview"
|
||||||
|
@remove="handleRemove"
|
||||||
|
:max-count="5"
|
||||||
|
>
|
||||||
|
<div v-if="imageFileList.length < 5">
|
||||||
|
<plus-outlined />
|
||||||
|
<div style="margin-top: 8px">上传图片</div>
|
||||||
|
</div>
|
||||||
|
</a-upload>
|
||||||
|
<a-modal v-model:open="previewVisible" :footer="null" @cancel="previewVisible = false">
|
||||||
|
<img alt="预览" style="width: 100%" :src="previewImage" />
|
||||||
|
</a-modal>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="价格" name="price">
|
<a-form-item label="价格" name="price">
|
||||||
<a-input-number
|
<a-input-number
|
||||||
@@ -105,6 +121,12 @@
|
|||||||
<a-form-item label="标签ID" name="tags">
|
<a-form-item label="标签ID" name="tags">
|
||||||
<a-input v-model:value="formState.tags" placeholder="请输入标签ID,多个用分号分隔" />
|
<a-input v-model:value="formState.tags" placeholder="请输入标签ID,多个用分号分隔" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
<a-form-item label="可预约美甲师ID" name="bookableArtists">
|
||||||
|
<a-input v-model:value="formState.bookableArtists" placeholder="请输入美甲师ID,多个用逗号分隔" />
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="可用优惠券ID" name="availableCoupons">
|
||||||
|
<a-input v-model:value="formState.availableCoupons" placeholder="请输入优惠券ID,多个用逗号分隔" />
|
||||||
|
</a-form-item>
|
||||||
<a-form-item label="店铺" name="shopId">
|
<a-form-item label="店铺" name="shopId">
|
||||||
<a-select
|
<a-select
|
||||||
v-model:value="formState.shopId"
|
v-model:value="formState.shopId"
|
||||||
@@ -136,10 +158,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import type { FormInstance } from 'ant-design-vue'
|
import type { FormInstance, UploadProps } from 'ant-design-vue'
|
||||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||||
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||||
import { adminProductApi, type Product, adminShopApi, type Shop } from '@/api/admin'
|
import { adminProductApi, type Product, adminShopApi, type Shop, adminFileApi, type ObjectStorageFileVO } from '@/api/admin'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const searchText = ref('')
|
const searchText = ref('')
|
||||||
@@ -151,6 +173,12 @@ const formRef = ref<FormInstance>()
|
|||||||
const currentProduct = ref<Product | null>(null)
|
const currentProduct = ref<Product | null>(null)
|
||||||
const shops = ref<Shop[]>([])
|
const shops = ref<Shop[]>([])
|
||||||
const loadingShops = ref(false)
|
const loadingShops = ref(false)
|
||||||
|
const previewVisible = ref(false)
|
||||||
|
const previewImage = ref('')
|
||||||
|
const imageFileList = ref<any[]>([])
|
||||||
|
const uploadedFileIds = ref<string[]>([])
|
||||||
|
const imageUrls = ref<Record<number, string>>({})
|
||||||
|
const imageIdCache = ref<Record<string, string>>({})
|
||||||
|
|
||||||
const pagination = reactive({
|
const pagination = reactive({
|
||||||
current: 1,
|
current: 1,
|
||||||
@@ -239,6 +267,9 @@ const fetchProductList = async () => {
|
|||||||
const res = await adminProductApi.listProducts(params)
|
const res = await adminProductApi.listProducts(params)
|
||||||
productList.value = res.list || []
|
productList.value = res.list || []
|
||||||
pagination.total = res.total || 0
|
pagination.total = res.total || 0
|
||||||
|
|
||||||
|
// 预加载图片签名链接
|
||||||
|
await loadImageUrls(res.list || [])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('获取商品列表失败')
|
message.error('获取商品列表失败')
|
||||||
} finally {
|
} finally {
|
||||||
@@ -246,6 +277,31 @@ const fetchProductList = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadImageUrls = async (products: Product[]) => {
|
||||||
|
for (const product of products) {
|
||||||
|
if (product.imageFileIds) {
|
||||||
|
const firstId = product.imageFileIds.split(',')[0]
|
||||||
|
if (firstId) {
|
||||||
|
try {
|
||||||
|
// 检查缓存
|
||||||
|
if (!imageIdCache.value[firstId]) {
|
||||||
|
const signedUrl = await adminFileApi.getSignedUrl(Number(firstId))
|
||||||
|
imageIdCache.value[firstId] = signedUrl
|
||||||
|
}
|
||||||
|
imageUrls.value[product.id] = imageIdCache.value[firstId]
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取签名链接失败:', error)
|
||||||
|
imageUrls.value[product.id] = DEFAULT_PRODUCT_IMAGE
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
imageUrls.value[product.id] = DEFAULT_PRODUCT_IMAGE
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
imageUrls.value[product.id] = DEFAULT_PRODUCT_IMAGE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
pagination.current = 1
|
pagination.current = 1
|
||||||
fetchProductList()
|
fetchProductList()
|
||||||
@@ -271,10 +327,12 @@ const showAddModal = () => {
|
|||||||
bookableArtists: '',
|
bookableArtists: '',
|
||||||
availableCoupons: ''
|
availableCoupons: ''
|
||||||
})
|
})
|
||||||
|
imageFileList.value = []
|
||||||
|
uploadedFileIds.value = []
|
||||||
modalVisible.value = true
|
modalVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const showEditModal = (record: Product) => {
|
const showEditModal = async (record: Product) => {
|
||||||
isEdit.value = true
|
isEdit.value = true
|
||||||
currentProduct.value = record
|
currentProduct.value = record
|
||||||
Object.assign(formState, {
|
Object.assign(formState, {
|
||||||
@@ -288,9 +346,94 @@ const showEditModal = (record: Product) => {
|
|||||||
bookableArtists: record.bookableArtists,
|
bookableArtists: record.bookableArtists,
|
||||||
availableCoupons: record.availableCoupons
|
availableCoupons: record.availableCoupons
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (record.imageFileIds) {
|
||||||
|
const ids = record.imageFileIds.split(',')
|
||||||
|
uploadedFileIds.value = ids
|
||||||
|
|
||||||
|
// 加载图片签名链接
|
||||||
|
const fileList = []
|
||||||
|
for (const [index, id] of ids.entries()) {
|
||||||
|
try {
|
||||||
|
// 检查缓存
|
||||||
|
if (!imageIdCache.value[id]) {
|
||||||
|
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||||
|
imageIdCache.value[id] = signedUrl
|
||||||
|
}
|
||||||
|
fileList.push({
|
||||||
|
uid: id,
|
||||||
|
name: `图片${index + 1}`,
|
||||||
|
status: 'done',
|
||||||
|
url: imageIdCache.value[id]
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取签名链接失败:', error)
|
||||||
|
fileList.push({
|
||||||
|
uid: id,
|
||||||
|
name: `图片${index + 1}`,
|
||||||
|
status: 'done',
|
||||||
|
url: ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageFileList.value = fileList
|
||||||
|
} else {
|
||||||
|
imageFileList.value = []
|
||||||
|
uploadedFileIds.value = []
|
||||||
|
}
|
||||||
modalVisible.value = true
|
modalVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const beforeUpload = (file: File) => {
|
||||||
|
const isImage = file.type.startsWith('image/')
|
||||||
|
if (!isImage) {
|
||||||
|
message.error('只能上传图片文件!')
|
||||||
|
}
|
||||||
|
const isLt2M = file.size / 1024 / 1024 < 2
|
||||||
|
if (!isLt2M) {
|
||||||
|
message.error('图片大小不能超过 2MB!')
|
||||||
|
}
|
||||||
|
return isImage && isLt2M
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleUploadImage = async (options: any) => {
|
||||||
|
const { file, onSuccess, onError } = options
|
||||||
|
try {
|
||||||
|
const res = await adminFileApi.uploadFile(file)
|
||||||
|
uploadedFileIds.value.push(String(res.id))
|
||||||
|
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||||
|
onSuccess({ url: String(res.id) })
|
||||||
|
message.success('图片上传成功')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('图片上传失败:', error)
|
||||||
|
onError(error)
|
||||||
|
message.error('图片上传失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePreview = async (file: any) => {
|
||||||
|
try {
|
||||||
|
// 检查缓存
|
||||||
|
if (!imageIdCache.value[file.uid]) {
|
||||||
|
const signedUrl = await adminFileApi.getSignedUrl(Number(file.uid))
|
||||||
|
imageIdCache.value[file.uid] = signedUrl
|
||||||
|
}
|
||||||
|
previewImage.value = imageIdCache.value[file.uid]
|
||||||
|
previewVisible.value = true
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取预览链接失败:', error)
|
||||||
|
message.error('获取预览链接失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRemove = (file: any) => {
|
||||||
|
const index = uploadedFileIds.value.indexOf(file.uid)
|
||||||
|
if (index > -1) {
|
||||||
|
uploadedFileIds.value.splice(index, 1)
|
||||||
|
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleModalOk = async () => {
|
const handleModalOk = async () => {
|
||||||
try {
|
try {
|
||||||
await formRef.value?.validate()
|
await formRef.value?.validate()
|
||||||
@@ -323,6 +466,8 @@ const handleDelete = async (record: Product) => {
|
|||||||
try {
|
try {
|
||||||
await adminProductApi.deleteProduct(record.id)
|
await adminProductApi.deleteProduct(record.id)
|
||||||
message.success('删除成功')
|
message.success('删除成功')
|
||||||
|
// 从缓存中移除
|
||||||
|
delete imageUrls.value[record.id]
|
||||||
fetchProductList()
|
fetchProductList()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('删除失败:', error)
|
console.error('删除失败:', error)
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|||||||
path.contains("/api/user/refresh-token") ||
|
path.contains("/api/user/refresh-token") ||
|
||||||
path.contains("/api/shop/list/simple") ||
|
path.contains("/api/shop/list/simple") ||
|
||||||
path.contains("/api/admin/auth/login") ||
|
path.contains("/api/admin/auth/login") ||
|
||||||
|
path.contains("/api/admin/object-storage-file/upload") ||
|
||||||
path.contains("/health");
|
path.contains("/health");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||||||
"/api/user/refresh-token",
|
"/api/user/refresh-token",
|
||||||
"/api/shop/list/simple",
|
"/api/shop/list/simple",
|
||||||
"/api/admin/auth/login",
|
"/api/admin/auth/login",
|
||||||
|
"/api/admin/object-storage-file/upload",
|
||||||
"/error",
|
"/error",
|
||||||
"/health/**"
|
"/health/**"
|
||||||
);
|
);
|
||||||
|
|||||||
+68
-2
@@ -2,12 +2,15 @@ package com.xiaowang.yuminailcore.controller;
|
|||||||
|
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.dto.ObjectStorageFileDTO;
|
import com.xiaowang.yuminailcore.dto.ObjectStorageFileDTO;
|
||||||
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
|
import com.xiaowang.yuminailcore.service.MinioService;
|
||||||
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
||||||
|
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象存储文件信息表 Controller
|
* 对象存储文件信息表 Controller
|
||||||
@@ -17,11 +20,74 @@ import java.util.List;
|
|||||||
* @date 2026-02-13
|
* @date 2026-02-13
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/object-storage-file")
|
@RequestMapping("/api/admin/object-storage-file")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ObjectStorageFileController {
|
public class ObjectStorageFileController {
|
||||||
|
|
||||||
private final ObjectStorageFileService objectStorageFileService;
|
private final ObjectStorageFileService objectStorageFileService;
|
||||||
|
private final MinioService minioService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 文件ID和URL
|
||||||
|
*/
|
||||||
|
@PostMapping("/upload")
|
||||||
|
public Result<ObjectStorageFileVO> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||||
|
try {
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||||
|
String objectName = UUID.randomUUID().toString() + fileExtension;
|
||||||
|
|
||||||
|
String fileUrl = minioService.uploadFile(file, objectName);
|
||||||
|
|
||||||
|
ObjectStorageFileDTO dto = new ObjectStorageFileDTO();
|
||||||
|
dto.setFileName(originalFilename);
|
||||||
|
dto.setFileUrl(fileUrl);
|
||||||
|
dto.setStatus(1);
|
||||||
|
|
||||||
|
Long fileId = objectStorageFileService.createObjectStorageFile(dto);
|
||||||
|
ObjectStorageFileVO fileVO = objectStorageFileService.getObjectStorageFileById(fileId);
|
||||||
|
|
||||||
|
return Result.success(fileVO);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("文件上传失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取带签名的图片链接
|
||||||
|
*
|
||||||
|
* @param fileId 文件ID
|
||||||
|
* @param expiryTimeInMinutes 有效期(分钟),默认60分钟
|
||||||
|
* @return 带签名的临时访问链接
|
||||||
|
*/
|
||||||
|
@GetMapping("/get-signed-url/{fileId}")
|
||||||
|
public Result<String> getSignedUrl(@PathVariable Long fileId, @RequestParam(defaultValue = "60") Integer expiryTimeInMinutes) {
|
||||||
|
try {
|
||||||
|
ObjectStorageFileVO fileVO = objectStorageFileService.getObjectStorageFileById(fileId);
|
||||||
|
if (fileVO == null) {
|
||||||
|
return Result.error("文件不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从fileUrl中提取objectName
|
||||||
|
String fileUrl = fileVO.getFileUrl();
|
||||||
|
// 提取最后一个/后面的部分作为objectName
|
||||||
|
int lastSlashIndex = fileUrl.lastIndexOf("/");
|
||||||
|
if (lastSlashIndex == -1) {
|
||||||
|
return Result.error("文件URL格式错误");
|
||||||
|
}
|
||||||
|
String objectName = fileUrl.substring(lastSlashIndex + 1);
|
||||||
|
|
||||||
|
String signedUrl = minioService.getPresignedUrl(objectName, expiryTimeInMinutes);
|
||||||
|
return Result.success(signedUrl);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("获取签名链接失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文件
|
* 创建文件
|
||||||
|
|||||||
+14
-2
@@ -9,6 +9,7 @@ import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
|||||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||||
|
import com.xiaowang.yuminailcore.service.MinioService;
|
||||||
import com.xiaowang.yuminailcore.service.UserService;
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -31,6 +32,7 @@ import java.util.UUID;
|
|||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final MinioService minioService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建用户
|
* 创建用户
|
||||||
@@ -234,10 +236,20 @@ public class UserController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/upload-avatar")
|
@PostMapping("/upload-avatar")
|
||||||
public Result<String> uploadAvatar(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
|
public Result<String> uploadAvatar(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
|
||||||
|
try {
|
||||||
Long userId = (Long) request.getAttribute("userId");
|
Long userId = (Long) request.getAttribute("userId");
|
||||||
String fileName = UUID.randomUUID().toString() + "_" + file.getOriginalFilename();
|
String originalFilename = file.getOriginalFilename();
|
||||||
String avatarUrl = "https://api.dicebear.com/7.x/avataaars/svg?seed=" + fileName;
|
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||||
|
String objectName = "avatar/" + userId + "/" + UUID.randomUUID().toString() + fileExtension;
|
||||||
|
|
||||||
|
String avatarUrl = minioService.uploadFile(file, objectName);
|
||||||
|
userService.updateUserAvatar(userId, avatarUrl);
|
||||||
|
|
||||||
return Result.success(avatarUrl);
|
return Result.success(avatarUrl);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("头像上传失败: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -52,4 +52,6 @@ public interface UserService extends IService<UserDO> {
|
|||||||
PageResultVO<UserVO> pageUsers(Integer page, Integer size, String keyword, Long shopId);
|
PageResultVO<UserVO> pageUsers(Integer page, Integer size, String keyword, Long shopId);
|
||||||
|
|
||||||
boolean updateUserStatus(Long id, Integer status);
|
boolean updateUserStatus(Long id, Integer status);
|
||||||
|
|
||||||
|
boolean updateUserAvatar(Long userId, String avatarUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -7,8 +7,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
||||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||||
|
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
||||||
import com.xiaowang.yuminailcore.service.ProductService;
|
import com.xiaowang.yuminailcore.service.ProductService;
|
||||||
import com.xiaowang.yuminailcore.service.TagService;
|
import com.xiaowang.yuminailcore.service.TagService;
|
||||||
|
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
|
||||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||||
import com.xiaowang.yuminailcore.vo.TagInfo;
|
import com.xiaowang.yuminailcore.vo.TagInfo;
|
||||||
@@ -17,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -33,6 +36,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
|||||||
|
|
||||||
private final ProductMapper productMapper;
|
private final ProductMapper productMapper;
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
|
private final ObjectStorageFileService objectStorageFileService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createProduct(ProductDTO productDTO) {
|
public Long createProduct(ProductDTO productDTO) {
|
||||||
@@ -180,6 +184,24 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
|||||||
productVO.setTagList(tagNames);
|
productVO.setTagList(tagNames);
|
||||||
productVO.setTagInfos(tagInfos);
|
productVO.setTagInfos(tagInfos);
|
||||||
|
|
||||||
|
// 转换图片ID为图片URL列表
|
||||||
|
List<String> imageUrls = new ArrayList<>();
|
||||||
|
if (productDO.getImageFileIds() != null && !productDO.getImageFileIds().isEmpty()) {
|
||||||
|
String[] fileIds = productDO.getImageFileIds().split(",");
|
||||||
|
for (String fileIdStr : fileIds) {
|
||||||
|
try {
|
||||||
|
Long fileId = Long.parseLong(fileIdStr.trim());
|
||||||
|
ObjectStorageFileVO fileVO = objectStorageFileService.getObjectStorageFileById(fileId);
|
||||||
|
if (fileVO != null && fileVO.getFileUrl() != null) {
|
||||||
|
imageUrls.add(fileVO.getFileUrl());
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 忽略无效的文件ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
productVO.setImageUrls(imageUrls);
|
||||||
|
|
||||||
return productVO;
|
return productVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
@@ -465,4 +465,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
userDO.setUpdateTime(LocalDateTime.now());
|
userDO.setUpdateTime(LocalDateTime.now());
|
||||||
return userMapper.updateById(userDO) > 0;
|
return userMapper.updateById(userDO) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateUserAvatar(Long userId, String avatarUrl) {
|
||||||
|
UserDO userDO = userMapper.selectById(userId);
|
||||||
|
if (userDO == null) {
|
||||||
|
throw new RuntimeException("用户不存在");
|
||||||
|
}
|
||||||
|
userDO.setAvatar(avatarUrl);
|
||||||
|
userDO.setUpdateTime(LocalDateTime.now());
|
||||||
|
return userMapper.updateById(userDO) > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
# 数据库连接编码配置
|
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/yumi_nail?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
|
||||||
|
|
||||||
# 日志编码配置
|
|
||||||
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
|
|
||||||
# 服务器编码配置
|
|
||||||
server.servlet.encoding.charset=UTF-8
|
|
||||||
server.servlet.encoding.force=true
|
|
||||||
server.servlet.encoding.enabled=true
|
|
||||||
|
|
||||||
# MyBatis编码配置
|
|
||||||
mybatis.configuration.map-underscore-to-camel-case=true
|
|
||||||
|
|
||||||
# 时区配置
|
|
||||||
spring.jackson.time-zone=Asia/Shanghai
|
|
||||||
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
|
|
||||||
server.timezone=Asia/Shanghai
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://localhost:3306/yumi_nail?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||||
|
jackson:
|
||||||
|
time-zone: Asia/Shanghai
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
|
||||||
|
logging:
|
||||||
|
pattern:
|
||||||
|
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
|
||||||
|
|
||||||
|
server:
|
||||||
|
servlet:
|
||||||
|
encoding:
|
||||||
|
charset: UTF-8
|
||||||
|
force: true
|
||||||
|
enabled: true
|
||||||
|
timezone: Asia/Shanghai
|
||||||
|
|
||||||
|
mybatis:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
|||||||
Reference in New Issue
Block a user