月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-06-02 dc0d4a7907f3affdbc116288cac24ad4ba05f319
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.lf.server.service.sys;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lf.server.entity.all.BaseEntity;
import com.lf.server.entity.data.FmeLogEntity;
import com.lf.server.entity.sys.AttachEntity;
import com.lf.server.helper.ClassHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.all.BasicMapper;
import com.lf.server.mapper.sys.AttachMapper;
import com.lf.server.service.all.UploadAttachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.lang.reflect.Field;
import java.util.List;
 
/**
 * 附件
 * @author WWW
 */
@Service
public class AttachService implements AttachMapper {
    @Autowired
    AttachMapper attachMapper;
 
    private static String tabs;
 
    @Override
    public Integer selectCount(String name) {
        name = StringHelper.getLikeUpperStr(name);
 
        return attachMapper.selectCount(name);
    }
 
    @Override
    public List<AttachEntity> selectByPage(String name, Integer limit, Integer offset) {
        name = StringHelper.getLikeUpperStr(name);
 
        return attachMapper.selectByPage(name, limit, offset);
    }
 
    @Override
    public List<AttachEntity> selectAll() {
        return attachMapper.selectAll();
    }
 
    @Override
    public AttachEntity selectById(int id) {
        return attachMapper.selectById(id);
    }
 
    @Override
    public AttachEntity selectByGuid(String guid) {
        return attachMapper.selectByGuid(guid);
    }
 
    @Override
    public List<AttachEntity> selectByGuids(List<String> guids) {
        return attachMapper.selectByGuids(guids);
    }
 
    @Override
    public AttachEntity selectByTabAndGuid(String tab, String tabGuid, String guid) {
        return attachMapper.selectByTabAndGuid(tab, tabGuid, guid);
    }
 
    @Override
    public List<AttachEntity> selectByTabGuids(String tab, List<String> guids) {
        return attachMapper.selectByTabGuids(tab, guids);
    }
 
    @Override
    public List<AttachEntity> selectByTab(String tab, String guid) {
        return attachMapper.selectByTab(tab, guid);
    }
 
    @Override
    public Integer insert(AttachEntity entity) {
        return attachMapper.insert(entity);
    }
 
    @Override
    public Integer inserts(List<AttachEntity> list) {
        return attachMapper.inserts(list);
    }
 
    @Override
    public Integer delete(int id) {
        return attachMapper.delete(id);
    }
 
    @Override
    public Integer deletes(List<Integer> ids) {
        return attachMapper.deletes(ids);
    }
 
    @Override
    public Integer update(AttachEntity entity) {
        return attachMapper.update(entity);
    }
 
    @Override
    public Integer updates(List<AttachEntity> list) {
        return attachMapper.updates(list);
    }
 
    @Override
    public List<FmeLogEntity> selectFmeLogs(String tabs) {
        return attachMapper.selectFmeLogs(tabs);
    }
 
    /**
     * 查询FME日志
     */
    public List<FmeLogEntity> selectFmeLogs() {
        if (StringHelper.isEmpty(tabs)) {
            tabs = UploadAttachService.getTabs().replace("'", "");
        }
 
        return attachMapper.selectFmeLogs(tabs);
    }
 
    @Override
    public Integer updateFmeLog(Integer id) {
        return attachMapper.updateFmeLog(id);
    }
 
    @Override
    public Integer insertAttachByMeta(String tab, String tabGuid, String metaName, String dirid) {
        return attachMapper.insertAttachByMeta(tab, tabGuid, metaName, dirid);
    }
 
    /**
     * 同步附件
     */
    public void syncAttaches(FmeLogEntity entity) {
        String tab = entity.getPgNs() + "." + entity.getTcdm();
        String fieldName = UploadAttachService.ATTACH_TABS.get(tab);
 
        List<?> list = selectRowsByParentid(entity.getTcdm().replace("_", ""), entity.getParentid(), fieldName);
        if (null == list || list.isEmpty()) {
            return;
        }
 
        Field field = UploadAttachService.getAnnexField(list.get(0), tab);
        if (null == field) {
            return;
        }
 
        for (Object obj : list) {
            String[] names = UploadAttachService.getNames(UploadAttachService.getAnnexName(obj, field));
            if (null == names || names.length == 0) {
                continue;
            }
 
            BaseEntity be = (BaseEntity) obj;
            String dirid = getDirid(be);
            for (String name : names) {
                if (StringHelper.isEmpty(name)) {
                    continue;
                }
                insertAttachByMeta(tab, be.getEventid(), name.trim(), dirid);
            }
        }
    }
 
    /**
     * 获取目录编码
     */
    private String getDirid(BaseEntity be) {
        if (StringHelper.isEmpty(be.getDirid())) {
            return null;
        }
 
        String dirid = be.getDirid().substring(0, 2);
 
        return StringHelper.getRightLike(dirid);
    }
 
    /**
     * 根据父ID查询记录
     */
    private List<?> selectRowsByParentid(String entity, String parentid, String field) {
        BasicMapper baseMapper = ClassHelper.getBasicMapper(entity);
        if (null == baseMapper) {
            return null;
        }
 
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("parentid", parentid);
        wrapper.apply(field + " is not null");
 
        return baseMapper.selectList(wrapper);
    }
}