cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
package cn.ksource.web.facade.impl;
 
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import cn.ksource.beans.GG_XTGN;
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.core.page.PageInfo;
import cn.ksource.core.util.JsonUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.web.facade.XtgnFacade;
@Service("xtgnFacade")
public class XtgnFacadeImpl implements XtgnFacade {
    
    @Autowired
    public BaseDao baseDao;
 
    @Override
    public Map deleteXtgn(String id) {
        String sql = "SELECT COUNT(ID) FROM GG_XTGN WHERE SJBH = :sjbh ";
        Map param = new HashMap();
        param.put("sjbh", id);
        int count = baseDao.queryForInteger(sql, param);
        
        String firstCate = new String();
        String secondCate = new String();
        GG_XTGN xtgn = new GG_XTGN(id).getInstanceById();
        String sjbh = xtgn.getSjbh();
        if(StringUtil.notEmpty(sjbh)) {
            GG_XTGN pxtgn = new GG_XTGN(sjbh).getInstanceById();
            int level = pxtgn.getType();
            if(level==2) {
                firstCate = pxtgn.getSjbh();
                secondCate = pxtgn.getId();
            } else {
                firstCate = pxtgn.getId();
            }
        }
        Map result = new HashMap();
        if(count > 0){
            result.put("msg", "存在子功能,不能删除");
        }else{
            xtgn.deleteById();
            result.put("msg", "1");
        }
        result.put("firstCate", firstCate);
        result.put("secondCate", secondCate);
        return result;
    }
 
    @Override
    public int queryXtgnCount(String pId) {
        StringBuilder builder = new StringBuilder("SELECT COUNT(ID) FROM GG_XTGN  WHERE 1 = 1 ");
        Map paramMap = new HashMap();
        if(StringUtil.notEmpty(pId)) {
            builder.append(" AND SJBH = :pId ");
            paramMap.put("pId", pId);
        } else {
            builder.append(" AND TYPE = 1 ");
        }
        
        int count = baseDao.queryForInteger(builder.toString(),paramMap);
        
        return count;
    }
 
    @Override
    public PageInfo queryXtgnData(PageInfo pageInfo,String pId) {
        StringBuilder builder = new StringBuilder("SELECT * FROM GG_XTGN  WHERE 1 = 1 ");
        Map paramMap = new HashMap();
        if(StringUtil.notEmpty(pId)) {
            builder.append(" AND SJBH = :pId ");
            paramMap.put("pId", pId);
        } else {
            builder.append(" AND TYPE = 1 ");
        }
        
        builder.append(" ORDER BY TYPE,SXH ");
        
        PageInfo info = baseDao.queryforSplitPageInfo(pageInfo, builder.toString(), paramMap);
        
        return info;
    }
 
    @Override
    public List<Map> queryXtgnTree(HttpServletRequest request) {
        Map paramMap = new HashMap();
        String selectSubSql = "SELECT * FROM GG_XTGN ORDER BY TYPE,SXH ";
        List<Map> cates = baseDao.queryForList(selectSubSql,paramMap);
        Map result = new HashMap();
        
        List<Map> resultList = new LinkedList<Map>();
        
        Map<String, Map> yjgnCache = new HashMap<String, Map>();
        Map<String, Map> ejgnCache = new HashMap<String, Map>();
        Map<String, Map> sjgnCache = new HashMap<String, Map>();
        
        for (Map map : cates) {
            String level = map.get("TYPE").toString();
            String id = map.get("ID").toString();
            
            //一级树
            if (level.equalsIgnoreCase("1")) {
                yjgnCache.put(id, map);
                List<Map> ejgnList = new LinkedList<Map>();
                map.put("ejTree", ejgnList);
                resultList.add(map);
                continue;
            }
            //二级树
            if (level.equalsIgnoreCase("2")) {
                String pId = map.get("SJBH").toString();
                if(yjgnCache.containsKey(pId)) {
                    Map yjgnMap = yjgnCache.get(pId);
                    List<Map> list = (List<Map>)yjgnMap.get("ejTree");
                    map.put("sjTree", new LinkedList<Map>());
                    list.add(map);
                    
                    ejgnCache.put(id, map);
                }
                continue;
            }
            //三级树
            if (level.equalsIgnoreCase("3")) {
                if(null!=map.get("SJBH")){
                    String pId = map.get("SJBH").toString();
                    if(ejgnCache.containsKey(pId)) {
                        Map ejgnMap = ejgnCache.get(map.get("SJBH").toString());
                        List<Map> list = (List<Map>)ejgnMap.get("sjTree");
                        map.put("fjTree", new LinkedList<Map>());
                        list.add(map);
                        sjgnCache.put(id, map);
                    }
                }
            }
        }
        System.out.println(JsonUtil.list2Json(resultList));
        return resultList;
    }
 
    @Override
    public boolean isGn_markExists(String gn_mark, String sjbh) {
        String selectsql = "select COUNT(ID) from GG_XTGN where GN_MARK=:gn_mark AND SJBH = :sjbh ";
        int count = baseDao.queryForInteger(selectsql,
                new SqlParameter().addValue("gn_mark", gn_mark).addValue("sjbh", sjbh));
        if(count > 0){
            return false;
        }else{
            return true;
        }
    }
    
    
 
}