许鹏程
6 天以前 001ead79e19e94ed4e693106431f122b3412529f
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
package com.product.mobile.core.service;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import com.product.common.lang.StringUtils;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.util.BaseUtil;
 
/**
 * 手机端,获取用户所有应用
 * @author Administrator
 *
 */
@Component
public class SystemTableMetaService extends AbstractBaseService{
    @Autowired
    public BaseDao baseDao;
    /**
     *     数据表结构信息
     * @param cpage
     * @param pagesize
     * @return
     * @throws BaseException
     */
    public FieldSetEntity getSystemTableMeta(FieldSetEntity fse) throws BaseException{
   
        Map<Object,Object> vs=fse.getValues();
        StringBuilder b=new StringBuilder();
        b.append("select t.table_name,f.field_name,f.field_length,f.field_show_name,f.field_type,f.field_reference,f.is_required from product_sys_datamodel_field f left join product_sys_datamodel_table t on f.table_uuid=t.uuid");
        List<Object> ps=new ArrayList<>();
        if(vs!=null && vs.size()>0) {
            b.append(" where ");
            Iterator keys=vs.keySet().iterator();
            int c=0;
            while(keys.hasNext()) {
                Object key=keys.next();
                Object field=vs.get(key);
//                if(StringUtils.isEmpty(field)) {
//                    continue;
//                }
                if(c>0) {
                    b.append(" or ");
                }
                Object fp[]=BaseUtil.buildQuestionMarkFilter("f.field_name","in",field.toString());
                b.append("(t.table_name=? ");
                ps.add(key);
                if(fp!=null && fp.length>1) {
                    b.append(" and ");
                    b.append(fp[0]);
                    ps.addAll((List)fp[1]);
                }
                b.append(")");
                c++;
            }
            b.append(" order by  t.table_name ");
            FieldSetEntity fs=new FieldSetEntity("product_sys_datamodel_field");
            DataTableEntity dt=baseDao.listTable(b.toString(), ps.toArray());
            String table=null;
            DataTableEntity sub=new DataTableEntity();
            for(int i=0;i<dt.getRows();i++) {
                String tb=dt.getString(i, "table_name");
                if(table!=null && !table.equals(tb)) {
                    sub.getMeta().getTableName()[0]=table;
                    fs.addSubDataTable(sub);
                    sub=new DataTableEntity();
                }
                table=tb;
                sub.addFieldSetEntity(dt.getFieldSetEntity(i));
            }
            sub.getMeta().getTableName()[0]=table;
            fs.addSubDataTable(sub);
            return fs;
        }
        return null;
    }
}