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
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
package cn.ksource.web.facade.colunm;
 
import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import cn.ksource.beans.CMS_CATEGORY;
import cn.ksource.beans.GG_XTGN;
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.page.PageInfo;
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.FileUtil;
import cn.ksource.core.util.JsonUtil;
import cn.ksource.core.util.MyFileUploadException;
import cn.ksource.core.util.StringUtil;
import cn.ksource.web.entity.colunm.CmsCategory;
import cn.ksource.web.service.colunm.ColunmService;
 
@Service("colunmFacade")
@SuppressWarnings("unchecked")
public class ColunmFacadeImpl implements ColunmFacade {
    
    @Autowired
    public BaseDao baseDao;
 
    @Resource(name="colunmService")
    private ColunmService colunmService;
 
    @Override
    public List<Map> getColunmClassifyTree(String id) {
         return colunmService.getColunmClassifyTree(id);
    }
 
    @Override
    public Map getColunmList(String nodeId, int page, int rows) {
        return colunmService.getColunmList(nodeId,page,rows);
    }
 
    @Override
    public int queryLevelById(String nodeId) {
        return colunmService.queryLevelById(nodeId);
    }
 
    /**
     * 保存栏目分类
     */
    @Override
    public void saveColumnClassify(CmsCategory cmsCategory,HttpServletRequest request) {
        String[] allowType =  new String[]{"gif","jpg","jpeg","png"};
        String uploadUrl = new String();
            try {
                uploadUrl = FileUtil.uploadFile4SpringMVC(request, "classifyimage" ,"/upload/classify",allowType);
                String pathPix = request.getSession().getServletContext().getRealPath("/");
                System.out.println("pathPix:"+pathPix+"url:"+uploadUrl);
                if(uploadUrl!=null){
                    String newName = FileUtil.resizeForEqualImg(new File(pathPix+uploadUrl), 50, 50, true);
                }
                //uploadUrl = uploadUrl.replace(uploadUrl.substring(uploadUrl.lastIndexOf("/")+1), uploadUrl);
            } catch (MyFileUploadException e) {
                e.printStackTrace();
            }
        cmsCategory.setClassifyImage(uploadUrl);
        colunmService.saveColumnClassify(cmsCategory);
    }
 
    /**
     * 删除栏目
     */
    @Override
    public void deleteColumnClassify(String id) {
        colunmService.deleteColumnClassify(id);
    }
 
    @Override
    public Map queryColunmById(String id) {
        return colunmService.queryColunmById(id);
    }
 
    /**
     * 更新栏目
     */
    @Override
    public void updateColunm(CmsCategory cmsCategory,HttpServletRequest request) {
        String[] allowType =  new String[]{"gif","jpg","jpeg","png"};
        String uploadUrl = new String();
        try {
            
            uploadUrl = FileUtil.uploadFile4SpringMVC(request, "classifyimage" ,"/upload/classify",allowType);
            if(null!=uploadUrl){
                cmsCategory.setClassifyImage(uploadUrl);
            }
        
        } catch (MyFileUploadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        colunmService.updateColunm(cmsCategory);
    }
 
    @Override
    public int queryClassifyCount(String pId) {
        StringBuilder builder = new StringBuilder("SELECT COUNT(ID) FROM CMS_CATEGORY  WHERE USINGSTATE = 1 ");
        Map paramMap = new HashMap();
        if(StringUtil.notEmpty(pId)) {
            builder.append(" AND UP_ID = :pId ");
            paramMap.put("pId", pId);
        } else {
            builder.append(" AND LEVEL = 1 ");
        }
        
        int count = baseDao.queryForInteger(builder.toString(),paramMap);
        
        return count;
    }
 
    @Override
    public PageInfo queryClassifyData(PageInfo pageInfo,String pId) {
        StringBuilder builder = new StringBuilder("SELECT * FROM CMS_CATEGORY  WHERE USINGSTATE = 1 ");
        Map paramMap = new HashMap();
        if(StringUtil.notEmpty(pId)) {
            builder.append(" AND UP_ID = :pId ");
            paramMap.put("pId", pId);
        } else {
            builder.append(" AND LEVEL = 1 ");
        }
        
        builder.append(" ORDER BY LEVEL,ORDERNUM ");
        
        PageInfo info = baseDao.queryforSplitPageInfo(pageInfo, builder.toString(), paramMap);
        
        return info;
    }
 
    @Override
    public List<Map> queryColumnTree(HttpServletRequest request) {
        Map paramMap = new HashMap();
        String selectSubSql = "SELECT * FROM CMS_CATEGORY WHERE USINGSTATE = 1 ORDER BY LEVEL,ORDERNUM ";
        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("LEVEL").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("UP_ID").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("UP_ID")){
                    String pId = map.get("UP_ID").toString();
                    if(ejgnCache.containsKey(pId)) {
                        Map ejgnMap = ejgnCache.get(map.get("UP_ID").toString());
                        List<Map> list = (List<Map>)ejgnMap.get("sjTree");
                        list.add(map);
                    }
                }
            }
        }
        System.out.println(JsonUtil.list2Json(resultList));
        return resultList;
    }
 
    @Override
    public Map deleteClassify(String id) {
        String sql = "SELECT COUNT(ID) FROM CMS_CATEGORY WHERE UP_ID = :up_id ";
        Map param = new HashMap();
        param.put("up_id", id);
        int count = baseDao.queryForInteger(sql, param);
        
        String firstCate = new String();
        String secondCate = new String();
        CMS_CATEGORY cate = new CMS_CATEGORY(id).getInstanceById();
        String sjbh = ConvertUtil.obj2StrBlank(cate.getUp_id());
        if(StringUtil.notEmpty(sjbh)) {
            CMS_CATEGORY pcate = new CMS_CATEGORY(sjbh).getInstanceById();
            int level = pcate.getLevel();
            if(level==2) {
                firstCate = ConvertUtil.obj2StrBlank(pcate.getUp_id());
                secondCate = pcate.getId();
            } else {
                firstCate = pcate.getId();
            }
        }
        Map result = new HashMap();
        if(count > 0){
            result.put("msg", "存在子分类,不能删除");
        }else{
            cate.setUsingstate(2).update();
            result.put("msg", "1");
        }
        result.put("firstCate", firstCate);
        result.put("secondCate", secondCate);
        return result;
    }
 
    
}