package com.javaweb.platform.controller; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.javaweb.common.annotation.Log; import com.javaweb.common.config.ServerConfig; import com.javaweb.common.enums.BusinessType; import com.javaweb.common.json.JSON; import com.javaweb.platform.constant.FrontUserStatus; import com.javaweb.platform.domain.FrontUser; import com.javaweb.platform.domain.UserMsg; import com.javaweb.platform.service.IFrontUserService; import com.javaweb.platform.service.IUserMsgService; import com.javaweb.platform.utils.ValidcodeUtils; import com.javaweb.common.core.controller.BaseController; import com.javaweb.common.core.domain.AjaxResult; import com.javaweb.common.utils.StringUtils; import com.javaweb.common.utils.poi.ExcelUtil; import com.javaweb.common.core.page.TableDataInfo; /** * 用户管理Controller * * @author zmk * @date 2022-03-21 */ @Controller @RequestMapping("/platform/frontuser") public class FrontUserController extends BaseController { private String prefix = "platform/frontuser"; @Autowired private IFrontUserService frontUserService; @Autowired private IUserMsgService userMsgService; @Autowired private ValidcodeUtils validcodeUtils; @RequiresPermissions("platform:frontuser:view") @GetMapping() public String frontuser() { return prefix + "/frontuser"; } /** * 查询用户管理列表 */ @RequiresPermissions("platform:frontuser:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(FrontUser frontUser) { startPage(); List list = frontUserService.selectFrontUserList(frontUser); return getDataTable(list); } /** * 导出用户管理列表 */ @RequiresPermissions("platform:frontuser:export") @Log(title = "用户管理", businessType = BusinessType.EXPORT) @PostMapping("/export") @ResponseBody public AjaxResult export(FrontUser frontUser) { List list = frontUserService.selectFrontUserList(frontUser); ExcelUtil util = new ExcelUtil(FrontUser.class); return util.exportExcel(list, "frontuser"); } /** * 新增用户管理 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存用户管理 */ @RequiresPermissions("platform:frontuser:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(FrontUser frontUser) { return toAjax(frontUserService.insertFrontUser(frontUser)); } @Autowired private ServerConfig serverConfig; /** * 修改用户管理 * @throws Exception */ @GetMapping("/edit/{id}") public String edit(@PathVariable("id") Long id, ModelMap mmap) throws Exception { FrontUser frontUser = frontUserService.selectFrontUserById(id); mmap.put("frontUser", frontUser); List list=new ArrayList<>(); String files =frontUser.getApplyLicense(); if(!StringUtils.isEmpty(files)){ List fList= JSON.unmarshal(files, List.class); for (String str : fList) { String addr = serverConfig.getUrl() + str; list.add(addr); } } mmap.put("files", list); return prefix + "/edit"; } /** * 修改保存用户管理 */ @RequiresPermissions("platform:frontuser:edit") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(FrontUser frontUser) { return toAjax(frontUserService.updateFrontUser(frontUser)); } /** * 驳回的页面 * @param mmap * @return * @throws Exception */ @GetMapping("/reject") public String rejct(String id, ModelMap mmap) throws Exception { FrontUser frontUser = frontUserService.selectFrontUserById(Long.parseLong(id)); mmap.put("frontUser", frontUser); return prefix + "/reject"; } /** * 驳回申请信息保存和发送 * @param frontUser * @return * @throws Exception */ @PostMapping("/rejectSave") @ResponseBody public AjaxResult rejctSave(FrontUser frontUser) throws Exception { //更新状态 frontUser.setStatus(FrontUserStatus.REJECT.getCode()); frontUserService.updateFrontUser(frontUser); //保存消息 FrontUser user =frontUserService.selectFrontUserById(frontUser.getId()); UserMsg userMsg = new UserMsg(); userMsg.setUserName(user.getUserName()); userMsg.setCreateDate(new Date()); userMsg.setMsg(frontUser.getRemark()); userMsgService.insertUserMsg(userMsg); //发送短信 try{ System.out.println(System.currentTimeMillis()); validcodeUtils.sendMesgToPhone("4", user.getPhone()); System.out.println(System.currentTimeMillis()); }catch(Exception e){ return AjaxResult.warn("发送短信失败"); } return AjaxResult.success("已驳回申请,并且发送了短信提醒"); } /** * 审核通过并且发送短信 * @param ids * @return */ @PostMapping("/approve") @ResponseBody public AjaxResult approve(String ids){ String [] idArray=ids.split(","); for(String id : idArray){ FrontUser frontUser=new FrontUser(); frontUser.setId(Integer.valueOf(id).longValue()); frontUserService.approve(frontUser); } for(String id : idArray){ FrontUser frontUser =frontUserService.selectFrontUserById(Long.parseLong(id)); UserMsg userMsg = new UserMsg(); userMsg.setUserName(frontUser.getUserName()); userMsg.setCreateDate(new Date()); userMsg.setMsg("您的注册申请审核已通过,欢迎使用平台进行查询服务"); userMsgService.insertUserMsg(userMsg); //发送短信 try{ validcodeUtils.sendMesgToPhone("3", frontUser.getPhone()); }catch(Exception e){ logger.error(e.toString()); continue; } } //发送短信 return AjaxResult.success("账号审核通过,已经发送信息提醒!"); } /** * 删除用户管理 */ @RequiresPermissions("platform:frontuser:remove") @Log(title = "用户管理", businessType = BusinessType.DELETE) @PostMapping( "/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(frontUserService.deleteFrontUserByIds(ids)); } }