付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
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
package com.wgcloud.controller;
 
import com.github.pagehelper.PageInfo;
import com.wgcloud.entity.AccountInfo;
import com.wgcloud.service.AccountInfoService;
import com.wgcloud.service.LogInfoService;
import com.wgcloud.util.MD5Utils;
import com.wgcloud.util.PageUtil;
import com.wgcloud.util.staticvar.StaticKeys;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @version v3.3
 * @ClassName:AccountInfoController.java
 * @author: http://www.wgstart.com
 * @date: 2022年6月6日
 * @Description: 用户账号管理信息
 * @Copyright: 2019-2022 wgcloud. All rights reserved.
 */
@Controller
@RequestMapping("/accountInfo")
public class AccountInfoController {
 
 
    private static final Logger logger = LoggerFactory.getLogger(AccountInfoController.class);
 
 
    @Resource
    private AccountInfoService accountInfoService;
    @Resource
    private LogInfoService logInfoService;
 
 
    /**
     * 根据条件查询AccountInfo信息列表
     *
     * @param accountInfo
     * @param model
     * @return
     */
    @RequestMapping(value = "list")
    public String AccountInfoList(AccountInfo accountInfo, Model model, HttpServletRequest request) {
        String errorMsg = "查询成员账号信息错误";
 
        Map<String, Object> params = new HashMap<String, Object>();
        try {
            PageInfo pageInfo = accountInfoService.selectByParams(params, Integer.valueOf(accountInfo.getPage()), Integer.valueOf(accountInfo.getPageSize()));
            PageUtil.initPageNumber(pageInfo, model);
            model.addAttribute("page", pageInfo);
            model.addAttribute("pageUrl", "/accountInfo/list?1=1");
            model.addAttribute("accountInfo", accountInfo);
        } catch (Exception e) {
            logger.error(errorMsg, e);
            logInfoService.save(errorMsg, e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "accountInfo/list";
    }
 
    /**
     * 单独修改密码
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "editPasswd")
    public String editPasswd(Model model, HttpServletRequest request) {
        String errorMsg = "修改成员密码错误";
 
        String id = request.getParameter("id");
        AccountInfo accountInfo = new AccountInfo();
        try {
            accountInfo = accountInfoService.selectById(id);
            model.addAttribute("accountInfo", accountInfo);
        } catch (Exception e) {
            logger.error(errorMsg, e);
            logInfoService.save(errorMsg, e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "accountInfo/passwd";
    }
 
 
    /**
     * 添加/修改
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "edit")
    public String edit(Model model, HttpServletRequest request) {
        String errorMsg = "添加成员账号信息错误";
 
        String id = request.getParameter("id");
        AccountInfo accountInfo = new AccountInfo();
        try {
            if (StringUtils.isEmpty(id)) {
                model.addAttribute("accountInfo", accountInfo);
 
                return "accountInfo/add";
            }
            accountInfo = accountInfoService.selectById(id);
            model.addAttribute("accountInfo", accountInfo);
        } catch (Exception e) {
            logger.error(errorMsg, e);
            logInfoService.save(errorMsg, e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "accountInfo/add";
    }
 
    /**
     * 保存用户信息
     *
     * @param AccountInfo
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "save")
    public String saveAccountInfo(AccountInfo AccountInfo, Model model, HttpServletRequest request) {
 
        if (!StringUtils.isEmpty(AccountInfo.getPasswd())) {
            AccountInfo.setPasswd(MD5Utils.GetMD5Code(AccountInfo.getPasswd()));
        }
        try {
            if (StringUtils.isEmpty(AccountInfo.getId())) {
                accountInfoService.save(AccountInfo);
                accountInfoService.saveLog(request, StaticKeys.LOG_ADD, AccountInfo);
            } else {
                accountInfoService.updateById(AccountInfo);
                accountInfoService.saveLog(request, StaticKeys.LOG_UPDATE, AccountInfo);
            }
 
        } catch (Exception e) {
            logger.error("保存成员账号信息错误:", e);
            logInfoService.save("保存成员账号信息错误", "保存成员信息错误:" + e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "redirect:/accountInfo/list";
    }
 
 
    /**
     * 删除用户
     *
     * @param model
     * @param request
     * @param redirectAttributes
     * @return
     */
    @RequestMapping(value = "del")
    public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
 
        String errorMsg = "删除成员账号错误";
        try {
            if (!StringUtils.isEmpty(request.getParameter("id"))) {
                String[] ids = request.getParameter("id").split(",");
                for (String id : ids) {
                    AccountInfo accountInfo = accountInfoService.selectById(id);
                    accountInfoService.deleteById(request.getParameter("id").split(","));
                    accountInfoService.saveLog(request, StaticKeys.LOG_DEL, accountInfo);
                }
            }
        } catch (Exception e) {
            logger.error(errorMsg, e);
            logInfoService.save(errorMsg, e.toString(), StaticKeys.LOG_XTCZ);
        }
 
        return "redirect:/accountInfo/list";
    }
 
 
}