Kaynağa Gözat

文件上传参数

lamphua 1 yıl önce
ebeveyn
işleme
f52872eacc

+ 2
- 2
oa-back/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java Dosyayı Görüntüle

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

+ 1
- 1
oa-back/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java Dosyayı Görüntüle

@@ -121,7 +121,7 @@ public class SysProfileController extends BaseController
121 121
         if (!file.isEmpty())
122 122
         {
123 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 125
             if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
126 126
             {
127 127
                 AjaxResult ajax = AjaxResult.success();

+ 12
- 9
oa-back/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java Dosyayı Görüntüle

@@ -54,11 +54,11 @@ public class FileUploadUtils
54 54
      * @return 文件名称
55 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 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 63
         catch (Exception e)
64 64
         {
@@ -74,11 +74,11 @@ public class FileUploadUtils
74 74
      * @return 文件名称
75 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 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 83
         catch (Exception e)
84 84
         {
@@ -98,7 +98,7 @@ public class FileUploadUtils
98 98
      * @throws IOException 比如读写文件出错时
99 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 102
             throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
103 103
             InvalidExtensionException
104 104
     {
@@ -110,7 +110,7 @@ public class FileUploadUtils
110 110
 
111 111
         assertAllowed(file, allowedExtension);
112 112
 
113
-        String fileName = extractFilename(file);
113
+        String fileName = extractFilename(file, fileType);
114 114
 
115 115
         String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
116 116
         file.transferTo(Paths.get(absPath));
@@ -120,10 +120,13 @@ public class FileUploadUtils
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 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 Dosyayı Görüntüle

@@ -133,6 +133,22 @@ public class CmcProject extends BaseEntity
133 133
     @Excel(name = "kml文件的中心位置纬度")
134 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 152
     public void setProjectId(String projectId)
137 153
     {
138 154
         this.projectId = projectId;
@@ -404,6 +420,38 @@ public class CmcProject extends BaseEntity
404 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 455
     @Override
408 456
     public String toString() {
409 457
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 17
- 1
oa-back/ruoyi-system/src/main/resources/mapper/oa/CmcProjectMapper.xml Dosyayı Görüntüle

@@ -29,6 +29,10 @@
29 29
         <result property="projectCp"    column="project_cp"    />
30 30
         <result property="kmlLng"    column="kml_lng"    />
31 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 36
         <association property="projectLeaderUser"    javaType="SysUser"         resultMap="ProjectLeaderResult" />
33 37
         <association property="projectRegistrantUser"    javaType="SysUser"         resultMap="ProjectRegistrantResult" />
34 38
         <association property="technicalDirectorUser"    javaType="SysUser"         resultMap="TechnicalDirectorResult" />
@@ -59,7 +63,7 @@
59 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 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 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 67
         left join sys_user as u on u.user_id = p.project_leader
64 68
         left join sys_user as u1 on u1.user_id = p.project_registrant
65 69
         left join cmc_technical as c on c.project_id = p.project_id
@@ -127,6 +131,10 @@
127 131
             <if test="projectCp != null">project_cp,</if>
128 132
             <if test="kmlLng != null">kml_lng,</if>
129 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 138
         </trim>
131 139
         <trim prefix="values (" suffix=")" suffixOverrides=",">
132 140
             <if test="projectId != null">#{projectId},</if>
@@ -153,6 +161,10 @@
153 161
             <if test="projectCp != null">#{projectCp},</if>
154 162
             <if test="kmlLng != null">#{kmlLng},</if>
155 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 168
         </trim>
157 169
     </insert>
158 170
 
@@ -182,6 +194,10 @@
182 194
             <if test="projectCp != null">project_cp = #{projectCp},</if>
183 195
             <if test="kmlLng != null">kml_lng = #{kmlLng},</if>
184 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 201
         </trim>
186 202
         where project_id = #{projectId}
187 203
     </update>

Loading…
İptal
Kaydet