package com.product.server.report.quartz;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import com.product.common.lang.StringUtils;
|
import com.product.core.cache.DataPoolCacheImpl;
|
import com.product.core.config.Global;
|
import com.product.core.dao.BaseDao;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.core.transfer.Transactional;
|
import com.product.server.report.service.idel.IViewDataConvertService;
|
|
/**
|
* 对报表原始数据进行清洗处理
|
* 定时任务方式
|
* @author Administrator
|
*
|
*/
|
@Component
|
public class ViewDataConvertService implements IViewDataConvertService {
|
@Autowired
|
public BaseDao baseDao = null;
|
|
private Map<String,String> configs=null;
|
/**
|
* 处理报表数据,把视图的数据插入到实体表中,在properties中读配置信息,[视图,实体表][]
|
* 视图表字段与实体表字段一致
|
* Map<视图表,实体表>
|
* @return Map<视图表,实体表>
|
*/
|
public Map<String,String> reportDataProcessConfig() {
|
String config=Global.getSystemConfig("report.data.process.config", null);
|
if(StringUtils.isEmpty(config)) {
|
return null;
|
}
|
String regex="\\[(.*?)]";
|
Pattern pattern = Pattern.compile(regex);
|
Matcher matcher = pattern.matcher(config);
|
configs=new HashMap<String,String>();
|
while (matcher.find()) {
|
String tables=matcher.group(1);
|
if(!StringUtils.isEmpty(tables)) {
|
String tbs[]=tables.split(",");
|
if(tbs.length>1) {
|
DataTableEntity table_view=DataPoolCacheImpl.getInstance().getCacheData("所有表信息",new String[] {tbs[0]});
|
DataTableEntity table=DataPoolCacheImpl.getInstance().getCacheData("所有表信息",new String[] {tbs[1]});
|
if(table!=null && table.getRows()>0
|
&& table_view!=null && table_view.getRows()>0
|
&& table_view.getFieldSetEntity(0).getInteger("table_type").intValue()==2
|
&& table.getFieldSetEntity(0).getInteger("table_type").intValue()==1) {
|
configs.put(tbs[0], tbs[1]);
|
}
|
}
|
}
|
}
|
return configs;
|
}
|
/**
|
* 报表数据处理任务
|
* 把视图的数据插入到实体表中
|
* 事务
|
*/
|
@Transactional
|
public void reportDataProcessTask() {
|
if(configs==null) {
|
reportDataProcessConfig();
|
}
|
for(String view:configs.keySet()) {
|
DataTableEntity table=DataPoolCacheImpl.getInstance().getCacheData("所有表信息",new String[] {view});
|
if( table==null || table.getRows()==0) {
|
continue;
|
}
|
FieldSetEntity t=table.getFieldSetEntity(0);
|
DataTableEntity ft=DataPoolCacheImpl.getInstance().getCacheData("表字段信息",new String[] {t.getString("uuid")});
|
SpringMVCContextHolder.getSystemLogger().info(view+":::::"+configs.get(view));
|
if( ft==null || ft.getRows()==0) {
|
continue;
|
}
|
StringBuilder fields=new StringBuilder();
|
StringBuilder de_value=new StringBuilder();//默认必须字段的值
|
for(int m=0;m<ft.getRows();m++) {
|
if(fields.length()>0) {
|
fields.append(",");
|
de_value.append(",");
|
}
|
fields.append(ft.getString(m,"field_name"));
|
de_value.append(ft.getString(m,"field_name"));
|
}
|
fields.append(",uuid,created_by,created_utc_datetime,org_level_uuid");
|
de_value.append(",uuid(),1,now(),'00000000-0000-0000-0000-000000000000'");
|
SpringMVCContextHolder.getSystemLogger().info(fields.toString());
|
SpringMVCContextHolder.getSystemLogger().info(de_value.toString());
|
if(fields.length()>0) {
|
//首先删除实体表
|
baseDao.executeUpdate("truncate table "+configs.get(view));
|
SpringMVCContextHolder.getSystemLogger().info("Insert into "+configs.get(view)+"("+fields.toString()+") select "+de_value.toString()+" from "+view);
|
//查出视图信息 插入表中
|
baseDao.executeUpdate("Insert into "+configs.get(view)+"("+fields.toString()+") select "+de_value.toString()+" from "+view);
|
}
|
}
|
}
|
|
static public void main(String args[]) {
|
String a="ae[a,b]see[xde,i3343]adee[agsdidg][dddd";
|
String regex="\\[(.*?)]";
|
Pattern pattern = Pattern.compile(regex);
|
Matcher matcher = pattern.matcher(a);
|
while (matcher.find()) {
|
System.out.println(matcher.group(1));
|
}
|
}
|
}
|