1821349743@qq.com
2023-02-20 059154a3b7d812b3bb4b89ecfa4d94f9b905f7e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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));
        }
    }
}