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
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.common.data.UserEntityInfo;
import com.vci.corba.framework.data.PvolumeInfo;
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.web.service.OsPvolumesServiceI;
import com.vci.web.util.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;
 
/**
 * 文件柜管理的服务实现类
 * @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("修改成功!");
    }
 
    /**
     * 卷 从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;
    }
 
}