| | |
| | | package com.zy.sc.common.web; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.sc.common.service.OssService; |
| | | import com.zy.sc.manager.entity.Issue; |
| | | import com.zy.sc.manager.service.IssueService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/10/7 |
| | |
| | | |
| | | @Autowired |
| | | private OssService ossService; |
| | | @Autowired |
| | | private IssueService issueService; |
| | | |
| | | @PostMapping("/upload.action") |
| | | public R upload(MultipartFile file) { |
| | |
| | | return R.ok(Cools.add("url", upload)); |
| | | } |
| | | |
| | | @PostMapping("/sensor/upload.action") |
| | | @PostMapping("/issue/upload.action") |
| | | @ManagerAuth(memo = "图片上传") |
| | | public R sensorUpload(MultipartFile file, @RequestParam("sensorId") Long sensorId) { |
| | | public R sensorUpload(MultipartFile file, @RequestParam("issueId") Long issueId) { |
| | | Issue issue = issueService.selectById(issueId); |
| | | if (null == issue) { |
| | | return R.error("设备不存在"); |
| | | } |
| | | String img = issue.getImg(); |
| | | JSONArray jsonArray = JSON.parseArray(img); |
| | | if (jsonArray == null) { |
| | | jsonArray = new JSONArray(); |
| | | } |
| | | if (jsonArray.size() >= 5) { |
| | | return R.error("图片上传数量已到上限"); |
| | | } |
| | | // oss |
| | | String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1); |
| | | InputStream inputStream = null; |
| | |
| | | return R.ok(Cools.add("src", upload)); |
| | | } |
| | | |
| | | @PostMapping("/issue/remove.action") |
| | | @ManagerAuth(memo = "图片移除") |
| | | public R sensorRemove(@RequestParam("issueId") Long issueId, @RequestParam("src") String src) { |
| | | Issue issue = issueService.selectById(issueId); |
| | | if (null == issue) { |
| | | return R.error("设备不存在"); |
| | | } |
| | | String img = issue.getImg(); |
| | | JSONArray jsonArray = JSON.parseArray(img); |
| | | if (jsonArray == null) { |
| | | jsonArray = new JSONArray(); |
| | | } |
| | | if (jsonArray.size() < 1) { |
| | | return R.error("没有可删除的图片"); |
| | | } |
| | | jsonArray.remove(src); |
| | | // 持久化 |
| | | issue.setImg(jsonArray.toJSONString()); |
| | | issue.setUpdateBy(getUserId()); |
| | | issue.setUpdateTime(new Date()); |
| | | if (!issueService.updateById(issue)) { |
| | | return R.error("保持数据库失败"); |
| | | } |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | } |