package com.cloud.user.controller; import com.cloud.common.constants.GlobalDict; import com.cloud.common.utils.OrgTypeUtil; import com.cloud.model.common.Result; import com.cloud.model.log.LogAnnotation; import com.cloud.model.sys.SysOrganization; import com.cloud.user.constants.UserAbstractLogModule; import com.cloud.user.filter.AuthNoneIgnore; import com.cloud.user.service.SysOrganizationService; import com.cloud.user.vo.SysOrganizationVO; import io.swagger.annotations.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.*; @RequestMapping("/data/api-u/org") @RestController @Api(value = "组织架构接口", description = "组织架构接口 - SysOrganizationController") public class SysOrganizationController { @Autowired private SysOrganizationService orgService; /** * 组织机构添加 * @param org * @return */ @PostMapping("/save") //@LogAnnotation(module =UserAbstractLogModule.ORG_SAVE) /*@PreAuthorize("hasAuthority('sys:org:save')")*/ @ApiOperation(value = "组织机构添加", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "org", value = "SysOrganization组织机构实体", required = true, dataType = "SysOrganization", paramType = "body"), }) public Map save(@RequestBody SysOrganizationVO org) { return orgService.save(org); } /** * 组织机构修改 * @param org * @return */ @PostMapping("/update") @ApiOperation(value = "组织机构修改", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "org", value = "SysOrganization组织机构实体", required = true, dataType = "SysOrganization", paramType = "body"), }) public Result update(@RequestBody SysOrganizationVO org) { int status = orgService.update(org); if(status > 0){ return Result.custom("修改成功!",0,true,null); }else{ return Result.custom("修改失败!",1,false,null); } } /** * 组织机构逻辑删除 * @param params * @return */ @GetMapping("/delete") @ApiOperation(value = "组织机构添加", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "org", value = "组织id", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "id", value = "机构id", required = true, dataType = "String", paramType = "query") }) public Map deleteOrg(@RequestParam Map params){ return orgService.deleteOrg(params); } /** * 查找组织树 */ @GetMapping("/tree") @AuthNoneIgnore @ApiOperation(value = "查找本机构及以下的组织机构,返回树形", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "orgById", value = "组织机构ID", required = true, dataType = "long", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "机构分库ID", required = false, dataType = "long", paramType = "query"), @ApiImplicitParam(name = "type", value = "组织级别", required = false, dataType = "string", paramType = "query") }) public List findOrgTree(@RequestParam Map params){ List all = orgService.findAll(params); Long orgById = Long.parseLong(params.get("orgById").toString()); List list = new ArrayList<>(); List datalist = new ArrayList<>(); setOrgTree(orgById, all, list); for(SysOrganization org:all){ if(org.getId().equals(orgById)){ org.setChild(list); datalist.add(org); } } return datalist; } /** * 遍历循环查找组织树的方法 */ private void setOrgTree(Long parentId, List all, List list) { all.forEach(org -> { if (parentId.equals(org.getParentId())) { list.add(org); List child = new ArrayList<>(); org.setChild(child); setOrgTree(org.getId(), all, child); } }); } @GetMapping("/findUpByType") @ApiOperation(value = "查找上级第一个指定的机构类型", notes = "例如:查找学校", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "要查找的机构类型", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "currentId", value = "指定的机构id,查它之上的机构", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "有值分库查,没值查全部", dataType = "Long", paramType = "query") }) SysOrganization findUpByType(Integer type, Long currentId,Long orgId){ return orgService.findUpByType(type,currentId,orgId); } @GetMapping("/findUpById") @ApiOperation(value = "查找上级第一个指定的机构类型", notes = "例如:查找学校", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "currentId", value = "指定的机构id,查它之上的机构", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "有值分库查,没值查全部", dataType = "Long", paramType = "query") }) SysOrganization findUpById(Long currentId,Long orgId){ return orgService.findUpById(currentId,orgId); } @GetMapping("/findUpByType/feign") @ApiOperation(value = "查找上级第一个指定的机构类型", notes = "例如:查找学校", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "要查找的机构类型", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "currentId", value = "指定的机构id,查它之上的机构", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "有值分库查,没值查全部", dataType = "Long", paramType = "query"), @ApiImplicitParam(name = " access_token", value = "token", dataType = "String", paramType = "query") }) SysOrganization findUpByTypeFeign(Integer type, Long currentId,Long orgId, String access_token){ return orgService.findUpByType(type,currentId,orgId); } @GetMapping("/findDownByType") @ApiOperation(value = "查找下级的指定类型的所有机构", notes = "例如;查找查找学校所有年级,年级所有的班级", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "要查找的机构类型", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "currentId", value = "指定的机构id,查它之下的机构", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "有值分库查,没值查全部", required = true, dataType = "Long", paramType = "query") }) List findDownByType(Integer type, String currentId,String orgId){ Long curId = null,orgid = null; if (currentId == null || "".equals( currentId) || "all".equalsIgnoreCase( currentId) ){ }else { curId = Long.valueOf(currentId); } if (orgId == null || "".equals( orgId) || "all".equalsIgnoreCase( orgId) ){ }else { orgid = Long.valueOf(orgId); } return orgService.findDownByType(type,curId,orgid); } @GetMapping("/findCheckSchool") @ApiOperation(value = "查找学区内的所有学校", notes = "查找学区内的所有学校仅展示id,name,address", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "currentId", value = "学区id", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "searchName", value = "学校名字", required = true, dataType = "String", paramType = "query") }) Map findCheckSchool(@RequestParam Map params){ return orgService.findCheckSchool(params); } @GetMapping("/findHeadquarters") @ApiOperation(value = "查找所有的总部", notes = "", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "currentId", value = "从哪个节点下开始查找", required = true, dataType = "String", paramType = "query"), }) List findHeadquarters(Long currentId){ String type= OrgTypeUtil.getByKey(GlobalDict.ROOT_SCHOOL).getValue(); return orgService.findHeadquarters(currentId,type); } @GetMapping("/findSubOrg") @ApiOperation(value = "查找下级的指定类型的所有子机构", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "headId", value = "总部Id", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "isSelf", value = "返回值是否包括总部", required = true, dataType = "boolean", paramType = "query") }) List findSubOrg(Long headId , boolean isSelf){ String type= OrgTypeUtil.getByKey(GlobalDict.ROOT_SCHOOL).getValue(); return orgService.findSubOrg(headId,isSelf,type); } @GetMapping("/findById") @ApiOperation(value = "通过id查询组织机构列表", notes = "通过id查询组织机构列表", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "总部Id", required = true, dataType = "Long", paramType = "form"), @ApiImplicitParam(name = "orgId", value = "组织机构id", required = false, dataType = "boolean", paramType = "form") }) public SysOrganization findById(Long id , Long orgId){ return orgService.findById(id, orgId); } @GetMapping("/findOrgByDep") @ApiOperation(value = "查找学校以上组织机构的部门", notes = "查找学校以上组织机构的部门", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "currentId", value = "机构id", required = true, dataType = "Long", paramType = "query") }) List findOrgByDep(Long currentId){ Integer type = Integer.parseInt(OrgTypeUtil.getByKey("部门").getValue()); return orgService.findDownByType(type,currentId,null); } @GetMapping("/findOrgIds") @ApiOperation(value = "根据传来的组织id查找它上级的学校学区orgId集合", notes = "根据传来的orgId查找它上级的学校学区orgId集合", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "组织id", required = true, dataType = "Long", paramType = "query") }) public List findOrgIds(@RequestParam Integer id){ List list = orgService.findOrgIds(id); return list; } @GetMapping("/findOrgName") @ApiOperation(value = "根据传来的机构id查找机构名称", notes = "根据传来的机构id查找机构名称", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "组织id", required = true, dataType = "Long", paramType = "query") }) public String findOrgName(@RequestParam Integer id){ return orgService.findOrgName(id); } }