Ureport豐富SQL數(shù)據(jù)集的SQL參數(shù)的數(shù)據(jù)類型

Ureport的SQL參數(shù)默認(rèn)支持的數(shù)據(jù)類型包括:String、Integer、Float、Boolean、Date、List。

當(dāng)前數(shù)據(jù)類型不滿足我們的功能需要,我們的時(shí)間再數(shù)據(jù)庫(kù)中都是通過(guò)時(shí)間戳(Long)的形式存放的。

需要修改的地方有兩部分:

一、頁(yè)面部分(JS代碼)

在ureport.console工程中,找到并打開(kāi)resources/ureport-asserts/js/designer.bundle.js文件,搜索如下內(nèi)容

<option>Integer</option>

在<option>Integer</option>的前后位置增加如下代碼后保存即可

<option>Long</option>

二、后臺(tái)部分(Java代碼)

在ureport.core工程中,修改com.bstek.ureport.definition.datasource.DataType.java

package com.bstek.ureport.definition.datasource;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

import com.bstek.ureport.Utils;

import com.bstek.ureport.exception.ReportComputeException;

/**

* @author Jacky.gao

* @since 2016年12月27日

*/

public enum DataType {

????Integer,Float,Boolean,String,Date,List,Long;

????public Object parse(Object obj){

????????if(obj==null)return null;

????????switch(this){

????????case Boolean:

????????????if(obj.toString().equals("")){

????????????????return null;

????????????}

????????????if(obj instanceof Boolean){

????????????????return (Boolean)obj;

????????????}else{

????????????????return java.lang.Boolean.valueOf(obj.toString());

????????????}

????????case Float:

????????????if(obj.toString().equals("")){

????????????????return null;

????????????}

????????????if(obj instanceof Float){

????????????????return (Float)obj;

????????????}else{

????????????????return Utils.toBigDecimal(obj).doubleValue();

????????????}

????????case Integer:

????????????if(obj.toString().equals("")){

????????????????return null;

????????????}

????????????if(obj instanceof Integer){

????????????????return (Integer)obj;

????????????}else{

????????????????return Utils.toBigDecimal(obj).intValue();

????????????}

case Long:

????????????if(obj.toString().equals("")){

????????????????return null;

????????????}

????????????if(obj instanceof Long){

????????????????return (Long)obj;

????????????}else{

????????????????return Utils.toBigDecimal(obj).longValue();

????????????}

????????case String:

????????????if(obj instanceof String){

????????????????return (String)obj;

????????????}else{

????????????????return obj.toString();

????????????}

????????case List:

????????????if(obj.toString().equals("")){

????????????????return null;

????????????}

????????????if(obj instanceof List){

????????????????return (List<?>)obj;

????????????}else{

????????????????String[] arrs=obj.toString().split(",");

????????????????List<String> list=new ArrayList<String>();

????????????????for(int i=0;i<arrs.length;i++){

????????????????????list.add(arrs[i]);

????????????????}

????????????????return list;

????????????}

????????case Date:

????????????if(obj.toString().equals("")){

????????????????return null;

????????????}

????????????if(obj instanceof Date){

????????????????return (Date)obj;

????????????}else{

????????????????Date date=null;

????????????????SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

????????????????try{

????????????????????date=sd.parse(obj.toString());

????????????????}catch(ParseException e){

????????????????????sd=new SimpleDateFormat("yyyy-MM-dd");

????????????????????try{

????????????????????????date=sd.parse(obj.toString());????????????????????????

????????????????????}catch(ParseException ex){

????????????????????????throw new ReportComputeException("Date parameter value pattern must be \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\".");

????????????????????}

????????????????}

????????????????return date;

????????????}

????????}

????????throw new ReportComputeException("Unknow parameter type : " + this);

????}

}

加粗傾斜字體部分為增加的內(nèi)容。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容