package weaver.interfaces.htsc.wdzx;

import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractCustomSqlConditionJavaCode;
import weaver.general.BaseBean;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import java.util.Map;

public class ModewcjywcjSearchTemplate extends AbstractCustomSqlConditionJavaCode {
    @Override
    public String generateSqlCondition(Map<String, Object> param) throws Exception {
        User user = (User)param.get("user");
        String ywcj = (String)param.get("ywcj");
        RecordSet rs = new RecordSet();
        String sqlCondition = "(";
        // (userid in(glyfzzd) or userid in(cjrfzzd)) and ywcj = ywcj
        int userid = user.getUID();
        BaseBean bb = new BaseBean();
        ResourceComInfo resComInfo;
        String userids = "select * from hrmresource where workcode in (select workcode  from hrmresource where id in ("+userid+")) ";
        rs.execute(userids);
        while(rs.next()){
//            String loginid = rs.getString("loginid");
            String id = rs.getString("id");
//            sqlCondition +="( '"+id + "' in (to_char(t1.cjrfzzd))) or ";
            sqlCondition +="instr( ','|| t1.cjrfzzd || ',' , ',"+id+",') >0 or ";
        }
        String or = sqlCondition.substring(0, sqlCondition.lastIndexOf("or"));
        System.out.println(or);
        or+=" ) and t1.ywcj like '" +ywcj+"%'";
        or = "(" +or+ ")";
        JAVATools.SetCmdwritelog("我创建+业务场景的sql====" + or);
        return or;
    }
}
