|
@@ -0,0 +1,88 @@
|
|
|
+package com.rf.psychological.structure.rest;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.rf.psychological.base.rest.BaseController;
|
|
|
+import com.rf.psychological.security.AesEncryptUtils;
|
|
|
+import com.rf.psychological.security.SafetyProcess;
|
|
|
+import com.rf.psychological.structure.dao.model.StructureEntity;
|
|
|
+import com.rf.psychological.structure.service.StructureService;
|
|
|
+import com.rf.psychological.utils.Result;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author:zzf
|
|
|
+ * @Date:2024/1/5:09:42
|
|
|
+ * @Description:
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/structure")
|
|
|
+@Api(tags = "组织架构")
|
|
|
+public class StructureController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StructureService service;
|
|
|
+ @ApiOperation(value = "新增/编辑组织架构",notes = "structureNo 组织架构编号;structureName:组织架构名称;parentStructureNo:上级组织架构编号")
|
|
|
+ @PostMapping("/save")
|
|
|
+ @SafetyProcess
|
|
|
+ public Result save(@RequestBody String json) throws Exception {
|
|
|
+ String data = AesEncryptUtils.decrypt(JSONObject.parseObject(json).getString("data"));
|
|
|
+ StructureEntity entity = JSONObject.parseObject(data).toJavaObject(StructureEntity.class);
|
|
|
+ if (StringUtils.isBlank(entity.getStructureNo())){
|
|
|
+ return fail("组织架构编号为空");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(entity.getStructureName())){
|
|
|
+ return fail("组织架构编号为空");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(entity.getParentStructureNo())){
|
|
|
+ entity.setParentStructureNo("0");
|
|
|
+ }
|
|
|
+ entity = this.service.save(entity);
|
|
|
+ return success(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除组织架构")
|
|
|
+ @SafetyProcess
|
|
|
+ @DeleteMapping("delete/{id}")
|
|
|
+ public Result delete(@PathVariable String id ){
|
|
|
+ //TODO 检查组织架构下是否存在用户
|
|
|
+
|
|
|
+ this.service.deleteById(id);
|
|
|
+ return success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询详情")
|
|
|
+ @GetMapping("get/{id}")
|
|
|
+ @SafetyProcess
|
|
|
+ public Result findById(@PathVariable String id){
|
|
|
+ StructureEntity entity = this.service.findById(id);
|
|
|
+ return success(entity);
|
|
|
+ }
|
|
|
+ @ApiOperation(value = "递归查询",notes = "id:组织架构id;includeSelf:是否包含本身;0否 1是")
|
|
|
+ @GetMapping("get/recursion/{id}/{includeSelf}")
|
|
|
+ @SafetyProcess
|
|
|
+ public Result findByIdRecursion(@PathVariable String id,@PathVariable String includeSelf){
|
|
|
+ StructureEntity entity = this.service.findById(id);
|
|
|
+ List<StructureEntity> entitys = new ArrayList<>();
|
|
|
+ if(entity != null){
|
|
|
+ if(includeSelf.equals("1")){
|
|
|
+ entitys.add(entity);
|
|
|
+ }
|
|
|
+ List<StructureEntity> entityList = this.service.findByIdRecursion(entity.getStructureNo());
|
|
|
+ if(entityList != null && entityList.size()>0){
|
|
|
+ entitys.addAll(entityList);
|
|
|
+ }
|
|
|
+ return success(entitys);
|
|
|
+ }
|
|
|
+
|
|
|
+ return fail("未找到");
|
|
|
+ }
|
|
|
+}
|