Parcourir la source

离职交接上传附件问题

huangguoce il y a 2 semaines
Parent
commit
23291a704d

+ 10 - 0
jeeplus-modules/jeeplus-human/src/main/java/com/jeeplus/human/depart/handover/mapper/HandoverMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.jeeplus.human.depart.handover.domain.Handover;
 import com.jeeplus.human.depart.handover.domain.HandoverProject;
+import com.jeeplus.sys.domain.WorkAttachmentInfo;
 import com.jeeplus.sys.service.dto.UserDTO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -46,6 +47,15 @@ public interface HandoverMapper extends BaseMapper<Handover> {
      */
     String getUserInfoByUserId(@Param("userId")String userId);
 
+    /**
+     * 根据AttachmentFla 和AttachmentId 查询附件信息
+     * @param id
+     * @param attachmentFlag
+     * @return
+     */
+    List<WorkAttachmentInfo> findListByIdAndAttachmentFlag(@Param("id") String id, @Param("attachmentFlag")String attachmentFlag);
+    @InterceptorIgnore(tenantLine = "true")
+    Integer findIsExit(@Param("id") String id, @Param("name")String name);
 
 }
 

+ 13 - 0
jeeplus-modules/jeeplus-human/src/main/java/com/jeeplus/human/depart/handover/mapper/xml/HandoverMapper.xml

@@ -88,4 +88,17 @@
             FROM human_resources_depart_handover_project a where a.handover_id = #{id} and del_flag = 0
     </select>
 
+    <select id="findListByIdAndAttachmentFlag" resultType="com.jeeplus.sys.domain.WorkAttachmentInfo">
+        SELECT * FROM work_attachment WHERE del_flag = 0 AND attachment_id = #{id} and attachment_flag = #{attachmentFlag}
+    </select>
+    <select id="findIsExit" resultType="java.lang.Integer">
+        SELECT
+            COUNT( 0 )
+        FROM
+            work_attachment
+        WHERE
+            del_flag = 0
+          AND attachment_id = #{id}
+          AND attachment_name = #{name}
+    </select>
 </mapper>

+ 112 - 47
jeeplus-modules/jeeplus-human/src/main/java/com/jeeplus/human/depart/handover/service/HandoverService.java

@@ -37,6 +37,7 @@ import org.apache.pdfbox.pdmodel.font.PDType0Font;
 import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
 import org.apache.pdfbox.util.Matrix;
 import org.apache.poi.xwpf.usermodel.*;
+import org.flowable.editor.language.json.converter.util.CollectionUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
@@ -190,25 +191,7 @@ public class HandoverService extends ServiceImpl<HandoverMapper, Handover> {
         List<WorkAttachmentInfo> workAttachments = reportData.getWorkAttachments();
 
         if (!CollectionUtil.isEmpty(workAttachments)) {
-            List<String> collect = workAttachments.stream().distinct().filter(item -> {
-                if (StringUtils.isNotBlank(item.getId())) {
-                    return true;
-                }
-                return false;
-            }).map(WorkAttachmentInfo::getId).collect(Collectors.toList());
-            if (CollectionUtil.isNotEmpty(workAttachments)) {
-                if(CollectionUtil.isNotEmpty(collect)){
-                    SpringUtil.getBean ( IWorkAttachmentApi.class ).deleteByAttachmentIdNotInIds(reportData.getId(),collect);
-                }
-                workAttachments.stream().forEach(i -> i.setAttachmentId(reportData.getId()));
-                Map<String,String> map = new HashMap<>();
-                map.put("workAttachments",JSON.toJSONString(workAttachments));
-                map.put("currentToken", TokenProvider.getCurrentToken());
-                SpringUtil.getBean ( IWorkAttachmentApi.class ).saveMsg2(map);
-            } else{
-                SpringUtil.getBean ( IWorkAttachmentApi.class ).deleteByAttachmentId(reportData.getId());
-//            ossService.remove(new QueryWrapper<WorkAttachmentInfo>().lambda().eq(WorkAttachmentInfo::getAttachmentId,workClientInfo.getId()));
-            }
+            updateFiles(workAttachments,userDTO,report.getId(),"workClient");
         }
 
         mapper.updateById(report);
@@ -416,6 +399,70 @@ public class HandoverService extends ServiceImpl<HandoverMapper, Handover> {
         return report;
     }
 
+    /**
+     * 修改附件信息
+     * @param list 待修改的附件列表
+     * @param userDTO 当前登录用户
+     * @param id 关联id
+     */
+    public void updateFiles(List<WorkAttachmentInfo> list, UserDTO userDTO, String id, String attachmentFlag) {
+        int j = 1;
+        String names = new String();
+        //表中存在,但是传过来不存在,说明已删除,表中数据也要删除
+        for (WorkAttachmentInfo dto : list) {
+            names = names + "," +dto.getUrl();
+        }
+        //查询保存的附件信息
+        List<WorkAttachmentInfo> infoList = mapper.findListByIdAndAttachmentFlag(id,attachmentFlag);
+        if (CollectionUtils.isNotEmpty(infoList)) {
+            for (WorkAttachmentInfo i : infoList) {
+                if (!names.contains(i.getUrl())) {
+//                    ossServiceMapper.deleteById(i.getId());
+                    SpringUtil.getBean ( IWorkAttachmentApi.class ).deleteById(i.getId());
+                }
+            }
+        }
+        //保存信息
+        for (WorkAttachmentInfo dto : list) {
+            //判断是否存在
+            Integer isExit = mapper.findIsExit(id, dto.getName());
+            if (isExit == 0) {
+                WorkAttachmentInfo i = new WorkAttachmentInfo();
+                //包含了url、size、name
+                i.setId(UUID.randomUUID().toString().replace("-", ""));
+//                i.getCreateBy().setId(userDTO.getId());
+                i.setCreateTime(new Date());
+//                i.getUpdateBy().setId(userDTO.getId());
+                i.setUpdateTime(new Date());
+                i.setDelFlag(0);
+                i.setUrl(dto.getUrl());
+                //文件类型处理
+                String fileName = dto.getName();
+                List<String> strings = Arrays.asList(fileName.split("\\."));
+                // 检查文件名是否有后缀
+                if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
+                    // 获取最后一个部分作为文件类型
+                    i.setType(strings.get(strings.size() - 1));
+                } else {
+                    // 如果没有后缀或文件名无效,设置一个默认类型或空
+                    i.setType("");
+                }
+                i.setAttachmentId(id);
+                i.setAttachmentName(dto.getName());
+                i.setAttachmentFlag(attachmentFlag);
+                i.setFileSize(dto.getSize());
+                i.setSort(j);
+                Map<String,String> map = new HashMap<>();
+                String workAttachment = JSON.toJSONString((i));
+                String userDTOInfo = JSON.toJSONString((userDTO));
+                map.put("workAttachment",workAttachment);
+                map.put("userDTO",userDTOInfo);
+                SpringUtil.getBean ( IWorkAttachmentApi.class ).insertWorkAttachment(map);
+//                ossServiceMapper.insertWorkAttachment(i, userDTO);
+                j++;
+            }
+        }
+    }
 
 
     public String getAssignee(String roleId){
@@ -505,40 +552,58 @@ public class HandoverService extends ServiceImpl<HandoverMapper, Handover> {
         //附件信息处理
         List<WorkAttachmentInfo> workAttachments = reportData.getWorkAttachments();
         if (CollectionUtil.isNotEmpty(workAttachments)) {
-            int j = 1;
-            for (WorkAttachmentInfo i : workAttachments) {
-                i.setId(UUID.randomUUID().toString().replace("-", ""));
-
-                //文件类型处理
-                String fileName = i.getAttachmentName();
-                List<String> strings = Arrays.asList(fileName.split("\\."));
-                // 检查文件名是否有后缀
-                if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
-                    // 获取最后一个部分作为文件类型
-                    i.setType(strings.get(strings.size() - 1));
-                } else {
-                    // 如果没有后缀或文件名无效,设置一个默认类型或空
-                    i.setType("");
-                }
-                i.setDelFlag(0);
-                i.setCreateTime(new Date());
-                i.setUpdateTime(new Date());
-                i.setAttachmentId(reportData.getId());
-                i.setSort(j);
-                Map<String,String> map = new HashMap<>();
-                String workAttachment = JSON.toJSONString((i));
-                String userDTOInfo = JSON.toJSONString((userDTO));
-                map.put("workAttachment",workAttachment);
-                map.put("userDTO",userDTOInfo);
-                SpringUtil.getBean ( IWorkAttachmentApi.class ).insertWorkAttachment(map);
-                j++;
-            }
+            saveFiles(workAttachments,userDTO,report.getId());
         }
 
         return report;
     }
 
     /**
+     * 保存附件信息
+     * @param list 待保存的附件列表
+     * @param userDTO 当前登录用户
+     * @param id 关联id
+     */
+    public void saveFiles(List<WorkAttachmentInfo> list, UserDTO userDTO, String id) {
+        int j = 1;
+        for (WorkAttachmentInfo dto : list) {
+            WorkAttachmentInfo i = new WorkAttachmentInfo();
+            //包含了url、size、name
+            i.setId(UUID.randomUUID().toString().replace("-", ""));
+//            i.getCreateBy().setId(userDTO.getId());
+            i.setCreateTime(new Date());
+//            i.getUpdateBy().setId(userDTO.getId());
+            i.setUpdateTime(new Date());
+            i.setDelFlag(0);
+            i.setUrl(dto.getUrl());
+            //文件类型处理
+            String fileName = dto.getName();
+            List<String> strings = Arrays.asList(fileName.split("\\."));
+            // 检查文件名是否有后缀
+            if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
+                // 获取最后一个部分作为文件类型
+                i.setType(strings.get(strings.size() - 1));
+            } else {
+                // 如果没有后缀或文件名无效,设置一个默认类型或空
+                i.setType("");
+            }
+            i.setAttachmentId(id);
+            i.setAttachmentName(dto.getName());
+            i.setAttachmentFlag("workClient");
+            i.setFileSize(dto.getSize());
+            i.setSort(j);
+//            ossServiceMapper.insertWorkAttachment(i, userDTO);
+            Map<String,String> map = new HashMap<>();
+            String workAttachment = JSON.toJSONString((i));
+            String userDTOInfo = JSON.toJSONString((userDTO));
+            map.put("workAttachment",workAttachment);
+            map.put("userDTO",userDTOInfo);
+            SpringUtil.getBean ( IWorkAttachmentApi.class ).insertWorkAttachment(map);
+            j++;
+        }
+    }
+
+    /**
      * 上传离职证明文件
      * @param wordPath
      * @param report