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

import com.alibaba.fastjson.JSONObject;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

public class GeneralESignBillHandler extends ListHandler {
    public String getTableDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
        Context ctx = SHRContext.getInstance().getContext();
        String id = request.getParameter("id");
        String number = request.getParameter("number");
        try {
            Map<String,Object> getSqlServiceMap = new HashMap<String,Object>();
            getSqlServiceMap.put("number",number);

            BOSUuid read = BOSUuid.read(id);
            BOSObjectType type = read.getType();
            System.out.println(type.toString());
            if (type.toString().equals("7BD37592")){//id类型为合同
                getSqlServiceMap.put("filter","  where \"employeeContract\".FID = '"+id+"'");
            }else  if (type.toString().equals("80EF7DED")){//id类型为员工
                getSqlServiceMap.put("filter","  where \"person\".FID = '"+id+"'");
            }else {
                throw new RuntimeException("传入id非合同id和员工ID");
            }
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id",id);
            getSqlServiceMap.put("otherParameters",jsonObject);
            Object o2 = MSFServiceFacadeFactory.getLocalInstance(ctx)
                    .processService("getESignConfigTableService", getSqlServiceMap);
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("code",200);
            map.put("data",o2);
            JSONUtils.SUCCESS(map);
        } catch (BOSException e) {
            throw new RuntimeException(e);
        } catch (EASBizException e) {
            throw new RuntimeException(e);
        }
        return null;
    }
}
