package com.engine.htxc.contract.dao;

import com.engine.htxc.commonutil.db.DbTools;
import com.engine.htxc.contract.util.ContractUtil;
import com.engine.integration.util.StringUtils;
import weaver.general.Util;

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

/**
 * <p>关于合同建模状态修改的类型</p>
 * @author K1810015
 * @version 1.0.0
 * @ClassName ContractModeDao.java
 * @createTime 2022年08月31日 20:33:00
 */
public class ContractModeDao {

    private DbTools dbtools=new DbTools();

    public Map<String,Object> modemap=new HashMap<>();

    public String modeid="";

    public String modetable="";

    /**
     * 默认标识，判断是否初始化成功
     * */
    private boolean flag=false;

    public ContractModeDao(String htlx,String id) {
        inittable(htlx);
        if(!flag || StringUtils.isBlank(id)){
            return ;
        }
        Map<String,String> wheremap=new HashMap<>();
        wheremap.put("id",id);
        modemap=dbtools.gettabletomap(modetable,wheremap);
    }

    public ContractModeDao(String htlx,String htbh,String htbb) {
        inittable(htlx);
        if(!flag ||  StringUtils.isBlank(htbh) || StringUtils.isBlank(htbb)){
            return ;
        }
        Map<String,String> wheremap=new HashMap<>();
        wheremap.put("htbh",htbh);
        wheremap.put("dqbb",htbb);
        modemap=dbtools.gettabletomap(modetable,wheremap);
        if(modemap!=null && !modemap.isEmpty()){
            modeid= Util.null2String(modemap.get("id"));
        }
    }

    public boolean updateMode(Map<String,String> setmap){
        if(!flag){
            return false;
        }
        if(setmap==null || setmap.isEmpty()){
            return false;
        }
        if(StringUtils.isBlank(modeid) || StringUtils.isBlank(modetable)){
            return false;
        }
        Map<String,String> wheremap=new HashMap<>(1);
        wheremap.put("id",modeid);
        return dbtools.updateSql(modetable,setmap,wheremap);

    }

    private void inittable(String htlx){
        if(StringUtils.isBlank(htlx) ){
            return ;
        }
        modetable= ContractUtil.getContractTableName(htlx);
        if(!StringUtils.isBlank(modetable)){
            flag=true;
        }
    }
}
