package com.engine.htsc.seal.service;

import com.engine.core.impl.Service;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LicenseService extends Service {

    public Map<String,Object> getLicenseListByDeptCode(String deptcodes, String type){
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();
        Map<String,Object> resultMap = new HashMap<>();

        List<Map<String,String>> licenseList = new ArrayList<>();
        for(String deptcode:deptcodes.split(",")){
            String sql = "select t1.bmbh,t1.zz,t3.imagefilename,t3.fileid from uf_zzwj t1 " +
                    "left join docimagefile t2 on t2.docid = t1.wjmc " +
                    "left join imagefile t3 on t3.imagefileid = t2.imagefileid " +
                    "where t1.bmbh = '"+deptcode+"'";
            if("1".equals(type)){
                sql += " and t1.zz like '%正本%'";
            }else if("2".equals(type)){
                sql += " and t1.zz like '%副本%'";
            }
            bs.writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                Map<String,String> licenseMap = new HashMap<>();
                licenseMap.put("deptcode", Util.null2String(rs.getString("bmbh")));
                licenseMap.put("name",Util.null2String(rs.getString("zz")));
                licenseMap.put("filename",Util.null2String(rs.getString("imagefilename")));
                licenseMap.put("fileid",Util.null2String(rs.getString("fileid")));
                licenseList.add(licenseMap);
            } 
        }

        resultMap.put("licenseList",licenseList);
        return resultMap;
    }

}
