package com.vci.web.service.impl;
|
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.common.data.UserEntityInfo;
|
import com.vci.corba.framework.data.PvolumeInfo;
|
import com.vci.dto.OsPvolumeDTO;
|
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.LangBaseUtil;
|
import com.vci.starter.web.util.LocalFileUtil;
|
import com.vci.starter.web.util.VciBaseUtil;
|
import com.vci.starter.web.util.WebThreadLocalUtil;
|
import com.vci.web.service.OsPvolumesServiceI;
|
import com.vci.starter.web.util.Lcm.Func;
|
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 java.io.File;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 文件柜管理的服务实现类
|
* @author yuxc
|
* @date 2024-10-14
|
*/
|
@Service
|
public class OsPvolumesServiceImpl implements OsPvolumesServiceI {
|
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* 分页查询卷
|
* @param pageSize 第几页
|
* @param pageIndex 页数
|
* @return 分页数据
|
*/
|
@Override
|
public BaseResult getPvolumesPage(short pageSize, short pageIndex) throws PLException {
|
PvolumeInfo[] pvolumesPage = platformClientUtil.getFrameworkService().getPvolumesPage(pageSize, pageIndex);
|
|
List<OsPvolumeDTO> pvs = new ArrayList<>();
|
for (PvolumeInfo pvolumeInfo : pvolumesPage) {
|
OsPvolumeDTO osPvolumeDTO = new OsPvolumeDTO();
|
osPvolumeDTO = tranferCorbaObjToPvolume(pvolumeInfo);
|
pvs.add(osPvolumeDTO);
|
}
|
return BaseResult.dataList(pvs);
|
}
|
|
@Override
|
public BaseResult savePvolume(OsPvolumeDTO dto) throws PLException {
|
PvolumeInfo pvoInfo = new PvolumeInfo();
|
pvoInfo.service = dto.getService();
|
// pvoInfo.id = dto.getId();
|
pvoInfo.name = dto.getName();
|
pvoInfo.host = dto.getHost();
|
pvoInfo.isvalid = dto.isIsvalid();
|
pvoInfo.path = dto.getPath();
|
//卷服务类型,机器类型
|
pvoInfo.type = dto.getType();
|
UserEntityInfo userInfo = new UserEntityInfo();
|
userInfo.setUserName(WebUtil.getCurrentUserId());
|
userInfo.setModules("com.vci.client.framework.systemConfig.volumn.PvolumePanel");
|
if(pvoInfo.isvalid){
|
PvolumeInfo[] allPvolumes = platformClientUtil.getFrameworkService().getAllPvolumes();
|
if(allPvolumes.length > 0){
|
// 将其他卷设置为非首选卷 0
|
platformClientUtil.getFrameworkService().updatePvolumeInvalid(userInfo);
|
}
|
}
|
String id= platformClientUtil.getFrameworkService().savePvolume(pvoInfo, userInfo);
|
if(StringUtils.isBlank(id)){
|
return BaseResult.fail("保存失败!");
|
}
|
return BaseResult.success("保存成功!");
|
}
|
|
@Override
|
public BaseResult updatePvolume(OsPvolumeDTO dto) throws PLException {
|
PvolumeInfo pvoInfo = new PvolumeInfo();
|
pvoInfo.service = StringUtils.isBlank(dto.getService()) ? "" : dto.getService();
|
pvoInfo.id = StringUtils.isBlank(dto.getId()) ? "" : dto.getId();
|
pvoInfo.name = StringUtils.isBlank(dto.getName()) ? "" : dto.getName();
|
pvoInfo.host = StringUtils.isBlank(dto.getHost()) ? "" : dto.getHost();
|
pvoInfo.isvalid = dto.isIsvalid();
|
pvoInfo.path = StringUtils.isBlank(dto.getPath()) ? "" : dto.getPath();
|
//卷服务类型,机器类型
|
pvoInfo.type = dto.getType();
|
|
if(StringUtils.isBlank(pvoInfo.service) || StringUtils.isBlank(pvoInfo.name) || StringUtils.isBlank(pvoInfo.path)){
|
throw new PLException("500", new String[]{"字段服务名、卷名称、卷服务路径不能为空!"});
|
}
|
PvolumeInfo[] allPvo = platformClientUtil.getFrameworkService().getAllPvolumes();
|
Map<String, PvolumeInfo> pvInfoMap = Arrays.stream(allPvo).collect(Collectors.toMap(e -> e.id, e -> e));
|
//如果是要进行修改,名称不变的情况下可以成功修改,这种情况下不是名称重复。
|
if(pvInfoMap.get(pvoInfo.id) == null){
|
throw new PLException("500", new String[]{"未查询到相关数据请重新操作!"});
|
}
|
if ( allPvo.length == 1 && !pvoInfo.isvalid){
|
throw new PLException("500", new String[]{"仅一条数据需设置为首选路径"});
|
}
|
UserEntityInfo userInfo = new UserEntityInfo();
|
userInfo.setUserName(WebUtil.getCurrentUserId());
|
userInfo.setModules("com.vci.client.framework.systemConfig.volumn.PvolumePanel");
|
if(pvoInfo.isvalid && allPvo.length > 0){
|
// 将其他卷设置为非首选卷 0
|
platformClientUtil.getFrameworkService().updatePvolumeInvalid(userInfo);
|
}
|
boolean b = platformClientUtil.getFrameworkService().updatePvolume(pvoInfo, userInfo);
|
if(!b){
|
return BaseResult.fail("修改失败!");
|
}
|
return BaseResult.success("修改成功!");
|
}
|
|
/**
|
* 删除卷
|
* @param ids 主键集合
|
* @return 删除结果
|
*/
|
@Override
|
public BaseResult deletePvolume(String ids) throws PLException {
|
if ( StringUtils.isBlank(ids)){
|
throw new PLException("500", new String[]{"请选择相关数据!!"});
|
}
|
for (String id : ids.split(",")) {
|
boolean isvalid = platformClientUtil.getFrameworkService().checkIsvalid(id);
|
if(isvalid) {
|
throw new PLException("500", new String[]{"选择数据为首选路径,不能删除!"});
|
}
|
}
|
UserEntityInfo userInfo = new UserEntityInfo();
|
userInfo.setUserName(WebUtil.getCurrentUserId());
|
userInfo.setModules("com.vci.client.framework.systemConfig.volumn.PvolumePanel");
|
boolean rs = platformClientUtil.getFrameworkService().deletePvolume(ids.split(","), userInfo);
|
if(!rs){
|
return BaseResult.fail("删除失败!");
|
}
|
return BaseResult.success("删除成功!");
|
}
|
|
/**
|
* 文件柜导出
|
* @param exportFileName 导出的文件名
|
* @param pvolumeIds 导出选中的卷id
|
* @return
|
* @throws PLException
|
*/
|
@Override
|
public String exportPvolumes(String exportFileName, String pvolumeIds) throws PLException {
|
if(Func.isBlank(pvolumeIds)){
|
throw new PLException("500",new String[]{"请勾选要导出的数据!"});
|
}
|
//界面没传名称,使用默认导出名称
|
exportFileName = Func.isBlank(exportFileName) ? "文件柜导出_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
|
//设置列名
|
List<String> columns = new ArrayList<>(Arrays.asList("卷名","机器类型","路径名称","首选路径","服务器","卷服务"));
|
|
//写excel
|
String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls";
|
try {
|
new File(excelPath).createNewFile();
|
} catch (Throwable e) {
|
throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
|
}
|
//设置列
|
List<WriteExcelData> excelDataList = new ArrayList<>();
|
//设置列头
|
for (int index = 0; index < columns.size(); index++) {
|
excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
|
}
|
//按照文件柜ID查询文件柜
|
List<String> pvolumeIdList = Func.toStrList(pvolumeIds);
|
List<PvolumeInfo> pvolumeInfoList = this.getPvolumeInfoByIds(pvolumeIdList);
|
|
if(Func.isEmpty(pvolumeInfoList)){
|
excelDataList.add(new WriteExcelData(1,1, "未获取到要导出的文件柜信息,请刷新后尝试重新导出!"));
|
}else{
|
for (int i = 0; i < pvolumeInfoList.size(); i++) {
|
PvolumeInfo pvolumeInfo = pvolumeInfoList.get(i);
|
excelDataList.add(new WriteExcelData(i+1,0, pvolumeInfo.name));
|
excelDataList.add(new WriteExcelData(i+1,1, pvolumeInfo.type));
|
excelDataList.add(new WriteExcelData(i+1,2, pvolumeInfo.path));
|
excelDataList.add(new WriteExcelData(i+1,3, pvolumeInfo.isvalid));
|
excelDataList.add(new WriteExcelData(i+1,4, pvolumeInfo.host));
|
excelDataList.add(new WriteExcelData(i+1,5, pvolumeInfo.service));
|
}
|
}
|
WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
|
ExcelUtil.writeDataToFile(excelPath, excelOption);
|
return excelPath;
|
}
|
|
/**
|
* 根据卷id查询卷
|
* @param ids
|
* @return
|
*/
|
@Override
|
public List<PvolumeInfo> getPvolumeInfoByIds(List<String> ids) throws PLException {
|
List<PvolumeInfo> pvolumeInfos = new ArrayList<>();
|
if(Func.isEmpty(ids)){
|
return pvolumeInfos;
|
}
|
PvolumeInfo[] allPvolumes = platformClientUtil.getFrameworkService().getAllPvolumes();
|
if (Func.isEmpty(allPvolumes)){
|
return pvolumeInfos;
|
}
|
pvolumeInfos = Arrays.stream(allPvolumes).filter(pvolumeInfo -> ids.contains(pvolumeInfo.id)).collect(Collectors.toList());
|
return pvolumeInfos;
|
}
|
|
/**
|
* 为文件柜分配成员----这个功能现在没用上,平台的保存方法是注释掉的
|
* @param pvolumId
|
* @param userIds
|
* @return
|
*/
|
@Override
|
public boolean savePvolumeUser(String pvolumId ,List<String> userIds) throws PLException {
|
VciBaseUtil.alertNotNull(pvolumId,"文件柜主键",userIds,"用户主键集合");
|
UserEntityInfo userEntityInfo = new UserEntityInfo();
|
userEntityInfo.setUserName(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId());
|
boolean resBoolean = platformClientUtil.getFrameworkService().savePvolumeUser(pvolumId, userIds.toArray(new String[userIds.size()]), userEntityInfo);
|
return resBoolean;
|
}
|
|
/**
|
* 卷 从Corba端转到Hibernate对象端
|
* @param pvoInfo
|
* @return
|
*/
|
private OsPvolumeDTO tranferCorbaObjToPvolume(PvolumeInfo pvoInfo) {
|
OsPvolumeDTO obj = new OsPvolumeDTO();
|
obj.setId(pvoInfo.id);
|
obj.setName(pvoInfo.name);
|
obj.setHost(pvoInfo.host);
|
obj.setService(pvoInfo.service);
|
obj.setType(pvoInfo.type);
|
obj.setPath(pvoInfo.path);
|
obj.setIsvalid(pvoInfo.isvalid);
|
return obj;
|
}
|
|
}
|