package com.engine.organization.wrapper;

import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.organization.entity.job.param.JobMergeParam;
import com.engine.organization.entity.job.param.JobSearchParam;
import com.engine.organization.entity.searchtree.SearchTreeParams;
import com.engine.organization.service.JobService;
import com.engine.organization.service.impl.JobServiceImpl;
import com.engine.organization.util.OrganizationFormItemUtil;
import com.engine.organization.util.response.ReturnResult;
import weaver.hrm.User;

import java.util.*;

/**
 * @description:
 * @author:dxfeng
 * @createTime: 2022/05/27
 * @version: 1.0
 */
public class JobWrapper extends Service {
    private JobService getJobService(User user) {
        return ServiceUtil.getService(JobServiceImpl.class, user);
    }

    /**
     * 左侧树
     *
     * @param params
     * @return
     */
    public Map<String, Object> getSearchTree(SearchTreeParams params) {
        return getJobService(user).getSearchTree(params);
    }

    /**
     * 列表
     *
     * @param param
     * @return
     */
    public Map<String, Object> listPage(JobSearchParam param) {
        return getJobService(user).listPage(param);
    }

    /**
     * 顶部按钮
     *
     * @return
     */
    public Map<String, Object> getHasRight() {
        return getJobService(user).getHasRight();
    }

    /**
     * 搜索条件
     *
     * @return
     */
    public Map<String, Object> getSearchCondition() {
        return getJobService(user).getSearchCondition();
    }

    /**
     * 获取新增表单
     *
     * @return
     */
    public Map<String, Object> getSaveForm() {
        return getJobService(user).getSaveForm();
    }

    /**
     * 获取详细表单
     *
     * @param params
     * @return
     */
    public Map<String, Object> getJobBaseForm(Map<String, Object> params) {
        return getJobService(user).getJobBaseForm(params);

    }

    /**
     * 保存基础信息
     *
     * @param params
     * @return
     */
    public Long saveBaseForm(Map<String, Object> params) {
        return getJobService(user).saveBaseForm(params);
    }

    /**
     * 更新主表、拓展表、明细表
     *
     * @param params
     * @return
     */
    public Long updateForm(Map<String, Object> params) {
        return getJobService(user).updateForm(params);
    }

    /**
     * 复制岗位到指定部门
     *
     * @param ids
     * @param department
     * @return
     */
    public int copyJobItem(String ids, String department) {
        return getJobService(user).copyJobItem(ids, department);
    }

    /**
     * @param params
     * @return
     */
    public int updateForbiddenTagById(JobSearchParam params) {
        return getJobService(user).updateForbiddenTagById(params);
    }

    /**
     * 根据ID批量删除
     *
     * @param ids
     * @return
     */
    public int deleteByIds(Collection<Long> ids) {
        return getJobService(user).deleteByIds(ids);
    }


    /**
     * 获取复制表单
     *
     * @return
     */
    public ReturnResult getCopyForm() {
        List<SearchConditionGroup> addGroups = new ArrayList<>();
        List<SearchConditionItem> condition = new ArrayList<>();
        SearchConditionItem deptBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 3, false, "复制到", "161", "department", "deptBrowser");
        deptBrowserItem.setRules("required|string");
        condition.add(deptBrowserItem);
        addGroups.add(new SearchConditionGroup("", true, condition));
        return ReturnResult.successed(addGroups);
    }

    /**
     * 根据岗位获取人员
     *
     * @param jobId
     * @return
     */
    public ReturnResult getHrmListByJobId(Long jobId) {
        Map<String, Object> hrmListByJobId = getJobService(user).getHrmListByJobId(jobId);
        return ReturnResult.successed(hrmListByJobId);
    }

    public List<SearchConditionGroup> getMergeForm() {
        return getJobService(user).getMergeForm();
    }

    public int mergeJob(JobMergeParam mergeParam) {
        return getJobService(user).mergeJob(mergeParam);
    }
}
