Browse Source

文件上传参数

lamphua 1 year ago
parent
commit
f52872eacc

+ 2
- 2
oa-back/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java View File

73
      * 通用上传请求(单个)
73
      * 通用上传请求(单个)
74
      */
74
      */
75
     @PostMapping("/upload")
75
     @PostMapping("/upload")
76
-    public AjaxResult uploadFile(MultipartFile file) throws Exception
76
+    public AjaxResult uploadFile(String fileType, MultipartFile file) throws Exception
77
     {
77
     {
78
         try
78
         try
79
         {
79
         {
80
             // 上传文件路径
80
             // 上传文件路径
81
             String filePath = RuoYiConfig.getUploadPath();
81
             String filePath = RuoYiConfig.getUploadPath();
82
             // 上传并返回新文件名称
82
             // 上传并返回新文件名称
83
-            String fileName = FileUploadUtils.upload(filePath, file);
83
+            String fileName = FileUploadUtils.upload(filePath, fileType, file);
84
             String url = serverConfig.getUrl() + fileName;
84
             String url = serverConfig.getUrl() + fileName;
85
             AjaxResult ajax = AjaxResult.success();
85
             AjaxResult ajax = AjaxResult.success();
86
             ajax.put("url", url);
86
             ajax.put("url", url);

+ 1
- 1
oa-back/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java View File

121
         if (!file.isEmpty())
121
         if (!file.isEmpty())
122
         {
122
         {
123
             LoginUser loginUser = getLoginUser();
123
             LoginUser loginUser = getLoginUser();
124
-            String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
124
+            String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), "头像", file, MimeTypeUtils.IMAGE_EXTENSION);
125
             if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
125
             if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
126
             {
126
             {
127
                 AjaxResult ajax = AjaxResult.success();
127
                 AjaxResult ajax = AjaxResult.success();

+ 12
- 9
oa-back/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java View File

54
      * @return 文件名称
54
      * @return 文件名称
55
      * @throws Exception
55
      * @throws Exception
56
      */
56
      */
57
-    public static final String upload(MultipartFile file) throws IOException
57
+    public static final String upload(String fileType, MultipartFile file) throws IOException
58
     {
58
     {
59
         try
59
         try
60
         {
60
         {
61
-            return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
61
+            return upload(getDefaultBaseDir(), fileType, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
62
         }
62
         }
63
         catch (Exception e)
63
         catch (Exception e)
64
         {
64
         {
74
      * @return 文件名称
74
      * @return 文件名称
75
      * @throws IOException
75
      * @throws IOException
76
      */
76
      */
77
-    public static final String upload(String baseDir, MultipartFile file) throws IOException
77
+    public static final String upload(String baseDir, String fileType, MultipartFile file) throws IOException
78
     {
78
     {
79
         try
79
         try
80
         {
80
         {
81
-            return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
81
+            return upload(baseDir, fileType, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
82
         }
82
         }
83
         catch (Exception e)
83
         catch (Exception e)
84
         {
84
         {
98
      * @throws IOException 比如读写文件出错时
98
      * @throws IOException 比如读写文件出错时
99
      * @throws InvalidExtensionException 文件校验异常
99
      * @throws InvalidExtensionException 文件校验异常
100
      */
100
      */
101
-    public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
101
+    public static final String upload(String baseDir, String fileType, MultipartFile file, String[] allowedExtension)
102
             throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
102
             throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
103
             InvalidExtensionException
103
             InvalidExtensionException
104
     {
104
     {
110
 
110
 
111
         assertAllowed(file, allowedExtension);
111
         assertAllowed(file, allowedExtension);
112
 
112
 
113
-        String fileName = extractFilename(file);
113
+        String fileName = extractFilename(file, fileType);
114
 
114
 
115
         String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
115
         String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
116
         file.transferTo(Paths.get(absPath));
116
         file.transferTo(Paths.get(absPath));
120
     /**
120
     /**
121
      * 编码文件名
121
      * 编码文件名
122
      */
122
      */
123
-    public static final String extractFilename(MultipartFile file)
123
+    public static final String extractFilename(MultipartFile file, String fileType)
124
     {
124
     {
125
-        return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
126
-                FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
125
+        //原始代码
126
+//        return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
127
+//                FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
128
+        return StringUtils.format("{}/{}.{}", fileType,
129
+                FilenameUtils.getBaseName(file.getOriginalFilename()), getExtension(file));
127
     }
130
     }
128
 
131
 
129
     public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
132
     public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException

+ 48
- 0
oa-back/ruoyi-system/src/main/java/com/ruoyi/oa/domain/CmcProject.java View File

133
     @Excel(name = "kml文件的中心位置纬度")
133
     @Excel(name = "kml文件的中心位置纬度")
134
     private String kmlLat;
134
     private String kmlLat;
135
 
135
 
136
+    /** 项目用车 */
137
+    @Excel(name = "项目用车")
138
+    private String cars;
139
+
140
+    /** 项目驾驶员 */
141
+    @Excel(name = "项目驾驶员")
142
+    private String drivers;
143
+
144
+    /** 项目设备 */
145
+    @Excel(name = "项目设备")
146
+    private String devices;
147
+
148
+    /** 项目参与人员 */
149
+    @Excel(name = "项目参与人员")
150
+    private String participates;
151
+
136
     public void setProjectId(String projectId)
152
     public void setProjectId(String projectId)
137
     {
153
     {
138
         this.projectId = projectId;
154
         this.projectId = projectId;
404
         return kmlLat;
420
         return kmlLat;
405
     }
421
     }
406
 
422
 
423
+    public String getCars()
424
+    {
425
+        return cars;
426
+    }
427
+    public void setDrivers(String drivers)
428
+    {
429
+        this.drivers = drivers;
430
+    }
431
+
432
+    public String getDrivers()
433
+    {
434
+        return drivers;
435
+    }
436
+    public void setDevices(String devices)
437
+    {
438
+        this.devices = devices;
439
+    }
440
+
441
+    public String getDevices()
442
+    {
443
+        return devices;
444
+    }
445
+    public void setParticipates(String participates)
446
+    {
447
+        this.participates = participates;
448
+    }
449
+
450
+    public String getParticipates()
451
+    {
452
+        return participates;
453
+    }
454
+
407
     @Override
455
     @Override
408
     public String toString() {
456
     public String toString() {
409
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
457
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 17
- 1
oa-back/ruoyi-system/src/main/resources/mapper/oa/CmcProjectMapper.xml View File

29
         <result property="projectCp"    column="project_cp"    />
29
         <result property="projectCp"    column="project_cp"    />
30
         <result property="kmlLng"    column="kml_lng"    />
30
         <result property="kmlLng"    column="kml_lng"    />
31
         <result property="kmlLat"    column="kml_lat"    />
31
         <result property="kmlLat"    column="kml_lat"    />
32
+        <result property="cars"    column="cars"    />
33
+        <result property="drivers"    column="drivers"    />
34
+        <result property="devices"    column="devices"    />
35
+        <result property="participates"    column="participates"    />
32
         <association property="projectLeaderUser"    javaType="SysUser"         resultMap="ProjectLeaderResult" />
36
         <association property="projectLeaderUser"    javaType="SysUser"         resultMap="ProjectLeaderResult" />
33
         <association property="projectRegistrantUser"    javaType="SysUser"         resultMap="ProjectRegistrantResult" />
37
         <association property="projectRegistrantUser"    javaType="SysUser"         resultMap="ProjectRegistrantResult" />
34
         <association property="technicalDirectorUser"    javaType="SysUser"         resultMap="TechnicalDirectorResult" />
38
         <association property="technicalDirectorUser"    javaType="SysUser"         resultMap="TechnicalDirectorResult" />
59
         select p.project_id, p.project_number, p.project_name, p.project_leader, u.nick_name as leader_nick_name, p.is_finished, p.project_source, p.party_a, p.contact_person, p.telephone,
63
         select p.project_id, p.project_number, p.project_name, p.project_leader, u.nick_name as leader_nick_name, p.is_finished, p.project_source, p.party_a, p.contact_person, p.telephone,
60
                p.project_type, p.project_level, p.project_registrant, u1.nick_name as registrant_nick_name, p.undertaking_dept, p.project_planner, p.site_leader, p.register_time, p.plan_time,
64
                p.project_type, p.project_level, p.project_registrant, u1.nick_name as registrant_nick_name, p.undertaking_dept, p.project_planner, p.site_leader, p.register_time, p.plan_time,
61
                p.entry_time, p.exit_time, p.remark, c.technical_director, u2.nick_name as director_nick_name, c.quality_inspector, u3.nick_name as inspector_nick_name, u3.user_id as inspector_user_id,
65
                p.entry_time, p.exit_time, p.remark, c.technical_director, u2.nick_name as director_nick_name, c.quality_inspector, u3.nick_name as inspector_nick_name, u3.user_id as inspector_user_id,
62
-               p.project_kml, p.project_cp, p.kml_lng, p.kml_lat from cmc_project as p
66
+               p.project_kml, p.project_cp, p.kml_lng, p.kml_lat, p.cars, p.drivers, p.devices, p.participates from cmc_project as p
63
         left join sys_user as u on u.user_id = p.project_leader
67
         left join sys_user as u on u.user_id = p.project_leader
64
         left join sys_user as u1 on u1.user_id = p.project_registrant
68
         left join sys_user as u1 on u1.user_id = p.project_registrant
65
         left join cmc_technical as c on c.project_id = p.project_id
69
         left join cmc_technical as c on c.project_id = p.project_id
127
             <if test="projectCp != null">project_cp,</if>
131
             <if test="projectCp != null">project_cp,</if>
128
             <if test="kmlLng != null">kml_lng,</if>
132
             <if test="kmlLng != null">kml_lng,</if>
129
             <if test="kmlLat != null">kml_lat,</if>
133
             <if test="kmlLat != null">kml_lat,</if>
134
+            <if test="cars != null">cars,</if>
135
+            <if test="drivers != null">drivers,</if>
136
+            <if test="devices != null">devices,</if>
137
+            <if test="participates != null">participates,</if>
130
         </trim>
138
         </trim>
131
         <trim prefix="values (" suffix=")" suffixOverrides=",">
139
         <trim prefix="values (" suffix=")" suffixOverrides=",">
132
             <if test="projectId != null">#{projectId},</if>
140
             <if test="projectId != null">#{projectId},</if>
153
             <if test="projectCp != null">#{projectCp},</if>
161
             <if test="projectCp != null">#{projectCp},</if>
154
             <if test="kmlLng != null">#{kmlLng},</if>
162
             <if test="kmlLng != null">#{kmlLng},</if>
155
             <if test="kmlLat != null">#{kmlLat},</if>
163
             <if test="kmlLat != null">#{kmlLat},</if>
164
+            <if test="cars != null">#{cars},</if>
165
+            <if test="drivers != null">#{drivers},</if>
166
+            <if test="devices != null">#{devices},</if>
167
+            <if test="participates != null">#{participates},</if>
156
         </trim>
168
         </trim>
157
     </insert>
169
     </insert>
158
 
170
 
182
             <if test="projectCp != null">project_cp = #{projectCp},</if>
194
             <if test="projectCp != null">project_cp = #{projectCp},</if>
183
             <if test="kmlLng != null">kml_lng = #{kmlLng},</if>
195
             <if test="kmlLng != null">kml_lng = #{kmlLng},</if>
184
             <if test="kmlLat != null">kml_lat = #{kmlLat},</if>
196
             <if test="kmlLat != null">kml_lat = #{kmlLat},</if>
197
+            <if test="cars != null">cars = #{cars},</if>
198
+            <if test="drivers != null">drivers = #{drivers},</if>
199
+            <if test="devices != null">devices = #{devices},</if>
200
+            <if test="participates != null">participates = #{participates},</if>
185
         </trim>
201
         </trim>
186
         where project_id = #{projectId}
202
         where project_id = #{projectId}
187
     </update>
203
     </update>

Loading…
Cancel
Save