package com.engine.htsc.smsd.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.smsd.service.IsSuitService;
import com.engine.htsc.smsd.service.impl.IsSuitServiceImpl;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.workflow.logging.Logger;
import weaver.workflow.logging.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

public class IsSuitAction {
    Logger logger = LoggerFactory.getLogger(IsSuitAction.class);
    private IsSuitService getService() {
        return ServiceUtil.getService(IsSuitServiceImpl.class);
    }


    /**
     * 根据部门编码以及流程类型获取当前流程是否适用扫码收单
     */
    @GET
    @Path("/getissuit")
    @Produces({MediaType.APPLICATION_JSON})
    public String getIsSuit(@Context HttpServletRequest request) {
        BaseBean bb = new BaseBean();
        bb.writeLog("=====================调用接口成功，进入查询是否适用扫码收单方法体=================");
        String bmmc = Util.null2String(request.getParameter("bmmc"));
        String lclx = Util.null2String(request.getParameter("lclx"));
        bb.writeLog("==================接收到的参数是：bmmc:" + bmmc + ",lclx:" + lclx + "================");
        Map<String, Object> params = new HashMap<>();
        params.put("bmmc",bmmc);
        params.put("lclx",lclx);
        Map<String, Object> isSuit = getService().getIsSuit(params);
        String back = JSONObject.toJSONString(isSuit);
        bb.writeLog("=========================即将传给前端的参数是："+ back);
        return back;
    }

    @GET
    @Path("/dataisadd")
    @Produces({MediaType.APPLICATION_JSON})
    public String dataIsAdd(@Context HttpServletRequest request){
        logger.info("===========判断数据是否可以添加================");
        String bmid = Util.null2String(request.getParameter("bmid"));
        String lclx = Util.null2String(request.getParameter("lclx"));
        logger.info("==================接收到的参数是：bmmc:" + bmid + ",lclx:" + lclx + "================");
        Map<String, Object> params = new HashMap<>();
        params.put("bmid",bmid);
        params.put("lclx",lclx);
        Map<String, Object> result = getService().dataIsAddService(params);
        String back = JSONObject.toJSONString(result);
        logger.info("=========================即将传给前端的参数是："+ back);
        return back;
    }
}
