|
20 | 20 | import com.tinyengine.it.common.exception.ServiceException; |
21 | 21 | import com.tinyengine.it.common.log.SystemServiceLog; |
22 | 22 | import com.tinyengine.it.common.utils.ImageThumbnailGenerator; |
23 | | -import com.tinyengine.it.common.utils.Utils; |
24 | 23 | import com.tinyengine.it.mapper.ResourceGroupResourceMapper; |
25 | 24 | import com.tinyengine.it.mapper.ResourceMapper; |
26 | | -import com.tinyengine.it.model.dto.ResourceRequestDto; |
27 | 25 | import com.tinyengine.it.model.entity.Resource; |
28 | 26 | import com.tinyengine.it.model.entity.ResourceGroupResource; |
29 | 27 | import com.tinyengine.it.service.material.ResourceService; |
30 | 28 | import org.apache.commons.lang3.StringUtils; |
31 | 29 | import org.springframework.beans.factory.annotation.Autowired; |
32 | 30 | import org.springframework.stereotype.Service; |
33 | 31 |
|
| 32 | +import java.net.URLEncoder; |
| 33 | +import java.nio.charset.StandardCharsets; |
| 34 | +import java.time.Instant; |
34 | 35 | import java.util.ArrayList; |
35 | 36 | import java.util.List; |
36 | 37 |
|
@@ -82,18 +83,18 @@ public Result<Resource> queryResourceById(Integer id) { |
82 | 83 | } |
83 | 84 |
|
84 | 85 | /** |
85 | | - * 根据data查询表t_resource信息 |
| 86 | + * 根据name查询表t_resource信息 |
86 | 87 | * |
87 | | - * @param data the data |
| 88 | + * @param name the name |
88 | 89 | * @return the resource |
89 | 90 | */ |
90 | 91 | @Override |
91 | | - @SystemServiceLog(description = "根据data查询表t_resource信息") |
92 | | - public Resource queryResourceByData(ResourceRequestDto data) { |
| 92 | + @SystemServiceLog(description = "根据name查询表t_resource信息") |
| 93 | + public Resource queryResourceByName(String name) { |
93 | 94 |
|
94 | 95 | QueryWrapper<Resource> queryWrapper = new QueryWrapper<>(); |
95 | | - queryWrapper.eq("name", data.getName()); |
96 | | - queryWrapper.eq("category", data.getCategory()); |
| 96 | + queryWrapper.eq("name", name); |
| 97 | + queryWrapper.eq("app_id", loginUserContext.getAppId()); |
97 | 98 |
|
98 | 99 | return this.baseMapper.selectOne(queryWrapper); |
99 | 100 | } |
@@ -172,26 +173,18 @@ public Resource createResource(Resource resource) throws Exception { |
172 | 173 | */ |
173 | 174 | @Override |
174 | 175 | @SystemServiceLog(description = "图片上传") |
175 | | - public Resource resourceUpload(Resource resource) throws Exception { |
176 | | - ResourceRequestDto resourceParam = new ResourceRequestDto(); |
177 | | - resourceParam.setName(resource.getName()); |
178 | | - resourceParam.setCategory(resource.getCategory()); |
179 | | - resourceParam.setResource(true); |
180 | | - |
181 | | - String encodedResourceParam = Utils.encodeObjectToBase64(resourceParam); |
182 | | - |
183 | | - ResourceRequestDto thumbnailParam = new ResourceRequestDto(); |
184 | | - thumbnailParam.setName(resource.getName()); |
185 | | - thumbnailParam.setCategory(resource.getCategory()); |
186 | | - thumbnailParam.setResource(false); |
187 | | - String encodedThumbnailParam = Utils.encodeObjectToBase64(thumbnailParam); |
188 | | - |
| 176 | + public Resource resourceUpload(Resource resource) { |
| 177 | + String imageName = Instant.now().toEpochMilli()+resource.getName(); |
| 178 | + resource.setName(imageName); |
189 | 179 | String resourceData = resource.getResourceData(); |
190 | 180 | String tinyEngineUrl = System.getenv("TINY_ENGINE_URL"); |
191 | 181 |
|
192 | 182 | if (!StringUtils.isEmpty(resourceData)) { |
193 | | - resource.setResourceUrl(String.format("%s?data=%s", tinyEngineUrl, encodedResourceParam)); |
194 | | - resource.setThumbnailUrl(String.format("%s?data=%s", tinyEngineUrl, encodedThumbnailParam)); |
| 183 | + String encodedName = URLEncoder.encode(imageName, StandardCharsets.UTF_8); |
| 184 | + String resourceUrl = tinyEngineUrl + "?name=" + encodedName + "&isResource=" + true; |
| 185 | + String thumbnailUrl = tinyEngineUrl + "?name=" + encodedName + "&isResource=" + false; |
| 186 | + resource.setResourceUrl(resourceUrl); |
| 187 | + resource.setThumbnailUrl(thumbnailUrl); |
195 | 188 | resource.setThumbnailData(ImageThumbnailGenerator.createThumbnail(resource.getResourceData(), 200, 200)); |
196 | 189 | } |
197 | 190 | QueryWrapper<Resource> queryWrapper = new QueryWrapper<>(); |
|
0 commit comments