ny
23 小时以前 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package jnpf.portal.controller;
 
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jnpf.base.ActionResult;
import jnpf.base.SystemApi;
import jnpf.base.controller.SuperController;
import jnpf.base.entity.SystemEntity;
import jnpf.base.model.VisualFunctionModel;
import jnpf.base.model.base.SystemListVO;
import jnpf.base.vo.DownloadVO;
import jnpf.base.vo.ListVO;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.constant.FileTypeConstant;
import jnpf.constant.MsgCode;
import jnpf.emnus.ExportModelTypeEnum;
import jnpf.emnus.ModuleTypeEnum;
import jnpf.file.FileApi;
import jnpf.model.ExportModel;
import jnpf.portal.PortalApi;
import jnpf.portal.entity.PortalEntity;
import jnpf.portal.model.*;
import jnpf.portal.service.PortalDataService;
import jnpf.portal.service.PortalService;
import jnpf.util.*;
import jnpf.util.context.RequestContext;
import jnpf.util.treeutil.SumTree;
import jnpf.util.treeutil.newtreeutil.TreeDotUtils2;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.*;
 
/**
 * 可视化门户
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2019年9月27日 上午9:18
 */
@Slf4j
@RestController
@Tag(name = "可视化门户", description = "Portal")
@RequestMapping("/Portal")
public class PortalController extends SuperController<PortalService, PortalEntity> implements PortalApi {
 
    @Autowired
    private PortalService portalService;
    @Autowired
    private FileApi fileApi;
    @Autowired
    private PortalDataService portalDataService;
    @Autowired
    private SystemApi systemService;
 
 
    @Operation(summary = "门户列表")
    @GetMapping
    @SaCheckPermission("onlineDev.visualPortal")
    public ActionResult list(PortalPagination portalPagination) {
        SystemEntity systemEntity = systemService.getInfoByEnCode(RequestContext.getAppCode());
        portalPagination.setSystemId(systemEntity.getId());
        List<VisualFunctionModel> modelAll = portalService.getModelList(portalPagination);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(portalPagination, PaginationVO.class);
        return ActionResult.page(modelAll, paginationVO);
    }
 
    @Operation(summary = "门户树形列表")
    @Parameters({
            @Parameter(name = "type", description = "类型:0-门户设计,1-配置路径"),
    })
    @GetMapping("/Selector")
    public ActionResult<ListVO<PortalSelectVO>> listSelect(String platform, String type) {
        List<PortalSelectModel> modelList = new ArrayList<>();
        modelList.addAll(portalService.getModSelectList());
        List<SumTree<PortalSelectModel>> sumTrees = TreeDotUtils2.convertListToTreeDot(modelList);
        List<PortalSelectVO> jsonToList = JsonUtil.getJsonToList(sumTrees, PortalSelectVO.class);
        return ActionResult.success(new ListVO<>(jsonToList));
    }
 
    @Operation(summary = "门户菜单下拉(切换门户)")
    @GetMapping("/Selector/Menu")
    public ActionResult<ListVO<PortalListVO>> selectorMenu() {
        return ActionResult.success(new ListVO<>(portalDataService.selectorMenu()));
    }
 
    @Operation(summary = "门户详情")
    @Parameters({
            @Parameter(name = "id", description = "主键"),
    })
    @GetMapping("/{id}")
    public ActionResult<PortalInfoVO> info(@PathVariable("id") String id, String platform) throws Exception {
        StpUtil.checkPermissionOr("onlineDev.visualPortal", id);
        PortalEntity entity = portalService.getInfo(id);
        if (entity == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        PortalInfoVO vo = JsonUtil.getJsonToBean(JsonUtilEx.getObjectToStringDateFormat(entity, "yyyy-MM-dd HH:mm:ss"), PortalInfoVO.class);
        vo.setFormData(portalDataService.getModelDataForm(new PortalModPrimary(id)));
        //获取发布信息
        VisualFunctionModel releaseInfo = portalService.getReleaseInfo(entity.getId());
        vo.setPcPortalIsRelease(releaseInfo.getPcPortalIsRelease());
        vo.setPcPortalReleaseName(releaseInfo.getPcPortalReleaseName());
        vo.setAppPortalIsRelease(releaseInfo.getAppPortalIsRelease());
        vo.setAppPortalReleaseName(releaseInfo.getAppPortalReleaseName());
        vo.setPcIsRelease(releaseInfo.getPcIsRelease());
        vo.setPcReleaseName(releaseInfo.getPcReleaseName());
        vo.setAppIsRelease(releaseInfo.getAppIsRelease());
        vo.setAppReleaseName(releaseInfo.getAppReleaseName());
        vo.setPlatformRelease(entity.getPlatformRelease());
        return ActionResult.success(vo);
    }
 
    @Operation(summary = "删除门户")
    @Parameters({
            @Parameter(name = "id", description = "主键"),
    })
    @DeleteMapping("/{id}")
    @SaCheckPermission("onlineDev.visualPortal")
    @DSTransactional
    public ActionResult<String> delete(@PathVariable("id") String id) {
        PortalEntity entity = portalService.getInfo(id);
        if (entity != null) {
            try {
                portalService.delete(entity);
            } catch (Exception e) {
                return ActionResult.fail(e.getMessage());
            }
        }
        return ActionResult.success(MsgCode.SU003.get());
    }
 
    @Operation(summary = "创建门户")
    @PostMapping()
    @SaCheckPermission("onlineDev.visualPortal")
    @DSTransactional
    public ActionResult<String> create(@RequestBody @Valid PortalCrForm portalCrForm) throws Exception {
        SystemEntity systemEntity = systemService.getInfoByEnCode(RequestContext.getAppCode());
        PortalEntity entity = JsonUtil.getJsonToBean(portalCrForm, PortalEntity.class);
        entity.setSystemId(systemEntity.getId());
        //判断名称是否重复
        if (portalService.isExistByFullName(entity.getFullName(), null, systemEntity.getId())) {
            return ActionResult.fail(MsgCode.EXIST001.get());
        }
        //判断编码是否重复
        if (StringUtil.isNotEmpty(entity.getEnCode())) {
            if (portalService.isExistByEnCode(entity.getEnCode(), null)) {
                return ActionResult.fail(MsgCode.EXIST002.get());
            }
        }
        // 修改模板排版数据
        if (Objects.equals(entity.getType(), 1)) {
            entity.setEnabledLock(null);
        }
        // 修改模板排版数据
        portalService.create(entity);
        portalDataService.createOrUpdate(new PortalModPrimary(entity.getId()), portalCrForm.getFormData());
        return ActionResult.success(MsgCode.SU001.get(), entity.getId());
    }
 
    @Operation(summary = "复制功能")
    @Parameters({
            @Parameter(name = "id", description = "主键"),
    })
    @PostMapping("/{id}/Actions/Copy")
    @SaCheckPermission("onlineDev.visualPortal")
    public ActionResult copyInfo(@PathVariable("id") String id) throws Exception {
        PortalEntity entity = portalService.getInfo(id);
        entity.setEnabledMark(0);
        String copyNum = UUID.randomUUID().toString().substring(0, 5);
        entity.setFullName(entity.getFullName() + ".副本" + copyNum);
        entity.setLastModifyTime(null);
        entity.setLastModifyUserId(null);
        entity.setId(RandomUtil.uuId());
        entity.setEnCode(entity.getEnCode() + copyNum);
        entity.setCreatorTime(new Date());
        entity.setCreatorUserId(UserProvider.getUser().getUserId());
        PortalEntity entity1 = JsonUtil.getJsonToBean(entity, PortalEntity.class);
        if (entity1.getEnCode().length() > 50 || entity1.getFullName().length() > 50) {
            return ActionResult.fail(MsgCode.PRI006.get());
        }
        portalService.create(entity1);
        portalDataService.createOrUpdate(new PortalModPrimary(entity1.getId()),
                portalDataService.getModelDataForm(new PortalModPrimary(id)));
        return ActionResult.success(MsgCode.SU007.get());
    }
 
    @Operation(summary = "修改门户")
    @Parameters({
            @Parameter(name = "id", description = "主键"),
    })
    @PutMapping("/{id}")
    @SaCheckPermission("onlineDev.visualPortal")
    @DSTransactional
    public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid PortalUpForm portalUpForm) throws Exception {
        PortalEntity originEntity = portalService.getInfo(portalUpForm.getId());
        if (originEntity == null) {
            ActionResult.fail(MsgCode.FA002.get());
        }
        //判断名称是否重复
        if (!originEntity.getFullName().equals(portalUpForm.getFullName()) && StringUtil.isNotEmpty(portalUpForm.getFullName())) {
            if (portalService.isExistByFullName(portalUpForm.getFullName(), portalUpForm.getId(), originEntity.getId())) {
                return ActionResult.fail(MsgCode.EXIST001.get());
            }
        }
        //判断编码是否重复
        if (!originEntity.getEnCode().equals(portalUpForm.getEnCode()) && StringUtil.isNotEmpty(portalUpForm.getEnCode())) {
            if (portalService.isExistByEnCode(portalUpForm.getEnCode(), portalUpForm.getId())) {
                return ActionResult.fail(MsgCode.EXIST002.get());
            }
        }
        // 修改排版数据
        if (Objects.equals(portalUpForm.getType(), 1)) {
            portalUpForm.setEnabledLock(null);
        }
        //修改状态
        if (Objects.equals(originEntity.getState(), 1)) {
            originEntity.setState(2);
            portalUpForm.setState(2);
        }
        // 修改排版数据
        portalDataService.createOrUpdate(new PortalModPrimary(portalUpForm.getId()), portalUpForm.getFormData());
        portalService.update(id, JsonUtil.getJsonToBean(portalUpForm, PortalEntity.class));
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    @Operation(summary = "门户导出")
    @Parameters({
            @Parameter(name = "modelId", description = "模板id"),
    })
    @PostMapping("/{modelId}/Actions/Export")
    @SaCheckPermission("onlineDev.visualPortal")
    public ActionResult exportFunction(@PathVariable("modelId") String modelId) throws Exception {
        PortalEntity entity = portalService.getInfo(modelId);
        if (entity != null) {
            PortalExportDataVo vo = new PortalExportDataVo();
            BeanUtils.copyProperties(entity, vo);
            vo.setId(entity.getId());
            vo.setModelType(ExportModelTypeEnum.Portal.getMessage());
            vo.setFormData(portalDataService.getModelDataForm(new PortalModPrimary(entity.getId())));
            DownloadVO downloadVO = fileApi.exportFile(new ExportModel(vo, FileTypeConstant.TEMPORARY, UserProvider.getToken(), entity.getFullName(), ModuleTypeEnum.VISUAL_PORTAL.getTableName()));
            return ActionResult.success(downloadVO);
        } else {
            return ActionResult.success(MsgCode.FA001.get());
        }
    }
 
    @SneakyThrows
    @Operation(summary = "门户导入")
    @Parameters({
            @Parameter(name = "file", description = "导入文件"),
    })
    @PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @SaCheckPermission("onlineDev.visualPortal")
    public ActionResult importFunction(@RequestPart("file") MultipartFile multipartFile, @RequestParam("type") Integer type) throws Exception {
        SystemEntity sysInfo = systemService.getInfoByEnCode(RequestContext.getAppCode());
        if (sysInfo == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        //判断是否为.json结尾
        if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.VISUAL_PORTAL.getTableName())) {
            return ActionResult.fail(MsgCode.IMP002.get());
        }
        //获取文件内容
        String fileContent = FileUtil.getFileContent(multipartFile);
        PortalExportDataVo vo = JsonUtil.getJsonToBean(fileContent, PortalExportDataVo.class);
        if (vo.getModelType() == null || !vo.getModelType().equals(ExportModelTypeEnum.Portal.getMessage())) {
            return ActionResult.fail(MsgCode.VS410.get());
        }
 
        PortalEntity entity = JsonUtil.getJsonToBean(fileContent, PortalEntity.class);
        if (!sysInfo.getId().equals(entity.getSystemId())) {
            entity.setId(RandomUtil.uuId());
            portalService.setAutoEnCode(entity);
            entity.setSystemId(sysInfo.getId());
        }
        StringJoiner errList = new StringJoiner("、");
        String copyNum = UUID.randomUUID().toString().substring(0, 5);
        if (portalService.getInfo(entity.getId()) != null) {
            if (Objects.equals(type, 0)) {
                errList.add("ID");
            } else {
                entity.setId(null);
            }
        }
        //判断编码是否重复
        if (portalService.isExistByEnCode(entity.getEnCode(), null)) {
            if (Objects.equals(type, 0)) {
                errList.add(MsgCode.IMP009.get());
            } else {
                entity.setEnCode(entity.getEnCode() + copyNum);
            }
        }
        //判断名称是否重复
        if (portalService.isExistByFullName(entity.getFullName(), null, entity.getSystemId())) {
            if (Objects.equals(type, 0)) {
                errList.add(MsgCode.IMP008.get());
            } else {
                entity.setFullName(entity.getFullName() + ".副本" + copyNum);
            }
        }
 
        if (Objects.equals(type, 0) && errList.length() > 0) {
            return ActionResult.fail(errList + MsgCode.IMP007.get());
        }
        if (null != entity.getId()) {
            portalService.setIgnoreLogicDelete().removeById(entity.getId());
            portalService.clearIgnoreLogicDelete();
        }
        entity.setEnabledMark(0);
        entity.setSortCode(0l);
        entity.setCreatorTime(new Date());
        entity.setCreatorUserId(UserProvider.getUser().getUserId());
        entity.setLastModifyTime(null);
        entity.setLastModifyUserId(null);
        portalService.create(entity);
        portalDataService.createOrUpdate(new PortalModPrimary(entity.getId()), vo.getFormData());
        return ActionResult.success(MsgCode.IMP001.get());
    }
 
    @Operation(summary = "门户获取系统下拉")
    @GetMapping("/systemFilter/{id}")
    public ActionResult<ListVO<SystemListVO>> systemFilterList(@PathVariable("id") String id, String category) {
        List<SystemListVO> systemListVOS = portalService.systemFilterList(id, category);
        return ActionResult.success(new ListVO<>(systemListVOS));
    }
 
    @Override
    @PostMapping("/getCurrentDefault")
    public String getCurrentDefault(@RequestBody DefaultModel model) {
        return portalDataService.getCurrentDefault(model.getAuthPortalIds(), model.getSystemId(), model.getUserId(), model.getPlatform());
    }
}