/
zj
2025-05-02 9102aa7e0b42ce5b9667fa3b67fede889df60fc0
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
package project.web.admin.controller.user;
 
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
import kernel.exception.BusinessException;
import kernel.util.StringUtils;
import kernel.web.Page;
import kernel.web.PageActionSupport;
import project.Constants;
import project.party.PartyService;
import project.party.model.Party;
import project.party.model.UserRecom;
import project.web.admin.service.user.AdminUserRecomService;
import security.internal.SecUserService;
 
/**
 * 推荐关系
 */
@RestController
public class AdminUserRecomController extends PageActionSupport {
 
    private Logger logger = LoggerFactory.getLogger(AdminUserRecomController.class);
 
    @Autowired
    private AdminUserRecomService adminUserRecomService;
    @Autowired
    private PartyService partyService;
    @Autowired
    private SecUserService secUserService;
    
    private final String action = "normal/adminUserRecomAction!";
 
    /**
     * 获取用户推荐列表
     */
    @RequestMapping(action + "list.action")
    public ModelAndView list(HttpServletRequest request) {
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        String query_username2 = request.getParameter("query_username2");
        String query_username = request.getParameter("query_username");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user_recom");
 
        int pageNo = 1;
        int pageSize = 20;
        Page page = null;
        try {
            
            pageNo = this.checkAndSetPageNo(request.getParameter("pageNo"));
 
            page = this.adminUserRecomService.pagedQuery(pageNo, pageSize, query_username2,
                    query_username, this.getLoginPartyId());
 
            List<Map> list = page.getElements();
            for (int i = 0; i < list.size(); i++) {
                Map map = list.get(i);
                
                if (null == map.get("rolename")) {
                    map.put("roleNameDesc", "");
                } else {
                    String roleName = map.get("rolename").toString();
                    map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
                }
            }
            
            modelAndView.addObject("tabs", this.bulidTabs());
            modelAndView.addObject("result", this.result);
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            return modelAndView;
        }
 
        modelAndView.addObject("pageNo", pageNo);
        modelAndView.addObject("pageSize", pageSize);
        modelAndView.addObject("page", page);
        modelAndView.addObject("message", message);
        modelAndView.addObject("error", error);
        modelAndView.addObject("query_username2", query_username2);
        modelAndView.addObject("query_username", query_username);
        return modelAndView;
    }
 
    /**
     * 修改用户推荐 页面
     */
    @RequestMapping(action + "toUpdate.action")
    public ModelAndView toUpdate(HttpServletRequest request) {
        String id = request.getParameter("id");
        String username = request.getParameter("username");
        String name_para = request.getParameter("name_para");
        String partyId = request.getParameter("partyId");
        
        ModelAndView modelAndView = new ModelAndView();
 
        try {
 
            String reco_username = "";
            String reco_usercode = "";
            
            UserRecom userRecom = this.adminUserRecomService.get(id);            
            if (userRecom != null) {
                username = this.secUserService.findUserByPartyId(userRecom.getPartyId()).getUsername();
                reco_username = this.secUserService.findUserByPartyId(userRecom.getReco_id()).getUsername();
                reco_usercode = this.partyService.cachePartyBy(userRecom.getReco_id(), true).getUsercode();
            }
 
            modelAndView.addObject("id", id);
            modelAndView.addObject("username", username);
            modelAndView.addObject("reco_username", reco_username);
            modelAndView.addObject("reco_usercode", reco_usercode);
            modelAndView.addObject("name_para", name_para);
            modelAndView.addObject("partyId", partyId);
            
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        }
        
        modelAndView.setViewName("user_recom_update");
        return modelAndView;
    }
 
    /**
     * 修改用户推荐
     */
    @RequestMapping(action + "update.action")
    public ModelAndView update(HttpServletRequest request) {
        String id = request.getParameter("id");
        String username = request.getParameter("username");
        String reco_username = request.getParameter("reco_username");
        String reco_usercode = request.getParameter("reco_usercode");
        String name_para = request.getParameter("name_para");
        String parent_usercode = request.getParameter("parent_usercode");
        String partyId = request.getParameter("partyId");        
        String login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            
            if (!StringUtils.isNotEmpty(parent_usercode)) {
                throw new BusinessException("新推荐人UID不能为空");
            }
            
            Party party = this.partyService.cachePartyBy(partyId, false);
            if (Constants.SECURITY_ROLE_TEST.equals(party.getRolename())) {
                throw new BusinessException("试用用户无法修改推荐关系");
            }
            
            Party par = this.partyService.findPartyByUsercode(parent_usercode);
            if (null == par) {
                throw new BusinessException("推荐人UID不存在");
            }
            
            if (Constants.SECURITY_ROLE_TEST.equals(par.getRolename())) {
                throw new BusinessException("试用用户无法成为推荐人");
            }
            
            String parent_username = par.getUsername();
            this.adminUserRecomService.update(partyId, parent_username, this.getUsername_login(), this.getIp(),
                    login_safeword);
            
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.addObject("id", id);
            modelAndView.addObject("username", username);
            modelAndView.addObject("reco_username", reco_username);
            modelAndView.addObject("reco_usercode", reco_usercode);
            modelAndView.addObject("name_para", name_para);
            modelAndView.addObject("parent_usercode", parent_usercode);
            modelAndView.addObject("partyId", partyId);
            modelAndView.addObject("login_safeword", login_safeword);
            modelAndView.setViewName("user_recom_update");
            return modelAndView;
        } catch (Throwable t) {
            modelAndView.addObject("error", t.getMessage());
            modelAndView.addObject("id", id);
            modelAndView.addObject("username", username);
            modelAndView.addObject("reco_username", reco_username);
            modelAndView.addObject("reco_usercode", reco_usercode);
            modelAndView.addObject("name_para", name_para);
            modelAndView.addObject("parent_usercode", parent_usercode);
            modelAndView.addObject("partyId", partyId);
            modelAndView.addObject("login_safeword", login_safeword);
            modelAndView.setViewName("user_recom_update");
            return modelAndView;
        }
        
        modelAndView.addObject("message", "修改成功");
        modelAndView.setViewName("redirect:/" + action + "list.action");
        return modelAndView;
    }
 
}