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);
|
}
|
}
|
}
|