package nccloud.web.hrhi.psndoc.action;

import nc.md.model.IBean;
import nc.vo.pub.BusinessException;
import nc.vo.pub.BusinessRuntimeException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFDate;
import nc.vo.pubapp.AppContext;
import nc.vo.uif2.LoginContext;
import nccloud.commons.lang.StringUtils;
import nccloud.framework.web.container.IRequest;
import nccloud.web.hr.pub.HRCommonAction;
import nccloud.web.hr.pub.HRNccTemplateUtils;
import nccloud.web.hr.pub.HRNccUtils;
import nccloud.web.hrhi.pub.MetaDataUtils;
import nccloud.web.hrhi.pub.PsndocTempUtils;
import nccloud.web.uapbd.commons.web.ParamUtils;

/**
 * 查询行主键
 */
public class PsndocSubQueryPKAction extends HRCommonAction {
    @Override
    public <T> Object execute(IRequest request, T para) throws Exception {
        ParamUtils param = new ParamUtils(request);
        LoginContext context = HRNccUtils.getLoginContext(param);
        // hr组织id，
        if (StringUtils.isBlank(context.getPk_org())) {
            throw new BusinessRuntimeException("Parameter Error!");
        }
        String tableCode = param.getString("table_code", null);
        if (StringUtils.isBlank(tableCode)) {
            // 参数错误 
            throw new BusinessRuntimeException("tableCode Parameter Error!");
        }
        IBean bean = MetaDataUtils.getBeanByName("hrhi", tableCode);
        Class subClass = Class.forName(bean.getFullClassName());
        SuperVO[] subSetVOs = (SuperVO[]) HRNccTemplateUtils.getVOFromGrid(subClass, PsndocTempUtils.getModelStr(param, null));
        if (subSetVOs == null || subSetVOs.length == 0) {
            throw new BusinessException("没有要上传附件的行");
        }
        String pk = subSetVOs[0].getPrimaryKey();
        return pk;
    }
}
