wangting
2025-01-15 5b59d04408cc6602fcb9edd2544f62bef709b8b1
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package com.vci.web.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vci.corba.portal.PortalServicePrx;
import com.vci.corba.portal.data.PLIcon;
import com.vci.dto.PLIconDTO;
import com.vci.pagemodel.PLIconGroupVO;
import com.vci.pagemodel.PLIconVO;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.PageHelper;
import com.vci.web.service.WebIconserviceI;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import edu.stanford.smi.protege.util.HashList;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description 图标服务
 * @Author dangsn
 * @Date 2024/12/20 10:27
 */
@Service
public class WebIconServiceImpl implements WebIconserviceI {
 
    /**
     * 客户端工具
     */
    @Resource
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 导入图标
     *
     * @param type
     * @param groups
     * @param iconFile 图标文件
     * @return 执行结果
     */
    @Override
    public void importIcon(String type, String groups, File iconFile) {
        try {
            String fileContent = FileUtils.readFileToString(iconFile, "UTF-8");
            JSONArray jsonArray = JSON.parseArray(fileContent);
 
            //获取所有的图标信息
            PortalServicePrx portalServicePrx = platformClientUtil.getPortalService();
            PLIcon[] iconArr = portalServicePrx.getAllPLIcon();
            List<String> nameList = new ArrayList<>();
            Map<String, PLIcon> iconMap = new HashMap<>();
            for(PLIcon icon : iconArr){
                nameList.add(icon.name);
                iconMap.put(icon.name, icon);
            }
 
            List<PLIcon> addList = new ArrayList<>();
            List<PLIcon> updateList = new ArrayList<>();
 
            for(int i = 0; i<jsonArray.size(); i++){
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                String iconContent = jsonObject.getString("svg");
                String iconName = jsonObject.getString("name").toLowerCase();
                if(iconContent.contains("<use href")){
                    iconContent = iconContent.replace("svg\"", "svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
                    iconContent = iconContent.replace("<use href","<use xlink:href");
                }
 
                if(nameList.contains(iconName)){
                    PLIcon icon = iconMap.get(iconName);
                    icon.content = iconContent;
                    icon.type = type;
                    icon.groups = groups;
                    icon.plModifyUser = WebUtil.getCurrentUserId();
                    updateList.add(icon);
                }else{
                    PLIcon icon = new PLIcon();
                    icon.oid = WebUtil.getPk();
                    icon.name = iconName;
                    icon.content = iconContent;
                    icon.type = type;
                    icon.groups = groups;
                    icon.plCreateUser = WebUtil.getCurrentUserId();
                    addList.add(icon);
                }
            }
 
            portalServicePrx.batchSavePLIcon(addList.toArray(new PLIcon[0]));
            portalServicePrx.batchUpdatePLIcon(updateList.toArray(new PLIcon[0]));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 新增图标
     *
     * @param iconDTO 图标传输对象
     */
    @Override
    public void addIcon(PLIconDTO iconDTO) {
        WebUtil.alertNotNull(iconDTO.getName(),"图标名称", iconDTO.getContent(),"图标内容");
 
        String iconContent = iconDTO.getContent();
        if(iconContent.contains("<use href")){
            iconContent = iconContent.replace("svg\"", "svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
            iconContent = iconContent.replace("<use href","<use xlink:href");
        }
 
        PLIcon plIcon = new PLIcon();
        plIcon.oid = WebUtil.getPk();
        plIcon.name = iconDTO.getName().toLowerCase();
        plIcon.content = iconContent;
        plIcon.type = iconDTO.getType();
        plIcon.groups = iconDTO.getGroups();
        plIcon.plCreateUser = WebUtil.getCurrentUserId();
        plIcon.plModifyUser = WebUtil.getCurrentUserId();
        try {
            PortalServicePrx portalServicePrx = platformClientUtil.getPortalService();
            portalServicePrx.savePLIcon(plIcon);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 修改图标
     *
     * @param iconDTO 图标传输对象
     */
    @Override
    public void editIcon(PLIconDTO iconDTO) {
        WebUtil.alertNotNull(iconDTO.getName(),"图标名称", iconDTO.getContent(),"图标内容");
        try {
            PortalServicePrx portalServicePrx = platformClientUtil.getPortalService();
            PLIcon plIcon = portalServicePrx.getPLIconByName(iconDTO.getName().toLowerCase());
            if(StringUtils.isBlank(plIcon.oid)){
                throw new VciBaseException("未获取到【"+iconDTO.getName()+"】图标信息!");
            }
 
            String iconContent = iconDTO.getContent();
            if(iconContent.contains("<use href")){
                iconContent = iconContent.replace("svg\"", "svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
                iconContent = iconContent.replace("<use href","<use xlink:href");
            }
 
            plIcon.content = iconContent;
            plIcon.type = iconDTO.getType();
            plIcon.groups = iconDTO.getGroups();
            plIcon.plCreateUser = iconDTO.getPlCreateUser();
            plIcon.plCreateTime = iconDTO.getPlCreateTime();
            plIcon.plModifyUser = WebUtil.getCurrentUserId();
            portalServicePrx.updatePLIcon(plIcon);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 删除图标
     *
     * @param iconDTO 图标传输对象
     */
    @Override
    public void delIcon(PLIconDTO iconDTO) {
        WebUtil.alertNotNull(iconDTO.getOid(),"图标主键", iconDTO.getName(),"图标名称");
        try {
            PortalServicePrx portalServicePrx = platformClientUtil.getPortalService();
            portalServicePrx.deletePLIconByName(iconDTO.getName());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 获取图标名称
     *
     * @return 图标名称
     */
    @Override
    public List<String> getIconName() {
        try {
            PortalServicePrx portalServicePrx = platformClientUtil.getPortalService();
            String[] nameArr = portalServicePrx.getPLIconName();
            return Arrays.asList(nameArr);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * @param baseQueryObject
     * @return
     */
    @Override
    public List<PLIconGroupVO> getAllIcon(BaseQueryObject baseQueryObject) {
        Map<String, String> conditionMap = baseQueryObject.getConditionMap();
        PLIcon plIcon = new PLIcon();
        String iconName = conditionMap.get("name");
        if(StringUtils.isNotBlank(iconName)){
            plIcon.name = iconName.toLowerCase();
        }
        plIcon.type = conditionMap.get("type");
        plIcon.groups = conditionMap.get("groups");
 
        try {
            PortalServicePrx portalServicePrx = platformClientUtil.getPortalService();
            PLIcon[] iconArr = portalServicePrx.getPagePLIcon(plIcon, 0, -1);
 
            List<PLIconGroupVO> groupVOS = new ArrayList<>();
            List<PLIconVO> voList = COS2VOS(Arrays.asList(iconArr));
            Map<String, List<PLIconVO>> voMap = voList.stream().collect(Collectors.groupingBy(PLIconVO::getLable));
            voMap.forEach((key, value)->{
                PLIconGroupVO groupVO = new PLIconGroupVO();
                groupVO.setLable(key);
                groupVO.setList(value);
                groupVOS.add(groupVO);
            });
 
            return groupVOS;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    private List<PLIconVO> COS2VOS(List<PLIcon> iconList){
        List<PLIconVO> voList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(iconList)){
            iconList.forEach(co->{
                voList.add(CO2VO(co));
            });
        }
        return voList;
    }
 
    private PLIconVO CO2VO(PLIcon icon){
        PLIconVO vo = new PLIconVO();
        vo.setOid(icon.oid);
        vo.setName(icon.name);
        vo.setContent(icon.content);
        vo.setType(icon.type);
        vo.setGroups(icon.groups);
        vo.setPlCreateTime(icon.plCreateTime);
        vo.setPlCreateUser(icon.plCreateUser);
        vo.setPlModifyTime(icon.plModifyTime);
        vo.setPlModifyUser(icon.plModifyUser);
        String[] nameArr = icon.name.split(":");
        if(nameArr.length > 1){
            vo.setLable(nameArr[0]);
        }
        return vo;
    }
 
    /**
     * 获取图标表格数据
     *
     * @param baseQueryObject 查询对象
     * @return 图标信息
     */
    @Override
    public DataGrid<PLIconVO> getGrid(BaseQueryObject baseQueryObject) {
        Map<String, String> conditionMap = baseQueryObject.getConditionMap();
        PageHelper pageHelper = baseQueryObject.getPageHelper();
        PLIcon plIcon = new PLIcon();
        String iconName = conditionMap.get("name");
        if(StringUtils.isNotBlank(iconName)){
            plIcon.name = iconName.toLowerCase();
        }
        plIcon.type = conditionMap.get("type");
        plIcon.groups = conditionMap.get("groups");
        try {
            PortalServicePrx portalServicePrx = platformClientUtil.getPortalService();
            PLIcon[] iconArr = portalServicePrx.getPagePLIcon(plIcon, pageHelper.getPage(), pageHelper.getLimit());
            List<PLIconVO> voList = COS2VOS(Arrays.asList(iconArr));
            DataGrid<PLIconVO> dataGrid = new DataGrid<>();
            dataGrid.setData(voList);
 
            long count = portalServicePrx.getCountPLIcon(plIcon);
            dataGrid.setTotal(count);
            return dataGrid;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}