| | |
| | | package com.ruoyi.sy.service.impl; |
| | | |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | import java.util.function.Predicate; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.device.hiksdk.config.MinioClientSingleton; |
| | | import com.ruoyi.device.hiksdk.util.minio.MinioUtils; |
| | | import com.ruoyi.sy.domain.ArdSyUser; |
| | | import com.ruoyi.sy.mapper.ArdSyUserMapper; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.utils.httpclient.SYCarClient; |
| | | import io.minio.GetPresignedObjectUrlArgs; |
| | | import io.minio.ListObjectsArgs; |
| | | import io.minio.PutObjectArgs; |
| | | import io.minio.Result; |
| | | import io.minio.http.Method; |
| | | import io.minio.messages.Item; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.sy.mapper.ArdSyCarMapper; |
| | | import com.ruoyi.sy.domain.ArdSyCar; |
| | | import com.ruoyi.sy.service.IArdSyCarService; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public int deleteArdSyCarByIds(String[] ids) { |
| | | List<ArdSyCar> result = ardSyCarMapper.selectArdSyCarByIds(ids); |
| | | List<String> objectNames = new ArrayList(); |
| | | for(ArdSyCar ardSyCar : result){ |
| | | if(ardSyCar.getCarPicture() != null && !ardSyCar.getCarPicture().equals("")){ |
| | | objectNames.add(ardSyCar.getCarPicture().split("/sycar/")[1]); |
| | | } |
| | | } |
| | | MinioUtils.removeObjects("sycar", objectNames); |
| | | return ardSyCarMapper.deleteArdSyCarByIds(ids); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String,String>> getAllCarModel() { |
| | | boolean exsit = MinioUtils.exitsBucket("sycar"); |
| | | if (exsit) { |
| | | List<Map<String,String>> listObjetcName = new ArrayList<>(); |
| | | try { |
| | | ListObjectsArgs listObjectsArgs = ListObjectsArgs.builder().prefix("carmodel/").bucket("sycar").build(); |
| | | Iterable<Result<Item>> myObjects = MinioClientSingleton.getMinioClient().listObjects(listObjectsArgs); |
| | | for (Result<Item> result : myObjects) { |
| | | Item item = result.get(); |
| | | Map<String,String> map = new HashMap(); |
| | | map.put("carModel","sycar/" + item.objectName()); |
| | | switch(item.objectName()){ |
| | | case "carmodel/aodi.glb":map.put("carType","奥迪");break; |
| | | case "carmodel/baolai.glb":map.put("carType","宝来");break; |
| | | case "carmodel/bieke.glb":map.put("carType","别克");break; |
| | | case "carmodel/bus1.glb":map.put("carType","大客车");break; |
| | | case "carmodel/car.glb":map.put("carType","小型车");break; |
| | | case "carmodel/fire(1).glb":map.put("carType","消防车");break; |
| | | case "carmodel/fute.glb":map.put("carType","福特");break; |
| | | case "carmodel/jingche_a.glb":map.put("carType","警车");break; |
| | | case "carmodel/jiuhu.glb":map.put("carType","救护车");break; |
| | | case "carmodel/oil.glb":map.put("carType","油罐车");break; |
| | | case "carmodel/truck.glb":map.put("carType","工程用车");break; |
| | | case "carmodel/van1.glb":map.put("carType","大货车");break; |
| | | default: |
| | | break; |
| | | } |
| | | listObjetcName.add(map); |
| | | } |
| | | return listObjetcName; |
| | | } catch (Exception ex) { |
| | | //log.error("minio获取桶下对象异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public String uploadCarPicture(String id, MultipartFile carPicture) { |
| | | //String url = MinioUtils.putObjectAndGetUrl("sycar",carPicture); |
| | | //判断文件是否为空 |
| | | if (null == carPicture || 0 == carPicture.getSize()) { |
| | | return ""; |
| | | } |
| | | boolean exsit = MinioUtils.exitsBucket("sycar"); |
| | | if (!exsit) { |
| | | boolean bucket = MinioUtils.createBucket("sycar"); |
| | | } |
| | | //文件名 |
| | | String originalFilename = carPicture.getOriginalFilename(); |
| | | //新的文件名 |
| | | String fileName = "carpicture/" + IdUtils.fastSimpleUUID()+"_"+ originalFilename; |
| | | try { |
| | | InputStream inputStream = carPicture.getInputStream(); |
| | | /*上传对象*/ |
| | | PutObjectArgs putObjectArgs = PutObjectArgs |
| | | .builder() |
| | | .bucket("sycar") |
| | | .object(fileName) |
| | | .stream(inputStream, carPicture.getSize(), -1) |
| | | .contentType(carPicture.getContentType()) |
| | | .build(); |
| | | MinioClientSingleton.getMinioClient().putObject(putObjectArgs); |
| | | inputStream.close(); |
| | | /*获取url*/ |
| | | GetPresignedObjectUrlArgs getPresignedObjectUrlArgs = GetPresignedObjectUrlArgs |
| | | .builder() |
| | | .bucket("sycar") |
| | | .object(fileName) |
| | | .method(Method.GET) |
| | | .build(); |
| | | String presignedObjectUrl = MinioClientSingleton.getMinioClient().getPresignedObjectUrl(getPresignedObjectUrlArgs); |
| | | String ObjectUrl = presignedObjectUrl.substring(0, presignedObjectUrl.indexOf("?")); |
| | | ArdSyCar ardSyCar = new ArdSyCar(); |
| | | ardSyCar.setId(id); |
| | | ardSyCar.setCarPicture(ObjectUrl); |
| | | ardSyCarMapper.updateArdSyCar(ardSyCar); |
| | | return ObjectUrl; |
| | | } catch (Exception ex) { |
| | | return ""; |
| | | } |
| | | } |
| | | } |