源码获取:博客首页 "资源" 里下载!
该项目为后管系统,主要功能包括:
看板、业务机会管理、客户管理、联系人管理、我的日报、团队日报、主数据管理:组织架构管理;系统管理:用户管理、角色管理、菜单管理等;
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:是;
1. 后端:SpringBoot+mybatis
2. 前端:FreeMarker+Angular+bootstrap+echarts+jQuery
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application-powerteam.yml配置文件中的数据库配置改为自己的配置;
4. 前台访问路径:http://localhost:8080/
登录账号:admin 登录密码:admin
@Controller
@RequestMapping("admin/system/user")
public class UserController {
@Autowired
UserService userService;
@Autowired
RoleService roleService;
@Autowired
UploadService uploadService;
@RequestMapping("list")
@SysLog("跳转系统用户列表页面")
public String list(){
return "admin/user/list";
}
@RequiresPermissions("sys:user:list")
@PostMapping("list")
@ResponseBody
public PageData list(@RequestParam(value = "page",defaultValue = "1")Integer page,
@RequestParam(value = "limit",defaultValue = "10")Integer limit,
ServletRequest request){
Map map = WebUtils.getParametersStartingWith(request, "s_");
PageData userPageData = new PageData<>();
QueryWrapper userWrapper = new QueryWrapper<>();
if(!map.isEmpty()){
String type = (String) map.get("type");
if(StringUtils.isNotBlank(type)) {
userWrapper.eq("is_admin", "admin".equals(type) ? true : false);
}
String keys = (String) map.get("key");
if(StringUtils.isNotBlank(keys)) {
userWrapper.and(wrapper -> wrapper.like("login_name", keys).or().like("tel", keys).or().like("email", keys));
}
}
IPage userPage = userService.page(new Page<>(page,limit),userWrapper);
userPageData.setCount(userPage.getTotal());
userPageData.setData(userPage.getRecords());
return userPageData;
}
@RequestMapping("add")
public String add(ModelMap modelMap){
List roleList = roleService.selectAll();
modelMap.put("roleList",roleList);
return "admin/user/add";
}
@RequiresPermissions("sys:user:add")
@PostMapping("add")
@ResponseBody
@SysLog("保存新增系统用户数据")
public ResponseEntity add(@RequestBody User user){
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
if(user.getRoleLists() == null || user.getRoleLists().size() == 0){
return ResponseEntity.failure("用户角色至少选择一个");
}
if(userService.userCount(user.getLoginName())>0){
return ResponseEntity.failure("登录名称已经存在");
}
// if(StringUtils.isNotBlank(user.getEmail())){
// if(userService.userCount(user.getEmail())>0){
// return ResponseEntity.failure("该邮箱已被使用");
// }
// }
// if(StringUtils.isNoneBlank(user.getTel())){
// if(userService.userCount(user.getTel())>0){
// return ResponseEntity.failure("该手机号已被绑定");
// }
// }
//设置默认密码
if(StringUtils.isBlank(user.getPassword())){
user.setPassword(Constants.DEFAULT_PASSWORD);
}
userService.saveUser(user);
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("保存用户信息出错");
}
//保存用户角色关系
userService.saveUserRoles(user.getId(),user.getRoleLists());
return ResponseEntity.success("操作成功");
}
@RequestMapping("edit")
public String edit(String id,ModelMap modelMap){
User user = userService.findUserById(id);
String roleIds = "";
if(user != null) {
roleIds = user.getRoleLists().stream().map(role -> role.getId()).collect(Collectors.joining(","));
}
List roleList = roleService.selectAll();
modelMap.put("localuser",user);
modelMap.put("roleIds",roleIds);
modelMap.put("roleList",roleList);
return "admin/user/edit";
}
@RequiresPermissions("sys:user:edit")
@PostMapping("edit")
@ResponseBody
@SysLog("保存系统用户编辑数据")
public ResponseEntity edit(@RequestBody User user){
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("用户ID不能为空");
}
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
if(user.getRoleLists() == null || user.getRoleLists().size() == 0){
return ResponseEntity.failure("用户角色至少选择一个");
}
User oldUser = userService.findUserById(user.getId());
if(StringUtils.isNotBlank(user.getEmail())){
if(!user.getEmail().equals(oldUser.getEmail())){
if(userService.userCount(user.getEmail())>0){
return ResponseEntity.failure("该邮箱已被使用");
}
}
}
if(StringUtils.isNotBlank(user.getLoginName())){
if(!user.getLoginName().equals(oldUser.getLoginName())) {
if (userService.userCount(user.getLoginName()) > 0) {
return ResponseEntity.failure("该登录名已存在");
}
}
}
if(StringUtils.isNotBlank(user.getTel())){
if(!user.getTel().equals(oldUser.getTel())) {
if (userService.userCount(user.getTel()) > 0) {
return ResponseEntity.failure("该手机号已经被绑定");
}
}
}
user.setIcon(oldUser.getIcon());
userService.updateUser(user);
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("保存用户信息出错");
}
userService.saveUserRoles(user.getId(),user.getRoleLists());
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:lock")
@PostMapping("lock")
@ResponseBody
@SysLog("锁定或开启系统用户")
public ResponseEntity lock(@RequestParam(value = "id",required = false)String id){
if(StringUtils.isBlank(id)){
return ResponseEntity.failure("参数错误");
}
User user = userService.getById(id);
if(user == null){
return ResponseEntity.failure("用户不存在");
}
userService.lockUser(user);
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:delete")
@PostMapping("delete")
@ResponseBody
@SysLog("删除系统用户数据(单个)")
public ResponseEntity delete(@RequestParam(value = "id",required = false)String id){
if(StringUtils.isBlank(id)){
return ResponseEntity.failure("参数错误");
}
User user = userService.getById(id);
if(user == null){
return ResponseEntity.failure("用户不存在");
}else if(user.getAdminUser()) {
return ResponseEntity.failure("不能删除后台用户");
}
userService.deleteUser(user);
return ResponseEntity.success("操作成功");
}
@RequiresPermissions("sys:user:delete")
@PostMapping("deleteSome")
@ResponseBody
@SysLog("删除系统用户数据(多个)")
public ResponseEntity deleteSome(@RequestBody List users){
if(users == null || users.size()==0){
return ResponseEntity.failure("请选择需要删除的用户");
}
for (User u : users){
if(u.getAdminUser()){
return ResponseEntity.failure("不能删除超级管理员");
}else{
userService.deleteUser(u);
}
}
return ResponseEntity.success("操作成功");
}
@RequestMapping("userinfo")
public String toEditMyInfo(ModelMap modelMap){
String userId = MySysUser.id();
User user = userService.findUserById(userId);
modelMap.put("userinfo",user);
modelMap.put("userRole",user.getRoleLists());
return "admin/user/userInfo";
}
@SysLog("系统用户个人信息修改")
@PostMapping("saveUserinfo")
@ResponseBody
public ResponseEntity saveUserInfo(User user){
if(StringUtils.isBlank(user.getId())){
return ResponseEntity.failure("用户ID不能为空");
}
if(StringUtils.isBlank(user.getLoginName())){
return ResponseEntity.failure("登录名不能为空");
}
User oldUser = userService.findUserById(user.getId());
if(StringUtils.isNotBlank(user.getEmail())){
if(!user.getEmail().equals(oldUser.getEmail())){
if(userService.userCount(user.getEmail())>0){
return ResponseEntity.failure("该邮箱已被使用");
}
}
}
if(StringUtils.isNotBlank(user.getTel())){
if(!user.getTel().equals(oldUser.getTel())) {
if (userService.userCount(user.getTel()) > 0) {
return ResponseEntity.failure("该手机号已经被绑定");
}
}
}
userService.updateById(user);
return ResponseEntity.success("操作成功");
}
@RequestMapping("changePassword")
public String changePassword(ModelMap modelMap){
modelMap.put("currentUser",userService.getById(MySysUser.id()));
return "admin/user/changePassword";
}
@CrossOrigin
@SysLog("用户修改密码")
@PostMapping("changePassword")
@ResponseBody
public ResponseEntity changePassword(@RequestParam(value = "userName",required = false)String userName,
@RequestParam(value = "oldPwd",required = false)String oldPwd,
@RequestParam(value = "newPwd",required = false)String newPwd,
@RequestParam(value = "confirmPwd",required = false)String confirmPwd){
if(StringUtils.isBlank(oldPwd)){
return ResponseEntity.failure("旧密码不能为空");
}
if(StringUtils.isBlank(newPwd)){
return ResponseEntity.failure("新密码不能为空");
}
if(StringUtils.isBlank(confirmPwd)){
return ResponseEntity.failure("确认密码不能为空");
}
if(!confirmPwd.equals(newPwd)){
return ResponseEntity.failure("确认密码与新密码不一致");
}
//小程序修改密码
if(StringUtils.isBlank(userName)){
//PC修改密码
User user = userService.findUserById(MySysUser.id());
byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
String password = Encodes.encodeHex(hashPassword);
if(!user.getPassword().equals(password)){
return ResponseEntity.failure("旧密码错误");
}
user.setPassword(newPwd);
Encodes.entryptPassword(user);
userService.updateById(user);
return ResponseEntity.success("操作成功");
}else {
//小程序修改密码
User user = userService.findUserByLoginName(userName);
byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
String password = Encodes.encodeHex(hashPassword);
if(!user.getPassword().equals(password)){
return ResponseEntity.failure("旧密码错误");
}
user.setPassword(newPwd);
Encodes.entryptPassword(user);
userService.updateById(user);
return ResponseEntity.success("操作成功");
}
}
@SysLog("上传头像")
@PostMapping("uploadFace")
@ResponseBody
public ResponseEntity uploadFile(@RequestParam("icon") MultipartFile file, HttpServletRequest httpServletRequest) {
if(file == null){
return ResponseEntity.failure("上传文件为空 ");
}
String url = null;
Map map = new HashMap();
try {
url = uploadService.upload(file);
map.put("url", url);
map.put("name", file.getOriginalFilename());
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.failure(e.getMessage());
}
return ResponseEntity.success("操作成功").setAny("data",map);
}
}
@Controller
@RequestMapping("admin/system/role")
public class RoleController {
@Autowired
RoleService roleService;
@Autowired
UserService userService;
@Autowired
MenuService menuService;
@RequestMapping(value = "list")
public String list(){
return "admin/role/list";
}
@RequiresPermissions("sys:role:list")
@PostMapping("list")
@ResponseBody
public PageData list(@RequestParam(value = "page",defaultValue = "1")Integer page,
@RequestParam(value = "limit",defaultValue = "10")Integer limit,
ServletRequest request){
Map map = WebUtils.getParametersStartingWith(request, "s_");
PageData rolePageData = new PageData<>();
QueryWrapper roleWrapper = new QueryWrapper<>();
roleWrapper.eq("del_flag",false);
if(!map.isEmpty()){
String keys = (String) map.get("key");
if(StringUtils.isNotBlank(keys)) {
roleWrapper.like("name", keys);
}
}
IPage rolePage = roleService.page(new Page<>(page,limit),roleWrapper);
rolePageData.setCount(rolePage.getTotal());
rolePageData.setData(setUserToRole(rolePage.getRecords()));
return rolePageData;
}
private List setUserToRole(List roles){
roles.forEach(r -> {
if(StringUtils.isNotBlank(r.getCreateId())){
User u = userService.findUserById(r.getCreateId());
if(StringUtils.isBlank(u.getNickName())){
u.setNickName(u.getLoginName());
}
r.setCreateUser(u);
}
if(StringUtils.isNotBlank(r.getUpdateId())){
User u = userService.findUserById(r.getUpdateId());
if(StringUtils.isBlank(u.getNickName())){
u.setNickName(u.getLoginName());
}
r.setUpdateUser(u);
}
});
return roles;
}
@RequestMapping("add")
public String add(ModelMap modelMap){
Map map = new HashMap();
map.put("parentId",null);
map.put("isShow",false);
List
@Controller
public class LonginController {
private final static Logger LOGGER = LoggerFactory.getLogger(LonginController.class);
public final static String LOGIN_TYPE = "loginType";
@Autowired
@Qualifier("captchaProducer")
DefaultKaptcha captchaProducer;
@Autowired
UserService userService;
@Autowired
MenuService menuService;
public enum LoginTypeEnum {
PAGE,ADMIN;
}
// @RequestMapping(value = "")
// public String welcome() {
// return "redirect:admin";
// }
@RequestMapping(value = {"admin","admin/index"})
public String adminIndex(RedirectAttributes attributes, ModelMap map) {
Subject s = SecurityUtils.getSubject();
attributes.addFlashAttribute(LOGIN_TYPE, LoginTypeEnum.ADMIN);
if(s.isAuthenticated()) {
return "redirect:index";
}
return "redirect:toLogin";
}
@RequestMapping(value = "toLogin")
public String adminToLogin(HttpSession session, @ModelAttribute(LOGIN_TYPE) String loginType) {
if(StringUtils.isBlank(loginType)) {
LoginTypeEnum attribute = (LoginTypeEnum) session.getAttribute(LOGIN_TYPE);
loginType = attribute == null ? loginType : attribute.name();
}
if(LoginTypeEnum.ADMIN.name().equals(loginType)) {
session.setAttribute(LOGIN_TYPE,LoginTypeEnum.ADMIN);
return "admin/login";
}else {
session.setAttribute(LOGIN_TYPE,LoginTypeEnum.PAGE);
return "login";
}
}
@RequestMapping(value = "index")
public String index(HttpSession session, @ModelAttribute(LOGIN_TYPE) String loginType) {
if(StringUtils.isBlank(loginType)) {
LoginTypeEnum attribute = (LoginTypeEnum) session.getAttribute(LOGIN_TYPE);
loginType = attribute == null ? loginType : attribute.name();
}
if(LoginTypeEnum.ADMIN.name().equals(loginType)) {
AuthRealm.ShiroUser principal = (AuthRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
session.setAttribute("icon",StringUtils.isBlank(principal.getIcon()) ? "/static/admin/img/face.jpg" : principal.getIcon());
return "admin/index";
}else {
AuthRealm.ShiroUser principal = (AuthRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
return "admin/index";
}
}
@RequestMapping("/getCaptcha")
public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
//设置页面不缓存
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
String verifyCode = captchaProducer.createText();
//将验证码放到HttpSession里面
request.getSession().setAttribute(Constants.VALIDATE_CODE, verifyCode);
LOGGER.info("本次生成的验证码为[" + verifyCode + "],已存放到HttpSession中");
//设置输出的内容的类型为JPEG图像
response.setContentType("image/jpeg");
BufferedImage bufferedImage = captchaProducer.createImage(verifyCode);
//写给浏览器
ImageIO.write(bufferedImage, "JPEG", response.getOutputStream());
}
@PostMapping("admin/login")
@SysLog("用户登录")
@ResponseBody
public ResponseEntity adminLogin(HttpServletRequest request) {
String username = request.getParameter("username");
String password = request.getParameter("password");
String rememberMe = request.getParameter("rememberMe");
String code = request.getParameter("code");
String driver = request.getParameter("driver");
String errorMsg = null;
//判断登陆设备
if(StringUtils.isBlank(driver)){
//电脑登录
if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){
return ResponseEntity.failure("用户名或者密码不能为空");
}else if(StringUtils.isBlank(code)){
return ResponseEntity.failure("验证码不能为空");
}
HttpSession session = request.getSession();
if(session == null){
return ResponseEntity.failure("session超时");
}
String trueCode = (String)session.getAttribute(Constants.VALIDATE_CODE);
if(StringUtils.isBlank(trueCode)){
return ResponseEntity.failure("验证码超时");
}
if(StringUtils.isBlank(code) || !trueCode.toLowerCase().equals(code.toLowerCase())){
return ResponseEntity.failure("验证码错误");
}else {
Subject user = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username,password,Boolean.valueOf(rememberMe));
try {
user.login(token);
}catch (IncorrectCredentialsException e) {
errorMsg = "用户名密码错误!";
}catch (UnknownAccountException e) {
errorMsg = "账户不存在!";
}catch (LockedAccountException e) {
errorMsg = "账户已被锁定!";
}catch (UserTypeAccountException e) {
errorMsg = "账户不是管理用户!";
}
if(StringUtils.isBlank(errorMsg)) {
ResponseEntity responseEntity = new ResponseEntity();
responseEntity.setSuccess(Boolean.TRUE);
responseEntity.setAny("url","index");
return responseEntity;
}else {
return ResponseEntity.failure(errorMsg);
}
}
}else{
//小程序或APP登录
if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){
return ResponseEntity.failure("用户名或者密码不能为空");
}
Subject user = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username,password,Boolean.valueOf(rememberMe));
try {
user.login(token);
}catch (IncorrectCredentialsException e) {
errorMsg = "用户名或密码错误!";
}catch (UnknownAccountException e) {
errorMsg = "账户不存在!";
}catch (LockedAccountException e) {
errorMsg = "账户已被锁定!";
}catch (UserTypeAccountException e) {
errorMsg = "账户不是管理用户!";
}
if(StringUtils.isBlank(errorMsg)) {
ResponseEntity responseEntity = new ResponseEntity();
responseEntity.setSuccess(Boolean.TRUE);
responseEntity.setAny("url","index");
return responseEntity;
}else {
return ResponseEntity.failure(errorMsg);
}
}
}
@RequestMapping("admin/main")
public String main(ModelMap map){
return "admin/main";
}
/***
* 获得用户所拥有的菜单列表
* @return
*/
@RequestMapping("/admin/user/getUserMenu")
@ResponseBody
public List getUserMenu(){
String userId = MySysUser.id();
List list = menuService.getShowMenuByUser(userId);
return list;
}
@RequestMapping("systemLogout")
@SysLog("退出系统")
public String logOut(){
SecurityUtils.getSubject().logout();
return "redirect:home";
}
}
源码获取:博客首页 "资源" 里下载!