package com.yihu.jw.entity.util;

/***
 * @ClassName: TransforSqlUtl
 * @Description:
 * @Auther: shi kejing
 * @Date: 2021/2/2 16:28
 */
public class TransforSqlUtl {

    private static final boolean dbEncrypt=false; //不需要加密时 改为false即可，实体类注释需同时处理

    public static String wlyySpecialistPatientRelationLike(String sql,String ...replaceName){
        for (String tmp :replaceName){
            String str = "AES_DECRYPT(from_base64("+tmp+"),'jkzl2021ZJXL*#%a')";
            if (dbEncrypt){
                sql = sql.replaceAll(tmp,str);
            }
        }
        return  sql;
    }

    public static String wlyySpecialistPatientRelationReplay(String sql,String ...replaceName){
        for (String tmp :replaceName){
            String str = "CAST(AES_DECRYPT(from_base64("+tmp+"),'jkzl2021ZJXL*#%a') AS CHAR ) ";
            if (dbEncrypt){
                sql = sql.replaceAll(tmp,str);
            }
        }
        return  sql;
    }
    public static String wlyy_service_itemAll(String sql){
        String sqlTmp = " *,CAST(AES_DECRYPT(from_base64(create_user_name),'jkzl2021ZJXL*#%a')AS CHAR ) AS create_user_name,\n" +
                "CAST( AES_DECRYPT(from_base64(update_user_name),'jkzl2021ZJXL*#%a')AS CHAR) AS update_user_name\n";
        if (dbEncrypt){
            sql = sql.replace("*", sqlTmp);
        }
        return sql;
    }

    public static String specialistPatientRelationAll(String sql) {
        String sqlTmp = " *,CAST(AES_DECRYPT(from_base64(doctor_name),'jkzl2021ZJXL*#%a')AS CHAR ) AS doctor_name,\n" +
                "CAST( AES_DECRYPT(from_base64(patient_name),'jkzl2021ZJXL*#%a')AS CHAR) AS patient_name,\n" +
                "CAST(AES_DECRYPT(from_base64(health_assistant_name),'jkzl2021ZJXL*#%a') AS CHAR) AS health_assistant_name,\n" +
                "CAST(AES_DECRYPT(from_base64(sign_doctor_name),'jkzl2021ZJXL*#%a') AS CHAR) AS sign_doctor_name,\n" +
                "CAST(AES_DECRYPT(from_base64(health_doctor_name),'jkzl2021ZJXL*#%a') AS CHAR) AS health_doctor_name,\n" +
                "CAST(AES_DECRYPT(from_base64(create_user_name),'jkzl2021ZJXL*#%a')AS CHAR)AS create_user_name,\n" +
                "CAST(AES_DECRYPT(from_base64(update_user_name),'jkzl2021ZJXL*#%a')AS CHAR)AS update_user_name \n" ;
        if (dbEncrypt){
            sql = sql.replace("*", sqlTmp);
        }
        return sql;

    }

    public static String specialistPatientRelationAll2(String sql) {
        String sqlTmp = " *,CAST(AES_DECRYPT(from_base64(r.doctor_name),'jkzl2021ZJXL*#%a')AS CHAR ) AS doctor_name,\n" +
                "CAST( AES_DECRYPT(from_base64(r.patient_name),'jkzl2021ZJXL*#%a')AS CHAR) AS patient_name,\n" +
                "CAST(AES_DECRYPT(from_base64(r.health_assistant_name),'jkzl2021ZJXL*#%a') AS CHAR) AS health_assistant_name,\n" +
                "CAST(AES_DECRYPT(from_base64(r.sign_doctor_name),'jkzl2021ZJXL*#%a') AS CHAR) AS sign_doctor_name,\n" +
                "CAST(AES_DECRYPT(from_base64(r.health_doctor_name),'jkzl2021ZJXL*#%a') AS CHAR) AS health_doctor_name,\n" +
                "CAST(AES_DECRYPT(from_base64(r.create_user_name),'jkzl2021ZJXL*#%a')AS CHAR)AS create_user_name,\n" +
                "CAST(AES_DECRYPT(from_base64(r.update_user_name),'jkzl2021ZJXL*#%a')AS CHAR)AS update_user_name \n" ;
        if (dbEncrypt){
            sql = sql.replace("*", sqlTmp);
        }
        return sql;

    }

    public static String deviceGrantDoctorName(String sql){

        if (dbEncrypt){
            sql = sql.replaceAll("d.grant_doctor_name","CAST(AES_DECRYPT(from_base64(d.grant_doctor_name),'jkzl2021ZJXL*#%a')AS char)");
        }
        return sql;

    }

    public static String deviceAll(String sql){
        String str = "*,CAST(AES_DECRYPT(from_base64(linkman),'jkzl2021ZJXL*#%a') AS CHAR ) AS linkman,CAST(AES_DECRYPT(from_base64(tel),'jkzl2021ZJXL*#%a') AS CHAR ) AS tel,CAST(AES_DECRYPT(from_base64(representative),'jkzl2021ZJXL*#%a') AS CHAR ) AS representative,CAST(AES_DECRYPT(from_base64(applicant_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS applicant_name,CAST(AES_DECRYPT(from_base64(applicant_identity),'jkzl2021ZJXL*#%a') AS CHAR ) AS applicant_identity,CAST(AES_DECRYPT(from_base64(applicant_tel),'jkzl2021ZJXL*#%a') AS CHAR ) AS applicant_tel,CAST(AES_DECRYPT(from_base64(grant_doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS grant_doctor_name";
        if (dbEncrypt){
            sql = sql.replace("*",str);
        }
        return sql;
    }

    public static String wlyyPatientDeviceLocationIdCard(String sql){
        if (dbEncrypt){
            sql = sql.replaceAll("idcard","CAST(AES_DECRYPT(from_base64(idcard),'jkzl2021ZJXL*#%a')AS char)");
        }
        return sql;
    }

    public static String wlyy_patient_rehabilitation_planName(String sql){
        String str = "CAST(AES_DECRYPT(from_base64(p.name),'jkzl2021ZJXL*#%a') AS CHAR ) AS name ";
        if (dbEncrypt){
            sql = sql.replaceAll("p.name",str);
        }
        return sql;
    }

    public static String wlyy_patient_rehabilitation_planName2(String sql){
        String str = "CAST(AES_DECRYPT(from_base64(p.name),'jkzl2021ZJXL*#%a') AS CHAR ) ";
        if (dbEncrypt){
            sql = sql.replaceAll("p.name",str);
        }
        return sql;
    }

    public static String wlyy_patient_rehabilitation_planAll2(String sql){
        String str = "p.*,CAST(AES_DECRYPT(from_base64(p.name),'jkzl2021ZJXL*#%a') AS CHAR ) AS name,CAST(AES_DECRYPT(from_base64(p.create_user_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS create_user_name,CAST(AES_DECRYPT(from_base64(p.update_user_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS update_user_name";
        if (dbEncrypt){
            sql = sql.replace("p.*",str);
        }
        return sql;
    }

    public static String wlyy_patient_rehabilitation_planCreateName(String sql){
        String str = "CAST(AES_DECRYPT(from_base64(p.create_user_name),'jkzl2021ZJXL*#%a') AS CHAR ) ";
        if (dbEncrypt){
            sql = sql.replaceAll("p.create_user_name",str);
        }
        return sql;
    }

    public static String wlyy_plan_detail_appointmentAll(String sql){
        String str = "*,CAST(AES_DECRYPT(from_base64(doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS doctor_name,CAST(AES_DECRYPT(from_base64(appointment_doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS appointment_doctor_name";
        if (dbEncrypt){
            sql = sql.replace("*",str);
        }
        return sql;
    }

    public static String wlyy_plan_detail_appointmentAppDoctorName(String sql){
        String str = "CAST(AES_DECRYPT(from_base64(a.doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) ";
        if (dbEncrypt){
            sql = sql.replace("a.doctor_name",str);
        }
        return sql;
    }

    public static String wlyy_rehabilitation_operate_recordsDoctorName(String sql){
        String str = "CAST(AES_DECRYPT(from_base64(r.doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) ";
        if (dbEncrypt){
            sql = sql.replaceAll("r.doctor_name",str);
        }
        return sql;
    }

    public static String wlyy_rehabilitation_plan_detailAll(String sql){
        String str = "*,CAST(AES_DECRYPT(from_base64(doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS doctor_name,CAST(AES_DECRYPT(from_base64(create_user_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS create_user_name,CAST(AES_DECRYPT(from_base64(update_user_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS update_user_name";
        if (dbEncrypt){
            sql = sql.replace("*",str);
        }
        return sql;
    }

    public static String wlyy_rehabilitation_plan_detailAll2(String sql){
        String str = "d.*,CAST(AES_DECRYPT(from_base64(d.doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS doctor_name,CAST(AES_DECRYPT(from_base64(d.create_user_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS create_user_name,CAST(AES_DECRYPT(from_base64(d.update_user_name),'jkzl2021ZJXL*#%a') AS CHAR ) AS update_user_name";
        if (dbEncrypt){
            sql =  sql.replace("d.*",str);
        }
        return sql;
    }

    public static String wlyy_rehabilitation_plan_detailDoctorName(String sql){
        String str = "CAST(AES_DECRYPT(from_base64(d.doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) ";
        if (dbEncrypt){
            sql = sql.replaceAll("d.doctor_name",str);
        }
        return sql;
    }

    public static String wlyy_rehabilitation_plan_detailDoctorName2(String sql){
        String str = "CAST(AES_DECRYPT(from_base64(d.doctor_name),'jkzl2021ZJXL*#%a') AS CHAR ) as doctor_name";
        if (dbEncrypt){
            sql = sql.replaceAll("d.doctor_name",str);
        }
        return sql;
    }
}
