Browse Source

-修改附件上传

jiangbiao 2 năm trước cách đây
mục cha
commit
98e2dedf20

+ 0 - 15
ruoyi-admin/src/main/java/com/ruoyi/web/controller/branch/TBranchStudyController.java

@@ -87,12 +87,6 @@ public class TBranchStudyController extends BaseController {
     @Log(title = "支部党课学习", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody TBranchStudy tBranchStudy) {
-        if (StringUtils.isNotEmpty(tBranchStudy.getFilesId())) {
-            TBranchStudy study = tBranchStudyService.selectTBranchStudyByStudyId(tBranchStudy.getStudyId());
-            if (StringUtils.isNotEmpty(study.getFilesId())) {
-                tBranchStudy.setFilesId(study.getFilesId() + "," + tBranchStudy.getFilesId());
-            }
-        }
         return toAjax(tBranchStudyService.updateTBranchStudy(tBranchStudy));
     }
 
@@ -110,15 +104,6 @@ public class TBranchStudyController extends BaseController {
     @Log(title = "支部党课删除附件", businessType = BusinessType.DELETE)
     @PutMapping("/delFile")
     public AjaxResult removeFile(@RequestBody TBranchStudy tBranchStudy) {
-        TBranchStudy study = tBranchStudyService.selectTBranchStudyByStudyId(tBranchStudy.getStudyId());
-        study.setFilesId(study.getFilesId().replace(tBranchStudy.getFilesId(), ""));
-        if (study.getFilesId().contains(",,")){
-            study.setFilesId(study.getFilesId().replace(",,", ","));
-        }
-        if (study.getFilesId().endsWith(",")) {
-            study.setFilesId(study.getFilesId().substring(0, study.getFilesId().length()-1));
-        }
-        tBranchStudyService.updateTBranchStudy(study);
         return toAjax(tFileService.deleteTFileById(Long.valueOf(tBranchStudy.getFilesId())));
     }
 }

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/branch/TFileController.java

@@ -36,10 +36,8 @@ public class TFileController extends BaseController {
      * 查询附件列表
      */
     @GetMapping("/list")
-    public TableDataInfo list(TFile tFile) {
-        startPage();
-        List<TFile> list = tFileService.selectTFileList(tFile);
-        return getDataTable(list);
+    public AjaxResult list(TFile tFile) {
+        return AjaxResult.success(tFileService.selectTFileList(tFile));
     }
 
     /**
@@ -91,12 +89,14 @@ public class TFileController extends BaseController {
 
 
     @PostMapping("/uploadFile")
-    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
+    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file,String tableName,Long tableId) throws IOException {
         if (!file.isEmpty()) {
-            String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file);
+            String avatar = FileUploadUtils.upload(RuoYiConfig.getFilePath(tableName), file);
             TFile tFile = new TFile();
             tFile.setName(file.getOriginalFilename());
             tFile.setUrl(avatar);
+            tFile.setTableId(tableId);
+            tFile.setTableName(tableName);
             tFile.setCreatedate(new Date());
             tFile.setCreaterCode(getUserId().toString());
             tFileService.insertTFile(tFile);

+ 49 - 42
ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java

@@ -5,91 +5,92 @@ import org.springframework.stereotype.Component;
 
 /**
  * 读取项目相关配置
- * 
+ *
  * @author ruoyi
  */
 @Component
 @ConfigurationProperties(prefix = "ruoyi")
-public class RuoYiConfig
-{
-    /** 项目名称 */
+public class RuoYiConfig {
+    /**
+     * 项目名称
+     */
     private String name;
 
-    /** 版本 */
+    /**
+     * 版本
+     */
     private String version;
 
-    /** 版权年份 */
+    /**
+     * 版权年份
+     */
     private String copyrightYear;
 
-    /** 实例演示开关 */
+    /**
+     * 实例演示开关
+     */
     private boolean demoEnabled;
 
-    /** 上传路径 */
+    /**
+     * 上传路径
+     */
     private static String profile;
 
-    /** 获取地址开关 */
+    /**
+     * 获取地址开关
+     */
     private static boolean addressEnabled;
 
-    /** 验证码类型 */
+    /**
+     * 验证码类型
+     */
     private static String captchaType;
 
-    public String getName()
-    {
+    public String getName() {
         return name;
     }
 
-    public void setName(String name)
-    {
+    public void setName(String name) {
         this.name = name;
     }
 
-    public String getVersion()
-    {
+    public String getVersion() {
         return version;
     }
 
-    public void setVersion(String version)
-    {
+    public void setVersion(String version) {
         this.version = version;
     }
 
-    public String getCopyrightYear()
-    {
+    public String getCopyrightYear() {
         return copyrightYear;
     }
 
-    public void setCopyrightYear(String copyrightYear)
-    {
+    public void setCopyrightYear(String copyrightYear) {
         this.copyrightYear = copyrightYear;
     }
 
-    public boolean isDemoEnabled()
-    {
+    public boolean isDemoEnabled() {
         return demoEnabled;
     }
 
-    public void setDemoEnabled(boolean demoEnabled)
-    {
+    public void setDemoEnabled(boolean demoEnabled) {
         this.demoEnabled = demoEnabled;
     }
 
-    public static String getProfile()
-    {
+    public static String getProfile() {
         return profile;
     }
 
-    public void setProfile(String profile)
-    {
+    public void setProfile(String profile) {
         RuoYiConfig.profile = profile;
     }
 
-    public static boolean isAddressEnabled()
-    {
+    public static boolean isAddressEnabled() {
         return addressEnabled;
     }
 
-    public void setAddressEnabled(boolean addressEnabled)
-    {
+    public void setAddressEnabled(boolean addressEnabled) {
         RuoYiConfig.addressEnabled = addressEnabled;
     }
 
@@ -104,32 +105,38 @@ public class RuoYiConfig
     /**
      * 获取导入上传路径
      */
-    public static String getImportPath()
-    {
+    public static String getImportPath() {
         return getProfile() + "/import";
     }
 
     /**
      * 获取头像上传路径
      */
-    public static String getAvatarPath()
-    {
+    public static String getAvatarPath() {
         return getProfile() + "/avatar";
     }
 
     /**
      * 获取下载路径
      */
-    public static String getDownloadPath()
-    {
+    public static String getDownloadPath() {
         return getProfile() + "/download/";
     }
 
     /**
      * 获取上传路径
      */
-    public static String getUploadPath()
-    {
+    public static String getUploadPath() {
         return getProfile() + "/upload";
     }
+
+
+    /**
+     * 获取上传路径
+     */
+    public static String getFilePath(String dir) {
+        return getProfile() + "/" + dir;
+
+    }
+
 }

+ 20 - 0
ruoyi-system/src/main/java/com/ruoyi/branch/domain/TFile.java

@@ -64,6 +64,26 @@ public class TFile extends BaseEntity
     @Excel(name = "部门编号")
     private Long deptId;
 
+    private Long tableId;
+
+    private String tableName;
+
+    public Long getTableId() {
+        return tableId;
+    }
+
+    public void setTableId(Long tableId) {
+        this.tableId = tableId;
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public void setTableName(String tableName) {
+        this.tableName = tableName;
+    }
+
     private Long[] filesId;
 
     public String getCreater() {

+ 12 - 2
ruoyi-system/src/main/resources/mapper/branch/TFileMapper.xml

@@ -17,6 +17,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updatedate"    column="updatedate"    />
         <result property="deptId"    column="dept_id"    />
         <result property="creater"    column="nick_name"    />
+        <result property="tableId"    column="table_id"    />
+        <result property="tableName"    column="table_name"    />
     </resultMap>
 
     <sql id="selectTFileVo">
@@ -24,11 +26,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </sql>
 
     <select id="selectTFileList" parameterType="TFile" resultMap="TFileResult">
-        select u.id, u.url, u.name, u.remarks, u.status, u.del_flag, u.creater_code, u.createdate, u.updater_code, u.updatedate, u.dept_id,su.nick_name from t_file u left join sys_dept d on u.dept_id = d.dept_id
+        select u.id, u.url, u.name, u.remarks, u.status, u.del_flag, u.creater_code, u.createdate, u.updater_code, u.updatedate, u.dept_id,u.table_id,u.table_name,su.nick_name from t_file u left join sys_dept d on u.dept_id = d.dept_id
         left join sys_user su on u.creater_code=su.user_id
         <where>
             <if test="url != null  and url != ''">and u.url = #{url}</if>
-            <if test="name != null  and name != ''">and u.name like concat('%', #{name}, '%')</if>
+            <if test="name != null  and name != ''">and u.name like concat(concat('%',#{name}),'%')</if>
+            <if test="tableId != null">and u.table_id=#{tableId}</if>
+            <if test="tableName != null  and tableName != ''">and u.table_name like concat(concat('%',#{tableName}),'%')</if>
             <if test="remarks != null  and remarks != ''">and u.remarks = #{remarks}</if>
             <if test="status != null ">and u.status = #{status}</if>
             <if test="createrCode != null  and createrCode != ''">and u.creater_code = #{createrCode}</if>
@@ -70,6 +74,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updaterCode != null">updater_code,</if>
             <if test="updatedate != null">updatedate,</if>
             <if test="deptId != null">dept_id,</if>
+            <if test="tableId != null">table_id,</if>
+            <if test="tableName != null">table_name,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
@@ -83,6 +89,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updaterCode != null">#{updaterCode},</if>
             <if test="updatedate != null">#{updatedate},</if>
             <if test="deptId != null">#{deptId},</if>
+            <if test="tableId != null">#{tableId},</if>
+            <if test="tableName != null">#{tableName},</if>
          </trim>
     </insert>
 
@@ -99,6 +107,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updaterCode != null">updater_code = #{updaterCode},</if>
             <if test="updatedate != null">updatedate = #{updatedate},</if>
             <if test="deptId != null">dept_id = #{deptId},</if>
+            <if test="tableId != null">table_id=#{tableId},</if>
+            <if test="tableName != null">table_name=#{tableName},</if>
         </trim>
         where id = #{id}
     </update>

+ 19 - 14
ruoyi-ui/src/views/branch/manage/index.vue

@@ -167,7 +167,7 @@
           <el-upload
             ref="doc"
             :headers="file.doc.headers"
-            :action="file.doc.url"
+            :action="file.doc.url+'?tableName=branchManage&tableId=' + file.doc.tableId"
             :disabled="file.doc.isUploading"
             :on-progress="handleFileDocProgress"
             :on-success="handleFileDocSuccess"
@@ -202,7 +202,7 @@
               size="mini"
               type="text"
               icon="el-icon-delete"
-              @click="handleFileDelete(scope.row)"
+              @click="handleFileDelete(scope.row.id)"
             >删除
             </el-button>
           </template>
@@ -226,7 +226,7 @@ import {treeselect} from "@/api/system/dept";
 import {getToken} from "@/utils/auth";
 import Treeselect from "@riophae/vue-treeselect";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
-import {listFile} from "../../../api/branch/file";
+import {delFile, listFile} from "../../../api/branch/file";
 import {delManageFile} from "../../../api/branch/manage";
 
 export default {
@@ -250,6 +250,7 @@ export default {
           // 设置上传的请求头部
           headers: {Authorization: "Bearer " + getToken()},
           // 上传的地址
+          tableId: 0,
           url: process.env.VUE_APP_BASE_API + "/branch/file/uploadFile",
         },
       },
@@ -353,10 +354,16 @@ export default {
     handleSee(url) {
       window.open(process.env.VUE_APP_BASE_API + url);
     },
-    handleFileDelete(row) {
-      delManageFile({filesId:row.id,manageId:this.file.id}).then(res=>{
-        this.$modal.msgSuccess("删除成功");
-        this.getFileList(this.file.id);
+    handleFileDelete(id) {
+      this.$confirm('是否确认删除?', "警告", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning"
+      }).then(function () {
+        return delFile(id);
+      }).then(() => {
+        this.getFileList();
+        this.msgSuccess("删除成功");
       })
     },
     //附件上传中处理
@@ -367,20 +374,18 @@ export default {
     handleFileDocSuccess(response, file, fileList) {
       updateManage({filesId: response.data, manageId: this.file.id}).then(response => {
         this.$modal.msgSuccess("上传成功");
-        this.getFileList(this.file.id)
+        this.getFileList();
       });
     },
     openFileDialog(row) {
       this.file.open = true;
       this.file.id = row.manageId;
+      this.file.doc.tableId = row.manageId;
       this.getFileList(row.manageId);
     },
-    getFileList(manageId) {
-      getManage(manageId).then(res => {
-        let filesId = res.data.filesId.split(',');
-        listFile({filesId: filesId}).then(result => {
-          this.file.dataList = result.rows
-        })
+    getFileList() {
+      listFile({tableId: this.file.doc.tableId, tableName: 'branchManage'}).then(res => {
+        this.file.dataList = res.data
       })
     },
     /** 查询支部党课学习资料管理列表 */

+ 45 - 27
ruoyi-ui/src/views/branch/xxyd/study/index.vue

@@ -10,16 +10,17 @@
         </el-date-picker>
       </el-form-item>
       <el-form-item label="地点" prop="studyVenue">
-        <el-input v-model="queryParams.studyVenue" placeholder="请输入地点" />
+        <el-input v-model="queryParams.studyVenue" placeholder="请输入地点"/>
       </el-form-item>
       <el-form-item label="内容" prop="contents">
-        <el-input v-model="queryParams.contents" placeholder="请输入内容" />
+        <el-input v-model="queryParams.contents" placeholder="请输入内容"/>
       </el-form-item>
       <el-form-item label="备注" prop="remarks">
-        <el-input v-model="queryParams.remarks" placeholder="请输入备注" />
+        <el-input v-model="queryParams.remarks" placeholder="请输入备注"/>
       </el-form-item>
       <el-form-item label="归属部门" prop="deptId" style="width: 268px;">
-        <treeselect style="width: 200px;" v-model="queryParams.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
+        <treeselect style="width: 200px;" v-model="queryParams.deptId" :options="deptOptions" :show-count="true"
+                    placeholder="请选择归属部门"/>
       </el-form-item>
       <el-form-item>
         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
@@ -108,7 +109,7 @@
             size="mini"
             type="text"
             icon="el-icon-folder"
-            @click="handleSee(scope.row)"
+            @click="openFileDialog(scope.row)"
           >查看附件
           </el-button>
         </template>
@@ -250,7 +251,7 @@
           <el-upload
             ref="doc"
             :headers="doc.headers"
-            :action="doc.url"
+            :action="doc.url+'?tableName=branchStudy&tableId=' + doc.tableId"
             :disabled="doc.isUploading"
             :on-progress="handleFileDocProgress"
             :on-success="handleFileDocSuccess"
@@ -261,38 +262,31 @@
           </el-upload>
         </el-col>
       </el-row>
-      <el-table>
+      <el-table :data="file.dataList">
         <el-table-column label="附件名称" align="center">
           <template slot-scope="scope">
             <el-button
               size="mini"
               type="text"
               icon="el-icon-document"
-              @click="">
+              @click="handleSee(scope.row.url)">
               {{ scope.row.name }}
             </el-button>
           </template>
         </el-table-column>
         <el-table-column label="上传人" align="center" prop="creater"/>
-        <el-table-column label="上传时间" align="center" prop="createDate">
+        <el-table-column label="上传时间" align="center" prop="createdate">
           <template slot-scope="scope">
-            <span>{{ parseTime(scope.row.studyTime, '{y}-{m}-{d}') }}</span>
+            <span>{{ parseTime(scope.row.createdate, '{y}-{m}-{d}') }}</span>
           </template>
         </el-table-column>
         <el-table-column label="操作" align="center">
           <template slot-scope="scope">
-            <el-button
-              size="mini"
-              type="text"
-              icon="el-icon-edit"
-              @click="handleUpdate(scope.row)"
-            >修改
-            </el-button>
             <el-button
               size="mini"
               type="text"
               icon="el-icon-delete"
-              @click="handleDelete(scope.row)"
+              @click="handleDeleteFile(scope.row.id)"
             >删除
             </el-button>
           </template>
@@ -309,6 +303,7 @@ import {getToken} from "@/utils/auth";
 import Treeselect from "@riophae/vue-treeselect";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
 import {listUser} from "@/api/system/user";
+import {delFile, listFile} from "../../../../api/branch/file";
 
 export default {
   name: "Study",
@@ -319,6 +314,7 @@ export default {
         id: null,
         open: false,
         fileList: [],
+        dataList: [],
       },
       doc: {
         file: "",
@@ -330,6 +326,7 @@ export default {
         isUploading: false,
         // 设置上传的请求头部
         headers: {Authorization: "Bearer " + getToken()},
+        tableId: 0,
         // 上传的地址
         url: process.env.VUE_APP_BASE_API + "/branch/file/uploadFile",
       },
@@ -388,13 +385,13 @@ export default {
       // 表单校验
       rules: {
         studyTime: [
-          { required: true, message: "时间不能为空", trigger: "blur" }
+          {required: true, message: "时间不能为空", trigger: "blur"}
         ],
         studyVenue: [
-          { required: true, message: "地点不能为空", trigger: "blur" }
+          {required: true, message: "地点不能为空", trigger: "blur"}
         ],
         deptId: [
-          { required: true, message: "归属部门不能为空", trigger: "blur" }
+          {required: true, message: "归属部门不能为空", trigger: "blur"}
         ],
       },
       // 用户列表
@@ -422,10 +419,9 @@ export default {
     },
     //附件上传成功处理
     handleFileDocSuccess(response, file, fileList) {
-      console.log(response.data, '-----', this.file.id)
-      // updateStudy({filesId: response.data, studyId: this.file.id}).then(response => {
-      //
-      // });
+      console.log(response.data, '-----', this.file.id);
+      this.$modal.msgSuccess("上传成功");
+      this.getFileList();
     },
     /** 查询用户列表 */
     getUserList() {
@@ -441,9 +437,31 @@ export default {
         this.userList = userList;
       });
     },
-    handleSee(row) {
+    handleSee(url) {
+      window.open(process.env.VUE_APP_BASE_API + url);
+    },
+    openFileDialog(row) {
+      console.log(row)
       this.file.open = true;
-      this.file.id = row.id;
+      this.doc.tableId = row.studyId;
+      this.getFileList();
+    },
+    getFileList() {
+      listFile({tableId: this.doc.tableId, tableName: 'branchStudy'}).then(res => {
+        this.file.dataList = res.data
+      })
+    },
+    handleDeleteFile(id) {
+      this.$confirm('是否确认删除?', "警告", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning"
+      }).then(function () {
+        return delFile(id);
+      }).then(() => {
+        this.getFileList();
+        this.msgSuccess("删除成功");
+      })
     },
     /** 查询支部党课学习列表 */
     getList() {