SQL工具类
package com.ebizwindow.crm.utils; import java.util.List; import com.ebizwindow.crm.constants.SqlConst;
import com.ebizwindow.crm.constants.TableConst;
import com.ebizwindow.crm.model.TableDefinition;
import com.ebizwindow.crm.portlet.base.SystemStatus;
import com.ebizwindow.crm.service.OpportunityLocalServiceUtil;
import com.ebizwindow.crm.service.TableDefinitionLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringPool; public class SQLUtil {
private static final String PK_COLUMN_CREATEUSERID = "createUserId";
private static final String PK_COLUMN_EDITUSERID = "editUserId";
private static final String PK_COLUMN_AUDITUSERID = "auditUserId";
private static final String PK_COLUMN_CLOSEUSERID = "closeUserId";
private static final String PK_COLUMN_CONFIRMUSERID = "confirmUserId";
private static final String PK_COLUMN_REQUESTUSERID = "requestUserId";
private static final String PK_COLUMN_EXECUTORID = "executorId";
private static final String PK_COLUMN_SUBMITUSERID = "submitUserId";
private static final String PK_COLUMN_OWNERID = "ownerId";
private static final String PK_COLUMN_UPID = "upId";
private static final String PK_COLUMN_CUSTOMERID = "customerId";
private static final String PK_COLUMN_CONTACTID = "contactId";
private static final String PK_COLUMN_CONTRACTID = "contractId";
private static final String PK_COLUMN_OPPORTUNITYID = "opportunityId";
private static final String PK_COLUMN_QUOTATIONID = "quotationId";
private static final String PK_COLUMN_CLUEID = "clueId";
private static final String PK_COLUMN_ACTIVITYID = "activityId";
private static final String PK_COLUMN_MARKETID = "marketId";
private static final String PK_COLUMN_SALESTEMPLATEID = "salesTemplateId";
private static final String PK_COLUMN_DEPARTMENTID = "departmentId";
private static final String PK_COLUMN_PRODUCTID = "productId";
private static final String PK_COLUMN_PROJECTID = "projectId"; public static String getQueryValue(String queryValue, String columnName, long companyId) throws SystemException {
String results = StringPool.BLANK;
String query = StringPool.BLANK;
if (columnName.equals(PK_COLUMN_CREATEUSERID)
|| columnName.equals(PK_COLUMN_EDITUSERID)
|| columnName.equals(PK_COLUMN_AUDITUSERID)
|| columnName.equals(PK_COLUMN_OWNERID)
|| columnName.equals(PK_COLUMN_CLOSEUSERID)
|| columnName.equals(PK_COLUMN_CONFIRMUSERID)
|| columnName.equals(PK_COLUMN_REQUESTUSERID)
|| columnName.equals(PK_COLUMN_SUBMITUSERID)
|| columnName.equals(PK_COLUMN_EXECUTORID) ) { query = "select userId from User_ where firstName like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_UPID) || columnName.equals(PK_COLUMN_CUSTOMERID)) { query = "select customerId from CRM_Customer where chineseName like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_CONTACTID)) { query = "select contactId from CRM_Contact where chineseName like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_MARKETID)) { query = "select marketId from CRM_Market where name like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_CLUEID)) { query = "select clueId from CRM_Clue where name like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_OPPORTUNITYID)) { query = "select opportunityId from CRM_Opportunity where topic like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_QUOTATIONID)) { query = "select quotationId from CRM_Quotation where name like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_CONTRACTID)) { query = "select contractId from CRM_Contract where name like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_ACTIVITYID)) { query = "select activityId from CRM_Activity where name like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_SALESTEMPLATEID)) { query = "select salesTemplateId from CRM_SalesTemplate where name like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_PRODUCTID)) { query = "select productId from CRM_Product where name like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_DEPARTMENTID)) { query = "select departmentId from OPERATOR_Department where departmentName like '%" + queryValue + "%'"; } else if (columnName.equals(PK_COLUMN_PROJECTID)) { query = "select projectId from CRM_Project where name like '%" + queryValue + "%'"; } query += " and companyId = '" + companyId + "'"; List<Long> entityIDs = OpportunityLocalServiceUtil.searchBySQLQueryString(query, -1, -1); String entityIDsStr = entityIDs.toString();
results = StringPool.OPEN_PARENTHESIS + entityIDsStr.subSequence(1, entityIDsStr.length() - 1) + StringPool.CLOSE_PARENTHESIS; return results;
} public static String symbolToString(String symbol, String value) {
String str = StringPool.BLANK;
if (!symbol.equals(StringPool.BLANK)) {
if (symbol.equals("eq") || symbol.equals(StringPool.EQUAL)) { str = " = '" + value + "'"; } else if (symbol.equals("gt") || symbol.equals(StringPool.GREATER_THAN)) { str = " > '" + value + "'"; } else if (symbol.equals("lt") || symbol.equals(StringPool.LESS_THAN)) { str = " < '" + value + "'"; } else if (symbol.equals("gteq") || symbol.equals(StringPool.GREATER_THAN_OR_EQUAL)) { str = " >= '" + value + "'"; } else if (symbol.equals("lteq") || symbol.equals(StringPool.LESS_THAN_OR_EQUAL)) { str = " <= '" + value + "'"; } else if (symbol.equals("ne") || symbol.equals(StringPool.NOT_EQUAL)) { str = " <> '" + value + "'"; } else if (symbol.equals("c")) { str = " like '%" + value + "%'"; } else if (symbol.equals("sl")) { str = " like '" + value + "%'"; } else if (symbol.equals("sr")) { str = " like '%" + value + "'"; } else if (symbol.equals("nn")) { str = " <> '' "; } else if (symbol.equals("n")) { str = " = '' "; } else if (symbol.equals("isn")) { str = " is null ";
} else if (symbol.equals("!eq")) {
str = " != '" + value + "'";
} else if (symbol.equals("tc")) {
str = " in " + value;
}
} else {
str = " = '' ";
}
return str;
} public static String getActivitySQL(long userId) throws SystemException {
StringBuffer sb = new StringBuffer("select activity.activityId from CRM_Activity activity where (activity.executorId in ")
.append(OperatorUtil.searchViewOperatorIds(userId,TableConst.ACTIVITY))
.append(" or activity.createUserId in ")
.append(OperatorUtil.searchViewOperatorIds(userId,TableConst.ACTIVITY))
.append(")");
return sb.toString();
} public static String getCustomerSQL(long userId) throws SystemException {
String sql = "select customer.customerId from CRM_Customer customer where (customer.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId, TableConst.CUSTOMER) + ")";
return sql;
} public static String getContactSQL(long userId) throws SystemException {
String sql = "select contact.contactId from CRM_Contact contact where (contact.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.CONTACT) + ")";
return sql;
} public static String getContactTop10SQL(long userId) throws SystemException {
String sql = "select contact.contactId from CRM_Contact contact where (contact.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.CONTACT) + ") order by contact.createDate limit 10 ";
return sql;
} public static String getContractSQL(long userId) throws SystemException {
String sql = "select contract.contractId from CRM_Contract contract where (contract.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.CONTRACT) + ")";
return sql;
} public static String getMarketSQL(long userId) throws SystemException {
String sql = "select market.marketId from CRM_Market market where (market.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.MARKET) + ")";
return sql;
} public static String getClueSQL(long userId) throws SystemException {
String sql = "select clue.clueId from CRM_Clue clue where (clue.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.CLUE) + ") and clue.auditStatus='"+SystemStatus.Audit.getStatus()+"'";
return sql;
} public static String getOpportunitySQL(long userId) throws SystemException {
String sql = "select opportunity.opportunityId from CRM_Opportunity opportunity where (opportunity.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.OPPORTUNITY) + ")";
return sql;
} public static String getOpportunityTop10SQL(long userId) throws SystemException {
String sql = "select opportunity.opportunityId from CRM_Opportunity opportunity where (opportunity.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.OPPORTUNITY) + ") order by opportunity.createDate limit 10";
return sql;
} public static String getQuotationSQL(long userId) throws SystemException {
String sql = "select quotation.quotationId from CRM_Quotation quotation where (quotation.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.QUOTATION) + ")";
return sql;
} public static String getOrderSQL(long userId) throws SystemException {
String sql = "select order_.orderId from CRM_Order order_ where (order_.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.ORDER) + ")"; return sql;
} public static String getProductSQL(long companyId) throws SystemException {
String sql = "select product.productId from CRM_Product product where product.companyId = '" + companyId + "'";
return sql;
} public static String getRPlanSQL(long userId) throws SystemException {
String sql = "select receivablesPlan.receivablesPlanId from CRM_ReceivablesPlan receivablesPlan where (receivablesPlan.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.RPLAN) + ")";
return sql;
} public static String getRRecordSQL(long userId) throws SystemException{
String sql = "select receivablesRecord.receivablesRecordId from CRM_ReceivablesRecord receivablesRecord where (receivablesRecord.ownerId in "
+ OperatorUtil.searchViewOperatorIds(userId,TableConst.RRECORD) + ")";
return sql;
} public static String getSQLBeginningByTableDefinitionId(long tableDefinitionId) throws PortalException, SystemException {
String result = "";
TableDefinition tableDefinition = TableDefinitionLocalServiceUtil.getTableDefinition(tableDefinitionId);
String tableName = tableDefinition.getTableName();
if (tableName.equals(TableConst.CRM_Customer)) {
result = SqlConst.CUSTOMER_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Customer)) {
result = SqlConst.CUSTOMER_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Contact)) {
result = SqlConst.CONTACT_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Market)) {
result = SqlConst.MARKET_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Clue)) {
result = SqlConst.CLUE_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Activity)) {
result = SqlConst.ACTIVITY_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Opportunity)) {
result = SqlConst.OPPORTUNITY_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Quotation)) {
result = SqlConst.QUOTATION_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Contract)) {
result = SqlConst.CONTRACT_SQL_BEGINNING;
} else if (tableName.equals(TableConst.CRM_Product)) {
result = SqlConst.PRODUCT_SQL_BEGINNING;
} else {
result = SqlConst.CUSTOMER_SQL_BEGINNING;
}
return result;
} public static String filterQuery(String columnName){
if (columnName.equals("type") || columnName.equals("code")) {
return columnName + StringPool.UNDERLINE;
} else {
return columnName;
}
} //private static Log _log = LogFactoryUtil.getLog(SQLUtil.class); }
SQL工具类的更多相关文章
- PHP文件上传,下载,Sql工具类!
PHP文件上传,下载,Sql工具类! 对文件大小,文件类型 同名覆盖 中文转码的操作,可直接使用 前台 upload.html <!DOCTYPE html> <html> & ...
- 数据库连接池与SQL工具类
数据库连接池与SQL工具类 1.数据库连接池 依赖包 pymysql dbutils # -*- coding: utf-8 -*- ''' @Time : 2021/11/19 16:45 @Aut ...
- Excel生成Oracle数据库表sql工具类
1.解决问题: 开发文档中字段比较多的时候,建表sql(Oracle下划线命名规范)比较麻烦,容易出错~~ (主要是懒) 特意手写一个工具,根据excel字段,生成建表的sql语句. ~~~末尾附Gi ...
- java学习笔记37(sql工具类:JDBCUtils)
在之前的内容中,我们发现,当我们执行一条语句时,每新建一个方法,就要重新连接一次数据库,代码重复率很高,那么能不能把这些重复代码封装成一个类呢,我们学习方法时,就学习到方法就是为了提高代码的利用率,所 ...
- sql 工具类function
--判断是否为整数 create or replace function is_number(param VARCHAR2) return NUMBER is v_num NUMBER; begin ...
- mysql ----BaseDao工具类
package com.zjw.dao; import java.sql.*; /** * 工具类 */ public class BaseDao { static final String DB_U ...
- 一、JDBC的概述 二、通过JDBC实现对数据的CRUD操作 三、封装JDBC访问数据的工具类 四、通过JDBC实现登陆和注册 五、防止SQL注入
一.JDBC的概述###<1>概念 JDBC:java database connection ,java数据库连接技术 是java内部提供的一套操作数据库的接口(面向接口编程),实现对数 ...
- JDBC课程2--实现Statement(用于执行SQL语句)--使用自定义的JDBCTools的工具类静态方法,包括insert/update/delete三合一
/**JDBC课程2--实现Statement(用于执行SQL语句) * 1.Statement :用于执行SQL语句的对象: * 1): 通过Connection 的createStatement( ...
- JDBC基础:JDBC快速入门,JDBC工具类,SQL注入攻击,JDBC管理事务
JDBC基础 重难点梳理 一.JDBC快速入门 1.jdbc的概念 JDBC(Java DataBase Connectivity:java数据库连接)是一种用于执行SQL语句的Java API,可以 ...
随机推荐
- Android Studio 调试系列之分析堆栈调用
Analyze a Stack Trace 方法:Thread.dumpStack() 一 代码中添加Thread.dumpStack() 二 Android Studio查看堆栈log 三 借助A ...
- java.lang.NoClassDefFoundError: Could not initialize class xxx 原因
一.问题及原因 程序里有个工具类,主要是调用它的静态方法来发送mq. 调用场景如下: 结果这两天报了个错: java.lang.NoClassDefFoundError: Could not init ...
- Android 音视频同步(A/V Sync)
1. 音视频同步原理 1)时间戳 音视频同步主要用于在音视频流的播放过程中,让同一时刻录制的声音和图像在播放的时候尽可能的在同一个时间输出. 解决音视频同步问题的最佳方案就是时间戳:首先选择一个参考 ...
- 【咸鱼教程】Egret可长按识别二维码(精确位置和大小)
教程目录一 实现原理二 实现过程三 Demo下载 本教程是在Egret中实现长按识别的二维码,并可以精确定位二维码的位置和大小,支持横屏和竖屏. 一 实现原理 微信中长按识别二维码,需要长按jpg或p ...
- 惠普hp服务器通过iLO接口远程安装操作系统
我们以hp proliant sl210t的机器为例,我们在配置好iLO接口的远程管理后,我们便可以通过iLO进行操作系统的安装 关于惠普服务器的iLO配置,可参笔者的另一篇文章<关于hp pr ...
- nginx socket转发设置
1.添加依赖模块,如下 --with-stream --with-stream_ssl_module 2.nginx.conf 配置,参考说明:ngx_stream_core_module user ...
- 关于*** WARNING L15: MULTIPLE CALL TO SEGMENT
编写51程序的时候,有时候会在主函数和中断函数里面调用同一个函数,如果正的出现这种情况,编译器会提出 这种警告: *** WARNING L15: MULTIPLE CALL TO SEGMENT(重 ...
- react封装简单的浏览器顶部加载进度条全局组件
在项目中经常会有在请求前后加loading或者加加载进度条,一般这些组件都会抽离出来作为全局组件 进度条的插件貌似都不是很符合自己项目中的需求,于是.. 参考nprogress样式,自己在项目中封装组 ...
- Asp.net MVC]Asp.net MVC5系列——在模型中添加
目录 概述 在模型中添加验证规则 自定义验证规则 伙伴类的使用 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5 ...
- js 字符中 带 函数 再传对象参数
不替换 ( .replace(/\"/g, "\\\"") )则会有错误: Uncaught SyntaxError: missing ) after argu ...