package com.vci.web.service.impl;
|
|
import cn.hutool.core.io.FileUtil;
|
import com.vci.constant.FrameWorkLangCodeConstant;
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.portal.data.Constraint;
|
import com.vci.corba.portal.data.PLAction;
|
import com.vci.corba.portal.data.PLActionCls;
|
import com.vci.corba.portal.data.PLActionParam;
|
import com.vci.dto.*;
|
import com.vci.starter.poi.bo.WriteExcelData;
|
import com.vci.starter.poi.bo.WriteExcelOption;
|
import com.vci.starter.poi.util.ExcelUtil;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.BaseResult;
|
import com.vci.starter.web.util.ControllerUtil;
|
import com.vci.starter.web.util.LangBaseUtil;
|
import com.vci.starter.web.util.LocalFileUtil;
|
import com.vci.web.enumpck.ActionEnum;
|
import com.vci.web.enumpck.PlTypetypeEnum;
|
import com.vci.web.other.ExportActionLogBean;
|
import com.vci.web.other.ExportBeans;
|
import com.vci.web.service.OsActionServiceI;
|
import com.vci.starter.web.util.Lcm.Func;
|
import com.vci.web.util.PinyinCommon;
|
import com.vci.web.util.PlatformClientUtil;
|
import com.vci.web.util.WebUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.*;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* Action管理的服务实现类
|
* @author yuxc
|
* @date 2024-8-16
|
*/
|
@Service
|
public class OsActionServiceImpl implements OsActionServiceI {
|
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
/**
|
* 保存Action分类信息
|
* @param pLActionCls Action分类信息
|
* @return 保存结果
|
*/
|
@Override
|
public BaseResult saveActionCls(PLActionClsDTO pLActionCls) throws PLException {
|
|
if (pLActionCls.getName() == null || pLActionCls.getName().trim().equals("")) {
|
throw new PLException("500", new String[]{"分类名称不能为空!"});
|
}
|
if (pLActionCls.getName().equals("未分类")) {
|
throw new PLException("500", new String[]{"未分类节点已经存在!"});
|
}
|
PLActionCls pac = new PLActionCls();
|
pac.id = WebUtil.getSnowflakePk();
|
pac.name = pLActionCls.getName();
|
pac.pid = pLActionCls.getPid();
|
pac.description = pLActionCls.getDescription() == null ? "" : pLActionCls.getDescription();
|
pac.creator = WebUtil.getCurrentUserId();
|
pac.createTime = System.currentTimeMillis();
|
pac.serialno = pLActionCls.getSerialno();
|
// 保存分类信息
|
String message = platformClientUtil.getUIService().creaetePLActionCls(pac);
|
if (message.startsWith("0")) {
|
if (message.equals("01")) {
|
message = "分类" + pac.name + "已经存在!";
|
} else if (message.equals("02")) {
|
message = "同一分类下序号不能重复!";
|
} else {
|
message = "保存分类时发生异常!" + message.substring(1);
|
}
|
throw new PLException("500", new String[]{message});
|
}
|
return BaseResult.success("分类创建成功!");
|
}
|
|
/**
|
* 修改Action分类信息
|
* @param pLActionCls Action分类信息
|
* @return 保存结果
|
*/
|
@Override
|
public BaseResult updateActionCls(PLActionClsDTO pLActionCls) throws PLException {
|
|
if (pLActionCls.getName() == null || pLActionCls.getName().trim().equals("")) {
|
throw new PLException("500", new String[]{"分类名称不能为空!"});
|
}
|
if (pLActionCls.getName().equals("未分类")) {
|
throw new PLException("500", new String[]{"未分类节点已经存在!"});
|
}
|
if (pLActionCls.getId() == null || pLActionCls.getId().trim().equals("")) {
|
throw new PLException("500", new String[]{"主键不能为空!"});
|
}
|
PLActionCls pac = new PLActionCls();
|
pac.name = pLActionCls.getName();
|
pac.pid = pLActionCls.getPid();
|
pac.id = pLActionCls.getId();
|
pac.description = pLActionCls.getDescription() == null ? "" : pLActionCls.getDescription();
|
pac.creator = WebUtil.getCurrentUserId();
|
pac.createTime = System.currentTimeMillis();
|
pac.serialno = pLActionCls.getSerialno();
|
// 修改分类信息
|
String message = platformClientUtil.getUIService().editPLActionCls(pac);
|
if (message.startsWith("0")) {
|
if (message.equals("01")) {
|
message = "分类" + pac.name + "已经存在!";
|
} else if (message.equals("02")) {
|
message = "同一分类下序号不能重复!";
|
} else {
|
message = "修改分类时发生异常!" + message.substring(1);
|
}
|
throw new PLException("500", new String[]{message});
|
}
|
return BaseResult.success("分类修改成功!");
|
}
|
|
/**
|
* 获取Action分类树
|
* isExp 是否用户导出 true是,false否
|
* @return 查询结果
|
*/
|
@Override
|
public BaseResult getActionTree(boolean isExp) throws PLException {
|
PLActionCls[] clses = platformClientUtil.getUIService().getPLActionClsArray();
|
PLActionClsDTO treDto = new PLActionClsDTO();
|
treDto.setName("Action分类");
|
treDto.setId("root");
|
Map<String, List<PLActionCls>> allDataMap = Arrays.stream(clses).collect(Collectors.groupingBy(pl -> pl.pid));
|
|
for (PLActionCls cls : clses) {
|
if (StringUtils.isBlank(cls.pid) || cls.pid.equals("root")) {
|
PLActionClsDTO parentDto = new PLActionClsDTO();
|
parentDto.setId(cls.id);
|
parentDto.setName(cls.name);
|
parentDto.setPid("root");
|
parentDto.setDescription(cls.description);
|
parentDto.setCreator(cls.creator);
|
parentDto.setCreateTime(cls.createTime);
|
parentDto.setSerialno(cls.serialno);
|
//这里处理导出树的逻辑
|
if(isExp){
|
Constraint[] consArray = new Constraint[1];
|
consArray[0] = new Constraint("plactioncls", cls.id);
|
PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray);
|
if(parentDto.getChilds().isEmpty() && plActionsByConsArray.length == 0){
|
continue;
|
}
|
for (PLAction plAction : plActionsByConsArray) {
|
PLActionDTO plActionDTO = new PLActionDTO();
|
plActionDTO.setPlName(plAction.plCode + "/" + plAction.plName);
|
plActionDTO.setPlCode(plAction.plCode);
|
plActionDTO.setPlOId(plAction.plOId);
|
parentDto.getActionChilds().add(plActionDTO);
|
}
|
}
|
addClsTreeNode(parentDto, allDataMap, isExp);
|
treDto.getChilds().add(parentDto);
|
}
|
}
|
PLActionClsDTO plac = new PLActionClsDTO();
|
plac.setName("未分类");
|
if(isExp){
|
Constraint[] consArray = new Constraint[1];
|
consArray[0] = new Constraint("plactioncls", "");
|
PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray);
|
for (PLAction plAction : plActionsByConsArray) {
|
PLActionDTO plActionDTO = new PLActionDTO();
|
plActionDTO.setPlName(plAction.plCode + "/" + plAction.plName);
|
plActionDTO.setPlCode(plAction.plCode);
|
plActionDTO.setPlOId(plAction.plOId);
|
plac.getActionChilds().add(plActionDTO);
|
}
|
}
|
treDto.getChilds().add(plac);
|
return BaseResult.success(treDto);
|
}
|
/**
|
* 获取Action表格数据
|
* dto 查询条件
|
* @return 查询结果
|
*/
|
@Override
|
public BaseResult getActionTableData(PLActionQueryDTO dto) throws PLException {
|
Constraint[] consArray ;
|
//这儿要用!=null控制,查询未分类节点的时候传的""
|
if(dto.getPlactioncls() != null){
|
consArray = new Constraint[7];
|
consArray[6] = new Constraint("plactioncls", dto.getPlactioncls().equals("root") ? "": dto.getPlactioncls());
|
}else {
|
consArray = new Constraint[6];
|
}
|
consArray[0] = new Constraint("plcode", dto.getPlcode());
|
consArray[1] = new Constraint("plname", dto.getPlname());
|
consArray[2] = new Constraint("plbsurl", dto.getPlbsurl());
|
consArray[3] = new Constraint("plcsclass", dto.getPlcsclass());
|
consArray[4] = new Constraint("pltypetype", dto.getPltypetype());
|
consArray[5] = new Constraint("pldesc", dto.getPldesc());
|
PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray);
|
Arrays.sort(plActionsByConsArray, new Comparator<PLAction>() {
|
@Override
|
public int compare(PLAction o1, PLAction o2) {
|
String py1 = PinyinCommon.getPingYin(o1.plCode);
|
String py2 = PinyinCommon.getPingYin(o2.plCode);
|
return py1.compareTo(py2);
|
}
|
});
|
return BaseResult.dataList(Arrays.asList(plActionsByConsArray));
|
}
|
/**
|
* 保存Action数据
|
* dto action传输对象
|
* @return 保存结果
|
*/
|
@Override
|
public BaseResult saveAction(PLActionDTO dto) throws PLException {
|
if(StringUtils.isBlank(dto.getPlCode())){
|
throw new PLException("500", new String[]{"请输入编号"});
|
}
|
PLAction[] actionsInDB= platformClientUtil.getUIService().getAllPLAction();
|
for(int i =0;i<actionsInDB.length;i++){
|
if (dto.getPlCode().equals(actionsInDB[i].plCode)) {
|
throw new PLException("500", new String[]{"新建Action编号重复,请重新输入编号"});
|
}
|
}
|
PLAction plAction = new PLAction();
|
plAction.plOId = WebUtil.getSnowflakePk();
|
plAction.plCode = StringUtils.defaultString(dto.getPlCode());
|
plAction.plName = StringUtils.defaultString(dto.getPlName());
|
plAction.plCSClass = StringUtils.defaultString(dto.getPlCSClass());
|
plAction.plBSUrl = StringUtils.defaultString(dto.getPlBSUrl());
|
plAction.plDesc = StringUtils.defaultString(dto.getPlDesc());
|
plAction.plCreateUser = WebUtil.getCurrentUserId();
|
plAction.plModifyUser = WebUtil.getCurrentUserId();
|
plAction.plActionCls = StringUtils.defaultString(dto.getPlActionCls());
|
plAction.plTypeType = StringUtils.defaultString(dto.getPlTypeType());
|
plAction.plImage = StringUtils.defaultString(dto.getPlImage());
|
boolean b = platformClientUtil.getUIService().savePLAction(plAction);
|
if(!b){
|
throw new PLException("500", new String[]{"保存失败!!"});
|
}
|
return BaseResult.success("操作成功!");
|
}
|
/**
|
* 修改Action数据
|
* dto action传输对象
|
* @return 修改结果
|
*/
|
@Override
|
public BaseResult updateAction(PLActionDTO dto) throws PLException {
|
if(StringUtils.isBlank(dto.getPlCode())){
|
throw new PLException("500", new String[]{"编号不能为空"});
|
}
|
PLAction[] actionsInDB= platformClientUtil.getUIService().getAllPLAction();
|
for(int i =0;i<actionsInDB.length;i++){
|
if (dto.getPlCode().equals(actionsInDB[i].plCode) && !dto.getPlOId().equals(actionsInDB[i].plOId)) {
|
throw new PLException("500", new String[]{"修改Action编号重复,请确认编号"});
|
}
|
}
|
PLAction plAction = new PLAction();
|
plAction.plOId = StringUtils.defaultString(dto.getPlOId());
|
plAction.plCode = StringUtils.defaultString(dto.getPlCode());
|
plAction.plName = StringUtils.defaultString(dto.getPlName());
|
plAction.plCSClass = StringUtils.defaultString(dto.getPlCSClass());
|
plAction.plBSUrl = StringUtils.defaultString(dto.getPlBSUrl());
|
plAction.plDesc = StringUtils.defaultString(dto.getPlDesc());
|
plAction.plCreateUser = dto.getPlCreateUser();
|
plAction.plModifyUser = WebUtil.getCurrentUserId();
|
plAction.plActionCls = StringUtils.defaultString(dto.getPlActionCls());
|
plAction.plTypeType = StringUtils.defaultString(dto.getPlTypeType());
|
plAction.plImage = StringUtils.defaultString(dto.getPlImage());
|
boolean b = platformClientUtil.getUIService().updatePLAction(plAction);
|
if(!b){
|
throw new PLException("500", new String[]{"修改失败!!"});
|
}
|
return BaseResult.success("修改成功!");
|
}
|
|
/**
|
* 删除Action数据
|
* dto action传输对象
|
* @return 删除结果
|
*/
|
@Override
|
public BaseResult deleteAction(PLActionDTO dto) throws PLException {
|
PLAction plAction = new PLAction();
|
plAction.plOId = StringUtils.defaultString(dto.getPlOId());
|
plAction.plCode = StringUtils.defaultString(dto.getPlCode());
|
plAction.plName = StringUtils.defaultString(dto.getPlName());
|
plAction.plCSClass = StringUtils.defaultString(dto.getPlCSClass());
|
plAction.plBSUrl = StringUtils.defaultString(dto.getPlBSUrl());
|
plAction.plDesc = StringUtils.defaultString(dto.getPlDesc());
|
plAction.plCreateUser = dto.getPlCreateUser();
|
plAction.plModifyUser = WebUtil.getCurrentUserId();
|
plAction.plActionCls = StringUtils.defaultString(dto.getPlActionCls());
|
plAction.plTypeType = StringUtils.defaultString(dto.getPlTypeType());
|
plAction.plImage = StringUtils.defaultString(dto.getPlImage());
|
boolean b = platformClientUtil.getUIService().deletePLAction(plAction);
|
if(!b){
|
throw new PLException("500", new String[]{"删除失败!!"});
|
}
|
return BaseResult.success("删除成功!");
|
}
|
/**
|
* 导出Action
|
* @return
|
*/
|
@Override
|
public void exportBeans(List<String> actionOid, HttpServletResponse response) throws PLException, IOException {
|
String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
|
String vciqtmfFileName = defaultTempFolder + File.separator + "VCIACTIONMODELFILE" + new Date().getTime() + ".vciamf";
|
HashMap exportBeans = new HashMap<String, Object>();
|
getExportBeans(actionOid, exportBeans);// 获得导出Bean同时,记录log
|
|
ObjectOutputStream vciamfFileStream = null;
|
try {
|
File vciqtmfFile = new File(vciqtmfFileName);
|
vciamfFileStream = new ObjectOutputStream(new FileOutputStream(vciqtmfFile));
|
vciamfFileStream.writeObject(exportBeans);
|
}finally {
|
try {
|
if (vciamfFileStream != null) {
|
vciamfFileStream.flush();
|
vciamfFileStream.close();
|
}
|
} catch (Exception e) {
|
throw new PLException("500",new String[]{"导出流关闭异常!"});
|
}
|
}
|
ControllerUtil.writeFileToResponse(response,vciqtmfFileName);
|
FileUtil.del(defaultTempFolder + File.separator);
|
}
|
|
@Override
|
public BaseResult impData(MultipartFile file) throws IOException, PLException {
|
// 导入的对象
|
ExportBeans exportBeans = null;
|
if (file == null) {
|
return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"});
|
}
|
if (!file.getOriginalFilename().endsWith(".vciamf")) {
|
throw new VciBaseException("仅能上传.vciqtf格式文件,请重新上传!");
|
}
|
HashMap map;
|
try {
|
ObjectInputStream obj = new ObjectInputStream(file.getInputStream());
|
map = (HashMap) obj.readObject();
|
} catch (ClassNotFoundException e) {
|
return BaseResult.fail("导入对象未获取成功!!导入对象版本号不同!");
|
}
|
//最终的持久化
|
ArrayList<PLActionCls> pLActionClsList = new ArrayList<>();
|
// 更换actionId后,可以从此导航中获得原来的id
|
HashMap<String /* newId */, String /* oldId */> actionIdNav = new HashMap<String /* newId */, String /* oldId */>();
|
// 更换actionClsId后,可以从此导航中获得原来的id
|
HashMap<String /* newId */, String /* oldId */> actionClsIdNav = new HashMap<String /* newId */, String /* oldId */>();
|
//保存所有父分类,用id主key
|
HashMap<String/*id*/,PLActionCls> actionClses = new HashMap<String/*id*/,PLActionCls>();
|
// 存储符合条件的PLAction
|
ArrayList<PLAction> optionPLActionList = new ArrayList<>();
|
// 存储符合条件的PLActionCls
|
ArrayList<PLActionCls> optionPLActionClsList = new ArrayList<>();
|
// 库中的所有Action分类对象
|
PLActionCls[] pLActionClses = null;
|
exportBeans = (ExportBeans) map.get("exportBeans");
|
// 添加导入的数据
|
addImportData(exportBeans, pLActionClsList, actionIdNav, actionClsIdNav, optionPLActionClsList, pLActionClses, optionPLActionList);
|
// 将PLActionCls 、PLAction 对应的set集合转换成数组(匹配原addExportTreeNode方法)
|
PLActionCls[] newPLActionClsArray = new PLActionCls[optionPLActionClsList.size()];
|
PLAction[] newPLActionArray = new PLAction[optionPLActionList.size()];
|
optionPLActionClsList.toArray(newPLActionClsArray);
|
optionPLActionList.toArray(newPLActionArray);
|
//清楚分类id
|
actionClses.clear();
|
//保存所有分类id
|
for (int i = 0; i < newPLActionClsArray.length; i++) {
|
actionClses.put(newPLActionClsArray[i].id,newPLActionClsArray[i]);
|
}
|
//保存所有存在action的分类(子分类存在action也保存)
|
HashSet<PLActionCls> pLActionClss =new HashSet<PLActionCls> ();
|
for (int i = 0; i < newPLActionArray.length; i++) {
|
//缓存该分类的所有父分类
|
saveParentCls(newPLActionArray[i].plActionCls,pLActionClss,actionClses);
|
}
|
PLActionCls[] actionClslist = new PLActionCls[pLActionClss.size()];
|
pLActionClss.toArray(actionClslist);
|
PLActionClsDTO treDto = new PLActionClsDTO();
|
treDto.setName("Action分类");
|
|
Map<String, List<PLAction>> plActionMap = Arrays.stream(newPLActionArray).collect(Collectors.groupingBy(e -> e.plActionCls));
|
Map<String, List<PLActionCls>> plActionClsMap = pLActionClss.stream().collect(Collectors.groupingBy(e -> e.pid));
|
Map<String, List<PLActionCls>> allCls = Arrays.stream(platformClientUtil.getUIService().getPLActionClsArray()).collect(Collectors.groupingBy(e -> e.name));
|
// 添加子节点(源树节点)
|
for (Map.Entry<String, PLActionCls> entry : exportBeans.getPLActionClsBeans().entrySet()) {
|
if (StringUtils.isBlank(entry.getValue().pid)) {
|
PLActionClsDTO parentDto = new PLActionClsDTO();
|
parentDto.setId(entry.getValue().id);
|
parentDto.setName(entry.getValue().name);
|
parentDto.setPid(entry.getValue().pid);
|
parentDto.setDescription(entry.getValue().description);
|
parentDto.setCreator(entry.getValue().creator);
|
parentDto.setCreateTime(entry.getValue().createTime);
|
parentDto.setSerialno(entry.getValue().serialno);
|
addExportTreeNode(plActionClsMap, plActionMap, parentDto, allCls, exportBeans);
|
treDto.getChilds().add(parentDto);
|
}
|
}
|
PLActionClsDTO noDto = new PLActionClsDTO();
|
noDto.setName("未分类");
|
if(plActionMap.containsKey("")){
|
for (PLAction plAction : plActionMap.get("")) {
|
PLActionClsDTO childPrentDto = new PLActionClsDTO();
|
if (plAction.plName.endsWith("@#修改$%")) {
|
childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#修改$%", "【修改完成】"));
|
plAction.plName = plAction.plName.replace("@#修改$%", "");
|
platformClientUtil.getUIService().updatePLAction(plAction);
|
}else
|
if (plAction.plName.endsWith("@#存在在未分类中$%")) {
|
childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改完成】"));
|
plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "");
|
platformClientUtil.getUIService().updatePLAction(plAction);
|
// plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改Action并按导入文件创建action分类】");
|
}
|
else {
|
childPrentDto.setName(plAction.plCode + "/" + "【新增完成】");
|
// plAction.plName += "【新增】";
|
platformClientUtil.getUIService().savePLAction(plAction);
|
}
|
dealParam(exportBeans, plAction);
|
childPrentDto.setId(plAction.plOId);
|
childPrentDto.setPid(plAction.plActionCls);
|
noDto.getChilds().add(childPrentDto);
|
}
|
}
|
treDto.getChilds().add(noDto);
|
|
return BaseResult.success(treDto);
|
}
|
/**
|
* 导出Action
|
* @param plActionExpDTO 导出属性设置对象
|
*/
|
@Override
|
public void exportAction(PLActionExpDTO plActionExpDTO, HttpServletResponse response) throws PLException, IOException {
|
String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
|
String excelPath = defaultTempFolder + File.separator + plActionExpDTO.getFileName() + ".xls";
|
try {
|
new File(excelPath).createNewFile();
|
} catch (Throwable e) {
|
throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
|
}
|
isValidPageForamt(plActionExpDTO);
|
//设置列
|
List<WriteExcelData> excelDataList = new ArrayList<>();
|
//设置列头
|
for (int index = 0; index < plActionExpDTO.getColumnName().size(); index++) {
|
excelDataList.add(new WriteExcelData(0,index, plActionExpDTO.getColumnName().get(index)));
|
}
|
PLAction[] allPLAction ;
|
if(plActionExpDTO.getDataType().equals(ActionEnum.EXP_ALL.getValue()) ||
|
plActionExpDTO.getDataType().equals(ActionEnum.EXP_PAGE.getValue())){
|
allPLAction = platformClientUtil.getUIService().getAllPLAction();
|
}else{
|
allPLAction = new PLAction[plActionExpDTO.getChooseDataOid().size()];
|
for (int i = 0; i < plActionExpDTO.getChooseDataOid().size(); i++) {
|
allPLAction[i] = platformClientUtil.getUIService().getPLActionById(plActionExpDTO.getChooseDataOid().get(i));
|
}
|
}
|
if(Func.isEmpty(allPLAction)){
|
excelDataList.add(new WriteExcelData(1,1, "根据属性名称未查询到属性信息,请刷新后尝试重新导出!"));
|
}else{
|
for (int i = 0; i < allPLAction.length; i++) {
|
PLAction action = allPLAction[i];
|
List<String> columnName = plActionExpDTO.getColumnName();
|
for (int index = 0; index < columnName.size(); index++) {
|
switch (columnName.get(index)){
|
case "编号":
|
excelDataList.add(new WriteExcelData(i+1,index, action.plCode));
|
break;
|
case "类路径":
|
excelDataList.add(new WriteExcelData(i+1,index, action.plBSUrl));
|
break;
|
case "链接地址":
|
excelDataList.add(new WriteExcelData(i+1,index, action.plCSClass));
|
break;
|
case "描述":
|
excelDataList.add(new WriteExcelData(i+1,index, action.plDesc));
|
break;
|
case "类型":
|
excelDataList.add(new WriteExcelData(i+1,index, action.plTypeType.equals(PlTypetypeEnum.BUSINESS.getValue()) ?
|
PlTypetypeEnum.BUSINESS.getText() : PlTypetypeEnum.LINK.getText()));
|
break;
|
case "名称":
|
excelDataList.add(new WriteExcelData(i+1,index, action.plName));
|
break;
|
}
|
}
|
}
|
}
|
WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
|
ExcelUtil.writeDataToFile(excelPath, excelOption);
|
ControllerUtil.writeFileToResponse(response,excelPath);
|
FileUtil.del(defaultTempFolder + File.separator);
|
}
|
/**
|
* 保存Action参数数据
|
* dto action传输对象
|
* @return 保存结果
|
*/
|
@Override
|
public BaseResult savePLActionParam(PLActionParamDTO dto) throws PLException {
|
if(dto.getName() == null || dto.getName().equals("")) {
|
throw new PLException("500",new String[]{"参数名称不能为空"});
|
}
|
PLActionParam param = new PLActionParam();
|
param.oid = "";
|
param.name = dto.getName();
|
param.defaultValue = dto.getDefaultValue();
|
param.description = dto.getDescription();
|
param.action = dto.getAction();
|
String message = platformClientUtil.getUIService().createPLActionParam(param);
|
|
if(message.startsWith("0")) {
|
if(message.equals("01")) {
|
throw new PLException("500",new String[]{"参数名已经存在!"});
|
} else {
|
throw new PLException("500",new String[]{"添加按钮参数时发生异常:" + message.substring(1)});
|
}
|
}
|
return BaseResult.success();
|
}
|
|
@Override
|
public BaseResult updatePLActionParam(PLActionParamDTO dto) throws PLException {
|
if(dto.getName() == null || dto.getName().equals("")) {
|
throw new PLException("500",new String[]{"参数名称不能为空"});
|
}
|
PLActionParam param = new PLActionParam();
|
param.oid = dto.getOid();
|
param.name = dto.getName();
|
param.defaultValue = dto.getDefaultValue();
|
param.description = dto.getDescription();
|
param.action = dto.getAction();
|
String message = platformClientUtil.getUIService().editPLActionParam(param);
|
|
if(message.startsWith("0")) {
|
if(message.equals("01")) {
|
throw new PLException("500",new String[]{"参数名已经存在!"});
|
} else {
|
throw new PLException("500",new String[]{"添加按钮参数时发生异常:" + message.substring(1)});
|
}
|
}
|
return BaseResult.success();
|
}
|
/**
|
* 删除Action参数数据
|
* oid 参数主键
|
* @return 保存结果
|
*/
|
@Override
|
public BaseResult deletePLActionParam(String oid) throws PLException {
|
if(StringUtils.isBlank(oid)){
|
throw new PLException("500", new String[]{"参数主键不能为空"});
|
}
|
String message = platformClientUtil.getUIService().deletePLActionParam(oid);
|
if (message.startsWith("0")) {
|
throw new PLException("500", new String[]{"删除按钮参数时发生异常:" + message.substring(1)});
|
}
|
return BaseResult.success();
|
}
|
/**
|
* 查询Action参数列表数据
|
* actionOid 参数主键
|
* @return 保存结果
|
*/
|
@Override
|
public BaseResult getPLActionParam(String actionOid) throws PLException {
|
if (StringUtils.isBlank(actionOid)){
|
throw new PLException("500", new String[]{"Action主键不能为空!"});
|
}
|
PLActionParam[] paramArrays = platformClientUtil.getUIService().getPLActionParamArrayByActionId(actionOid);
|
List<PLActionParamDTO> dtos = new ArrayList<>();
|
for (PLActionParam paramArray : paramArrays) {
|
PLActionParamDTO dto = new PLActionParamDTO();
|
dto.setAction(paramArray.action);
|
dto.setOid(paramArray.oid);
|
dto.setName(paramArray.name);
|
dto.setDescription(paramArray.description);
|
dto.setDefaultValue(paramArray.defaultValue);
|
dtos.add(dto);
|
}
|
return BaseResult.dataList(dtos);
|
}
|
|
/**
|
* 删除分类
|
* @param dto 分类对象
|
* @return 处理结果
|
* @throws PLException
|
*/
|
@Override
|
public BaseResult deleteActionCls(PLActionClsDTO dto) throws PLException {
|
PLActionCls[] clses = platformClientUtil.getUIService().getPLActionClsArray();
|
// 将所有分类父分类保存
|
HashSet<String> clsPids = new HashSet<String>();
|
for (PLActionCls plActionCls : clses) {
|
clsPids.add(plActionCls.pid);
|
}
|
if (dto.getName().equals("未分类")) {
|
throw new PLException("500", new String[]{"未分类不能删除!"});
|
}
|
if (clsPids.contains(dto.getId())) {
|
throw new PLException("500", new String[]{"该分类下存在子分类不能删除!\n请删除此分类下的子分类!"});
|
}
|
// 执行删除操作
|
PLActionCls actionCls = new PLActionCls();
|
actionCls.id = dto.getId();
|
actionCls.name = dto.getName();
|
String message = platformClientUtil.getUIService().deletePLActionCls(actionCls);
|
if (message.startsWith("0")) {
|
throw new PLException("500", new String[]{"删除分类失败!" + message.substring(1)});
|
}
|
return BaseResult.success("分类删除成功!" + message.substring(1));
|
}
|
|
public boolean isValidPageForamt(PLActionExpDTO plActionExpDTO) throws PLException {
|
|
boolean res = false;
|
if(plActionExpDTO.getDataType().equals(ActionEnum.EXP_ALL.getValue()) ||
|
plActionExpDTO.getDataType().equals(ActionEnum.EXP_CHOOSE.getValue())) {
|
res = true;
|
return res;
|
}
|
if(StringUtils.isBlank(plActionExpDTO.getPageNum())){
|
throw new PLException("500", new String[]{"页码不能为空"});
|
} else{
|
int pageCount = 1;//这里固定由于界面没有翻页功能
|
String[] pages = plActionExpDTO.getPageNum().split("-");
|
|
// 用dobule接收输入的数据,防止输入超大值(大于Integer.MAX_VALUE)
|
// 转换成Integer,进行比较,及在提示内容中去掉double类型数据可能会出现的小数点
|
if(pages.length == 1){
|
double pageD = Double.parseDouble(pages[0]);
|
if(pageD > Integer.MAX_VALUE){
|
throw new PLException("500", new String[]{"起始页码 " + String.valueOf(pageD) + " 不得大于 " + Integer.MAX_VALUE});
|
}else{
|
int page = (int)pageD;
|
if(page > pageCount){
|
throw new PLException("500", new String[]{"输入的页码 " + page + " 不得大于总页数 " + pageCount});
|
} else if(page > Integer.MAX_VALUE){
|
throw new PLException("500", new String[]{"输入的页码 " + page + " 不得大于 " + Integer.MAX_VALUE});
|
} else {
|
res = true;
|
}
|
}
|
} else{
|
double pageStartD = Double.parseDouble(pages[0]);
|
double pageEndD = Double.parseDouble(pages[1]);
|
if(pageStartD > Integer.MAX_VALUE){
|
throw new PLException("500", new String[]{"起始页码 " + pageStartD + " 不得大于 " + Integer.MAX_VALUE});
|
} else if(pageEndD > Integer.MAX_VALUE){
|
throw new PLException("500", new String[]{"结束页码 " + pageEndD + " 不得大于 " + Integer.MAX_VALUE});
|
} else{
|
int pageStart = (int)pageStartD;
|
int pageEnd = (int)pageEndD;
|
if(pageStart > pageCount){
|
throw new PLException("500", new String[]{"起始页码 " + pageStart + " 不得大于总页数 " + pageCount});
|
} else if(pageEnd > pageCount){
|
throw new PLException("500", new String[]{"结束页码 " + pageEnd + " 不得大于总页数 " + pageCount});
|
} else if(pageStart > pageEnd){
|
throw new PLException("500", new String[]{"起始页码 " + pageStart + " 不得大于结束页码 " + pageEnd});
|
} else{
|
res = true;
|
}
|
}
|
}
|
}
|
return res;
|
}
|
|
/**
|
* 处理参数列表
|
* @param exportBeans 导入数据集合
|
* @param plAction action对象
|
* @throws PLException
|
*/
|
private void dealParam(ExportBeans exportBeans, PLAction plAction) throws PLException {
|
PLActionParam[] plActionParamArrayByActionId = exportBeans.getPLActionParamArrayByActionId(plAction.plOId);
|
PLActionParam[] paramArray = platformClientUtil.getUIService().getPLActionParamArrayByActionId(plAction.plOId);
|
Map<String, List<PLActionParam>> params = Arrays.stream(paramArray).collect(Collectors.groupingBy(e -> e.oid));
|
if(plActionParamArrayByActionId == null){
|
return;
|
}
|
for (PLActionParam param : plActionParamArrayByActionId) {
|
if(params.containsKey(param)){
|
platformClientUtil.getUIService().editPLActionParam(param);
|
}else {
|
platformClientUtil.getUIService().createPLActionParam(param);
|
}
|
}
|
}
|
|
private void addExportTreeNode(Map<String, List<PLActionCls>> pLActionClses, Map<String, List<PLAction>> plActions,
|
PLActionClsDTO parentDto,Map<String, List<PLActionCls>> allCls, ExportBeans exportBeans) throws PLException {
|
|
//处理当前节点下的action
|
if(plActions.containsKey(parentDto.getId())){
|
for (PLAction plAction : plActions.get(parentDto.getId())) {
|
PLActionClsDTO childPrentDto = new PLActionClsDTO();
|
childPrentDto.setId(plAction.plOId);
|
if (plAction.plName.endsWith("@#修改$%")) {
|
childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#修改$%", "【修改成功】"));
|
// plAction.plName = plAction.plName.replace("@#修改$%", "【修改】");
|
plAction.plName = plAction.plName.replace("@#修改$%", "");
|
platformClientUtil.getUIService().updatePLAction(plAction);
|
}else
|
if (plAction.plName.endsWith("@#存在在未分类中$%")) {
|
childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改Action成功】"));
|
// plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改Action并按导入文件创建action分类】");
|
plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "");
|
platformClientUtil.getUIService().updatePLAction(plAction);
|
}
|
else {
|
childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#新增%", "【新增成功】"));
|
// plAction.plName += "【新增】";
|
platformClientUtil.getUIService().savePLAction(plAction);
|
}
|
dealParam(exportBeans, plAction);
|
childPrentDto.setPid(plAction.plActionCls);
|
parentDto.getChilds().add(childPrentDto);
|
}
|
}
|
if(pLActionClses.containsKey(parentDto.getId())){
|
List<PLActionCls> plActionCls = pLActionClses.get(parentDto.getId());
|
for (PLActionCls plActionCl : plActionCls) {
|
PLActionClsDTO childParentDto = new PLActionClsDTO();
|
childParentDto.setId(plActionCl.id);
|
if(allCls.containsKey(childParentDto.getName())){
|
childParentDto.setName(plActionCl.name);
|
}else {
|
childParentDto.setName(plActionCl.name + "【新增完成】");
|
platformClientUtil.getUIService().creaetePLActionCls(plActionCl);
|
}
|
childParentDto.setPid(plActionCl.pid);
|
childParentDto.setDescription(plActionCl.description);
|
childParentDto.setCreator(plActionCl.creator);
|
childParentDto.setCreateTime(plActionCl.createTime);
|
childParentDto.setSerialno(plActionCl.serialno);
|
addExportTreeNode(pLActionClses, plActions, childParentDto, allCls, exportBeans);
|
parentDto.getChilds().add(childParentDto);
|
}
|
|
}
|
|
}
|
|
|
/**
|
* 保存所有父分类
|
* @param plActionCls
|
* @param pLActionClsList
|
*/
|
private void saveParentCls(String plActionCls, HashSet<PLActionCls> pLActionClsList,
|
HashMap<String/*id*/,PLActionCls> actionClses) {
|
if(actionClses.containsKey(plActionCls)){
|
PLActionCls pCls = actionClses.get(plActionCls);
|
pLActionClsList.add(pCls);
|
saveParentCls(pCls.pid, pLActionClsList, actionClses);
|
}
|
|
}
|
|
private void addImportData(ExportBeans exportBeans, ArrayList<PLActionCls> pLActionClsList, HashMap<String /* newId */,
|
String /* oldId */> actionIdNav,HashMap<String /* newId */, String /* oldId */> actionClsIdNav,
|
ArrayList<PLActionCls> optionPLActionClsList, PLActionCls[] pLActionClses, ArrayList<PLAction> plActionList)
|
throws PLException {
|
HashMap<String, PLAction> pLActionBeans = exportBeans.getPLActions();
|
if (pLActionBeans == null) {
|
throw new VciBaseException("导入对象未获取成功!!");
|
}
|
//数据库中没有存在的数据对象,需要进行保存
|
// ArrayList<PLAction> plActionList = new ArrayList<>();
|
PLAction[] allPLAction = platformClientUtil.getUIService().getAllPLAction();
|
Map<String, PLAction> allPLActionMap = Arrays.stream(allPLAction).collect(Collectors.toMap(e -> e.plOId, e -> e));
|
Set<Map.Entry<String, PLAction>> plActions = pLActionBeans.entrySet();
|
for (Map.Entry<String, PLAction> entry : plActions) {
|
PLAction plAction = entry.getValue();
|
PLAction plActionInDB =allPLActionMap.get(plAction.plOId);
|
|
if (plActionInDB != null) {
|
if( plActionInDB.plActionCls != ""){
|
plAction.plActionCls = plActionInDB.plActionCls;
|
// plAction.plOId = newId;
|
plAction.plName += "@#修改$%";
|
plActionList.add(plAction);
|
continue;
|
}else{
|
plAction.plName += "@#存在在未分类中$%";
|
}
|
|
}
|
// 将该实例acion存入到plActionList中
|
plActionList.add(plAction);
|
|
// 定义list存储当前action到数据库action的路径上的所有PLActionCls对象
|
List<PLActionCls> plActionClsList = new ArrayList<PLActionCls>();
|
// 获得库中的最近的PLActionCls对象
|
String pId = WebUtil.getSnowflakePk();
|
String oId = WebUtil.getSnowflakePk();
|
|
PLActionCls pLActionCls = getParentPLActionClsInDBById(plAction,
|
pId, plActionClsList, actionClsIdNav, exportBeans, optionPLActionClsList, pLActionClses);
|
|
changePLActionOID(plAction, oId, pId, actionIdNav);
|
|
if (plActionClsList.size() == 1) {
|
// 删除"未分类"分类对象
|
PLActionCls plActionCls = plActionClsList.get(plActionClsList
|
.size() - 1);
|
|
if(pLActionCls != null){
|
plAction.plActionCls = pLActionCls.id;
|
if(plActionCls.name.equals("未分类")){
|
plAction.plActionCls = "";
|
}
|
plActionClsList.remove(plActionClsList.size() - 1);
|
}else{
|
if(plActionCls.name.equals("未分类")){
|
plActionClsList.remove(plActionClsList.size() - 1);
|
}else{
|
plActionCls.pid = "";
|
}
|
|
}
|
|
}
|
if (plActionClsList.size() >= 2) {
|
|
PLActionCls plActionCls2 = plActionClsList.get(plActionClsList
|
.size() - 2);
|
PLActionCls plActionCls1 = plActionClsList.get(plActionClsList
|
.size() - 1);
|
if (pLActionCls != null) {
|
// 将导入对象与“库中的最近的PLActionCls对 象”name相同的对象
|
// 的下一个PLActionCls对象父id改为库中“最近”PLActionCls对象id
|
plActionClsList.remove(plActionClsList.size() - 1);
|
plActionCls2.pid = pLActionCls.id;
|
}else{
|
if(plActionCls1.name.equals("未分类")){
|
plActionClsList.remove(plActionClsList.size() - 1);
|
plActionCls2.pid = "";
|
}else{
|
plActionCls1.pid = "";
|
}
|
|
}
|
|
}
|
// 增加到整体list中用来最终持久化
|
pLActionClsList.addAll(plActionClsList);
|
}
|
}
|
|
|
private void changePLActionOID(PLAction plAction, String oId, String pId, HashMap<String /* newId */, String /* oldId */> actionIdNav) {
|
actionIdNav.put(oId, plAction.plOId);
|
plAction.plOId = oId;
|
plAction.plActionCls = pId;
|
}
|
/***
|
* 获得库中的PLActionCls对象,用来嫁接导入来的树
|
*
|
* @param
|
* @param plActionClsList
|
* @return
|
*/
|
private PLActionCls getParentPLActionClsInDBById(Object plActionClsIdObj,
|
String newPLActionClsId, List<PLActionCls> plActionClsList,
|
HashMap<String /* newId */, String /* oldId */> actionClsIdNav,ExportBeans exportBeans,
|
ArrayList<PLActionCls> optionPLActionClsList, PLActionCls[] pLActionClses) {
|
String pId = null;
|
if (plActionClsIdObj instanceof PLAction) {
|
pId = ((PLAction) plActionClsIdObj).plActionCls;
|
if(pId.equals("")){
|
PLActionCls noneCls = new PLActionCls("", "未分类", "", "", "", 0, (short)0);
|
plActionClsList.add(noneCls);
|
return noneCls;
|
}
|
}
|
if (plActionClsIdObj instanceof PLActionCls) {
|
pId = ((PLActionCls) plActionClsIdObj).pid;
|
pId = actionClsIdNav.get(pId);
|
if(pId.equals("")){
|
pId = "null";
|
}
|
|
}
|
|
PLActionCls plActionCls = exportBeans.getPLActionClsBeanById(pId);// 从导入对象中获得父分类
|
|
|
PLActionCls tempPLActionCls = null;
|
if (plActionCls != null) {// plActionCls为空 证明父节点为根节点
|
|
plActionClsList.add(plActionCls);
|
if(optionPLActionClsList.contains(plActionCls)){
|
return plActionCls ;
|
}
|
for (PLActionCls Cls : pLActionClses) {
|
if ((plActionCls.id.equals("") && plActionCls.name.trim()
|
.equals("未分类"))
|
|| plActionCls.name.trim().equals(Cls.name.trim())) {
|
tempPLActionCls = Cls;
|
}
|
}
|
plActionCls.id = newPLActionClsId; // 修改父分类id
|
} else {
|
return null;
|
}
|
|
if (tempPLActionCls == null) {
|
String newClsId = WebUtil.getSnowflakePk();
|
actionClsIdNav.put(newClsId, plActionCls.pid);
|
plActionCls.pid = newClsId;
|
return getParentPLActionClsInDBById(plActionCls, newClsId,
|
plActionClsList, actionClsIdNav, exportBeans, optionPLActionClsList, pLActionClses);
|
}
|
return tempPLActionCls;
|
}
|
|
/**
|
* 处理导出的对象
|
* @param actionOid 界面选择的action列表数据
|
* @param exportBeansMap 导出对象
|
* @return
|
* @throws PLException
|
*/
|
private void getExportBeans(List<String> actionOid, HashMap exportBeansMap) throws PLException {
|
PLActionCls[] plActionClsArray = platformClientUtil.getUIService().getPLActionClsArray();
|
Map<String, PLActionCls> clsMap = Arrays.stream(plActionClsArray).collect(Collectors.toMap(e -> e.id, e -> e));
|
ExportBeans exportBeans = new ExportBeans();
|
for (String oid : actionOid) {
|
PLAction plAction = platformClientUtil.getUIService().getPLActionById(oid);
|
//有父节点则进行处理
|
if(StringUtils.isNotBlank(plAction.plActionCls)){
|
allPLActionClsParent(exportBeans, clsMap.get(plAction.plActionCls), clsMap);
|
}
|
exportBeans.getPLActions().put(plAction.plOId, plAction);
|
PLActionParam[] params = platformClientUtil.getUIService().getPLActionParamArrayByActionId(plAction.plOId);
|
if(params != null && params.length > 0){//如果参数存在
|
for (PLActionParam plActionParam : params) {//添加action参数
|
exportBeans.addPLActionParamBean(plActionParam);
|
}
|
}
|
String category = clsMap.containsKey(plAction.plActionCls) ? clsMap.get(plAction.plActionCls).name : "";
|
exportBeans.setLogBean(new ExportActionLogBean(ExportActionLogBean.RIGHT_STATE,
|
plAction.plCode,plAction.plName,plAction.plCSClass,plAction.plBSUrl,
|
plAction.plTypeType,plAction.plDesc,category));
|
}
|
exportBeansMap.put("exportBeans", exportBeans);
|
}
|
//增加父类数据
|
private void allPLActionClsParent(ExportBeans exportBeans, PLActionCls cls, Map<String, PLActionCls> clsMap) {
|
if(cls.pid != ""){
|
allPLActionClsParent(exportBeans, clsMap.get(cls.pid), clsMap);
|
}
|
exportBeans.addPLActionClsBean(cls);
|
}
|
|
/**
|
* 添加子节点
|
* @param parentDto 父节点对象
|
* @param allDataMap 所有分组对象
|
* @param isExp true为导出功能的树,false为界面分类树
|
*/
|
private void addClsTreeNode(PLActionClsDTO parentDto, Map<String, List<PLActionCls>> allDataMap, Boolean isExp) throws PLException {
|
if(allDataMap.containsKey(parentDto.id)){
|
for (PLActionCls cls : allDataMap.get(parentDto.id)) {
|
PLActionClsDTO childDto = new PLActionClsDTO();
|
childDto.setId(cls.id);
|
childDto.setName(cls.name);
|
childDto.setPid(cls.pid);
|
childDto.setDescription(cls.description);
|
childDto.setCreator(cls.creator);
|
childDto.setCreateTime(cls.createTime);
|
childDto.setSerialno(cls.serialno);
|
if(isExp){
|
Constraint[] consArray = new Constraint[1];
|
consArray[0] = new Constraint("plactioncls", cls.id);
|
PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray);
|
if(parentDto.getChilds().isEmpty() && plActionsByConsArray.length == 0){
|
continue;
|
}
|
for (PLAction plAction : plActionsByConsArray) {
|
PLActionDTO plActionDTO = new PLActionDTO();
|
plActionDTO.setPlName(plAction.plCode + "/" + plAction.plName);
|
plActionDTO.setPlCode(plAction.plCode);
|
plActionDTO.setPlOId(plAction.plOId);
|
parentDto.getActionChilds().add(plActionDTO);
|
}
|
}
|
addClsTreeNode(childDto, allDataMap, isExp);
|
parentDto.getChilds().add(childDto);
|
}
|
}
|
}
|
|
}
|