| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.Station3D; |
| | | import com.whyc.service.Station3DService; |
| | | import com.whyc.util.ActionUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @RequestMapping("station3D") |
| | | @Api(tags = "3D机房配置") |
| | | public class Station3DController { |
| | | public class Station3DController extends BaseController{ |
| | | |
| | | @Autowired |
| | | private Station3DService service; |
| | |
| | | return new Response().setII(1,"新增成功"); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | @PostMapping("delete") |
| | | @ApiOperation(value = "删除") |
| | | public Response delete(@RequestParam int stationId){ |
| | | service.delete(stationId); |
| | | return new Response().setII(1,"删除成功"); |
| | | } |
| | | |
| | | @PutMapping |
| | | @PostMapping("update") |
| | | @ApiOperation(value = "更新") |
| | | public Response update(@RequestBody Station3D station3D){ |
| | | service.update(station3D); |
| | | return new Response().setII(1,"更新成功"); |
| | | } |
| | | |
| | | @PostMapping("updateBatch") |
| | | @ApiOperation(value = "更新批量") |
| | | public Response updateBatch(@RequestBody List<Station3D> station3DList){ |
| | | service.updateBatch(station3DList); |
| | | return new Response().setII(1,"更新成功"); |
| | | } |
| | | |
| | |
| | | |
| | | @PostMapping("uploadPicture") |
| | | @ApiOperation(value = "上传图片") |
| | | public Response uploadPicture(@RequestBody Map<String,String> map){ |
| | | public Response uploadPicture(@RequestBody Map<String,String> map,HttpServletRequest request){ |
| | | String fileData = (String)map.get("fileData"); |
| | | String pictureName = (String)map.get("pictureName"); |
| | | String stationName = (String)map.get("stationName"); |
| | | service.uploadPicture(stationName,fileData,pictureName); |
| | | //过滤特殊字符,避免路径遍历攻击 |
| | | pictureName = ActionUtil.filterFileName(pictureName); |
| | | service.uploadPicture(stationName,fileData,pictureName,request); |
| | | return new Response().setII(1,"上传成功"); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 读取 |
| | | * @return |
| | | */ |
| | | @GetMapping("loadPicture") |
| | | @ApiOperation(value = "读取图片") |
| | | public Response pictureLoad(HttpServletRequest request){ |
| | | /*=========图片保存===========*/ |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | File jarFile = applicationHome.getDir(); |
| | | //存储3D站点图片的文件夹 |
| | | |
| | | //开发 |
| | | String fileDirName = jarFile.getParentFile().toString()+File.separator+"fg_photo_3DStation"; |
| | | //打包 |
| | | //String fileDirName = jarFile.toString()+File.separator+"fg_photo_3DStation"; |
| | | |
| | | //图片的Url |
| | | File file = new File(fileDirName); |
| | | if(file.exists()){ |
| | | File[] files = file.listFiles(); |
| | | return new Response().set(1,files); |
| | | }else{ |
| | | return new Response().set(1,new ArrayList<>()); |
| | | } |
| | | } |
| | | |
| | | } |