刘光辉
5 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
package jnpf.elnController;
 
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.elnEntity.template.ElnTemplateForms;
import jnpf.elnEntity.template.ElnTemplateVos;
import jnpf.elnService.template.ElnTemplateBindingService;
import jnpf.elnService.template.ElnTemplateCatalogService;
import jnpf.elnService.template.ElnTemplateHealthService;
import jnpf.elnService.template.ElnTemplateStepService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@Tag(name = "ELN模板目录")
@RestController
@RequestMapping("/templateCatalog")
@RequiredArgsConstructor
@SaCheckPermission("dianziJiluMubanGuanli")
public class ElnTemplateCatalogController {
 
    private final ElnTemplateCatalogService catalogService;
    private final ElnTemplateHealthService healthService;
    private final ElnTemplateBindingService bindingService;
    private final ElnTemplateStepService stepService;
 
    @GetMapping
    public ActionResult<PageListVO<ElnTemplateVos.ListItem>> list(ElnTemplateForms.Query query) {
        return pageResult(catalogService.page(query));
    }
 
    @GetMapping("/directory")
    public ActionResult<PageListVO<ElnTemplateVos.CatalogItem>> directory(ElnTemplateForms.Query query) {
        return pageResult(catalogService.directory(query));
    }
 
    private static <T> ActionResult<PageListVO<T>> pageResult(IPage<T> page) {
        PageListVO<T> result = new PageListVO<>();
        result.setList(page.getRecords());
        PaginationVO pagination = new PaginationVO();
        pagination.setCurrentPage(page.getCurrent());
        pagination.setPageSize(page.getSize());
        pagination.setTotal(Math.toIntExact(page.getTotal()));
        result.setPagination(pagination);
        return ActionResult.success(result);
    }
 
    @GetMapping("/{templateId}")
    public ActionResult<ElnTemplateVos.Detail> detail(@PathVariable("templateId") String templateId) {
        return ActionResult.success(catalogService.detail(templateId));
    }
 
    @PostMapping("/{sourceTemplateId}/versions")
    public ActionResult<ElnTemplateVos.Detail> createVersion(
            @PathVariable("sourceTemplateId") String sourceTemplateId,
            @RequestBody ElnTemplateForms.CreateVersion form) {
        return ActionResult.success(catalogService.createVersion(sourceTemplateId, form));
    }
 
    @GetMapping("/{templateId}/health")
    public ActionResult<ElnTemplateHealthService.HealthReport> health(
            @PathVariable("templateId") String templateId) {
        return ActionResult.success(healthService.inspect(templateId));
    }
 
    @GetMapping("/{templateId}/steps")
    public ActionResult<ElnTemplateVos.StepConfiguration> steps(
            @PathVariable("templateId") String templateId) {
        return ActionResult.success(stepService.configuration(templateId));
    }
 
    @PutMapping("/{templateId}/steps")
    public ActionResult<ElnTemplateVos.StepConfiguration> saveSteps(
            @PathVariable("templateId") String templateId,
            @RequestBody ElnTemplateForms.SaveStepConfiguration form) {
        return ActionResult.success(stepService.save(templateId, form));
    }
 
    @PostMapping("/{templateId}/publish")
    public ActionResult<Void> publish(@PathVariable("templateId") String templateId,
                                      @RequestBody ElnTemplateForms.Reason form) {
        catalogService.publish(templateId, reason(form));
        return ActionResult.success();
    }
 
    @PostMapping("/{templateId}/enable")
    public ActionResult<Void> enable(@PathVariable("templateId") String templateId,
                                     @RequestBody ElnTemplateForms.Reason form) {
        catalogService.enable(templateId, reason(form));
        return ActionResult.success();
    }
 
    @PostMapping("/{templateId}/disable")
    public ActionResult<Void> disable(@PathVariable("templateId") String templateId,
                                      @RequestBody ElnTemplateForms.Reason form) {
        catalogService.disable(templateId, reason(form));
        return ActionResult.success();
    }
 
    @PostMapping("/currentVersion")
    public ActionResult<Void> switchCurrent(@RequestBody ElnTemplateForms.SwitchCurrent form) {
        catalogService.switchCurrent(form.getTemplateCode(), form.getTemplateId(), form.getReason());
        return ActionResult.success();
    }
 
    @PostMapping("/bindings/{bindingId}/confirmRemoveMissing")
    public ActionResult<Void> confirmRemoveMissing(
            @PathVariable("bindingId") String bindingId,
            @RequestBody ElnTemplateForms.RemoveMissingConfirm form) {
        bindingService.confirmRemoveMissing(bindingId, form);
        return ActionResult.success();
    }
 
    private static String reason(ElnTemplateForms.Reason form) {
        return form == null || !StringUtils.hasText(form.getReason()) ? null : form.getReason().trim();
    }
}