package psdi.app.iface.oa;

import com.alibaba.fastjson.JSONObject;
import psdi.app.iface.comm.UrlConstants;
import psdi.app.iface.srm.Srm2EamHandler;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.server.MXServer;
import psdi.util.MXException;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.Date;

/**
 * OA调用EAM单点登录 用于OA首页点击EAM logo登录跳转至EAM启动中心
 * edit 20230519
 */
@Path("/eam")
public class Oa2EamStartcntrService {

    String loginUrl = UrlConstants.loginUrl;

    @POST
    @Path("/startcntr")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public String startcntr(String received) throws IOException, MXException {
        JSONObject msgJSONObject = new JSONObject();
        if("".equalsIgnoreCase(received) || null==received){
            msgJSONObject.put("code", "20001");
            msgJSONObject.put("errmsg", "参数不能为空");
            return msgJSONObject.toString();
        }
        JSONObject jsonObject = JSONObject.parseObject(received);
//        JSONObject jsonObject2 = JSONObject.parseObject(jsonObject.getString("SendData"));
//        if(null==jsonObject2){
//            msgJSONObject.put("code", "20001");
//            msgJSONObject.put("errmsg", "错误！入参格式不对");
//            return msgJSONObject.toString();
//        }
        String secret = jsonObject.getString("secret");//加密secret AESUtil.createCiphertext("0113992-OA2EAMIFACE"); 0113992工号 OA2EAMIFACE固定值
        if("".equalsIgnoreCase(secret) || null==secret){
            msgJSONObject.put("code", "20001");
            msgJSONObject.put("errmsg", "secret不能为空");
            return msgJSONObject.toString();
        }
        loginUrl+=secret;
        msgJSONObject.put("code", "10000");
        msgJSONObject.put("msg", "success");
        msgJSONObject.put("pcurl", loginUrl);
        return msgJSONObject.toString();
    }
}
