package com.kingdee.eas.hr.project.handler;

import com.google.common.collect.Maps;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;

import com.kingdee.eas.hr.project.MemberManagementInfo;
import com.kingdee.eas.hr.project.ProjectManagementFactory;
import com.kingdee.eas.hr.project.ProjectManagementInfo;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;

import com.kingdee.shr.base.syssetting.web.handler.EditHandler;

import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.MessageFormat;
import java.util.Map;

/** 项目成员管理表单
 * @BelongsProject: dataImpExp820
 * @BelongsPackage: com.kingdee.eas.hr.project.handler
 * @Author: lhbj
 * @CreateTime: 2024-11-27  18:21
 * @Description: TODO
 * @Version: 1.0
 */
public class MemberManagementEditHandler extends EditHandler {

    @Override
    protected void setInitData(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, Map<String, Object> initData) throws SHRWebException {
        super.setInitData(request, response, modelMap, initData);
        MemberManagementInfo management = (MemberManagementInfo) modelMap.getAttribute("model");
        initData.put("MemberState",management.getState().getValue());
        Context ctx = SHRContext.getInstance().getContext();
        try {
            String prijectId = this.getProjectId(request);
            if(StringUtils.isNotBlank(prijectId)) {
                Map<String,String> projectMap = Maps.newHashMap();
                ProjectManagementInfo p= ProjectManagementFactory.getLocalInstance(ctx).getProjectManagementInfo(new ObjectUuidPK(prijectId));
                projectMap.put("id",p.getId().toString());
                projectMap.put("number",p.getNumber());
                projectMap.put("projectCode",p.getString("projectCode"));
                projectMap.put("projectName",p.getString("projectName"));
                projectMap.put("projectLevel",p.getString("projectLevel"));
                projectMap.put("notes",p.getString("notes"));
                projectMap.put("projectState",p.getString("projectState"));
                initData.put("projectManagement",projectMap);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    protected String getProjectId(HttpServletRequest request) throws SHRWebException {
        String billId = request.getParameter("prijectID");
        if (StringUtils.isEmpty(billId)) {
            billId = request.getParameter("prijectId");
        }

        if (StringUtils.isEmpty(billId)) {
            billId = (String)request.getAttribute("prijectId");
        }
        return billId;

    }

}
