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

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.basedata.org.AdminOrgUnitFactory;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.org.IAdminOrgUnit;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.hr.org.web.handler.OrgUnitEditHandler;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import org.apache.log4j.Logger;

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

/**
 * @author qingwu
 * @date 2024/10/29
 * @apiNote
 */
public class OrgUnitEditHandlerEx extends OrgUnitEditHandler {
    Logger logger = Logger.getLogger(OrgUnitEditHandlerEx.class);
    private Context ctx = SHRContext.getInstance().getContext();

    @Override
    protected IObjectPK runSaveData(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model) throws SHRWebException, EASBizException {

        IObjectPK iObjectPK = super.runSaveData(request, response, model);
        AdminOrgUnitInfo adminOrgUnitInfo = (AdminOrgUnitInfo) model;
        //IObjectValue bmfzr = (IObjectValue) adminOrgUnitInfo.get("bmfzr");
        //logger.error("OrgUnitEditHandlerEx-=------bmfzr---" + bmfzr.get("id"));
        //IObjectValue bmjl = (IObjectValue) adminOrgUnitInfo.get("bmjl");
        //logger.error("OrgUnitEditHandlerEx-=------bmjl---" + bmjl.get("id"));
        //IObjectValue zj = (IObjectValue) adminOrgUnitInfo.get("zj");
        //logger.error("OrgUnitEditHandlerEx-=------zj---" + zj.get("id"));
        //IObjectValue fz = (IObjectValue) adminOrgUnitInfo.get("fz");
        //logger.error("OrgUnitEditHandlerEx-=------fz---" + fz.get("id"));
        try {
            SelectorItemCollection sic = new SelectorItemCollection();
            sic.add("bmfzr");
            sic.add("bmjl");
            sic.add("zj");
            sic.add("fz");
            IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx);
            iAdminOrgUnit.updatePartial(adminOrgUnitInfo, sic);
        } catch (BOSException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        return iObjectPK;
    }
}
