package com.tuoheng.admin.service.dept;

import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.request.dept.AddDeptRequest;
import com.tuoheng.admin.request.dept.EditDeptRequest;
import com.tuoheng.admin.service.dept.add.AddDeptService;
import com.tuoheng.admin.service.dept.delete.DeleteDeptService;
import com.tuoheng.admin.service.dept.query.QueryChildListService;
import com.tuoheng.admin.service.dept.query.QueryDeptInfoService;
import com.tuoheng.admin.service.dept.query.QueryListTreeByDeptIdService;
import com.tuoheng.admin.service.dept.query.QueryListTreeService;
import com.tuoheng.admin.service.dept.update.UpdateDeptService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 部门业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2022-11-16
 */
@Slf4j
@Service
public class DeptServiceImpl implements IDeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Autowired
    private QueryListTreeService queryListTreeService;

    @Autowired
    private QueryListTreeByDeptIdService queryListTreeByDeptIdService;

    @Autowired
    private QueryChildListService queryChildListService;

    @Autowired
    private QueryDeptInfoService queryDeptInfoService;

    @Autowired
    private AddDeptService addDeptService;

    @Autowired
    private UpdateDeptService updateDeptService;

    @Autowired
    private DeleteDeptService deleteDeptService;

    /**
     * 查询部门树形列表
     *
     * @return 部门
     */
    @Override
    public JsonResult getListTree() {
        return queryListTreeService.getListTree();
    }

    /**
     * 查询当前部门树形列表
     *
     * @return 部门
     */
    @Override
    public JsonResult getListTreeByDeptId(String deptId) {
        return queryListTreeByDeptIdService.getListTree(deptId);
    }

    /**
     * 根据id查询子部门列表
     *
     * @return 部门
     */
    @Override
    public JsonResult getChildList(String id) {
        return queryChildListService.getChildList(id);
    }

    /**
     * 查询部门
     *
     * @param id 部门主键
     * @return 部门
     */
    @Override
    public JsonResult getDeptInfo(String id) {
        return queryDeptInfoService.getDeptInfo(id);
    }

    /**
     * 新增部门
     *
     * @param addDeptRequest 新增部门对象
     * @return 结果
     */
    @Override
    public JsonResult insert(AddDeptRequest addDeptRequest) {
        return addDeptService.add(addDeptRequest);
    }

    /**
     * 修改部门
     *
     * @param oldEditDeptRequest 原部门对象
     * @param newEditDeptRequest 新部门对象
     * @return 结果
     */
    @Override
    public JsonResult update(EditDeptRequest oldEditDeptRequest, EditDeptRequest newEditDeptRequest) {
        return updateDeptService.update(oldEditDeptRequest, newEditDeptRequest);
    }

    /**
     * 删除部门信息
     *
     * @param id 部门主键
     * @return 结果
     */
    @Override
    public JsonResult deleteById(String id) {
        return deleteDeptService.deleteById(id);
    }
}
