chore: 落地 eip4-platform 多模块骨架基线(PoC→工程化)
从 eip4-poc 迁入双层制模块化单体:保真层 platform-legacy-core (com.dsasp 引擎原样)+ 现代层 platform-metadata/auth/flow-gateway/ converter/ai + platform-app 启动器。ArchUnit 纪律固化(保真层禁依赖现代层)。 此为 C1 对拍工作的编译通过基线。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
24
platform-legacy-core/pom.xml
Normal file
24
platform-legacy-core/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.eip4</groupId>
|
||||
<artifactId>eip4-platform</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>platform-legacy-core</artifactId>
|
||||
<name>platform-legacy-core</name>
|
||||
<description>保真层:移植引擎原样,包名 com.dsasp.* 不动。对拍=完成定义,与 framework 源码 diff 保持最小</description>
|
||||
<dependencies>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency>
|
||||
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId></dependency>
|
||||
<dependency><groupId>org.dom4j</groupId><artifactId>dom4j</artifactId></dependency>
|
||||
<dependency><groupId>jaxen</groupId><artifactId>jaxen</artifactId></dependency>
|
||||
<dependency><groupId>org.apache.groovy</groupId><artifactId>groovy-jsr223</artifactId></dependency>
|
||||
<dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId></dependency>
|
||||
<dependency><groupId>org.json</groupId><artifactId>json</artifactId></dependency>
|
||||
<dependency><groupId>jakarta.servlet</groupId><artifactId>jakarta.servlet-api</artifactId><scope>provided</scope></dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dsasp.client.viewframework.template.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植替换类:原版把脚本日志推送到 Vaadin MainComponent 的浏览器控制台。
|
||||
* 保持静态方法签名不变,实现降级为 slf4j 日志输出。
|
||||
*/
|
||||
public class Console {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger("eip3.script.console");
|
||||
|
||||
public static void error(Object errMsg) {
|
||||
LOG.error(convert(errMsg));
|
||||
}
|
||||
|
||||
public static void log(Object logMsg) {
|
||||
LOG.info(convert(logMsg));
|
||||
}
|
||||
|
||||
public static void debug(Object debugMsg) {
|
||||
LOG.debug(convert(debugMsg));
|
||||
}
|
||||
|
||||
public static void info(Object infoMsg) {
|
||||
LOG.info(convert(infoMsg));
|
||||
}
|
||||
|
||||
private static String convert(Object msg) {
|
||||
if (msg == null) {
|
||||
return "null";
|
||||
}
|
||||
if (msg instanceof Throwable t) {
|
||||
StringWriter sw = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(sw));
|
||||
return sw.toString();
|
||||
}
|
||||
return String.valueOf(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dsasp.server.common.core;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface Function {
|
||||
|
||||
/**
|
||||
* function name
|
||||
* @return
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* use function tip
|
||||
* @return
|
||||
*/
|
||||
String tip();
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package com.dsasp.server.common.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
|
||||
public class OriginServiceBean{
|
||||
|
||||
private String beanName;
|
||||
|
||||
private String method;
|
||||
|
||||
private List<String> arg;
|
||||
|
||||
private String returnResult;
|
||||
|
||||
private String type;
|
||||
|
||||
private String description;
|
||||
|
||||
private String displayName;
|
||||
|
||||
private String id;
|
||||
|
||||
public OriginServiceBean(){
|
||||
|
||||
}
|
||||
|
||||
public OriginServiceBean(GeneralPOJO po){
|
||||
id = po.get_ID();
|
||||
beanName = (String)po.get_Value(CLASSNAME);
|
||||
method = (String)po.get_Value(METHODNAME);
|
||||
returnResult = (String)po.get_Value(RETURNCLASSNAME);
|
||||
type = (String)po.get_Value(TYPE);
|
||||
description = (String)po.get_Value(DESCRIPTION);
|
||||
displayName = (String)po.get_Value(NAME);
|
||||
List<GeneralPOJO> list = (List<GeneralPOJO>)po.get_Value(ARGS);
|
||||
if(list != null && list.size() > 0){
|
||||
arg = new ArrayList<String>();
|
||||
for(GeneralPOJO pojo : list){
|
||||
arg.add((String)pojo.get_Value(ARGCLASSNAME));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getArg() {
|
||||
return arg;
|
||||
}
|
||||
|
||||
|
||||
public String getReturnResult() {
|
||||
return returnResult;
|
||||
}
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public void setArg(List<String> arg) {
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
public void setReturnResult(String returnResult) {
|
||||
this.returnResult = returnResult;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pojo
|
||||
*/
|
||||
public void updateToPO(GeneralPOJO pojo){
|
||||
pojo.set_ValueOfColumn(TYPE, type);
|
||||
pojo.set_ValueOfColumn(NAME, displayName);
|
||||
pojo.set_ValueOfColumn(CLASSNAME, beanName);
|
||||
pojo.set_ValueOfColumn(METHODNAME, method);
|
||||
pojo.set_ValueOfColumn(DESCRIPTION, description);
|
||||
pojo.set_ValueOfColumn(RETURNCLASSNAME, returnResult);
|
||||
|
||||
if(arg != null && arg.size() > 0){
|
||||
List<Map> list = new ArrayList<Map>();
|
||||
String originServiceId = pojo.get_ID();
|
||||
for(int i = 0; i < arg.size(); i ++){
|
||||
String a = arg.get(i);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(ORIGINSERVICEID, originServiceId);
|
||||
map.put(ARGCLASSNAME, a);
|
||||
map.put(SEQUENCE, i);
|
||||
list.add(map);
|
||||
}
|
||||
pojo.set_ValueOfColumn(ARGS, list);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> convertToMap(){
|
||||
Map<String, Object> list = new HashMap<String, Object>();
|
||||
list.put(TYPE, type);
|
||||
list.put(NAME, displayName);
|
||||
list.put(CLASSNAME, beanName);
|
||||
list.put(METHODNAME, method);
|
||||
list.put(DESCRIPTION, description);
|
||||
list.put(RETURNCLASSNAME, returnResult);
|
||||
if(arg != null && arg.size() > 0){
|
||||
List<Map> args = new ArrayList<Map>();
|
||||
for(int i = 0; i < arg.size(); i++){
|
||||
String a = arg.get(i);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(ARGCLASSNAME, a);
|
||||
map.put(SEQUENCE, i);
|
||||
args.add(map);
|
||||
}
|
||||
list.put(ARGS, args);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public static final String TYPE = "TYPE";
|
||||
public static final String NAME = "NAME";
|
||||
public static final String CLASSNAME = "CLASSNAME";
|
||||
public static final String METHODNAME = "METHODNAME";
|
||||
public static final String DESCRIPTION = "DESCRIPTION";
|
||||
public static final String RETURNCLASSNAME = "RETURNCLASSNAME";
|
||||
|
||||
public static final String ARGCLASSNAME = "ARGCLASSNAME";
|
||||
public static final String ARGS = "ARGS";
|
||||
public static final String ORIGINSERVICEID = "ORIGINSERVICEID";
|
||||
public static final String SEQUENCE = "SEQUENCE";
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dsasp.server.common.core.service;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
/**
|
||||
* mark the function is a origin service. it is use in a service bean
|
||||
* @author wuqz
|
||||
*
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface OriginServiceMethod {
|
||||
String name();
|
||||
String type();
|
||||
String description();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dsasp.server.common.core.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.dsasp.server.common.core.OriginServiceBean;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版在 OSGi bundle 启动时 SAX 扫描 /META-INF/spring 下的
|
||||
* service bean XML 注册 OriginServiceBean。PoC 不加载旧式服务流 XML,
|
||||
* 保留静态 classList 契约(空列表),parserXml 退化为 no-op。
|
||||
*/
|
||||
public class ScanServiceBeanXml {
|
||||
|
||||
public static List<OriginServiceBean> classList = new ArrayList<OriginServiceBean>();
|
||||
|
||||
public static void parserXml(Object bundleContext) {
|
||||
// no-op:旧式 OriginService XML 不在 WS1 验证范围
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.dsasp.server.common.core.service;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植替换类:原版是 OSGi BundleListener,遍历 bundle 注册服务按
|
||||
* "org.springframework.osgi.bean.name" 取 bean(72 行服务定位器)。
|
||||
* 这里保持类名、包名与 getInstance().getBeanByName() 调用契约不变,
|
||||
* 实现降级为对单一 Spring ApplicationContext 的查找,旧代码零修改。
|
||||
*/
|
||||
@Component
|
||||
public class SpringBeanOsgiServices implements ApplicationContextAware {
|
||||
|
||||
private static SpringBeanOsgiServices servicesContext;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
public SpringBeanOsgiServices() {
|
||||
servicesContext = this;
|
||||
}
|
||||
|
||||
public static SpringBeanOsgiServices getInstance() {
|
||||
return servicesContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public Object getBeanByName(String beanName) {
|
||||
if (beanName == null || beanName.isEmpty() || applicationContext == null) {
|
||||
return null;
|
||||
}
|
||||
if (!applicationContext.containsBean(beanName)) {
|
||||
return null;
|
||||
}
|
||||
return applicationContext.getBean(beanName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
|
||||
|
||||
|
||||
public abstract class AbstractPOJOInfo implements POJOInfo {
|
||||
|
||||
protected static CCache<String, POJOInfo> s_cache = new CCache<String, POJOInfo>("POInfo", 200);
|
||||
protected static CCache<String, String> id_cache = new CCache<String, String>("TableName", 200);
|
||||
|
||||
/**
|
||||
* POInfo Factory
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID AD_Table_ID
|
||||
* @param trxName Transaction name
|
||||
* @return POInfo
|
||||
*/
|
||||
public static POJOInfo getPOInfo (String AD_Table_Name)
|
||||
{
|
||||
//FIXME: load tableName info
|
||||
String key = AD_Table_Name;
|
||||
POJOInfo retValue = (POJOInfo)s_cache.get(key);
|
||||
if (retValue == null)
|
||||
{
|
||||
retValue = ((DataDicService)SpringBeanOsgiServices.getInstance().getBeanByName("dataDicService")).loadInfo(AD_Table_Name);
|
||||
s_cache.put(key, retValue);
|
||||
if(id_cache.get(retValue.getAD_Table_ID()) == null){
|
||||
id_cache.put(retValue.getAD_Table_ID(), retValue.getTableName());
|
||||
}
|
||||
}
|
||||
return retValue;
|
||||
} // getPOInfo
|
||||
|
||||
public static String getTableName(String entityId){
|
||||
String tableName = id_cache.get(entityId);
|
||||
if(StringUtil.isEmpty(tableName)){
|
||||
SYS_Entity entity = ((DataDicService)SpringBeanOsgiServices.getInstance().getBeanByName("dataDicService")).getSYSEntity(entityId);
|
||||
tableName = (String)entity.getPo().get_Value("TABLENAME");
|
||||
id_cache.put(entityId, tableName);
|
||||
}
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public static void setChangePOInfo(String entityId){
|
||||
String tableName = id_cache.remove(entityId);
|
||||
if(!StringUtil.isEmpty(tableName)){
|
||||
s_cache.remove(tableName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植替换类:原版为 Adempiere CCache(HashMap + 过期 + CacheMgt 全局注册,
|
||||
* GPL-2 头)。移植代码只使用其 Map API(get/put/containsKey),故重写为最小实现,
|
||||
* 去除 CacheInterface/CacheMgt 依赖与 GPL 来源代码。构造器签名保持兼容。
|
||||
*/
|
||||
public class CCache<K, V> extends HashMap<K, V> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String name;
|
||||
|
||||
public CCache(String name, int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CCache(String name, int initialCapacity, int expireMinutes) {
|
||||
this(name, initialCapacity);
|
||||
// PoC:元数据缓存不做过期;如需失效调用 reset()
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int reset() {
|
||||
int size = size();
|
||||
clear();
|
||||
return size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
public class CustomSearchConditional {
|
||||
|
||||
private String conditional;
|
||||
|
||||
public CustomSearchConditional(String conditional){
|
||||
this.conditional = conditional;
|
||||
}
|
||||
|
||||
public String getConditional() {
|
||||
return conditional;
|
||||
}
|
||||
|
||||
public void setConditional(String conditional) {
|
||||
this.conditional = conditional;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,682 @@
|
||||
/******************************************************************************
|
||||
* Product: Compiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. 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 General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* System Display Types.
|
||||
* <pre>
|
||||
* SELECT AD_Reference_ID, Name FROM AD_Reference WHERE ValidationType = 'D'
|
||||
* </pre>
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DisplayType.java,v 1.6 2006/08/30 20:30:44 comdivision Exp $
|
||||
*
|
||||
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||
* <li>BF [ 1810632 ] PricePrecision error in InfoProduct (and similar)
|
||||
*/
|
||||
public final class DisplayType
|
||||
{
|
||||
// /** Display Type 10 String */
|
||||
// public static final int String = 10;
|
||||
// /** Display Type 11 Integer */
|
||||
// public static final int Integer = 11;
|
||||
// /** Display Type 12 Amount */
|
||||
// public static final int Amount = 12;
|
||||
// /** Display Type 13 ID */
|
||||
// public static final int ID = 13;
|
||||
// /** Display Type 14 Text */
|
||||
// public static final int Text = 14;
|
||||
// /** Display Type 15 Date */
|
||||
// public static final int Date = 15;
|
||||
// /** Display Type 16 DateTime */
|
||||
// public static final int DateTime = 16;
|
||||
// /** Display Type 17 List */
|
||||
// public static final int List = 17;
|
||||
// /** Display Type 18 Table */
|
||||
// public static final int Table = 18;
|
||||
// /** Display Type 19 TableDir */
|
||||
// public static final int TableDir = 19;
|
||||
// /** Display Type 20 YN */
|
||||
// public static final int YesNo = 20;
|
||||
// /** Display Type 21 Location */
|
||||
// public static final int Location = 21;
|
||||
// /** Display Type 22 Number */
|
||||
// public static final int Number = 22;
|
||||
// /** Display Type 23 BLOB */
|
||||
// public static final int Binary = 23;
|
||||
// /** Display Type 24 Time */
|
||||
// public static final int Time = 24;
|
||||
// /** Display Type 25 Account */
|
||||
// public static final int Account = 25;
|
||||
// /** Display Type 26 RowID */
|
||||
// public static final int RowID = 26;
|
||||
// /** Display Type 27 Color */
|
||||
// public static final int Color = 27;
|
||||
// /** Display Type 28 Button */
|
||||
// public static final int Button = 28;
|
||||
// /** Display Type 29 Quantity */
|
||||
// public static final int Quantity = 29;
|
||||
// /** Display Type 30 Search */
|
||||
// public static final int Search = 30;
|
||||
// /** Display Type 31 Locator */
|
||||
// public static final int Locator = 31;
|
||||
// /** Display Type 32 Image */
|
||||
// public static final int Image = 32;
|
||||
// /** Display Type 33 Assignment */
|
||||
// public static final int Assignment = 33;
|
||||
// /** Display Type 34 Memo */
|
||||
// public static final int Memo = 34;
|
||||
// /** Display Type 35 PAttribute */
|
||||
// public static final int PAttribute = 35;
|
||||
// /** Display Type 36 CLOB */
|
||||
// public static final int TextLong = 36;
|
||||
// /** Display Type 37 CostPrice */
|
||||
// public static final int CostPrice = 37;
|
||||
// /** Display Type 38 File Path */
|
||||
// public static final int FilePath = 38;
|
||||
// /** Display Type 39 File Name */
|
||||
// public static final int FileName = 39;
|
||||
// /** Display Type 40 URL */
|
||||
// public static final int URL = 40;
|
||||
// /** Display Type 42 PrinterName */
|
||||
// public static final int PrinterName = 42;
|
||||
// Candidates:
|
||||
|
||||
|
||||
/** Display Type 10 String */
|
||||
public static final String String = "NVARCHAR";
|
||||
// /** Display Type 11 Integer */
|
||||
public static final String Integer = "INTEGER";
|
||||
// /** Display Type 12 Amount */
|
||||
// public static final int Amount = 12;
|
||||
// /** Display Type 13 ID */
|
||||
public static final String ID = "CHAR";
|
||||
// /** Display Type 14 Text */
|
||||
// public static final int Text = 14;
|
||||
// /** Display Type 15 Date */
|
||||
public static final String Date = "DATE";
|
||||
// /** Display Type 16 DateTime */
|
||||
public static final String DateTime = "TIME";
|
||||
// /** Display Type 17 List */
|
||||
public static final String List = "LIST";
|
||||
// /** Display Type 18 Table */
|
||||
// public static final int Table = 18;
|
||||
// /** Display Type 19 TableDir */
|
||||
// public static final int TableDir = 19;
|
||||
// /** Display Type 20 YN */
|
||||
public static final String YesNo = "BOOLEAN";
|
||||
// /** Display Type 21 Location */
|
||||
// public static final int Location = 21;
|
||||
// /** Display Type 22 Number */
|
||||
public static final String Number = "DECIMAL";
|
||||
|
||||
public static final String Money = "MONEY";
|
||||
|
||||
public static final String ENUMERATE = "ENUMERATE";
|
||||
|
||||
// /** Display Type 23 BLOB */
|
||||
public static final String Binary = "BLOB";
|
||||
|
||||
public static final String Code = "CODE";
|
||||
|
||||
public static final String STATUS = "STATUS";
|
||||
|
||||
|
||||
// /** Display Type 24 Time */
|
||||
// public static final int Time = 24;
|
||||
// /** Display Type 25 Account */
|
||||
// public static final int Account = 25;
|
||||
// /** Display Type 26 RowID */
|
||||
// public static final int RowID = 26;
|
||||
// /** Display Type 27 Color */
|
||||
// public static final int Color = 27;
|
||||
// /** Display Type 28 Button */
|
||||
// public static final int Button = 28;
|
||||
// /** Display Type 29 Quantity */
|
||||
// public static final int Quantity = 29;
|
||||
// /** Display Type 30 Search */
|
||||
// public static final int Search = 30;
|
||||
// /** Display Type 31 Locator */
|
||||
// public static final int Locator = 31;
|
||||
// /** Display Type 32 Image */
|
||||
// public static final int Image = 32;
|
||||
// /** Display Type 33 Assignment */
|
||||
// public static final int Assignment = 33;
|
||||
// /** Display Type 34 Memo */
|
||||
// public static final int Memo = 34;
|
||||
// /** Display Type 35 PAttribute */
|
||||
// public static final int PAttribute = 35;
|
||||
// /** Display Type 36 CLOB */
|
||||
// public static final int TextLong = 36;
|
||||
// /** Display Type 37 CostPrice */
|
||||
// public static final int CostPrice = 37;
|
||||
// /** Display Type 38 File Path */
|
||||
// public static final int FilePath = 38;
|
||||
// /** Display Type 39 File Name */
|
||||
// public static final int FileName = 39;
|
||||
// /** Display Type 40 URL */
|
||||
// public static final int URL = 40;
|
||||
// /** Display Type 42 PrinterName */
|
||||
// public static final int PrinterName = 42;
|
||||
|
||||
/**
|
||||
* - New Display Type
|
||||
INSERT INTO AD_REFERENCE
|
||||
(AD_REFERENCE_ID, AD_CLIENT_ID,AD_ORG_ID,ISACTIVE,CREATED,CREATEDBY,UPDATED,UPDATEDBY,
|
||||
NAME,DESCRIPTION,HELP, VALIDATIONTYPE,VFORMAT,ENTITYTYPE)
|
||||
VALUES (35, 0,0,'Y',SysDate,0,SysDate,0,
|
||||
'PAttribute','Product Attribute',null,'D',null,'D');
|
||||
*
|
||||
* - org.compiere.model.MModel (??)
|
||||
* - org.compiere.grid.ed.VEditor/Dialog
|
||||
* - org.compiere.grid.ed.VEditorFactory
|
||||
* - RColumn, WWindow
|
||||
* add/check 0_cleanupAD.sql
|
||||
*/
|
||||
|
||||
// See DBA_DisplayType.sql ----------------------------------------------
|
||||
|
||||
/** Maximum number of digits */
|
||||
private static final int MAX_DIGITS = 28; // Oracle Standard Limitation 38 digits
|
||||
/** Digits of an Integer */
|
||||
private static final int INTEGER_DIGITS = 10;
|
||||
/** Maximum number of fractions */
|
||||
private static final int MAX_FRACTION = 12;
|
||||
/** Default Amount Precision */
|
||||
private static final int AMOUNT_FRACTION = 2;
|
||||
|
||||
/** Logger */
|
||||
// private static CLogger s_log = CLogger.getCLogger (DisplayType.class);
|
||||
|
||||
/**
|
||||
* Returns true if (numeric) ID (Table, Search, Account, ..).
|
||||
* (stored as Integer)
|
||||
* @param displayType Display Type
|
||||
* @return true if ID
|
||||
*/
|
||||
public static boolean isID (String displayType)
|
||||
{
|
||||
// if (displayType == ID || displayType == Table || displayType == TableDir
|
||||
// || displayType == Search || displayType == Location || displayType == Locator
|
||||
// || displayType == Account || displayType == Assignment || displayType == PAttribute
|
||||
// || displayType == Image || displayType == Color)
|
||||
// return true;
|
||||
// return false;
|
||||
if(ID.equals(displayType)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} // isID
|
||||
|
||||
/**
|
||||
* Returns true, if DisplayType is numeric (Amount, Number, Quantity, Integer).
|
||||
* (stored as BigDecimal)
|
||||
* @param displayType Display Type
|
||||
* @return true if numeric
|
||||
*/
|
||||
public static boolean isNumeric(String displayType)
|
||||
{
|
||||
if (Money.equals(displayType) || Number.equals(displayType))
|
||||
return true;
|
||||
return false;
|
||||
} // isNumeric
|
||||
|
||||
/**
|
||||
* Get Default Precision.
|
||||
* Used for databases who cannot handle dynamic number precision.
|
||||
* @param displayType display type
|
||||
* @return scale (decimal precision)
|
||||
*/
|
||||
public static int getDefaultPrecision(int displayType)
|
||||
{
|
||||
if (Number.equals(displayType))
|
||||
return 6;
|
||||
return 0;
|
||||
} // getDefaultPrecision
|
||||
|
||||
|
||||
/**
|
||||
* Returns true, if DisplayType is text (String, Text, TextLong, Memo).
|
||||
* @param displayType Display Type
|
||||
* @return true if text
|
||||
*/
|
||||
public static boolean isText(String displayType)
|
||||
{
|
||||
if (String.equals(displayType) || Code.equals(displayType))
|
||||
return true;
|
||||
return false;
|
||||
} // isText
|
||||
|
||||
/**
|
||||
* Returns true if DisplayType is a Date.
|
||||
* (stored as Timestamp)
|
||||
* @param displayType Display Type
|
||||
* @return true if date
|
||||
*/
|
||||
public static boolean isDate (String displayType)
|
||||
{
|
||||
if (Date.equals(displayType) || DateTime.equals(displayType))
|
||||
return true;
|
||||
return false;
|
||||
} // isDate
|
||||
|
||||
/**
|
||||
* Returns true if DisplayType is a VLookup (List, Table, TableDir, Search).
|
||||
* (stored as Integer)
|
||||
* @param displayType Display Type
|
||||
* @return true if Lookup
|
||||
*/
|
||||
public static boolean isLookup(String displayType)
|
||||
{
|
||||
if (List.equals(displayType))
|
||||
return true;
|
||||
return false;
|
||||
} // isLookup
|
||||
|
||||
/**
|
||||
* Returns true if DisplayType is a Large Object
|
||||
* @param displayType Display Type
|
||||
* @return true if LOB
|
||||
*/
|
||||
public static boolean isLOB (String displayType)
|
||||
{
|
||||
if (Binary.equals(displayType))
|
||||
return true;
|
||||
return false;
|
||||
} // isLOB
|
||||
|
||||
/**************************************************************************
|
||||
* Return Format for numeric DisplayType
|
||||
* @param displayType Display Type (default Number)
|
||||
* @param language Language
|
||||
* @param pattern Java Number Format pattern e.g. "#,##0.00"
|
||||
* @return number format
|
||||
*/
|
||||
public static DecimalFormat getNumberFormat(String displayType, Locale locale, String pattern)
|
||||
{
|
||||
|
||||
DecimalFormat format = null;
|
||||
if (locale != null)
|
||||
format = (DecimalFormat)NumberFormat.getNumberInstance(locale);
|
||||
else
|
||||
format = (DecimalFormat)NumberFormat.getNumberInstance(Locale.CHINA);
|
||||
//
|
||||
if (pattern != null && pattern.length() > 0)
|
||||
{
|
||||
try {
|
||||
format.applyPattern(pattern);
|
||||
return format;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// s_log.log(Level.WARNING, "Invalid number format: " + pattern);
|
||||
}
|
||||
}
|
||||
else if (displayType == Integer)
|
||||
{
|
||||
format.setParseIntegerOnly(true);
|
||||
format.setMaximumIntegerDigits(INTEGER_DIGITS);
|
||||
format.setMaximumFractionDigits(0);
|
||||
}
|
||||
else // if (displayType == Number)
|
||||
{
|
||||
format.setMaximumIntegerDigits(MAX_DIGITS);
|
||||
format.setMaximumFractionDigits(MAX_FRACTION);
|
||||
format.setMinimumFractionDigits(1);
|
||||
}
|
||||
return format;
|
||||
} // getDecimalFormat
|
||||
|
||||
/**************************************************************************
|
||||
* Return Format for numeric DisplayType
|
||||
* @param displayType Display Type (default Number)
|
||||
* @param language Language
|
||||
* @return number format
|
||||
*/
|
||||
public static DecimalFormat getNumberFormat(String displayType, Locale locale)
|
||||
{
|
||||
return getNumberFormat(displayType, locale, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Format for numeric DisplayType
|
||||
* @param displayType Display Type
|
||||
* @return number format
|
||||
*/
|
||||
public static DecimalFormat getNumberFormat(String displayType)
|
||||
{
|
||||
return getNumberFormat (displayType, null);
|
||||
} // getNumberFormat
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Return Date Format
|
||||
* @return date format
|
||||
*/
|
||||
public static SimpleDateFormat getDateFormat()
|
||||
{
|
||||
return getDateFormat (DisplayType.Date, null);
|
||||
} // getDateFormat
|
||||
|
||||
|
||||
/**
|
||||
* Return format for date displayType
|
||||
* @param displayType Display Type
|
||||
* @return date format
|
||||
*/
|
||||
public static SimpleDateFormat getDateFormat (String displayType)
|
||||
{
|
||||
return getDateFormat (displayType, null);
|
||||
} // getDateFormat
|
||||
|
||||
/**
|
||||
* Return format for date displayType
|
||||
* @param displayType Display Type (default Date)
|
||||
* @param language Language
|
||||
* @return date format
|
||||
*/
|
||||
public static SimpleDateFormat getDateFormat (String displayType, Locale locale)
|
||||
{
|
||||
return getDateFormat(displayType, locale, null);
|
||||
}
|
||||
/**
|
||||
* Return format for date displayType
|
||||
* @param displayType Display Type (default Date)
|
||||
* @param language Language
|
||||
* @param pattern Java Simple Date Format pattern e.g. "dd/MM/yy"
|
||||
* @return date format
|
||||
*/
|
||||
public static SimpleDateFormat getDateFormat (String displayType, Locale locale, String pattern)
|
||||
{
|
||||
// Language myLanguage = language;
|
||||
// if (myLanguage == null)
|
||||
// myLanguage = Language.getLoginLanguage();
|
||||
// //
|
||||
if ( pattern != null && pattern.length() > 0)
|
||||
{
|
||||
SimpleDateFormat format = (SimpleDateFormat)DateFormat.getInstance();
|
||||
try {
|
||||
format.applyPattern(pattern);
|
||||
return format;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// s_log.log(Level.WARNING, "Invalid date pattern: " + pattern);
|
||||
}
|
||||
}
|
||||
|
||||
if (displayType == DateTime)
|
||||
return getDateTimeFormat(locale);
|
||||
// else if (displayType == Date)
|
||||
return getDateFormat(locale); // default
|
||||
} // getDateFormat
|
||||
|
||||
/**
|
||||
* JDBC Date Format YYYY-MM-DD
|
||||
* @return date format
|
||||
*/
|
||||
static public SimpleDateFormat getDateFormat_JDBC()
|
||||
{
|
||||
return new SimpleDateFormat ("yyyy-MM-dd");
|
||||
} // getDateFormat_JDBC
|
||||
|
||||
/**
|
||||
* JDBC Timestamp Format yyyy-mm-dd hh:mm:ss
|
||||
* @return timestamp format
|
||||
*/
|
||||
static public SimpleDateFormat getTimestampFormat_Default()
|
||||
{
|
||||
return new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
|
||||
} // getTimestampFormat_JDBC
|
||||
|
||||
/**
|
||||
* Return Storage Class.
|
||||
* (used for MiniTable)
|
||||
* @param displayType Display Type
|
||||
* @param yesNoAsBoolean - yes or no as boolean
|
||||
* @return class Integer - BigDecimal - Timestamp - String - Boolean
|
||||
*/
|
||||
public static Class getClass (String displayType, boolean yesNoAsBoolean)
|
||||
{
|
||||
if (List.equals(displayType))
|
||||
return List.class;
|
||||
else if (Integer.equals(displayType)) // note that Integer is stored as BD
|
||||
return Integer.class;
|
||||
else if (isNumeric(displayType))
|
||||
return java.math.BigDecimal.class;
|
||||
else if (isDate(displayType))
|
||||
return DateTime.class;
|
||||
else if (YesNo.equals(displayType))
|
||||
return Boolean.class;
|
||||
else if (isID(displayType) || String.equals(displayType) || Code.equals(displayType))
|
||||
return String.class;
|
||||
else if (isLOB(displayType)) // CLOB is String
|
||||
return byte[].class;
|
||||
else if(ENUMERATE.equals(displayType)){
|
||||
return Integer.class;
|
||||
}else if(STATUS.equals(displayType)){
|
||||
return Integer.class;
|
||||
}
|
||||
//
|
||||
return Object.class;
|
||||
} // getClass
|
||||
|
||||
// /**
|
||||
// * Get SQL DataType
|
||||
// * @param displayType AD_Reference_ID
|
||||
// * @param columnName name
|
||||
// * @param fieldLength length
|
||||
// * @return SQL Data Type in Oracle Notation
|
||||
// */
|
||||
// public static String getSQLDataType (String displayType, String columnName, int fieldLength)
|
||||
// {
|
||||
// if (columnName.equals("EntityType")
|
||||
// || columnName.equals ("AD_Language"))
|
||||
// return "VARCHAR2(" + fieldLength + ")";
|
||||
// // ID
|
||||
// if (DisplayType.isID(displayType))
|
||||
// {
|
||||
// if (columnName.endsWith("_ID")
|
||||
// || columnName.endsWith("tedBy")
|
||||
// || columnName.endsWith("_Acct") )
|
||||
// return "NUMBER(10)";
|
||||
// else if (fieldLength < 4)
|
||||
// return "CHAR(" + fieldLength + ")";
|
||||
// else // EntityType, AD_Language fallback
|
||||
// return "VARCHAR2(" + fieldLength + ")";
|
||||
// }
|
||||
// //
|
||||
// if (displayType == DisplayType.Integer)
|
||||
// return "NUMBER(10)";
|
||||
// if (DisplayType.isDate(displayType))
|
||||
// return "DATE";
|
||||
// if (DisplayType.isNumeric(displayType))
|
||||
// return "NUMBER";
|
||||
// if (displayType == DisplayType.Binary)
|
||||
// return "BLOB";
|
||||
// if (displayType == DisplayType.TextLong
|
||||
// || (displayType == DisplayType.Text && fieldLength >= 4000))
|
||||
// return "CLOB";
|
||||
// if (displayType == DisplayType.YesNo)
|
||||
// return "CHAR(1)";
|
||||
// if (displayType == DisplayType.List) {
|
||||
// if (fieldLength == 1)
|
||||
// return "CHAR(" + fieldLength + ")";
|
||||
// else
|
||||
// return "NVARCHAR2(" + fieldLength + ")";
|
||||
// }
|
||||
// if (displayType == DisplayType.Color) // this condition is never reached - filtered above in isID
|
||||
// {
|
||||
// if (columnName.endsWith("_ID"))
|
||||
// return "NUMBER(10)";
|
||||
// else
|
||||
// return "CHAR(" + fieldLength + ")";
|
||||
// }
|
||||
// if (displayType == DisplayType.Button)
|
||||
// {
|
||||
// if (columnName.endsWith("_ID"))
|
||||
// return "NUMBER(10)";
|
||||
// else
|
||||
// return "CHAR(" + fieldLength + ")";
|
||||
// }
|
||||
//// if (!DisplayType.isText(displayType))
|
||||
//// s_log.severe("Unhandled Data Type = " + displayType);
|
||||
//
|
||||
// return "NVARCHAR2(" + fieldLength + ")";
|
||||
// } // getSQLDataType
|
||||
|
||||
// /**
|
||||
// * Get Description
|
||||
// * @param displayType display Type
|
||||
// * @return display type description
|
||||
// */
|
||||
// public static String getDescription (int displayType)
|
||||
// {
|
||||
// if (displayType == String)
|
||||
// return "String";
|
||||
// if (displayType == Integer)
|
||||
// return "Integer";
|
||||
// if (displayType == Amount)
|
||||
// return "Amount";
|
||||
// if (displayType == ID)
|
||||
// return "ID";
|
||||
// if (displayType == Text)
|
||||
// return "Text";
|
||||
// if (displayType == Date)
|
||||
// return "Date";
|
||||
// if (displayType == DateTime)
|
||||
// return "DateTime";
|
||||
// if (displayType == List)
|
||||
// return "List";
|
||||
// if (displayType == Table)
|
||||
// return "Table";
|
||||
// if (displayType == TableDir)
|
||||
// return "TableDir";
|
||||
// if (displayType == YesNo)
|
||||
// return "YesNo";
|
||||
// if (displayType == Location)
|
||||
// return "Location";
|
||||
// if (displayType == Number)
|
||||
// return "Number";
|
||||
// if (displayType == Binary)
|
||||
// return "Binary";
|
||||
// if (displayType == Time)
|
||||
// return "Time";
|
||||
// if (displayType == Account)
|
||||
// return "Account";
|
||||
// if (displayType == RowID)
|
||||
// return "RowID";
|
||||
// if (displayType == Color)
|
||||
// return "Color";
|
||||
// if (displayType == Button)
|
||||
// return "Button";
|
||||
// if (displayType == Quantity)
|
||||
// return "Quantity";
|
||||
// if (displayType == Search)
|
||||
// return "Search";
|
||||
// if (displayType == Locator)
|
||||
// return "Locator";
|
||||
// if (displayType == Image)
|
||||
// return "Image";
|
||||
// if (displayType == Assignment)
|
||||
// return "Assignment";
|
||||
// if (displayType == Memo)
|
||||
// return "Memo";
|
||||
// if (displayType == PAttribute)
|
||||
// return "PAttribute";
|
||||
// if (displayType == TextLong)
|
||||
// return "TextLong";
|
||||
// if (displayType == CostPrice)
|
||||
// return "CostPrice";
|
||||
// if (displayType == FilePath)
|
||||
// return "FilePath";
|
||||
// if (displayType == FileName)
|
||||
// return "FileName";
|
||||
// if (displayType == URL)
|
||||
// return "URL";
|
||||
// if (displayType == PrinterName)
|
||||
// return "PrinterName";
|
||||
// //
|
||||
// return "UNKNOWN DisplayType=" + displayType;
|
||||
// } // getDescription
|
||||
|
||||
public static SimpleDateFormat getDateFormat(Locale m_locale)
|
||||
{
|
||||
// if (m_dateFormat == null)
|
||||
// {
|
||||
SimpleDateFormat m_dateFormat = (SimpleDateFormat)DateFormat.getDateInstance
|
||||
(DateFormat.SHORT, m_locale);
|
||||
String sFormat = m_dateFormat.toPattern();
|
||||
// some short formats have only one M and/or d (e.g. ths US)
|
||||
if (sFormat.indexOf("MM") == -1 || sFormat.indexOf("dd") == -1)
|
||||
{
|
||||
sFormat = sFormat.replaceFirst("d+", "dd");
|
||||
sFormat = sFormat.replaceFirst("M+", "MM");
|
||||
// log.finer(sFormat + " => " + nFormat);
|
||||
m_dateFormat.applyPattern(sFormat);
|
||||
}
|
||||
// Unknown short format => use JDBC
|
||||
if (m_dateFormat.toPattern().length() != 8)
|
||||
m_dateFormat.applyPattern("yyyy-MM-dd");
|
||||
|
||||
// 4 digit year
|
||||
if (m_dateFormat.toPattern().indexOf("yyyy") == -1)
|
||||
{
|
||||
sFormat = m_dateFormat.toPattern();
|
||||
String nFormat = "";
|
||||
for (int i = 0; i < sFormat.length(); i++)
|
||||
{
|
||||
if (sFormat.charAt(i) == 'y')
|
||||
nFormat += "yy";
|
||||
else
|
||||
nFormat += sFormat.charAt(i);
|
||||
}
|
||||
m_dateFormat.applyPattern(nFormat);
|
||||
}
|
||||
m_dateFormat.setLenient(true);
|
||||
// }
|
||||
return m_dateFormat;
|
||||
} // getDateFormat
|
||||
|
||||
/**
|
||||
* Get Date Time Format.
|
||||
* Used for Display only
|
||||
* @return Date Time format MMM d, yyyy h:mm:ss a z -or- dd.MM.yyyy HH:mm:ss z
|
||||
* -or- j nnn aaaa, H' ?????? 'm' ????'
|
||||
*/
|
||||
public static SimpleDateFormat getDateTimeFormat(Locale m_locale)
|
||||
{
|
||||
SimpleDateFormat retValue = (SimpleDateFormat)DateFormat.getDateTimeInstance
|
||||
(DateFormat.MEDIUM, DateFormat.LONG, m_locale);
|
||||
// log.finer("Pattern=" + retValue.toLocalizedPattern() + ", Loc=" + retValue.toLocalizedPattern());
|
||||
return retValue;
|
||||
} // getDateTimeFormat
|
||||
|
||||
public static SimpleDateFormat getTimeFormat(Locale m_locale)
|
||||
{
|
||||
return (SimpleDateFormat)DateFormat.getTimeInstance
|
||||
(DateFormat.LONG, m_locale);
|
||||
}
|
||||
|
||||
|
||||
} // DisplayType
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
|
||||
public class Enumerate {
|
||||
protected static CCache<String, List<EnumerateItem>> s_cache = new CCache<String, List<EnumerateItem>>("Enumerate", 2000);
|
||||
|
||||
/**
|
||||
* get enumerate items by enumerate type
|
||||
* @param enumerateType
|
||||
* @return
|
||||
*/
|
||||
public static List<EnumerateItem> getEnumerateItems(String enumerateType){
|
||||
List<EnumerateItem> enumerateItems = s_cache.get(enumerateType);
|
||||
if(enumerateItems == null || enumerateItems.size() == 0){
|
||||
enumerateItems = ((DataDicService)SpringBeanOsgiServices.getInstance().getBeanByName("dataDicService")).getEnumerateItems(enumerateType);
|
||||
s_cache.put(enumerateType, enumerateItems);
|
||||
}
|
||||
return enumerateItems;
|
||||
}
|
||||
|
||||
public static EnumerateItem getEnumerateItem(String enumerateType, Integer value){
|
||||
List<EnumerateItem> list = getEnumerateItems(enumerateType);
|
||||
if(list != null && list.size() > 0){
|
||||
for(EnumerateItem item : list){
|
||||
if(item.getCodeValue().equals(value)){
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getEnumerateItemDes(String enumerateType, Integer value){
|
||||
List<EnumerateItem> list = getEnumerateItems(enumerateType);
|
||||
if(list != null && list.size() > 0){
|
||||
for(EnumerateItem item : list){
|
||||
if(item.getCodeValue().equals(value)){
|
||||
return item.getCodeDes();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getEnumerateItemValue(String enumerateType, String Des){
|
||||
List<EnumerateItem> list = getEnumerateItems(enumerateType);
|
||||
if(list != null && list.size() > 0){
|
||||
for(EnumerateItem item : list){
|
||||
if(item.getCodeDes().equals(Des)){
|
||||
return item.getCodeValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
public static void setChange(String enumerateType){
|
||||
s_cache.remove(enumerateType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
public class EnumerateItem {
|
||||
private String codeDes;
|
||||
private Integer codeValue;
|
||||
private String enumerateType;
|
||||
|
||||
private String extendAttributeOne;
|
||||
private String extendAttributeTwo;
|
||||
private String extendAttributeThree;
|
||||
// private String
|
||||
|
||||
public String getCodeDes() {
|
||||
return codeDes;
|
||||
}
|
||||
public void setCodeDes(String codeDes) {
|
||||
this.codeDes = codeDes;
|
||||
}
|
||||
public Integer getCodeValue() {
|
||||
return codeValue;
|
||||
}
|
||||
public void setCodeValue(Integer codeValue) {
|
||||
this.codeValue = codeValue;
|
||||
}
|
||||
public String getEnumerateType() {
|
||||
return enumerateType;
|
||||
}
|
||||
public void setEnumerateType(String enumerateType) {
|
||||
this.enumerateType = enumerateType;
|
||||
}
|
||||
public String getExtendAttributeOne() {
|
||||
return extendAttributeOne;
|
||||
}
|
||||
public void setExtendAttributeOne(String extendAttributeOne) {
|
||||
this.extendAttributeOne = extendAttributeOne;
|
||||
}
|
||||
public String getExtendAttributeTwo() {
|
||||
return extendAttributeTwo;
|
||||
}
|
||||
public void setExtendAttributeTwo(String extendAttributeTwo) {
|
||||
this.extendAttributeTwo = extendAttributeTwo;
|
||||
}
|
||||
public String getExtendAttributeThree() {
|
||||
return extendAttributeThree;
|
||||
}
|
||||
public void setExtendAttributeThree(String extendAttributeThree) {
|
||||
this.extendAttributeThree = extendAttributeThree;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
public interface GeneralPOJO {
|
||||
|
||||
|
||||
public static final String KEYEND = "_ID";
|
||||
|
||||
public static final String DISPLAY = "_DISPLAY__";
|
||||
|
||||
public static final String NULL = "NULL";
|
||||
|
||||
public static final String UPDATETIME = "UPDATETIME";
|
||||
|
||||
public static final String CREATETIME = "CREATETIME";
|
||||
|
||||
public static final String UPDATEBY = "UPDATEBY";
|
||||
|
||||
public static final String CREATEBY = "CREATEBY";
|
||||
|
||||
public static final String ISACTIVE = "ISACTIVE";
|
||||
|
||||
public static final String DEPARTID = "DEPARTID";
|
||||
|
||||
public static final String ORGID = "ORGID";
|
||||
|
||||
public static final String PROCESSED = "PROCESSED";
|
||||
|
||||
public static final String PROCESSINGE = "PROCESSING";
|
||||
|
||||
public static final String VERSION = "VERSION";
|
||||
|
||||
public static final String DOCUMENT = "DOCUMENT";
|
||||
|
||||
public static final String STATUS = "STATUS";
|
||||
|
||||
public static final String AND = "AND";
|
||||
|
||||
public static final String OR = "OR";
|
||||
|
||||
public static final String SEQUENCE = "SEQUENCE_NUMBER";
|
||||
|
||||
/**
|
||||
* 条件字段后缀
|
||||
*/
|
||||
public static final String OP = "_OP__";
|
||||
|
||||
/**系统维护的字段*/
|
||||
public static final String[] SYSFIELD = {"UPDATETIME","CREATETIME","UPDATEBY","CREATEBY","ISACTIVE","DEPARTID","ORGID","PROCESSED","PROCESSING","VERSION","DOCUMENT","STATUS"};
|
||||
|
||||
|
||||
public String toString();// toString
|
||||
|
||||
/**
|
||||
* Equals based on ID
|
||||
* @param cmp comparator
|
||||
* @return true if ID the same
|
||||
*/
|
||||
public boolean equals (Object cmp);
|
||||
|
||||
|
||||
/**
|
||||
* Get TableName.
|
||||
* @return table name
|
||||
*/
|
||||
public String get_TableName();
|
||||
|
||||
/**
|
||||
* Get Key Columns.
|
||||
* @return table name
|
||||
*/
|
||||
public String[] get_KeyColumns();
|
||||
|
||||
/**
|
||||
* Get Table ID.
|
||||
* @return table id
|
||||
*/
|
||||
public String get_Table_ID();
|
||||
|
||||
/**
|
||||
* Return Single Key Record ID
|
||||
* @return ID or 0
|
||||
*/
|
||||
public String get_ID();
|
||||
|
||||
/**
|
||||
* Return Deleted Single Key Record ID
|
||||
* @return ID or 0
|
||||
*/
|
||||
public String get_IDOld();
|
||||
|
||||
// getCtx
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Get Value
|
||||
* @param index index
|
||||
* @return value
|
||||
*/
|
||||
public Object get_Value (int index);
|
||||
|
||||
/**
|
||||
* Get Value
|
||||
* @param columnName column name
|
||||
* @return value or null
|
||||
*/
|
||||
public Object get_Value (String columnName);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Value of Column
|
||||
* @param AD_Column_ID column
|
||||
* @return value or null
|
||||
*/
|
||||
public Object get_ValueOfColumn (String AD_Column_ID);
|
||||
|
||||
/**
|
||||
* Get Old Value
|
||||
* @param index index
|
||||
* @return value
|
||||
*/
|
||||
public Object get_ValueOld (int index);
|
||||
|
||||
|
||||
/**
|
||||
* Get new Value
|
||||
* @param index index
|
||||
* @return value
|
||||
*/
|
||||
public Object get_ValueNew (int index);
|
||||
|
||||
/**
|
||||
* Get Old Value
|
||||
* @param columnName column name
|
||||
* @return value or null
|
||||
*/
|
||||
public Object get_ValueOld (String columnName);
|
||||
|
||||
/**
|
||||
* Is Value Changed
|
||||
* @param index index
|
||||
* @return true if changed
|
||||
*/
|
||||
public boolean is_ValueChanged (int index);
|
||||
|
||||
/**
|
||||
* Is Value Changed
|
||||
* @param columnName column name
|
||||
* @return true if changed
|
||||
*/
|
||||
public boolean is_ValueChanged (String columnName);
|
||||
|
||||
/**
|
||||
* Return new - old.
|
||||
* - New Value if Old Value is null
|
||||
* - New Value - Old Value if Number
|
||||
* - otherwise null
|
||||
* @param index index
|
||||
* @return new - old or null if not appropriate or not changed
|
||||
*/
|
||||
public Object get_ValueDifference (int index);
|
||||
/**
|
||||
* Return new - old.
|
||||
* - New Value if Old Value is null
|
||||
* - New Value - Old Value if Number
|
||||
* - otherwise null
|
||||
* @param columnName column name
|
||||
* @return new - old or null if not appropriate or not changed
|
||||
*/
|
||||
public Object get_ValueDifference (String columnName);
|
||||
|
||||
/**
|
||||
* Set value of Column
|
||||
* @param columnName
|
||||
* @param value
|
||||
*/
|
||||
public void set_ValueOfColumn(String columnName, Object value);
|
||||
/**
|
||||
* Set value of Column returning boolean
|
||||
* @param columnName
|
||||
* @param value
|
||||
* @returns boolean indicating success or failure
|
||||
*/
|
||||
public boolean set_ValueOfColumnReturningBooleanByName(String columnName, Object value);
|
||||
|
||||
/**
|
||||
* Set Value of Column
|
||||
* @param AD_Column_ID column
|
||||
* @param value value
|
||||
*/
|
||||
public void set_ValueOfColumnByID (String AD_Column_ID, Object value);
|
||||
|
||||
/**
|
||||
* Set Value of Column
|
||||
* @param AD_Column_ID column
|
||||
* @param value value
|
||||
* @returns boolean indicating success or failure
|
||||
*/
|
||||
public boolean set_ValueOfColumnReturningBooleanByID (String AD_Column_ID, Object value);
|
||||
|
||||
|
||||
/**
|
||||
* Set Custom Column
|
||||
* @param columnName column
|
||||
* @param value value
|
||||
*/
|
||||
public void set_CustomColumn (String columnName, Object value);
|
||||
/**
|
||||
* Set Custom Column returning boolean
|
||||
* @param columnName column
|
||||
* @param value value
|
||||
* @returns boolean indicating success or failure
|
||||
*/
|
||||
public boolean set_CustomColumnReturningBoolean (String columnName, Object value);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Get Column Count
|
||||
* @return column count
|
||||
*/
|
||||
public int get_ColumnCount();
|
||||
|
||||
/**
|
||||
* Get Column Name
|
||||
* @param index index
|
||||
* @return ColumnName
|
||||
*/
|
||||
public String get_ColumnName (int index);
|
||||
|
||||
|
||||
/**
|
||||
* Get Column Index
|
||||
* @param columnName column name
|
||||
* @return index of column with ColumnName or -1 if not found
|
||||
*/
|
||||
public int get_ColumnIndex (String columnName);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set Active
|
||||
* @param active active
|
||||
*/
|
||||
public void setIsActive (boolean active);
|
||||
|
||||
/**
|
||||
* Is Active
|
||||
* @return is active
|
||||
*/
|
||||
public boolean isActive();
|
||||
|
||||
/**
|
||||
* Get Created
|
||||
* @return created
|
||||
*/
|
||||
public DateTime getCreated();
|
||||
|
||||
/**
|
||||
* Get Updated
|
||||
* @return updated
|
||||
*/
|
||||
public DateTime getUpdated();
|
||||
|
||||
/**
|
||||
* Get CreatedBy
|
||||
* @return AD_User_ID
|
||||
*/
|
||||
public int getCreatedBy();
|
||||
|
||||
/**
|
||||
* Get UpdatedBy
|
||||
* @return AD_User_ID
|
||||
*/
|
||||
public int getUpdatedBy();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is new record
|
||||
* @return true if new
|
||||
*/
|
||||
public boolean is_new();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is there a Change to be saved?
|
||||
* @return true if record changed
|
||||
*/
|
||||
public boolean is_Changed();
|
||||
|
||||
/**
|
||||
* Create Single/Multi Key Where Clause
|
||||
* @param withValues if true uses actual values otherwise ?
|
||||
* @return where clause
|
||||
*/
|
||||
public StringBuffer get_WhereClause (boolean withValues);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get value as Boolean
|
||||
* @param columnName
|
||||
* @return boolean value
|
||||
*/
|
||||
public boolean get_ValueAsBoolean(String columnName);
|
||||
|
||||
public int get_ValueAsInt (int index);
|
||||
|
||||
public int get_ValueAsInt(String columnName);
|
||||
|
||||
public StringBuffer getSelectBuild();
|
||||
|
||||
public StringBuffer getSelectBuild(List<String> cols);
|
||||
|
||||
|
||||
public Map<String, Object> toMap();
|
||||
|
||||
/**
|
||||
* return required type date, if not match, return the NA of the type
|
||||
* @param index
|
||||
* @param displayType
|
||||
* @return
|
||||
*/
|
||||
public Object getValueAsType(int index, String displayType);
|
||||
|
||||
/**
|
||||
* return required type date, if not match, return the NA of the type
|
||||
* @param columnName
|
||||
* @param displayType
|
||||
* @return
|
||||
*/
|
||||
public Object getValueAsType(String columnName, String displayType);
|
||||
|
||||
public boolean isVirtualColumn (int index);
|
||||
|
||||
public String get_ColumnDisplayType (int index);
|
||||
|
||||
public Class get_ColumnClass(int index);
|
||||
|
||||
public StringBuffer get_SearchWhereClause (Map map);
|
||||
|
||||
/**
|
||||
* get column display name, if the column is a Entity Object , return the entity display name
|
||||
* @param colName
|
||||
* @param defaultValue
|
||||
* @param timeZone
|
||||
* @return
|
||||
*/
|
||||
public String get_DisplayValue(String colName, boolean defaultValue, DateTimeZone timeZone);
|
||||
|
||||
/**
|
||||
* get the entity display name
|
||||
* @return
|
||||
*/
|
||||
public String get_EntityDisplayName();
|
||||
|
||||
/**
|
||||
* get index column reference table foreign key columnName
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public String get_referenceValueColumnName(int index);
|
||||
|
||||
/**
|
||||
* get index column reference table foreign key columnName
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public POJOInfo get_poInfo();
|
||||
|
||||
/**
|
||||
* get the entity display column
|
||||
* @return
|
||||
*/
|
||||
public String get_EntityDisplayColumn();
|
||||
|
||||
/**
|
||||
* get display type column name list
|
||||
* @param displayType
|
||||
* @return
|
||||
*/
|
||||
public List<String> get_ColumnsByDisplayType(String displayType);
|
||||
|
||||
/**
|
||||
* get pojoInfo by tableName
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public POJOInfo initPO(String tableName);
|
||||
|
||||
/**
|
||||
* load hierarchical Value, update it, the value set to the old value
|
||||
* @param columnName
|
||||
*/
|
||||
public boolean updateHierarchicalValue(String columnName, List list);
|
||||
|
||||
/**
|
||||
* load hierarchical Value, update it, the value set to the old value
|
||||
* @param columnName
|
||||
*/
|
||||
public boolean updateHierarchicalValue(int index, List list);
|
||||
|
||||
public GeneralPOJO getMainPO();
|
||||
|
||||
public void setMainPO(GeneralPOJO po);
|
||||
|
||||
public Properties getCtx();
|
||||
}
|
||||
@@ -0,0 +1,404 @@
|
||||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. 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 General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.privilege.bean.DataFilterRule;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Persistent Object Info.
|
||||
* Provides structural information
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: POInfo.java,v 1.2 2006/07/30 00:58:37 jjanke Exp $
|
||||
* @author Victor Perez, e-Evolution SC
|
||||
* <li>[ 2195894 ] Improve performance in PO engine
|
||||
* <li>http://sourceforge.net/tracker/index.php?func=detail&aid=2195894&group_id=176962&atid=879335
|
||||
*/
|
||||
public interface POJOInfo
|
||||
{
|
||||
/**
|
||||
* String representation
|
||||
* @return String Representation
|
||||
*/
|
||||
public String toString();
|
||||
/**
|
||||
* String representation for index
|
||||
* @param index column index
|
||||
* @return String Representation
|
||||
*/
|
||||
public String toString (int index);
|
||||
|
||||
/**
|
||||
* Get Table Name
|
||||
* @return Table Name
|
||||
*/
|
||||
public String getTableName();
|
||||
|
||||
/**
|
||||
* Get AD_Table_ID
|
||||
* @return AD_Table_ID
|
||||
*/
|
||||
public String getAD_Table_ID();
|
||||
/**
|
||||
* Table has a Key Column
|
||||
* @return true if has a key column
|
||||
*/
|
||||
public boolean hasKeyColumn();
|
||||
|
||||
/**
|
||||
* Get Table Access Level
|
||||
* @return Table.ACCESS..
|
||||
*/
|
||||
public int getAccessLevel();
|
||||
|
||||
/**************************************************************************
|
||||
* Get ColumnCount
|
||||
* @return column count
|
||||
*/
|
||||
public int getColumnCount();
|
||||
|
||||
/**
|
||||
* Get Column Index
|
||||
* @param ColumnName column name
|
||||
* @return index of column with ColumnName or -1 if not found
|
||||
*/
|
||||
public int getColumnIndexByName (String ColumnName);
|
||||
/**
|
||||
* Get Column Index
|
||||
* @param AD_Column_ID column
|
||||
* @return index of column with ColumnName or -1 if not found
|
||||
*/
|
||||
public int getColumnIndexByID (String AD_Column_ID);
|
||||
|
||||
/**
|
||||
* @param columnName
|
||||
* @return AD_Column_ID if found, -1 if not found
|
||||
*/
|
||||
public String getAD_Column_ID(String columnName);
|
||||
|
||||
|
||||
/**
|
||||
* Get Column Name
|
||||
* @param index index
|
||||
* @return ColumnName column name
|
||||
*/
|
||||
public String getColumnName (int index);
|
||||
|
||||
/**
|
||||
* Get Column SQL or Column Name
|
||||
* @param index index
|
||||
* @return ColumnSQL column sql or name
|
||||
*/
|
||||
public String getColumnSQL (int index, String prefix, StringBuffer lateral);
|
||||
|
||||
/**
|
||||
* Is Column Virtual?
|
||||
* @param index index
|
||||
* @return true if column is virtual
|
||||
*/
|
||||
public boolean isVirtualColumn (int index);
|
||||
|
||||
/**
|
||||
* Get Column Label
|
||||
* @param index index
|
||||
* @return column label
|
||||
*/
|
||||
public String getColumnLabel (int index);
|
||||
|
||||
/**
|
||||
* Get Column Description
|
||||
* @param index index
|
||||
* @return column description
|
||||
*/
|
||||
public String getColumnDescription (int index);
|
||||
|
||||
/**
|
||||
* Get Column Class
|
||||
* @param index index
|
||||
* @return Class
|
||||
*/
|
||||
public Class<?> getColumnClass (int index);
|
||||
|
||||
/**
|
||||
* Get Column Display Type
|
||||
* @param index index
|
||||
* @return DisplayType
|
||||
*/
|
||||
public String getColumnDisplayType (int index);
|
||||
|
||||
/**
|
||||
* Get Column Default Logic
|
||||
* @param index index
|
||||
* @return Default Logic
|
||||
*/
|
||||
public String getDefaultLogic (int index);
|
||||
|
||||
/**
|
||||
* Is Column Mandatory
|
||||
* @param index index
|
||||
* @return true if column mandatory
|
||||
*/
|
||||
public boolean isColumnMandatory (int index);
|
||||
|
||||
/**
|
||||
* Is Column Updateable
|
||||
* @param index index
|
||||
* @return true if column updateable
|
||||
*/
|
||||
public boolean isColumnUpdateable (int index);
|
||||
|
||||
/**
|
||||
* Set Column Updateable
|
||||
* @param index index
|
||||
* @param updateable column updateable
|
||||
*/
|
||||
public void setColumnUpdateable (int index, boolean updateable);
|
||||
|
||||
/**
|
||||
* Set all columns updateable
|
||||
* @param updateable updateable
|
||||
*/
|
||||
public void setUpdateable (boolean updateable);
|
||||
/**
|
||||
* Is Lookup Column
|
||||
* @param index index
|
||||
* @return true if it is a lookup column
|
||||
*/
|
||||
public boolean isColumnLookup (int index);
|
||||
/**
|
||||
* Get Lookup
|
||||
* @param index index
|
||||
* @return Lookup
|
||||
*/
|
||||
// public Lookup getColumnLookup (int index)
|
||||
// {
|
||||
// if (!isColumnLookup(index))
|
||||
// return null;
|
||||
// //
|
||||
// int WindowNo = 0;
|
||||
// // List, Table, TableDir
|
||||
// Lookup lookup = null;
|
||||
//// try
|
||||
//// {
|
||||
//// lookup = MLookupFactory.get (m_ctx, WindowNo,
|
||||
//// m_columns[index].AD_Column_ID, m_columns[index].DisplayType,
|
||||
//// Env.getLanguage(m_ctx), m_columns[index].ColumnName,
|
||||
//// m_columns[index].AD_Reference_Value_ID,
|
||||
//// m_columns[index].IsParent, m_columns[index].ValidationCode);
|
||||
//// }
|
||||
//// catch (Exception e)
|
||||
//// {
|
||||
//// lookup = null; // cannot create Lookup
|
||||
//// }
|
||||
// return lookup;
|
||||
// /** @todo other lookup types */
|
||||
// } // getColumnLookup
|
||||
|
||||
/**
|
||||
* Is Column Key
|
||||
* @param index index
|
||||
* @return true if column is the key
|
||||
*/
|
||||
public boolean isKey (int index);
|
||||
|
||||
/**
|
||||
* Is Column Parent
|
||||
* @param index index
|
||||
* @return true if column is a Parent
|
||||
*/
|
||||
// public boolean isColumnParent (int index)
|
||||
// {
|
||||
// if (index < 0 || index >= m_columns.length)
|
||||
// return false;
|
||||
// return m_columns[index].IsParent;
|
||||
// } // isColumnParent
|
||||
|
||||
/**
|
||||
* Is Column Translated
|
||||
* @param index index
|
||||
* @return true if column is translated
|
||||
*/
|
||||
// public boolean isColumnTranslated (int index)
|
||||
// {
|
||||
// if (index < 0 || index >= m_columns.length)
|
||||
// return false;
|
||||
// return m_columns[index].IsTranslated;
|
||||
// } // isColumnTranslated
|
||||
|
||||
/**
|
||||
* Is Table Translated
|
||||
* @return true if table is translated
|
||||
*/
|
||||
// public boolean isTranslated ()
|
||||
// {
|
||||
// for (int i = 0; i < m_columns.length; i++)
|
||||
// {
|
||||
// if (m_columns[i].IsTranslated)
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// } // isTranslated
|
||||
|
||||
// /**
|
||||
// * Is Column (data) Encrypted
|
||||
// * @param index index
|
||||
// * @return true if column is encrypted
|
||||
// */
|
||||
// public boolean isEncrypted (int index)
|
||||
// {
|
||||
// if (index < 0 || index >= m_columns.length)
|
||||
// return false;
|
||||
// return m_columns[index].IsEncrypted;
|
||||
// } // isEncrypted
|
||||
|
||||
/**
|
||||
* Is allowed logging on this column
|
||||
*
|
||||
* @param index
|
||||
* index
|
||||
* @return true if column is allowed to be logged
|
||||
*/
|
||||
public boolean isAllowLogging(int index);
|
||||
|
||||
/**
|
||||
* Get Column FieldLength
|
||||
* @param index index
|
||||
* @return field length
|
||||
*/
|
||||
public int getFieldLength (int index);
|
||||
|
||||
/**
|
||||
* Get Column FieldLength
|
||||
* @param columnName Column Name
|
||||
* @return field length or 0
|
||||
*/
|
||||
public int getFieldLength (String columnName);
|
||||
|
||||
/**
|
||||
* Validate Content
|
||||
* @param index index
|
||||
* @param value new Value
|
||||
* @return null if all valid otherwise error message
|
||||
*/
|
||||
public String validate (int index, Object value);
|
||||
|
||||
/**
|
||||
* Validate Content (Mandatory ,Length and Min/Max)
|
||||
* @param index
|
||||
* @param value newValue
|
||||
* @return null if all valid otherwise error message
|
||||
*/
|
||||
public String validateValue(int index, Object value);
|
||||
/**
|
||||
* Build select clause
|
||||
* @return stringbuffer
|
||||
*/
|
||||
public StringBuffer buildSelect();
|
||||
|
||||
public StringBuffer buildSelect(List<String> cols);
|
||||
|
||||
public StringBuffer buildSelect(List<String> cols, String prefix);
|
||||
|
||||
public StringBuffer buildCount();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return if table save log
|
||||
*/
|
||||
public boolean isChangeLog();
|
||||
|
||||
/**
|
||||
* get the reference value of the col , if the col is a entity Object or a enumerate
|
||||
* @param columnName
|
||||
* @return
|
||||
*/
|
||||
public String getReferenceValue(String columnName);
|
||||
|
||||
public String getReferenceValue(int index);
|
||||
|
||||
public int getDisplayIndex();
|
||||
|
||||
public String getReferenceValueTable(int index);
|
||||
|
||||
public String getReferenceValueTable(String columnName);
|
||||
|
||||
|
||||
public String getReferenceValueColumnName(int index);
|
||||
|
||||
public String getReferenceValueColumnName(String columnName);
|
||||
|
||||
|
||||
/**
|
||||
* Is Column identifier
|
||||
* @param index index
|
||||
* @return true if column mandatory
|
||||
*/
|
||||
public boolean isIdentifier (int index);
|
||||
|
||||
/**
|
||||
* is column combidentifier
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public boolean isCombidentifier (int index);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<Rule> getRules();
|
||||
|
||||
/**
|
||||
* return table type 0: main table 1: sub table 2: middle table
|
||||
* @return
|
||||
*/
|
||||
public int getTableType();
|
||||
|
||||
public String getKeyColumnName();
|
||||
|
||||
public String getTableDisplayName();
|
||||
|
||||
public List<DataFilterRule> getDataFilterRules();
|
||||
|
||||
public List<String> get_ColumnsByDisplayType(String displayType);
|
||||
|
||||
/**
|
||||
* columnName is a foreign key, return it reference table
|
||||
* @param columnName
|
||||
* @return
|
||||
*/
|
||||
public String getReferenceTable(int index);
|
||||
|
||||
/**
|
||||
* columnName is a foreign key, return it reference table
|
||||
* @param columnName
|
||||
* @return
|
||||
*/
|
||||
public String getReferenceTable(String columnName);
|
||||
|
||||
public String getEnumerateType(String columnName);
|
||||
|
||||
public String getEnumerateType(int index);
|
||||
|
||||
|
||||
} // POInfo
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PojoMap<String,Object> extends HashMap<String,Object>{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
public Object get_Value(String columnName){
|
||||
return get(columnName);
|
||||
}
|
||||
|
||||
public PojoMap<String, Object> toMap(){
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface Rule {
|
||||
|
||||
public static final String TABLENAME = "SYS_RULE";
|
||||
public static final String name = "NAME";
|
||||
public static final String content = "CONTENT";
|
||||
public static final String entityId = "ENTITYID";
|
||||
public static final String verificationTime = "VERIFICATIONTIME";
|
||||
|
||||
public static final Integer BEFORESAVE = 0;
|
||||
public static final Integer AFTERSAVE = 1;
|
||||
public static final Integer BEFOREDELETE = 2;
|
||||
public static final Integer AFTERDELETE = 3;
|
||||
|
||||
|
||||
|
||||
public GeneralPOJO getPo();
|
||||
|
||||
|
||||
public String getName() ;
|
||||
|
||||
|
||||
public void setName(String name);
|
||||
|
||||
|
||||
public String getContent();
|
||||
|
||||
|
||||
public void setContent(String content);
|
||||
|
||||
|
||||
public String getEntityId();
|
||||
|
||||
|
||||
public void setEntityId(String entityId);
|
||||
|
||||
|
||||
public Integer getVerificationTime();
|
||||
|
||||
|
||||
public void setVerificationTime(Integer verificationTime);
|
||||
|
||||
public Map<String, Object> convertToMap();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SYS_Entity {
|
||||
|
||||
/**
|
||||
* get sys_entity po
|
||||
* @return
|
||||
*/
|
||||
public GeneralPOJO getPo();
|
||||
|
||||
// public void setPo(GeneralPO po) {
|
||||
// this.po = po;
|
||||
// }
|
||||
|
||||
/**
|
||||
* get "SYS_ENTITY"
|
||||
* @return
|
||||
*/
|
||||
public String getTablename();
|
||||
|
||||
/**
|
||||
* 0: main table 1: sub table 2: mid table
|
||||
* @return
|
||||
*/
|
||||
public Integer getTabletype();
|
||||
|
||||
/**
|
||||
* table or view
|
||||
* @return
|
||||
*/
|
||||
public boolean isView();
|
||||
|
||||
/**
|
||||
* get entity attributes
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> getAttributes();
|
||||
|
||||
/**
|
||||
* create the table create postgresql sql
|
||||
* @return
|
||||
*/
|
||||
public String createTableSql();
|
||||
|
||||
|
||||
/**
|
||||
* delete table sql
|
||||
* @return
|
||||
*/
|
||||
public String delteTableSql();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.dsasp.server.common.dataDic.bean;
|
||||
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
*
|
||||
* @author shanxh
|
||||
*
|
||||
*/
|
||||
public class SysConfig {
|
||||
protected static CCache<String, String> key_cache = new CCache<String, String>(
|
||||
"SysConfig", 200);
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @return 配置的属性值
|
||||
*/
|
||||
public static String getConfigValue(String key) {
|
||||
String configValue = key_cache.get(key);
|
||||
if (StringUtil.isEmpty(configValue)) {
|
||||
configValue = ((DataDicService) SpringBeanOsgiServices
|
||||
.getInstance().getBeanByName("dataDicService"))
|
||||
.getConfigValue(key);
|
||||
key_cache.put(key, configValue);
|
||||
}
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public static void setChangeValue(String key) {
|
||||
key_cache.remove(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.dsasp.server.common.dataDic.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface CodeRuleService {
|
||||
public String getCode(String tableName,String columnName,Map<String,Object> map) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.dsasp.server.common.dataDic.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.EnumerateItem;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.POJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.Rule;
|
||||
import com.dsasp.server.common.dataDic.bean.SYS_Entity;
|
||||
|
||||
public interface DataDicService {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* control privilege by user self
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> listSelect(int firstResult, int pageSize, Map<String, Object> map);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param countSql
|
||||
* @return
|
||||
*/
|
||||
|
||||
public long findCount(String countSql);
|
||||
|
||||
/**
|
||||
* get entity attributes whit the entity ID
|
||||
* @param entityID
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> getEntityAttributes(String entityID);
|
||||
|
||||
/**
|
||||
* select the meta
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> getMeta(int firstResult, int pageSize);
|
||||
|
||||
|
||||
/**
|
||||
* only save Entity
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public Object save(Map<String, Object> entity, Properties ctx);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public Object update(Map<String, Object> entity, Properties ctx);
|
||||
|
||||
|
||||
/**
|
||||
* set isActivity is false.
|
||||
* @param entity
|
||||
* @param userID
|
||||
* @return
|
||||
*/
|
||||
public boolean delete(Map<String, Object> entity, Properties ctx);
|
||||
|
||||
public SYS_Entity getSYSEntity(String entityId);
|
||||
|
||||
/**
|
||||
* load the entity info with the tableName;
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public POJOInfo loadInfo(String tableName);
|
||||
|
||||
/**
|
||||
* find the reference Entity's tableName, use the Entity class
|
||||
* @param referenceId
|
||||
* @return
|
||||
*/
|
||||
public String getReferenceEntityTableName(String referenceId);
|
||||
|
||||
/**
|
||||
* find the sub table name with the reference value id , it's reference id is List
|
||||
* @param referenceValueId
|
||||
* @return
|
||||
*/
|
||||
public String getEntityTableNameByReferenceValue(String referenceValueId);
|
||||
|
||||
/**
|
||||
* get the foreign key by ferenceValue
|
||||
* @param referenceValueId
|
||||
* @return
|
||||
*/
|
||||
public String getColumnNameByReferenceValue(String referenceValueId);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
public String executeCreateSql(String sql);
|
||||
|
||||
/**
|
||||
* get entity by table name
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public SYS_Entity getSYSEntityByTableName(String tableName);
|
||||
|
||||
public GeneralPOJO getTableDefaultAttribute();
|
||||
|
||||
/**
|
||||
* get all entity with the entity of the entity id for foreign key
|
||||
* @param entityId
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> getEntitysWithForeignKey(String entityId);
|
||||
|
||||
/**
|
||||
* update or save reference and reference value
|
||||
* @param po
|
||||
* @param ctx
|
||||
*/
|
||||
public void saveOrUpdateReference(GeneralPOJO po, Properties ctx);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public List<Rule> getRule(String tableName);
|
||||
|
||||
public List<EnumerateItem> getEnumerateItems(String enumerateType);
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @return 系统配置的属性值
|
||||
*/
|
||||
public String getConfigValue(String key);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.dsasp.server.common.dataDic.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
|
||||
public interface POJOCRUDService {
|
||||
|
||||
/**
|
||||
* count of the result page
|
||||
*/
|
||||
public static final String PAGE_COUNT = "pagecount";
|
||||
|
||||
public static final String LIST_RESULT = "listresult";
|
||||
|
||||
/**
|
||||
* the count of records of per page
|
||||
*/
|
||||
public static final String PAGE_SIZE = "pagesize";
|
||||
|
||||
/**
|
||||
* search record from the start record number
|
||||
*/
|
||||
public static final String PAGE_START = "pagestart";
|
||||
|
||||
public static final String ORDER = "order";
|
||||
/**
|
||||
* if true , list select method only return the count size of result list
|
||||
*/
|
||||
public static final String IS_ONLY_GET_COUNT = "is_only_get_count";
|
||||
|
||||
/**
|
||||
* key/value Value is List type , contains all the result column . other columns don't return
|
||||
*/
|
||||
public static final String RETURN_COLUMNS_LIST = "return_columns_list";
|
||||
|
||||
/**
|
||||
* key/value Value is List type , contains all the result column . other columns don't return
|
||||
*/
|
||||
public static final String SUM_COLUMNS_LIST = "sum_columns_list";
|
||||
|
||||
public static final String RETURN_SUM_COLUMNS_MAP = "return_sum_columns_map";
|
||||
|
||||
/**
|
||||
* fuzzy query, query the entity all display name except date and number field
|
||||
*/
|
||||
public static final String FUZZY_QUERY = "fuzzy_query";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String PARENT_COLUMN_NAME = "parent_column_name";
|
||||
|
||||
|
||||
public Map<String, Object> listSelect(Map map, final String tableName, Properties ctx);
|
||||
|
||||
public GeneralPOJO save(Map map, final String tableName, Properties ctx);
|
||||
|
||||
public GeneralPOJO update(Map map, final String tableName, Properties ctx);
|
||||
|
||||
public GeneralPOJO delete(String entityId, final String tableName, Properties ctx);
|
||||
|
||||
public GeneralPOJO forceDelete(String entityId, final String tableName, Properties ctx);
|
||||
|
||||
public GeneralPOJO loadPOJO(String entityId, String tableName, Properties ctx, Boolean isHierarchical);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param map where conditional
|
||||
* @param tableName special tableName
|
||||
* @param ctx
|
||||
* @param returnColumnMap special the return columns
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> listSelectSpecialCol(Map map, final String tableName, Properties ctx, List<String> returnColumnMap);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param map 自定义sql的排序需要单独列在map中
|
||||
* @param tableName
|
||||
* @param sql 自定义sql
|
||||
* @param ctx
|
||||
* @param returnColMap
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> listSelectBySql(Map map, final String tableName, String sql, Properties ctx, List<String> returnColMap);
|
||||
/**
|
||||
* 根据返回类型的要求返回值,returnSetType为空表示不返回,则返回空
|
||||
* @param returnSetType
|
||||
* @param ctx
|
||||
* @param procedure
|
||||
* @return
|
||||
*/
|
||||
public Object executeProcedureReturnObject(String returnType, String[][] returnSetType, Properties ctx, String procedure);
|
||||
|
||||
/**
|
||||
* 批量保存实体
|
||||
* @param list
|
||||
* @param tableName
|
||||
* @param ctx
|
||||
*/
|
||||
public void batchSave(List<Map> list, String tableName, Properties ctx);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.dsasp.server.common.dataDic.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.POJOInfo;
|
||||
|
||||
public interface POJOService {
|
||||
|
||||
/**
|
||||
* control privilege by user self
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> listSelect(String sql, String tableName, int firstResult, int pageSize);
|
||||
|
||||
/**
|
||||
* control privilege by user self
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> listSelectSpecialCols(String sql, String tableName, int firstResult, int pageSize, List<String> cols);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param countSql
|
||||
* @return
|
||||
*/
|
||||
|
||||
public long findCount(String countSql);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sumSql
|
||||
* @return
|
||||
*/
|
||||
|
||||
public Map<String,Object> findSumColumn(String sumSql);
|
||||
|
||||
|
||||
/**
|
||||
* control privilege by this method
|
||||
* @param tableName
|
||||
* @param firstResult
|
||||
* @param count
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public List<GeneralPOJO> listSelect(String tableName, int firstResult, int pageSize, Object[] propertyId, boolean[] ascending, String userId, Map map);
|
||||
|
||||
|
||||
public long findCount(String tableName, String userId);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean save(GeneralPOJO po, String userID);
|
||||
|
||||
/**
|
||||
* deal whith optimistic lock version
|
||||
* @param po
|
||||
* @return
|
||||
*/
|
||||
public boolean update(GeneralPOJO po, String userID);
|
||||
|
||||
|
||||
/**
|
||||
* deal whith optimistic lock version
|
||||
* @param po
|
||||
* @return
|
||||
*/
|
||||
public boolean delete(GeneralPOJO po, String userID, Boolean force);
|
||||
|
||||
public boolean deleteCascadeValidate(String tableName, String recordID);
|
||||
|
||||
|
||||
public GeneralPOJO loadPOJO(String entityId, String tableName, Properties ctx, Boolean isHierarchical);
|
||||
|
||||
public GeneralPOJO loadPOJO(String entityId, String tableName);
|
||||
|
||||
/**
|
||||
* get table info
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public POJOInfo getPOJOInfo(String tableName);
|
||||
|
||||
|
||||
/**
|
||||
* execute the procedure, return void, or type or set
|
||||
* @param sql
|
||||
*/
|
||||
public Object executeProcedureReturnList(final String sql, String returnType,
|
||||
String[][] returnCols);
|
||||
|
||||
|
||||
public StringBuffer save_convertToSql(GeneralPOJO po, String userID, String foreignColName);
|
||||
|
||||
public void batchExecute(String sql);
|
||||
|
||||
public Map<String, Object> executeQueryForMap(String sql);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dsasp.server.common.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* 权限异常
|
||||
*
|
||||
*/
|
||||
public class PrivilegeException extends RuntimeException {
|
||||
|
||||
public PrivilegeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PrivilegeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PrivilegeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PrivilegeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.dsasp.server.common.exception;
|
||||
|
||||
/**
|
||||
* 编号相同异常
|
||||
* @author zhengwr
|
||||
*
|
||||
*/
|
||||
public class SameCodeException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* 编号重复的字段
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 编号重复的表
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
public SameCodeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SameCodeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SameCodeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SameCodeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public SameCodeException(String message,String tableName, String columName) {
|
||||
super(message);
|
||||
this.tableName = tableName;
|
||||
this.columnName = columName;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dsasp.server.common.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* 逻辑验证异常
|
||||
*
|
||||
*/
|
||||
public class ValidationException extends RuntimeException {
|
||||
|
||||
public ValidationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ValidationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ValidationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ValidationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.dsasp.server.common.file.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
|
||||
public interface FileService {
|
||||
|
||||
/**
|
||||
* temporary file list
|
||||
* @param tempFiles
|
||||
* @param tableName
|
||||
* @param businessKey
|
||||
*/
|
||||
public String save(String tempFile, String fileName, int size, String tableName, String businessKey, Properties ctx);
|
||||
|
||||
public void saveDoc(String relativePath, String fileName, int size, String tableName, String businessKey, Properties ctx);
|
||||
|
||||
|
||||
/**
|
||||
* get doc file by relative path
|
||||
* @param relativePath
|
||||
* @param fileName
|
||||
* @param isZip
|
||||
* @return
|
||||
*/
|
||||
public File getDocFile(String relativePath, String fileName, boolean isZip);
|
||||
/**
|
||||
* delete file by doc ids
|
||||
* @param fileIds
|
||||
*/
|
||||
public void delete(List<String> fileIds, String userId);
|
||||
|
||||
public void delete(String fileId, String userId);
|
||||
|
||||
public void deleteAttatchmentByBusinessKey(String businessKey, String userId);
|
||||
|
||||
public void deleteAttatchmentByBusinessKey(List<String> businessKeys, String userId);
|
||||
|
||||
/**
|
||||
* 定期清理已标志删除文件
|
||||
*/
|
||||
public void clearDeletedDocument();
|
||||
|
||||
/**
|
||||
* 定期清理垃圾文件,如:保存失败,事务回滚产生的垃圾文件
|
||||
*/
|
||||
public void clearDumpFile();
|
||||
|
||||
public List<GeneralPOJO> getDoc(List<String> businessKeys);
|
||||
|
||||
/**
|
||||
* 获得图片地址(取业务的第一个附件)
|
||||
* @param tablename
|
||||
* @param businesskey
|
||||
* @return
|
||||
*/
|
||||
public String getPicPath(String tablename,String businesskey);
|
||||
|
||||
|
||||
public String saveDecoderBase64File(String base64Code, String userId, String tableName, Properties ctx)throws Exception;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.dsasp.server.common.file.service;
|
||||
|
||||
public class SYSDoc {
|
||||
public static String SYSDocTableName = "SYS_DOC";
|
||||
public static String fileName = "FILENAME";
|
||||
public static String fileExt = "FILEEXT";
|
||||
public static String fileSize = "FILESIZE";
|
||||
public static String filePath = "FILEPATH";
|
||||
public static String tableName = "TABLENAME";
|
||||
public static String businessKey = "BUSINESSKEY";
|
||||
public static String md5Hash = "MD5HASH";
|
||||
|
||||
/**
|
||||
* sys_doc_id
|
||||
*/
|
||||
public static String docId = "SYS_DOC_ID";
|
||||
|
||||
/**
|
||||
* System.currentTimeMillis() plus upload file name
|
||||
*/
|
||||
public static String tempFile = "TEMPFILE";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版为 Groovy 脚本函数库(currentYear/currentMonth 等默认值函数),
|
||||
* 仅被 FunctionUtil 以 class 引用注册。WS3 脚本验证时回迁完整实现。
|
||||
*/
|
||||
public class GetDefaultValueFunction {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版为 780 行 Groovy 脚本函数库(@Function 注解暴露给模板脚本)。
|
||||
* PoC 阶段只实现被 Java 代码直接调用的 findCount(POInfo.java:860);
|
||||
* 完整 Groovy 函数库在 WS3 脚本验证时以 groovy-jsr223 联合编译方式回迁。
|
||||
*/
|
||||
public class GetServicesFunction {
|
||||
|
||||
public static long findCount(String countSql) {
|
||||
DataDicService dataDicService =
|
||||
(DataDicService) SpringBeanOsgiServices.getInstance().getBeanByName("dataDicService");
|
||||
return dataDicService.findCount(countSql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版为 Groovy 脚本函数库,仅被 FunctionUtil 以 class 引用注册。
|
||||
* WS3 脚本验证时回迁完整实现。
|
||||
*/
|
||||
public class GetValueFunction {
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.dsasp.server.common.log.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DataLogDetail {
|
||||
|
||||
private String DataLogDetail_Id;
|
||||
|
||||
private String dataLogId;
|
||||
|
||||
private String columnName;
|
||||
|
||||
private String oldValue;
|
||||
|
||||
private String newValue;
|
||||
|
||||
private List<DataLogItem> list;
|
||||
|
||||
public String getDataLogDetail_Id() {
|
||||
return DataLogDetail_Id;
|
||||
}
|
||||
|
||||
public void setDataLogDetail_Id(String dataLogDetail_Id) {
|
||||
DataLogDetail_Id = dataLogDetail_Id;
|
||||
}
|
||||
|
||||
public String getDataLogId() {
|
||||
return dataLogId;
|
||||
}
|
||||
|
||||
public void setDataLogId(String dataLogId) {
|
||||
this.dataLogId = dataLogId;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public String getOldValue() {
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public void setOldValue(String oldValue) {
|
||||
this.oldValue = oldValue;
|
||||
}
|
||||
|
||||
public String getNewValue() {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public void setNewValue(String newValue) {
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
public List<DataLogItem> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<DataLogItem> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.dsasp.server.common.log.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DataLogItem {
|
||||
|
||||
private String DataLogItem_Id;
|
||||
|
||||
private String userId;
|
||||
|
||||
private String recordId;
|
||||
|
||||
private String tableName;
|
||||
|
||||
private String mainDataLogItemId;
|
||||
|
||||
private int type;
|
||||
|
||||
/**
|
||||
* operate type
|
||||
*/
|
||||
public static final Integer OPERATE_NEW = 1;
|
||||
public static final Integer OPERATE_UPDATE = 2;
|
||||
public static final Integer OPERATE_DELETE = 3;
|
||||
|
||||
private List<DataLogDetail> detailList = new ArrayList<DataLogDetail>();
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getRecordId() {
|
||||
return recordId;
|
||||
}
|
||||
|
||||
public void setRecordId(String recordId) {
|
||||
this.recordId = recordId;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public List<DataLogDetail> getDetailList() {
|
||||
return detailList;
|
||||
}
|
||||
|
||||
public void setDetailList(List<DataLogDetail> list) {
|
||||
this.detailList = list;
|
||||
}
|
||||
|
||||
public String getMainDataLogItemId() {
|
||||
return mainDataLogItemId;
|
||||
}
|
||||
|
||||
public void setMainDataLogItemId(String mainDataLogItemId) {
|
||||
this.mainDataLogItemId = mainDataLogItemId;
|
||||
}
|
||||
|
||||
public String getDataLogItem_Id() {
|
||||
return DataLogItem_Id;
|
||||
}
|
||||
|
||||
public void setDataLogItem_Id(String dataLogItem_Id) {
|
||||
DataLogItem_Id = dataLogItem_Id;
|
||||
}
|
||||
|
||||
public void addDataLogDetail(DataLogDetail detail){
|
||||
detailList.add(detail);
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.dsasp.server.common.log.bean;
|
||||
|
||||
public interface LogItem {
|
||||
|
||||
public String toDetail();
|
||||
|
||||
public String toDifferent(LogItem oldObject);
|
||||
|
||||
public boolean isLog();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dsasp.server.common.log.bean;
|
||||
|
||||
import com.dsasp.server.common.log.service.SystemLogManager.LogType;
|
||||
|
||||
public class SysLogItem {
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public LogType getLogType() {
|
||||
return logType;
|
||||
}
|
||||
public void setLogType(LogType logType) {
|
||||
this.logType = logType;
|
||||
}
|
||||
public String getLogContent() {
|
||||
return logContent;
|
||||
}
|
||||
public void setLogContent(String logContent) {
|
||||
this.logContent = logContent;
|
||||
}
|
||||
private LogType logType;
|
||||
private String logContent;
|
||||
private String userId;
|
||||
|
||||
|
||||
|
||||
public SysLogItem(LogType logType, String logContent, String userId) {
|
||||
super();
|
||||
this.logType = logType;
|
||||
this.logContent = logContent;
|
||||
this.userId = userId;
|
||||
}
|
||||
public SysLogItem() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.dsasp.server.common.log.service;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.log.bean.DataLogItem;
|
||||
|
||||
public interface DataOperatorLog {
|
||||
|
||||
public DataLogItem insertData(GeneralPOJO po, String dataLogItemId, String mainDataLogItemId);
|
||||
|
||||
public DataLogItem updateData(GeneralPOJO po, String dataLogItemId, String mainDataLogItemId);
|
||||
|
||||
public DataLogItem deleteData(GeneralPOJO po, String dataLogItemId, String mainDataLogItemId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dsasp.server.common.log.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import com.dsasp.server.common.log.bean.SysLogItem;
|
||||
|
||||
|
||||
public interface SystemLogManager {
|
||||
public enum LogType{
|
||||
ERRORS("Errors"),
|
||||
INFO("Info"),
|
||||
DEBUG("Debug"),
|
||||
WARNINGS("Warnings");
|
||||
private String value;
|
||||
private LogType(String value) {
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
public String getValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
public static LogType getType(String value) {
|
||||
for (LogType c : LogType.values()) {
|
||||
if (c.getValue().equals(value)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null ;
|
||||
}
|
||||
}
|
||||
|
||||
public void log(LogType logType,String logContent);
|
||||
|
||||
public void deleteAll();
|
||||
|
||||
public void deleteByType(String type);
|
||||
|
||||
public void log( List<SysLogItem> items);
|
||||
|
||||
public void deleteByLoginTime(List<String> userIds,DateTime[] loginTimes);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.dsasp.server.common.organization.bean;
|
||||
|
||||
public class Position {
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String departId;
|
||||
|
||||
private String type;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDepartId() {
|
||||
return departId;
|
||||
}
|
||||
|
||||
public void setDepartId(String departId) {
|
||||
this.departId = departId;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.dsasp.server.common.privilege.bean;
|
||||
|
||||
public class Conditional {
|
||||
|
||||
/**
|
||||
* table field
|
||||
*/
|
||||
private String preConditional;
|
||||
/**
|
||||
* sign > ,<, = , in ...
|
||||
*/
|
||||
private String sign;
|
||||
/**
|
||||
* back conditional
|
||||
*/
|
||||
private String backConditional;
|
||||
|
||||
/**
|
||||
* conditional type
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* and / or with next rule
|
||||
*/
|
||||
private String op;
|
||||
|
||||
|
||||
public String getPreConditional() {
|
||||
return preConditional;
|
||||
}
|
||||
public void setPreConditional(String preConditional) {
|
||||
this.preConditional = preConditional;
|
||||
}
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
public String getBackConditional() {
|
||||
return backConditional;
|
||||
}
|
||||
public void setBackConditional(String backConditional) {
|
||||
this.backConditional = backConditional;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
public String getOp() {
|
||||
return op;
|
||||
}
|
||||
public void setOp(String op) {
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static final String SIGN_GREATER = ">";
|
||||
public static final String SIGN_GREATEREQUAL = ">=";
|
||||
public static final String SIGN_LESS = "<";
|
||||
public static final String SIGN_LESSEQUAL = "<=";
|
||||
public static final String SIGN_EQUAL = "=";
|
||||
public static final String SIGN_CONTAIN = "in";
|
||||
public static final String SIGN_NOTCONTAIN = "not in";
|
||||
|
||||
|
||||
public static final String CURRENTUSER = "CURRENTUSERID";
|
||||
public static final String CURRENTUSERDEPART = "CURRENTUSERDEPARTID";
|
||||
public static final String CURRENTUSERORG = "CURRENTUSERORGID";
|
||||
public static final String SPECIALDEPART = "SPECIALDEPART";
|
||||
public static final String SPECAILORG = "SPECIALORG";
|
||||
public static final String NUMBER = "NUMBER";
|
||||
public static final String TEXT = "TEXT";
|
||||
|
||||
//所属项目
|
||||
public static final String OWNNERPROJECT = "OWNNERPROJECT";
|
||||
|
||||
|
||||
// public static final String AND = "AND";
|
||||
// public static final String OR = "OR";
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.dsasp.server.common.privilege.bean;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class DataFilterRule {
|
||||
private List<String> roles;
|
||||
|
||||
private List<Conditional> ConditionalList;
|
||||
|
||||
private String id;
|
||||
|
||||
|
||||
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(List<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public List<Conditional> getConditionalList() {
|
||||
return ConditionalList;
|
||||
}
|
||||
|
||||
public void setConditionalList(List<Conditional> conditionalList) {
|
||||
ConditionalList = conditionalList;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.dsasp.server.common.privilege.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DataPrivilege {
|
||||
|
||||
public final static int READ = 0;
|
||||
public final static int WRITE = 1;
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* entity
|
||||
*/
|
||||
private String entityId;
|
||||
|
||||
/**
|
||||
* 0: read, 1: write
|
||||
*/
|
||||
private int operation;
|
||||
|
||||
/**
|
||||
* 0: oneself,1:special users,2:owner depart,3:special depart,4:owner org, 5:special org, 6: all
|
||||
*/
|
||||
private int scopeType;
|
||||
|
||||
/**
|
||||
* if scopeType is a special type, specialUnits's value is not null;
|
||||
*/
|
||||
private List<String> specialUnits;
|
||||
|
||||
/**
|
||||
* default permission is all field
|
||||
*/
|
||||
private boolean isAll;
|
||||
|
||||
/**
|
||||
* if isAll is false, exceptionFields is the except fields
|
||||
*/
|
||||
private List<String> exceptionFields;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public void setEntityId(String entityId) {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public int getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public void setOperation(int operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public int getScopeType() {
|
||||
return scopeType;
|
||||
}
|
||||
|
||||
public void setScopeType(int scopeType) {
|
||||
this.scopeType = scopeType;
|
||||
}
|
||||
|
||||
public List<String> getSpecialUnits() {
|
||||
return specialUnits;
|
||||
}
|
||||
|
||||
public void setSpecialUnits(List<String> specialUnits) {
|
||||
this.specialUnits = specialUnits;
|
||||
}
|
||||
|
||||
public boolean isAll() {
|
||||
return isAll;
|
||||
}
|
||||
|
||||
public void setAll(boolean isAll) {
|
||||
this.isAll = isAll;
|
||||
}
|
||||
|
||||
public List<String> getExceptionFields() {
|
||||
return exceptionFields;
|
||||
}
|
||||
|
||||
public void setExceptionFields(List<String> exceptionFields) {
|
||||
this.exceptionFields = exceptionFields;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.dsasp.server.common.privilege.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.privilege.bean.DataFilterRule;
|
||||
import com.dsasp.server.common.privilege.bean.DataPrivilege;
|
||||
|
||||
public interface DataPrivilegeService {
|
||||
|
||||
|
||||
// /**
|
||||
// * get user's the privilege of the action, 0: without permission 1: all permission 2: the permission of some fields ,
|
||||
// * @param userID
|
||||
// * @return map, key is entityID, value is privilege set
|
||||
// */
|
||||
// public DataPrivilege getPrivilege(String userID, String entity, int operationType);
|
||||
|
||||
public String getWhereClause(Properties ctx, String tableName);
|
||||
|
||||
// /**
|
||||
// * get the action special permission of some fields,
|
||||
// * @param userID
|
||||
// * @param entity
|
||||
// * @return
|
||||
// */
|
||||
// public List<String> getSpecPrivileges(String userID, String entity);
|
||||
|
||||
|
||||
// public List<DataPrivilege> getRoleDataPrivilege(String roleId);
|
||||
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param roleId
|
||||
// * @param privilege
|
||||
// * @return
|
||||
// */
|
||||
// public boolean updateDataPrivilege(String roleId, DataPrivilege privilege);
|
||||
|
||||
|
||||
/**
|
||||
* update the entity all rules
|
||||
* @param entityId
|
||||
* @param list
|
||||
* @param ctx
|
||||
*/
|
||||
public void saveOrUpdateDataPrivilege(String entityId, List<DataFilterRule> list, Properties ctx);
|
||||
|
||||
|
||||
/**
|
||||
* get entity all the rule
|
||||
* @param entityId
|
||||
* @return
|
||||
*/
|
||||
public List<DataFilterRule> getEntityDataFilterRule(String entityId);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.dsasp.server.common.user.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.dsasp.server.common.organization.bean.Position;
|
||||
|
||||
|
||||
/**
|
||||
* Interface describing the logged in user.
|
||||
*
|
||||
* @author Frederik Heremans
|
||||
*/
|
||||
public interface LoggedInUser extends Serializable {
|
||||
|
||||
public static final String CURRENTUSER = "CURRENTUSER";
|
||||
|
||||
public static final String CURRENTDEPART = "CURRENTDEPART";
|
||||
|
||||
public static final String CURRENTORG = "CURRENTORG";
|
||||
|
||||
public static final String ROLES = "ROLES";
|
||||
|
||||
public static final String ADMIN = "ADMIN ";
|
||||
|
||||
public static final String CURRENTPROJECT ="CURRENTPROJECT";//工程切换
|
||||
|
||||
public static final String DEFAULTPROJECT = "DEFAULTPROJECT";//个人设置工程
|
||||
|
||||
public static final String COMPLETEDPROJECT="COMPLETEDPROJECT";//竣工工程
|
||||
|
||||
public static final String DEFAULTPAGESIZE="DEFAULTPAGESIZE";
|
||||
|
||||
String getId();
|
||||
|
||||
String getFirstName();
|
||||
|
||||
String getLastName();
|
||||
|
||||
String getFullName();
|
||||
|
||||
String getPassword();
|
||||
|
||||
boolean isAdmin();
|
||||
|
||||
Position getMainPosition();
|
||||
}
|
||||
@@ -0,0 +1,655 @@
|
||||
package com.dsasp.server.common.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.Writer;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.Time;
|
||||
import java.sql.Types;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
public class DbUtil {
|
||||
public static void testJndi(String jndi) throws Exception {
|
||||
// Connection conn = getConnection(jndi);
|
||||
// conn.close();
|
||||
}
|
||||
public static boolean isBlobField(int type) {
|
||||
switch (type) {
|
||||
case -2:
|
||||
case -3:
|
||||
case -4:
|
||||
case 2004:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isTextField(int type) {
|
||||
switch (type) {
|
||||
case -1:
|
||||
case -16:
|
||||
case 2005:
|
||||
case 2011:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isLargeField(int type) {
|
||||
switch (type) {
|
||||
case -1:
|
||||
case -2:
|
||||
case -3:
|
||||
case -4:
|
||||
case -16:
|
||||
case 2004:
|
||||
case 2005:
|
||||
case 2011:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static String getTypeCategory(int type) {
|
||||
switch (type) {
|
||||
case Types.BIGINT:
|
||||
case Types.INTEGER:
|
||||
case Types.SMALLINT:
|
||||
case Types.TINYINT:
|
||||
return "int";
|
||||
case Types.DECIMAL:
|
||||
case Types.DOUBLE:
|
||||
case Types.FLOAT:
|
||||
case Types.NUMERIC:
|
||||
case Types.REAL:
|
||||
return "float";
|
||||
case Types.TIMESTAMP:
|
||||
case Types.DATE:
|
||||
case Types.TIME:
|
||||
return "date";
|
||||
case Types.BOOLEAN:
|
||||
case Types.BIT:
|
||||
return "bool";
|
||||
default:
|
||||
return "string";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFields(ResultSetMetaData meta, int colCount,
|
||||
boolean dateAsString, JSONObject keyMap) throws Exception {
|
||||
int i, type;
|
||||
String name, category, fmt;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
buf.append('[');
|
||||
for (i = 0; i < colCount; i++) {
|
||||
if (i > 0)
|
||||
buf.append(',');
|
||||
buf.append("{name:");
|
||||
name = meta.getColumnLabel(i + 1);
|
||||
if (StringUtil.isEmpty(name))
|
||||
name = "FIELD" + Integer.toString(i + 1);
|
||||
buf.append(StringUtil.quote(name));
|
||||
buf.append(",type:\"");
|
||||
if (keyMap != null && keyMap.has(name))
|
||||
type = Types.VARCHAR;
|
||||
else
|
||||
type = meta.getColumnType(i + 1);
|
||||
if (dateAsString
|
||||
&& (type == Types.TIMESTAMP || type == Types.DATE || type == Types.TIME))
|
||||
type = Types.VARCHAR;
|
||||
category = getTypeCategory(type);
|
||||
buf.append(category);
|
||||
switch (type) {
|
||||
case Types.TIMESTAMP:
|
||||
case Types.DATE:
|
||||
fmt = "Y-m-d H:i:s.u";
|
||||
break;
|
||||
case Types.TIME:
|
||||
fmt = "H:i:s";
|
||||
break;
|
||||
default:
|
||||
fmt = null;
|
||||
}
|
||||
if (fmt != null) {
|
||||
buf.append("\",dateFormat:\"");
|
||||
buf.append(fmt);
|
||||
}
|
||||
buf.append("\"}");
|
||||
}
|
||||
buf.append(']');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String getColumns(ResultSetMetaData meta, int colCount,
|
||||
String editorType, boolean rowNumber, boolean dateAsString,
|
||||
JSONObject keyMap) throws Exception {
|
||||
int i, k, len, type, editor;
|
||||
boolean isText, isBlob, isMap;
|
||||
String field, name, validator, renderer;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
if (editorType.equals("editable"))
|
||||
editor = 1;
|
||||
else if (editorType.equals("readOnly"))
|
||||
editor = 2;
|
||||
else
|
||||
editor = 0;
|
||||
buf.append('[');
|
||||
if (rowNumber)
|
||||
buf
|
||||
.append("{width:45,sortable:false,hideable:false,type:\"rowNumber\",renderer:\"Wb.nr\",align:\"right\"}");
|
||||
for (i = 0; i < colCount; i++) {
|
||||
if (rowNumber || i > 0)
|
||||
buf.append(',');
|
||||
field = meta.getColumnLabel(i + 1);
|
||||
if (StringUtil.isEmpty(field))
|
||||
field = "FIELD" + Integer.toString(i + 1);
|
||||
name = StringUtil.quote(field);
|
||||
buf.append("{dataIndex:");
|
||||
buf.append(name);
|
||||
buf.append(",header:");
|
||||
buf.append(name);
|
||||
isMap = keyMap != null && keyMap.has(field);
|
||||
if (isMap)
|
||||
type = Types.VARCHAR;
|
||||
else
|
||||
type = meta.getColumnType(i + 1);
|
||||
isText = isTextField(type);
|
||||
isBlob = isBlobField(type);
|
||||
renderer = "Wb.htmlRender";
|
||||
validator = "";
|
||||
if (isMap)
|
||||
len = 20;
|
||||
else if (isText)
|
||||
len = 25;
|
||||
else if (isBlob)
|
||||
len = 6;
|
||||
else
|
||||
len = meta.getColumnDisplaySize(i + 1);
|
||||
switch (type) {
|
||||
case Types.TIMESTAMP:
|
||||
case Types.DATE:
|
||||
if (editor == 1)
|
||||
validator = "Wb.tsValidator";
|
||||
if (!dateAsString)
|
||||
renderer = "Wb.dateRender";
|
||||
len = 18;
|
||||
break;
|
||||
case Types.TIME:
|
||||
if (editor == 1)
|
||||
validator = "Wb.tmValidator";
|
||||
if (!dateAsString)
|
||||
renderer = "Wb.timeRender";
|
||||
len = 10;
|
||||
break;
|
||||
case Types.BIGINT:
|
||||
case Types.INTEGER:
|
||||
case Types.SMALLINT:
|
||||
case Types.TINYINT:
|
||||
case Types.DECIMAL:
|
||||
case Types.DOUBLE:
|
||||
case Types.FLOAT:
|
||||
case Types.NUMERIC:
|
||||
case Types.REAL:
|
||||
buf.append(",align:\"right\"");
|
||||
if (editor == 1)
|
||||
validator = "Wb.numValidator";
|
||||
break;
|
||||
}
|
||||
if (editor == 1 && isBlob)
|
||||
buf.append(",renderer:\"Wb.downRender('" + field + "')\"");
|
||||
else {
|
||||
buf.append(",renderer:");
|
||||
buf.append(StringUtil.quote(renderer));
|
||||
}
|
||||
buf.append(",sortable:true,width:");
|
||||
k = name.length() - 1;
|
||||
if (len < k)
|
||||
len = k;
|
||||
if (len < 5)
|
||||
len = 5;
|
||||
if (len > 25)
|
||||
len = 25;
|
||||
buf.append(len * 9);
|
||||
if (editor > 0 && !isBlob) {
|
||||
buf.append(",editor:{xtype:\"");
|
||||
if (isText)
|
||||
buf.append("textarea\",height:100");
|
||||
else
|
||||
buf.append("textfield\"");
|
||||
if (meta.isNullable(i + 1) == ResultSetMetaData.columnNoNulls)
|
||||
buf.append(",allowBlank:false");
|
||||
if (isMap || isBlob || editor == 2 || meta.isReadOnly(i + 1))
|
||||
buf
|
||||
.append(",readOnly:true,fieldStyle:\"background-image:none;background-color:#C0C0C0\"");
|
||||
if (!validator.isEmpty()) {
|
||||
buf.append(",validator:");
|
||||
buf.append(validator);
|
||||
}
|
||||
buf.append('}');
|
||||
}
|
||||
buf.append('}');
|
||||
}
|
||||
buf.append(']');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void exportData(Writer writer, ResultSet rs) throws Exception {
|
||||
// ResultSetMetaData meta = rs.getMetaData();
|
||||
// int i, j = meta.getColumnCount(), ct = 0, types[] = new int[j];
|
||||
//
|
||||
// writer.write("[[");
|
||||
// for (i = 0; i < j; i++) {
|
||||
// types[i] = meta.getColumnType(i + 1);
|
||||
// if (i > 0)
|
||||
// writer.write(',');
|
||||
// writer.write(meta.getColumnName(i + 1));
|
||||
// }
|
||||
// writer.write(']');
|
||||
// while (rs.next()) {
|
||||
// writer.write(",[");
|
||||
// for (i = 0; i < j; i++) {
|
||||
// if (i > 0)
|
||||
// writer.write(',');
|
||||
// writer.write(StringUtil.encode(DbUtil.getObject(rs, i + 1,
|
||||
// types[i], false)));
|
||||
// }
|
||||
// writer.write(']');
|
||||
// ct++;
|
||||
// }
|
||||
// writer.write(']');
|
||||
// writer.flush();
|
||||
}
|
||||
|
||||
// public static String getArray(ResultSet rs) throws Exception {
|
||||
// StringBuilder buf = new StringBuilder();
|
||||
// ResultSetMetaData meta = rs.getMetaData();
|
||||
// int i, j = meta.getColumnCount(), ct = 0, types[] = new int[j], limit = Var
|
||||
// .getInt("webbuilder.control.limitRecords");
|
||||
// boolean isFirst = true;
|
||||
//
|
||||
// for (i = 0; i < j; i++)
|
||||
// types[i] = meta.getColumnType(i + 1);
|
||||
// buf.append('[');
|
||||
// while (rs.next()) {
|
||||
// if (ct > limit)
|
||||
// break;
|
||||
// if (isFirst)
|
||||
// isFirst = false;
|
||||
// else
|
||||
// buf.append(',');
|
||||
// if (j > 1) {
|
||||
// buf.append('[');
|
||||
// for (i = 0; i < j; i++) {
|
||||
// if (i > 0)
|
||||
// buf.append(',');
|
||||
// buf.append(StringUtil.encode(DbUtil.getObject(rs, i + 1,
|
||||
// types[i], true)));
|
||||
// }
|
||||
// buf.append(']');
|
||||
// } else
|
||||
// buf.append(StringUtil.encode(DbUtil.getObject(rs, 1, types[0],
|
||||
// true)));
|
||||
// ct++;
|
||||
// }
|
||||
// buf.append(']');
|
||||
// return buf.toString();
|
||||
// }
|
||||
|
||||
public static String getCharStream(ResultSet rs, int index)
|
||||
throws Exception {
|
||||
return (String) getObject(rs, index, -1);
|
||||
}
|
||||
|
||||
public static void setCharStream(PreparedStatement st, int index,
|
||||
String value) throws Exception {
|
||||
setObject(st, index, -1, value);
|
||||
}
|
||||
|
||||
public static Object getObject(CallableStatement st, int index, int type)
|
||||
throws Exception {
|
||||
switch (type) {
|
||||
case Types.CHAR:
|
||||
case Types.NCHAR:
|
||||
case Types.VARCHAR:
|
||||
case Types.NVARCHAR:
|
||||
return st.getString(index);
|
||||
case Types.INTEGER:
|
||||
return st.getInt(index);
|
||||
case Types.TINYINT:
|
||||
return st.getByte(index);
|
||||
case Types.SMALLINT:
|
||||
return st.getShort(index);
|
||||
case Types.BIGINT:
|
||||
return st.getLong(index);
|
||||
case Types.REAL:
|
||||
case Types.FLOAT:
|
||||
return st.getFloat(index);
|
||||
case Types.DOUBLE:
|
||||
return st.getDouble(index);
|
||||
case Types.DECIMAL:
|
||||
case Types.NUMERIC:
|
||||
return st.getBigDecimal(index);
|
||||
case Types.TIMESTAMP:
|
||||
case Types.DATE:
|
||||
return st.getTimestamp(index);
|
||||
case Types.TIME:
|
||||
return st.getTime(index);
|
||||
case Types.BOOLEAN:
|
||||
case Types.BIT:
|
||||
return st.getBoolean(index);
|
||||
case Types.LONGVARCHAR:
|
||||
case Types.LONGNVARCHAR:
|
||||
case Types.CLOB:
|
||||
case Types.NCLOB:
|
||||
Reader rd = st.getCharacterStream(index);
|
||||
if (rd == null)
|
||||
return null;
|
||||
else
|
||||
return StringUtil.readString(rd);
|
||||
default:
|
||||
return st.getObject(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getObject(ResultSet rs, int index, int type)
|
||||
throws Exception {
|
||||
return getObject(rs, index, type, true);
|
||||
}
|
||||
|
||||
public static Object getObject(ResultSet rs, int index, int type,
|
||||
boolean ignoreBlob) throws Exception {
|
||||
Object obj;
|
||||
switch (type) {
|
||||
case Types.CHAR:
|
||||
case Types.NCHAR:
|
||||
case Types.VARCHAR:
|
||||
case Types.NVARCHAR:
|
||||
obj = rs.getString(index);
|
||||
break;
|
||||
case Types.INTEGER:
|
||||
obj = rs.getInt(index);
|
||||
break;
|
||||
case Types.TINYINT:
|
||||
obj = rs.getByte(index);
|
||||
break;
|
||||
case Types.SMALLINT:
|
||||
obj = rs.getShort(index);
|
||||
break;
|
||||
case Types.BIGINT:
|
||||
obj = rs.getLong(index);
|
||||
break;
|
||||
case Types.REAL:
|
||||
case Types.FLOAT:
|
||||
obj = rs.getFloat(index);
|
||||
break;
|
||||
case Types.DOUBLE:
|
||||
obj = rs.getDouble(index);
|
||||
break;
|
||||
case Types.DECIMAL:
|
||||
case Types.NUMERIC:
|
||||
obj = rs.getBigDecimal(index);
|
||||
break;
|
||||
case Types.TIMESTAMP:
|
||||
case Types.DATE:
|
||||
obj = rs.getTimestamp(index);
|
||||
break;
|
||||
case Types.TIME:
|
||||
obj = rs.getTime(index);
|
||||
break;
|
||||
case Types.BOOLEAN:
|
||||
case Types.BIT:
|
||||
obj = rs.getBoolean(index);
|
||||
break;
|
||||
case Types.LONGVARCHAR:
|
||||
case Types.LONGNVARCHAR:
|
||||
case Types.CLOB:
|
||||
case Types.NCLOB:
|
||||
Reader rd = rs.getCharacterStream(index);
|
||||
if (rd == null)
|
||||
obj = null;
|
||||
else
|
||||
obj = StringUtil.readString(rd);
|
||||
break;
|
||||
case Types.BLOB:
|
||||
case Types.BINARY:
|
||||
case Types.VARBINARY:
|
||||
case Types.LONGVARBINARY:
|
||||
InputStream is = rs.getBinaryStream(index);
|
||||
if (ignoreBlob) {
|
||||
if (is == null)
|
||||
return "(blob)";
|
||||
else {
|
||||
is.close();
|
||||
return "(BLOB)";
|
||||
}
|
||||
} else
|
||||
return is;
|
||||
default:
|
||||
obj = rs.getObject(index);
|
||||
}
|
||||
if (rs.wasNull())
|
||||
return null;
|
||||
else
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static void setObject(PreparedStatement st, int index, int type,
|
||||
Object obj) throws Exception {
|
||||
if (obj != null && !(obj instanceof String)) {
|
||||
if (obj instanceof InputStream)
|
||||
st.setBinaryStream(index, (InputStream) obj,
|
||||
((InputStream) obj).available());
|
||||
else if (obj instanceof DateTime)
|
||||
st.setLong(index, ((DateTime)obj).getMillis());
|
||||
else {
|
||||
if (type != 12)
|
||||
st.setObject(index, obj, type);
|
||||
else
|
||||
st.setObject(index, obj);
|
||||
}
|
||||
return;
|
||||
}
|
||||
String value;
|
||||
|
||||
if (obj == null)
|
||||
value = null;
|
||||
else
|
||||
value = (String) obj;
|
||||
if (StringUtil.isEmpty(value))
|
||||
st.setNull(index, type);
|
||||
else {
|
||||
switch (type) {
|
||||
case Types.CHAR:
|
||||
case Types.NCHAR:
|
||||
case Types.VARCHAR:
|
||||
case Types.NVARCHAR:
|
||||
st.setString(index, value);
|
||||
break;
|
||||
case Types.INTEGER:
|
||||
st.setInt(index, Integer.parseInt(value));
|
||||
break;
|
||||
case Types.TINYINT:
|
||||
st.setByte(index, Byte.parseByte(value));
|
||||
break;
|
||||
case Types.SMALLINT:
|
||||
st.setShort(index, Short.parseShort(value));
|
||||
break;
|
||||
case Types.BIGINT:
|
||||
st.setLong(index, Long.parseLong(value));
|
||||
break;
|
||||
case Types.REAL:
|
||||
case Types.FLOAT:
|
||||
st.setFloat(index, Float.parseFloat(value));
|
||||
break;
|
||||
case Types.DOUBLE:
|
||||
st.setDouble(index, Double.parseDouble(value));
|
||||
break;
|
||||
case Types.DECIMAL:
|
||||
case Types.NUMERIC:
|
||||
st.setBigDecimal(index, new BigDecimal(value));
|
||||
break;
|
||||
case Types.TIMESTAMP:
|
||||
case Types.DATE:
|
||||
st.setLong(index, Long.parseLong(value));
|
||||
break;
|
||||
case Types.TIME:
|
||||
st.setTime(index, Time.valueOf(fixTime(value)));
|
||||
break;
|
||||
case Types.BOOLEAN:
|
||||
case Types.BIT:
|
||||
st.setBoolean(index, StringUtil.getBool(value));
|
||||
break;
|
||||
case Types.LONGVARCHAR:
|
||||
case Types.LONGNVARCHAR:
|
||||
case Types.CLOB:
|
||||
case Types.NCLOB:
|
||||
st.setCharacterStream(index, new StringReader(value), value
|
||||
.length());
|
||||
break;
|
||||
case Types.BLOB:
|
||||
case Types.BINARY:
|
||||
case Types.VARBINARY:
|
||||
// case Types.LONGVARBINARY:
|
||||
// InputStream is = new ByteArrayInputStream(StringUtil
|
||||
// .decodeBase64(value));
|
||||
// st.setBinaryStream(index, is, is.available());
|
||||
// break;
|
||||
default:
|
||||
st.setObject(index, value, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String TO_DATE (DateTime time, boolean dayOnly, Locale local)
|
||||
{
|
||||
if (time == null)
|
||||
{
|
||||
if (dayOnly)
|
||||
return "TRUNC(SysDate)";
|
||||
return "SysDate";
|
||||
}
|
||||
|
||||
StringBuffer dateString = new StringBuffer("'");
|
||||
if (dayOnly)
|
||||
{
|
||||
dateString.append(time.toString(ExDateUtil.YYYY_MM_DD, local));
|
||||
dateString.append("'");
|
||||
}
|
||||
else
|
||||
{
|
||||
dateString.append(time.toString(ExDateUtil.YYYY_MM_DD_HH_MM_SS_SS, local)); // cut off miliseconds
|
||||
dateString.append("'");
|
||||
}
|
||||
return dateString.toString();
|
||||
}
|
||||
|
||||
public static String TO_STRING (String txt, int maxLength)
|
||||
{
|
||||
if (txt == null || txt.length() == 0)
|
||||
return "NULL";
|
||||
// Length
|
||||
String text = txt;
|
||||
if (maxLength != 0 && text.length() > maxLength)
|
||||
text = txt.substring(0, maxLength);
|
||||
|
||||
// copy characters (we need to look through anyway)
|
||||
StringBuffer out = new StringBuffer();
|
||||
out.append(QUOTE); // '
|
||||
for (int i = 0; i < text.length(); i++)
|
||||
{
|
||||
char c = text.charAt(i);
|
||||
if (c == QUOTE)
|
||||
out.append("''");
|
||||
else
|
||||
out.append(c);
|
||||
}
|
||||
out.append(QUOTE); // '
|
||||
//
|
||||
return out.toString();
|
||||
} // TO_STRING
|
||||
|
||||
/** Quote */
|
||||
private static final char QUOTE = '\'';
|
||||
|
||||
|
||||
public static String encodeString(String str) throws Exception {
|
||||
return StringUtil.replace(URLEncoder.encode(str, "utf-8"), "+", "%20");
|
||||
}
|
||||
|
||||
public static int isToOs(InputStream is, OutputStream os) throws Exception {
|
||||
byte buf[] = new byte[8192];
|
||||
int len, size = 0;
|
||||
|
||||
while ((len = is.read(buf)) > 0) {
|
||||
os.write(buf, 0, len);
|
||||
size += len;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public static void closeInputStream(InputStream inputStream) {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String fixTime(String str) {
|
||||
if (str.indexOf(':') == -1)
|
||||
return "00:00:00";
|
||||
int b = str.indexOf(' '), e = str.indexOf('.');
|
||||
if (b == -1)
|
||||
b = 0;
|
||||
if (e == -1)
|
||||
e = str.length();
|
||||
return str.substring(b, e);
|
||||
}
|
||||
|
||||
public static String fixTimestamp(String str) {
|
||||
if (str.indexOf(':') == -1)
|
||||
return qualify(str) + " 00:00:00";
|
||||
else {
|
||||
int i = str.indexOf(' ');
|
||||
return qualify(str.substring(0, i)) + str.substring(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static String qualify(String dateStr) {
|
||||
if (dateStr.length() == 10)
|
||||
return dateStr;
|
||||
String[] sec = StringUtil.split(dateStr, "-");
|
||||
if (sec.length == 3) {
|
||||
StringBuilder buf = new StringBuilder(10);
|
||||
buf.append(sec[0]);
|
||||
buf.append("-");
|
||||
if (sec[1].length() == 1)
|
||||
buf.append("0");
|
||||
buf.append(sec[1]);
|
||||
buf.append("-");
|
||||
if (sec[2].length() == 1)
|
||||
buf.append("0");
|
||||
buf.append(sec[2]);
|
||||
return buf.toString();
|
||||
} else
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package com.dsasp.server.common.util;
|
||||
|
||||
import org.joda.time.DateMidnight;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.Days;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
/**
|
||||
* Date Utility Class used to convert Strings to Dates and Timestamps to correct
|
||||
* time pattern. Minutes should be mm not MM (MM is month).
|
||||
*/
|
||||
public class ExDateUtil {
|
||||
public static final String TIME_PATTERN = "HH:mm";
|
||||
public static final String YYYY_MM_DD_HH_MM_SS_SS = "yyyy-MM-dd HH:mm:ss.SS";
|
||||
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
|
||||
public static final String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
public static final String YYYYMMDD = "yyyyMMdd";
|
||||
public static final long DAY = 24L * 60L * 60L * 1000L;
|
||||
/**
|
||||
* Checkstyle rule: utility classes should not have public constructor
|
||||
*/
|
||||
/**
|
||||
* 返回当前日期+时间
|
||||
* YYYY_MM_DD_HH_MM_SS
|
||||
* @return DateTime 返回该日期
|
||||
*/
|
||||
public final static DateTime getNow(DateTimeZone timezone) {
|
||||
return new DateTime(timezone);
|
||||
}
|
||||
/**
|
||||
* 返回当前日期+时间(00:00:00)
|
||||
* YYYY_MM_DD_HH_MM_SS
|
||||
* @return DateTime 返回该日期
|
||||
*/
|
||||
public final static DateTime getDate(DateTimeZone timezone) {
|
||||
return new DateMidnight(timezone).toDateTime();
|
||||
}
|
||||
/**
|
||||
* 返回当前日期+时间
|
||||
* YYYY_MM_DD_HH_MM_SS
|
||||
* @return String 返回该日期的字符串格式
|
||||
*/
|
||||
public final static String getNowTimeByString(DateTimeZone timezone) {
|
||||
DateTime now = getNow(timezone);
|
||||
return now.toString(YYYY_MM_DD_HH_MM_SS);
|
||||
}
|
||||
/**
|
||||
* 返回当天的开始日期+时间
|
||||
* YYYY_MM_DD_HH_MM_SS
|
||||
* @return DateTime 返回该日期
|
||||
*/
|
||||
public final static DateTime getStartTimeOfDay(DateTimeZone timezone){
|
||||
return new DateMidnight(timezone).toDateTime();
|
||||
}
|
||||
/**
|
||||
* 返回当天的开始日期+时间(00:00:00)
|
||||
* YYYY_MM_DD_HH_MM_SS
|
||||
* @return String 返回该日期的字符串格式
|
||||
*/
|
||||
public final static String getStartTimeOfDayByString(DateTimeZone timezone){
|
||||
DateTime start = getStartTimeOfDay(timezone);
|
||||
return start.toString(YYYY_MM_DD_HH_MM_SS);
|
||||
}
|
||||
/**
|
||||
* 返回当天的最后日期+时间(23:59:59)
|
||||
* YYYY_MM_DD_HH_MM_SS
|
||||
* @return String 返回该日期
|
||||
*/
|
||||
public final static DateTime getEndTimeOfDay(DateTimeZone timezone){
|
||||
DateTime now = getStartTimeOfDay(timezone);
|
||||
DateTime end = now.plusDays(1).plus(-1000);
|
||||
return end;
|
||||
}
|
||||
/**
|
||||
* 返回指定日期的月份第一天
|
||||
*/
|
||||
public final static DateTime getStartDayOfMonth(DateTime date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTime(date.getYear(), date.getMonthOfYear(), 1, 0, 0, 0);
|
||||
}
|
||||
/**
|
||||
* 返回指定日期的月份最后一天
|
||||
*/
|
||||
public final static DateTime getEndDayOfMonth(DateTime date) {
|
||||
if (date == null)
|
||||
return null;
|
||||
DateTime dt = getStartDayOfMonth(date);// 所在月第一天
|
||||
dt = dt.plusMonths(1);// 所在月的下一个月第一天
|
||||
return dt.plusDays(-1);
|
||||
}
|
||||
/**
|
||||
* 返回指定日期的年
|
||||
* @return Integer 返回年
|
||||
*/
|
||||
public final static Integer getYear(DateTime date){
|
||||
if (date == null)
|
||||
return null;
|
||||
return date.getYear();
|
||||
}
|
||||
/**
|
||||
* 返回指定日期的月份
|
||||
* @return Integer 返回月份
|
||||
*/
|
||||
public final static Integer getMonth(DateTime date){
|
||||
if (date == null)
|
||||
return null;
|
||||
return date.getMonthOfYear();
|
||||
}
|
||||
/**
|
||||
* 返回指定日期的当月日期
|
||||
* @return Integer 返回当月日期
|
||||
*/
|
||||
public final static Integer getDay(DateTime date){
|
||||
if (date == null)
|
||||
return null;
|
||||
return date.getDayOfMonth();
|
||||
}
|
||||
/**
|
||||
* 给指定的日期注入一个结束时间23:59:59
|
||||
* @param date
|
||||
* @return Date
|
||||
*/
|
||||
public final static DateTime innerEndTimeOfDay(DateTime date){
|
||||
if (date == null)
|
||||
return null;
|
||||
DateTime newDate = innerStartTimeOfDay(date);
|
||||
return newDate.plusDays(1).plus(-1000);
|
||||
}
|
||||
/**
|
||||
* 给指定的日期注入一个开始时间00:00:00
|
||||
* @param date
|
||||
* @return Date
|
||||
*/
|
||||
public final static DateTime innerStartTimeOfDay(DateTime date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
DateMidnight md = new DateMidnight(date.getMillis(), date.getZone());
|
||||
return md.toDateTime();
|
||||
}
|
||||
/**
|
||||
* 返回当天的最后日期+时间
|
||||
* @return String 返回该日期的字符串格式(yyyy-MM-dd HH:mm:ss)
|
||||
*/
|
||||
public final static String getEndTimeOfDayByString(DateTimeZone timezone) {
|
||||
DateTime date = getEndTimeOfDay(timezone);
|
||||
return date.toString(YYYY_MM_DD_HH_MM_SS);
|
||||
}
|
||||
/**
|
||||
* 转换指定的时间字符串为指定的格式的时间
|
||||
* @param date
|
||||
* @param pattern
|
||||
* @return 格式化后的时间
|
||||
*/
|
||||
public final static DateTime convertStringTodate(String date, String pattern) {
|
||||
if (date == null || pattern == null)
|
||||
return null;
|
||||
DateTimeFormatter format = DateTimeFormat.forPattern(pattern);
|
||||
return DateTime.parse(date, format);
|
||||
}
|
||||
/**
|
||||
* 转换指定的时间为指定的格式的时间字符串
|
||||
* @param date
|
||||
* @param pattern
|
||||
* @return 格式化后的时间字符串
|
||||
*/
|
||||
public final static String convertDateToString(DateTime date, String pattern)
|
||||
{
|
||||
if (date == null || pattern == null)
|
||||
return null;
|
||||
return date.toString(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较2个日期,返回相差天数
|
||||
* @param from 被减数
|
||||
* @param to 减数
|
||||
* @return int 天数
|
||||
*/
|
||||
public final static int compareDate(DateTime from,DateTime to){
|
||||
return Days.daysBetween(from, to).getDays();
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间转换显示星期
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public final static String convertDateToWeek(DateTime date){
|
||||
if (date == null)
|
||||
return null;
|
||||
int day = date.getDayOfWeek();
|
||||
String showWeek = "";
|
||||
switch (day) {
|
||||
case 1:
|
||||
showWeek = "星期一";
|
||||
break;
|
||||
case 2:
|
||||
showWeek = "星期二";
|
||||
break;
|
||||
case 3:
|
||||
showWeek = "星期三";
|
||||
break;
|
||||
case 4:
|
||||
showWeek = "星期四";
|
||||
break;
|
||||
case 5:
|
||||
showWeek = "星期五";
|
||||
break;
|
||||
case 6:
|
||||
showWeek = "星期六";
|
||||
break;
|
||||
default:
|
||||
showWeek = "星期日";
|
||||
break;
|
||||
}
|
||||
return showWeek;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// DateTime dt = new DateTime(2013,9,25,11,12,0);
|
||||
// DateMidnight md = new DateMidnight(dt.getMillis(),dt.getZone());
|
||||
// System.out.println(dt);
|
||||
// System.out.println(md.toDateTime());
|
||||
// System.out.println(getEndTimeOfDay(DateTimeZone.UTC));
|
||||
// System.out.println(innerEndTimeOfDay(new DateTime()));
|
||||
// System.out.println(convertDateToWeek(new DateTime()));
|
||||
// System.out.println(compareDate(new DateTime(2013,8,30,0,0,0),new DateTime()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,809 @@
|
||||
package com.dsasp.server.common.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.text.CollationKey;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
public class StringUtil {
|
||||
private static final String HexCharSet = "0123456789ABCDEF";
|
||||
|
||||
/**
|
||||
* ASCII表中可见字符从!开始,偏移位值为33(Decimal)
|
||||
*/
|
||||
private static final char DBC_CHAR_START = 33; // 半角!
|
||||
/**
|
||||
* ASCII表中可见字符到~结束,偏移位值为126(Decimal)
|
||||
*/
|
||||
private static final char DBC_CHAR_END = 126; // 半角~
|
||||
/**
|
||||
* 全角对应于ASCII表的可见字符从!开始,偏移值为65281
|
||||
*/
|
||||
private static final char SBC_CHAR_START = 65281; // 全角!
|
||||
/**
|
||||
* 全角对应于ASCII表的可见字符到~结束,偏移值为65374
|
||||
*/
|
||||
private static final char SBC_CHAR_END = 65374; // 全角~
|
||||
/**
|
||||
* ASCII表中除空格外的可见字符与对应的全角字符的相对偏移
|
||||
*/
|
||||
private static final int CONVERT_STEP = 65248; // 全角半角转换间隔
|
||||
/**
|
||||
* 全角空格的值,它没有遵从与ASCII的相对偏移,必须单独处理
|
||||
*/
|
||||
private static final char SBC_SPACE = 12288; // 全角空格 12288
|
||||
/**
|
||||
* 半角空格的值,在ASCII中为32(Decimal)
|
||||
*/
|
||||
private static final char DBC_SPACE = ' '; // 半角空格
|
||||
|
||||
/**
|
||||
* 半角字符->全角字符转换
|
||||
* 只处理空格,!到˜之间的字符,忽略其他
|
||||
*/
|
||||
public static String banjiaoToQuanjiao(String src) {
|
||||
if (src == null)
|
||||
return src;
|
||||
char[] ca = src.toCharArray();
|
||||
char[] buf = new char[ca.length];
|
||||
for (int i = 0; i < ca.length; i++) {
|
||||
if (ca[i] == DBC_SPACE) //半角空格
|
||||
buf[i] = SBC_SPACE;
|
||||
else if ((ca[i] >= DBC_CHAR_START) && (ca[i] <= DBC_CHAR_END))//!到~
|
||||
buf[i] = (char) (ca[i] + CONVERT_STEP);
|
||||
else
|
||||
buf[i] = ca[i];
|
||||
}
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全角字符->半角字符转换
|
||||
* 只处理全角的空格,全角!到全角~之间的字符,忽略其他
|
||||
*/
|
||||
public static String quanjiaoToBanjiao(String src) {
|
||||
if (src == null)
|
||||
return src;
|
||||
char[] ca = src.toCharArray();
|
||||
char[] buf = new char[ca.length];
|
||||
for (int i = 0; i < src.length(); i++) {
|
||||
if (ca[i] >= SBC_CHAR_START && ca[i] <= SBC_CHAR_END)//全角!到~
|
||||
buf[i] = (char) (ca[i] - CONVERT_STEP);
|
||||
else if (ca[i] == SBC_SPACE)//全角空格
|
||||
buf[i] = DBC_SPACE;
|
||||
else
|
||||
buf[i] = ca[i];
|
||||
}
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
public static String[] sort(List<String> list) {
|
||||
String[] sl = list.toArray(new String[list.size()]);
|
||||
return StringUtil.sort(sl);
|
||||
}
|
||||
|
||||
public static String[] sort(String[] list) {
|
||||
Arrays.sort(list, new Comparator<String>() {
|
||||
Collator collator = Collator.getInstance();
|
||||
|
||||
public int compare(String s1, String s2) {
|
||||
CollationKey key1 = collator.getCollationKey(optString(s1)
|
||||
.toLowerCase());
|
||||
CollationKey key2 = collator.getCollationKey(optString(s2)
|
||||
.toLowerCase());
|
||||
return key1.compareTo(key2);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String duplicate(String text, int count) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
buf.append(text);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String[] getList(String... args) {
|
||||
String r[] = new String[args.length];
|
||||
int i = 0;
|
||||
|
||||
for (String s : args)
|
||||
r[i++] = s;
|
||||
return r;
|
||||
}
|
||||
|
||||
public static String[] split(String string, String separator) {
|
||||
String[] result;
|
||||
if (isEmpty(string)) {
|
||||
result = new String[1];
|
||||
result[0] = "";
|
||||
return result;
|
||||
}
|
||||
result = new String[stringOccur(string, separator) + 1];
|
||||
int oldPos = 0, pos = 0, count = 0, len = separator.length();
|
||||
while (pos != -1) {
|
||||
pos = string.indexOf(separator, oldPos);
|
||||
if (pos != -1) {
|
||||
result[count++] = string.substring(oldPos, pos);
|
||||
pos += len;
|
||||
oldPos = pos;
|
||||
}
|
||||
}
|
||||
result[count] = string.substring(oldPos);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isSame(String string1, String string2) {
|
||||
String s1, s2;
|
||||
|
||||
if (string1 == null)
|
||||
s1 = "";
|
||||
else
|
||||
s1 = string1;
|
||||
if (string2 == null)
|
||||
s2 = "";
|
||||
else
|
||||
s2 = string2;
|
||||
return s1.equalsIgnoreCase(s2);
|
||||
}
|
||||
|
||||
public static boolean isEqual(String string1, String string2) {
|
||||
String s1, s2;
|
||||
|
||||
if (string1 == null)
|
||||
s1 = "";
|
||||
else
|
||||
s1 = string1;
|
||||
if (string2 == null)
|
||||
s2 = "";
|
||||
else
|
||||
s2 = string2;
|
||||
return s1.equals(s2);
|
||||
}
|
||||
|
||||
public static String toHTML(String string) {
|
||||
return toHTML(string, false, true);
|
||||
}
|
||||
|
||||
public static String convertHTML(String string) {
|
||||
if (isEmpty(string))
|
||||
return "";
|
||||
int i, j = string.length();
|
||||
StringBuilder out = new StringBuilder();
|
||||
char c;
|
||||
|
||||
for (i = 0; i < j; i++) {
|
||||
c = string.charAt(i);
|
||||
switch (c) {
|
||||
case '&':
|
||||
out.append("&");
|
||||
break;
|
||||
case '>':
|
||||
out.append(">");
|
||||
break;
|
||||
case '<':
|
||||
out.append("<");
|
||||
break;
|
||||
default:
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String toHTML(String string, boolean nbspAsEmpty,
|
||||
boolean brAsEnter) {
|
||||
if (isEmpty(string)) {
|
||||
if (nbspAsEmpty)
|
||||
return " ";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
int i, j = string.length();
|
||||
StringBuilder out = new StringBuilder();
|
||||
char c;
|
||||
|
||||
for (i = 0; i < j; i++) {
|
||||
c = string.charAt(i);
|
||||
switch (c) {
|
||||
case ' ':
|
||||
out.append(" ");
|
||||
break;
|
||||
case '"':
|
||||
out.append(""");
|
||||
break;
|
||||
case '<':
|
||||
out.append("<");
|
||||
break;
|
||||
case '>':
|
||||
out.append(">");
|
||||
break;
|
||||
case '&':
|
||||
out.append("&");
|
||||
break;
|
||||
case '\n':
|
||||
if (brAsEnter)
|
||||
out.append("<br>");
|
||||
else
|
||||
out.append(" ");
|
||||
break;
|
||||
case '\r':
|
||||
break;
|
||||
case '\t':
|
||||
out.append(" ");
|
||||
break;
|
||||
default:
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static boolean across(String[] list1, String[] list2) {
|
||||
if (list1 == null || list2 == null)
|
||||
return false;
|
||||
for (String s1 : list1)
|
||||
for (String s2 : list2)
|
||||
if (s1.equals(s2))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int indexOf(String list[], String string) {
|
||||
int i, j;
|
||||
|
||||
if (list == null)
|
||||
return -1;
|
||||
j = list.length;
|
||||
for (i = 0; i < j; i++)
|
||||
if (list[i].equals(string))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static String concat(String s, String... more) {
|
||||
StringBuilder buf = new StringBuilder(s);
|
||||
for (String t : more)
|
||||
buf.append(t);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static boolean getBool(String value) {
|
||||
return isEqual(value, "1") || isSame(value, "true");
|
||||
}
|
||||
|
||||
public static int stringOccur(String source, String dest) {
|
||||
if (isEmpty(source) || isEmpty(dest))
|
||||
return 0;
|
||||
int pos = 0, count = 0;
|
||||
while (pos != -1) {
|
||||
pos = source.indexOf(dest, pos);
|
||||
if (pos != -1) {
|
||||
pos++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String string, boolean decimal) {
|
||||
int i, j;
|
||||
String ts;
|
||||
char ch;
|
||||
|
||||
ts = string.trim();
|
||||
if (decimal && stringOccur(string, ".") > 1)
|
||||
return false;
|
||||
if (ts.length() > 1 && isEqual(ts.substring(0, 1), "-"))
|
||||
ts = ts.substring(1);
|
||||
j = ts.length();
|
||||
if (j == 0)
|
||||
return false;
|
||||
for (i = 0; i < j; i++) {
|
||||
ch = ts.charAt(i);
|
||||
if (!(ch >= '0' && ch <= '9') && (!decimal || ch != '.'))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String toLine(String string) {
|
||||
if (string == null)
|
||||
return "";
|
||||
string = string.trim();
|
||||
int i, len = string.length();
|
||||
if (len == 0)
|
||||
return "";
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
char c;
|
||||
for (i = 0; i < len; i++) {
|
||||
c = string.charAt(i);
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
buffer.append(' ');
|
||||
break;
|
||||
default:
|
||||
buffer.append(c);
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static List<Entry<String, ?>> sortMapValue(Map<String, ?> map) {
|
||||
List<Entry<String, ?>> list = new ArrayList<Entry<String, ?>>(
|
||||
map.entrySet());
|
||||
Collections.sort(list, new Comparator<Entry<String, ?>>() {
|
||||
Collator collator = Collator.getInstance();
|
||||
|
||||
public int compare(Entry<String, ?> e1, Entry<String, ?> e2) {
|
||||
CollationKey key1 = collator.getCollationKey(e1.getValue()
|
||||
.toString().toLowerCase());
|
||||
CollationKey key2 = collator.getCollationKey(e2.getValue()
|
||||
.toString().toLowerCase());
|
||||
return key1.compareTo(key2);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map) {
|
||||
return sortMapKey(map, false);
|
||||
}
|
||||
|
||||
public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map,
|
||||
boolean keyAsNumber) {
|
||||
List<Entry<String, ?>> list = new ArrayList<Entry<String, ?>>(
|
||||
map.entrySet());
|
||||
final boolean keyAsNum = keyAsNumber;
|
||||
Collections.sort(list, new Comparator<Entry<String, ?>>() {
|
||||
Collator collator = Collator.getInstance();
|
||||
|
||||
public int compare(Entry<String, ?> e1, Entry<String, ?> e2) {
|
||||
if (keyAsNum)
|
||||
return Integer.parseInt(e1.getKey())
|
||||
- Integer.parseInt(e2.getKey());
|
||||
else {
|
||||
CollationKey key1 = collator.getCollationKey(e1.getKey()
|
||||
.toLowerCase());
|
||||
CollationKey key2 = collator.getCollationKey(e2.getKey()
|
||||
.toLowerCase());
|
||||
return key1.compareTo(key2);
|
||||
}
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String getNamePart(String string) {
|
||||
if (string == null)
|
||||
return "";
|
||||
int index = string.indexOf('=');
|
||||
|
||||
if (index == -1)
|
||||
return string;
|
||||
else
|
||||
return string.substring(0, index);
|
||||
}
|
||||
|
||||
public static String getValuePart(String string) {
|
||||
if (string == null)
|
||||
return "";
|
||||
int index = string.indexOf('=');
|
||||
|
||||
if (index == -1)
|
||||
return "";
|
||||
else
|
||||
return string.substring(index + 1);
|
||||
}
|
||||
|
||||
// public static String replaceParameters(HttpServletRequest request,
|
||||
// String text) throws Exception {
|
||||
// int start = 0, startPos = text.indexOf("{#", start), endPos = text
|
||||
// .indexOf("#}", startPos + 2);
|
||||
// if (startPos != -1 && endPos != -1) {
|
||||
// String prefix, paramName, paramValue;
|
||||
// StringBuilder buf = new StringBuilder();
|
||||
//
|
||||
// while (startPos != -1 && endPos != -1) {
|
||||
// paramName = text.substring(startPos + 2, endPos);
|
||||
// prefix = substring(paramName, 0, 4);
|
||||
// if (prefix.equals("Var.")) {
|
||||
// paramValue = Var.get(paramName.substring(4));
|
||||
// if (paramValue == null)
|
||||
// paramValue = "";
|
||||
// } else if (prefix.equals("Str."))
|
||||
// paramValue = Str.format(request, paramName.substring(4));
|
||||
// else
|
||||
// paramValue = WebUtil.fetch(request, paramName);
|
||||
// buf.append(text.substring(start, startPos));
|
||||
// buf.append(paramValue);
|
||||
// start = endPos + 2;
|
||||
// startPos = text.indexOf("{#", start);
|
||||
// endPos = text.indexOf("#}", startPos + 2);
|
||||
// }
|
||||
// buf.append(text.substring(start));
|
||||
// return buf.toString();
|
||||
// } else
|
||||
// return text;
|
||||
// }
|
||||
|
||||
public static String replace(String string, String oldString,
|
||||
String newString) {
|
||||
return innerReplace(string, oldString, newString, true);
|
||||
}
|
||||
|
||||
public static String replaceFirst(String string, String oldString,
|
||||
String newString) {
|
||||
return innerReplace(string, oldString, newString, false);
|
||||
}
|
||||
|
||||
public static String substring(String string, int pos, int len) {
|
||||
if (string == null || string.length() < len - pos)
|
||||
return "";
|
||||
return string.substring(pos, pos + len);
|
||||
}
|
||||
|
||||
public static String joinArray(String list[], String spliter) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
boolean isFirst = true;
|
||||
|
||||
for (String s : list) {
|
||||
if (isFirst)
|
||||
isFirst = false;
|
||||
else
|
||||
buf.append(spliter);
|
||||
buf.append(s);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String joinList(Iterable<String> list, String spliter) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
boolean isFirst = true;
|
||||
|
||||
for (String s : list) {
|
||||
if (isFirst)
|
||||
isFirst = false;
|
||||
else
|
||||
buf.append(spliter);
|
||||
buf.append(s);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String getUtfString(InputStream stream) throws Exception {
|
||||
return getString(stream, "utf-8");
|
||||
}
|
||||
|
||||
// public static String getString(InputStream stream) throws Exception {
|
||||
// return getString(stream, Var.get("server.charset"));
|
||||
// }
|
||||
|
||||
public static String getString(InputStream stream, String charset)
|
||||
throws Exception {
|
||||
try {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
// SysUtil.isToOs(stream, os);
|
||||
if (StringUtil.isEmpty(charset))
|
||||
return new String(os.toByteArray());
|
||||
else
|
||||
return new String(os.toByteArray(), charset);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static String innerReplace(String string, String oldString,
|
||||
String newString, boolean isAll) {
|
||||
if (string == null)
|
||||
return "";
|
||||
int index = string.indexOf(oldString);
|
||||
if (index == -1)
|
||||
return string;
|
||||
int start = 0, len = oldString.length();
|
||||
if (len == 0)
|
||||
return string;
|
||||
StringBuilder buffer = new StringBuilder(string.length() + len);
|
||||
do {
|
||||
buffer.append(string.substring(start, index));
|
||||
buffer.append(newString);
|
||||
start = index + len;
|
||||
if (!isAll)
|
||||
break;
|
||||
index = string.indexOf(oldString, start);
|
||||
} while (index != -1);
|
||||
buffer.append(string.substring(start));
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String quote(String string) {
|
||||
if (string == null)
|
||||
return "\"\"";
|
||||
int len = string.length();
|
||||
if (len == 0)
|
||||
return "\"\"";
|
||||
char b, c = 0;
|
||||
int i;
|
||||
String t;
|
||||
StringBuilder sb = new StringBuilder(len + 4);
|
||||
|
||||
sb.append('"');
|
||||
for (i = 0; i < len; i++) {
|
||||
b = c;
|
||||
c = string.charAt(i);
|
||||
switch (c) {
|
||||
case '\\':
|
||||
case '"':
|
||||
sb.append('\\');
|
||||
sb.append(c);
|
||||
break;
|
||||
case '/':
|
||||
if (b == '<')
|
||||
sb.append('\\');
|
||||
sb.append(c);
|
||||
break;
|
||||
case '\b':
|
||||
sb.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
sb.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
sb.append("\\n");
|
||||
break;
|
||||
case '\f':
|
||||
sb.append("\\f");
|
||||
break;
|
||||
case '\r':
|
||||
sb.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
|
||||
|| (c >= '\u2000' && c < '\u2100')) {
|
||||
t = "000" + Integer.toHexString(c);
|
||||
sb.append("\\u");
|
||||
sb.append(t.substring(t.length() - 4));
|
||||
} else
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
sb.append('"');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String[] merge(String[] list1, String[] list2) {
|
||||
int l = list1.length, i, j = l + list2.length;
|
||||
String[] list = new String[j];
|
||||
for (i = 0; i < j; i++) {
|
||||
if (i < l)
|
||||
list[i] = list1[i];
|
||||
else
|
||||
list[i] = list2[i - l];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String optString(String s) {
|
||||
if (s == null)
|
||||
return "";
|
||||
else
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否为空。“”也认为空
|
||||
* 对于String类型将先去除左右空格再判断
|
||||
*/
|
||||
public static boolean empty(Object s) {
|
||||
if (s == null)
|
||||
return true;
|
||||
if (s instanceof String)
|
||||
return ((String) s).trim().length() == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 不去空格的是否为空判断方法
|
||||
*/
|
||||
public static boolean isEmpty(String string) {
|
||||
return string == null || string.length() == 0;
|
||||
}
|
||||
|
||||
public static String byteToHex(byte[] bs) {
|
||||
StringBuilder buf = new StringBuilder(bs.length * 2);
|
||||
String s;
|
||||
for (byte b : bs) {
|
||||
s = Integer.toHexString(b & 0XFF);
|
||||
if (s.length() == 1)
|
||||
buf.append('0');
|
||||
buf.append(s);
|
||||
}
|
||||
return buf.toString().toUpperCase();
|
||||
}
|
||||
|
||||
public static byte[] hexToByte(String s) {
|
||||
int i, j = s.length() / 2, k;
|
||||
char[] b = s.toCharArray();
|
||||
byte[] d = new byte[j];
|
||||
|
||||
for (i = 0; i < j; i++) {
|
||||
k = i * 2;
|
||||
d[i] = (byte) (HexCharSet.indexOf(b[k]) << 4 | HexCharSet
|
||||
.indexOf(b[k + 1]));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
// public static String encodeBase64(InputStream is) throws Exception {
|
||||
// OutputStream eos = null;
|
||||
// ByteArrayOutputStream bos1, bos2;
|
||||
//
|
||||
// try {
|
||||
// bos1 = new ByteArrayOutputStream();
|
||||
// bos2 = new ByteArrayOutputStream();
|
||||
// SysUtil.isToOs(is, bos1);
|
||||
// eos = MimeUtility.encode(bos2, "base64");
|
||||
// eos.write(bos1.toByteArray());
|
||||
// } finally {
|
||||
// is.close();
|
||||
// if (eos != null)
|
||||
// eos.close();
|
||||
// }
|
||||
// return new String(bos2.toByteArray());
|
||||
// }
|
||||
//
|
||||
// public static byte[] decodeBase64(String data) throws Exception {
|
||||
// ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
|
||||
// ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
// InputStream bis;
|
||||
//
|
||||
// bis = MimeUtility.decode(is, "base64");
|
||||
// try {
|
||||
// SysUtil.isToOs(bis, os);
|
||||
// } finally {
|
||||
// bis.close();
|
||||
// }
|
||||
// return os.toByteArray();
|
||||
// }
|
||||
//
|
||||
// public static String encode(Object obj) throws Exception {
|
||||
// if (obj == null)
|
||||
// return "null";
|
||||
// else {
|
||||
// if (obj instanceof InputStream)
|
||||
// return quote(encodeBase64((InputStream) obj));
|
||||
// if (obj instanceof Number || obj instanceof Boolean)
|
||||
// return obj.toString();
|
||||
// else
|
||||
// return quote(obj.toString());
|
||||
// }
|
||||
// }
|
||||
|
||||
public static String readString(Reader reader) throws Exception {
|
||||
char buf[] = new char[8192];
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int len;
|
||||
|
||||
while ((len = reader.read(buf)) > 0) {
|
||||
sb.append(buf, 0, len);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String TO_DATE(DateTime time, boolean dayOnly, Locale local) {
|
||||
if (time == null) {
|
||||
if (dayOnly)
|
||||
return "TRUNC(SysDate)";
|
||||
return "SysDate";
|
||||
}
|
||||
|
||||
StringBuffer dateString = new StringBuffer("'");
|
||||
if (dayOnly) {
|
||||
dateString.append(time.toString(ExDateUtil.YYYY_MM_DD, local));
|
||||
dateString.append("'");
|
||||
} else {
|
||||
dateString.append(time.toString(ExDateUtil.YYYY_MM_DD_HH_MM_SS_SS,
|
||||
local)); // cut off miliseconds
|
||||
dateString.append("'");
|
||||
}
|
||||
return dateString.toString();
|
||||
}
|
||||
|
||||
public static String TO_STRING(String txt, int maxLength) {
|
||||
if (txt == null)
|
||||
return "NULL";
|
||||
// Length
|
||||
String text = txt;
|
||||
if (maxLength != 0 && text.length() > maxLength)
|
||||
text = txt.substring(0, maxLength);
|
||||
|
||||
// copy characters (we need to look through anyway)
|
||||
StringBuffer out = new StringBuffer();
|
||||
out.append(QUOTE); // '
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if (c == QUOTE)
|
||||
out.append("''");
|
||||
else
|
||||
out.append(c);
|
||||
}
|
||||
out.append(QUOTE); // '
|
||||
//
|
||||
return out.toString();
|
||||
} // TO_STRING
|
||||
|
||||
public static String convertSplitStrToSql(String txt) {
|
||||
if (txt == null || !txt.contains(",")) {
|
||||
return TO_STRING(txt, 0);
|
||||
} else {
|
||||
String[] splitStrs = txt.split(",");
|
||||
StringBuffer re = new StringBuffer();
|
||||
for (String str : splitStrs) {
|
||||
re.append(TO_STRING(str, 0));
|
||||
re.append(",");
|
||||
}
|
||||
re.deleteCharAt(re.length() - 1);
|
||||
return re.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertListStrToSql(List<String> list) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return "''";
|
||||
} else {
|
||||
|
||||
StringBuffer re = new StringBuffer();
|
||||
for (String str : list) {
|
||||
re.append(TO_STRING(str, 0));
|
||||
re.append(",");
|
||||
}
|
||||
re.deleteCharAt(re.length() - 1);
|
||||
return re.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* content xml toString , get attributes value list name="value", "=" before
|
||||
* and after is not space
|
||||
*
|
||||
* @param content
|
||||
* @param keyName
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getKeyValue(String content, String keyName) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
int index = 0;
|
||||
while (index != -1 && !StringUtil.isEmpty(content)) {
|
||||
index = content.indexOf(keyName + "=\"");
|
||||
if (index != -1) {
|
||||
content = content.substring(index + keyName.length() + 2);
|
||||
index = content.indexOf("\"");
|
||||
if (index > 0) {
|
||||
list.add(content.substring(0, index));
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static final char QUOTE = '\'';
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.dsasp.server.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.SysConfig;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用ThreadLocal提供一个存储线程内变量的地方.
|
||||
* <p/>
|
||||
* 客户端代码可以用静态方法存储和获取线程内变量,不需要依赖于HttpSession.
|
||||
* web层的Controller可通过此处向business层传入user之类的变量
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public class UserSession {
|
||||
private static final ThreadLocal sessionMap = new ThreadLocal<Properties>(){
|
||||
protected Properties initialValue() { return (null);}
|
||||
};
|
||||
private static Properties admin;
|
||||
|
||||
private static int count = 0;
|
||||
|
||||
public static Properties getAdmin(){
|
||||
if(admin == null){
|
||||
admin = new Properties();
|
||||
admin.setProperty(LoggedInUser.CURRENTUSER, LoggedInUser.ADMIN);
|
||||
List<String> roles = new ArrayList<String>();
|
||||
roles.add(LoggedInUser.ADMIN);
|
||||
admin.put(LoggedInUser.ROLES, roles);
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
|
||||
public static Properties get() {
|
||||
// System.out.println(" 当前获取线程 " + Thread.currentThread().getId());
|
||||
return(Properties) sessionMap.get();
|
||||
}
|
||||
|
||||
public static void set(Properties user) {
|
||||
sessionMap.set(user);
|
||||
}
|
||||
|
||||
public static void remove() {
|
||||
sessionMap.remove();
|
||||
}
|
||||
|
||||
public static String getCompanyName() {
|
||||
|
||||
return SysConfig.getConfigValue("com.dsasp.server.organize.COMPANY");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.dsasp.server.common.viewframework.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ProjectSwitchService {
|
||||
|
||||
public boolean isUserInProjects(String userId);
|
||||
|
||||
public Map<String,String> findAllProjectByUserId(String userId);
|
||||
|
||||
public String getProjectOrgId(String projectId);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.dsasp.server.common.workflow.bean;
|
||||
|
||||
public interface WFProcessInstance {
|
||||
|
||||
public String getProcessInstanceId();
|
||||
|
||||
public String getTitle();
|
||||
|
||||
public String getName();
|
||||
|
||||
public String getIniator();
|
||||
|
||||
public String getIniatorTime();
|
||||
|
||||
public String getStatusDisplay();
|
||||
|
||||
public Integer getStatus();
|
||||
|
||||
public String getEndTime();
|
||||
|
||||
public boolean isEnd();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.dsasp.server.common.workflow.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import com.dsasp.server.common.workflow.bean.WFProcessInstance;
|
||||
|
||||
public interface ProcessCoreService {
|
||||
|
||||
public static final String INITIATORUSERID = "WFINITIATORUSERID";
|
||||
public static final String INITIATORDEPARTID = "WFINITIATORDEPARTID";
|
||||
public static final String FORMKEYID = "WFFORMKEYID";
|
||||
public static final String TABLENAME = "TABLENAME";
|
||||
public static final String PROCESSTITLE = "PROCESSTITLE";
|
||||
public static final String PROCESSTASKTYPE= "PROCESSTASKTYPE";
|
||||
public static final String PROJECTID = "PROJECTID";
|
||||
|
||||
public static final String NEED_VALIDATE = "NEED_VALIDATE";
|
||||
|
||||
public static final int STATUS_NOSUBMIT = 1;
|
||||
public static final int STATUS_PROCESSING = 2;
|
||||
public static final int STATUS_PASS = 3;
|
||||
public static final int STATUS_NOPASS = 4;
|
||||
public static final int STATUS_RESUBMIT = 5;
|
||||
public static final int STATUS_INVALID = 6;
|
||||
|
||||
|
||||
public boolean startWF(String processDefinitionKey, Map<String, Object> variables, String businessKey, Properties ctx);
|
||||
|
||||
public boolean startWorkflow(String processDefinitionKey, Map<String, Object> variables, String tableName, String businessKey, Properties ctx);
|
||||
|
||||
|
||||
public boolean reSubmit(String processDefinitionKey, Map<String, Object> variables, String businessKey, Properties ctx);
|
||||
|
||||
|
||||
|
||||
public void passProcess(String taskId, Map<String, Object> variables, String description)
|
||||
throws Exception;
|
||||
|
||||
|
||||
public void backProcess(String taskId, String activityId,
|
||||
Map<String, Object> variables, boolean isStart, String description) throws Exception;
|
||||
|
||||
public List<String> backProcessBath(List<Map<String,Object>> protaskList) throws Exception;
|
||||
|
||||
public void activebackProcess(String taskId, String activityId,
|
||||
Map<String, Object> variables, Boolean isStart, String description) throws Exception;
|
||||
|
||||
|
||||
public void callBackProcess(String taskId, String activityId, String description)
|
||||
throws Exception ;
|
||||
|
||||
public void endProcess(String taskId, String description) throws Exception;
|
||||
|
||||
|
||||
public void transferAssignee(String taskId, List<String> userIds, String description);
|
||||
|
||||
|
||||
/**
|
||||
* 创建子任务
|
||||
* @param parentTaskId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public boolean createSubTask(String parentTaskId, List<String> userIds, String description);
|
||||
|
||||
/**
|
||||
* 创建与本任务无关的新任务
|
||||
* @param variable
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public boolean createNewTask(String taskId, Map<String, Object> variable, List<String> userIds, String description);
|
||||
|
||||
|
||||
/**
|
||||
* 根据当前任务ID,查询可以驳回的任务节点
|
||||
*
|
||||
* @param taskId
|
||||
* 当前任务ID
|
||||
*/
|
||||
public List<String> findBackAvtivity(String taskId) throws Exception;
|
||||
|
||||
/**
|
||||
* 根据当前任务ID,查询可以驳回的任务节点
|
||||
*
|
||||
* @param taskId
|
||||
* 当前任务ID
|
||||
*/
|
||||
public List<Map<String,Object>> findBackTaskName(String taskId) throws Exception;
|
||||
|
||||
/**
|
||||
* 当activity为空时,默认为前一处理者,否则为指定节点处理者
|
||||
* @param processInstanceId
|
||||
* @param activityId
|
||||
* @return
|
||||
*/
|
||||
public String getSpecialActivityProcessor(String processInstanceId,
|
||||
String activityId) ;
|
||||
|
||||
public List<WFProcessInstance> queryHistoricProcessInstance(
|
||||
String title,String processName, String iniator, DateTime start, DateTime end,
|
||||
int firstResult, int maxResults,String fz);
|
||||
|
||||
/**
|
||||
* 更换审批人
|
||||
* @param taskId
|
||||
* @param oldAssignee
|
||||
* @param userCodes
|
||||
* @param description
|
||||
*/
|
||||
public void changeAssignee(String taskId, List<String> userCodes,
|
||||
String description);
|
||||
|
||||
/**
|
||||
* 根据业务主键获取流程实例Id
|
||||
*/
|
||||
public String getProcessInstanceIdByBusinessKey(String businessKey);
|
||||
|
||||
/**
|
||||
* 根据流程实例获取流程定义id
|
||||
*/
|
||||
public String getProcessDefitionIdByInstanceId(String processInstanceId);
|
||||
|
||||
public long queryHistoricProcessInstanceCount(
|
||||
String title,String processName, String iniator, DateTime start, DateTime end,String fz);
|
||||
|
||||
public Object getWFVariable(String businessKey, String variableName);
|
||||
|
||||
public void setWFVariable(String businessKey,String variableName,Object obj);
|
||||
|
||||
public boolean invalid(String processDefinitionKey, Map variables, String tableName,
|
||||
String businessKey,String invalidReason, Properties ctx) ;
|
||||
|
||||
public void dleteCompleteProcessInstance(String processInstanceId);
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.dsasp.server.dataDic.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.DisplayType;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
public class DataDicHelper {
|
||||
|
||||
public static void addDefaultTableId(Map<String, Object> map, String tableName){
|
||||
Map<String, Object> attributeMap = new HashMap<String, Object>();
|
||||
attributeMap.put("COLUMNNAME", tableName.toUpperCase() + "_ID");
|
||||
attributeMap.put("METAID", "91D87CCD-3D7C-4C94-A89A-92595B926AD0");
|
||||
attributeMap.put("ISKEY", 1);
|
||||
attributeMap.put("ISMANDATORY", 1);
|
||||
attributeMap.put("ISIDENTIFIER", 1);
|
||||
attributeMap.put("REFERENCEID", "CHAR");
|
||||
attributeMap.put("DISPLAYNAME", "主键");
|
||||
attributeMap.put("ENTITYDISPLAYSEQ", 1);
|
||||
Object obj = map.get("ATTRIBUTES");
|
||||
if (obj != null && obj instanceof List) {
|
||||
List attributes = (List) obj;
|
||||
attributes.add(attributeMap);
|
||||
}else{
|
||||
throw new ValidationException("传入参数有误");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<GeneralPOJO> getTableDefaultAttributes(){
|
||||
List<GeneralPOJO> list = new ArrayList<GeneralPOJO>();
|
||||
list.add(getTableDefaultCreateByAtrribute());
|
||||
list.add(getTableDefaultCreateTimeAtrribute());
|
||||
list.add(getTableDefaultUpdateByAtrribute());
|
||||
list.add(getTableDefaultUpdateTimeAtrribute());
|
||||
list.add(getTableDefaultIsActiveAtrribute());
|
||||
list.add(getTableDefaultVersionAtrribute());
|
||||
list.add(getTableDefaultOrgAtrribute());
|
||||
list.add(getTableDefaultDepartAtrribute());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultCreateTimeAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.CREATETIME);
|
||||
map.put("DISPLAYNAME", "创建时间");
|
||||
map.put("METAID", "005667B8-EB06-4250-87B7-24C894457201");
|
||||
map.put("ISMANDATORY", 1);
|
||||
map.put("REFERENCEID", DisplayType.DateTime);
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "时间");
|
||||
map.put("ENTITYDISPLAYSEQ", 50);
|
||||
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultCreateByAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.CREATEBY);
|
||||
map.put("DISPLAYNAME", "创建者");
|
||||
|
||||
map.put("METAID", "AF87713D-FEC0-4F98-9474-9E7FBD7356D3");
|
||||
map.put("ISMANDATORY", 1);
|
||||
//FIXME: 创建者应为用户对象
|
||||
map.put("REFERENCEID", DisplayType.String);
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "文本");
|
||||
map.put("ENTITYDISPLAYSEQ", 51);
|
||||
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultUpdateTimeAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.UPDATETIME);
|
||||
map.put("DISPLAYNAME", "更新时间");
|
||||
map.put("METAID", "D46666E6-5BA8-41A9-B876-5EF8BCFD3081");
|
||||
map.put("ISMANDATORY", 1);
|
||||
map.put("REFERENCEID", DisplayType.DateTime);
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "时间");
|
||||
map.put("ENTITYDISPLAYSEQ", 52);
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultUpdateByAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.UPDATEBY);
|
||||
map.put("DISPLAYNAME", "更新者");
|
||||
map.put("METAID", "D3FDC944-BBC2-431D-AAE6-1C0852D9F373");
|
||||
map.put("ISMANDATORY", 1);
|
||||
//FIXME: 创建者应为用户对象
|
||||
map.put("REFERENCEID", DisplayType.String);
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "文本");
|
||||
map.put("ENTITYDISPLAYSEQ", 53);
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultIsActiveAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.ISACTIVE);
|
||||
map.put("DISPLAYNAME", "是否有效");
|
||||
map.put("METAID", "B2AF976B-A5CF-4E5F-A391-0578E92D9A5C");
|
||||
map.put("ISMANDATORY", 1);
|
||||
map.put("DEFAULTVALUE", "1");
|
||||
map.put("REFERENCEID", DisplayType.YesNo);
|
||||
map.put("ENUMERATETYPE", "YESNO");
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "布尔值");
|
||||
map.put("ENTITYDISPLAYSEQ", 56);
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultVersionAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.VERSION);
|
||||
map.put("DISPLAYNAME", "版本");
|
||||
map.put("ISMANDATORY", 1);
|
||||
map.put("METAID", "A9985CC5-E3B5-4C0C-997C-DA39A583D14B");
|
||||
map.put("DEFAULTVALUE", "0");
|
||||
map.put("REFERENCEID", DisplayType.Integer);
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "整型");
|
||||
map.put("ENTITYDISPLAYSEQ", 57);
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultDepartAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.DEPARTID);
|
||||
map.put("DISPLAYNAME", "部门");
|
||||
map.put("ISMANDATORY", 1);
|
||||
map.put("METAID", "AF7E8D34-387A-4667-BF07-A977A5C4BD12");
|
||||
//FIXME: 部门对象
|
||||
map.put("REFERENCEID", DisplayType.String);
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "文本");
|
||||
map.put("ENTITYDISPLAYSEQ", 55);
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
public static GeneralPOJO getTableDefaultOrgAtrribute(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("COLUMNNAME", GeneralPOJO.ORGID);
|
||||
map.put("DISPLAYNAME", "组织");
|
||||
map.put("METAID", "9586433E-695A-42AA-A9A3-10EE0195D2EA");
|
||||
map.put("ISMANDATORY", 1);
|
||||
//FIXME: 组织对象
|
||||
map.put("REFERENCEID", DisplayType.String);
|
||||
map.put("REFERENCEID" + GeneralPOJO.DISPLAY, "文本");
|
||||
map.put("ENTITYDISPLAYSEQ", 54);
|
||||
return new GeneralPO("SYS_ENTITYATTRIBUTE", map, UserSession.get());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package com.dsasp.server.dataDic.bean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.AbstractPOJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.DisplayType;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.POJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.SYS_Entity;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
import com.dsasp.server.db.startorupdate.InstallOrUpdate;
|
||||
|
||||
public class Entity implements SYS_Entity{
|
||||
public static final String tableName = "SYS_ENTITY";
|
||||
|
||||
public static final String tableType = "TABLETYPE";
|
||||
|
||||
public static final String isView = "ISVIEW";
|
||||
|
||||
public static final String attributes = "ATTRIBUTES";
|
||||
|
||||
public static final Integer MAINTABLE = 0;
|
||||
public static final Integer SUBTABLE = 1;
|
||||
public static final Integer MIDTABLE = 2;
|
||||
|
||||
private GeneralPOJO po;
|
||||
|
||||
public Entity(GeneralPOJO po){
|
||||
if (tableName.equals(po.get_TableName())) {
|
||||
this.po = po;
|
||||
}else{
|
||||
throw new ValidationException("参数类型不是实体类型");
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralPOJO getPo() {
|
||||
return po;
|
||||
}
|
||||
|
||||
// public void setPo(GeneralPO po) {
|
||||
// this.po = po;
|
||||
// }
|
||||
|
||||
public String getTablename() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public Integer getTabletype() {
|
||||
if(po != null){
|
||||
return po.get_ValueAsInt(tableType);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean isView() {
|
||||
if(po != null){
|
||||
return po.get_ValueAsBoolean(isView);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<GeneralPOJO> getAttributes(){
|
||||
return (List<GeneralPOJO>)po.get_Value(attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* create the table create postgresql sql
|
||||
* @return
|
||||
*/
|
||||
public String createTableSql() {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
if (!isView()) {
|
||||
StringBuffer unique = new StringBuffer();
|
||||
StringBuffer combUnique = new StringBuffer();
|
||||
sql.append("CREATE TABLE ").append(po.get_Value(tableNameCol)).append("\n");
|
||||
sql.append("(").append("\n");
|
||||
List<GeneralPOJO> list = getAttributes();
|
||||
if (list != null && list.size() > 0) {
|
||||
for (GeneralPOJO attribute : list) {
|
||||
processAttribute(attribute, sql, unique, combUnique);
|
||||
}
|
||||
}
|
||||
sql.append(unique);
|
||||
if (combUnique.length() > 0) {
|
||||
sql.append(combUnique).append("), \n");
|
||||
}
|
||||
if (MIDTABLE != getTabletype()) {
|
||||
sql.append("primary key (").append(po.get_Value(tableNameCol))
|
||||
.append("_ID)").append("\n");
|
||||
} else {
|
||||
int index = sql.lastIndexOf(",");
|
||||
sql.delete(index, index + 1);
|
||||
}
|
||||
sql.append("); \n");
|
||||
}
|
||||
if (InstallOrUpdate.isDevDB()) {
|
||||
sql.append(getOrderEntity());
|
||||
}
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
private StringBuffer getOrderEntity(){
|
||||
StringBuffer order = new StringBuffer();
|
||||
order.append("INSERT INTO order_entity(order_entity_id, tablename, sys_entitytype, sequ, updatetime, version, updateby)");
|
||||
order.append(" VALUES ( ");
|
||||
order.append(StringUtil.TO_STRING(UUID.randomUUID().toString(), 0)).append(", ");
|
||||
order.append(StringUtil.TO_STRING(po.get_Value(tableNameCol).toString(), 0)).append(", ");
|
||||
order.append(StringUtil.TO_STRING(po.get_Value("ENTITYTYPE").toString(), 0)).append(", ");
|
||||
order.append(StringUtil.TO_STRING("1", 0)).append(", ");
|
||||
order.append(System.currentTimeMillis()).append(", ");
|
||||
order.append(0).append(", ");
|
||||
order.append(StringUtil.TO_STRING(LoggedInUser.ADMIN, 0)).append("); \n");
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
* create column sql
|
||||
* @param attribute
|
||||
* @param sqlPre
|
||||
* @param unique
|
||||
* @param combUnique
|
||||
*/
|
||||
private void processAttribute(GeneralPOJO attribute, StringBuffer sqlPre, StringBuffer unique, StringBuffer combUnique){
|
||||
boolean readOnly = attribute.get_ValueAsBoolean(isReadonly);
|
||||
if(!readOnly){
|
||||
String clazz = (String)attribute.get_Value(referenceid);
|
||||
if (!DisplayType.List.equals(clazz)) {
|
||||
String colName = (String)attribute.get_Value(columnName);
|
||||
boolean mandatory = attribute.get_ValueAsBoolean(isMandatory);
|
||||
boolean identifier = attribute.get_ValueAsBoolean(isIdentifier);
|
||||
boolean combIdentifier = attribute.get_ValueAsBoolean(isCombidentifier);
|
||||
String defValue = (String)attribute.get_Value(Entity.defaultValue);
|
||||
if(GeneralPOJO.CREATEBY.equals(colName) || GeneralPOJO.UPDATEBY.equals(colName)
|
||||
|| GeneralPOJO.ORGID.equals(colName) || GeneralPOJO.DEPARTID.equals(colName)){
|
||||
sqlPre.append(colName).append(" character(36) ");
|
||||
}else if (DisplayType.String.equals(clazz) || DisplayType.Code.equals(clazz)) {
|
||||
Integer length = (Integer)attribute.get_Value(fieldLength);
|
||||
if(length == null || length <= 0){
|
||||
length = 100;
|
||||
}
|
||||
sqlPre.append(colName).append(" character varying(").append(length).append(") ");
|
||||
} else if (DisplayType.Integer.equals(clazz) || DisplayType.YesNo.equals(clazz) || DisplayType.ENUMERATE.equals(clazz)) {
|
||||
sqlPre.append(colName).append(" integer ");
|
||||
} else if (DisplayType.Number.equals(clazz) || DisplayType.Money.equals(clazz)) {
|
||||
sqlPre.append(colName).append(" numeric(18,6) ");
|
||||
} else if (DisplayType.Date.equals(clazz) || DisplayType.DateTime.equals(clazz)) {
|
||||
sqlPre.append(colName).append(" bigint ");
|
||||
} else if (DisplayType.Binary.equals(clazz) || DisplayType.STATUS.equals(clazz)) {
|
||||
return;
|
||||
} else if(DisplayType.ID.equals(clazz)){
|
||||
sqlPre.append(colName).append(" character(36) ");
|
||||
}else{
|
||||
String tableName = (String)po.get_Value(tableNameCol);
|
||||
POJOInfo info = AbstractPOJOInfo.getPOInfo(tableName);
|
||||
String referenceTableName = info.getReferenceTable(colName);
|
||||
sqlPre.append(colName).append(" character(36) REFERENCES " + referenceTableName);
|
||||
}
|
||||
if(mandatory){
|
||||
sqlPre.append(" NOT NULL ");
|
||||
}
|
||||
if(!StringUtil.isEmpty(defValue) && !DisplayType.Binary.equals(clazz)){
|
||||
if(DisplayType.Integer.equals(clazz) || DisplayType.YesNo.equals(clazz) || DisplayType.Number.equals(clazz) || DisplayType.Money.equals(clazz)){
|
||||
sqlPre.append(" DEFAULT ");
|
||||
sqlPre.append(defValue);
|
||||
}
|
||||
}
|
||||
sqlPre.append(", \n");
|
||||
if(identifier){
|
||||
unique.append(" unique (").append(colName).append("), \n");
|
||||
}else if(combIdentifier){
|
||||
// after combUnique string append in the createTableSql function
|
||||
if(combUnique.length() == 0){
|
||||
combUnique.append(" unique (");
|
||||
}else{
|
||||
combUnique.append(",");
|
||||
}
|
||||
combUnique.append(colName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* delete table sql
|
||||
* @return
|
||||
*/
|
||||
public String delteTableSql() {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
if (!isView()) {
|
||||
sql.append("drop table if exists ").append(getTablename())
|
||||
.append(" cascade;");
|
||||
}
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* sys_entityattribute table field name
|
||||
*/
|
||||
public static final String isKey = "ISKEY";
|
||||
public static final String isMandatory = "ISMANDATORY";
|
||||
public static final String isIdentifier = "ISIDENTIFIER";
|
||||
public static final String referenceid = "REFERENCEID";
|
||||
public static final String isReadonly = "ISREADONLY";
|
||||
public static final String isCombidentifier = "ISCOMBIDENTIFIER";
|
||||
public static final String fieldLength = "FIELDLENGTH";
|
||||
public static final String defaultValue = "DEFAULTVALUE";
|
||||
public static final String columnName = "COLUMNNAME";
|
||||
public static final String tableNameCol = "TABLENAME";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.dsasp.server.dataDic.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.Rule;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
|
||||
public class EntityRule implements Rule{
|
||||
|
||||
public static final String TABLENAME = "SYS_RULE";
|
||||
private GeneralPOJO po;
|
||||
private static final String name = "NAME";
|
||||
private static final String content = "CONTENT";
|
||||
private static final String entityId = "ENTITYID";
|
||||
private static final String verificationTime = "VERIFICATIONTIME";
|
||||
|
||||
public static final Integer BEFORESAVE = 0;
|
||||
public static final Integer AFTERSAVE = 1;
|
||||
public static final Integer BEFOREDELETE = 2;
|
||||
public static final Integer AFTERDELETE = 3;
|
||||
|
||||
|
||||
public EntityRule(GeneralPOJO po) {
|
||||
if (TABLENAME.equals(po.get_TableName())) {
|
||||
this.po = po;
|
||||
} else {
|
||||
throw new ValidationException("传入实体参数不匹配");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GeneralPOJO getPo() {
|
||||
return po;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return (String)po.get_Value(name);
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
po.set_ValueOfColumn(EntityRule.name, name);
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return (String)po.get_Value(content);
|
||||
}
|
||||
|
||||
|
||||
public void setContent(String content) {
|
||||
po.set_ValueOfColumn(EntityRule.content, content);
|
||||
}
|
||||
|
||||
|
||||
public String getEntityId() {
|
||||
return (String)po.get_Value(entityId);
|
||||
}
|
||||
|
||||
|
||||
public void setEntityId(String entityId) {
|
||||
po.set_ValueOfColumn(EntityRule.entityId, entityId);
|
||||
}
|
||||
|
||||
|
||||
public Integer getVerificationTime() {
|
||||
return po.get_ValueAsInt(verificationTime);
|
||||
}
|
||||
|
||||
|
||||
public void setVerificationTime(Integer verificationTime) {
|
||||
po.set_ValueOfColumn(EntityRule.verificationTime, verificationTime);
|
||||
}
|
||||
|
||||
public Map<String, Object> convertToMap(){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(TABLENAME + "_ID", getPo().get_ID());
|
||||
map.put(name, getPo().get_Value(name));
|
||||
map.put(content, getPo().get_Value(content));
|
||||
map.put(entityId, getPo().get_Value(entityId));
|
||||
map.put(verificationTime, getPo().get_Value(verificationTime));
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,199 @@
|
||||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. 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 General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package com.dsasp.server.dataDic.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.DisplayType;
|
||||
|
||||
/**
|
||||
* PO Info Column Info Value Object
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: POInfoColumn.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class POInfoColumn implements Serializable
|
||||
{
|
||||
/** Used by Remote FinReport */
|
||||
static final long serialVersionUID = -3983585608504631958L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param ad_Column_ID Column ID
|
||||
* @param columnName Column name
|
||||
* @param columnSQL virtual column
|
||||
* @param displayType Display Type
|
||||
* @param isMandatory Mandatory
|
||||
* @param isUpdateable Updateable
|
||||
* @param defaultLogic Default Logic
|
||||
* @param columnLabel Column Label
|
||||
* @param columnDescription Column Description
|
||||
* @param isKey true if key
|
||||
* @param isParent true if parent
|
||||
* @param ad_Reference_Value_ID reference value
|
||||
* @param validationCode sql validation code
|
||||
* @param fieldLength Field Length
|
||||
* @param valueMin minimal value
|
||||
* @param valueMax maximal value
|
||||
* @param isTranslated translated
|
||||
* @param isEncrypted encrypted
|
||||
* @param isAllowLogging allow logging
|
||||
*/
|
||||
public POInfoColumn (String ad_Column_ID, String columnName, String columnSQL, String displayType,
|
||||
boolean isMandatory, boolean isUpdateable, String defaultLogic,
|
||||
String columnLabel, String columnDescription,
|
||||
boolean isKey, String validationCode,
|
||||
int fieldLength, String valueMin, String valueMax,
|
||||
boolean isAllowLogging, String ad_Reference_Value_ID, String enumerateType, boolean isIdentifier, boolean iscombidentifier)
|
||||
{
|
||||
AD_Column_ID = ad_Column_ID;
|
||||
ColumnName = columnName;
|
||||
ColumnSQL = columnSQL;
|
||||
this.displayType = displayType;
|
||||
|
||||
if (columnName.equals("Posted")
|
||||
|| columnName.equals("Processed")
|
||||
|| columnName.equals("Processing"))
|
||||
{
|
||||
ColumnClass = Boolean.class;
|
||||
}
|
||||
else if (columnName.endsWith("_ID") && isKey)
|
||||
{
|
||||
this.displayType = DisplayType.ID;
|
||||
ColumnClass = String.class;
|
||||
}
|
||||
//FIXME: 非基本类型处<E59E8B>? else
|
||||
ColumnClass = DisplayType.getClass(displayType, true);
|
||||
IsMandatory = isMandatory;
|
||||
IsUpdateable = isUpdateable;
|
||||
DefaultLogic = defaultLogic;
|
||||
ColumnLabel = columnLabel;
|
||||
ColumnDescription = columnDescription;
|
||||
IsKey = isKey;
|
||||
// IsParent = isParent;
|
||||
//
|
||||
AD_Reference_Value_ID = ad_Reference_Value_ID;
|
||||
ValidationCode = validationCode;
|
||||
//
|
||||
FieldLength = fieldLength;
|
||||
ValueMin = valueMin;
|
||||
try
|
||||
{
|
||||
if (valueMin != null && valueMin.length() > 0)
|
||||
ValueMin_BD = new BigDecimal(valueMin);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// CLogger.get().log(Level.SEVERE, "ValueMin=" + valueMin, ex);
|
||||
}
|
||||
ValueMax = valueMax;
|
||||
try
|
||||
{
|
||||
if (valueMax != null && valueMax.length() > 0)
|
||||
ValueMax_BD = new BigDecimal(valueMax);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// CLogger.get().log(Level.SEVERE, "ValueMax=" + valueMax, ex);
|
||||
}
|
||||
// IsTranslated = isTranslated;
|
||||
// IsEncrypted = isEncrypted;
|
||||
IsAllowLogging = isAllowLogging;
|
||||
this.enumerateType = enumerateType;
|
||||
this.IsIdentifier = isIdentifier;
|
||||
this.IsCombidentifier = iscombidentifier;
|
||||
|
||||
} // Column
|
||||
|
||||
/** Column ID */
|
||||
public String AD_Column_ID;
|
||||
/** Column Name */
|
||||
public String ColumnName;
|
||||
/** Virtual Column */
|
||||
public String ColumnSQL;
|
||||
/** Display Type */
|
||||
public String displayType;
|
||||
/** Data Type */
|
||||
public Class<?> ColumnClass;
|
||||
/** Mandatory */
|
||||
public boolean IsMandatory;
|
||||
/** Default Value */
|
||||
public String DefaultLogic;
|
||||
/** Updateable */
|
||||
public boolean IsUpdateable;
|
||||
/** Label */
|
||||
public String ColumnLabel;
|
||||
/** Description */
|
||||
public String ColumnDescription;
|
||||
/** PK */
|
||||
public boolean IsKey;
|
||||
/** FK to Parent */
|
||||
// public boolean IsParent;
|
||||
/** Translated */
|
||||
// public boolean IsTranslated;
|
||||
// /** Encrypted */
|
||||
// public boolean IsEncrypted;
|
||||
/** Allow Logging */
|
||||
public boolean IsAllowLogging;
|
||||
|
||||
/** Reference Value */
|
||||
public String AD_Reference_Value_ID;
|
||||
/** Validation */
|
||||
public String ValidationCode;
|
||||
|
||||
/** Field Length */
|
||||
public int FieldLength;
|
||||
/** Min Value */
|
||||
public String ValueMin;
|
||||
/** Max Value */
|
||||
public String ValueMax;
|
||||
/** Min Value */
|
||||
public BigDecimal ValueMin_BD = null;
|
||||
/** Max Value */
|
||||
public BigDecimal ValueMax_BD = null;
|
||||
|
||||
/**
|
||||
* display type is list , AD_Reference_Value_ID reference table and foreign name
|
||||
*/
|
||||
public ReferenceValue referenceValue;
|
||||
|
||||
/**
|
||||
* display type is object , reference table
|
||||
*/
|
||||
public String referenceTable;
|
||||
|
||||
public String enumerateType;
|
||||
|
||||
public boolean IsIdentifier;
|
||||
public boolean IsCombidentifier;
|
||||
|
||||
/**
|
||||
* String representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("POInfo.Column[");
|
||||
sb.append(ColumnName).append(",ID=").append(AD_Column_ID)
|
||||
.append(",DisplayType=").append(displayType)
|
||||
.append(",ColumnClass=").append(ColumnClass);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
} // POInfoColumn
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.dsasp.server.dataDic.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ReferenceValue implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2483585608504631960L;
|
||||
|
||||
|
||||
private String columnName;
|
||||
|
||||
private String entityTable;
|
||||
|
||||
|
||||
|
||||
public ReferenceValue(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getEntityTable() {
|
||||
return entityTable;
|
||||
}
|
||||
|
||||
public void setEntityTable(String entityTable) {
|
||||
this.entityTable = entityTable;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.dsasp.server.dataDic.bean;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
|
||||
public class Rule {
|
||||
|
||||
public static final String TABLENAME = "SYS_RULE";
|
||||
private GeneralPOJO po;
|
||||
private static final String name = "NAME";
|
||||
private static final String content = "CONTENT";
|
||||
private static final String entityId = "ENTITYID";
|
||||
private static final String verificationTime = "VERIFICATIONTIME";
|
||||
|
||||
|
||||
public Rule(GeneralPOJO po) {
|
||||
if (TABLENAME.equals(po.get_TableName())) {
|
||||
this.po = po;
|
||||
} else {
|
||||
throw new ValidationException("传入实体参数不匹配");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GeneralPOJO getPo() {
|
||||
return po;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return (String)po.get_Value(name);
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
po.set_ValueOfColumn(Rule.name, name);
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return (String)po.get_Value(content);
|
||||
}
|
||||
|
||||
|
||||
public void setContent(String content) {
|
||||
po.set_ValueOfColumn(Rule.content, content);
|
||||
}
|
||||
|
||||
|
||||
public String getEntityId() {
|
||||
return (String)po.get_Value(entityId);
|
||||
}
|
||||
|
||||
|
||||
public void setEntityId(String entityId) {
|
||||
po.set_ValueOfColumn(Rule.entityId, entityId);
|
||||
}
|
||||
|
||||
|
||||
public Integer getVerificationTime() {
|
||||
return po.get_ValueAsInt(verificationTime);
|
||||
}
|
||||
|
||||
|
||||
public void setVerificationTime(Integer verificationTime) {
|
||||
po.set_ValueOfColumn(Rule.verificationTime, verificationTime);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.dsasp.server.dataDic.binding;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.script.Bindings;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
|
||||
public class GeneralPOJOBindings implements Bindings {
|
||||
|
||||
protected static final Set<String> UNSTORED_KEYS =
|
||||
new HashSet<String>(Arrays.asList("out", "out:print", "lang:import", "context", "elcontext", "print", "println", "po", "ctx"));
|
||||
|
||||
protected GeneralPOJO scriptResolvers;
|
||||
protected Properties ctx;
|
||||
|
||||
public GeneralPOJOBindings(GeneralPOJO po, Properties ctx) {
|
||||
this.scriptResolvers = po;
|
||||
if (ctx != null) {
|
||||
this.ctx = ctx;
|
||||
} else {
|
||||
this.ctx = new Properties();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
if ("po".equals(key) || "ctx".equals(key)
|
||||
|| scriptResolvers.get_ColumnIndex((String)key) != -1 || ctx.contains(key) || "mainPO".equals(key)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object get(Object key) {
|
||||
if("mainPO".equals(key)){
|
||||
return scriptResolvers.getMainPO();
|
||||
}
|
||||
else if ("po".equals(key)) {
|
||||
return scriptResolvers;
|
||||
} else if ("ctx".equals(key)) {
|
||||
return ctx;
|
||||
} else if (scriptResolvers.get_ColumnIndex((String)key) != -1) {
|
||||
return scriptResolvers.get_Value((String)key);
|
||||
} else if (ctx.contains(key)) {
|
||||
return ctx.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object put(String name, Object value) {
|
||||
Object oldValue = null;
|
||||
if (!UNSTORED_KEYS.contains(name)) {
|
||||
oldValue = scriptResolvers.get_Value(name);
|
||||
scriptResolvers.set_ValueOfColumn(name, value);
|
||||
}
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public Set<java.util.Map.Entry<String, Object>> entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().entrySet();
|
||||
}
|
||||
|
||||
public Set<String> keySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().keySet();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().size();
|
||||
}
|
||||
|
||||
public Collection<Object> values() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().values();
|
||||
}
|
||||
|
||||
public void putAll(Map< ? extends String, ? extends Object> toMerge) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object remove(Object key) {
|
||||
if (UNSTORED_KEYS.contains(key)) {
|
||||
return null;
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.dsasp.server.dataDic.binding;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory;
|
||||
|
||||
import com.dsasp.server.common.exception.PrivilegeException;
|
||||
import com.dsasp.server.common.exception.SameCodeException;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
|
||||
public class ScriptingEnginesManager {
|
||||
|
||||
public static final String GROOVY_SCRIPTING_LANGUAGE = "groovy";
|
||||
|
||||
private static ScriptingEnginesManager scriptingEnginesManager;
|
||||
|
||||
private Map<String, CompiledScript> compilerScripts = new HashMap<String, CompiledScript>();
|
||||
|
||||
private final ScriptEngineManager scriptEngineManager;
|
||||
|
||||
public ScriptingEnginesManager() {
|
||||
scriptEngineManager = new ScriptEngineManager();
|
||||
scriptEngineManager.registerEngineName(GROOVY_SCRIPTING_LANGUAGE,
|
||||
new GroovyScriptEngineFactory());
|
||||
}
|
||||
|
||||
public ScriptingEnginesManager addScriptEngineFactory(
|
||||
ScriptEngineFactory scriptEngineFactory) {
|
||||
scriptEngineManager.registerEngineName(
|
||||
scriptEngineFactory.getEngineName(), scriptEngineFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setScriptEngineFactories(
|
||||
List<ScriptEngineFactory> scriptEngineFactories) {
|
||||
if (scriptEngineFactories != null) {
|
||||
for (ScriptEngineFactory scriptEngineFactory : scriptEngineFactories) {
|
||||
scriptEngineManager.registerEngineName(
|
||||
scriptEngineFactory.getEngineName(),
|
||||
scriptEngineFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object evaluateGroovy(String key, String script, Bindings bindings) {
|
||||
ScriptEngine scriptEngine = scriptEngineManager
|
||||
.getEngineByName(GROOVY_SCRIPTING_LANGUAGE);
|
||||
|
||||
if (scriptEngine == null) {
|
||||
throw new RuntimeException(
|
||||
"Can't find scripting engine for '" + GROOVY_SCRIPTING_LANGUAGE + "'");
|
||||
}
|
||||
CompiledScript comScript = compilerScripts.get(key);
|
||||
|
||||
try {
|
||||
|
||||
if (comScript == null || StringUtil.isEmpty(key)) {
|
||||
comScript = ((Compilable) scriptEngine).compile(script);
|
||||
if (comScript == null) {
|
||||
return null;
|
||||
}
|
||||
compilerScripts.put(key, comScript);
|
||||
}
|
||||
return comScript.eval(bindings);
|
||||
} catch (ScriptException e) {
|
||||
//To Console Debug
|
||||
try {
|
||||
CompiledScript comScript2 = ((Compilable) scriptEngine).compile("import com.dsasp.client.viewframework.template.util.Console; Console.error(errorMsg)");
|
||||
bindings.put("errorMsg", e);
|
||||
comScript2.eval(bindings);
|
||||
} catch (ScriptException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
Throwable throwCase = e.getCause();
|
||||
while(throwCase != null ){
|
||||
if(throwCase instanceof ValidationException){
|
||||
throw (ValidationException)throwCase;
|
||||
}else if(throwCase instanceof PrivilegeException){
|
||||
throw (PrivilegeException)throwCase;
|
||||
}else if(throwCase instanceof SameCodeException){
|
||||
throw (SameCodeException)throwCase;
|
||||
}else{
|
||||
throwCase = throwCase.getCause();
|
||||
}
|
||||
}
|
||||
//FIXME: 脚本异常提醒
|
||||
throw new RuntimeException(key + " --- problem evaluating script: "
|
||||
+ e.getMessage().substring(15));
|
||||
}
|
||||
}
|
||||
|
||||
public static ScriptingEnginesManager getScriptingEnginesManager() {
|
||||
if (scriptingEnginesManager == null) {
|
||||
scriptingEnginesManager = new ScriptingEnginesManager();
|
||||
}
|
||||
return scriptingEnginesManager;
|
||||
}
|
||||
|
||||
public void setChangeScript(String key){
|
||||
compilerScripts.remove(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
package com.dsasp.server.dataDic.service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.AbstractPOJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.CodeRuleService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
public class CodeRuleServiceImpl implements CodeRuleService{
|
||||
|
||||
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setPojoCRUDService(POJOCRUDService pojoCRUDService) {
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
}
|
||||
|
||||
protected final String REGEX_Y = "\\%Y\\{([2,4])\\}";
|
||||
|
||||
protected final String REGEX_M= "\\%M\\{([1,2])\\}";
|
||||
|
||||
protected final String REGEX_D= "\\%D\\{([1,2])\\}";
|
||||
|
||||
protected final String REGEX_T= "\\%T\\{([0-9a-zA-Z:\\s_,.'=-]+)\\}";
|
||||
|
||||
protected final String REGEX_N= "\\%N\\{([0-9,]+)\\}";
|
||||
|
||||
//可能用于递增的项(除了流水号,其它都可能作为递增项)
|
||||
private final String[] ADDREGEXS = {REGEX_Y,REGEX_M,REGEX_D,REGEX_T};
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private POJOCRUDService pojoCRUDService;
|
||||
|
||||
@Override
|
||||
public String getCode(String tableName, String columnName,
|
||||
Map<String, Object> map) throws Exception{
|
||||
String columnId = AbstractPOJOInfo.getPOInfo(tableName).getAD_Column_ID(columnName);
|
||||
Map<String,Object> param = new HashMap<String, Object>();
|
||||
param.put("COLUMNID", columnId);
|
||||
Map<String,Object> result = pojoCRUDService.listSelect(param, "SYS_CODERULE", UserSession.getAdmin());
|
||||
List<GeneralPOJO> pojos = (List<GeneralPOJO>)result.get(POJOCRUDService.LIST_RESULT);
|
||||
if(pojos != null && pojos.size() == 1 ){
|
||||
GeneralPOJO pojo = pojos.get(0);
|
||||
String codeRule = (String)pojo.get_Value("RULE");
|
||||
String addRule = (String)pojo.get_Value("ADDRULE");
|
||||
Boolean isopen = (Boolean)pojo.get_Value("ISOPEN");
|
||||
String resultCode = codeRule;
|
||||
if(!isopen){
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<String> types = getMatcher(REGEX_T, codeRule);
|
||||
Set<String> numbers = getMatcher(REGEX_N, codeRule);
|
||||
|
||||
if(numbers.size() > 1){//暂不处理多个流水号
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
//查询编码(公司编码、工程编码etc.)
|
||||
Map<String, Object> realMap = getRealMap(tableName, codeRule, map);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Map<String,Object> dataY = new HashMap<String, Object>();
|
||||
dataY.put("2", new SimpleDateFormat("yy").format(cal.getTime()));
|
||||
dataY.put("4", new SimpleDateFormat("yyyy").format(cal.getTime()));
|
||||
|
||||
Map<String,Object> dataM = new HashMap<String, Object>();
|
||||
dataM.put("1", new SimpleDateFormat("M").format(cal.getTime()));
|
||||
dataM.put("2", new SimpleDateFormat("MM").format(cal.getTime()));
|
||||
|
||||
Map<String,Object> dataD = new HashMap<String, Object>();
|
||||
dataD.put("1", new SimpleDateFormat("d").format(cal.getTime()));
|
||||
dataD.put("2", new SimpleDateFormat("dd").format(cal.getTime()));
|
||||
|
||||
resultCode = composeRule(REGEX_Y, resultCode, dataY);
|
||||
resultCode = composeRule(REGEX_M, resultCode, dataM);
|
||||
resultCode = composeRule(REGEX_D, resultCode, dataD);
|
||||
resultCode = composeRule(REGEX_T, resultCode, realMap);
|
||||
|
||||
if(numbers.size() == 0){
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
String number = numbers.iterator().next();
|
||||
String[] ns = number.split(",");
|
||||
Long maxLength = Long.parseLong(ns[0]);
|
||||
Long start = 0L;
|
||||
if(ns.length > 1){
|
||||
start = Long.parseLong(ns[1]);
|
||||
}
|
||||
|
||||
//递增基础(计算流水号)
|
||||
//1、查询流水号根据哪些项递增。
|
||||
Set<String> replaceRegexs = getRegexByAddRule(addRule);
|
||||
//2、组合正则表达式(递增基础替换,不作为递增结果的替换为正则通配符,流水号长度使用通配符)
|
||||
String wheresql = codeRule;
|
||||
|
||||
wheresql = composeRule_IsReplace(REGEX_Y, wheresql, dataY,replaceRegexs);
|
||||
wheresql = composeRule_IsReplace(REGEX_M, wheresql, dataM,replaceRegexs);
|
||||
wheresql = composeRule_IsReplace(REGEX_D, wheresql, dataD,replaceRegexs);
|
||||
wheresql = composeRule_IsReplace(REGEX_T, wheresql, realMap,replaceRegexs);
|
||||
|
||||
Map<String,Object> dataN = new HashMap<String, Object>();
|
||||
dataN.put(number, "(\\\\d{"+maxLength+"})");
|
||||
wheresql = composeRule(REGEX_N, wheresql, dataN);
|
||||
Pattern p = Pattern.compile("\\(.*?\\)");
|
||||
Matcher m = p.matcher(wheresql);
|
||||
int position = 0;
|
||||
while(m.find()){
|
||||
if(("\\\\d{"+maxLength+"}").equals(m.group())){
|
||||
break;
|
||||
}
|
||||
position ++;
|
||||
}
|
||||
wheresql = "^"+wheresql+"$";
|
||||
//3、用正则表达式作为查询条件,查询业务数据表。
|
||||
|
||||
//SELECT (regexp_matches(CODE , 'JT(19|20|21)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])(\d{5})'))[4] FROM TEST_INVI WHERE CODE ~'JT(19|20|21)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])(\d{5})'
|
||||
//ORDER BY (regexp_matches(CODE , 'JT(19|20|21)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])(\d{5})'))[4] DESC LIMIT 1
|
||||
String select = "SELECT (regexp_matches("+ columnName +",'"+wheresql+"'))["+position+"] AS "+columnName
|
||||
+ " FROM "+tableName +" WHERE "+columnName+" ~'"+wheresql
|
||||
+"' ORDER BY "+"(regexp_matches("+columnName+",'"+wheresql+"'))["+position+"]"
|
||||
+" DESC LIMIT 1";
|
||||
SqlRowSet set = jdbcTemplate.queryForRowSet(select);
|
||||
String maxCode = null;
|
||||
if(set != null && set.next()){
|
||||
maxCode = set.getString(columnName);
|
||||
}
|
||||
|
||||
//4、取出最大的数据。
|
||||
Long maxNumber = null;
|
||||
if(maxCode != null){
|
||||
maxNumber = Long.parseLong(maxCode);
|
||||
}
|
||||
//5、将最大数据中的流水号取出来+1。
|
||||
if(maxNumber != null){
|
||||
maxNumber = maxNumber+1;
|
||||
}else{
|
||||
maxNumber = start;
|
||||
}
|
||||
if(maxNumber == null){
|
||||
throw new Exception("未找到最大流水号!");
|
||||
}
|
||||
//6、验证最大流水号长度。
|
||||
int maxNumberLength = String.valueOf(maxNumber).length();
|
||||
if(maxNumberLength > maxLength){
|
||||
throw new Exception("流水号达到最大上限!");
|
||||
}
|
||||
//7、组合新的流水号。
|
||||
|
||||
dataN = new HashMap<String, Object>();
|
||||
dataN.put(number, addZero(maxNumber,maxLength-maxNumberLength));
|
||||
resultCode = composeRule(REGEX_N, resultCode, dataN);
|
||||
return resultCode;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String addZero(Long number,Long x){
|
||||
if(number != null){
|
||||
String ns = String.valueOf(number);
|
||||
String zeros = "";
|
||||
for(int i=0; i < x; i++){
|
||||
zeros +="0";
|
||||
}
|
||||
return zeros+ns;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String,Object> getRealMap(String tableName,String codeRule,Map<String,Object> map) throws Exception{
|
||||
Map<String,Object> rtnMap = new HashMap<String, Object>();
|
||||
Set<String> set = getMatcher(REGEX_T, codeRule);
|
||||
for(String sT : set){
|
||||
String[] arry = sT.split(",");
|
||||
if(arry.length == 2){//通过外键查询
|
||||
String columName = arry[0]!=null?arry[0].trim():null;//当前表中的字段,通过该字段查询外键表
|
||||
String refTableColumnName = arry[1]!=null?arry[1].trim():null;//外键表中待查字段
|
||||
String refTable = AbstractPOJOInfo.getPOInfo(tableName).getReferenceTable(columName);
|
||||
String entityId = (String)map.get(columName);
|
||||
if(refTable == null){
|
||||
throw new Exception(columName+"外键关联表未找到!");
|
||||
}
|
||||
if(entityId == null){
|
||||
throw new Exception(columName+"传入数据为空!");
|
||||
}
|
||||
GeneralPOJO pojo = pojoCRUDService.loadPOJO(entityId, refTable, UserSession.getAdmin(), false);
|
||||
rtnMap.put(sT, pojo.get_Value(refTableColumnName));
|
||||
}else if (arry.length == 3){//通过SQL语句查询
|
||||
String columName = arry[0]!=null?arry[0].trim():null;//当前表中的字段
|
||||
String rtnColumName = arry[1]!=null?arry[1].trim():null;//返回的字段
|
||||
String selectSQL = arry[2]!=null?arry[2].trim():null;//SQL语句
|
||||
Object entityId = map.get(columName);
|
||||
if(entityId == null){
|
||||
throw new Exception(columName+"传入数据为空!");
|
||||
}
|
||||
selectSQL = selectSQL.replaceAll(":"+columName, " '"+entityId+"' ");
|
||||
String code = jdbcTemplate.queryForObject(selectSQL,String.class);
|
||||
// String code = null;//编码
|
||||
// if(rowSet != null && rowSet.next()){
|
||||
// if(StringUtil.isEmpty(rtnColumName)
|
||||
// ||StringUtil.isEmpty(rtnColumName.trim())){
|
||||
// code = rowSet.getString(0);
|
||||
// }else{
|
||||
// code = rowSet.getString(rtnColumName.trim());
|
||||
// }
|
||||
// }
|
||||
rtnMap.put(sT, code);
|
||||
}
|
||||
}
|
||||
return rtnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流水号根据哪些条件递增
|
||||
* @param addRule
|
||||
* @return
|
||||
*/
|
||||
private Set<String> getRegexByAddRule(String addRule){
|
||||
Set<String> set = new HashSet<String>();
|
||||
if(addRule != null){
|
||||
for(String regex : ADDREGEXS){
|
||||
Set<String> _regex = getMatcherALL(regex, addRule);
|
||||
if(_regex.size() > 0){
|
||||
set.addAll(_regex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
// private Long searchMaxNumber(String codeRuleId,String baseRule){
|
||||
// Map<String,Object> param = new HashMap<String, Object>();
|
||||
// param.put("CODERULEID", codeRuleId);
|
||||
// param.put("BASERULE", baseRule);
|
||||
// Map<String,Object> result = pojoCRUDService.listSelect(param, "SYS_CODEMAX", UserSession.getAdmin());
|
||||
// List<GeneralPOJO> pojos = (List<GeneralPOJO>)result.get(POJOCRUDService.LIST_RESULT);
|
||||
// if(pojos != null && pojos.size() > 0 ){
|
||||
// //FIXME :to Long
|
||||
// Integer maxNumber = (Integer)pojos.get(0).get_Value("maxnumber");
|
||||
// return Long.valueOf(maxNumber);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
// private String composeRuleNoNumber(String resultCode,Map<String,Object> map){
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// Map<String,Object> dataY = new HashMap<String, Object>();
|
||||
// dataY.put("2", new SimpleDateFormat("yy").format(cal.getTime()));
|
||||
// dataY.put("4", new SimpleDateFormat("yyyy").format(cal.getTime()));
|
||||
//
|
||||
// Map<String,Object> dataM = new HashMap<String, Object>();
|
||||
// dataM.put("1", new SimpleDateFormat("M").format(cal.getTime()));
|
||||
// dataM.put("2", new SimpleDateFormat("MM").format(cal.getTime()));
|
||||
//
|
||||
// Map<String,Object> dataD = new HashMap<String, Object>();
|
||||
// dataD.put("1", new SimpleDateFormat("d").format(cal.getTime()));
|
||||
// dataD.put("2", new SimpleDateFormat("dd").format(cal.getTime()));
|
||||
//
|
||||
// try {
|
||||
// resultCode = composeRule(REGEX_T, resultCode, map);
|
||||
// resultCode = composeRule(REGEX_Y, resultCode, dataY);
|
||||
// resultCode = composeRule(REGEX_M, resultCode, dataM);
|
||||
// resultCode = composeRule(REGEX_D, resultCode, dataD);
|
||||
// return resultCode;
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private Set<String> getMatcher(String regex, String source) {
|
||||
Set<String> result = new LinkedHashSet<String>();
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(source);
|
||||
while (matcher.find()) {
|
||||
result.add(matcher.group(1));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Set<String> getMatcherALL(String regex, String source) {
|
||||
Set<String> result = new LinkedHashSet<String>();
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(source);
|
||||
while (matcher.find()) {
|
||||
result.add(matcher.group(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按正则替换编码规则表达式
|
||||
* @param regex 正则表达式
|
||||
* @param template 编码规则表达式
|
||||
* @param data 各种编号的值
|
||||
* @return
|
||||
* @throws Exception data未传入相应的值即提示错误
|
||||
*/
|
||||
private String composeRule(String regex,String template, Map<String,Object> data)
|
||||
throws Exception {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(template);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String name = matcher.group(1);
|
||||
if (data.get(name) == null) {
|
||||
throw new Exception(name+"为空!");
|
||||
}
|
||||
String value = data.get(name).toString();
|
||||
|
||||
matcher.appendReplacement(sb, value);
|
||||
|
||||
}
|
||||
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 产生查询最大编码的正则表达式条件
|
||||
* @param regex 替换的正则表达式
|
||||
* @param template codeRule编码规则表达式
|
||||
* @param data 各种编号的值
|
||||
* @param set 流水号的递增项
|
||||
* @return
|
||||
* @throws Exception data未传入相应的值即提示错误
|
||||
*/
|
||||
private String composeRule_IsReplace(String regex,String template, Map<String,Object> data,Set<String> set)
|
||||
throws Exception {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(template);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String nameAll = matcher.group(0);
|
||||
String name = matcher.group(1);
|
||||
String value = null;
|
||||
if(set.contains(nameAll)){
|
||||
if(data.get(name) != null)
|
||||
value = (String) data.get(name);
|
||||
}else{
|
||||
if("%Y{2}".equals(nameAll)){
|
||||
value = "(\\\\d{2})";
|
||||
}else if("%Y{4}".equals(nameAll)){
|
||||
value = "(19|20|21)\\\\d{2}";
|
||||
}else if("%M{1}".equals(nameAll)){
|
||||
value = "([1-9]|1[012])";
|
||||
}else if("%M{2}".equals(nameAll)){
|
||||
value = "(0[1-9]|1[012])";
|
||||
}else if("%D{1}".equals(nameAll)){
|
||||
value = "([1-9]|[12]\\\\d|3[01])";
|
||||
}else if("%D{2}".equals(nameAll)){
|
||||
value = "(0[1-9]|[12]\\\\d|3[01])";
|
||||
}else{
|
||||
value = "(.*)";
|
||||
}
|
||||
}
|
||||
if (value == null) {
|
||||
throw new Exception(name+"为空!");
|
||||
}
|
||||
|
||||
matcher.appendReplacement(sb, value);
|
||||
|
||||
}
|
||||
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
CodeRuleServiceImpl test = new CodeRuleServiceImpl();
|
||||
String codeRule ="%T{ORGID}-%Y{4}-%M{2}-%D{2}-%N{5,25}";
|
||||
String addRule = "%T{ORGID}";
|
||||
Boolean isopen = true;
|
||||
|
||||
Set<String> types = test.getMatcher(test.REGEX_T, codeRule);
|
||||
Set<String> numbers = test.getMatcher(test.REGEX_N, codeRule);
|
||||
|
||||
String number = numbers.iterator().next();
|
||||
String[] ns = number.split(",");
|
||||
Long maxLength = Long.parseLong(ns[0]);
|
||||
Long start = 0L;
|
||||
if(ns.length > 1){
|
||||
start = Long.parseLong(ns[1]);
|
||||
}
|
||||
|
||||
//递增基础(计算流水号)
|
||||
//1、查询流水号根据哪些项递增。
|
||||
Set<String> replaceRegexs = test.getRegexByAddRule(addRule);
|
||||
//2、组合正则表达式(递增基础替换,不作为递增结果的替换为正则通配符,流水号长度使用通配符)
|
||||
String wheresql = codeRule;
|
||||
try {
|
||||
// for(String regex : ADDREGEXS){
|
||||
// wheresql = composeRule_IsReplace(regex, wheresql, map,replaceRegexs);
|
||||
// }
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Map<String,Object> dataY = new HashMap<String, Object>();
|
||||
dataY.put("2", new SimpleDateFormat("yy").format(cal.getTime()));
|
||||
dataY.put("4", new SimpleDateFormat("yyyy").format(cal.getTime()));
|
||||
|
||||
Map<String,Object> dataM = new HashMap<String, Object>();
|
||||
dataM.put("1", new SimpleDateFormat("M").format(cal.getTime()));
|
||||
dataM.put("2", new SimpleDateFormat("MM").format(cal.getTime()));
|
||||
|
||||
Map<String,Object> dataD = new HashMap<String, Object>();
|
||||
dataD.put("1", new SimpleDateFormat("d").format(cal.getTime()));
|
||||
dataD.put("2", new SimpleDateFormat("dd").format(cal.getTime()));
|
||||
|
||||
Map<String,Object> map = new HashMap<String, Object>();
|
||||
map.put("ORGID", "YI");
|
||||
|
||||
wheresql = test.composeRule_IsReplace(test.REGEX_Y, wheresql, dataY,replaceRegexs);
|
||||
wheresql = test.composeRule_IsReplace(test.REGEX_M, wheresql, dataM,replaceRegexs);
|
||||
wheresql = test.composeRule_IsReplace(test.REGEX_D, wheresql, dataD,replaceRegexs);
|
||||
wheresql = test.composeRule_IsReplace(test.REGEX_T, wheresql, map,replaceRegexs);
|
||||
|
||||
Map<String,Object> dataN = new HashMap<String, Object>();
|
||||
dataN.put(number, "(\\\\d{"+maxLength+"})");
|
||||
wheresql = test.composeRule(test.REGEX_N, wheresql, dataN);
|
||||
System.out.println(wheresql);
|
||||
Pattern p = Pattern.compile("\\(.*?\\)");
|
||||
Matcher m = p.matcher(wheresql);
|
||||
int position = 0;
|
||||
while(m.find()){
|
||||
position ++;
|
||||
if(("\\\\d{"+maxLength+"}").equals(m.group())){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Pattern pp = Pattern.compile(wheresql);
|
||||
Matcher mm = pp.matcher("YI-1988-02-02-00001");
|
||||
if(mm.find()){
|
||||
System.out.println(mm.group(position));
|
||||
}
|
||||
// Set<String> ss = test.getMatcher(wheresql, "YI-1988-02-02-00001");
|
||||
// for(String s : ss){
|
||||
// //System.out.println(s);
|
||||
// }
|
||||
//
|
||||
// Pattern p = Pattern.compile("\\(.*?\\)");
|
||||
// Matcher m = p.matcher(wheresql);
|
||||
// while(m.find()){
|
||||
// System.out.println(m.group());
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
package com.dsasp.server.dataDic.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.dsasp.server.common.core.service.OriginServiceMethod;
|
||||
import com.dsasp.server.common.dataDic.bean.AbstractPOJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.EnumerateItem;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.POJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.Rule;
|
||||
import com.dsasp.server.common.dataDic.bean.SYS_Entity;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOService;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.dataDic.bean.DataDicHelper;
|
||||
import com.dsasp.server.dataDic.bean.Entity;
|
||||
import com.dsasp.server.dataDic.bean.EntityRule;
|
||||
import com.dsasp.server.dataDic.bean.GeneralPO;
|
||||
import com.dsasp.server.dataDic.bean.POInfo;
|
||||
@Service(value="dataDicService")
|
||||
@Transactional
|
||||
public class DataDicServiceImpl implements DataDicService {
|
||||
|
||||
@Autowired
|
||||
private POJOService pojoService;
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
public POJOService getPojoService() {
|
||||
return pojoService;
|
||||
}
|
||||
|
||||
public void setPojoService(POJOService pojoService) {
|
||||
this.pojoService = pojoService;
|
||||
}
|
||||
|
||||
public JdbcTemplate getJdbcTemplate() {
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Map<String, Object> entity, Properties ctx) {
|
||||
// //FIXME: 权限
|
||||
// HashMap map = new HashMap();
|
||||
// map.put(tableName + "_ID", entityId);
|
||||
// GeneralPO po = new GeneralPO(tableName, map, ctx);
|
||||
// return pojoService.delete(po, ctx != null ? ctx.getProperty("userId") : "admin", false);
|
||||
|
||||
entity.put("ISACTIVE", false);
|
||||
update(entity, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long findCount(String countSql) {
|
||||
|
||||
return pojoService.findCount(countSql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeneralPOJO> getEntityAttributes(String entityID) {
|
||||
String sql = "SELECT * FROM SYS_EntityAttribute WHERE entityId = '" + entityID + "'";
|
||||
return pojoService.listSelect(sql, "SYS_EntityAttribute", 0, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeneralPOJO> getMeta(int firstResult, int pageSize) {
|
||||
String sql = "SELECT * FROM SYS_Meta";
|
||||
return pojoService.listSelect(sql, "SYS_Meta", firstResult, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeneralPOJO> listSelect(int firstResult, int pageSize, Map<String, Object> map) {
|
||||
String sql = "SELECT * FROM SYS_Entity ";
|
||||
return pojoService.listSelect(sql, "SYS_Entity", firstResult, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object save(Map<String, Object> entity, Properties ctx) {
|
||||
GeneralPO po = new GeneralPO("SYS_ENTITY", entity, ctx);
|
||||
pojoService.save(po, ctx != null ? ctx.getProperty(LoggedInUser.CURRENTUSER) : null);
|
||||
return po;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object update(Map<String, Object> entity, Properties ctx) {
|
||||
// FIXME: 权限
|
||||
String entityId = (String) entity.get("SYS_Entity" + "_ID");
|
||||
GeneralPOJO po = pojoService.loadPOJO(entityId, "SYS_Entity", ctx, true);
|
||||
if (po != null) {
|
||||
int count = po.get_ColumnCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (entity.containsKey(po.get_ColumnName(i))) {
|
||||
String name = po.get_ColumnName(i);
|
||||
po.set_ValueOfColumn(name, entity.get(name));
|
||||
}
|
||||
}
|
||||
// FIXME: userid is not null, this is test
|
||||
return pojoService.update(po,
|
||||
ctx != null ? ctx.getProperty(LoggedInUser.CURRENTUSER) : LoggedInUser.ADMIN);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SYS_Entity getSYSEntity(String entityId) {
|
||||
GeneralPOJO po = pojoService.loadPOJO(entityId, "SYS_ENTITY", UserSession.getAdmin(), true);
|
||||
return new Entity(po);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SYS_Entity getSYSEntityByTableName(String tableName) {
|
||||
SqlRowSet set = jdbcTemplate.queryForRowSet("SELECT SYS_ENTITY_ID FROM SYS_ENTITY WHERE ISACTIVE=1 AND TABLENAME ='" + tableName + "'");
|
||||
if(set != null && set.next()){
|
||||
String entityId = set.getString("SYS_ENTITY_ID");
|
||||
GeneralPOJO po = pojoService.loadPOJO(entityId, "SYS_ENTITY", UserSession.getAdmin(), false);
|
||||
return new Entity(po);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public POJOInfo loadInfo(String tableName) {
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("select t.tableName,c.columnName,c.referenceID," // 1..3
|
||||
+ " c.isMandatory,c.isReadOnly,c.defaultValue,c.displayName,c.description,c.SYS_EntityAttribute_id,c.isKey,c.ruleId as ruleCode," // 4..6
|
||||
+ " c.fieldLength,c.valueMin,c.valueMax, t.accessLevel,c.columnSQL, " // 7..9
|
||||
+ " t.isChangeLog as isChangeLog, c.referencevalue as referencevalue, c.isentitydisplay, c.enumeratetype, c.isidentifier, c.iscombidentifier, t.tabletype ,t.sys_entity_id, t.name "); // 21
|
||||
sql.append(" from SYS_Entity as t inner join SYS_EntityAttribute as c on (t.SYS_Entity_id = c.entityId)");
|
||||
// + " left join SYS_Meta as e on(c.metaId = e.SYS_Meta_id)");
|
||||
sql.append(" where t.tableName = ? and t.isActive = 1 and c.isActive = 1 ORDER BY C.ENTITYDISPLAYSEQ ASC");
|
||||
SqlRowSet result = jdbcTemplate.queryForRowSet(sql.toString(),
|
||||
new Object[] { tableName });
|
||||
POJOInfo info = new POInfo(tableName, result);
|
||||
return info;
|
||||
|
||||
}
|
||||
|
||||
public String getReferenceEntityTableName(String referenceId){
|
||||
String select = "SELECT TABLENAME FROM SYS_REFERENCE AS RE INNER JOIN SYS_ENTITY AS ENT ON RE.ENTITYID = ENT.SYS_ENTITY_ID WHERE RE.SYS_REFERENCE_ID='" + referenceId + "'";
|
||||
SqlRowSet set = jdbcTemplate.queryForRowSet(select);
|
||||
if(set != null && set.next()){
|
||||
return set.getString("TABLENAME");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getEntityTableNameByReferenceValue(String referenceValueId){
|
||||
String select = "SELECT ENT.TABLENAME " +
|
||||
" FROM SYS_REFERENCEVALUE AS RE " +
|
||||
" INNER JOIN SYS_ENTITY AS ENT ON RE.ENTITYID = ENT.SYS_ENTITY_ID " +
|
||||
" WHERE RE.SYS_REFERENCEVALUE_ID='" + referenceValueId + "'";
|
||||
SqlRowSet set = jdbcTemplate.queryForRowSet(select);
|
||||
if(set != null && set.next()){
|
||||
return set.getString("TABLENAME");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getColumnNameByReferenceValue(String referenceValueId){
|
||||
String select = "SELECT ATTRI.COLUMNNAME " +
|
||||
" FROM SYS_REFERENCEVALUE AS RE " +
|
||||
" INNER JOIN SYS_ENTITYATTRIBUTE AS ATTRI ON RE.ENTITYID = ATTRI.ENTITYID AND RE.ENTITYATTRIBUTEID = ATTRI.SYS_ENTITYATTRIBUTE_ID" +
|
||||
" WHERE RE.SYS_REFERENCEVALUE_ID='" + referenceValueId + "'";
|
||||
SqlRowSet set = jdbcTemplate.queryForRowSet(select);
|
||||
if(set != null && set.next()){
|
||||
return set.getString("COLUMNNAME");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String executeCreateSql(String sql) {
|
||||
if (!StringUtil.isEmpty(sql)
|
||||
&& (sql.toUpperCase().trim().startsWith("CREATE ") || sql.trim().startsWith("INSERT INTO order_entity"))
|
||||
&& sql.trim().split(";").length <= 2) {
|
||||
String[] sqls = sql.trim().split(";");
|
||||
if (sqls.length == 1
|
||||
|| sqls[1].trim().startsWith("INSERT INTO order_entity")) {
|
||||
jdbcTemplate.execute(sql);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return "非合法的创建表脚本";
|
||||
}
|
||||
|
||||
@OriginServiceMethod(name="新增实体的默认属性", type = "dataDic" , description = "新增实体,默认产生createby,updatby,createtime,updatetime,version,isactive,orgid,departid")
|
||||
@Override
|
||||
public GeneralPOJO getTableDefaultAttribute() {
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
GeneralPOJO po = new GeneralPO("SYS_ENTITY", map, UserSession.get());
|
||||
po.updateHierarchicalValue("ATTRIBUTES", DataDicHelper.getTableDefaultAttributes());
|
||||
return po;
|
||||
}
|
||||
|
||||
public List<GeneralPOJO> getEntitysWithForeignKey(String entityId){
|
||||
String selectReferenceId = "SELECT SYS_REFERENCE_ID FROM SYS_REFERENCE WHERE ENTITYID='" + entityId + "'";
|
||||
SqlRowSet set = jdbcTemplate.queryForRowSet(selectReferenceId);
|
||||
if(set != null && set.next()){
|
||||
String referenceId = set.getString("SYS_REFERENCE_ID");
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
GeneralPOJO po = new GeneralPO("SYS_REFERENCEVALUE", map, UserSession.getAdmin());
|
||||
StringBuffer select = po.getSelectBuild();
|
||||
select.append(" LEFT JOIN SYS_ENTITYATTRIBUTE AS A ON P.ENTITYID=A.ENTITYID AND P.ENTITYATTRIBUTEID=A.SYS_ENTITYATTRIBUTE_ID WHERE P.ISACTIVE=1 AND A.ISACTIVE=1 AND A.REFERENCEID='");
|
||||
select.append(referenceId);
|
||||
select.append("'");
|
||||
return pojoService.listSelect(select.toString(), po.get_TableName(), 0, Integer.MAX_VALUE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* save or update reference and reference value
|
||||
*/
|
||||
public void saveOrUpdateReference(GeneralPOJO po, Properties ctx){
|
||||
Entity entity = new Entity(po);
|
||||
String entityId = entity.getPo().get_ID();
|
||||
//save or update reference
|
||||
if(!entity.isView() && entity.getTabletype() == Entity.MAINTABLE){
|
||||
String existReference = "SELECT COUNT(*) FROM SYS_REFERENCE WHERE ISACTIVE = 1 AND ENTITYID='" + entityId + "'";
|
||||
int count = jdbcTemplate.queryForObject(existReference, Integer.class);
|
||||
if(count == 0){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("ENTITYID", entityId);
|
||||
map.put("NAME", entity.getPo().get_Value("NAME"));
|
||||
map.put("DESCRIPTION", entity.getPo().get_Value("DESCRIPTION"));
|
||||
GeneralPO referencePo = new GeneralPO("SYS_REFERENCE", map, ctx);
|
||||
pojoService.save(referencePo, null);
|
||||
}else{
|
||||
String update = "UPDATE SYS_REFERENCE SET NAME ='" + entity.getPo().get_Value("NAME") + "' WHERE ENTITYID = '" + entityId + "'";
|
||||
jdbcTemplate.update(update);
|
||||
}
|
||||
}
|
||||
|
||||
//save or update reference value
|
||||
List<GeneralPOJO> attributes = entity.getAttributes();
|
||||
String updateReferenceValue = "UPDATE SYS_REFERENCEVALUE SET ISACTIVE=0 WHERE ENTITYID='" + entityId + "'";
|
||||
jdbcTemplate.update(updateReferenceValue);
|
||||
for (GeneralPOJO attri : attributes) {
|
||||
boolean readOnly = attri.get_ValueAsBoolean(Entity.isReadonly);
|
||||
if (!readOnly) {
|
||||
String displayType = (String) attri
|
||||
.get_Value(Entity.referenceid);
|
||||
if(displayType.length() > 20){
|
||||
String sysEntityAttributeId = attri.get_ID();
|
||||
String existReference = "SELECT COUNT(*) FROM SYS_REFERENCEVALUE WHERE ENTITYID='" + entityId + "' AND ENTITYATTRIBUTEID='" + sysEntityAttributeId + "'";
|
||||
int count = jdbcTemplate.queryForObject(existReference, Integer.class);
|
||||
if(count == 0){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("ENTITYID", entityId);
|
||||
map.put("NAME", entity.getPo().get_Value("NAME"));
|
||||
map.put("ENTITYATTRIBUTEID", sysEntityAttributeId);
|
||||
// map.put("DESCRIPTION", entity.getPo().get_Value("DESCRIPTION"));
|
||||
GeneralPO referencePo = new GeneralPO("SYS_REFERENCEVALUE", map, ctx);
|
||||
pojoService.save(referencePo, null);
|
||||
}else{
|
||||
String updateReferenceValueAttri = "UPDATE SYS_REFERENCEVALUE SET ISACTIVE=1 WHERE ENTITYID='" + entityId + "' AND ENTITYATTRIBUTEID='" + sysEntityAttributeId + "'";
|
||||
jdbcTemplate.update(updateReferenceValueAttri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//validate the reference value
|
||||
String validateSql = "SELECT ATT.DISPLAYNAME FROM SYS_ENTITYATTRIBUTE AS ATT INNER JOIN SYS_REFERENCEVALUE AS REVALUE ON ATT.REFERENCEVALUE=REVALUE.SYS_REFERENCEVALUE_ID WHERE REVALUE.ISACTIVE=0 AND REVALUE.ENTITYID='" + entityId + "'";
|
||||
SqlRowSet validateCount = jdbcTemplate.queryForRowSet(validateSql);
|
||||
if(validateCount.next()){
|
||||
throw new ValidationException(validateCount.getString("DISPLAYNAME") + "属性被其他实体应用,不能删除");
|
||||
}
|
||||
AbstractPOJOInfo.setChangePOInfo(entityId);
|
||||
//String deleteSql = "DELETE FROM SYS_REFERENCEVALUE WHERE ISACTIVE=0 AND ENTITYID='" + entityId + "'";
|
||||
}
|
||||
|
||||
public List<Rule> getRule(String tableName){
|
||||
SqlRowSet set = jdbcTemplate.queryForRowSet("SELECT SYS_ENTITY_ID FROM SYS_ENTITY WHERE ISACTIVE=1 AND TABLENAME ='" + tableName + "'");
|
||||
List<Rule> listRule = new ArrayList<Rule>();
|
||||
if(set != null && set.next()){
|
||||
String entityId = set.getString("SYS_ENTITY_ID");
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
GeneralPO po = new GeneralPO("SYS_RULE", map, UserSession.getAdmin());
|
||||
StringBuffer select = po.getSelectBuild();
|
||||
map.put("ENTITYID", entityId);
|
||||
StringBuffer where = po.get_SearchWhereClause(map);
|
||||
select.append(where);
|
||||
List<GeneralPOJO> list = pojoService.listSelect(select.toString(), po.get_TableName(), 0, Integer.MAX_VALUE);
|
||||
|
||||
for(GeneralPOJO poRule : list){
|
||||
listRule.add(new EntityRule(poRule));
|
||||
}
|
||||
}
|
||||
return listRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnumerateItem> getEnumerateItems(String enumerateType) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("SYS_ENUMERATETYPE_ID", enumerateType);
|
||||
GeneralPOJO po = new GeneralPO("SYS_ENUMERATE", map, UserSession.getAdmin());
|
||||
List<String> cols = new ArrayList<String>();
|
||||
cols.add("CODEVALUE");
|
||||
cols.add("CODEDES");
|
||||
cols.add("EXTENDATTRIBUTEONE");
|
||||
cols.add("EXTENDATTRIBUTETWO");
|
||||
cols.add("EXTENDATTRIBUTETHREE");
|
||||
StringBuffer select = po.getSelectBuild(cols);
|
||||
StringBuffer where = po.get_SearchWhereClause(map);
|
||||
if(where != null && where.length() > 0){
|
||||
select.append(where).append(" ORDER BY ORDERASC ASC");
|
||||
}
|
||||
List<GeneralPOJO> list = pojoService.listSelectSpecialCols(select.toString(), po.get_TableName(), 0, Integer.MAX_VALUE, cols);
|
||||
int size = list.size();
|
||||
if(list != null && size > 0){
|
||||
List<EnumerateItem> items = new ArrayList<EnumerateItem>();
|
||||
for(int i = 0; i < size; i++){
|
||||
GeneralPOJO pojo = list.get(i);
|
||||
EnumerateItem item = new EnumerateItem();
|
||||
item.setCodeValue((Integer)pojo.get_Value("CODEVALUE"));
|
||||
item.setCodeDes((String)pojo.get_Value("CODEDES"));
|
||||
item.setExtendAttributeOne((String)pojo.get_Value("EXTENDATTRIBUTEONE"));
|
||||
item.setExtendAttributeTwo((String)pojo.get_Value("EXTENDATTRIBUTETWO"));
|
||||
item.setExtendAttributeThree((String)pojo.get_Value("EXTENDATTRIBUTETHREE"));
|
||||
item.setEnumerateType(enumerateType);
|
||||
items.add(item);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getConfigValue(String key) {
|
||||
SqlRowSet set = jdbcTemplate
|
||||
.queryForRowSet("SELECT VALUE FROM SYS_APPLICATION_CONFIG WHERE SYS_APPLICATION_CONFIG_ID = '"
|
||||
+ key + "'");
|
||||
if (set != null && set.next()) {
|
||||
return set.getString("VALUE");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,610 @@
|
||||
package com.dsasp.server.dataDic.service;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.dsasp.server.common.core.service.OriginServiceMethod;
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.DisplayType;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.POJOInfo;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOService;
|
||||
import com.dsasp.server.common.file.service.FileService;
|
||||
import com.dsasp.server.common.file.service.SYSDoc;
|
||||
import com.dsasp.server.common.log.service.SystemLogManager;
|
||||
import com.dsasp.server.common.log.service.SystemLogManager.LogType;
|
||||
import com.dsasp.server.common.privilege.service.DataPrivilegeService;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.dataDic.bean.Entity;
|
||||
import com.dsasp.server.dataDic.bean.GeneralPO;
|
||||
import com.dsasp.server.dataDic.bean.POInfo;
|
||||
|
||||
@Service(value="pojoCRUDService")
|
||||
@Transactional
|
||||
public class POJOCRUDServiceImpl implements POJOCRUDService{
|
||||
|
||||
@Autowired
|
||||
private POJOService pojoService;
|
||||
|
||||
@Autowired
|
||||
private DataPrivilegeService dataPrivilegeService;
|
||||
|
||||
|
||||
public POJOService getPojoService() {
|
||||
return pojoService;
|
||||
}
|
||||
|
||||
|
||||
public void setPojoService(POJOService pojoService) {
|
||||
this.pojoService = pojoService;
|
||||
}
|
||||
|
||||
|
||||
public DataPrivilegeService getDataPrivilegeService() {
|
||||
return dataPrivilegeService;
|
||||
}
|
||||
|
||||
|
||||
public void setDataPrivilegeService(DataPrivilegeService dataPrivilegeService) {
|
||||
this.dataPrivilegeService = dataPrivilegeService;
|
||||
}
|
||||
|
||||
private SystemLogManager systemLogManager;
|
||||
public SystemLogManager getSystemLogManager() {
|
||||
return systemLogManager;
|
||||
}
|
||||
|
||||
public void setSystemLogManager(SystemLogManager systemLogManager) {
|
||||
this.systemLogManager = systemLogManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return the result key count: number, key result: list
|
||||
*/
|
||||
@OriginServiceMethod(name = "通用数据查询",type = "dataDic", description = "数据查询,通用方法,Map 查询条件,tableName 查询实体,ctx 环境")
|
||||
public Map<String, Object> listSelect(Map map, final String tableName, Properties ctx) {
|
||||
Object returnList = map.get(RETURN_COLUMNS_LIST);
|
||||
return listSelectSpecialCol(map, tableName, ctx, returnList == null ? null : (List<String>)returnList);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the result key count: number, key result: list
|
||||
*/
|
||||
@OriginServiceMethod(name = "通用数据查询(指定返回列)",type = "dataDic", description = "可以指定返回字段的数据查询,通用方法,Map 查询条件,tableName 查询实体,ctx 环境, returnColMap 查询需要返回的列")
|
||||
public Map<String, Object> listSelectSpecialCol(Map map, final String tableName, Properties ctx, List<String> returnColMap) {
|
||||
//FIXME:数据权限
|
||||
POJOInfo info = POInfo.getPOInfo(tableName);
|
||||
if (returnColMap != null && returnColMap.size() > 0) {
|
||||
if (info != null && info.getTableType() != Entity.MIDTABLE) {
|
||||
if (!returnColMap.contains(tableName + "_ID")) {
|
||||
returnColMap.add(tableName + "_ID");
|
||||
}
|
||||
String displayName = info.getColumnName(info.getDisplayIndex());
|
||||
if(!returnColMap.contains(displayName)){
|
||||
returnColMap.add(displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
String order = (String)map.get(ORDER);
|
||||
order = replaceReferOrderCols(order, info);
|
||||
getOrderCols(order, returnColMap,info);
|
||||
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
GeneralPO po = new GeneralPO(tableName, new HashMap<String,Object>(), ctx);
|
||||
StringBuffer select = po.getSelectBuild(returnColMap);
|
||||
if(!map.containsKey(RETURN_COLUMNS_LIST)){
|
||||
map.put(RETURN_COLUMNS_LIST, returnColMap);
|
||||
}
|
||||
StringBuffer where = po.get_SearchWhereClause(map);
|
||||
String privilege = null;
|
||||
if(ctx != null && !ctx.get(LoggedInUser.CURRENTUSER).equals(LoggedInUser.ADMIN)){
|
||||
privilege = dataPrivilegeService.getWhereClause(ctx, tableName);
|
||||
}
|
||||
|
||||
StringBuffer countSelect = null;
|
||||
if(info != null && info.getTableType() != Entity.MIDTABLE){
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
list.add(tableName + "_ID");
|
||||
countSelect = po.getSelectBuild(list);
|
||||
}
|
||||
if(select != null && select.length() > 0){
|
||||
boolean hasWhere = false;
|
||||
if(where != null && where.length() > 0){
|
||||
select.append(where);
|
||||
if(countSelect != null && countSelect.length() > 0){
|
||||
countSelect.append(where);
|
||||
}
|
||||
hasWhere = true;
|
||||
}
|
||||
if(privilege != null && privilege.length() > 0){
|
||||
if(!hasWhere){
|
||||
select.append(" WHERE ");
|
||||
if(countSelect != null && countSelect.length() > 0){
|
||||
countSelect.append(" WHERE ");
|
||||
}
|
||||
hasWhere = true;
|
||||
}
|
||||
// else{
|
||||
// select.append(" AND ");
|
||||
// }
|
||||
select.append(privilege);
|
||||
|
||||
if(countSelect != null && countSelect.length() > 0){
|
||||
countSelect.append(privilege);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(select == null || select.length() == 0 ){
|
||||
return result;
|
||||
}
|
||||
String countSel = "SELECT COUNT(*) AS COU FROM (" + (countSelect != null && countSelect.length() > 0 ? countSelect : select) + ") AS TEMPTABLE ";
|
||||
|
||||
if (!StringUtil.isEmpty(order)) {
|
||||
select.append(" ");
|
||||
select.append(order);
|
||||
}
|
||||
//合计列
|
||||
if(map.containsKey(SUM_COLUMNS_LIST)){
|
||||
List<String> sumCols = (List<String>)map.get(SUM_COLUMNS_LIST);
|
||||
String sumsql = "SELECT ";
|
||||
if(sumCols != null && sumCols.size() > 0){
|
||||
for(String col : sumCols){
|
||||
int cIndex = info.getColumnIndexByName(col);
|
||||
if(cIndex> 0
|
||||
&& (DisplayType.Number.equals(info.getColumnDisplayType(cIndex))
|
||||
||DisplayType.Money.equals(info.getColumnDisplayType(cIndex)))
|
||||
){
|
||||
sumsql +="SUM(" +col+") as "+col+",";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(sumsql.lastIndexOf(",")>0){
|
||||
sumsql= sumsql.substring(0,sumsql.length()-1)+" FROM (" + select + ") AS TEMPTABLE ";
|
||||
Map<String, Object> sumMap = pojoService.findSumColumn(sumsql);
|
||||
if(sumMap != null && sumMap.size() > 0){
|
||||
Set<String> keys = sumMap.keySet();
|
||||
for(String key : keys){
|
||||
int cIndex = info.getColumnIndexByName(key);
|
||||
if(cIndex > 0 && sumMap.get(key) != null){
|
||||
String dt = info.getColumnDisplayType(cIndex);
|
||||
if(DisplayType.Number.equals(dt)){
|
||||
String formatStr = info.getColumnDescription(cIndex);
|
||||
DecimalFormat format = null;
|
||||
if(StringUtil.isEmpty(formatStr) || !(formatStr.contains("#") || formatStr.contains("0"))){
|
||||
format = new DecimalFormat("#.####");
|
||||
}else{
|
||||
format = new DecimalFormat(formatStr);
|
||||
}
|
||||
sumMap.put(key, format.format(sumMap.get(key)));
|
||||
}else if (DisplayType.Money.equals(dt)) {
|
||||
String formatStr = info.getColumnDescription(cIndex);
|
||||
DecimalFormat format = null;
|
||||
if(StringUtil.isEmpty(formatStr) || !(formatStr.contains("#") || formatStr.contains("0"))){
|
||||
format = new DecimalFormat("#,##0.00");
|
||||
}else{
|
||||
format = new DecimalFormat(formatStr);
|
||||
}
|
||||
sumMap.put(key, format.format(sumMap.get(key)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.put(RETURN_SUM_COLUMNS_MAP, sumMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//记录日志
|
||||
logSql(countSel, tableName);
|
||||
long count = pojoService.findCount(countSel);
|
||||
String selectStr = select.toString();
|
||||
if(selectStr.contains(" DISTINCT ")){
|
||||
long countWithoutDistinct = pojoService.findCount(countSel.replace("DISTINCT ", " "));
|
||||
if(count >= 1 && count == countWithoutDistinct){
|
||||
selectStr = selectStr.replace(" DISTINCT ", " ");
|
||||
}
|
||||
}
|
||||
|
||||
result.put(PAGE_COUNT, count);
|
||||
boolean isOnlyGetCount = map.get(IS_ONLY_GET_COUNT) == null ? false : (Boolean)map.get(IS_ONLY_GET_COUNT);
|
||||
if (count >= 1 && !isOnlyGetCount) {
|
||||
Object startObj = map.get(PAGE_START);
|
||||
Object sizeObj = map.get(PAGE_SIZE);
|
||||
int sta = (startObj == null ? 0 : (Integer) startObj);
|
||||
int size = (sizeObj == null ? (int)count : (Integer) sizeObj);
|
||||
sta = (sta > count ? 0 : sta);
|
||||
size = (size > count ? (int)count : size);
|
||||
//记录日志
|
||||
logSql(select.toString(), tableName);
|
||||
List<GeneralPOJO> list = pojoService.listSelectSpecialCols(selectStr,
|
||||
tableName, sta,
|
||||
size, returnColMap);
|
||||
result.put(LIST_RESULT, list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件和外键替换排序字段
|
||||
* @param orderBy
|
||||
* @param info
|
||||
* @return
|
||||
*/
|
||||
private String replaceReferOrderCols(String orderBy, POJOInfo info) {
|
||||
if (!StringUtil.isEmpty(orderBy)) {
|
||||
orderBy = orderBy.replaceAll(" " + GeneralPOJO.DOCUMENT + " ", " " + GeneralPOJO.DOCUMENT + GeneralPOJO.DISPLAY + " ");
|
||||
|
||||
String[] cols = orderBy.toUpperCase().replace("ORDER", "")
|
||||
.replaceAll(" BY ", "").replaceAll(" DESC", "")
|
||||
.replaceAll(" ASC", "").split(",");
|
||||
for(String col : cols){
|
||||
String[] strs = col.trim().split("\\.");
|
||||
String colName = null;
|
||||
if(strs.length > 1){
|
||||
colName = strs[1];
|
||||
}else if(strs.length == 1){
|
||||
colName = strs[0];
|
||||
}
|
||||
if(info.getColumnIndexByName(colName)>0
|
||||
){
|
||||
String rt = info.getReferenceTable(colName);
|
||||
if(rt != null){
|
||||
orderBy = orderBy.replaceAll(" " + colName + " ", " " + colName + GeneralPOJO.DISPLAY + " ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
private List<String> getOrderCols(String orderBy, List<String> list,POJOInfo info) {
|
||||
if (!StringUtil.isEmpty(orderBy) && list != null) {
|
||||
String[] cols = orderBy.toUpperCase().replace("ORDER", "")
|
||||
.replaceAll(" BY ", "").replaceAll(" DESC", "")
|
||||
.replaceAll(" ASC", "").split(",");
|
||||
for(String col : cols){
|
||||
String[] strs = col.trim().split("\\.");
|
||||
String colName = null;
|
||||
if(strs.length > 1){
|
||||
colName = strs[1];
|
||||
}else if(strs.length == 1){
|
||||
colName = strs[0];
|
||||
}
|
||||
if(info.getColumnIndexByName(colName)>0
|
||||
){
|
||||
String rt = info.getReferenceTable(colName);
|
||||
if(rt != null){
|
||||
orderBy = orderBy.replaceAll(" " + colName + " ", " " + colName + GeneralPOJO.DISPLAY + " ");
|
||||
}
|
||||
|
||||
}
|
||||
if(!list.contains(colName)){
|
||||
list.add(colName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@OriginServiceMethod(name = "自定义sql数据查询(指定返回列)",type = "dataDic", description = "可以指定返回字段的数据查询,通用方法,Map 查询条件,tableName 查询实体,sql 自定义sql, ctx 环境, returnColMap 查询需要返回的列")
|
||||
public Map<String, Object> listSelectBySql(Map map, final String tableName, String sql, Properties ctx, List<String> returnColMap) {
|
||||
|
||||
String order = (String)map.get(ORDER);
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
if(!map.containsKey(RETURN_COLUMNS_LIST)){
|
||||
map.put(RETURN_COLUMNS_LIST, returnColMap);
|
||||
}
|
||||
|
||||
String countSel = "SELECT COUNT(*) AS COU FROM (" + sql + ") AS TEMPTABLE ";
|
||||
if (!StringUtil.isEmpty(order)) {
|
||||
sql = sql + order;
|
||||
}
|
||||
//记录日志
|
||||
logSql(countSel, tableName);
|
||||
long count = pojoService.findCount(countSel);
|
||||
|
||||
result.put(PAGE_COUNT, count);
|
||||
boolean isOnlyGetCount = map.get(IS_ONLY_GET_COUNT) == null ? false : (Boolean)map.get(IS_ONLY_GET_COUNT);
|
||||
if (count >= 1 && !isOnlyGetCount) {
|
||||
Object startObj = map.get(PAGE_START);
|
||||
Object sizeObj = map.get(PAGE_SIZE);
|
||||
int sta = (startObj == null ? 0 : (Integer) startObj);
|
||||
int size = (sizeObj == null ? (int)count : (Integer) sizeObj);
|
||||
sta = (sta > count ? 0 : sta);
|
||||
size = (size > count ? (int)count : size);
|
||||
//记录日志
|
||||
logSql(sql, tableName);
|
||||
List<GeneralPOJO> list = pojoService.listSelectSpecialCols(sql,
|
||||
tableName, sta,
|
||||
size, returnColMap);
|
||||
result.put(LIST_RESULT, list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return the result key count: number, key result: list
|
||||
*/
|
||||
@OriginServiceMethod(name = "通用数据查询(指定返回列)",type = "dataDic", description = "可以指定返回字段的数据查询,通用方法,Map 查询条件,tableName 查询实体,ctx 环境, returnColMap 查询需要返回的列")
|
||||
public Map<String, Object> searchTreeStru(Map map, final String tableName, Properties ctx, List<String> returnColMap) {
|
||||
//FIXME:数据权限
|
||||
String parentColumnName = (String)map.get(PARENT_COLUMN_NAME);
|
||||
if (!StringUtil.isEmpty(parentColumnName)) {
|
||||
|
||||
if (returnColMap != null && returnColMap.size() > 0) {
|
||||
POJOInfo info = POInfo.getPOInfo(tableName);
|
||||
if (info != null && info.getTableType() != Entity.MIDTABLE) {
|
||||
if (!returnColMap.contains(tableName + "_ID")) {
|
||||
returnColMap.add(tableName + "_ID");
|
||||
}
|
||||
String displayName = info.getColumnLabel(info
|
||||
.getDisplayIndex());
|
||||
if (!returnColMap.contains(displayName)) {
|
||||
returnColMap.add(displayName);
|
||||
}
|
||||
if(!returnColMap.contains(parentColumnName)){
|
||||
returnColMap.add(parentColumnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
GeneralPO po = new GeneralPO(tableName,
|
||||
new HashMap<String, Object>(), ctx);
|
||||
if (!map.containsKey(RETURN_COLUMNS_LIST)) {
|
||||
map.put(RETURN_COLUMNS_LIST, returnColMap);
|
||||
}
|
||||
String privilege = "";
|
||||
if(ctx != null && !ctx.get(LoggedInUser.CURRENTUSER).equals(LoggedInUser.ADMIN)){
|
||||
privilege = dataPrivilegeService.getWhereClause(ctx, tableName);
|
||||
}
|
||||
//FIXME:需考虑权限和排序
|
||||
StringBuffer select = po.getWithRecursive(returnColMap, map, parentColumnName, privilege);
|
||||
String sql = select.toString();
|
||||
|
||||
String order = (String)map.get(ORDER);
|
||||
|
||||
|
||||
String countSel = "SELECT COUNT(*) AS COU FROM (" + sql + ") AS TEMPTABLE ";
|
||||
if (!StringUtil.isEmpty(order)) {
|
||||
sql = sql + order;
|
||||
}
|
||||
//记录日志
|
||||
logSql(countSel, tableName);
|
||||
long count = pojoService.findCount(countSel);
|
||||
|
||||
result.put(PAGE_COUNT, count);
|
||||
boolean isOnlyGetCount = map.get(IS_ONLY_GET_COUNT) == null ? false : (Boolean)map.get(IS_ONLY_GET_COUNT);
|
||||
if (count >= 1 && !isOnlyGetCount) {
|
||||
Object startObj = map.get(PAGE_START);
|
||||
Object sizeObj = map.get(PAGE_SIZE);
|
||||
int sta = (startObj == null ? 0 : (Integer) startObj);
|
||||
int size = (sizeObj == null ? (int)count : (Integer) sizeObj);
|
||||
sta = (sta > count ? 0 : sta);
|
||||
size = (size > count ? (int)count : size);
|
||||
//记录日志
|
||||
logSql(sql, tableName);
|
||||
List<GeneralPOJO> list = pojoService.listSelectSpecialCols(sql,
|
||||
tableName, sta,
|
||||
size, returnColMap);
|
||||
result.put(LIST_RESULT, list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@OriginServiceMethod(name = "通用数据保存",type = "dataDic", description = "数据保存,通用方法,Map 保存数据,tableName 保存实体,ctx 环境")
|
||||
@Override
|
||||
public GeneralPOJO save(Map map, String tableName, Properties ctx) {
|
||||
//FIXME: 数据权限
|
||||
GeneralPO po = new GeneralPO(tableName, map, ctx);
|
||||
pojoService.save(po, ctx != null ? ctx.getProperty(LoggedInUser.CURRENTUSER) : LoggedInUser.ADMIN);
|
||||
return po;
|
||||
}
|
||||
|
||||
|
||||
@OriginServiceMethod(name = "通用数据更新",type = "dataDic", description = "数据更新,通用方法,Map 更新数据,tableName 更新实体,ctx 环境")
|
||||
@Override
|
||||
public GeneralPOJO update(Map map, String tableName, Properties ctx) {
|
||||
//FIXME: 数据权限
|
||||
String entityId = (String) map.get(tableName + "_ID");
|
||||
GeneralPOJO po = pojoService.loadPOJO(entityId,
|
||||
tableName, ctx, true);
|
||||
if (po != null) {
|
||||
int count = po.get_ColumnCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (map.containsKey(po.get_ColumnName(i))) {
|
||||
String name = po.get_ColumnName(i);
|
||||
po.set_ValueOfColumn(name, map.get(name));
|
||||
}
|
||||
}
|
||||
//FIXME: userid is not null, this is test
|
||||
pojoService.update(po,
|
||||
ctx != null ? ctx.getProperty(LoggedInUser.CURRENTUSER) : LoggedInUser.ADMIN);
|
||||
return po;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@OriginServiceMethod(name = "通用数据删除",type = "dataDic", description = "数据删除,通用方法,entityId 删除数据id,tableName 删除实体,ctx 环境")
|
||||
@Override
|
||||
public GeneralPOJO delete(String entityId, String tableName, Properties ctx) {
|
||||
//FIXME: 数据权限
|
||||
|
||||
GeneralPOJO po = loadPOJO(entityId, tableName, ctx, true);
|
||||
pojoService.delete(po, ctx != null ? ctx.getProperty("userId") : "admin", false);
|
||||
return po;
|
||||
}
|
||||
|
||||
@OriginServiceMethod(name = "通用数据强行删除",type = "dataDic", description = "数据删除,通用方法,entityId 删除数据id,tableName 删除实体,ctx 环境")
|
||||
@Override
|
||||
public GeneralPOJO forceDelete(String entityId, String tableName,
|
||||
Properties ctx) {
|
||||
GeneralPOJO po = loadPOJO(entityId, tableName, ctx, true);
|
||||
pojoService.delete(po, ctx != null ? ctx.getProperty("userId") : "admin", true);
|
||||
return po;
|
||||
}
|
||||
|
||||
@OriginServiceMethod(name = "通用数据加载",type = "dataDic", description = "数据加载,通用方法,entityId 加载数据id,tableName 加载实体,ctx 环境,isHierarchical 是否级联加载")
|
||||
@Override
|
||||
public GeneralPOJO loadPOJO(String entityId, String tableName, Properties ctx, Boolean isHierarchical) {
|
||||
GeneralPOJO result = null;
|
||||
// GeneralPOJO po = new GeneralPO(tableName, null, UserSession.get());
|
||||
// //FIXME: 数据权限
|
||||
// StringBuffer select = po.getSelectBuild();
|
||||
// String sql = select + " WHERE " + tableName + "_ID='" + entityId + "'";
|
||||
// List<GeneralPOJO> list = pojoService.listSelect(sql, tableName, 0, 1);
|
||||
// if(list != null && list.size() == 1){
|
||||
// result = list.get(0);
|
||||
// }
|
||||
result = pojoService.loadPOJO(entityId, tableName, ctx, isHierarchical);
|
||||
// if(isHierarchical && result != null){
|
||||
// hierarchicalQuery(result, ctx);
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
|
||||
private void hierarchicalQuery(GeneralPOJO po, Properties ctx){
|
||||
if(po != null){
|
||||
int count = po.get_ColumnCount();
|
||||
for(int i = 0; i < count; i++){
|
||||
String type = po.get_ColumnDisplayType(i);
|
||||
if(DisplayType.List.equals(type)){
|
||||
String referenceColumn = po.get_referenceValueColumnName(i);
|
||||
String referenceTable = po.get_poInfo().getReferenceValueTable(i);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(referenceColumn, po.get_ID());
|
||||
GeneralPO subPo = new GeneralPO(referenceTable, new HashMap<String, Object>(), ctx);
|
||||
StringBuffer select = subPo.getSelectBuild();
|
||||
StringBuffer where = subPo.get_SearchWhereClause(map);
|
||||
if(select != null && select.length() > 0){
|
||||
if(where != null && where.length() > 0){
|
||||
select.append(where);
|
||||
}
|
||||
}
|
||||
//增加子表默认排序,按第二个col升序排序,第一个col为id
|
||||
String orderCol = subPo.get_ColumnName(1);
|
||||
select.append(" ORDER ").append(" BY P.").append(orderCol).append(" ASC ");
|
||||
|
||||
List<GeneralPOJO> list = pojoService.listSelect(select.toString(), referenceTable, 0, Integer.MAX_VALUE);
|
||||
POJOInfo referenceInfo = po.initPO(referenceTable);
|
||||
if(referenceInfo.getTableType() == Entity.MIDTABLE && list.size() > 0){
|
||||
String otherForeignCol = referenceColumn.equals(referenceInfo.getColumnName(0)) ? referenceInfo.getColumnName(1) : referenceInfo.getColumnName(0);
|
||||
List<String> midList = new ArrayList<String>();
|
||||
for(GeneralPOJO midPO : list){
|
||||
midList.add((String)midPO.get_Value(otherForeignCol));
|
||||
}
|
||||
po.updateHierarchicalValue(i, midList);
|
||||
} else {
|
||||
loadSubTableDoc(list, ctx);
|
||||
po.updateHierarchicalValue(i, list);
|
||||
}
|
||||
}else if(DisplayType.Binary.equals(type)){
|
||||
loadDoc(po, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载子表的附件
|
||||
* @param list
|
||||
*/
|
||||
private void loadSubTableDoc(List<GeneralPOJO> list, Properties ctx){
|
||||
if(list != null && list.size() > 0){
|
||||
GeneralPOJO po = list.get(0);
|
||||
if(po != null){
|
||||
int count = po.get_ColumnCount();
|
||||
for(int i = 0; i < count; i++){
|
||||
String type = po.get_ColumnDisplayType(i);
|
||||
if(DisplayType.Binary.equals(type)){
|
||||
for(GeneralPOJO pojo : list){
|
||||
loadDoc(pojo, i);
|
||||
}
|
||||
}else if(DisplayType.List.equals(type)){
|
||||
for(GeneralPOJO pojo : list){
|
||||
hierarchicalQuery(pojo, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDoc(GeneralPOJO po, int i){
|
||||
FileService fileService = (FileService)SpringBeanOsgiServices.getInstance().getBeanByName("fileService");
|
||||
List<String> businessKeys = new ArrayList<String>();
|
||||
businessKeys.add(po.get_ID());
|
||||
List<GeneralPOJO> list = fileService.getDoc(businessKeys);
|
||||
if (list != null) {
|
||||
List<Map<String, Object>> objs = new ArrayList<Map<String, Object>>();
|
||||
for (GeneralPOJO file : list) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(SYSDoc.docId, file.get_ID());
|
||||
map.put(SYSDoc.fileName,
|
||||
file.get_Value(SYSDoc.fileName));
|
||||
map.put(SYSDoc.fileSize,
|
||||
file.get_Value(SYSDoc.fileSize));
|
||||
map.put(SYSDoc.filePath,
|
||||
file.get_Value(SYSDoc.filePath));
|
||||
map.put(GeneralPOJO.UPDATETIME, file.get_Value(GeneralPOJO.UPDATETIME));
|
||||
objs.add(map);
|
||||
}
|
||||
po.updateHierarchicalValue(i, objs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Object executeProcedureReturnObject(
|
||||
String returnType, String[][] returnSetType, Properties ctx, String procedure) {
|
||||
return pojoService.executeProcedureReturnList(procedure, returnType, returnSetType);
|
||||
}
|
||||
|
||||
@OriginServiceMethod(name = "通用数据批量保存",type = "dataDic", description = "数据;批量保存,通用方法,list 保存数据,tableName 保存实体,ctx 环境")
|
||||
public void batchSave(List<Map> list, String tableName, Properties ctx) {
|
||||
// FIXME: 数据权限 忽略批量插入的日志
|
||||
if (list != null) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String userID = ctx != null ? ctx
|
||||
.getProperty(LoggedInUser.CURRENTUSER) : LoggedInUser.ADMIN;
|
||||
for (Map map : list) {
|
||||
GeneralPO po = new GeneralPO(tableName, map, ctx);
|
||||
buffer.append(pojoService.save_convertToSql(po, userID, null))
|
||||
.append(";\n");
|
||||
}
|
||||
if (buffer.length() > 0) {
|
||||
pojoService.batchExecute(buffer.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logSql(String sql,String tableName){
|
||||
if(tableName != null && !tableName.startsWith("SYS_")){
|
||||
this.systemLogManager.log(LogType.INFO, sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,66 @@
|
||||
package com.dsasp.server.dataDic.util;
|
||||
|
||||
public class FunctionBean {
|
||||
|
||||
private String className;// 类名
|
||||
private String method;// 方法名称+参数类型
|
||||
private String methodName;// 方法名称
|
||||
private String tip;
|
||||
private String name;
|
||||
private String returnResult;
|
||||
|
||||
public FunctionBean() {
|
||||
|
||||
}
|
||||
public FunctionBean(String className){
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public String getTip() {
|
||||
return tip;
|
||||
}
|
||||
|
||||
public void setTip(String tip) {
|
||||
this.tip = tip;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getReturnResult() {
|
||||
return returnResult;
|
||||
}
|
||||
|
||||
public void setReturnResult(String returnResult) {
|
||||
this.returnResult = returnResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.dsasp.server.dataDic.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dsasp.server.common.core.Function;
|
||||
import com.dsasp.server.common.function.GetDefaultValueFunction;
|
||||
import com.dsasp.server.common.function.GetServicesFunction;
|
||||
import com.dsasp.server.common.function.GetValueFunction;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
|
||||
public class FunctionUtil {
|
||||
private static Map<String, List<FunctionBean>> functionMap;
|
||||
private static Map<String, String> functionDescription;//函数类型描述
|
||||
private static boolean init;
|
||||
|
||||
/**
|
||||
* @return 函数
|
||||
*/
|
||||
public static Map<String, List<FunctionBean>> getFunctions() {
|
||||
if (!init)
|
||||
init0();
|
||||
return functionMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 函数类型
|
||||
*/
|
||||
public static Map<String, String> getDescriptions() {
|
||||
if (!init)
|
||||
init0();
|
||||
return functionDescription;
|
||||
}
|
||||
|
||||
private static synchronized void init0() {
|
||||
if (init)
|
||||
return;
|
||||
List<Class> list = new ArrayList<Class>();
|
||||
list.add(GetValueFunction.class);
|
||||
list.add(GetServicesFunction.class);
|
||||
list.add(GetDefaultValueFunction.class);
|
||||
functionMap = new HashMap<String, List<FunctionBean>>();
|
||||
functionDescription = new HashMap<String, String>();
|
||||
functionDescription.put(GetValueFunction.class.getName(), "字段取值函数");
|
||||
functionDescription.put(GetServicesFunction.class.getName(), "服务调用函数");
|
||||
functionDescription.put(GetDefaultValueFunction.class.getName(), "默认值函数");
|
||||
for (Class functionClass : list) {
|
||||
List<FunctionBean> functionList = new ArrayList<FunctionBean>();//方法属性List
|
||||
|
||||
String beanClassName = functionClass.getName();
|
||||
String className = functionClass.getSimpleName();
|
||||
Method[] methods = functionClass.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getAnnotation(Function.class) != null) {
|
||||
FunctionBean fb = new FunctionBean(className);
|
||||
Function f = (Function) method
|
||||
.getAnnotation(Function.class);
|
||||
Class[] paras = method.getParameterTypes();
|
||||
String paraTypes = "";
|
||||
if (paras != null && paras.length > 0) {
|
||||
for (Class c : paras) {
|
||||
String name = c.getName();
|
||||
if (name.indexOf(".") != -1) {
|
||||
name = name
|
||||
.substring(name.lastIndexOf(".") + 1);
|
||||
}
|
||||
paraTypes = paraTypes + "," + name;
|
||||
}
|
||||
}
|
||||
if (!StringUtil.isEmpty(paraTypes)) {
|
||||
paraTypes = "(" + paraTypes.substring(1) + ")";
|
||||
} else {
|
||||
paraTypes = "()";
|
||||
}
|
||||
fb.setMethod(method.getName() + paraTypes);
|
||||
fb.setMethodName(method.getName());
|
||||
fb.setName(f.name());
|
||||
fb.setTip(f.tip());
|
||||
fb.setReturnResult(method.getReturnType().getName());
|
||||
functionList.add(fb);
|
||||
}
|
||||
}
|
||||
functionMap.put(beanClassName, functionList);
|
||||
}
|
||||
init = true;
|
||||
return;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
FunctionUtil.getFunctions();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.dsasp.server.db.startorupdate;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版在 OSGi bundle 启动时按版本执行 install SQL,并以
|
||||
* 硬编码的开发库 host/dbname 判断 isDevDB()(开发库跳过结构更新)。
|
||||
* PoC 中不做启动期 DDL,按生产行为返回 false。
|
||||
*/
|
||||
public class InstallOrUpdate {
|
||||
|
||||
public static boolean isDevDB() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user