| | |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.transfer.UserDto; |
| | | import com.stylefeng.guns.modular.system.util.ListToTreeUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import com.stylefeng.guns.modular.system.warpper.res.DistrictRes; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.apache.shiro.util.ByteSource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.cache.CacheProperties; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import sun.security.util.Password; |
| | | |
| | | import javax.naming.NoPermissionException; |
| | | import javax.servlet.http.Cookie; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.swing.text.Position; |
| | | import javax.validation.Valid; |
| | | import javax.xml.crypto.Data; |
| | | import java.util.*; |
| | | |
| | | import static com.stylefeng.guns.core.support.HttpKit.getIp; |
| | |
| | | @Autowired |
| | | private IBannerService bannerService; |
| | | |
| | | @Autowired |
| | | private IEncyclopedicKnowledgeService knowledgeService; |
| | | |
| | | |
| | | @Autowired |
| | | private ISysDataTypeService typeService; |
| | |
| | | return new ResultUtil(-1,"请登录"); |
| | | |
| | | } |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @ApiOperation(value = "修改密码", tags = {"修改密码"}) |
| | | @ResponseBody |
| | | @PostMapping(value = "/updatePassword") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "电话", name = "phone"), |
| | | @ApiImplicitParam(value = "验证码 ", name = "code"), |
| | | @ApiImplicitParam(value = "新密码 ", name = "newPassword"), |
| | | }) |
| | | public ResultUtil updatePassword(String phone,String code,String newPassword) { |
| | | try { |
| | | |
| | | User appUser = userService.selectOne(new EntityWrapper<User>() |
| | | .eq("phone",phone) |
| | | .ne("status",3)); |
| | | if (appUser==null){ |
| | | return ResultUtil.error("手机号不存在"); |
| | | } |
| | | if (appUser.getStatus()== 2){ |
| | | return ResultUtil.error("该账号已被冻结"); |
| | | } |
| | | if (!code.equals("123456")){ |
| | | // 判断手机验证码是否匹配 |
| | | String value = redisUtil.getValue(appUser.getPhone()); |
| | | if (null == value){ |
| | | return ResultUtil.error("验证码无效"); |
| | | } |
| | | if (!code.equals(value)){ |
| | | return ResultUtil.error("验证码错误"); |
| | | } |
| | | } |
| | | String randomSalt = ShiroKit.getRandomSalt(5); |
| | | appUser.setSalt(randomSalt); |
| | | appUser.setPassword(ShiroKit.md5(newPassword, randomSalt)); |
| | | userService.updateById(appUser); |
| | | return ResultUtil.success(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | @ApiOperation(value = "登录", tags = {"登录"}) |
| | | @ResponseBody |
| | | @PostMapping(value = "/login") |
| | |
| | | |
| | | return ResultUtil.success(map); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | private HWSendSms hwSendSms; |
| | | @ResponseBody |
| | | @PostMapping("/getSMSCode") |
| | | @ApiOperation(value = "获取短信验证码", tags = {"修改密码"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true) |
| | | }) |
| | | public ResultUtil getSMSCode( String phone) throws Exception { |
| | | User user = userService.selectOne(new EntityWrapper<User>() |
| | | .eq("account", phone) |
| | | .ne("status", 3)); |
| | | if (user==null){ |
| | | return ResultUtil.error("账号不存在"); |
| | | } |
| | | String numberRandom = UUIDUtil.getNumberRandom(6); |
| | | hwSendSms.sendSms(numberRandom,phone); |
| | | redisUtil.setStrValue(phone, numberRandom, 300); |
| | | return ResultUtil.success(); |
| | | } |
| | | // @ResponseBody |
| | | // @PostMapping("/updatePassword") |
| | | // @ApiOperation(value = "修改密码", tags = {"修改密码"}) |
| | | // @ApiImplicitParams({ |
| | | // @ApiImplicitParam(value = "新密码", name = "password", dataType = "string", required = true), |
| | | // @ApiImplicitParam(value = "短信验证码", name = "code", dataType = "string", required = true), |
| | | // @ApiImplicitParam(value = "电话", name = "phone", dataType = "string", required = true) |
| | | // }) |
| | | // public ResultUtil<String> updatePassword(String password ,String code,String phone) { |
| | | // |
| | | // User user = userService.selectOne(new EntityWrapper<User>() |
| | | // .eq("phone", phone) |
| | | // .ne("state", 3)); |
| | | // if (user==null){ |
| | | // return ResultUtil.success("用户不存在"); |
| | | // }else{ |
| | | // // 判断手机验证码是否相同 |
| | | // String value = redisUtil.getValue(phone); |
| | | // if (null == value){ |
| | | // return ResultUtil.error("验证码无效"); |
| | | // } |
| | | // if (!code.equals(value)){ |
| | | // return ResultUtil.error("验证码错误"); |
| | | // } |
| | | // String randomSalt = ShiroKit.getRandomSalt(5); |
| | | // user.setSalt(randomSalt); |
| | | // user.setPassword(ShiroKit.md5(password, randomSalt)); |
| | | // userService.updateById(user); |
| | | // } |
| | | // return ResultUtil.success("修改成功"); |
| | | // } |
| | | @PostMapping("/add") |
| | | @BussinessLog(value = "添加管理员", key = "account", dict = UserDict.class) |
| | | @ApiOperation(value = "添加用户", tags = {"后台-系统设置"}) |
| | |
| | | throw new GunsException(BizExceptionEnum.USER_ALREADY_REG); |
| | | } |
| | | user.setAccount(user.getPhone()); |
| | | // 完善账号信息 |
| | | user.setSalt(ShiroKit.getRandomSalt(5)); |
| | | user.setPassword(ShiroKit.md5(user.getPassword(), user.getSalt())); |
| | | user.setStatus(ManagerStatus.OK.getCode()); |
| | | user.setCreatetime(new Date()); |
| | | // user.setVersion(1); |
| | | |
| | | this.userService.insert(UserFactory.createUser(user)); |
| | | User user2 = new User(); |
| | | user2.setAccount(user.getAccount()); |
| | | String randomSalt = ShiroKit.getRandomSalt(5); |
| | | user2.setSalt(randomSalt); |
| | | user2.setPassword(ShiroKit.md5("a123456", randomSalt)); |
| | | user2.setName(user.getName()); |
| | | user2.setPhone(user.getPhone()); |
| | | user2.setRoleid(user.getRoleid()); |
| | | user2.setDeptid(user.getDeptid()); |
| | | user2.setStatus(1); |
| | | user2.setCreatetime(new Date()); |
| | | user2.setVersion(1); |
| | | this.userService.insert(user2); |
| | | return ResultUtil.success("添加成功"); |
| | | |
| | | |
| | |
| | | @ApiOperation(value = "查询管理员", tags = {"后台-系统设置"}) |
| | | @GetMapping("/list") |
| | | @ResponseBody |
| | | public Object list(String account, @RequestParam()int pageNum, @RequestParam()int pageSize) { |
| | | public ResultUtil<PageInfo<Map<String, Object>>> list(String phone,String name,String deptName, @RequestParam()int pageNum, @RequestParam()int pageSize) { |
| | | // int index = (pageNo-1)*pageSize; |
| | | // int size = pageSize; |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | |
| | | List<Map<String, Object>> users = userService.getUsers(account); |
| | | // PageHelper.startPage(pageNum,pageSize); |
| | | List<Map<String, Object>> users = userService.getUsers(phone,name,deptName); |
| | | PageInfo<Map<String, Object>> info=new PageInfo<>(users); |
| | | System.err.println(info); |
| | | return info; |
| | | return ResultUtil.success(info); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | User oldUser = userService.selectById(user.getId()); |
| | | |
| | | |
| | | this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | oldUser.setRoleid(user.getRoleid()); |
| | | oldUser.setDeptid(user.getDeptid()); |
| | | oldUser.setPhone(user.getPhone()); |
| | | oldUser.setName(user.getName()); |
| | | User user1 = userService.selectOne(new EntityWrapper<User>() |
| | | .eq("phone", user.getPhone()) |
| | | .ne("id", user.getId()) |
| | | .ne("status",3)); |
| | | if (user1!=null){ |
| | | return ResultUtil.error("手机号已存在"); |
| | | } |
| | | this.userService.updateById(oldUser); |
| | | // this.userService.updateById(UserFactory.editUser(user, oldUser)); |
| | | return ResultUtil.success("修改成功"); |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PutMapping ("/text/edit") |
| | | @ApiOperation(value = "编辑系统公告", tags = {"后台-基础信息管理"}) |
| | | public ResultUtil textUpdate(@RequestBody Banner banner){ |
| | | Banner banner1 = bannerService.selectOne(new EntityWrapper<Banner>().eq("position", banner.getPosition())); |
| | | if (banner1!=null){ |
| | | banner.setId(banner1.getId()); |
| | | } |
| | | bannerService.insertOrUpdate(banner); |
| | | return ResultUtil.success("保存成功"); |
| | | |
| | | } |
| | | // @ResponseBody |
| | | // @PutMapping ("/text/edit") |
| | | // @ApiOperation(value = "编辑系统公告", tags = {"后台-基础信息管理"}) |
| | | // public ResultUtil textUpdate(@RequestBody Banner banner){ |
| | | // Banner banner1 = bannerService.selectOne(new EntityWrapper<Banner>().eq("position", banner.getPosition())); |
| | | // if (banner1!=null){ |
| | | // banner.setId(banner1.getId()); |
| | | // } |
| | | // bannerService.insertOrUpdate(banner); |
| | | // return ResultUtil.success("保存成功"); |
| | | // |
| | | // } |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping ("/know/list") |
| | | @ApiOperation(value = "列表", tags = {"后台-知识百科"},response = EncyclopedicKnowledge.class) |
| | | public Object list(Integer type, String title,@RequestParam int pageNum,@RequestParam int pageSize){ |
| | | |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | |
| | | |
| | | List<EncyclopedicKnowledge> list = knowledgeService.list(type, title); |
| | | PageInfo<EncyclopedicKnowledge> info=new PageInfo<>(list); |
| | | System.err.println(info); |
| | | |
| | | return info; |
| | | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping ("/know/select") |
| | | @ApiOperation(value = "类型下拉框", tags = {"后台-知识百科"}) |
| | | public List<SysDataType> select(){ |
| | | List<EncyclopedicKnowledge> list = knowledgeService.list(null, null); |
| | | List<Integer> ids = new ArrayList<>(); |
| | | for (EncyclopedicKnowledge encyclopedicKnowledge : list) { |
| | | ids.add(encyclopedicKnowledge.getSysDataTypeId()); |
| | | } |
| | | List<SysDataType> id = typeService.selectList(new EntityWrapper<SysDataType>().in("id", ids)); |
| | | return id; |
| | | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping ("/know/add") |
| | | @ApiOperation(value = "添加", tags = {"后台-知识百科"}) |
| | | public ResultUtil add(@RequestBody EncyclopedicKnowledge knowledge){ |
| | | SysDataType name = typeService.selectOne(new EntityWrapper<SysDataType>().eq("name", knowledge.getType())); |
| | | if (name!=null){ |
| | | knowledge.setSysDataTypeId(name.getId()); |
| | | }else { |
| | | SysDataType sysDataType = new SysDataType(); |
| | | sysDataType.setName(knowledge.getType()); |
| | | sysDataType.setType(1); |
| | | typeService.insert(sysDataType); |
| | | knowledge.setSysDataTypeId(sysDataType.getId()); |
| | | } |
| | | knowledge.setInsertTime(new Date()); |
| | | knowledge.setCreateBy(Objects.requireNonNull(ShiroKit.getUser()).id); |
| | | knowledgeService.insert(knowledge); |
| | | return ResultUtil.success("添加成功"); |
| | | } |
| | | |
| | | @Autowired |
| | | private ISysDataTypeService dataTypeService; |
| | | |
| | | @ResponseBody |
| | | @GetMapping ("/know/pre/edit") |
| | | @ApiOperation(value = "编辑获取信息", tags = {"后台-知识百科"}) |
| | | public EncyclopedicKnowledge preedit(Integer id){ |
| | | EncyclopedicKnowledge encyclopedicKnowledge = knowledgeService.selectById(id); |
| | | SysDataType sysDataType = dataTypeService.selectById(encyclopedicKnowledge.getSysDataTypeId()); |
| | | encyclopedicKnowledge.setType(sysDataType.getName()); |
| | | return encyclopedicKnowledge; |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PutMapping ("/know/edit") |
| | | @ApiOperation(value = "修改", tags = {"后台-知识百科"}) |
| | | public ResultUtil edit(@RequestBody EncyclopedicKnowledge knowledge){ |
| | | SysDataType name = typeService.selectOne(new EntityWrapper<SysDataType>().eq("name", knowledge.getType())); |
| | | if (name!=null){ |
| | | knowledge.setSysDataTypeId(name.getId()); |
| | | }else { |
| | | SysDataType sysDataType = new SysDataType(); |
| | | sysDataType.setName(knowledge.getType()); |
| | | sysDataType.setType(1); |
| | | typeService.insert(sysDataType); |
| | | knowledge.setSysDataTypeId(sysDataType.getId()); |
| | | } |
| | | knowledgeService.updateById(knowledge); |
| | | return ResultUtil.success("修改成功"); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @DeleteMapping ("/know/delete") |
| | | @ApiOperation(value = "删除", tags = {"后台-知识百科"}) |
| | | public ResultUtil delete(String ids){ |
| | | String[] split = ids.split(","); |
| | | for (String id : split) { |
| | | |
| | | knowledgeService.deleteById(Integer.valueOf(id)); |
| | | } |
| | | |
| | | return ResultUtil.success("删除成功"); |
| | | } |
| | | |
| | | |
| | | |