xinyb
2022-05-18 c2dc593c9b8948718381f3a2996b6f94a59ad80a
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
 * 生成3类型窗体文件,生成路径已系统菜单为准,文件为formID_file.jsp为准。
 * xiangluan
 * 2010-04-16
 */
package com.yc.service.build.type.v2;
 
import com.yc.action.grid.GridUtils;
import com.yc.api.bean.T9685Entity;
import com.yc.api.service.ApiServiceIfc;
import com.yc.exception.ApplicationException;
import com.yc.factory.FactoryBean;
import com.yc.service.BaseService;
import com.yc.service.sqlformat.entity.SqlFormatEntity;
import com.yc.service.sqlformat.utils.SqlFormatUtils;
import com.yc.service.tree.TreeIfc;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service("V3")
public class T_3_Impl extends BaseImpl implements T_3_Ifc {
 
 
    @Autowired
    private TreeIfc treeIfc;
    @Autowired
    private ApiServiceIfc apiServiceIfc;
 
    @Override
    public int build(BaseBean baseBean) throws Exception {
        // 读取gform表的信息
        Map<String, Object> gformInfo = this.init(baseBean);
        Map<String, Object> treeSet = null;
        List<Map<String, Object>> treeSetList = treeIfc.getTreeSet(baseBean.formID, baseBean.type);
        if (treeSetList != null) {
            if(treeSetList.size()==0)
                throw new ApplicationException("请在【9824】对"+baseBean.formID+"树形相关参数进行配置");
            treeSet = treeSetList.get(0);
        }
        String autoCodeColumn = treeIfc.getAutoCodeColumn(baseBean.formID);
        String autoCodeConfig = treeIfc.getAutoCodeConfig(baseBean.formID);
        if (treeSet.get("treewidth") != null && !StringUtils.isBlank(treeSet.get("treewidth").toString())) {// 判断属性边框宽度是否设置
            int trwidth = 0;
            if (treeSet.get("treewidth").toString().indexOf("%") != -1) {
                trwidth = Integer.parseInt(treeSet.get("treewidth").toString().replace("%", "0"));
                trwidth = trwidth + 60;
            } else {
                trwidth = Integer.parseInt(treeSet.get("treewidth").toString());
            }
            trwidth = trwidth > 0 ? trwidth : 300;
            gformInfo.put("treewidth", trwidth + "px");
        } else {
            gformInfo.put("treewidth", "300px");// 没有设置的情况默认300px
        }
        //----查找树节点id,通过treefromid再查一次9824树本身的nodeid,detailNodeid是格线里的字段,在这里做一个转换
        //把之前nodeid的值用树自身的nodeid代替。
        BaseService baseService = (BaseService) FactoryBean.getBean("BaseService");
        for (Map map : treeSetList) {//修改对应的值,nodeid是树节点字段,detailNodeid是格线字段
            String nodeid = baseService.getJdbcTemplate().queryForObject(" select nodeid from _sysTreeSet where formid=? ", String.class, GridUtils.prossRowSetDataType_String(map, "treeformid"));
 
            map.put("detailNodeid", GridUtils.prossRowSetDataType_String(map, "nodeid"));
            map.put("nodeid", nodeid);
        }
        //----------
        buildDataHead(gformInfo);
        buildTop(gformInfo);
        buildHelpPage(gformInfo);
        buildJsCssHead(treeSetList, baseBean);
        buildGrid(baseBean);
        buildTreeData(treeSetList, gformInfo, autoCodeColumn, autoCodeConfig);
        buildFoolter(baseBean);
        buildIndex(gformInfo);
 
        return 0;
    }
 
    /**
     * 生成js css 导入的页面
     *
     * @throws Exception
     */
    public void buildJsCssHead(List<Map<String, Object>> treeSetList, BaseBean baseBean) throws Exception {
        String fileName = "jsCssHead.jsp";
        String data = getPageCode(fileName, baseBean);
        // ----------------
 
        Map<String, Map> treeList = new HashMap<>();//保存多树的设置信息
        for (Map treeSet : treeSetList) {
            Map<String, String> tree = new HashMap<>();//保存树的设置信息
//        Map treeSet=treeSetList.get(0);
            ////data = data.replace("[?autocode]", autoCodeColumn);
            //data = data.replace("[?autocodeConfig]", autoCodeConfig);
            tree.put("displayfield", trim(treeSet.get("displayfield")).toLowerCase());
            tree.put("nodeid", trim(treeSet.get("nodeid")).toLowerCase());
            tree.put("separatedst", trim(treeSet.get("separatedst")));
            tree.put("detailNodeid", trim(treeSet.get("detailNodeid")));
            //
            String treeFormid = trim(treeSet.get("treeformid"));
            String treeFormType = baseBean.type + "";
            if (!treeFormid.equals(baseBean.formID + "")) {
                List<Map<String, Object>> refTypes = treeIfc.getTreeSetByFormid("formtype", treeFormid);
                if (refTypes.size() > 0) {
                    treeFormType = trim(refTypes.get(0).get("formtype"));
                }
            }
            tree.put("treeFormId", treeFormid);
            tree.put("treeFormType", treeFormType);
            treeList.put(treeFormid, tree);
            //
            //    String columns = gformIfc.getColumns(Integer.parseInt(formID), true);
            //data = data.replace("[?columns]", "[" + columns + "]");
        }
        data = data.replace("[?trees]", GridUtils.toJson(treeList));
        //增加树过滤条件,作为参数传到后台执行
        BaseService baseService = (BaseService) FactoryBean.getBean("BaseService");
        Map treefilterstr = baseService.getSimpleJdbcTemplate().queryForMap(" select top 1 formid,formtype,treeformid,treeName,SortID,keyfield,parentfield,nodeid,listfield,displayfield,separatedst,treefield,autocodefield,treefilterstr,authcheck,allowdrag,defNodeTypeFilter,startnodetypefilter,treewidth from _sysTreeSet where formid=? ", baseBean.getFormID());
        final SqlFormatEntity sqlFormatByEntity = SqlFormatUtils.createSQLFormatByEntity(treefilterstr, 9824);
        data = data.replace("[?treefilterstr]", sqlFormatByEntity==null?"null":GridUtils.toJson(sqlFormatByEntity));
        buildPageCode(data, fileName, baseBean);
    }
 
    /**
     * 生成TreeData页面
     *
     * @throws Exception
     */
    public void buildTreeData(List<Map<String, Object>> treeSetList, Map<String, Object> gformInfo, String autoCodeColumn, String autoCodeConfig) throws Exception {
        BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
        String formID = baseBean.formID;
        Map<String, Map> treeList = new HashMap<>();//保存多树的设置信息
        String treeFormids = "";
        for (Map treeSet : treeSetList) {
 
            if (StringUtils.isBlank((String) treeSet.get("nodeid"))) {
                throw new RuntimeException("3类型树功能号:" + formID + "生成有误。在树设置9824功能号中,[节点字段]字段不能为空,该字段用于配置显示节点信息,必需要配置该字段才能生成!");
            }
            if (treeSet.get("treeformid") == null) {
                throw new RuntimeException("3类型树功能号:" + formID + "生成有误。在树设置9824功能号中,[树功能号]字段不能为空,该字段用于引用2类型树,必须需要配置该字段才能生成!");
            }
            if (StringUtils.isBlank((String) treeSet.get("displayfield"))) {
                throw new RuntimeException("3类型树功能号:" + formID + "生成有误。在树设置9824功能号中,[显示字段列表]字段不能为空,必需要配置该字段才能生成!");
            }
            // 树功能号
            String treeFormid = treeSet.get("treeformid").toString();
            // 功能号主表名
            String str_tableName = null;
            if (!treeFormid.equals(formID)) {// 如果树功能号不等于当前功能号
                List<Map<String, Object>> refTypes = treeIfc.getTreeSetByFormid("formtype", treeFormid);
                if (refTypes.size() == 0 || refTypes.size() > 1) {
                    throw new RuntimeException("3类型树功能号:" + formID + "生成有误。在树设置9824功能号中所对应的功能号没有或有多个!");
                }
                int treeFormidType = 0;
                if (refTypes.get(0).get("formtype") != null) {
                    treeFormidType = (Integer) refTypes.get(0).get("formtype");
                }
                Map<String, Object> tmp = gformIfc.getGformInfo(treeFormidType == 20 ? "dttable" : "hdtable", Integer.parseInt(treeFormid));
                str_tableName = tmp.get(treeFormidType == 20 ? "dttable" : "hdtable").toString();
            } else {
                str_tableName = gformInfo.get("hdtable").toString();
            }
 
            if (StringUtils.isBlank(str_tableName)) {
                throw new RuntimeException("3类型树功能号:" + formID + "生成有误。在树设置9824功能号中,[树功能号]字段所对应的功能号的主表字段为空!");
            }
            // 功能号过滤条件--树显示是用树设置的过滤条件
            // String str_formdatafilters = gformInfo.get("formdatafilters")==null?"":gformInfo.get("formdatafilters").toString();
            // 生成第一层节点查询sql
            // 主键字段名
            String primayKey = "";
            String firstNodeSql = treeIfc.buildFirstLayerTreeSQL(treeSet, str_tableName, primayKey);// 树的查询sql
            // if(!"".equals(trim(gformInfo.get("formdatafilters")))){
            // firstNodeSql+=" and ("+gformInfo.get("formdatafilters")+")";
            // }
 
 
            String sql = trim(treeIfc.buildTreeSQLNotFilter(treeSet, str_tableName, primayKey));// 树节点信息查询sql
            String querySql = trim(treeIfc.buildQueryTreeSQL(treeSet, str_tableName, primayKey));// 树的查询sql
            //格线对应的字段,用作查询格线时的参数名称
            String detailNodeid = treeSet.get("detailNodeid").toString().trim();
            // 显示字段
            String displayfield = treeSet.get("displayfield").toString().trim();
            // 分割符
            String separatedst = treeSet.get("separatedst") == null ? "" : treeSet.get("separatedst").toString();
            String nodeid = GridUtils.prossRowSetDataType_String(treeSet, "nodeid");
            //格线取第一个节点作为第一次加载时的条件 By dananus
            String tempNode = this.getSimpleJdbcTemplate().queryForObject(" set nocount on ; declare @fieldid varchar(50);select top 1 @fieldid = fieldid from gfield where formid = ? and initvalue = ?;select @fieldid;", String.class, formID, nodeid);
            if (tempNode == null) {
                throw new ApplicationException("由于在9824设置了树功能号为【" + treeFormid + "】的节点字段【" + nodeid + "】,因此必须在9802中设置【" + formID + "】功能号与树关联字段的初始值设为【" + nodeid + "】");
            }
            //tempNode = nodeid;
            StringBuffer treeNodeStr = new StringBuffer();
            treeNodeStr.append(" cast(" + tempNode + " as varchar) in (select top 1 cast(").append(nodeid + " as varchar) from ")
                    .append(str_tableName)
                    .append(" as b where (b.parentrowid =''  or b.parentrowid is null or not exists (select 1 from ")
                    .append(str_tableName).append(" c where b.parentrowid = c.rowid ").append(") ) ");
            // 树过滤条件
            String treefilterstr = GridUtils.prossRowSetDataType_String(treeSet, "treefilterstr");
            if (!"".equals(treefilterstr)) {
                //firstNodeSql += " and (" + treefilterstr + ")";
                querySql += " and (" + treefilterstr + ")";
                treeNodeStr.append(" and (" + treefilterstr + ")");
            }
 
            // 树类型排序
            if (treeSet.get("treeformid") != null) {
                Map<String, Object> gformInfo1 = gformIfc.getGformInfo("index1", Integer.parseInt(treeSet.get("treeformid").toString()));
                if (gformInfo1.get("index1") != null && !gformInfo1.get("index1").toString().equals("")) {
                    if(treeNodeStr.indexOf("order by") < 0) {
                        treeNodeStr.append(" order by " + gformInfo1.get("index1").toString().replace(";", ","));
                    }
                    if(firstNodeSql.indexOf("order by") < 0) {
                            firstNodeSql += " order by " + gformInfo1.get("index1").toString().replace(";", ",");
                        }
 
                }
            }
            treeNodeStr.append(")");
 
 
            // ----------------
            // 替换
            Map<String, String> tree = new HashMap();
            String treeid = trim(treeSet.get("treeformid").toString());
            tree.put("table", str_tableName);
            tree.put("autocode", autoCodeColumn);
            tree.put("autocodeConfig", autoCodeConfig);
            tree.put("treeformid", treeid);
            tree.put("firstNodeSql", firstNodeSql);
            tree.put("sql", sql);
            tree.put("querySql", querySql);
            tree.put("displayfield", trim(displayfield).toLowerCase());
            tree.put("nodeid", trim(nodeid));
            tree.put("detailNodeid", trim(detailNodeid));
            tree.put("separatedst", trim(separatedst));
            tree.put("treeNodeStr", treeNodeStr.toString());
            treeList.put(treeid, tree);
            treeFormids += treeid + ";";
        }
        // 读文件
        String fileName = "treeData.jsp";
        String data = getPageCode(fileName, baseBean);
        String temp = GridUtils.toJson(treeList).replaceAll("\"", "\\\\\\\\\"");
        data = data.replaceAll("@_treeList_@", temp);
        data = data.replaceAll("@_treeFormids_@", treeFormids);
        buildPageCode(data, fileName, baseBean);
        // 处理页面第一次加载时取树的第一个节点作为格线显示的查询条件
        String fileName1 = "tree.jsp";
        String opt = getPageCode(fileName1, baseBean);
        opt = opt.replaceAll("@_treeList_@", temp);
        opt = opt.replaceAll("@_treeFormids_@", treeFormids);
        buildPageCode(opt, fileName1, baseBean);
    }
 
 
    /**
     * 生成主页面
     *
     * @throws Exception
     */
    @Override
    public void buildIndex(Map<String, Object> gformInfo) throws Exception {
        BaseBean baseBean = (BaseBean) gformInfo.get(BEAN_INFO);
        String fileName = "index.jsp";
        String data = getPageCode(fileName, baseBean);
        //
 
        // --------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz--------[begin]----------------------
        if (true) {
            //String menuname_str = "";
            String sSQL = " set nocount on ; select * from gform where formid='" + baseBean.formID + "' and isTitle='1' ";// isTitle=1表示配置了显示大标题
            List<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>();
            arrayList = getArrayList(sSQL);
            if (arrayList.size() > 0) {// 如果配置了显示大标题
 
                String TopAndTitle_str = "<table id=\"top_table\" width=\"100%\" bgcolor=\"#DEEDF7\">\n" + "<tr>\n" + "<td>\n" + "<div id=\"title_top\">[?title]</div>\n" + "</td></tr>\n"
//                        + "<tr>\n" + "<td>\n" + "<hr style=\"position: absolute;left:0px;top:28px;height: 1px;color: #bdc7c6;width: 99%;\">\n" + "</td>\n"
//                        + "</tr>\n"
                        + "<tr><td>\n" + "<div id=\"tplt-top\">\n" + "\t\t\t<%@ include file=\"top.jsp\" %>\n" + "\t\t</div>\n" + "</td></tr>\n" + "</table>";
                data = data.replace("[?TopAndTitle]", TopAndTitle_str);// 替换功能号标识符
                data = data.replace("[?NorthHeight]", "height:68px;");// 替换部分功能号index.jsp页面的top层的宽度
            } else {// 如果没有配置显示大标题
 
                String TopAndTitle_str = "<script type=\"text/javascript\">\n" + "var bh=30;\n" + "</script>\n" + "<div id=\"tplt-top\">\n" + "\t\t\t<%@ include file=\"top.jsp\" %>\n" + "</div>";
 
                data = data.replace("[?TopAndTitle]", TopAndTitle_str);// 替换功能号标识符
                data = data.replace("[?NorthHeight]", "");// 替换部分功能号index.jsp页面的top层的宽度
            }
        }
        // --------从gform表获取是否显示大标题字段值(isTitle)判断是否显示大标题,并替换标识符-2012-02-20-syz-----[end]-------------------------//
 
        //-------------文字颜色说明---------xin 2022-5-18 16:09:54-----------//
        StringBuilder colorText =new StringBuilder();//文字颜色说明
        if(StringUtils.isNotBlank(baseBean.formID)) {
            List<T9685Entity> colorList = apiServiceIfc.get9685List(Integer.parseInt(baseBean.formID));
            if (colorList != null && colorList.size() > 0) {
                colorText.append("文字颜色说明");
                for (T9685Entity t : colorList) {
                    colorText.append("<div><span title=\"" + t.getItemMemo() + "\" class=\"spanColor\" " +
                            "style=\"background-color: " + t.getHexColor() + "\"></span>" +
                            "<span style=\"color: " + t.getHexColor() + "\">" +
                            t.getColorName() + "</span></div>");
                }
            }
        }
        //文字颜色说明 xin 2022-5-18 15:53:13
        data = data.replace("[?ColorDescription]",colorText);
        // ----------------
        data = data.replace("[?title]", gformInfo.get("formname") + "");
        data = data.replace("[?treewidth]", gformInfo.get("treewidth") + "");
        data = data.replaceAll("@gridJsp@", baseBean.formID + "_grid.jsp");
        buildPageCode(data, fileName, baseBean);
    }
 
}