zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
package com.shlanbao.tzsc.pms.sys.wctMenu.service.impl;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.shlanbao.tzsc.utils.tools.BeanConvertor;
import com.shlanbao.tzsc.utils.tools.FillUserInfoUtil;
import com.shlanbao.tzsc.utils.tools.LogAnno;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.shlanbao.tzsc.base.dao.WCTMenuDaoI;
import com.shlanbao.tzsc.base.mapping.WCTMenu;
import com.shlanbao.tzsc.base.model.Json;
import com.shlanbao.tzsc.base.model.Tree;
import com.shlanbao.tzsc.base.service.BaseService;
import com.shlanbao.tzsc.pms.sys.wctMenu.service.WctMenuServiceI;
import com.shlanbao.tzsc.utils.tools.StringUtil;
 
import javax.servlet.http.HttpServletRequest;
 
@Service
public class WctMenuServiceImpl extends BaseService implements WctMenuServiceI {
    @Autowired
    private WCTMenuDaoI wctMenuDaoI;
    @Autowired
    private HttpServletRequest request;
    /**
     * 加载wct菜单.顶部菜单UPID=top   左侧主菜单UPID=root  左侧子菜单 UPID=数字
    * <p>Description: </p>
    * @author shisihai
    * @date 2016下午4:53:17
    */
    @Override
    public List<Tree> loadTroubleTree(String id) {
        List<Tree> wctMenuTree=new ArrayList<>();
        try{
            Tree topTree=null;//顶部菜单
            Tree leftTree=null;//左侧主菜单
            Object params=null;
            List<WCTMenu> topResult=null;//顶部
            List<WCTMenu> leftResult=null;//左侧
            List<WCTMenu> lowResult=null;//左侧子菜单
            //初始化时,加载顶部菜单
            if(!StringUtil.notEmpty(id)){
                params="top";
                String hql="from WCTMenu o where o.upId=? order by o.grade asc";
                topResult=wctMenuDaoI.query(hql, params);
                //加载左侧主菜单
                for (WCTMenu topMenu : topResult) {
                    topTree=setTreeVal(topMenu);
                    params=topMenu.getModul();
                    hql="from WCTMenu o where o.modul=? and o.upId=? order by o.grade asc";
                    leftResult=wctMenuDaoI.query(hql, params,"root");
                    List<Tree> leftTrees=new ArrayList<>();
                    //加载左侧子菜单
                    for (WCTMenu leftMenu : leftResult) {
                        leftTree=setTreeVal(leftMenu);
                        hql="from WCTMenu o where o.modul=? and o.upId=? order by o.grade asc";
                        lowResult=wctMenuDaoI.query(hql, params,leftMenu.getId());
                        leftTree.setChildren(setChildTrees(lowResult));
                        leftTrees.add(leftTree);
                    }
                    topTree.setChildren(leftTrees);
                    wctMenuTree.add(topTree);
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return wctMenuTree;
    }
    /**
     * 将wct菜单封装tree
    * <p>Description: </p>
    * @author shisihai
    * @date 2016上午8:38:55
     */
    private Tree setTreeVal(WCTMenu menu){
            Tree tree=new Tree();
            Map<String,Object> attrs=new HashMap<>();
            tree.setId(menu.getId());
            tree.setSeq((long)menu.getGrade());
            tree.setPid(menu.getUpId());
            tree.setText(menu.getMenu_title());
            //自定义属性
            attrs.put("menuUrl", menu.getMenu_url());
            attrs.put("modul", menu.getModul());
            attrs.put("imgPath", menu.getImgPath());
            attrs.put("menuType", menu.getType());
            attrs.put("del", menu.getDel());
            attrs.put("attr1", menu.getAttr1());
            attrs.put("attr2", menu.getAttr2());
            attrs.put("attr3", menu.getAttr3());
            attrs.put("attr4", menu.getAttr4());
            tree.setAttributes(attrs);
            return tree;
    }
    
    private List<Tree> setChildTrees(List<WCTMenu> menus){
        List<Tree> trees=new ArrayList<>();
        if(menus!=null && menus.size()>0){
            for (WCTMenu menu : menus) {
                trees.add(setTreeVal(menu));
            }
        }
        return trees;
    }
    /**
     * 根据id查询wct菜单
    * <p>Description: </p>
    * @author shisihai
    * @date 2016下午1:31:17
    */
    @Override
    public WCTMenu queryMenuById(String id) {
        return wctMenuDaoI.findById(WCTMenu.class, id);
    }
    
    /**
     * 修改WCT菜单
    * <p>Description: </p>
    * @author shisihai
    * @date 2016下午1:36:18
    */
    @LogAnno(operateType = "修改WCT菜单")
    @Override
    public Json editWctMenu(WCTMenu menu) {
        Json json=new Json();
        try {
            WCTMenu wctMenu = wctMenuDaoI.findById(WCTMenu.class, menu.getId());
            BeanConvertor.copyProperties(menu,wctMenu);
            FillUserInfoUtil.fillUpdateUserInfo(wctMenu,request);
            wctMenuDaoI.saveOrUpdate(wctMenu);
            json.setSuccess(true);
            json.setMsg("修改菜单成功!");
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("修改菜单失败!");
        }
        return json;
    }
    /**
     * 新增菜单
    * <p>Description: </p>
    * @author shisihai
    * @date 2016下午1:40:59
    */
    @LogAnno(operateType = "新增菜单")
    @Override
    public Json addWctMenu(WCTMenu menu) {
        Json json=new Json();
        try {
            WCTMenu m=wctMenuDaoI.findById(WCTMenu.class, menu.getId());
            if(m!=null){
                json.setMsg("新增菜单失败!id重复!");
                return json;
            }
            FillUserInfoUtil.fillCreateUserInfo(menu,request);
            wctMenuDaoI.save(menu);
            json.setSuccess(true);
            json.setMsg("新增菜单成功!");
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("新增菜单失败!");
        }
        return json;
    }
    
}