张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
package com.thhy.pm.modules.biz.technology.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.thhy.general.common.BasicResult;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.pm.modules.biz.file.service.FileService;
import com.thhy.pm.modules.biz.technology.entity.TchFile;
import com.thhy.pm.modules.biz.technology.entity.TchFiles;
import com.thhy.pm.modules.biz.technology.entity.TchFilesListVo;
import com.thhy.pm.modules.biz.technology.mapper.TchFileMapper;
import com.thhy.pm.modules.biz.technology.mapper.TchFilesMapper;
import com.thhy.pm.modules.biz.technology.service.TchFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.Serializable;
import java.util.Date;
import java.util.List;
 
/**
 *  服务实现类
 * @author zhang_xiao_bo
 * @since 2023-04-25 13:06:53
 */
@Service
public class TchFileServiceImpl implements TchFileService {
 
 
 
    @Autowired
    private TchFileMapper tchFileMapper;
 
    @Autowired
    private TchFilesMapper filesMapper;
 
    @Autowired
    private FileService fileService;
 
 
    public TchFile get(Serializable id){
        return tchFileMapper.queryById(id);
    }
 
    public List<TchFile> findList(TchFile tchFile){
        return tchFileMapper.findList(tchFile);
    }
 
    @Override
    public List<TchFilesListVo> fileList(TchFiles tchFiles) {
        List<TchFilesListVo> filesListVos = filesMapper.findList(tchFiles);
        filesListVos.forEach(tf->{
            JSONObject json = new JSONObject();
            json.put("fullpath",tf.getTchFile());
            BasicResult basicResult = fileService.fileinfo(json.toJSONString());
            if(basicResult.isSuccess()){
                JSONArray jsonArray = JSONArray.parseArray(basicResult.getData().toString());
                for(Object obj : jsonArray){
                    JSONObject j = JSON.parseObject(obj.toString());
                    if(j.containsKey("name")&&"name".equals(j.getString("name"))){
                        tf.setTchFileName(j.getString("value"));
                    }
                }
            }
        });
        return filesListVos;
    }
 
    /**
     * 增加和修改
     * @param tchFile
     */
    @Transactional
    public void addTchFile(TchFile tchFile){
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        List<TchFiles> tchFilesList = tchFile.getTchFilesList();
        if(tchFile.getTchFileId() == null){
            //增加操作
            tchFile.setCreateUser(userInfo.getUserId());
            tchFileMapper.insert(tchFile);
        }else{
            //修改操作
            tchFile.setUpdateUser(userInfo.getUserId());
            tchFile.setUpdateTime(new Date());
            tchFileMapper.update(tchFile);
            filesMapper.deleteByTchId(tchFile.getTchFileId());
        }
        for(TchFiles tchFiles : tchFilesList){
            tchFiles.setTchId(tchFile.getTchFileId());
            filesMapper.insert(tchFiles);
        }
 
    }
 
    /**
     * 修改
     * @param tchFile
     */
    public void update(TchFile tchFile){
        tchFileMapper.update(tchFile);
    }
 
    /**
     * 删除
     * @param tchFileId
     */
    public void delete(Serializable tchFileId){
        tchFileMapper.deletelogic(tchFileId);
    }
}