项目编号:BS-XX-192
一,环境介绍
语言环境:Java: jdk1.8
数据库:Mysql: mysql5.7
应用服务器:Tomcat: tomcat8.5.31
开发工具:IDEA或eclipse
开发技术:Springboot+Vue+HTML
二,项目简介
科学技术的快速更新和发展,有效的推动了计算机技术的进步,从而为计算机技术在社会上的推广运用奠定了坚实的基础。计算机的出现有限的推动了社会各行各业的进步与发展,为人类历史文明与文化的传播提供了有效的路径,帮助人类的发展制造了大量的财富。由于科学技术是社会发展的第一生产力,而科学技术发展的组成就是计算机技术的运用与推广。近年来,因其计算机技术的发展,其应用领域已经从刚开始的军事和科学研究领域逐步蔓延到人们生产、生活等各个方面。如今,人类社会发展从工业化走向高度信息化,计算机技术对人们的影响也在日渐增大。
随着信息化时代的到来,管理系统都趋向于智能化、系统化,防疫物资管理系统也不例外,但目前国内仍都使用人工管理,市场规模越来越大,同时信息量也越来越庞大,人工管理显然已无法应对时代的变化。计算机具有最为普通的存储功能,运算和控制功能,输入输出功能。这些功能,能够很快提高效率,节约时间,不断缩小计算成本,人力成本,同时他比手工化操作更具有科学性,规范性,准确性。所以防疫物资管理系统能很好地解决这一问题,轻松应对防疫物资管理平时的工作,既能提高人力物力财力,又能加快工作的效率,取代人工管理是必然趋势。
该防疫物资管理系统以SpringBoot作为框架,B/S模式以及MySql作为后台运行的数据库,同时使用Tomcat用为系统的服务器。本系统主要包括首页、个人中心、用户管理、物资管理、物资类型管理、物资租借、在线交流管理社区公告管理、新闻资讯管理、租赁表管理、外来人员报备等功能,通过这些功能的实现基本能够满足日常防疫物资管理的操作。
本文着重阐述了防疫物资管理系统的分析、设计与实现,首先介绍开发系统和环境配置、数据库的设计,接着说明功能模块的详细实现,最后进行了总结。
普通用户用例
管理员
超级管理员
三,系统展示
用户注册
登录
系统首页
物资商品
购物车
公告管理
后台管理
其它界面展示略
四,核心代码展示
package com.example.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; import com.example.common.Result; import com.example.common.ResultCode; import com.example.entity.AdminInfo; import com.example.service.AdminInfoService; import com.example.exception.CustomException; import com.example.common.ResultCode; import com.example.vo.AdminInfoVo; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.example.service.*; import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Value; import cn.hutool.core.util.StrUtil; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @RestController @RequestMapping(value = "/adminInfo") public class AdminInfoController { @Resource private AdminInfoService adminInfoService; @PostMapping public Result<AdminInfo> add(@RequestBody AdminInfoVo adminInfo) { adminInfoService.add(adminInfo); return Result.success(adminInfo); } @DeleteMapping("/{id}") public Result delete(@PathVariable Long id) { adminInfoService.delete(id); return Result.success(); } @PutMapping public Result update(@RequestBody AdminInfoVo adminInfo) { adminInfoService.update(adminInfo); return Result.success(); } @GetMapping("/{id}") public Result<AdminInfo> detail(@PathVariable Long id) { AdminInfo adminInfo = adminInfoService.findById(id); return Result.success(adminInfo); } @GetMapping public Result<List<AdminInfoVo>> all() { return Result.success(adminInfoService.findAll()); } @GetMapping("/page/{name}") public Result<PageInfo<AdminInfoVo>> page(@PathVariable String name, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize, HttpServletRequest request) { return Result.success(adminInfoService.findPage(name, pageNum, pageSize, request)); } @PostMapping("/register") public Result<AdminInfo> register(@RequestBody AdminInfo adminInfo) { if (StrUtil.isBlank(adminInfo.getName()) || StrUtil.isBlank(adminInfo.getPassword())) { throw new CustomException(ResultCode.PARAM_ERROR); } return Result.success(adminInfoService.add(adminInfo)); } /** * 批量通过excel添加信息 * @param file excel文件 * @throws IOException */ @PostMapping("/upload") public Result upload(MultipartFile file) throws IOException { List<AdminInfo> infoList = ExcelUtil.getReader(file.getInputStream()).readAll(AdminInfo.class); if (!CollectionUtil.isEmpty(infoList)) { // 处理一下空数据 List<AdminInfo> resultList = infoList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getName())).collect(Collectors.toList()); for (AdminInfo info : resultList) { adminInfoService.add(info); } } return Result.success(); } @GetMapping("/getExcelModel") public void getExcelModel(HttpServletResponse response) throws IOException { // 1. 生成excel Map<String, Object> row = new LinkedHashMap<>(); row.put("name", "admin"); row.put("password", "123456"); row.put("nickName", "管理员"); row.put("sex", "男"); row.put("age", 22); row.put("birthday", "TIME"); row.put("phone", "18843232356"); row.put("address", "上海市"); row.put("code", "111"); row.put("email", "aa@163.com"); row.put("cardId", "342425199001116372"); row.put("level", 1); List<Map<String, Object>> list = CollUtil.newArrayList(row); // 2. 写excel ExcelWriter writer = ExcelUtil.getWriter(true); writer.write(list, true); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); response.setHeader("Content-Disposition","attachment;filename=adminInfoModel.xlsx"); ServletOutputStream out = response.getOutputStream(); writer.flush(out, true); writer.close(); IoUtil.close(System.out); } }
package com.example.controller; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import com.example.common.Result; import com.example.common.ResultCode; import com.example.entity.Account; import com.example.entity.AuthorityInfo; import com.example.exception.CustomException; import com.example.entity.AdminInfo; import com.example.entity.BusinessInfo; import com.example.entity.UserInfo; import com.example.service.AdminInfoService; import com.example.service.BusinessInfoService; import com.example.service.UserInfoService; import org.springframework.web.bind.annotation.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import cn.hutool.json.JSONUtil; import java.util.*; import java.util.stream.Collectors; @RestController public class AccountController { @Value("${authority.info}") private String authorityStr; @Resource private AdminInfoService adminInfoService; @Resource private BusinessInfoService businessInfoService; @Resource private UserInfoService userInfoService; /** * 用户登陆 * @param account * @param request * @return */ @PostMapping("/login") public Result<Account> login(@RequestBody Account account, HttpServletRequest request) { if (StrUtil.isBlank(account.getName()) || StrUtil.isBlank(account.getPassword()) || account.getLevel() == null) { throw new CustomException(ResultCode.PARAM_LOST_ERROR); } Integer level = account.getLevel(); Account login = new Account(); if (1 == level) { login = adminInfoService.login(account.getName(), account.getPassword()); } if (2 == level) { login = businessInfoService.login(account.getName(), account.getPassword()); } if (3 == level) { login = userInfoService.login(account.getName(), account.getPassword()); } request.getSession().setAttribute("user", login);//设置session return Result.success(login); } @PostMapping("/register")//注册 public Result<Account> register(@RequestBody Account account) { Integer level = account.getLevel(); Account login = new Account(); if (1 == level) {//超级管理员 AdminInfo info = new AdminInfo(); BeanUtils.copyProperties(account, info);//将account的属性copy到info对象中 login = adminInfoService.add(info); } if (2 == level) {//普通管理员 BusinessInfo info = new BusinessInfo(); BeanUtils.copyProperties(account, info); login = businessInfoService.add(info); } if (3 == level) {//普通社区用户 UserInfo info = new UserInfo(); BeanUtils.copyProperties(account, info); login = userInfoService.add(info); } return Result.success(login); } @GetMapping("/logout") public Result logout(HttpServletRequest request) { request.getSession().setAttribute("user", null); return Result.success(); } @GetMapping("/auth") public Result getAuth(HttpServletRequest request) { Object user = request.getSession().getAttribute("user"); if(user == null) { return Result.error("401", "未登录"); } return Result.success(user); } @GetMapping("/getAccountInfo") public Result<Object> getAccountInfo(HttpServletRequest request) { Account account = (Account) request.getSession().getAttribute("user"); if (account == null) { return Result.success(new Object()); } Integer level = account.getLevel(); if (1 == level) { return Result.success(adminInfoService.findById(account.getId())); } if (2 == level) { return Result.success(businessInfoService.findById(account.getId())); } if (3 == level) { return Result.success(userInfoService.findById(account.getId())); } return Result.success(new Object()); } @GetMapping("/getSession") public Result<Map<String, String>> getSession(HttpServletRequest request) { Account account = (Account) request.getSession().getAttribute("user"); if (account == null) { return Result.success(new HashMap<>(1)); } Map<String, String> map = new HashMap<>(1); map.put("username", account.getName()); return Result.success(map); } @GetMapping("/getAuthority")//获取登录身份级别信息 public Result<List<AuthorityInfo>> getAuthorityInfo() { List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class); return Result.success(authorityInfoList); } /** * 获取当前用户所能看到的模块信息 * @param request * @return */ @GetMapping("/authority") public Result<List<Integer>> getAuthorityInfo(HttpServletRequest request) { Account user = (Account) request.getSession().getAttribute("user"); if (user == null) { return Result.success(new ArrayList<>()); } JSONArray objects = JSONUtil.parseArray(authorityStr); for (Object object : objects) { JSONObject jsonObject = (JSONObject) object; if (user.getLevel().equals(jsonObject.getInt("level"))) { JSONArray array = JSONUtil.parseArray(jsonObject.getStr("models")); List<Integer> modelIdList = array.stream().map((o -> { JSONObject obj = (JSONObject) o; return obj.getInt("modelId"); })).collect(Collectors.toList()); return Result.success(modelIdList); } } return Result.success(new ArrayList<>()); } @GetMapping("/permission/{modelId}") public Result<List<Integer>> getPermission(@PathVariable Integer modelId, HttpServletRequest request) { List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class); Account user = (Account) request.getSession().getAttribute("user"); if (user == null) { return Result.success(new ArrayList<>()); } Optional<AuthorityInfo> optional = authorityInfoList.stream().filter(x -> x.getLevel().equals(user.getLevel())).findFirst(); if (optional.isPresent()) { Optional<AuthorityInfo.Model> firstOption = optional.get().getModels().stream().filter(x -> x.getModelId().equals(modelId)).findFirst(); if (firstOption.isPresent()) { List<Integer> info = firstOption.get().getOperation(); return Result.success(info); } } return Result.success(new ArrayList<>()); } @PutMapping("/updatePassword") public Result updatePassword(@RequestBody Account info, HttpServletRequest request) { Account account = (Account) request.getSession().getAttribute("user"); if (account == null) { return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg); } String oldPassword = SecureUtil.md5(info.getPassword()); if (!oldPassword.equals(account.getPassword())) { return Result.error(ResultCode.PARAM_PASSWORD_ERROR.code, ResultCode.PARAM_PASSWORD_ERROR.msg); } info.setPassword(SecureUtil.md5(info.getNewPassword())); Integer level = account.getLevel(); if (1 == level) { AdminInfo adminInfo = new AdminInfo(); BeanUtils.copyProperties(info, adminInfo); adminInfoService.update(adminInfo); } if (2 == level) { BusinessInfo businessInfo = new BusinessInfo(); BeanUtils.copyProperties(info, businessInfo); businessInfoService.update(businessInfo); } if (3 == level) { UserInfo userInfo = new UserInfo(); BeanUtils.copyProperties(info, userInfo); userInfoService.update(userInfo); } info.setLevel(level); info.setName(account.getName()); // 清空session,让用户重新登录 request.getSession().setAttribute("user", null); return Result.success(); } @PostMapping("/resetPassword") public Result resetPassword(@RequestBody Account account) { Integer level = account.getLevel(); if (1 == level) { AdminInfo info = adminInfoService.findByUserName(account.getName()); if (info == null) { return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg); } info.setPassword(SecureUtil.md5("123456")); adminInfoService.update(info); } if (2 == level) { BusinessInfo info = businessInfoService.findByUserName(account.getName()); if (info == null) { return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg); } info.setPassword(SecureUtil.md5("123456")); businessInfoService.update(info); } if (3 == level) { UserInfo info = userInfoService.findByUserName(account.getName()); if (info == null) { return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg); } info.setPassword(SecureUtil.md5("123456")); userInfoService.update(info); } return Result.success(); } }
五,相关作品展示
基于Java开发、Python开发、PHP开发、C#开发等相关语言开发的实战项目
基于Nodejs、Vue等前端技术开发的前端实战项目
基于微信小程序和安卓APP应用开发的相关作品
基于51单片机等嵌入式物联网开发应用
基于各类算法实现的AI智能应用
基于大数据实现的各类数据管理和推荐系统