package com.engine.htsc.smsd.dao;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

import java.util.HashMap;
import java.util.Map;

public class IsSuitCmd extends AbstractCommonCommand<Map<String, Object>> {
    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    public IsSuitCmd(Map<String, Object> params) {
        this.params = params;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        BaseBean bb = new BaseBean();
        Map<String, Object> back = new HashMap<>();
        RecordSet rs = new RecordSet();
        String sql = "";
//        需求更改为默认为否，没有权限
        String isSuit = "1";
        bb.writeLog("========成功进入查询是否适用的扫码收单的dao层代码======");
        bb.writeLog("=====接受到的参数是：" + JSONObject.toJSONString(params));
        try {
            String bmmc = Util.null2String(params.get("bmmc"));
            String lclx = Util.null2String(params.get("lclx"));
            sql = "select sfsysmsd from uf_CodeScanRec where ',' || bmmc || ',' like '%,"+bmmc+",%' and lclx = ?";
            bb.writeLog("即将执行的SQL是："+sql);
            rs.executeQuery(sql, lclx);
            if (rs.next()) {
                bb.writeLog("=======sql执行结果是：" + rs.getString("sfsysmsd"));
                isSuit = "0".equals(rs.getString("sfsysmsd")) ? "0" : "1";
            }
            back.put("status", "success");
            back.put("isSuit", isSuit);
        } catch (Exception e) {
            e.getMessage();
            back.put("status", "defeated");
            back.put("isSuit", isSuit);
        }

        return back;
    }
}
