All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.herodotus.stirrup.rest.servlet.upms.controller.hr.SysOrganizationController Maven / Gradle / Ivy

The newest version!
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2020-2030 郑庚伟 ZHENGGENGWEI (码匠君),  Licensed under the AGPL License
 *
 * This file is part of Herodotus Stirrup.
 *
 * Herodotus Stirrup is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Herodotus Stirrup is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */

package cn.herodotus.stirrup.rest.servlet.upms.controller.hr;

import cn.herodotus.stirrup.core.definition.domain.Result;
import cn.herodotus.stirrup.data.crud.service.JpaWriteableService;
import cn.herodotus.stirrup.logic.upms.converter.SysOrganizationToTreeNodeConverter;
import cn.herodotus.stirrup.logic.upms.entity.hr.SysOrganization;
import cn.herodotus.stirrup.logic.upms.enums.OrganizationCategory;
import cn.herodotus.stirrup.logic.upms.service.hr.SysOrganizationService;
import cn.herodotus.stirrup.web.api.servlet.AbstractJpaWriteableController;
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.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.lang3.ObjectUtils;
import org.dromara.hutool.core.tree.MapTree;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 

Description: 单位管理接口

* * @author : gengwei.zheng * @date : 2021/9/21 12:19 */ @RestController @RequestMapping("/hr/organization") @Tag(name = "单位管理接口") @Validated public class SysOrganizationController extends AbstractJpaWriteableController { private final SysOrganizationService sysOrganizationService; public SysOrganizationController(SysOrganizationService sysOrganizationService) { this.sysOrganizationService = sysOrganizationService; } @Override public JpaWriteableService getWriteableService() { return this.sysOrganizationService; } private OrganizationCategory parseOrganizationCategory(Integer category) { if (ObjectUtils.isEmpty(category)) { return null; } else { return OrganizationCategory.get(category); } } private List getSysOrganizations(Integer category) { return sysOrganizationService.findAll(parseOrganizationCategory(category)); } @Operation(summary = "条件分页查询单位", description = "根据动态输入的字段查询单位分页信息", responses = {@ApiResponse(description = "单位列表", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SysOrganization.class)))}) @Parameters({ @Parameter(name = "pageNumber", required = true, description = "当前页码"), @Parameter(name = "pageSize", required = true, description = "每页显示数量"), @Parameter(name = "category", description = "机构分类 (索引数字值)"), }) @GetMapping("/condition") public Result> findByCondition(@NotNull @RequestParam("pageNumber") Integer pageNumber, @NotNull @RequestParam("pageSize") Integer pageSize, @RequestParam(value = "category", required = false) Integer category) { Page pages = sysOrganizationService.findByCondition(pageNumber, pageSize, parseOrganizationCategory(category)); return result(pages); } @Operation(summary = "获取全部单位", description = "获取全部单位数据", responses = {@ApiResponse(description = "单位列表", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SysOrganization.class)))}) @Parameters({ @Parameter(name = "category", description = "机构分类 (索引数字值)"), }) @GetMapping("/list") public Result> findAll(@RequestParam(value = "category", required = false) Integer category) { List sysOrganizations = getSysOrganizations(category); return result(sysOrganizations); } @Operation(summary = "获取单位树", description = "获取全部单位数据,转换为树形结构", responses = {@ApiResponse(description = "单位树", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SysOrganization.class)))}) @Parameters({ @Parameter(name = "category", description = "机构分类 (索引数字值)"), }) @GetMapping("/tree") public Result>> findTree(@RequestParam(value = "category", required = false) Integer category) { List sysOrganizations = getSysOrganizations(category); return result(sysOrganizations, new SysOrganizationToTreeNodeConverter()); } @DeleteMapping("/{id}") @Override public Result delete(@PathVariable String id) { boolean isInUse = sysOrganizationService.isInUse(id); if (isInUse) { return Result.failure("该单位被部分部门引用,请删除关联关系后再删除!"); } else { sysOrganizationService.deleteById(id); return Result.success("删除成功!"); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy