Browse Source

修改上传照片的功能

konghl 4 years ago
parent
commit
827c01beb3

+ 25 - 5
security-protection-service/src/main/java/com/ai/bss/security/protection/controller/ResourceToolManageController.java

@ -9,6 +9,7 @@ import org.apache.commons.lang.StringUtils;
9 9
import org.springframework.beans.factory.annotation.Autowired;
10 10
import org.springframework.stereotype.Controller;
11 11
import org.springframework.web.bind.annotation.ModelAttribute;
12
import org.springframework.web.bind.annotation.RequestBody;
12 13
import org.springframework.web.bind.annotation.RequestMapping;
13 14
import org.springframework.web.bind.annotation.RequestParam;
14 15
import org.springframework.web.bind.annotation.ResponseBody;
@ -82,7 +83,6 @@ public class ResourceToolManageController {
82 83
		}
83 84
84 85
		return ResourceToolManageService.queryOneResourceTool(resourceToolId);
85
86 86
	}
87 87
88 88
	/**
@ -93,13 +93,13 @@ public class ResourceToolManageController {
93 93
	 */
94 94
	@ResponseBody
95 95
	@RequestMapping("/createResourceTool")
96
	public CommonResponse<ResourceTool> createResourceTool(@RequestParam(value="file",required=false) MultipartFile meFile, ResourceTool resourceTool) throws Exception {
96
	public CommonResponse<ResourceTool> createResourceTool(@RequestBody ResourceTool resourceTool) throws Exception {
97 97
		if (resourceTool == null || StringUtils.isEmpty(resourceTool.getResourceToolCode())
98 98
				|| StringUtils.isEmpty(resourceTool.getResourceToolName())) {
99 99
			return CommonResponse.fail("500", "新增失败");
100 100
		}
101 101
102
		return ResourceToolManageService.createResourceTool(meFile,resourceTool);
102
		return ResourceToolManageService.createResourceTool(resourceTool);
103 103
	}
104 104
105 105
	/**
@ -110,14 +110,14 @@ public class ResourceToolManageController {
110 110
	 */
111 111
	@ResponseBody
112 112
	@RequestMapping("/modifyResourceTool")
113
	public CommonResponse<ResourceTool> modifyResourceTool(@RequestParam(value="file",required=false) MultipartFile meFile, ResourceTool resourceTool) throws Exception {
113
	public CommonResponse<ResourceTool> modifyResourceTool(@RequestBody ResourceTool resourceTool) throws Exception {
114 114
		if (resourceTool == null || resourceTool.getResourceToolId() == null
115 115
				|| StringUtils.isEmpty(resourceTool.getResourceToolCode())
116 116
				|| StringUtils.isEmpty(resourceTool.getResourceToolName())) {
117 117
			return CommonResponse.fail("500", "修改失败");
118 118
		}
119 119
120
		return ResourceToolManageService.modifyResourceTool(meFile,resourceTool);
120
		return ResourceToolManageService.modifyResourceTool(resourceTool);
121 121
	}
122 122
123 123
	/**
@ -139,4 +139,24 @@ public class ResourceToolManageController {
139 139
		return ResourceToolManageService.deleteResourceTool(resourceToolIds);
140 140
	}
141 141
142
	/**
143
	 * 上传设备照片
144
	 * @param meFile
145
	 * @return
146
	 * @throws Exception
147
	 */
148
	@ResponseBody
149
	@RequestMapping("/uploadResourceToolPicture")
150
	public CommonResponse<Map<String, String>> uploadResourceToolPicture(
151
			@RequestParam(value = "picture") MultipartFile meFile, @RequestParam(required = false) String pictureUrl)
152
			throws Exception {
153
		if (meFile == null || StringUtils.isEmpty(meFile.getOriginalFilename())) {
154
			return CommonResponse.fail("500", "上传失败");
155
		}
156
157
		Map<String, String> resultMap = ResourceToolManageService.uploadResourceToolPicture(meFile, pictureUrl);
158
159
		return CommonResponse.ok(resultMap);
160
	}
161
142 162
}

+ 28 - 25
security-protection-service/src/main/java/com/ai/bss/security/protection/service/impl/ResourceToolManageServiceImpl.java

@ -102,7 +102,7 @@ public class ResourceToolManageServiceImpl implements ResourceToolManageService
102 102
103 103
		if (CollectionUtils.isEmpty(response.getData().getData())
104 104
				|| CollectionUtils.isEmpty(response.getData().getData().get(0))) {
105
			return response.fail("504", "获取设备信息失败");
105
			return CommonResponse.fail("504", "获取设备信息失败");
106 106
		}
107 107
		Map<String, Object> resultMap = response.getData().getData().get(0);
108 108
@ -116,47 +116,31 @@ public class ResourceToolManageServiceImpl implements ResourceToolManageService
116 116
117 117
		if (resultMap.get("pictureUrl") == null || "#".equals(resultMap.get("pictureUrl").toString())) {
118 118
			resultMap.put("toolPictureUrl", "");
119
			resultMap.put("isExistPicture", "0");
119 120
		} else {
120 121
			String pictureUrl = minioService.getObjectUrl(minioConfig.getBucketWorkToolImage(),
121 122
					resultMap.get("pictureUrl").toString());
122 123
			resultMap.put("toolPictureUrl", pictureUrl);
124
			resultMap.put("isExistPicture", "1");
123 125
		}
124 126
125 127
		return CommonResponse.ok(resultMap);
126 128
	}
127 129
128 130
	@Override
129
	public CommonResponse<ResourceTool> createResourceTool(MultipartFile meFile, ResourceTool resourceTool) {
130
		if (meFile != null) {
131
			String fileName = meFile.getOriginalFilename();
132
			String fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length());
133
			String minioFileName = UUID.fastUUID().toString() + fileType;
134
			minioService.putObject(minioConfig.getBucketWorkToolImage(), meFile, minioFileName);
135
			resourceTool.setPictureUrl(minioFileName);
136
		} else {
131
	public CommonResponse<ResourceTool> createResourceTool(ResourceTool resourceTool) {
132
		if (StringUtils.isEmpty(resourceTool.getPictureUrl())) {
137 133
			resourceTool.setPictureUrl("#");
138 134
		}
139
140
		resourceTool.setVideoUrl("#");
135
		if (StringUtils.isEmpty(resourceTool.getVideoUrl())) {
136
			resourceTool.setVideoUrl("#");
137
		}
141 138
		CommonRequest<ResourceTool> request = new CommonRequest<ResourceTool>(resourceTool);
142 139
		return resourceToolCommand.saveWorkToolWithNoMapArea(request);
143 140
	}
144 141
145 142
	@Override
146
	public CommonResponse<ResourceTool> modifyResourceTool(MultipartFile meFile, ResourceTool resourceTool) {
147
		if (meFile != null) {
148
			String fileName = meFile.getOriginalFilename();
149
			String fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length());
150
			String minioFileName = UUID.fastUUID().toString() + fileType;
151
			minioService.putObject(minioConfig.getBucketWorkToolImage(), meFile, minioFileName);
152
153
			/*if (StringUtils.isNotBlank(resourceTool.getPictureUrl()) && !"#".equals(resourceTool.getPictureUrl())) {
154
				minioService.removeObject(minioConfig.getBucketWorkToolImage(), resourceTool.getPictureUrl());
155
			}*/
156
157
			resourceTool.setPictureUrl(minioFileName);
158
		}
159
143
	public CommonResponse<ResourceTool> modifyResourceTool(ResourceTool resourceTool) {
160 144
		CommonRequest<ResourceTool> request = new CommonRequest<ResourceTool>(resourceTool);
161 145
		return resourceToolCommand.saveWorkToolWithNoMapArea(request);
162 146
	}
@ -173,4 +157,23 @@ public class ResourceToolManageServiceImpl implements ResourceToolManageService
173 157
		}
174 158
	}
175 159
160
	@Override
161
	public Map<String, String> uploadResourceToolPicture(MultipartFile meFile, String pictureUrl) throws Exception {
162
		if (StringUtils.isNotBlank(pictureUrl) && !"#".equals(pictureUrl)) {
163
			minioService.removeObject(minioConfig.getBucketWorkToolImage(), pictureUrl);
164
		}
165
166
		String fileName = meFile.getOriginalFilename();
167
		String fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length());
168
		String minioFileName = UUID.fastUUID().toString() + fileType;
169
		minioService.putObject(minioConfig.getBucketWorkToolImage(), meFile, minioFileName);
170
171
		String toolPictureUrl = minioService.getObjectUrl(minioConfig.getBucketWorkToolImage(), minioFileName);
172
173
		Map<String, String> resultMap = new HashMap<String, String>();
174
		resultMap.put("pictureUrl", minioFileName);
175
		resultMap.put("toolPictureUrl", toolPictureUrl);
176
		return resultMap;
177
	}
178
176 179
}

+ 10 - 2
security-protection-service/src/main/java/com/ai/bss/security/protection/service/interfaces/ResourceToolManageService.java

@ -47,14 +47,14 @@ public interface ResourceToolManageService {
47 47
	 * @param resourceTool
48 48
	 * @return
49 49
	 */
50
	CommonResponse<ResourceTool> createResourceTool(MultipartFile meFile,ResourceTool resourceTool);
50
	CommonResponse<ResourceTool> createResourceTool(ResourceTool resourceTool);
51 51
52 52
	/**
53 53
	 * 修改设备信息
54 54
	 * @param resourceTool
55 55
	 * @return
56 56
	 */
57
	CommonResponse<ResourceTool> modifyResourceTool(MultipartFile meFile,ResourceTool resourceTool);
57
	CommonResponse<ResourceTool> modifyResourceTool(ResourceTool resourceTool);
58 58
59 59
	/**
60 60
	 * 删除设备信息
@ -63,4 +63,12 @@ public interface ResourceToolManageService {
63 63
	 */
64 64
	CommonResponse<Void> deleteResourceTool(List<String> resourceToolIds);
65 65
66
	/**
67
	 * 上传设备照片
68
	 * @param meFile
69
	 * @param pictureUrl
70
	 * @return
71
	 * @throws Exception
72
	 */
73
	Map<String, String> uploadResourceToolPicture(MultipartFile meFile, String pictureUrl) throws Exception;
66 74
}