| | |
| | | |
| | | |
| | | |
| | | import java.awt.image.BufferedImage; |
| | | import java.util.List; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.domain.DocumentMaterials; |
| | | import com.ruoyi.framework.config.ServerConfig; |
| | | import com.ruoyi.service.IDocumentMaterialsService; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM; |
| | | import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE; |
| | |
| | | @RequestMapping("/system/materials") |
| | | public class DocumentMaterialsController extends BaseController |
| | | { |
| | | @Autowired |
| | | private ServerConfig serverConfig; |
| | | |
| | | @Autowired |
| | | private IDocumentMaterialsService documentMaterialsService; |
| | | |
| | |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody DocumentMaterials documentMaterials) |
| | | { |
| | | return toAjax(documentMaterialsService.insertDocumentMaterials(documentMaterials)); |
| | | int res = documentMaterialsService.insertDocumentMaterials(documentMaterials); |
| | | System.out.println(res+"][[[[[[[[[[[[[[[[[["); |
| | | return toAjax(res); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | return toAjax(documentMaterialsService.deleteDocumentMaterialsByMaterialIds(materialIds)); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/upload") |
| | | public AjaxResult uploadFile(MultipartFile file) throws Exception |
| | | { |
| | | // System.out.println("sdfd9999999999999999999999999999999"); |
| | | try |
| | | { |
| | | //根据文件名称,然后修改对应数据的url |
| | | String fname = file.getOriginalFilename(); |
| | | |
| | | // System.out.println(fname); |
| | | // 上传文件路径 |
| | | String filePath = RuoYiConfig.getUploadPath(); |
| | | // System.out.println(filePath); |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | //分割文件名 |
| | | String [] nams = fname.split("\\."); |
| | | Long nam = Long.parseLong(nams[0]); |
| | | //文件名称 |
| | | String pname = nams[1]; |
| | | ajax.put("url", url); |
| | | //拿到图像属性 |
| | | BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); |
| | | int wid = bufferedImage.getWidth(); |
| | | int hei = bufferedImage.getHeight(); |
| | | double sz = Double.parseDouble(String.format("%.2f", file.getSize()*1.0/1024)); |
| | | System.out.println(wid+":"+hei+":"+sz); |
| | | //计算fileNumber |
| | | Long fileNumber = documentMaterialsService.getFiNum(nam); |
| | | //插入数据库对应的url当中 |
| | | documentMaterialsService.updateByPageNumber(nam, fileNumber,wid, hei, sz, fileName, pname); |
| | | // System.out.println(url); |
| | | // System.out.println(fileName); |
| | | ajax.put("fileName", fileName); |
| | | // System.out.println(FileUtils.getName(fileName)); |
| | | ajax.put("newFileName", FileUtils.getName(fileName)); |
| | | ajax.put("originalFilename", file.getOriginalFilename()); |
| | | return ajax; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | System.out.println(e); |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | | } |
| | | } |