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();
|
}
|
}
|