package com.cloud.device.controller;
|
|
import com.cloud.device.constants.Constants;
|
import com.cloud.device.filter.AuthNoneIgnore;
|
import com.cloud.device.model.Device;
|
import com.cloud.device.model.Dic;
|
import com.cloud.device.model.Org;
|
import com.cloud.device.service.DeviceService;
|
import com.cloud.device.service.OrgService;
|
import com.cloud.device.vo.MenuTreeVo;
|
import com.cloud.model.common.Result;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.NamedBean;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.MediaType;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Slf4j
|
@Api(value = "DicController", description = "组织机构管理")
|
@RequestMapping("/data/api-d/org")
|
@RestController
|
public class OrgController {
|
|
@Autowired
|
private OrgService orgService;
|
@Autowired
|
private DeviceService deviceService;
|
|
@ApiOperation(value="保存组织架构",notes = "保存组织架构",httpMethod = "POST",produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "org", value = "组织机构实例", required = true, dataType = "Org", paramType = "body")
|
|
})
|
@RequestMapping("/saveOrg")
|
public Result saveOrg(@RequestBody Org org) {
|
try {
|
log.info("父级id:"+org.getParentId()+",组织名称:"+org.getName());
|
if(org.getId() !=null && org.getId() >0){
|
return Result.ok("保存成功", orgService.updateByIdSelective(org));
|
}else{
|
return Result.ok("添加成功", orgService.insertSelective(org));
|
}
|
}
|
catch (Exception e) {
|
log.error(e.getMessage());
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
|
}
|
|
@GetMapping("/findOrg")
|
@ApiOperation(value = "获取组织树", notes = "获取组织树", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "name", value = "组织名称", required = false, dataType = "String", paramType = "query")
|
})
|
public List<MenuTreeVo> findOrg(@RequestParam String name){
|
List<MenuTreeVo> list = new ArrayList<>();
|
try {
|
return orgService.findOrg(name);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return list;
|
}
|
|
@ApiOperation(value = "删除组织机构", notes = "删除组织机构", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "query")
|
})
|
@RequestMapping("/deleteOrg")
|
public Result deleteOrg(@RequestParam Long id){
|
log.info("删除orgId:"+id);
|
//先判断是否有子组织
|
List<Org> children = orgService.findChildById(id);
|
if(children !=null && children.size() >0){
|
return Result.custom("此组织下有子节点,不允许删除!",401,false,"删除失败!");
|
}
|
List<Device> devices = deviceService.findByOrgId(id);
|
if(devices !=null && devices.size() >0){
|
return Result.custom("此组织下有设备信息,不允许删除!",401,false,"删除失败!");
|
}
|
return Result.ok(Constants.RESULT_DELETE_OK,orgService.deleteById(id));
|
}
|
}
|