基于Springboot实现送水公司信息管理
作者主页:
简介:Java领域优质创作者、CSDN博客专家 Java项目、简历模板、学习资料、面试题库、技术互助
文末获取源码
项目编号:BS-XX-014
项目描述
springboot实现的送水后台管理系统
运行环境
jdk8+tomcat7+mysql+IntelliJ IDEA+maven
项目技术(必填)
SpringBoot+mybatis
数据库文件(可选)
压缩包自带
依赖包文件(可选)
maven项目
项目运行截图:

系统主界面
客户管理

送水工管理

送水历史订单

工资计算

统计送水数量

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 znz
* @version 1.0
* @date 2022/1/2 16:25
*/public class AccountServiceImpl implements AccountService { /**
* service依赖mapper,程序运行期SpringBoot容器自动帮我们
* 按照类型装配(将AccountMapper对象自动装配到AccountServiceImpl里面)
*/
private AccountMapper accountMapper; /**
* 处理用户登录的业务逻辑
* 步骤:
* 1 根据用户名查询对应的账户
* 2 判断账户对象(Account)是否为空
* 3 如果为空登录失败(数据库没有这个用户),返回false
* 4 如果非空,对表单输入的密码进行MD5加密
* 5 判断加密之后的密码和数据库的密码是否相等
* 6 如果相等登录成功,返回true
* 7 如果不相等登录失败,返回false
*
* @param userName 浏览器表单输入的用户名
* @param userPwd 浏览器表单输入的密码
* @return 登录成功返回true,否则返回false
*/
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); // 将加密之后的密码和数据库密码进行比较,条件成立:登录成功,返回true。否则登录失败,返回false
if (Objects.equals(encodingPwd,account.getUserPwd())) { return true;
} else { return false;
}
}
}
package com.minzu.service.impl;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;import com.minzu.entities.Customer;import com.minzu.mapper.CustomerMapper;import com.minzu.service.CustomerService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;/**
* TODO: 客户管理业务逻辑接口的实现类
* 被@Service注解修饰的类是接口实现类,SpringBoot启动的时候会自动注入
* @author znz
* @version 1.0
* @date 2022/1/1 8:27
*/public class CustomerServiceImpl implements CustomerService { /**
* 自动装配客户管理Mapper接口
*/
private CustomerMapper customerMapper; /**
* 查询所有的客户信息
*
* @return 客户列表
*/
public List<Customer> listCustomer() { return customerMapper.selectList(null);
} /**
* 添加客户信息
*
* @param customer 需要添加的客户对象
* @return 受影响行数,大于0添加成功,否则添加失败
*/
public int saveCustomer(Customer customer) { return customerMapper.insert(customer);
} /**
* 根据客户名称搜索满足条件的客户列表
* 例如:例如:使用模糊查询,搜索所有包含“老”的客户信息
* 步骤:
* 1 定义QueryWrapper对象
* 2 定义查询条件
* 3 调用CustomerMapper对象的selectList方法,将QueryWrapper对象注入到该方法中
* 4 返回搜索结果
* @param userName 搜索的查询条件
* @return 满足条件的客户列表
*/
public List<Customer> searchCustomer(String userName) {
QueryWrapper<Customer> qw = new QueryWrapper<>();
qw.like("cust_name",userName);
List<Customer> custList = customerMapper.selectList(qw); return custList;
} /**
* 根据客户ID删除客户信息
* 步骤:
* 1 创建QueryWrapper对象
* 2 设置要删除的条件
* 3 根据id删除客户信息,返回受影响行数
* @param cid 客户ID
* @return 受影响行数,大于0删除成功,否则删除失败
*/
public int deleteCustomerById(Integer cid) {
QueryWrapper<Customer> qw = new QueryWrapper<>();
qw.eq("cid",cid); return customerMapper.delete(qw);
} /**
* 根据客户id查询对应的客户信息
* 步骤:
* 1 创建QueryWrapper对象
* 2 设置查询条件
* 3 调用CustomerMapper对象selectOne方法,并将QueryWrapper对象注入到该方法中,返回客户信息
* @param cid 客户id
* @return 客户信息
*/
public Customer getCustomerById(Integer cid) {
QueryWrapper<Customer> qw = new QueryWrapper<>();
qw.eq("cid",cid); return customerMapper.selectOne(qw);
} /**
* 修改客户信息
* 步骤:
* 1 创建QueryWrapper对象
* 2 设置要修改的条件(根据ID进行修改)
* 3 调用CustomerMapper的update方法修改客户信息,并返回受影响行数
* @param customer 采集的客户信息
* @return 受影响行数
*/
public int updateCustomer(Customer customer) {
QueryWrapper<Customer> qw = new QueryWrapper<>();
qw.eq("cid",customer.getCid()); return customerMapper.update(customer,qw);
}
}
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 znz
* @version 1.0
* @date 2022/1/3 8:56
*/public class HistoryServiceImpl implements HistoryService {
private HistoryMapper historyMapper; /**
* 查询所有的送水历史信息
* @return 送水历史列表
*/
public List<History> listHistory() { return historyMapper.listHistory();
} /**
* 添加送水历史
*
* @param history 表单采集的送水历史信息
* @return 受影响行数,大于0添加成功,否则添加失败
*/
public int saveHistory(History history) { return historyMapper.saveHistory(history);
} /**
* 根据送水历史ID查询对应的送水历史
* 用途:修改之前的数据回显
*
* @param hid 送水历史ID
* @return 送水历史信息
*/
public History getHistoryById(Integer hid) { return historyMapper.getHistoryById(hid);
} /**
* 修改送水历史
*
* @param history 表单采集的的送水历史信息
* @return update语句受影响行数,大于0修改成功,否则修改失败
*/
public int updateHistory(History history) { return historyMapper.updateHistory(history);
} /**
* 批量删除
*
* @param idList 需要批量删除的送水历史id列表
* @return 受影响行数,大于0批量删除成功,否批量删除失败
*/
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);
}
}
package com.minzu.service.impl;import cn.hutool.core.util.StrUtil;import com.minzu.entities.Salary;import com.minzu.entities.Worker;import com.minzu.mapper.SalaryMapper;import com.minzu.service.SalaryService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.text.SimpleDateFormat;import java.util.*;import java.util.stream.Collectors;/**
* TODO: 计算工资业务逻辑实现类
* @author znz
* @version 1.0
* @date 2022/1/2 8:38
*/public class SalaryServiceImpl implements SalaryService { /**
* 自动装配SalaryMapper对象
*/
private SalaryMapper salaryMapper; /**
* 计算所有送水工的工资
* @return 工资列表
*/
public List<Salary> listCalcSalary() { return salaryMapper.listCalcSalary();
} /**
* 根据条件计算某一段时间的送水工工资
*
* @param startDate 开始时间
* @param endDate 结束时间
* @return 工资列表
*/
public List<Salary> listCalcSalaryByCondition(String startDate, String endDate) { // 条件成立:表示输入的结束时间为Null,将系统当前时间作为结束时间
if(StrUtil.isEmpty(endDate)){ long currentTime = System.currentTimeMillis(); Date dt = new Date(currentTime); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
endDate = sdf.format(dt);
} // salaryList 在某个时间段已经为客户送过水的送水工信息
List<Salary> salaryList = salaryMapper.listCalcSalaryByCondition(startDate, endDate); // 没有为客户送过水的送水工信息
List<Worker> workerList = salaryMapper.queryNonSendWaterWorker(); // 获取以送水的送水工名称
List<String> workerNameList =
salaryList.stream()
.map(Salary::getWorkerName)
.collect(Collectors.toList()); // 将没有送水的送水工信息合并到salaryList
// 遍历workerList,将worker对象的数据注入到Salary对象中,让后添加到salaryList集合
workerList.forEach(worker->{ // 条件成立:表示没有没有送水的送水工在salaryList集合中不存在,将其放入集合
if (!workerNameList.contains(worker.getWorkerName())){ Salary sa = new Salary();
sa.setWorkerName(worker.getWorkerName());
sa.setWorkerSalary(worker.getWorkerSalary());
sa.setWorkerMoney(worker.getWorkerMoney()); // 没有送水的送水工默认送水数量为0
sa.setSendWaterCount(0); // 没有送水的送水工默认实发工资为基本工资
sa.setFinalSalary(Double.valueOf(worker.getWorkerSalary()));
salaryList.add(sa);
}
}); // 将“实发工资”按照降序排序
// 需要对每个送水工的”实发工资“进行比较
Collections.sort(salaryList,(o1,o2)->{ if(o1.getFinalSalary() > o2.getFinalSalary()){ return -1;
} else if (o1.getFinalSalary() < o2.getFinalSalary()){ return 1;
} else { return 0;
}
});// Collections.sort(salaryList, new Comparator<Salary>() {// @Override// public int compare(Salary o1, Salary o2) {// if(o1.getFinalSalary() > o2.getFinalSalary()){// return -1;// } else if(o1.getFinalSalary() < o2.getFinalSalary()) {// return 1;// } else {// return 0;// }// }// });
return salaryList;
}
}
package com.minzu.service.impl;import com.minzu.entities.WaterDetails;import com.minzu.mapper.WaterDetailsMapper;import com.minzu.service.WaterDetailsService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;/**
* TODO
*
* @author znz
* @version 1.0
* @date 2022/1/2 15:36
*/public class WaterDetailsServiceImpl implements WaterDetailsService {
private WaterDetailsMapper waterDetailsMapper; /**
* 查询每个送水工送水的详细信息
*
* @return 送水信息列表
*/
public List<WaterDetails> queryWaterDetails() { return waterDetailsMapper.queryWaterDetails();
}
}