Material Management | Design and implementation of epidemic prevention material management system based on Spring Boot technology

Author Home Page: Programming Compass

About the author: High-quality creator in the Java field, CSDN blog expert, CSDN content partner, Nuggets guest author, Alibaba Cloud blog expert, 51CTO guest author, many years of architect design experience, Tencent classroom resident lecturer

Main contents: Java projects, Python projects, front-end projects, artificial intelligence and big data, resume templates, study materials, interview question bank, technical mutual assistance

Collect, like and don’t get lost. It’s good to follow the author.

Get the source code at the end of the article 

 Project number: BS-XX-192

1. Introduction to the environment

Locale: Java: jdk1.8

Database: Mysql: mysql5.7

Application server: Tomcat: tomcat8.5.31

Development tools: IDEA or eclipse

Development technology: Springboot+Vue+HTML

2. Project Introduction

The rapid update and development of science and technology have effectively promoted the progress of computer technology, thus laying a solid foundation for the promotion and application of computer technology in society. The emergence of computers has greatly promoted the progress and development of all walks of life in society, provided an effective path for the spread of human historical civilization and culture, and helped human development create a large amount of wealth. Since science and technology are the primary productive forces in social development, the development of science and technology consists of the application and promotion of computer technology. In recent years, due to the development of computer technology, its application fields have gradually spread from the initial military and scientific research fields to all aspects of people's production and life. Today, human society has developed from industrialization to high informatization, and the impact of computer technology on people is also increasing day by day.

With the advent of the information age, management systems tend to be intelligent and systematic, and the epidemic prevention material management system is no exception. However, manual management is still used in China. The market size is getting larger and larger, and the amount of information is also increasing. It is huge and manual management is obviously unable to cope with the changes of the times. Computers have the most common storage functions, computing and control functions, and input and output functions. These functions can quickly improve efficiency, save time, and continuously reduce computing costs and labor costs. At the same time, they are more scientific, standardized, and accurate than manual operations. Therefore, the epidemic prevention material management system can solve this problem well and easily handle the daily work of epidemic prevention material management. It can not only improve human, material and financial resources, but also speed up the work efficiency. It is an inevitable trend to replace manual management.

The epidemic prevention material management system uses SpringBoot as the framework, B/S mode and MySql as the database running in the background, and uses Tomcat as the system server. This system mainly includes functions such as home page, personal center, user management, material management, material type management, material leasing, online communication management, community announcement management, news information management, rental list management, outsider reporting, etc. The realization of these functions is basically Able to meet the daily operations of epidemic prevention material management.

This article focuses on the analysis, design and implementation of the epidemic prevention material management system. It first introduces the development system and environment configuration, and the design of the database, then explains the detailed implementation of the functional modules, and finally makes a summary.

Common user use cases

administrator

super administrator

3. System display

User registration

Log in

System home page

Material goods

shopping cart

Announcement management

Backstage management

Other interfaces are briefly shown

4. Core code display

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", "[email protected]");
		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();
    }
}

5. Display of related works

Practical projects based on Java development, Python development, PHP development, C# development and other related languages

Front-end practical projects developed based on Nodejs, Vue and other front-end technologies

Related works based on WeChat applet and Android APP application development

Development and application of embedded Internet of Things based on 51 microcontroller and other embedded devices

AI intelligent applications based on various algorithms

Various data management and recommendation systems based on big data

 

 

Guess you like

Origin blog.csdn.net/whirlwind526/article/details/133513437