|
@@ -0,0 +1,84 @@
|
|
|
|
+package com.huimv.farm.musk.controller;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.huimv.farm.musk.common.utils.Result;
|
|
|
|
+import com.huimv.farm.musk.common.utils.ResultCode;
|
|
|
|
+import com.huimv.farm.musk.common.utils.UploadImage;
|
|
|
|
+import com.huimv.farm.musk.entity.BaseBuilding;
|
|
|
|
+import com.huimv.farm.musk.entity.BaseImg;
|
|
|
|
+import com.huimv.farm.musk.entity.Farm;
|
|
|
|
+import com.huimv.farm.musk.service.IBaseImgService;
|
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 前端控制器
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author author
|
|
|
|
+ * @since 2024-09-09
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/base-img")
|
|
|
|
+@CrossOrigin
|
|
|
|
+public class BaseImgController {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBaseImgService baseImgService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UploadImage uploadImage;
|
|
|
|
+
|
|
|
|
+ @PostMapping("/addImg")
|
|
|
|
+ public Result addImg(@RequestParam(value = "imgUrl") MultipartFile imgUrl,
|
|
|
|
+ @RequestParam(value = "farmId") Integer farmId) throws IOException {
|
|
|
|
+ BaseImg baseImg = new BaseImg();
|
|
|
|
+ baseImg.setFarmId(farmId);
|
|
|
|
+ String imageCom = uploadImage.uploadImg(imgUrl);
|
|
|
|
+ if ("上传失败".equals(imageCom)){
|
|
|
|
+ return new Result(ResultCode.FAIL,"图片上传失败");
|
|
|
|
+ }
|
|
|
|
+ baseImg.setImgUrl(imageCom);
|
|
|
|
+ baseImgService.save(baseImg);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,"添加成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/deleteImg")
|
|
|
|
+ public Result deleteImg( @RequestBody Map<String, Integer> map) {
|
|
|
|
+ try {
|
|
|
|
+ Integer id = map.get("id");
|
|
|
|
+ baseImgService.removeById(id);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ return new Result(ResultCode.FAIL,"删除失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new Result(ResultCode.SUCCESS,"删除成功");
|
|
|
|
+ }
|
|
|
|
+ @PostMapping("/updateImg")
|
|
|
|
+ public Result updateImg( @RequestParam(value = "imgUrl") MultipartFile imgUrl,
|
|
|
|
+ @RequestParam(value = "id") Integer id) throws IOException {
|
|
|
|
+
|
|
|
|
+ BaseImg baseImg = baseImgService.getById(id);
|
|
|
|
+ String imageCom = uploadImage.uploadImg(imgUrl);
|
|
|
|
+ if ("上传失败".equals(imageCom)){
|
|
|
|
+ return new Result(ResultCode.FAIL,"图片上传失败");
|
|
|
|
+ }
|
|
|
|
+ baseImg.setImgUrl(imageCom);
|
|
|
|
+ baseImgService.removeById(id);
|
|
|
|
+
|
|
|
|
+ return new Result(ResultCode.SUCCESS,"修改成功");
|
|
|
|
+ }
|
|
|
|
+ @PostMapping("/listImg")
|
|
|
|
+ public Result listImg( @RequestBody Map<String, Integer> map) {
|
|
|
|
+ Integer id = map.get("farmId");
|
|
|
|
+ return new Result(ResultCode.SUCCESS, baseImgService.list(new QueryWrapper<BaseImg>().eq("farm_id", id)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|