/** * *************************************************************************** * Copyright (c) 2010 Qcadoo Limited * Project: Qcadoo Framework * Version: 1.4 *
* This file is part of Qcadoo. *
* Qcadoo is free software; you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation; either version 3 of the License, * or (at your option) any later version. *
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License for more details. *
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ***************************************************************************
*/
package com.ruoyi.common.numgen;
import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @author zhangxy
*/
@AllArgsConstructor
@Service
public class NumberGeneratorModelHelper {
private JdbcTemplate jdbcTemplate;
private static final String NUMBER_EXIST_QUERY_TEMPLATE = "select count(*) from ${TABLE_NAME} where ${NUMBER_FIELD}='${VALUE}'";
private static final String GET_NUMBERS_QUERY_TEMPLATE = "select MAX( CAST( "
+ " coalesce(TRIM(LEADING '0' from ${NUMBER_FIELD}), '0') "
+ " AS UNSIGNED ) ) "
+ "from ${TABLE_NAME} where 1=1";
private static final String GET_PREFIX_AWARE_NUMBERS_QUERY_TEMPLATE = "select MAX( CAST( "
+ " TRIM(LEADING '0' from SUBSTRING(${NUMBER_FIELD}, ${NUMBER_STARTS_AT})) "
+ " AS UNSIGNED ) ) "
+ "from ${TABLE_NAME} where ${NUMBER_FIELD} like '${PREFIX}%'";
private static final String GET_SUFFIX_AWARE_NUMBERS_QUERY_TEMPLATE = "select MAX( CAST( "
+ " TRIM(LEADING '0' from SUBSTRING(${NUMBER_FIELD}, 1, POSITION('${SUFFIX}' IN ${NUMBER_FIELD}) - 1)) "
+ " AS UNSIGNED )) "
+ "from ${TABLE_NAME} where ${NUMBER_FIELD} like '%${SUFFIX}'";
public boolean numberExist(final String value, final NumberTableInfo numberTableInfo) {
Map