一,环境介绍
语言环境:Java: jdk1.8
数据库:Mysql: mysql5.7
应用服务器:Tomcat: tomcat8.5.31
开发工具:IDEA或eclipse
开发技术:Springboot+Vue
二,项目简介
对于工程建设而言,目前也越来越多的通过信息化技术和网络技术的应用,来更多的解决信息的传播和业务数据的管理问题。传统的工程建设行业,更多的是通过人工管理这些工程建设中涉及到的各种业务数据和流程,不仅管理繁琐,人员的沟通效率也十分低下,甚至涉及一些索贿受贿的不规范操作。通过信息化的流程化的应用,可以大大提高审批和管理效率,减少中间沟通环节,让所有的业务流程管理更加透明化。
本课题主要研究如何基于软件开发技术实现项目管理系统的开发,主要运用JAVA开发语言的相关技术和前端的技术来实现一个前后端分离的业务管理系统。系统的后台开发主要运用Springboot和Mybatisplus框架来开发实现相关服务接口,前端用主要运用VUE+ElementUI来实现前端开发,通过业务接口对接来实现前后端的交互,数据交互使用JSON的数据格式来实现数据封装,在业务数据存储方面主要使用MYSQL数据库和REDIS缓存数据库进行数据存储。
2.1 功能性需求分析
根据系统功能,系统共(确定)分为9种角色,分别是:
1、系统管理员(基本信息维护)
2、用户服务部(可以查询所有项目)
3、分公司(施工单位)(有可能是多个)(只能查询自己负责的项目)(技术员、材料员2个角色)
4、安全质量部(可以查询所有项目)
5、技术设备部(可以查询所有项目)
6、经营计划部(可以查询所有项目)
7、财务部(可以查询所有项目)
8、查询者(登录后可以查询到除“经营计划部”、“财务部”以外的数据)
各用户角色对应的主要业务操作功能如下:
1.系统管理员的主要功能
1)分公司管理
增加、修改、删除分公司。
涉及的数据项:公司编号(隐藏)、公司名字、备注,3项信息。
2)用户管理(包含授权)
增加、修改、删除用户。
涉及的数据项:用户编号(隐藏)、用户名(建议使用手机号)、姓名、所在公司(或部门)、电话、密码(隐藏)、备注,6项信息。
3)使用材料管理
涉及的数据项:材料编号(隐藏)、工程分类(居民、非居民、中压等)、材料名字、材料规格、材料单价、计量单位、备注,7项信息。
2.用户服务部功能
1)项目查询
可以在系统中查询全部项目,多条件查询,查看项目详细信息,导出项目到Excel表。
2)增加项目
用户点击“增加项目”按钮,弹出窗口,填写项目详细信息,保存即可。
3)修改项目
修改的信息项同增加项目时的信息项
4)删除项目
将项目“项目状态”修改为“删除”,项目状态为“删除”的项目,其他部门不能查询或修改信息。
3.分公司(施工单位)功能
技术人员操作公能:
1)技术员查询项目
查询范围:自己负责的(当前登录用户负责的项目)项目。(项目在增加时已经指定了“施工公司技术人”)。
2)技术员填写项目信息字段
3)技术员填写项目用到的计划领用材料单
技术员增加、修改、删除用到的材料。
①增加:选择材料名字(管理员已经设置好)、填写领用数量、(其他项目)转入数量、备注即可,单价、计量单位自动同步。
②修改:只能修改领用数量、转入数量、备注。
③删除:删除该项目的这个材料即可。
材料员操作功能:
1)材料员查询项目
查询范围:自己所在分公司的全部项目。
2)完善项目用料管理
选择某一个项目后,在弹出窗口,可以填写该项目的材料的实际用量、流转去向 2个字段,并保存。“工程材料确认单”在该步骤导出。
3)填写项目材料票交接日期
4.安全质量部功能
1)项目查询
可以在系统中查询全部项目,多条件查询,查看项目详细信息,可以导出数据到Excel表格。
2)修改项目中对应本部门的字段
5.技术设备部功能
1)项目查询(可能有特殊统计功能)
可以在系统中查询全部项目,多条件查询,查看项目详细信息,可以导出数据到Excel表格。
2)修改项目中对应本部门的字段
6.经营计划部功能
1)项目查询
可以在系统中查询全部项目,多条件查询,查看项目详细信息,可以导出数据到Excel表格。
2)修改项目中对应本部门的字段
7.财务部功能
1)项目查询
可以在系统中查询全部项目,多条件查询,查看项目详细信息,可以导出数据到Excel表格。
2)修改项目中对应本部门的字段
2.2 非功能需求分析
非功能需求从实际运行和使用环境进行分析,主要包括以下两点:
(1)系统页面需求:本系统是业务系统,网页美观大方,简洁朴素,符合业务系统的特征即可。
(2)系统的拓展性需求。系统在设计时要分层设计,后台可以在原有的基础上进行功能增加,方便以后系统的功能拓展。
(3)稳定性需求:本系统要运行稳定,在服务器上运行要保证稳定,运行不能卡顿,操作要流畅。
(4)系统安全性需求。本系统在设计时需要对公司的业务数据保证安全,对数据库必要字段加密,数据要经常备份。
三,系统展示
用户登录
用户管理
角色管理
项目 管理
材料展示
四,核心代码展示
package cn.zwz.data.controller; import cn.zwz.basics.exception.ZwzException; import cn.zwz.basics.log.LogType; import cn.zwz.basics.log.SystemLog; import cn.zwz.basics.utils.*; import cn.zwz.data.entity.Setting; import cn.zwz.data.entity.User; import cn.zwz.data.service.IFileService; import cn.zwz.data.service.ISettingService; import cn.zwz.data.service.IUserService; import cn.zwz.data.utils.ZwzFileUtils; import cn.zwz.data.utils.ZwzNullUtils; import cn.zwz.basics.baseVo.PageVo; import cn.zwz.basics.baseVo.Result; import cn.zwz.data.entity.File; import cn.hutool.core.util.StrUtil; import cn.zwz.data.vo.OssSettingVo; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import java.util.Objects; /** * 系统文件 * @author me */ @Slf4j @Controller @Api(tags = "文件管理") @RequestMapping("/zwz/file") @Transactional public class FileController { @Autowired private ZwzFileUtils zwzFileUtils; @Autowired private IUserService iUserService; @Autowired private IFileService iFileService; @Autowired private ISettingService iSettingService; @PersistenceContext private EntityManager entityManager; @SystemLog(about = "查询系统文件", type = LogType.DATA_CENTER,doType = "FILE-01") @RequestMapping(value = "/getByCondition", method = RequestMethod.GET) @ApiOperation(value = "查询系统文件") @ResponseBody public Result<IPage<File>> getByCondition(@ModelAttribute File file,@ModelAttribute PageVo page) { QueryWrapper<File> qw = new QueryWrapper<>(); if(!ZwzNullUtils.isNull(file.getFKey())) { qw.eq("f_key",file.getFKey()); } if(!ZwzNullUtils.isNull(file.getType())) { qw.eq("type",file.getType()); } if(!ZwzNullUtils.isNull(file.getName())) { qw.eq("name",file.getName()); } IPage<File> fileList = iFileService.page(PageUtil.initMpPage(page),qw); OssSettingVo os = getOssSetting(); Map<String, String> map = new HashMap<>(16); for(File e : fileList.getRecords()) { if (e.getLocation() != null && Objects.equals(0,e.getLocation())) { String url = os.getFileHttp() + os.getFileView() + "/"; entityManager.detach(e); e.setUrl(url + e.getId()); } if (StrUtil.isNotBlank(e.getCreateBy())) { if (!map.containsKey(e.getCreateBy())) { QueryWrapper<User> userQw = new QueryWrapper<>(); userQw.eq("username",e.getCreateBy()); User u = iUserService.getOne(userQw); if (u != null) { e.setNickname(u.getNickname()); } map.put(e.getCreateBy(), u.getNickname()); } else { e.setNickname(map.get(e.getCreateBy())); } } } map = null; return new ResultUtil<IPage<File>>().setData(fileList); } @SystemLog(about = "文件复制", type = LogType.DATA_CENTER,doType = "FILE-02") @RequestMapping(value = "/copy", method = RequestMethod.POST) @ApiOperation(value = "文件复制") @ResponseBody public Result<Object> copy(@RequestParam String id,@RequestParam String key) { File file = iFileService.getById(id); if(file.getLocation() == null){ file.setLocation(0); } String toKey = "副本_" + key; key = file.getUrl(); String newUrl = zwzFileUtils.copyFile(key, toKey); File newFile = new File().setName(file.getName()).setFKey(toKey).setSize(file.getSize()).setType(file.getType()).setLocation(file.getLocation()).setUrl(newUrl); iFileService.saveOrUpdate(newFile); return ResultUtil.data(); } @SystemLog(about = "文件重命名", type = LogType.DATA_CENTER,doType = "FILE-03") @RequestMapping(value = "/rename", method = RequestMethod.POST) @ApiOperation(value = "文件重命名") @ResponseBody public Result<Object> upload(@RequestParam String id, @RequestParam String newKey, @RequestParam String newName) { File file = iFileService.getById(id); if(file.getLocation() == null){ file.setLocation(0); } String newUrl = ""; String oldKey = file.getFKey(); if(!Objects.equals(newKey,oldKey)){ oldKey = file.getUrl(); newUrl = zwzFileUtils.renameFile(oldKey, newKey); } file.setName(newName); file.setFKey(newKey); if(!oldKey.equals(newKey)) { file.setUrl(newUrl); } iFileService.saveOrUpdate(file); return ResultUtil.data(); } @SystemLog(about = "文件重命名", type = LogType.DATA_CENTER,doType = "FILE-04") @RequestMapping(value = "/delete", method = RequestMethod.POST) @ApiOperation(value = "文件重命名") @ResponseBody public Result<Object> delete(@RequestParam String[] ids) { for(String id : ids) { File file = iFileService.getById(id); if(file.getLocation() == null){ file.setLocation(0); } String key = file.getUrl(); zwzFileUtils.deleteFile(key); iFileService.removeById(id); } return ResultUtil.data(); } @SystemLog(about = "预览文件", type = LogType.DATA_CENTER,doType = "FILE-05") @RequestMapping(value = "/view/{id}", method = RequestMethod.GET) @ApiOperation(value = "预览文件") public void view(@PathVariable String id,@RequestParam(required = false) String filename,@RequestParam(required = false, defaultValue = "false") Boolean preview,HttpServletResponse httpServletResponse) throws IOException { File selectFile = iFileService.getById(id); if(selectFile == null){ throw new ZwzException("文件不存在"); } if(ZwzNullUtils.isNull(filename)){ filename = selectFile.getFKey(); } if(!preview){ httpServletResponse.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8")); } httpServletResponse.setContentLengthLong(selectFile.getSize()); httpServletResponse.setContentType(selectFile.getType()); httpServletResponse.addHeader("Accept-Ranges", "bytes"); if(selectFile.getSize() != null && selectFile.getSize() > 0){ httpServletResponse.addHeader("Content-Range", "bytes " + 0 + "-" + (selectFile.getSize()-1) + "/" + selectFile.getSize()); } zwzFileUtils.view(selectFile.getUrl(), httpServletResponse); } public OssSettingVo getOssSetting() { Setting s1 = iSettingService.getById("FILE_VIEW"); Setting s2 = iSettingService.getById("FILE_HTTP"); Setting s3 = iSettingService.getById("FILE_PATH"); if(s1 == null || s1 == null || s1 == null) { return null; } return new OssSettingVo(s1.getValue(),s2.getValue(),s3.getValue()); } }
package cn.zwz.data.controller; import cn.zwz.basics.log.SystemLog; import cn.zwz.basics.redis.RedisTemplateHelper; import cn.zwz.basics.utils.*; import cn.zwz.basics.security.SecurityUserDetails; import cn.zwz.basics.parameter.CommonConstant; import cn.zwz.basics.log.LogType; import cn.zwz.basics.exception.ZwzException; import cn.zwz.basics.baseVo.PageVo; import cn.zwz.basics.baseVo.Result; import cn.zwz.data.entity.*; import cn.zwz.data.service.*; import cn.zwz.data.utils.ZwzNullUtils; import cn.zwz.data.vo.PermissionDTO; import cn.zwz.data.vo.RoleDTO; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.validation.Valid; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.*; import java.util.stream.Collectors; /** * 用户 * @author me */ @RestController @Api(tags = "用户接口") @RequestMapping("/zwz/user") @CacheConfig(cacheNames = "user") @Transactional public class UserController { @Autowired private IUserService iUserService; @Autowired private IDepartmentService iDepartmentService; @Autowired private IRoleService iRoleService; @Autowired private IUserRoleService iUserRoleService; @Autowired private IDepartmentHeaderService iDepartmentHeaderService; @Autowired private IRolePermissionService iRolePermissionService; @Autowired private RedisTemplateHelper redisTemplateHelper; @Autowired private IPermissionService iPermissionService; @PersistenceContext private EntityManager entityManager; @Autowired private SecurityUtil securityUtil; @Autowired private StringRedisTemplate redisTemplate; private static final String REDIS_PRE_1 = "userRole::"; private static final String REDIS_PRE_2 = "userRole::depIds:"; private static final String REDIS_PRE_3 = "permission::userMenuList:"; private static final String REDIS_PRE_4 = "user::"; @SystemLog(about = "获取当前登录用户", type = LogType.DATA_CENTER,doType = "USER-02") @RequestMapping(value = "/info", method = RequestMethod.GET) @ApiOperation(value = "获取当前登录用户") public Result<User> getUserInfo(){ User u = securityUtil.getCurrUser(); entityManager.clear(); u.setPassword(null); return new ResultUtil<User>().setData(u); } @RequestMapping(value = "/regist", method = RequestMethod.POST) @ApiOperation(value = "注册用户") public Result<Object> regist(@Valid User u){ u.setEmail(u.getMobile() + "@qq.com"); QueryWrapper<User> userQw = new QueryWrapper<>(); userQw.and(wrapper -> wrapper.eq("username", u.getUsername()).or().eq("mobile",u.getMobile())); if(iUserService.count(userQw) > 0L) { return ResultUtil.error("登陆账号/手机号重复"); } String encryptPass = new BCryptPasswordEncoder().encode(u.getPassword()); u.setPassword(encryptPass).setType(0); iUserService.saveOrUpdate(u); QueryWrapper<Role> roleQw = new QueryWrapper<>(); roleQw.eq("default_role",true); List<Role> roleList = iRoleService.list(roleQw); if(roleList.size() > 0){ for(Role role : roleList) { iUserRoleService.saveOrUpdate(new UserRole().setUserId(u.getId()).setRoleId(role.getId())); } } return ResultUtil.data(u); } @SystemLog(about = "解锁验证密码", type = LogType.DATA_CENTER,doType = "USER-03") @RequestMapping(value = "/unlock", method = RequestMethod.POST) @ApiOperation(value = "解锁验证密码") public Result<Object> unLock(@RequestParam String password){ User u = securityUtil.getCurrUser(); if(!new BCryptPasswordEncoder().matches(password, u.getPassword())){ return ResultUtil.error("密码不正确"); } return ResultUtil.data(null); } @SystemLog(about = "重置密码", type = LogType.DATA_CENTER,doType = "USER-04") @RequestMapping(value = "/resetPass", method = RequestMethod.POST) @ApiOperation(value = "重置密码") public Result<Object> resetPass(@RequestParam String[] ids){ for(String id : ids){ User userForReset = iUserService.getById(id); if(userForReset == null) { return ResultUtil.error("不存在"); } userForReset.setPassword(new BCryptPasswordEncoder().encode("123456")); iUserService.saveOrUpdate(userForReset); redisTemplate.delete(REDIS_PRE_4 + userForReset.getUsername()); } return ResultUtil.success(); } @SystemLog(about = "修改用户资料", type = LogType.DATA_CENTER,doType = "USER-05") @RequestMapping(value = "/edit", method = RequestMethod.POST) @ApiOperation(value = "修改用户资料",notes = "用户名密码不会修改 需要username更新缓存") @CacheEvict(key = "#u.username") public Result<Object> editOwn(User u){ User old = securityUtil.getCurrUser(); u.setUsername(old.getUsername()); u.setPassword(old.getPassword()); iUserService.saveOrUpdate(u); return ResultUtil.success("修改成功"); } @SystemLog(about = "修改密码", type = LogType.DATA_CENTER,doType = "USER-06") @RequestMapping(value = "/modifyPass", method = RequestMethod.POST) @ApiOperation(value = "修改密码") public Result<Object> modifyPass(@RequestParam String password,@RequestParam String newPass,@RequestParam String passStrength){ User user = securityUtil.getCurrUser(); if(!new BCryptPasswordEncoder().matches(password, user.getPassword())){ return ResultUtil.error("原密码不正确"); } String newEncryptPass= new BCryptPasswordEncoder().encode(newPass); user.setPassword(newEncryptPass); user.setPassStrength(passStrength); iUserService.saveOrUpdate(user); redisTemplate.delete(REDIS_PRE_4 + user.getUsername()); return ResultUtil.success(); } @SystemLog(about = "查询用户", type = LogType.DATA_CENTER,doType = "USER-07") @RequestMapping(value = "/getUserList", method = RequestMethod.GET) @ApiOperation(value = "查询用户") public Result<IPage<User>> getUserList(@ModelAttribute User user, @ModelAttribute PageVo page) { QueryWrapper<User> userQw = new QueryWrapper<>(); if(!ZwzNullUtils.isNull(user.getNickname())) { userQw.like("nickname",user.getNickname()); } if(!ZwzNullUtils.isNull(user.getDepartmentId())) { userQw.eq("department_id",user.getDepartmentId()); } IPage<User> userData = iUserService.page(PageUtil.initMpPage(page),userQw); for(User u: userData.getRecords()) { QueryWrapper<Role> roleQw = new QueryWrapper<>(); roleQw.inSql("id","SELECT role_id FROM a_user_role WHERE user_id = '" + u.getId() + "'"); List<Role> list = iRoleService.list(roleQw); List<RoleDTO> roleDTOList = list.stream().map(e->{ return new RoleDTO().setId(e.getId()).setName(e.getName()).setDescription(e.getDescription()); }).collect(Collectors.toList()); u.setRoles(roleDTOList); entityManager.detach(u); u.setPassword(null); } return new ResultUtil<IPage<User>>().setData(userData); } @SystemLog(about = "根据部门查询用户", type = LogType.DATA_CENTER,doType = "USER-08") @RequestMapping(value = "/getByDepartmentId", method = RequestMethod.GET) @ApiOperation(value = "根据部门查询用户") public Result<List<User>> getByCondition(@RequestParam String departmentId){ QueryWrapper<User> userQw = new QueryWrapper<>(); userQw.eq("department_id", departmentId); List<User> list = iUserService.list(userQw); entityManager.clear(); list.forEach(u -> { u.setPassword(null); }); return new ResultUtil<List<User>>().setData(list); } @SystemLog(about = "模拟搜索用户", type = LogType.DATA_CENTER,doType = "USER-09") @RequestMapping(value = "/searchByName/{username}", method = RequestMethod.GET) @ApiOperation(value = "模拟搜索用户") public Result<List<User>> searchByName(@PathVariable String username) throws UnsupportedEncodingException { QueryWrapper<User> userQw = new QueryWrapper<>(); userQw.eq("username", URLDecoder.decode(username, "utf-8")); userQw.eq("status", 0); List<User> list = iUserService.list(userQw); entityManager.clear(); list.forEach(u -> { u.setPassword(null); }); return new ResultUtil<List<User>>().setData(list); } @SystemLog(about = "查询全部用户", type = LogType.DATA_CENTER,doType = "USER-10") @RequestMapping(value = "/getAll", method = RequestMethod.GET) @ApiOperation(value = "查询全部用户") public Result<List<User>> getAll(){ List<User> userList = iUserService.list(); for(User user: userList){ entityManager.clear(); user.setPassword(null); } return new ResultUtil<List<User>>().setData(userList); } @SystemLog(about = "管理员修改资料", type = LogType.DATA_CENTER,doType = "USER-11") @RequestMapping(value = "/admin/edit", method = RequestMethod.POST) @ApiOperation(value = "管理员修改资料") @CacheEvict(key = "#u.username") public Result<Object> edit(User u,@RequestParam(required = false) String[] roleIds){ User customaryUser = iUserService.getById(u.getId()); // 登陆账号和密码不能发生变更 u.setUsername(customaryUser.getUsername()); u.setPassword(customaryUser.getPassword()); if(!Objects.equals(customaryUser.getMobile(),u.getMobile())) { QueryWrapper<User> customaryUserQw = new QueryWrapper<>(); customaryUserQw.ne("id",customaryUser.getId()); customaryUserQw.eq("mobile",u.getMobile()); long customaryUserCount = iUserService.count(customaryUserQw); if(customaryUserCount > 0) { return ResultUtil.error("手机号重复"); } } if(!ZwzNullUtils.isNull(u.getDepartmentId())) { Department department = iDepartmentService.getById(u.getDepartmentId()); if(department != null) { u.setDepartmentTitle(department.getTitle()); } } else { u.setDepartmentId(""); u.setDepartmentTitle(""); } // 吃哦就花 iUserService.saveOrUpdate(u); QueryWrapper<UserRole> userRoleQw = new QueryWrapper<>(); userRoleQw.eq("user_id",u.getId()); iUserRoleService.remove(userRoleQw); if(roleIds != null && roleIds.length > 0) { for (String roleId : roleIds) { UserRole ur = new UserRole(); ur.setUserId(u.getId()); ur.setRoleId(roleId); iUserRoleService.saveOrUpdate(ur); } } redisTemplate.delete(REDIS_PRE_1 + u.getId()); redisTemplate.delete(REDIS_PRE_2 + u.getId()); redisTemplate.delete(REDIS_PRE_3 + u.getId()); return ResultUtil.success(); } @SystemLog(about = "添加用户", type = LogType.DATA_CENTER,doType = "USER-12") @RequestMapping(value = "/admin/add", method = RequestMethod.POST) @ApiOperation(value = "添加用户") public Result<Object> add(@Valid User u,@RequestParam(required = false) String[] roleIds) { QueryWrapper<User> userQw = new QueryWrapper<>(); userQw.and(wrapper -> wrapper.eq("username", u.getUsername()).or().eq("mobile",u.getMobile())); if(iUserService.count(userQw) > 0L) { return ResultUtil.error("登陆账号/手机号重复"); } if(!ZwzNullUtils.isNull(u.getDepartmentId())){ Department department = iDepartmentService.getById(u.getDepartmentId()); if(department != null){ u.setDepartmentTitle(department.getTitle()); } }else{ u.setDepartmentId(""); u.setDepartmentTitle(""); } u.setPassword(new BCryptPasswordEncoder().encode(u.getPassword())); iUserService.saveOrUpdate(u); if(roleIds != null && roleIds.length > 0) { for (String roleId : roleIds) { UserRole userRole = new UserRole(); userRole.setUserId(u.getId()); userRole.setRoleId(roleId); iUserRoleService.saveOrUpdate(userRole); } } return ResultUtil.success(); } @SystemLog(about = "禁用用户", type = LogType.DATA_CENTER,doType = "USER-13") @RequestMapping(value = "/disable", method = RequestMethod.POST) @ApiOperation(value = "禁用用户") public Result<Object> disable( @RequestParam String id){ User user = iUserService.getById(id); if(user == null){ return ResultUtil.error("用户不存在"); } user.setStatus(CommonConstant.USER_STATUS_LOCK); iUserService.saveOrUpdate(user); redisTemplate.delete("user::"+user.getUsername()); return ResultUtil.success(); } @SystemLog(about = "启用用户", type = LogType.DATA_CENTER,doType = "USER-14") @RequestMapping(value = "/enable", method = RequestMethod.POST) @ApiOperation(value = "启用用户") public Result<Object> enable(@RequestParam String id){ User user = iUserService.getById(id); if(user==null){ return ResultUtil.error("用户不存在"); } user.setStatus(CommonConstant.USER_STATUS_NORMAL); iUserService.saveOrUpdate(user); redisTemplate.delete("user::"+user.getUsername()); return ResultUtil.success(); } @SystemLog(about = "删除用户", type = LogType.DATA_CENTER,doType = "USER-15") @RequestMapping(value = "/delByIds", method = RequestMethod.POST) @ApiOperation(value = "删除用户") public Result<Object> delByIds(@RequestParam String[] ids) { for(String id:ids){ User u = iUserService.getById(id); redisTemplate.delete("user::" + u.getUsername()); redisTemplate.delete("userRole::" + u.getId()); redisTemplate.delete("userRole::depIds:" + u.getId()); redisTemplate.delete("permission::userMenuList:" + u.getId()); Set<String> keys = redisTemplateHelper.keys("department::*"); redisTemplate.delete(keys); iUserService.removeById(id); QueryWrapper<UserRole> urQw = new QueryWrapper<>(); urQw.eq("user_id",id); iUserRoleService.remove(urQw); QueryWrapper<DepartmentHeader> dhQw = new QueryWrapper<>(); dhQw.eq("user_id",id); iDepartmentHeaderService.remove(dhQw); } return ResultUtil.success(); } @SystemLog(about = "导入用户", type = LogType.DATA_CENTER,doType = "USER-16") @RequestMapping(value = "/importData", method = RequestMethod.POST) @ApiOperation(value = "导入用户") public Result<Object> importData(@RequestBody List<User> users){ List<Integer> errors = new ArrayList<>(); List<String> reasons = new ArrayList<>(); int count = 0; for(User u: users){ count++; if(StrUtil.isBlank(u.getUsername())||StrUtil.isBlank(u.getPassword())){ errors.add(count); reasons.add("账号密码为空"); continue; } QueryWrapper<User> userQw = new QueryWrapper<>(); userQw.eq("username",u.getUsername()); if(iUserService.count(userQw) > 0L) { errors.add(count); reasons.add("用户名已存在"); continue; } u.setPassword(new BCryptPasswordEncoder().encode(u.getPassword())); if(StrUtil.isNotBlank(u.getDepartmentId())){ Department department = iDepartmentService.getById(u.getDepartmentId()); if(department == null) { errors.add(count); reasons.add("部门不存在"); continue; } } if(u.getStatus()==null){ u.setStatus(CommonConstant.USER_STATUS_NORMAL); } iUserService.saveOrUpdate(u); if(u.getDefaultRole() != null && u.getDefaultRole()==1) { QueryWrapper<Role> roleQw = new QueryWrapper<>(); roleQw.eq("default_role",true); List<Role> roleList = iRoleService.list(roleQw); if(roleList!=null&&roleList.size()>0){ for(Role role : roleList){ UserRole ur = new UserRole().setUserId(u.getId()).setRoleId(role.getId()); iUserRoleService.saveOrUpdate(ur); } } } } int successCount = users.size() - errors.size(); String successMessage = "成功导入 " + successCount + " 位用户"; String failMessage = "成功导入 " + successCount + " 位用户,失败 " + errors.size() + " 位用户。<br>" +"第 " + errors.toString() + " 行数据导入出错,错误原因是为 <br>" + reasons.toString(); String message = null; if(errors.size() == 0){ message = successMessage; }else{ message = failMessage; } return ResultUtil.success(message); } @ApiOperation(value = "添加用户的角色和菜单信息") public User userToDTO(User user) { if(user == null) { return null; } // 角色 QueryWrapper<UserRole> urQw = new QueryWrapper<>(); urQw.eq("user_id", user.getId()); List<UserRole> roleList = iUserRoleService.list(urQw); List<RoleDTO> roleDTOList = new ArrayList<>(); for (UserRole userRole : roleList) { Role role = iRoleService.getById(userRole.getRoleId()); if(role != null) { roleDTOList.add(new RoleDTO().setId(role.getId()).setName(role.getName())); } } user.setRoles(roleDTOList); // 菜单 List<String> permissionIdList = new ArrayList<>(); for (RoleDTO dto : roleDTOList) { QueryWrapper<RolePermission> rpQw = new QueryWrapper<>(); rpQw.eq("role_id",dto.getId()); List<RolePermission> list = iRolePermissionService.list(rpQw); for (RolePermission rp : list) { boolean flag = true; for (String id : permissionIdList) { if(Objects.equals(id,rp.getPermissionId())) { flag = false; break; } } if(flag) { permissionIdList.add(rp.getPermissionId()); } } } List<PermissionDTO> permissionDTOList = new ArrayList<>(); for (String id : permissionIdList) { Permission permission = iPermissionService.getById(id); if(permission != null) { if(Objects.equals(permission.getType(),CommonConstant.PERMISSION_OPERATION)) { continue; } permissionDTOList.add(new PermissionDTO().setTitle(permission.getTitle()).setPath(permission.getPath())); } } user.setPermissions(permissionDTOList); return user; } }
五,相关作品展示
基于Java开发、Python开发、PHP开发、C#开发等相关语言开发的实战项目
基于Nodejs、Vue等前端技术开发的前端实战项目
基于微信小程序和安卓APP应用开发的相关作品
基于51单片机等嵌入式物联网开发应用
基于各类算法实现的AI智能应用
基于大数据实现的各类数据管理和推荐系统