| | |
| | | @PostMapping("save") |
| | | @ApiOperation("保存") |
| | | @LogOperation("保存") |
| | | public Result save(@RequestBody MultipartFile file, Long id, Integer isDefault, |
| | | String name, String contentType, Integer productType, String remark) { |
| | | SysPictureBase sysPictureBase; |
| | | SysPictureBase pictureBase = sysPictureBaseService.getDefaultImg(productType); |
| | | if (id != 0) { |
| | | sysPictureBase = sysPictureBaseService.get(id); |
| | | sysPictureBase.setIsDefault(isDefault); |
| | | sysPictureBase.setName(name); |
| | | sysPictureBase.setContentType(contentType); |
| | | sysPictureBase.setProductType(productType); |
| | | sysPictureBase.setRemark(remark); |
| | | public Result save(@RequestBody SysPictureBase sysPictureBase) { |
| | | if (sysPictureBase.getId() != null) { |
| | | sysPictureBaseService.update(sysPictureBase); |
| | | } else { |
| | | sysPictureBase = new SysPictureBase(); |
| | | sysPictureBase.setIsDefault(isDefault); |
| | | sysPictureBase.setName(name); |
| | | sysPictureBase.setContentType(contentType); |
| | | sysPictureBase.setProductType(productType); |
| | | sysPictureBase.setRemark(remark); |
| | | sysPictureBaseService.insert(sysPictureBase); |
| | | } |
| | | if (sysPictureBase.getIsDefault()==1){ |
| | | if (pictureBase.getId()==null){ |
| | | sysPictureBaseService.updateByDefault(sysPictureBase.getId(),sysPictureBase.getProductType()); |
| | | sysPictureBaseService.updateProdeuctImg(sysPictureBase.getId(),sysPictureBase.getProductType(),null); |
| | | }else{ |
| | | if (!sysPictureBase.getId().equals(pictureBase.getId())){ |
| | | sysPictureBaseService.updateByDefault(sysPictureBase.getId(),sysPictureBase.getProductType()); |
| | | sysPictureBaseService.updateProdeuctImg(sysPictureBase.getId(),sysPictureBase.getProductType(),pictureBase.getId()); |
| | | } |
| | | } |
| | | } |
| | | if (file != null) { |
| | | BufferedImage bufferedImage = null; |
| | | try { |
| | | String fileName = file.getOriginalFilename(); |
| | | String[] arr = fileName.split("\\."); |
| | | String suffixName = arr[arr.length - 1].toLowerCase(); |
| | | |
| | | bufferedImage = ImageIO.read(file.getInputStream()); |
| | | // 宽度 |
| | | int width = bufferedImage.getWidth(); |
| | | sysPictureBase.setWidth(width); |
| | | // 高度 |
| | | int height = bufferedImage.getHeight(); |
| | | sysPictureBase.setHeight(height); |
| | | sysPictureBaseService.update(sysPictureBase); |
| | | String tempUploadDir = localPath + "/product_img/"; |
| | | File dir = new File(tempUploadDir); |
| | | if (!dir.exists()) { |
| | | dir.mkdirs(); |
| | | } |
| | | ImageIO.write(bufferedImage, suffixName, new File(tempUploadDir + sysPictureBase.getId().toString())); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | if (sysPictureBase.getIsDefault() == 1 && sysPictureBase.getProductType()!=20) { |
| | | sysPictureBaseService.updateByDefault(sysPictureBase.getId(), sysPictureBase.getProductType()); |
| | | sysPictureBaseService.updateProdeuctImg(sysPictureBase.getId(), sysPictureBase.getProductType(), null); |
| | | } |
| | | return Result.ok(); |
| | | } |
| | |
| | | //关流 |
| | | outputStream.close(); |
| | | in.close(); |
| | | } catch (IOException e) { |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping("/getSvgImage") |
| | | public void getSvgImage(HttpServletResponse response, Long id) { |
| | | sysPictureBaseService.getSvgImage(response,id); |
| | | } |
| | | |
| | | @GetMapping("/getDefaultImg") |
| | |
| | | SysPictureBase data = sysPictureBaseService.getDefaultImg(productType); |
| | | return Result.ok(data); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | @ApiOperation("删除") |
| | | @LogOperation("删除") |