@[TOC](博客目录)
# Spring Boot+Layui+mybatis+Mysql实现的垃圾回收管理系统
本系统为了解决垃圾回收乱象,通过利用系统的垃圾回收流程,提高垃圾回收效率,通过垃圾回收的申请,增删改查,垃圾运输申请、垃圾状态查询、以及系统公告、个人信息更新等,实现了垃圾回收的科学管理。
## 实现功能截图
登录注册
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/3dfc86a052304c3dbb1407d7e95e155a.png)
首页
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/7ed66f2af6954b14a442960514f3bba6.png)
垃圾回收添加
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/7fd19c322af6460393503b09bae2506f.png)
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/c8ff6327d7b84efd85efed37dcd66bce.png)
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/68764f708e3b4402bb6d039cf42f3460.png)
垃圾回收编辑、删除
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/898bf8d4e3f34b649f6e8c0259514a38.png)
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/88e0b5522b6a49a58412aa731eb2d5ac.png)
垃圾去向运出申请
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/6af8bb025ff944b09b503268de774022.png)
垃圾状态筛选
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/f2f0c05412fc4a138c992b3b96233cf0.png)
打包运输
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/da842671c9454e169c0b8cf78145d7e2.png)
系统公告
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/c845b5b77a164d9ca32ec00bee5e334e.png)
个人信息
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/de0df258ab014c74b405c0cd3ddb4cd4.png)
## 系统功能
本垃圾回收管理系统实现了以下功能:
1、登录、注册
2、垃圾回收管理(添加、编辑、删除、状态筛选)
3、垃圾去向运输申请
4、垃圾打包运输
5、系统公告
6、个人信息编辑
## 使用技术
数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:Spring Boot+Layui+mybatis
## 代码
实体类
Garbage.java
```java
package com.garbage.demo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.garbage.demo.common.Search;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 垃圾入库表
* </p>
*
* @author Code2Life
* 公众号:程序猿矛盾体
* @since 2020-10-15
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class Garbage implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 垃圾类型
*/
private Integer type;
/**
* 垃圾重量(单位:kg)
*/
private Double weight;
/**
* 状态(0为在厂,1为出厂)
*/
private Integer status;
private String origin;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
private LocalDateTime createTime;
private Integer transportId;
}
```
Transport.java
```java
package com.garbage.demo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 运输表
* </p>
*
* @author Code2Life
* 公众号:程序猿矛盾体
* @since 2020-10-15
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class Transport implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 目的地
*/
private String dest;
private Integer type;
/**
* 运出时间
*/
private LocalDate outTime;
/**
* 审核状态(0为申请中,1为申请成功,2为申请失败)
*/
private Integer status;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
private LocalDateTime createTime;
}
```
Service层
GarbageServiceImpl.java
```java
package com.garbage.demo.service.impl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.garbage.demo.entity.Garbage;
import com.garbage.demo.entity.Transport;
import com.garbage.demo.mapper.GarbageMapper;
import com.garbage.demo.service.IGarbageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.garbage.demo.service.ITransportService;
import com.garbage.demo.vo.request.RequestGarbageListByTypeVo;
import com.garbage.demo.vo.request.RequestGarbageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
/**
* <p>
* 垃圾入库表 服务实现类
* </p>
*
* @author Code2Life
* 公众号:程序猿矛盾体
* @since 2020-10-15
*/
@Service
public class GarbageServiceImpl extends ServiceImpl<GarbageMapper, Garbage> implements IGarbageService {
@Autowired
IGarbageService garbageService;
@Override
public IPage<Garbage> list(RequestGarbageListVo garbageListVo) {
IPage<Garbage> garbageIPage = new Page<>(garbageListVo.getDisplayStart(),
garbageListVo.getDisplayLength());
QueryWrapper<Garbage> wrapper = new QueryWrapper<>();
if(ObjectUtils.isNotEmpty(garbageListVo.getType())){
wrapper.eq("type",garbageListVo.getType());
}
if(ObjectUtils.isNotEmpty(garbageListVo.getStatus())){
wrapper.eq("status",garbageListVo.getStatus());
}
if(ObjectUtils.isNotEmpty(garbageListVo.getEntryTime())){
wrapper.like("create_time",garbageListVo.getEntryTime());
}
return page(garbageIPage,wrapper);
}
@Override
public IPage<Garbage> getByType(RequestGarbageListByTypeVo garbageListByTypeVo) {
IPage<Garbage> garbageIPage = new Page<>(garbageListByTypeVo.getDisplayStart()
,garbageListByTypeVo.getDisplayLength());
QueryWrapper<Garbage> wrapper = new QueryWrapper<>();
wrapper.eq("type",garbageListByTypeVo.getType());
wrapper.eq("status",0);
wrapper.isNull("transport_id");
if(ObjectUtils.isNotEmpty(garbageListByTypeVo.getEntryTime())){
String startTime = "";
String endTime = "";
String str = garbageListByTypeVo.getEntryTime();
char[] arr = str.toCharArray();
for(int i = 0; i<arr.length;i++){
if(arr[i] == ' '){
i+=2;
}else if(startTime.length()<10){
startTime += arr[i];
}else if(endTime.length()<10){
endTime += arr[i];
}
}
wrapper.between("create_time",startTime,endTime);
}
return page(garbageIPage,wrapper);
}
@Override
public IPage<Garbage> getByTransportId(Integer transportId, Integer limit, Integer page) {
IPage<Garbage> garbageIPage = new Page<>(page,limit);
QueryWrapper<Garbage> wrapper = new QueryWrapper<>();
wrapper.eq("transport_id",transportId);
return page(garbageIPage,wrapper);
}
@Override
public Double getWeightByTransportId(Integer transportId) {
QueryWrapper<Garbage> wrapper = new QueryWrapper<>();
wrapper.eq("transport_id",transportId);
ArrayList<Garbage> list = (ArrayList<Garbage>)garbageService.list(wrapper);
Double weight = 0.0;
for (Garbage g :list){
weight += g.getWeight();
}
return weight;
}
@Autowired
ITransportService transportService;
@Override
public void removeAllTransportId() {
QueryWrapper<Transport> tq = new QueryWrapper<>();
tq.eq("status",2);
ArrayList<Transport> ts = (ArrayList<Transport>)transportService.list(tq);
if(ts.isEmpty()){
return;
}
ArrayList<Integer> ids = new ArrayList<>();
for(Transport t :ts){
ids.add(t.getId());
}
UpdateWrapper<Garbage> garbageUpdateWrapper = new UpdateWrapper<>();
garbageUpdateWrapper.set("transport_id", null);
garbageUpdateWrapper.in("transport_id",ids);
garbageService.update(garbageUpdateWrapper);
}
}
```
TransportServiceImpl.java
```java
package com.garbage.demo.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.garbage.demo.entity.Garbage;
import com.garbage.demo.entity.Transport;
import com.garbage.demo.mapper.TransportMapper;
import com.garbage.demo.service.IGarbageService;
import com.garbage.demo.service.ITransportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.garbage.demo.vo.request.RequestTransportAddVo;
import com.garbage.demo.vo.request.RequestTransportListVo;
import com.garbage.demo.vo.response.ResponseTransportListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.security.Key;
import java.util.HashMap;
import java.util.Map;
/**
* <p>
* 运输表 服务实现类
* </p>
*
* @author Code2Life
* 公众号:程序猿矛盾体
* @since 2020-10-15
*/
@Service
public class TransportServiceImpl extends ServiceImpl<TransportMapper, Transport> implements ITransportService {
@Autowired
IGarbageService garbageService;
@Autowired
ITransportService transportService;
@Override
@Transactional
public boolean add(RequestTransportAddVo transportAddVo) {
Transport transport = new Transport();
BeanUtils.copyProperties(transportAddVo,transport);
transportService.save(transport);
//更新垃圾列表的运输id
UpdateWrapper<Garbage> wrapper = new UpdateWrapper<>();
wrapper.in("id",transportAddVo.getGarbageIds());
wrapper.set("transport_id",transport.getId());
return garbageService.update(wrapper);
}
@Override
public IPage<ResponseTransportListVo> list(RequestTransportListVo transportListVo) {
IPage<Transport> page = new Page<>(transportListVo.getDisplayStart(),
transportListVo.getDisplayLength());
QueryWrapper<Transport> wrapper = new QueryWrapper<>();
if(ObjectUtils.isNotEmpty(transportListVo.getType())){
wrapper.eq("type",transportListVo.getType());
}
if(ObjectUtils.isNotEmpty(transportListVo.getOutTime())){
wrapper.eq("out_time",transportListVo.getOutTime());
}
if(ObjectUtils.isNotEmpty(transportListVo.getStatus())){
wrapper.eq("status",transportListVo.getStatus());
}
return transportService.page(page,wrapper).convert(transport->{
ResponseTransportListVo listVo = new ResponseTransportListVo();
BeanUtils.copyProperties(transport,listVo);
listVo.setWeight(garbageService.getWeightByTransportId(transport.getId()));
return listVo;
});
}
@Autowired
TransportMapper transportMapper;
@Override
public void UpdateStatus() {
transportMapper.updateStatus();
}
}
```
controller层
GarbageController.java
```java
package com.garbage.demo.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.garbage.demo.common.Result;
import com.garbage.demo.entity.Garbage;
import com.garbage.demo.service.IGarbageService;
import com.garbage.demo.utils.StringConst;
import com.garbage.demo.vo.request.RequestDeleteVo;
import com.garbage.demo.vo.request.RequestGarbageAddVo;
import com.garbage.demo.vo.request.RequestGarbageListByTypeVo;
import com.garbage.demo.vo.request.RequestGarbageListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 垃圾入库表 前端控制器
* </p>
*
* @author Code2Life
* 公众号:程序猿矛盾体
* @since 2020-10-15
*/
@RestController
@RequestMapping("/garbage")
public class GarbageController {
@Autowired
private IGarbageService garbageService;
@PostMapping("/saveOrUpdate")
public Result saveOrUpdate(@RequestBody RequestGarbageAddVo requestGarbageAddVo){
String result;
if(requestGarbageAddVo.getWeight()<0){
return Result.getFailure().setMsg("重量输入错误!!");
}
if(ObjectUtils.isNotEmpty(requestGarbageAddVo.getId())){
result = "修改";
}else{
result = "添加";
}
Garbage garbage = new Garbage();
BeanUtils.copyProperties(requestGarbageAddVo,garbage);
if(garbageService.saveOrUpdate(garbage)){
return Result.getSuccess().setMsg(result + "成功!!!");
}else{
return Result.getFailure().setMsg(result + "失败!!!");
}
}
@DeleteMapping("/deleteByIds")
public Result delete(@RequestBody RequestDeleteVo requestDeleteVo){
if(ObjectUtils.isNotEmpty(requestDeleteVo.getIntegerIds())){
QueryWrapper<Garbage> garbageQueryWrapper = new QueryWrapper<>();
garbageQueryWrapper.isNull("transport_id");
garbageQueryWrapper.in("id",requestDeleteVo.getIntegerIds());
garbageService.remove(garbageQueryWrapper);
return Result.getSuccess().setMsg(StringConst.DELETE_SUCCESS);
}
return Result.getFailure().setMsg(StringConst.DELETE_ERROR);
}
@PostMapping("/list")
public Result list(@RequestBody RequestGarbageListVo garbageListVo){
IPage<Garbage> garbageIPage = garbageService.list(garbageListVo);
return Result.getSuccess().setData(garbageIPage);
}
@GetMapping("/getById/{id}")
public Result getById(@PathVariable Integer id){
return Result.getSuccess().setData(garbageService.getById(id));
}
@PostMapping("/getByType")
public Result getByType(@RequestBody RequestGarbageListByTypeVo garbageListByTypeVo){
IPage<Garbage> garbageIPage = garbageService.getByType(garbageListByTypeVo);
return Result.getSuccess().setData(garbageIPage);
}
@GetMapping("/getByTransportId/{transportId}")
public Result getByTransportId(@PathVariable Integer transportId
,@RequestParam(value = "limit") Integer limit,@RequestParam(value = "page") Integer page){
IPage<Garbage> garbageIPage = garbageService.getByTransportId(transportId,limit ,page);
return Result.getSuccess().setData(garbageIPage);
}
}
```
TransportController.java
```java
package com.garbage.demo.controller;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.garbage.demo.common.Result;
import com.garbage.demo.entity.Garbage;
import com.garbage.demo.entity.Transport;
import com.garbage.demo.service.IGarbageService;
import com.garbage.demo.service.ITransportService;
import com.garbage.demo.vo.request.RequestTransportAddVo;
import com.garbage.demo.vo.request.RequestTransportListVo;
import com.garbage.demo.vo.response.ResponseTransportListVo;
//import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.imageio.ImageIO;
/**
* <p>
* 运输表 前端控制器
* </p>
*
* @author Code2Life
* 公众号:程序猿矛盾体
* @since 2020-10-15
*/
@RestController
@RequestMapping("/transport")
public class TransportController {
@Autowired
ITransportService transportService;
@Autowired
IGarbageService garbageService;
@PostMapping("/add")
public Result add(@RequestBody RequestTransportAddVo transportAddVo){
if(transportService.add(transportAddVo)){
return Result.getSuccess().setMsg("提交成功!!!");
}
return Result.getFailure().setMsg("提交失败!!!");
}
@PostMapping("/list")
public Result list(@RequestBody RequestTransportListVo transportListVo){
IPage<ResponseTransportListVo> page = transportService.list(transportListVo);
return Result.getSuccess().setData(page);
}
@GetMapping("/packaging/{id}")
@Transactional
public Result packaging(@PathVariable Integer id){
UpdateWrapper<Garbage> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("transport_id",id);
updateWrapper.set("status",1);
garbageService.update(updateWrapper);
UpdateWrapper<Transport> transportUpdateWrapper = new UpdateWrapper<>();
transportUpdateWrapper.eq("id",id);
transportUpdateWrapper.set("status",3);
transportService.update(transportUpdateWrapper);
return Result.getSuccess().setMsg("已运输");
}
@GetMapping("/passOrRefuse/{b}/{id}")
public Result passOrRefuse(@PathVariable Boolean b, @PathVariable Integer id){
UpdateWrapper<Transport> transportUpdateWrapper = new UpdateWrapper<>();
transportUpdateWrapper.eq("id",id);
if(b){
transportUpdateWrapper.set("status",1);
}else{
transportUpdateWrapper.set("status",2);
}
transportService.update(transportUpdateWrapper);
return Result.getSuccess().setMsg("操作成功");
}
}
```
## 写在最后
如果运行代码中遇到问题,或者需要完整源码和报告,可以加博主V交流:Code2Life2
觉得有用,记得一键三连哦!