fei
1 天以前 e899d2709f21b322232fb64778fef296233be3f0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.ruoyi.web.controller.archive;
 
 
 
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 org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
 
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;
 
/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/system/materials")
public class DocumentMaterialsController extends BaseController
{
    @Autowired
    private ServerConfig serverConfig;
 
    @Autowired
    private IDocumentMaterialsService documentMaterialsService;
 
    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:materials:list')")
    @GetMapping("/list")
    public AjaxResult list(DocumentMaterials documentMaterials)
    {
 
        Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
        return documentMaterialsService.selectDataList(documentMaterials, pageNum, pageSize);
    }
 
    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:materials:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DocumentMaterials documentMaterials)
    {
        List<DocumentMaterials> list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials);
        ExcelUtil<DocumentMaterials> util = new ExcelUtil<DocumentMaterials>(DocumentMaterials.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }
 
    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:materials:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") String materialId)
    {
        return success(documentMaterialsService.selectDocumentMaterialsByMaterialId(materialId));
    }
 
    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:materials:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocumentMaterials documentMaterials)
    {
        int res = documentMaterialsService.insertDocumentMaterials(documentMaterials);
        System.out.println(res+"][[[[[[[[[[[[[[[[[[");
        return toAjax(res);
    }
 
    /**
     * 修改【请填写功能名称】
     *
     * system:materials:edit
     */
    @PreAuthorize("@ss.hasPermi('system:materials:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocumentMaterials documentMaterials)
    {
        return toAjax(documentMaterialsService.updateDocumentMaterials(documentMaterials));
    }
 
    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:materials:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable String[] materialIds)
    {
        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());
        }
    }
}