Fancy
2025-01-07 28f6317f7189d5c4a7e64f57dd6c7fc2011f8632
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
package com.dy.pmsOther.fileManage;
 
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.daoOth.OthFileMapper;
import com.dy.pmsGlobal.daoOth.OthFileManageMapper;
import com.dy.pmsGlobal.dyFile.FileOperate;
import com.dy.pmsGlobal.dyFile.FileRestVo;
import com.dy.pmsGlobal.pojoOth.OthFile;
import com.dy.pmsGlobal.pojoOth.OthFileManage;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Service
public class FileManageSv {
    private OthFileManageMapper dao;
    private FileOperate fileOperate;
    private OthFileMapper othFileMapper;
    @Value("${dy.webFile.fmUrl}")
    private String fmUrl ;
    @Autowired
    public void setDao(OthFileManageMapper dao) {
        this.dao = dao;
    }
    @Autowired
    public void setFileOperate(FileOperate fileOperate) {
        this.fileOperate = fileOperate;
    }
    @Autowired
    public void setOthFileMapper(OthFileMapper othFileMapper) {
        this.othFileMapper = othFileMapper;
    }
 
 
    public OthFileManage one(Long fileId) {
        OthFileManage uploadFile =dao.selectByPrimaryKey(fileId);
        addUrl(List.of(uploadFile));
        return uploadFile;
    }
    private void addUrl(List<OthFileManage> fileList){
        fileList.forEach(uploadFile -> {
            if(uploadFile != null){
                OthFile othFile = othFileMapper.selectByPrimaryKey(uploadFile.fileId);
                if (othFile != null) {
                    FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, othFile.hash);
                    uploadFile.webUrl = fileRestVo.fileWebDownloadPath + uploadFile.fileId;
                    uploadFile.orgName = othFile.orgName;
                    uploadFile.extName = othFile.extName;
                }
            }
        });
    }
 
    /**
     * 获取列表
     */
    public QueryResultVo<List<OthFileManage>> selectSome(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
 
        //查询符合条件的记录总数
        Long itemTotal = dao.selectSomeCount(params);
 
        QueryResultVo<List<OthFileManage>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ;
        //计算分页等信息
        rsVo.calculateAndSet(itemTotal, params);
 
        //查询符合条件的记录
        rsVo.obj = dao.selectSome(params) ;
        addUrl(rsVo.obj);
        return rsVo ;
    }
 
    @Transactional
    public int save(OthFileManage uploadFile) {
        int count=0;
        if(uploadFile.id==null){
            uploadFile.deleted = false;
            uploadFile.dt = new Date();
            count = dao.insertSelective(uploadFile);
        }else{
            uploadFile.dt = new Date();
            count = dao.updateByPrimaryKeySelective(uploadFile);
        }
        return count;
    }
 
    @Transactional
    public int delete(Long id) {
        int count=0;
        count = dao.deleteLogicById(id);
        return count;
    }
}