package com.zjrs.zwnw.bsdb.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.zwnw.bsdb.bpo.DbsxBPO;
import com.zjrs.zwnw.bsdb.dto.TreeNodeDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api("督办管理_公共接口")
@RestController
@RequestMapping("/api/dbgl/comm")
public class DbglCommController {

    private static final Logger logger = LoggerFactory.getLogger(DbglReportController.class);

    @Resource
    DbsxBPO dbsxBPO;

    /**
     * 查询组织机构
     *
     * @param params 查询条件
     * @return
     */
    @ApiOperation(value = "查询组织机构", notes = "查询组织机构")
    @PostMapping("/member/tree")
    public AjaxResponse queryMemberTree(@RequestBody Map<String, Object> params) {
        logger.info("查询组织机构");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List<TreeNodeDTO> pageResult = dbsxBPO.queryUserTree(params);
            ajaxResponse.setData("data", pageResult);
        } catch (Exception e) {
            logger.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }


    /**
     * 查询组织机构
     *
     * @param params 查询条件
     * @return
     */
    @ApiOperation(value = "查询组织机构", notes = "查询组织机构")
    @PostMapping("/user_org/query")
    public AjaxResponse queryUserOrg(@RequestBody Map<String, Object> params) {
        logger.info("查询组织机构");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List<TreeNodeDTO> pageResult = dbsxBPO.queryUserOrg(params);
            ajaxResponse.setData("data", pageResult);
        } catch (Exception e) {
            logger.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}
