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 params = new HashMap(); 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"; } }