SpringBoot+Mybatis+Thymeleaf+Mysql实现的送水公司后台管理系统(功能包含客户管理,送水工管理、送水历史管理、计算工资、统计送水次数等)
SpringBoot+Mybatis+Thymeleaf+Mysql实现的送水公司后台管理系统(功能包含客户管理,送水工管理、送水历史管理、计算工资、统计送水次数等)
·
SpringBoot+Mybatis+Thymeleaf+Mysql实现的送水公司后台管理系统
本系统是一个在线的送水公司的后台管理系统,通过后台管理,可以方便的将客户信息以及送水工的送水信息以及工资等汇总在一起,方便了统一的管理,提高了公司业务效率,节省了线下管理成本。
(文末查看完整源码)
实现功能截图
登录
客户管理
送水工管理
模糊搜索
送水历史管理
计算工资
统计送水数量
系统功能
本系统实现了以下功能:
1、登录
2、客户管理
3、送水工管理
4、送水历史管理
5、送水次数统计
6、计算工资
等
使用技术
数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:SpringBoot+Mybatis+Thymeleaf+Maven
项目结构
代码
java端
实体类
Account.java
package com.minzu.entities;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* TODO
* @TableName("account")注解表示实体类Account对应数据库的tb_account表
* @author caojie
* @version 1.0
* @date 2021/10/21 16:15
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("account")
public class Account {
private Integer aid;
private String userName;
private String userPwd;
private String userEmail;
private String userMobile;
}
History.java
package com.minzu.entities;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* TODO: 送水历史管理的实体类,它关联了送水工实体和客户实体
* @author caojie
* @version 1.0
* @date 2021/10/26 8:31
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("history")
public class History {
/**
* 送水工编号
*/
private Integer hid;
/**
* 送水历史关联送水工
*/
private Worker worker;
/**
* 送水时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date sendWaterTime;
/**
* 送水历史关联的客户
*/
private Customer customer;
/**
* 送水数量
*/
private Integer sendWaterCount;
}
service层
AccountServiceImpl.java
package com.minzu.service.impl;
import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.minzu.entities.Account;
import com.minzu.mapper.AccountMapper;
import com.minzu.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* TODO:登录业务逻辑实现类
* 被@Service注解修饰的类是业务逻辑实现类
* @author
* @version 1.0
* @date 2021/10/21 16:25
*/
@Service
public class AccountServiceImpl implements AccountService {
/**
* service依赖mapper,程序运行期SpringBoot容器自动帮我们
* 按照类型装配(将AccountMapper对象自动装配到AccountServiceImpl里面)
*/
@Autowired
private AccountMapper accountMapper;
/**
* 处理用户登录的业务逻辑
* 步骤:
* 1 根据用户名查询对应的账户
* 2 判断账户对象(Account)是否为空
* 3 如果为空登录失败(数据库没有这个用户),返回false
* 4 如果非空,对表单输入的密码进行MD5加密
* 5 判断加密之后的密码和数据库的密码是否相等
* 6 如果相等登录成功,返回true
* 7 如果不相等登录失败,返回false
*
* @param userName 浏览器表单输入的用户名
* @param userPwd 浏览器表单输入的密码
* @return 登录成功返回true,否则返回false
*/
@Override
public boolean login(String userName, String userPwd) {
// 封装查询条件
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.eq("user_name",userName);
// 根据用户名查询对应的账户
Account account = accountMapper.selectOne(qw);
// 条件成立:表示没有对应的账户,登录失败,返回false
if (null == account) {
return false;
}
// 对表单输入的密码进行加密
// encodingPwd存储加密之后的密码
// String encodingPwd = DigestUtil.md5Hex(userPwd);
String encodingPwd = userPwd;
// 将加密之后的密码和数据库密码进行比较,条件成立:登录成功,返回true。否则登录失败,返回false
if (Objects.equals(encodingPwd,account.getUserPwd())) {
return true;
} else {
return false;
}
}
}
HistoryServiceImpl.java
package com.minzu.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.minzu.entities.History;
import com.minzu.mapper.HistoryMapper;
import com.minzu.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* TODO: 送水历史管理接口实现类
*
* @author
* @version 1.0
* @date 2021/10/26 8:56
*/
@Service
public class HistoryServiceImpl implements HistoryService {
@Autowired
private HistoryMapper historyMapper;
/**
* 查询所有的送水历史信息
* @return 送水历史列表
*/
@Override
public List<History> listHistory() {
return historyMapper.listHistory();
}
/**
* 添加送水历史
*
* @param history 表单采集的送水历史信息
* @return 受影响行数,大于0添加成功,否则添加失败
*/
@Override
public int saveHistory(History history) {
return historyMapper.saveHistory(history);
}
/**
* 根据送水历史ID查询对应的送水历史
* 用途:修改之前的数据回显
*
* @param hid 送水历史ID
* @return 送水历史信息
*/
@Override
public History getHistoryById(Integer hid) {
return historyMapper.getHistoryById(hid);
}
/**
* 修改送水历史
*
* @param history 表单采集的的送水历史信息
* @return update语句受影响行数,大于0修改成功,否则修改失败
*/
@Override
public int updateHistory(History history) {
return historyMapper.updateHistory(history);
}
/**
* 批量删除
*
* @param idList 需要批量删除的送水历史id列表
* @return 受影响行数,大于0批量删除成功,否批量删除失败
*/
@Override
public int batchDeleteHistory(String idList) {
// 字符串转换为List集合
String[] split = StrUtil.split(idList, ",");
List<Integer> ids = new ArrayList<>();
for (String id : split) {
if (StrUtil.isNotEmpty(id)) {
ids.add(Integer.parseInt(id));
}
}
return historyMapper.batchDeleteHistory(ids);
}
}
controller层
AccountController.java
package com.minzu.controller;
import com.minzu.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession;
/**
* TODO
*
* @author
* @version 1.0
* @date 2021/10/21 16:32
*/
@Controller
@Slf4j
public class AccountController {
/**
* Controller控制器依赖于业务逻辑层,将AccountService自动装配到控制器(AccountController对象)
*/
@Autowired
private AccountService accountService;
/**
* 该方法用来处理前端浏览器的登录请求,登录成功跳转到"送水工管理系统"主页面,登录失败返回index.html页面
* 步骤:
* 1 调用业务逻辑对象(AccountService)的login方法判断登录是否成功
* 2 登录成功跳转到"送水工管理系统"主页面
* 3 登录失败返回index.html页面,并给出提示"用户名或者密码错误"
* @param userName 浏览器表单采集的用户名
* @param userPwd 浏览器表单采集的密码
* @param model 用来在视图层和控制层之间传递数据的对象
* @return 登录成功跳转到"送水工管理系统"主页面,登录失败返回index.html页面
*/
@RequestMapping(value="/login",method = RequestMethod.POST)
public String login(String userName, String userPwd, Model model, HttpSession session) {
boolean result = accountService.login(userName, userPwd);
// 条件成立:登录成功,否则登录失败
if(result) {
//登陆成功,将表单输入的用户名传递到前端页面
session.setAttribute("currentUser",userName);
// 登录成功跳转到主页面
return "waterMainMenu";
} else {
model.addAttribute("loginFail","用户名或者密码错误");
return "index";
}
}
}
HistoryController.java
package com.minzu.controller;
import cn.hutool.core.util.StrUtil;
import com.minzu.entities.Customer;
import com.minzu.entities.History;
import com.minzu.entities.Worker;
import com.minzu.service.CustomerService;
import com.minzu.service.HistoryService;
import com.minzu.service.WorkerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.jws.WebParam;
import java.util.ArrayList;
import java.util.List;
/**
* TODO: 送水历史管理的控制器,处理送水历史管理所有的请求
*
* @author
* @version 1.0
* @date 2021/10/26 8:57
*/
@RequestMapping("/history")
@Controller
@Slf4j
public class HistoryController {
/**
* 自动装配送水历史管理业务逻辑对象HistoryService
*/
@Autowired
private HistoryService historyService;
/**
* 送水历史需要用到客户信息,自动装配客户业务逻辑
*/
@Autowired
private CustomerService customerService;
/**
* 送水历史需要用到客户信息,自动装配送水工业务逻辑
*/
@Autowired
private WorkerService workerService;
/**
* 点击“添加”按钮,跳转到“添加送水历史”页面,在送水历史新页面上显示所有的送水工信息和客户信息
* @param model
* @return “添加送水历史”页面
*/
@RequestMapping("/preSaveHis")
public String preSaveHistory(Model model) {
// 查询所有的送水工和客户信息
List<Worker> workerList = workerService.listWorker();
List<Customer> custList = customerService.listCustomer();
// 将送水工信息和客户信息渲染到前端页面上
model.addAttribute("custList",custList);
model.addAttribute("workerList",workerList);
return "historySave";
}
/**
* 在“添加送水历史页面”点击“提交”按钮,将送水历史信息持久化(insert插入)到数据库中,然后返回“送水历史列表”,重新
* 查询送水历史列表显示新添加的数据
* 步骤:
* 1 将客户ID和送水工ID注入到History对象
* 2 调用HistoryService对象的saveHistory方法将表单采集的数据持久化到数据库
* 3 重新“查询送水历史信息”,显示新添加的数据
* @param workerId 表单采集的送水工编号
* @param custId 表单采集的客户编号
* @param history 表单采集的送水历史信息
* @return 重定向到送水历史列表路径
*/
@RequestMapping(value = "/saveHis",method = RequestMethod.POST)
public String saveHistory(Integer workerId,Integer custId,History history) {
log.info("workerId = "+workerId);
log.info("custId = "+custId);
log.info("history = "+history);
Worker worker = new Worker();
worker.setWid(workerId);
Customer customer = new Customer();
customer.setCid(custId);
// History注入送水功和客户信息
history.setWorker(worker);
history.setCustomer(customer);
// 持久化History对象
// rows 返回执行insert 语句受影响行数
int rows = historyService.saveHistory(history);
log.info("save History rows = "+rows);
return "redirect:/history/listHis";
}
/**
* 点击“送水历史管理”查询所有的送水历史信息
* 返回“送水历史列表”页面
* @param model
*/
@RequestMapping("/listHis")
public String listHistory(Model model) {
List<History> hisList = historyService.listHistory();
model.addAttribute("hisList",hisList);
log.info("history size "+hisList.size());
return "historyList";
}
/**
* 在“送水历史列表”页面,点击“修改”按钮,根据ID查询对应的“送水历史”信息,然后将信息渲染到前端页面
* 步骤:
* 1 查询所有客户信息
* 2 查询所有送水工信息
* 3 根据ID查询对应的送水历史信息
* 4 将以上信息渲染到前端页面上
* 5 跳转到“修改送水历史”页面
* @param hid 送水历史ID
* @param model
* @return “修改送水历史”页面
*/
@RequestMapping("/preUpdateHis/{hid}")
public String preUpdateHistory(@PathVariable("hid") Integer hid, Model model) {
List<Customer> custList = customerService.listCustomer();
List<Worker> workerList = workerService.listWorker();
History history = historyService.getHistoryById(hid);
// 将查询的数据渲染到前端页面,完成数据的回显
model.addAttribute("custList",custList);
model.addAttribute("workerList",workerList);
model.addAttribute("history",history);
// 跳转到“修改送水历史”页面
return "historyUpdate";
}
/**
* 点击“提交”按钮修改送水历史信息,修改完毕重定向执行“送水历史列表”,显示已修改的“送水历史信息”
* 步骤:
* 1 将送水工ID和客户ID注入到History对象
* 2 调用HistoryService对象的updateHistory方法完成修改
* 3 修改完毕重定向执行“送水历史列表”
* @param workerId 送水历史对应的送水工ID
* @param custId 送水历史对应的客户ID
* @param history 送水历史信息
* @return 重定向执行“送水历史列表”
*/
@RequestMapping(value="/updateHis",method=RequestMethod.POST)
public String updateHistory(Integer workerId,Integer custId,History history) {
log.info(" update custId id = "+custId);
log.info(" update worker id = "+workerId);
log.info(" update History = "+history);
Worker worker = new Worker();
worker.setWid(workerId);
Customer customer = new Customer();
customer.setCid(custId);
history.setCustomer(customer);
history.setWorker(worker);
// 修改送水历史,返回受影响行数
int rows = historyService.updateHistory(history);
log.info("update history rows = "+rows);
return "redirect:/history/listHis";
}
/**
* 处理批量删除请求
* @param idList 前端传入的要删除的送水历史id列表
* @return OK 批量删除成功,Fail表示批量删除失败
*/
@RequestMapping(value="/batchDeleteHistory",method = RequestMethod.POST)
@ResponseBody
public String batchDeleteHistory(String idList) {
// 调用业务逻辑层方法进行批量删除
int rows = historyService.batchDeleteHistory(idList);
if (rows > 0) {
return "OK";
} else {
return "Fail";
}
}
}
完整源码
觉得有用,记得一键三连哦!

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)