| | |
| | | import com.zy.sc.common.service.OssService; |
| | | import com.zy.sc.manager.entity.Issue; |
| | | import com.zy.sc.manager.service.IssueService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | |
| | | /** |
| | | * Created by vincent on 2020/10/7 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | public class UploadController extends BaseController { |
| | | |
| | |
| | | |
| | | @PostMapping("/upload.action") |
| | | public R upload(MultipartFile file) { |
| | | String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1); |
| | | log.info("开始上传文件:{};文件大小:{}", file.getOriginalFilename(), file.getSize()); |
| | | InputStream inputStream = null; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String upload=ossService.upload(inputStream,suffix); |
| | | String upload = ossService.upload(inputStream,file.getOriginalFilename()); |
| | | return R.ok(Cools.add("url", upload)); |
| | | } |
| | | |
| | |
| | | public R sensorUpload(MultipartFile file, @RequestParam("issueId") Long issueId) { |
| | | Issue issue = issueService.selectById(issueId); |
| | | if (null == issue) { |
| | | return R.error("设备不存在"); |
| | | return R.error("故障不存在"); |
| | | } |
| | | String img = issue.getImg(); |
| | | JSONArray jsonArray = JSON.parseArray(img); |
| | |
| | | return R.error("图片上传数量已到上限"); |
| | | } |
| | | // oss |
| | | String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1); |
| | | InputStream inputStream = null; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String upload = ossService.upload(inputStream,suffix); |
| | | String upload = ossService.upload(inputStream,file.getOriginalFilename()); |
| | | if (Cools.isEmpty(upload)) { |
| | | return R.error("上传OSS服务失败"); |
| | | } |
| | | jsonArray.add(upload); |
| | | // 持久化 |
| | | issue.setImg(jsonArray.toJSONString()); |
| | | issue.setUpdateBy(getUserId()); |
| | | issue.setUpdateTime(new Date()); |
| | | if (!issueService.updateById(issue)) { |
| | | return R.error("上传图片失败"); |
| | | } |
| | | return R.ok(Cools.add("src", upload)); |
| | | } |
| | |
| | | issue.setUpdateBy(getUserId()); |
| | | issue.setUpdateTime(new Date()); |
| | | if (!issueService.updateById(issue)) { |
| | | return R.error("保持数据库失败"); |
| | | return R.error("删除图片失败"); |
| | | } |
| | | return R.ok("删除成功"); |
| | | } |