package com.engine.htxc.eseal.dao;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.engine.htxc.commonutil.db.DbTools;
import com.engine.integration.util.StringUtils;

import weaver.general.Util;
import weaver.interfaces.htsc.comInfo.PropBean;

/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName EsealBaseDao.java
 * @createTime 2022年07月10日 14:22:00
 */
public class EsealBaseDao {

    public static PropBean pb = new PropBean();

    public static DbTools dbtools = new DbTools();

    public static Map<String, Object> getsealmap(String lcxx, String eselname, String deptid) {
        if (StringUtils.isBlank(lcxx) || StringUtils.isBlank(eselname) || StringUtils.isBlank(deptid)) {
            return null;
        }
        String deptnamevalue = Util.null2String(pb.getPropName("contract.eseal.deptname"));
        if (deptnamevalue.equals(eselname)) {
            String sql = "select t1.id,t1.yzmc,t1.yzlx from uf_ContractSeal t1,uf_tsld t2 where t2.yz = t1.yzlx "
                + "and t1.ssjg = '" + deptid + "' and t2.lcxx=? and t2.qt=? ";
            return dbtools.getsqltomap(sql, lcxx, eselname);
        } else {
            String sql = "select t1.id,t1.yzmc,t1.yzlx from uf_ContractSeal"
                + " t1,uf_tsld t2 where t2.yz = t1.yzbh and t2.lcxx=? and t2.qt=?";
            return dbtools.getsqltomap(sql, lcxx, eselname);
        }
    }

    /**
     * <p>修改印章编号</p>
     * @title getmodelsealmap
     * @author K1810015
     * @updateTime 2022/8/30 20:33
     */
    public static Map<String, Object> getmodelsealmap(String lcxx, String eselname, String deptid) {
        if (StringUtils.isBlank(lcxx) || StringUtils.isBlank(eselname) || StringUtils.isBlank(deptid)) {
            return null;
        }
        String deptnamevalue = Util.null2String(pb.getPropName("contract.eseal.deptname"));
        if (deptnamevalue.equals(eselname)) {
            String sql = "select t1.yzbh as id,t1.yzmc,t1.yzlx from uf_ContractSeal t1,uf_quickseal t2 where t2.yz = t1.yzbh "
                + "and t1.ssjg = '" + deptid + "' and t2.gljm=? and t2.unkey=?";
            return dbtools.getsqltomap(sql, lcxx, eselname);
        } else {
            String sql = "select t1.yzbh as id,t1.yzmc,t1.yzlx from uf_ContractSeal"
                + " t1,uf_quickseal t2 where t2.yz = t1.yzbh and  t2.gljm=? and t2.unkey=?";
            return dbtools.getsqltomap(sql, lcxx, eselname);
        }

    }

    /**
     * <p>修改印章编号</p>
     * @title getmodelsealmap
     * @author K1810015
     * @updateTime 2022/8/30 20:33
     */
    public static List<Map<String,Object>> getSealNoToName(String esealno) {
        List<Map<String,Object>> list=new ArrayList<>();
        if (StringUtils.isBlank(esealno) ) {
            return list;
        }
            String sql =" select * from uf_ContractSeal where yzbh in ("+ Arrays.stream(esealno.split(",")).distinct().map(item->"\'"+item+"\'").collect(Collectors.joining(","))+")";
            return dbtools.getSqlToList(sql, null);

    }



}
