| package com.ruoyi.storage.minio.service.impl; | 
|   | 
| import java.io.UnsupportedEncodingException; | 
| import java.net.URLDecoder; | 
| import java.net.URLEncoder; | 
| import java.text.ParseException; | 
| import java.text.SimpleDateFormat; | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| import com.alibaba.fastjson2.JSONObject; | 
| import com.ruoyi.common.utils.DateUtils; | 
|   | 
| import com.ruoyi.common.utils.uuid.IdUtils; | 
| import com.ruoyi.storage.minio.domain.jsonbean.*; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.scheduling.annotation.Async; | 
| import org.springframework.stereotype.Service; | 
| import com.ruoyi.storage.minio.mapper.StorageMinioEventMapper; | 
| import com.ruoyi.storage.minio.domain.StorageMinioEvent; | 
| import com.ruoyi.storage.minio.service.IStorageMinioEventService; | 
|   | 
| import javax.annotation.Resource; | 
|   | 
| /** | 
|  * 存储事件Service业务层处理 | 
|  * | 
|  * @author ard | 
|  * @date 2023-08-05 | 
|  */ | 
| @Service | 
| @Slf4j(topic = "minio") | 
| public class StorageMinioEventServiceImpl implements IStorageMinioEventService { | 
|     @Resource | 
|     private StorageMinioEventMapper storageMinioEventMapper; | 
|   | 
|     /** | 
|      * 查询存储事件 | 
|      * | 
|      * @param id 存储事件主键 | 
|      * @return 存储事件 | 
|      */ | 
|     @Override | 
|     public StorageMinioEvent selectStorageMinioEventById(String id) { | 
|         return storageMinioEventMapper.selectStorageMinioEventById(id); | 
|     } | 
|   | 
|     /** | 
|      * 查询存储事件列表 | 
|      * | 
|      * @param storageMinioEvent 存储事件 | 
|      * @return 存储事件 | 
|      */ | 
|     @Override | 
|     public List<StorageMinioEvent> selectStorageMinioEventList(StorageMinioEvent storageMinioEvent) { | 
|         return storageMinioEventMapper.selectStorageMinioEventList(storageMinioEvent); | 
|     } | 
|   | 
|     /** | 
|      * 新增存储事件 | 
|      * | 
|      * @param storageMinioEvent 存储事件 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     public int insertStorageMinioEvent(StorageMinioEvent storageMinioEvent) { | 
|         storageMinioEvent.setId(IdUtils.simpleUUID()); | 
|         storageMinioEvent.setCreateTime(DateUtils.getNowDate()); | 
|         return storageMinioEventMapper.insertStorageMinioEvent(storageMinioEvent); | 
|     } | 
|   | 
|     /** | 
|      * 修改存储事件 | 
|      * | 
|      * @param storageMinioEvent 存储事件 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     public int updateStorageMinioEvent(StorageMinioEvent storageMinioEvent) { | 
|         return storageMinioEventMapper.updateStorageMinioEvent(storageMinioEvent); | 
|     } | 
|   | 
|     /** | 
|      * 批量删除存储事件 | 
|      * | 
|      * @param ids 需要删除的存储事件主键 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     public int deleteStorageMinioEventByIds(String[] ids) { | 
|         return storageMinioEventMapper.deleteStorageMinioEventByIds(ids); | 
|     } | 
|   | 
|     /** | 
|      * 删除存储事件信息 | 
|      * | 
|      * @param id 存储事件主键 | 
|      * @return 结果 | 
|      */ | 
|     @Override | 
|     public int deleteStorageMinioEventById(String id) { | 
|         return storageMinioEventMapper.deleteStorageMinioEventById(id); | 
|     } | 
|   | 
|     @Async | 
|     @Override | 
|     public void parseStorageMinioEvent(String message) { | 
|         try { | 
|             JsonsRootBean jsonsRootBean = JSONObject.parseObject(message, JsonsRootBean.class); | 
|             if (jsonsRootBean != null) { | 
|                 Records records = jsonsRootBean.getRecords().get(0); | 
|                 StorageMinioEvent storageMinioEvent = new StorageMinioEvent(); | 
|                 storageMinioEvent.setEventTime(records.getEventTime()); | 
|                 String eventType = records.getEventName().substring(0, records.getEventName().indexOf(":", records.getEventName().indexOf(":") + 1));//不包含本身位置 | 
|                 storageMinioEvent.setEventType(eventType); | 
|                 storageMinioEvent.setBucketName(records.getS3().getBucket().getName()); | 
|                 String encode = null; | 
|                 try { | 
|                     encode = URLDecoder.decode(records.getS3().getMObject().getKey(), "UTF-8"); | 
|                 } catch (UnsupportedEncodingException e) { | 
|                     e.printStackTrace(); | 
|                 } | 
|                 storageMinioEvent.setObjectName(encode); | 
|                 storageMinioEvent.setObjectSize(records.getS3().getMObject().getSize()); | 
|                 storageMinioEvent.setObjectType(records.getS3().getMObject().getContentType()); | 
|                 storageMinioEvent.setHost(records.getSource().getHost()); | 
|                 storageMinioEvent.setEndpoint(records.getResponseElements().getXMinioOriginEndpoint()); | 
|                 storageMinioEvent.setUserName(records.getRequestParameters().getPrincipalid()); | 
|   | 
|                 int i = insertStorageMinioEvent(storageMinioEvent); | 
|                 if (i > 0) { | 
|                     log.debug("minio操作日志入库成功!【" + storageMinioEvent.getEventType() + "】"); | 
|                 } | 
|             } | 
|         } | 
|         catch (Exception ex) | 
|         { | 
|             log.error("minio事件格式化异常:"+ex.getMessage()); | 
|         } | 
|     } | 
| } |