package com.kingdee.eas.custom.permissioncontrol.handler;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.metadata.entity.*;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.hr.ats.lightapp.util.SHRBillUtil;
import com.kingdee.eas.hr.emp.PersonPositionInfo;
import com.kingdee.shr.base.permission.ISHRUserAdminOrgPerm;
import com.kingdee.shr.base.permission.SHRUserAdminOrgPermCollection;
import com.kingdee.shr.base.permission.SHRUserAdminOrgPermFactory;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
import com.kingdee.shr.base.syssetting.web.handler.EditHandler;
import com.kingdee.util.StringUtils;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description 权限申请单编辑处理类
 * @Date 2026/7/3 14:26
 * @Created by HeYuan
 */
public class PermApplyBillEditHandler extends EditHandler {

    public void getApplicantOrgAndRightsAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        Context ctx = this.getContext();
        //申请人id
        String applyPersonId = request.getParameter("applyPersonId");
        if (StringUtils.isEmpty(applyPersonId)) {
            throw new ShrWebBizException("申请人Id为空!");
        }

        try {
            //获取任职组织
            PersonPositionInfo personPositionInfo = SHRBillUtil.getAdminOrgUnit(applyPersonId, ctx);
            AdminOrgUnitInfo personDep = personPositionInfo.getPersonDep();
            //获取角色

            //获取组织范围权限
            ISHRUserAdminOrgPerm ishrUserAdminOrgPerm = SHRUserAdminOrgPermFactory.getLocalInstance(ctx);
            FilterInfo filterInfo = new FilterInfo();

            FilterItemCollection filterItems = filterInfo.getFilterItems();
            filterItems.add(new FilterItemInfo("user.person.id", applyPersonId));

            SelectorItemCollection sic = new SelectorItemCollection();
            sic.add("adminOrg.*");
            sic.add("isIncludeSubOrg");

            EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
            SHRUserAdminOrgPermCollection shrUserAdminOrgPermCol = ishrUserAdminOrgPerm.getSHRUserAdminOrgPermCollection(entityViewInfo);



        } catch (BOSException e) {
            throw new ShrWebBizException(e.getMessage());
        }

    }


}
