package com.kingdee.eas.hr.org.web.handler;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
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.custom.orgunitEx.ProjectType;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
import org.springframework.ui.ModelMap;

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

/**
 * @Description 行政组织信息form扩展
 * @Date 2024/5/9 16:43
 * @Created by Heyuan
 */
public class OrgUnitEditHandlerEx extends OrgUnitEditHandler {

    /**
     * 获取查询列
     *
     * @return
     * @throws SHRWebException
     */
    protected SelectorItemCollection getSelectors() throws SHRWebException {
        SelectorItemCollection sic = super.getSelectors();
        if (sic != null) {
            sic.add("projectType");
        }
        return sic;
    }

    @Override
    protected void afterSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model) throws SHRWebException {
        super.afterSave(request, response, model);
        try {
            //更新项目类型
            AdminOrgUnitInfo adminOrgUnitInfo = (AdminOrgUnitInfo) model;
            Context ctx = SHRContext.getInstance().getContext();
            String id = adminOrgUnitInfo.getId().toString();
            ProjectType projecttype = (ProjectType) adminOrgUnitInfo.get("projecttype");
            String updateSql = "update T_ORG_Admin set cfprojecttype1 = ? where fid =?";
            if(projecttype == null){
                DbUtil.execute(ctx,updateSql,new Object[]{"",id});
            }else{
                String value = projecttype.getValue();
                DbUtil.execute(ctx,updateSql,new Object[]{value,id});
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ShrWebBizException(e.getMessage());
        }
    }
}
