package com.engine.organization.wrapper;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.organization.annotation.Log;
import com.engine.organization.entity.postion.param.PostInfoSearchParam;
import com.engine.organization.entity.postion.po.PostInfoPO;
import com.engine.organization.enums.LogModuleNameEnum;
import com.engine.organization.enums.OperateTypeEnum;
import com.engine.organization.mapper.post.PostInfoMapper;
import com.engine.organization.service.PostInfoService;
import com.engine.organization.service.impl.PostInfoServiceImpl;
import com.engine.organization.util.OrganizationWrapper;
import com.engine.organization.util.db.MapperProxyFactory;
import weaver.hrm.User;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author:dxfeng
 * @createTime: 2022/05/13
 * @version: 1.0
 */
public class PostInfoWrapper extends OrganizationWrapper {
    private PostInfoService getPostInfoService(User user) {
        return ServiceUtil.getService(PostInfoServiceImpl.class, user);
    }

    private PostInfoMapper getPostInfoMapper() {
        return MapperProxyFactory.getProxy(PostInfoMapper.class);
    }

    /**
     * 职务信息列表
     *
     * @param params
     * @return
     */
    public Map<String, Object> listPage(Map<String, Object> params) {
        return getPostInfoService(user).listPage(params);
    }

    /**
     * 新增职务信息
     *
     * @param param
     * @return
     */
    @Log(operateType = OperateTypeEnum.ADD, operateModule = LogModuleNameEnum.POSTINFO, operateDesc = "新增职务信息")
    public int savePostInfo(PostInfoSearchParam param) {
        int savePostInfo = getPostInfoService(user).savePostInfo(param);
        writeOperateLog(new Object() {
        }.getClass(), param.getPostInfoName(), JSON.toJSONString(param), "新增职务信息");

        return savePostInfo;
    }

    /**
     * 更新职务信息
     *
     * @param param
     * @return
     */
    @Log(operateType = OperateTypeEnum.UPDATE, operateModule = LogModuleNameEnum.POSTINFO, operateDesc = "更新职务信息")
    public int updatePostInfo(PostInfoSearchParam param) {
        PostInfoPO postInfoByID = getPostInfoMapper().getPostInfoByID(param.getId());
        int updatePostInfo = getPostInfoService(user).updatePostInfo(param);
        writeOperateLog(new Object() {
        }.getClass(), postInfoByID.getPostInfoName(), JSON.toJSONString(param), postInfoByID, getPostInfoMapper().getPostInfoByID(param.getId()));
        return updatePostInfo;
    }

    /**
     * 更新禁用标记
     *
     * @param params
     */
    @Log(operateType = OperateTypeEnum.UPDATE, operateModule = LogModuleNameEnum.POSTINFO, operateDesc = "更新职务信息禁用标识")
    public int updateForbiddenTagById(PostInfoSearchParam params) {
        PostInfoPO postInfoByID = getPostInfoMapper().getPostInfoByID(params.getId());
        int updateForbiddenTagById = getPostInfoService(user).updateForbiddenTagById(params);
        writeOperateLog(new Object() {
        }.getClass(), postInfoByID.getPostInfoName(), JSON.toJSONString(params), postInfoByID, getPostInfoMapper().getPostInfoByID(params.getId()));
        return updateForbiddenTagById;
    }

    /**
     * 根据ID批量删除
     *
     * @param ids
     */
    @Log(operateType = OperateTypeEnum.DELETE, operateModule = LogModuleNameEnum.POSTINFO, operateDesc = "删除职务信息")
    public int deleteByIds(Collection<Long> ids) {
        List<PostInfoPO> postInfoPOS = getPostInfoMapper().getPostInfosByIds(ids);
        int deleteByIds = getPostInfoService(user).deleteByIds(ids);
        for (PostInfoPO postInfoPO : postInfoPOS) {
            writeOperateLog(new Object() {
            }.getClass(), postInfoPO.getPostInfoName(), JSON.toJSONString(ids), "删除职务信息");
        }
        return deleteByIds;
    }

    /**
     * 获取搜索条件
     *
     * @param params
     * @return
     */
    public Map<String, Object> getSearchCondition(Map<String, Object> params) {
        return getPostInfoService(user).getSearchCondition(params);
    }


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

    /**
     * 获取列表页面按钮信息
     *
     * @return
     */
    public Map<String, Object> getHasRight() {
        return getPostInfoService(user).getHasRight();
    }

}
