package org.security.desk.esb.request;

import cn.hutool.core.date.DateUtil;
import lombok.Data;
import org.security.common.constant.CommonConstant;
import org.security.common.utils.CommonUtil;
import org.security.desk.esb.SeqNOFactory;

/**
 * @author zj 2022/9/1
 */
@Data
public class EsbRequest<Body> {

	private SysHeadRequest SYS_HEAD;
	private AppHeadRequest APP_HEAD;
	private LocalHeadRequest LOCAL_HEAD;
	private Body BODY;

	public static EsbRequest creatEsbRequest(String scvCd, String svcScn, String chnlTp, Object body) {
		String tranDate = DateUtil.format(DateUtil.date(), "yyyyMMdd");
		String tranTm = DateUtil.format(DateUtil.date(), "HHmmssSSS");
		String seqNo = SeqNOFactory.getSeqNo(tranDate, tranTm);
		EsbRequest<Object> esbRequest = new EsbRequest<>();
		SysHeadRequest sysHeadRequest = new SysHeadRequest();
		sysHeadRequest.setSvcCd(scvCd); //服务吗
		sysHeadRequest.setSvcScn(svcScn);  //场景码
		sysHeadRequest.setChnlTp(chnlTp);//渠道类型
		sysHeadRequest.setTmnlNo("");//终端号
		sysHeadRequest.setCnsmSysSvrId(CommonConstant.SYS_ID);//消费方系统服务器Id
		sysHeadRequest.setCnsmSysId(CommonConstant.SYS_ID);//消费方系统Id
		sysHeadRequest.setCnsmSysSeqNo(seqNo);//消费方系统流水号
		sysHeadRequest.setSrcSysTmnlNo("");//源发起系统终端号
		sysHeadRequest.setSrcSysSvrId(CommonConstant.SYS_ID);//源发起系统服务器Id
		sysHeadRequest.setSrcSysId(CommonConstant.SYS_ID);//源发起系统Id
		sysHeadRequest.setSrcSysSeqNo(seqNo);//源发起系统流水号
		sysHeadRequest.setMac(CommonUtil.getMacAddress());//MAC值
		sysHeadRequest.setTranDt(tranDate);//交易日期
		sysHeadRequest.setTranTm(tranTm);//交易时间
		sysHeadRequest.setFileFlg("0");//文件标志 0 无文件
		sysHeadRequest.setIP(CommonUtil.getIpAddress());//IP地址
		sysHeadRequest.setVerNo("");//版本号
		sysHeadRequest.setLegalOrgId("");//法人代码
		sysHeadRequest.setBizDt("");//业务日期
		sysHeadRequest.setBizTacNo("");//业务追踪号

		AppHeadRequest appHeadRequest = new AppHeadRequest();
		appHeadRequest.setTlrNo("");//柜员号
		appHeadRequest.setBranchId("");//机构Id
		appHeadRequest.setTlrPswd("");//柜员密码
		appHeadRequest.setTlrLvl("");//柜员级别
		appHeadRequest.setTlrTp("");//柜员类别
		appHeadRequest.setTlrVrfyMode("");//柜员验证方式

		LocalHeadRequest localHeadRequest = new LocalHeadRequest();
		localHeadRequest.setNCBSCfrmFlg("1");

		esbRequest.setSYS_HEAD(sysHeadRequest);
		esbRequest.setAPP_HEAD(appHeadRequest);
		esbRequest.setLOCAL_HEAD(localHeadRequest);
		esbRequest.setBODY(body);
		return esbRequest;
	}
}
