From 90400afc2e72950229506fa76d474c25b6c8eed3 Mon Sep 17 00:00:00 2001 From: gaoaoy <1042166043@qq.com> Date: 星期三, 06 三月 2024 15:45:13 +0800 Subject: [PATCH] 6 设备工具明细 图片上传 --- cnas-server/src/main/java/com/yuanchu/mom/mapper/DeviceMapper.java | 1 cnas-server/src/main/java/com/yuanchu/mom/service/impl/DeviceServiceImpl.java | 4 +- cnas-server/src/main/resources/mapper/DeviceMapper.xml | 9 ++-- cnas-server/src/main/java/com/yuanchu/mom/controller/DeviceController.java | 50 ++++++++++++------------ cnas-server/src/main/java/com/yuanchu/mom/service/DeviceService.java | 3 + cnas-server/src/main/java/com/yuanchu/mom/pojo/Device.java | 4 +- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/cnas-server/src/main/java/com/yuanchu/mom/controller/DeviceController.java b/cnas-server/src/main/java/com/yuanchu/mom/controller/DeviceController.java index c5f3e08..4536e8b 100644 --- a/cnas-server/src/main/java/com/yuanchu/mom/controller/DeviceController.java +++ b/cnas-server/src/main/java/com/yuanchu/mom/controller/DeviceController.java @@ -14,9 +14,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletRequest; import java.io.File; -import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -28,6 +26,7 @@ @RestController @RequestMapping("/deviceScope") public class DeviceController { + private DeviceService deviceService; @@ -80,31 +79,32 @@ //鍥剧墖涓婁紶 @ApiOperation(value = "鍥剧墖涓婁紶") - @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) - public Result uploadFile(MultipartFile file, HttpServletRequest request) throws IOException { - //鑾峰彇鏂囦欢鍚嶇О - HashMap<String, String> list = new HashMap<>(); + @PostMapping("/uploadFile") + public Result uploadFile(MultipartFile file) { + + System.out.println(file.getOriginalFilename()); + String urlString = null; + String pathName = null; String filename = file.getOriginalFilename(); - String s = filename.substring(filename.lastIndexOf("."), filename.length()); - - System.out.println(filename); - //鑾峰彇鐪熷疄璺緞 - String realPath = request.getServletContext().getRealPath("/Users/gaoaoy/webapp/images"); - //鍒涘缓鏂囦欢 - File file1 = new File(realPath); - if (!file1.exists()) { - file1.mkdirs(); + try { + String path = "/Users/gaoaoy/webapp/images"; + File realpath = new File(path); + if (!realpath.exists()) { + realpath.mkdirs(); + } + pathName = UUID.randomUUID() + "_" + file.getOriginalFilename(); + urlString = realpath + "/" + pathName; + file.transferTo(new File(urlString)); + System.out.println(pathName); + HashMap<String, String> map = new HashMap<>(); + map.put("name", filename); + map.put("url", pathName); + return Result.success(map); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("鍥剧墖涓婁紶閿欒"); + return null; } - file.transferTo(new File(file1 + "/" + filename)); - String ss= filename; - UUID uuid = UUID.randomUUID(); - ss = uuid.toString() + s; - String ful = "/Users/gaoaoy/webapp/images" + ss; - System.out.println(file1); - - list.put("url", ful); - list.put("name", filename); - return Result.success(list); } @ApiOperation(value = "鑾峰彇璁惧璐熻矗浜�") diff --git a/cnas-server/src/main/java/com/yuanchu/mom/mapper/DeviceMapper.java b/cnas-server/src/main/java/com/yuanchu/mom/mapper/DeviceMapper.java index be52c4b..26d3add 100644 --- a/cnas-server/src/main/java/com/yuanchu/mom/mapper/DeviceMapper.java +++ b/cnas-server/src/main/java/com/yuanchu/mom/mapper/DeviceMapper.java @@ -22,6 +22,7 @@ List<Device> authorizedPerson(); + //鏌ヨ List<Device> search(@Param(value = "status") Integer status, @Param(value = "deviceName") String deviceName, @Param(value = "specificationModel") String specificationModel, @Param(value = "largeCategory") String largeCategory); diff --git a/cnas-server/src/main/java/com/yuanchu/mom/pojo/Device.java b/cnas-server/src/main/java/com/yuanchu/mom/pojo/Device.java index d0c6c01..317afd5 100644 --- a/cnas-server/src/main/java/com/yuanchu/mom/pojo/Device.java +++ b/cnas-server/src/main/java/com/yuanchu/mom/pojo/Device.java @@ -138,11 +138,11 @@ @ValueTableShow(28) @ApiModelProperty(value = "鍥剧墖涓婁紶") - private Integer imageUpload; + private String imageUpload; @ValueTableShow(29) @ApiModelProperty(value = "鍥剧墖澶囨敞") - private Integer imageName; + private String imageName; @ApiModelProperty(value = "鍒涘缓浜篿d") @TableField(fill = FieldFill.INSERT) diff --git a/cnas-server/src/main/java/com/yuanchu/mom/service/DeviceService.java b/cnas-server/src/main/java/com/yuanchu/mom/service/DeviceService.java index d62ed5f..0da1d90 100644 --- a/cnas-server/src/main/java/com/yuanchu/mom/service/DeviceService.java +++ b/cnas-server/src/main/java/com/yuanchu/mom/service/DeviceService.java @@ -1,5 +1,6 @@ package com.yuanchu.mom.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.yuanchu.mom.pojo.Device; @@ -11,7 +12,7 @@ */ public interface DeviceService extends IService<Device> { - Map<String, Object> selectDeviceParameter(com.baomidou.mybatisplus.extension.plugins.pagination.Page page, Device itemParameter); + Map<String, Object> selectDeviceParameter(Page page, Device itemParameter); int addDeviceParameter(Device itemParameter); diff --git a/cnas-server/src/main/java/com/yuanchu/mom/service/impl/DeviceServiceImpl.java b/cnas-server/src/main/java/com/yuanchu/mom/service/impl/DeviceServiceImpl.java index 1ed9636..17d7753 100644 --- a/cnas-server/src/main/java/com/yuanchu/mom/service/impl/DeviceServiceImpl.java +++ b/cnas-server/src/main/java/com/yuanchu/mom/service/impl/DeviceServiceImpl.java @@ -1,5 +1,6 @@ package com.yuanchu.mom.service.impl; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.yuanchu.mom.common.GetLook; import com.yuanchu.mom.common.PrintChina; @@ -31,7 +32,6 @@ map.put("head", PrintChina.printChina(Device.class)); Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDeviceParameter"); if (map1.get("look") == 1) itemParameter.setCreateUser(map1.get("userId")); -// deviceMapper.selectPage(page, QueryWrappers.queryWrappers(itemParameter)); map.put("body", deviceMapper.selectPage(page, QueryWrappers.queryWrappers(itemParameter))); return map; } @@ -53,7 +53,7 @@ @Override public List<Device> selectEquipmentOverview() { - return deviceMapper.selectEquipmentOverview(new com.baomidou.mybatisplus.extension.plugins.pagination.Page(1, 10), QueryWrappers.queryWrappers(new Device())); + return deviceMapper.selectEquipmentOverview(new Page(1, 10), QueryWrappers.queryWrappers(new Device())); } @Override diff --git a/cnas-server/src/main/resources/mapper/DeviceMapper.xml b/cnas-server/src/main/resources/mapper/DeviceMapper.xml index 7ef524b..ac14df2 100644 --- a/cnas-server/src/main/resources/mapper/DeviceMapper.xml +++ b/cnas-server/src/main/resources/mapper/DeviceMapper.xml @@ -59,11 +59,10 @@ </if> </select> <select id="authorizedPerson" resultType="com.yuanchu.mom.pojo.Device"> - select * - from (select id, - authorized_person, - status - from device) a + select id, + authorized_person, + status + from device </select> <select id="search" resultType="com.yuanchu.mom.pojo.Device"> select * -- Gitblit v1.9.3