package com.mosty.base.controller;

import com.mosty.base.model.dto.base.GetDeptListDTO;
import com.mosty.base.model.dto.base.GetSsbmDto;
import com.mosty.base.model.dto.base.SysDeptDTO;
import com.mosty.base.model.query.base.GetSysDeptListQuery;
import com.mosty.base.model.query.base.SysDeptQuery;
import com.mosty.base.model.vo.base.DeptInfoVo;
import com.mosty.base.service.DeptService;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.core.business.entity.SysDept;
import com.mosty.common.token.JwtSysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @since 2022/8/1
 * 部门数据处理相关
 **/
@Api(tags = "部门数据处理相关")
@RestController
@AllArgsConstructor
@RequestMapping("/deptFeign")
public class DeptController {

    private final DeptService deptService;

    @ApiOperation("根据部门deptid获取所属分县局、所属地市州")
    @JwtSysUser
    @GetMapping("getOrgByDeptId/{deptid}")
    public ResponseResult<DeptInfoVo> getOrgByDeptId(@PathVariable("deptid") String deptid) {
        return ResponseResult.success(this.deptService.getOrgByDeptId(deptid));
    }

    @ApiOperation("根据部门orgcode获取所属分县局、所属地市州")
    @GetMapping("getOrgByOrgcode/{orgcode}")
    public ResponseResult<DeptInfoVo> getOrgByOrgcode(@PathVariable("orgcode") String orgcode) {
        return ResponseResult.success(this.deptService.getOrgByOrgcode(orgcode));
    }

    @ApiOperation("查询所有的部门信息列表")
    @JwtSysUser
    @GetMapping("getDeptAll")
    public ResponseResult<List<DeptInfoVo>> getDeptAll() {
        return ResponseResult.success(this.deptService.getDeptAll());
    }

    @ApiOperation("查询部门下的所有子部门信息,排除一些部门")
    @JwtSysUser
    @PostMapping("getChildDept")
    public ResponseResult<List<DeptInfoVo>> getChildDept(@RequestBody GetDeptListDTO dto) {
        return ResponseResult.success(this.deptService.getChildDept(dto));
    }

    @ApiOperation("查询分局下的所有的派出所信息")
    @PostMapping("getPcsByFxjdm/{orgcode}")
    public ResponseResult<List<SysDeptDTO>> getPcsByFxjdm(@PathVariable("orgcode") String orgcode) {
        return ResponseResult.success(this.deptService.getPcsByFxjdm(orgcode));
    }

    @ApiOperation("获取部门信息")
    @PostMapping("getOrg")
    public ResponseResult<List<SysDept>> getOrg(@RequestBody SysDeptQuery deptQuery) {
        return ResponseResult.success(this.deptService.getOrg(deptQuery));
    }


    @ApiOperation("获取组织机构信息列表")
    @PostMapping("getOrganizationList")
    public ResponseResult<List<SysDept>> getOrganizationList(@RequestBody GetSysDeptListQuery query) {
        return ResponseResult.success(this.deptService.getOrganizationList(query));
    }

    @ApiOperation("重置部门的部门ROOT")
    @PostMapping("resetRootPath")
    public ResponseResult<Void> resetRootPath() {
        this.deptService.resetRootPath();
        return ResponseResult.success();
    }

//     @ApiOperation("获取查询条件")
//    @PostMapping("getSsbm/{ssbmdm}/{isChild}")
//    public ResponseResult<String> getSsbm(@PathVariable("ssbmdm") String ssbmdm,
//                                          @PathVariable("isChild") String isChild) {
//        return ResponseResult.success("成功", this.deptService.getSsbm(ssbmdm, isChild));
//    }


    @ApiOperation("获取查询条件")
    @PostMapping("getSsbm")
    @JwtSysUser
    public ResponseResult<String> getSsbm(@RequestBody GetSsbmDto dto) {
        return ResponseResult.success("成功", this.deptService.getSsbm(dto.getSsbmdm(), dto.getIsChild()));
    }


    @ApiOperation("根据类型查询所有的部门")
    @GetMapping("getDeptByType")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型 01.市局 02.县局 03.派出所", required = true)
    })
    public ResponseResult<List<SysDept>> getJzOrPcs(String type, String ssbmdm) {
        return ResponseResult.success(this.deptService.getDeptByType(type, ssbmdm));
    }

    @ApiOperation("查询父级部门")
    @GetMapping("getParentOrgCode")
    @JwtSysUser
    public ResponseResult<List<String>> getParentOrgCode(String ssbmdm) {
        return ResponseResult.success(this.deptService.getParentOrgCode(ssbmdm));
    }

    @ApiOperation("查询父级部门")
    @GetMapping("/getParentDept")
    ResponseResult<SysDept> getParentDept(String ssbmid) {
        return ResponseResult.success(this.deptService.getParentDept(ssbmid));
    }

    @ApiOperation("查询部门详情")
    @GetMapping("/getSysDeptBySsbmdm")
    ResponseResult<SysDept> getSysDeptBySsbmdm(String ssbmdm) {
        return ResponseResult.success(this.deptService.getSysDeptBySsbmdm(ssbmdm));
    }

    @ApiOperation("同步组织机构部门")
    @GetMapping("/tbZjjgDm")
    public ResponseResult<Void> tbZjjgDm() {
        this.deptService.tbZjjgDm();
        return ResponseResult.success();
    }

    @ApiOperation("同步组织机构人员")
    @GetMapping("/tbZzjgRy")
    public ResponseResult<Void> tbZzjgRy() {
        this.deptService.tbZzjgRy();
        return ResponseResult.success();
    }
}
