Commit a1fd855b authored by 雍欢's avatar 雍欢

自定义查询SQL方言

parent c37b9fd1
create or replace view `v_sa_oporg_exclude_pos` (`id`, `type_id`, `code`, `name`, `long_name`, `parent_id`, `full_id`, `full_code`, `full_name`, `org_kind_id`, `depth`, `person_id`, `node_kind_id`, `description`, `status`, `sequence`, `version`, `org_code`, `dept_code`, `position_code`, `person_member_code`, `is_center`, `center_code`, `org_id`, `dept_id`, `position_id`, `person_member_id`, `center_id`, `org_name`, `dept_name`, `position_name`, `person_member_name`, `center_name`, `full_sequence`, `full_org_kind_id`, `is_virtual`) as
select id, type_id, code, name, long_name,
(case org_kind_id when 'psm' then dept_id else parent_id end) parent_id,
full_id,
full_code, full_name, org_kind_id, depth, person_id, node_kind_id,
description, status, sequence, version, org_code, dept_code,
position_code, person_member_code, is_center, center_code, org_id,
dept_id, position_id, person_member_id, center_id, org_name,
dept_name, position_name, person_member_name, center_name,
full_sequence, full_org_kind_id, is_virtual
from sa_oporg
where org_kind_id != 'pos';
CREATE
OR REPLACE VIEW V_ACT_HI_PROCINST (
PROC_INST_ID_,
BUSINESS_KEY_,
PROC_DEF_ID_,
PROCESS_DEFINITION_KEY_,
PROC_FULL_ID,
PROC_FULL_NAME,
PROC_NAME,
PROC_SYS_NAME,
START_TIME_,
END_TIME_,
APPLICANT_PERSON_MEMBER_ID_,
APPLICANT_PERSON_MEMBER_NAME_,
APPLICANT_DEPT_NAME_,
APPLICANT_ORG_NAME_,
PROC_STATUS_ID_
) AS SELECT
pe.id_ AS proc_inst_id_,
pe.business_key_,
pe.proc_def_id_,
pe.key_ AS process_definition_key_,
pdf.full_id proc_full_id,
pdf.full_name proc_full_name,
pdf. NAME proc_name,
substr(
pdf.full_name,
2,
instr(substr(pdf.full_name,3), '/') - 2
) proc_sys_name,
pe.start_time_,
pe.end_time_,
pe.applicant_person_member_id_,
pe.applicant_person_member_name_,
pe.applicant_dept_name_,
pe.applicant_org_name_,
pe.status_id_ proc_status_id_
FROM
act_hi_procinst_extension pe
join act_re_procdef pd on pe.proc_def_id_ = pd.id_
left join wf_procdef pdf on pd.key_ = pdf.proc_id
WHERE
pdf.node_kind_id = 'proc';
\ No newline at end of file
DROP VIEW "SYS_USERS_VIEW";
DROP VIEW "SYS_USERS_VIEW"; -- 不需要
DROP VIEW "V_ACT_HI_PROCINST";
DROP VIEW "V_ACT_HI_TASK";
DROP VIEW "V_ACT_HI_TASK_FOR_DELETE";
DROP VIEW "V_ACT_RU_TASK";
DROP VIEW "V_ACT_HI_TASK"; -- 不需要
DROP VIEW "V_ACT_HI_TASK_FOR_DELETE"; -- 不需要
DROP VIEW "V_ACT_RU_TASK"; -- 不需要
DROP VIEW "V_SA_OPORG_EXCLUDE_POS";
CREATE OR REPLACE VIEW "SYS_USERS_VIEW" ("EMPID", "EMPNAME", "USERID", "STATUS", "PASSWORD", "ORGID_ID") AS
......
......@@ -48,12 +48,12 @@ public class AgentApplicationImpl extends BaseApplication implements AgentApplic
@Override
public Agent loadValidAgent(String clientPsmId) {
QueryDescriptor queryDescriptor = this.sqlExecutorDao.getQuery(QUERY_XML_FILE_PATH, "agent");
String sql = queryDescriptor.getSqlByName("loadValid");
Map<String, Object> params = new HashMap<String, Object>(1);
String jpql = queryDescriptor.getSqlByName("loadValid");
Map<String, Object> params = new HashMap<>(1);
params.put("psmId", clientPsmId);
@SuppressWarnings("unchecked")
List<Agent> agents = this.generalRepository.query(sql, params);
List<Agent> agents = this.generalRepository.query(jpql, params);
if (agents.size() > 0) {
return agents.get(0);
}
......
......@@ -18,8 +18,7 @@ public class VersionListener {
private Long getNextId() {
SQLExecutorDao sqlExecutor = ApplicationContextWrapper.getBean("sqlExecutorDao", SQLExecutorDao.class);
QueryDescriptor queryDescriptor = sqlExecutor.getQuery("config/uasp/query/bmp/common.xml", "common");
Long version = sqlExecutor.getSqlQuery().getJDBCDao().queryToLong(queryDescriptor.getSqlByName("nextVersion"));
return version;
return sqlExecutor.getSqlQuery().getJDBCDao().queryToLong(String.format(queryDescriptor.getSqlByName("nextSequence"), "version_seq"));
}
@PrePersist
......
package com.huigou.data.domain.service;
import java.sql.Date;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......
......@@ -13,13 +13,13 @@ public interface JDBCDao {
/**
* 正则表达式去除空格,制表符及换行符
*/
static final Pattern pattern = Pattern.compile("\t|\r|\n");
Pattern pattern = Pattern.compile("\t|\r|\n");
DataSource getDataSource();
/**
* 执行查询返回List<Object[]>
*
*
* @param sql
* @param args
* @return
......@@ -29,7 +29,7 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个 List<T>
*
*
* @param sql
* @param args
* @param cls
......@@ -40,7 +40,7 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个 List<T>
*
*
* @param sql
* @param cls
* @param param
......@@ -51,7 +51,7 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个List,通过mapper组合查询结果
*
*
* @param sql
* @param mapper
* @param args
......@@ -62,19 +62,19 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个List,通过mapper组合查询结果
*
* @author
*
* @param sql
* @param mapper
* @param param
* @return
* @throws
* @author
*/
List<?> queryToListByMapperMapParam(String sql, QueryRowMapper<?> mapper, Map<String, Object> param);
/**
* 执行带参数的查询方法返回一个List<Map<String,Object>>
*
*
* @param sql
* @param mapper
* @param args
......@@ -85,7 +85,7 @@ public interface JDBCDao {
/**
* 执行MAP参数的查询方法返回一个List<Map<String,Object>>
*
*
* @param sql
* @param args
* @return
......@@ -95,7 +95,7 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个Map<String,Object>
*
*
* @param sql
* @param args
* @return
......@@ -105,7 +105,7 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个Map<String,Object>,只查询一条记录
*
*
* @param sql
* @param args
* @return
......@@ -114,7 +114,7 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个Map<String,Object>
*
*
* @param sql
* @param params
* @return
......@@ -124,7 +124,7 @@ public interface JDBCDao {
/**
* 执行带参数的查询方法返回一个Map<String,Object>,只查询一条记录
*
*
* @param sql
* @param params
* @return
......@@ -134,7 +134,7 @@ public interface JDBCDao {
/**
* 执行带参数查询方法返回一个object
*
*
* @param sql
* @param args
* @param cls
......@@ -145,7 +145,7 @@ public interface JDBCDao {
/**
* 执行带参数查询方法返回一个object,只查询一条数据
*
*
* @param sql
* @param cls
* @param args
......@@ -155,7 +155,7 @@ public interface JDBCDao {
/**
* 执行带参数查询方法返回一个object
*
*
* @param sql
* @param cls
* @param param
......@@ -166,7 +166,7 @@ public interface JDBCDao {
/**
* 执行带参数查询方法返回一个object,只查询一条数据
*
*
* @param sql
* @param cls
* @param param
......@@ -176,7 +176,7 @@ public interface JDBCDao {
/**
* 执行查询方法返回一个INT
*
*
* @param sql
* @param args
* @return
......@@ -186,16 +186,18 @@ public interface JDBCDao {
/**
* 查询orcale Sequence
*
*
* @param name
* @return
* @throws Exception
* @deprecated 已被 {@link com.huigou.data.repository.GeneralRepositorySuper#getSequence(String)} 替代。
*/
@Deprecated
Long getSequence(String name);
/**
* 执行查询方法返回一个Long
*
*
* @param sql
* @param args
* @return
......@@ -205,7 +207,7 @@ public interface JDBCDao {
/**
* 执行查询方法返回一个String
*
*
* @param sql
* @param args
* @return
......@@ -215,7 +217,7 @@ public interface JDBCDao {
/**
* 执行带参数的SQL
*
*
* @param sql
* @param args
* @throws SQLException
......@@ -224,7 +226,7 @@ public interface JDBCDao {
/**
* 执行带参数的SQL
*
*
* @param sql
* @param param
* @return
......@@ -233,7 +235,7 @@ public interface JDBCDao {
/**
* 执行批量SQL
*
*
* @param sql
* @throws SQLException
*/
......@@ -241,21 +243,21 @@ public interface JDBCDao {
/**
* 批量执行一条SQL語句
*
*
* @param sql
* @param args
* @throws SQLException
* @例子: String sql = "update table1 set column1=?, column2=? where id=?";
* List<Object[]> dataSet = { { "value11", "value12", 1 }, 第一次執行的參數 {
* "value21", * "value22", 2 },第二次執行的參數 { "value31", "value32", 3 } };
* //第三次執行的參數
* List<Object[]> dataSet = { { "value11", "value12", 1 }, 第一次執行的參數 {
* "value21", * "value22", 2 },第二次執行的參數 { "value31", "value32", 3 } };
* //第三次執行的參數
*/
void batchUpdate(String sql, final List<Object[]> dataSet);
/**
* 执行储存过程
*
*
* @param sql
* @param declaredParameters
* @param params
......@@ -265,31 +267,31 @@ public interface JDBCDao {
/**
* 保存clob字段
*
* @author
*
* @param sql
* @param data
* @param param
* @author
*/
void saveClob(String sql, final String data, final Object... param);
/**
* 从数据库中查询clob字段
*
* @author
*
* @param sql
* @param clobNames
* @param param
* @author
*/
Map<String, Object> loadClob(String sql, final String[] clobNames, final Object... param);
/**
* 从数据库中查询clob字段
*
* @author
*
* @param sql
* @param param
* @return
* @author
*/
String loadClob(String sql, final Object... param);
......
......@@ -299,6 +299,7 @@ public class JDBCDaoImpl implements JDBCDao {
* @return
* @throws Exception
*/
@Override
public Long getSequence(String name) {
String sql = "select " + name + ".nextval from dual";
SqlRowSet srs = (SqlRowSet) jdbcTemplate.query(sql, getResultSetExtractor());
......
......@@ -132,7 +132,7 @@ public class QueryPermissionBuilderImpl implements QueryPermissionBuilder {
}
StringBuffer sb = new StringBuffer();
sb.append("select * from (").append(sql).append(")");
sb.append("select * from (").append(sql).append(") t_t_");
sb.append(" where 1=1 ");
if (StringUtil.hasField(sql, "full_id")) {
List<OrgUnit> list = findSubordinations(operator.getUserId(), operator.getPersonMemberFullIds(), manageType);
......
......@@ -7,6 +7,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.huigou.data.query.executor.SQLExecutorDao;
import com.huigou.util.*;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity;
import org.activiti.engine.task.Task;
......@@ -49,11 +51,6 @@ import com.huigou.uasp.bpm.engine.repository.HistoricTaskInstanceExtensionReposi
import com.huigou.uasp.bpm.engine.repository.HistoricTaskInstanceRelationRepository;
import com.huigou.uasp.bpm.engine.repository.RuntimeTaskExtensionRepository;
import com.huigou.uasp.bpm.managment.application.ProcDefinitionApplication;
import com.huigou.util.ClassHelper;
import com.huigou.util.CommonUtil;
import com.huigou.util.Constants;
import com.huigou.util.StringUtil;
import com.huigou.util.Util;
@Service("actApplication")
public class ActApplicationImpl extends BaseApplication implements ActApplication {
......@@ -160,7 +157,8 @@ public class ActApplicationImpl extends BaseApplication implements ActApplicatio
HistoricTaskInstanceExtension historicTaskInstExtension = new HistoricTaskInstanceExtension(runtimeTaskExtension);
// 增加版本号保存
Long version = this.sqlExecutorDao.getSequence("version_seq");
QueryDescriptor queryDescriptor = sqlExecutorDao.getQuery("config/uasp/query/bmp/common.xml", "common");
long version = sqlExecutorDao.getSqlQuery().getJDBCDao().queryToLong(String.format(queryDescriptor.getSqlByName("nextVersion")));
runtimeTaskExtension.setVersion(version);
runtimeTaskExtensionRepository.save(runtimeTaskExtension);
historicTaskInstExtension.setVersion(version);
......@@ -317,8 +315,7 @@ public class ActApplicationImpl extends BaseApplication implements ActApplicatio
/**
* 检查任务ID不能为空
*
* @param taskId
* 任务ID
* @param taskId 任务ID
*/
private void checkTaskIdNotNull(String taskId) {
Util.check(!StringUtil.isBlank(taskId), "任务ID不能为空,请刷新页面后重试。");
......@@ -475,7 +472,7 @@ public class ActApplicationImpl extends BaseApplication implements ActApplicatio
if (StringUtil.isNotBlank(currentItem.getProcUnitHandlerId()) && currentItem.getGroupId().equals(0)) {
iterator.remove();
} else if (currentItem.getProcessDefinitionGroupId() > currentProcUnitProcessDefinitionGroupId
|| (currentItem.getProcessDefinitionGroupId().equals(currentProcUnitProcessDefinitionGroupId) && currentItem.getGroupId() >= groupId)) {
|| (currentItem.getProcessDefinitionGroupId().equals(currentProcUnitProcessDefinitionGroupId) && currentItem.getGroupId() >= groupId)) {
iterator.remove();
}
}
......@@ -488,7 +485,7 @@ public class ActApplicationImpl extends BaseApplication implements ActApplicatio
for (int j = i + 1; j < backTasks.size(); j++) {
nextItem = backTasks.get(j);
if (currentItem.getTaskDefKey().equals(nextItem.getTaskDefKey()) && currentItem.getGroupId().equals(nextItem.getGroupId())
&& currentItem.getExecutorFullName().equals(nextItem.getExecutorFullName())) {
&& currentItem.getExecutorFullName().equals(nextItem.getExecutorFullName())) {
removedBackTaskInfos.add(nextItem);
}
}
......
......@@ -18,10 +18,10 @@ public interface HistoricTaskInstanceExtensionRepository extends JpaRepository<H
List<HistoricTaskInstanceExtension> findByProcUnitHandlerIdOrderByVersion(String procUnitHandlerId);
@Query(name = "historicTaskInstExtension.findApplicantTask", value = "from HistoricTaskInstanceExtension o where o.businessKey = ?1 and o.taskDefinitionKey = 'Apply' and o.previousId is null")
@Query(name = "historicTaskInstExtension.findApplicantTask", value = "from HistoricTaskInstanceExtension o where o.businessKey = ?1 and o.taskDefinitionKey = 'Apply' and (o.previousId is null or o.previousId='')")
HistoricTaskInstanceExtension findApplicantTask(String bizId);
@Query(name = "historicTaskInstExtension.findApplicantTaskByBizCode", value = "from HistoricTaskInstanceExtension o where o.businessCode = ?1 and o.taskDefinitionKey = 'Apply' and o.previousId is null")
@Query(name = "historicTaskInstExtension.findApplicantTaskByBizCode", value = "from HistoricTaskInstanceExtension o where o.businessCode = ?1 and o.taskDefinitionKey = 'Apply' and (o.previousId is null or o.previousId='')")
HistoricTaskInstanceExtension findApplicantTaskByBizCode(String bizCode);
List<HistoricTaskInstanceExtension> findByBusinessKeyAndTaskDefinitionKey(String bizId, String procUnitId);
......
......@@ -5,7 +5,7 @@
select next_sequence('version_seq')
</sql>
<sql name="nextSequence">
SELECT next_sequence(%s)
SELECT next_sequence('%s')
</sql>
<sql name="updateFullName">
update %s
......
......@@ -783,7 +783,7 @@
from Agent o left join o.client
where o.client.id = :psmId
and o.status = 1
and sysdate between o.startDate and o.endDate
and current_date between o.startDate and o.endDate
</sql>
<condition column="start_date" name="startDate" symbol="&gt;=" type="java.util.Date" alias="t"/>
<condition column="end_date" name="endDate" symbol="&lt;=" type="java.util.Date" alias="t"/>
......
......@@ -90,6 +90,11 @@
<artifactId>huigou-uasp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.huigou</groupId>
<artifactId>huigou-demo</artifactId>
<version>${project.version}</version>
</dependency>
<!-- 公用的组件包 -->
<dependency>
<groupId>commons-lang</groupId>
......
......@@ -22,6 +22,11 @@
<property name="queryXmlManager" ref="queryXmlManager" />
</bean>
<bean id="mapperScannerConfigurer" class="com.topsunit.query.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.huigou.**.mapper"/>
<property name="sqlExecutorBeanName" value="sqlExecutorDao" />
</bean>
<bean id="generalRepository" class="com.huigou.data.repository.GeneralRepository">
</bean>
......
......@@ -19,6 +19,7 @@
<module>huigou-uasp</module>
<module>huigou-loader</module>
<module>huigou-xt</module>
<module>huigou-demo</module>
</modules>
<properties>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment