基于javaweb+mysql的ssm+maven快递代拿系统(java+ssm+bootstrap+shiro+mysql+html)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven快递代拿系统(java+ssm+bootstrap+shiro+mysql+html)
使用技术
采用 Spring + SpringMVC + MyBatisPlus,连接池采用 Druid,安全框架使用 Shiro,前端采用 Bootstrap + layer 实现。
支付采用支付宝沙箱环境,支付APP下载链接,点击这里。
支付账号:uceskd4358 sandbox.com 登录密码、支付密码:111111
注意:
请务必使用以上链接下载沙箱支付宝
,也务必使用以上账号登录。不要使用真实支付宝APP和真实支付宝账号登录。
运行环境
-
集成开发环境:IntelliJ IDEA
-
项目构建工具:Maven - 数据库:MYSQL 5.7+ - JDK版本:1.8 - Tomcat版本:Tomcat8
(1)首先请创建数据库: shell CREATE DATABASE IF NOT EXISTS `express-ssm` /*!40100 DEFAULT CHARACTER SET utf8 */
(2)导入项目 sql 文件夹下的 express-ssm.sql
文件。 (3)编辑项目中 src/main/resources/cnf/mysql.properties
文件,修改数据库连接信息: jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/express-ssm?useUnicode=true&useSSL=false&characterEncoding=utf-8 jdbc.username=root # MYSQL 用户名 jdbc.password=root # MYSQL 密码
运行
项目运行时,在tomcat中配置项目运行路径为http://localhost:8080/ 注意:后面不要带项目名,否则会运行出错;
默认账户
注:以下为本项目默认存在的用户名密码,请将本仓库项目在本地运行后使用以下密码登录。
| 权限 | 用户名 | 密码 | | 管理员 | admin | 123 | | 配送员 | 李四 | 123 | | 用户名 | 小红 | 123 |
List<FeedbackDto> list = globalFunction.feedback2dto(selectPage.getRecords());
Map<String,Object> map = new HashMap<>();
map.put("total", selectPage.getTotal());
map.put("rows", list);
return map;
}
/**
* 删除反馈
*/
@PostMapping("/delete")
public Msg deleteById(String[] ids) {
for(String id : ids) {
feedbackService.deleteById(id);
}
return Msg.ok();
}
/**
* 处理反馈
*/
@PostMapping("")
public Msg handleFeedback(String id, String content) {
if(StringUtils.isBlank(id) || StringUtils.isBlank(content)) {
return Msg.error("参数错误");
}
Feedback feedback = feedbackService.selectById(id);
// 设置处理人为当前用户
feedback.setStaffId(globalFunction.getUserId());
feedback.setResult(content);
// 0代表未处理,1代表已处理;默认为0
feedback.setStatus(1);
feedbackService.updateById(feedback);
return Msg.ok();
}
}
return Msg.ok(null,result);
}
/**
* 获取所有反馈
*/
@GetMapping("/list")
public Map listFeedback(Integer rows, Integer page, FeedbackSelectWrapper fsw, @RequestParam(defaultValue = "createDate") String order) {
// Get请求中文编码
try {
fsw.setName(globalFunction.iso8859ToUtf8(fsw.getName()));
fsw.setStaffName(globalFunction.iso8859ToUtf8(fsw.getStaffName()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 得到筛选条件
EntityWrapper<Feedback> feedbackWrapper = globalFunction.getFeedbackWrapper(fsw);
Page<Feedback> selectPage = feedbackService.selectPage(new Page<>(page, rows,order,false), feedbackWrapper);
List<FeedbackDto> list = globalFunction.feedback2dto(selectPage.getRecords());
Map<String,Object> map = new HashMap<>();
map.put("total", selectPage.getTotal());
map.put("rows", list);
return map;
}
/**
* 删除反馈
*/
@PostMapping("/delete")
public Msg deleteById(String[] ids) {
for(String id : ids) {
feedbackService.deleteById(id);
}
return Msg.ok();
}
/**
* 处理反馈
// 1、设置请求参数
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
// 页面跳转同步通知页面路径
alipayRequest.setReturnUrl(aliPaySetting.getReturnUrl());
// 服务器异步通知页面路径
alipayRequest.setNotifyUrl(aliPaySetting.getNotifyUrl());
// 2、SDK已经封装掉了公共参数,这里只需要传入业务参数,请求参数查阅开头Wiki
Map<String,String> map = new HashMap<>(16);
map.put("out_trade_no", expressId);
map.put("total_amount", String.valueOf(money));
map.put("subject", "快递代拿");
map.put("body", "快递代拿在线支付");
// 销售产品码
map.put("product_code","FAST_INSTANT_TRADE_PAY");
alipayRequest.setBizContent(JsonUtils.objectToJson(map));
response.setContentType("text/html;charset=utf-8");
try{
// 3、生成支付表单
AlipayTradePagePayResponse alipayResponse = alipayClient.pageExecute(alipayRequest);
if(alipayResponse.isSuccess()) {
String result = alipayResponse.getBody();
response.getWriter().write(result);
} else {
response.getWriter().write("error");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@GetMapping("/alipay/return")
public String alipayReturn(HttpServletRequest request, HttpServletResponse response) {
// 获取参数
Map<String,String> params = getPayParams(request);
try {
// 验证订单
boolean flag = expressPaymentService.validAlipay(params);
if(flag) {
// 验证成功后,修改订单状态为已支付
String orderId = params.get("out_trade_no");
/*
* 订单状态(与官方统一)
* WAIT_BUYER_PAY:交易创建,等待买家付款;
* TRADE_CLOSED:未付款交易超时关闭,或支付完成后全额退款;
* TRADE_SUCCESS:交易支付成功;
* TRADE_FINISHED:交易结束,不可退款
*/
// 获取支付宝订单号
express.setStatus(ExpressStatusEnum.ERROR.getIndex());
express.setStaffRemark(text);
expressService.updateById(express);
}
}
return Msg.ok();
}
}
/**
* 产生验证码图片的servlet
*/
public class VerifyCodeServlet extends HttpServlet {
private static final long serialVersionUID = -5051097528828603895L;
/**
* 验证码图片的宽度。
*/
private int width = 100;
/**
* 验证码图片的高度。
*/
private int height = 30;
/**
* 验证码字符个数
*/
private int codeCount = 4;
/**
* 字体高度
*/
private int fontHeight;
/**
* 干扰线数量
*/
private int interLine = 16;
}
}
private static final void doSetCookie(HttpServletRequest request, HttpServletResponse response, String cookieName,
String cookieValue, int cookieMaxage, String encodeString) {
try {
if (cookieValue == null) {
cookieValue = "";
} else {
cookieValue = URLEncoder.encode(cookieValue, encodeString);
}
Cookie cookie = new Cookie(cookieName, cookieValue);
if (cookieMaxage > 0)
cookie.setMaxAge(cookieMaxage);
if (null != request) {// 设置域名的cookie
String domainName = getDomainName(request);
// System.out.println(domainName);
if (!"localhost".equals(domainName)) {
cookie.setDomain(domainName);
}
}
cookie.setPath("/");
response.addCookie(cookie);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 得到cookie的域名(跨域访问)
*/
private static final String getDomainName(HttpServletRequest request) {
String domainName = null;
String serverName = request.getRequestURL().toString();
if (serverName == null || serverName.equals("")) {
domainName = "";
} else {
serverName = serverName.toLowerCase();
serverName = serverName.substring(7);
final int end = serverName.indexOf("/");
serverName = serverName.substring(0, end);
*/
@Controller
public class PageController {
@GetMapping("/")
public String showIndex() {
return "index";
}
@GetMapping("/login")
public String showLogin() {
return "login";
}
@GetMapping("/feedback")
public String showFeedBack() {
return "feedback";
}
@GetMapping("/search")
public String showSearch() {
return "search";
}
@GetMapping("/payment")
public String showPayment() {
return "payment";
}
@GetMapping("/payment/result")
public String showPaymentResult() {
return "payment_result";
}
@GetMapping("/admin/express")
public String showAExpress() {
return "admin/express";
}
@GetMapping("/admin/expressRecycle")
public String showExpressRecycle() {
return "admin/expressRecycle";
}
@GetMapping("/admin/staff")
public String showStaff() {
return "admin/staff";
}
// 画边框。
gd.setColor(Color.BLACK);
gd.drawRect(0, 0, width - 1, height - 1);
// 随机产生16条干扰线,使图象中的认证码不易被其它程序探测到。
gd.setColor(Color.gray);
for (int i = 0; i < interLine; i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
gd.drawLine(x, y, x + xl, y + yl);
}
// randomCode用于保存随机产生的验证码,以便用户登录后进行验证。
StringBuffer randomCode = new StringBuffer();
int red = 0, green = 0, blue = 0;
// 随机产生codeCount数字的验证码。
for (int i = 0; i < codeCount; i++) {
// 得到随机产生的验证码数字。
String strRand = String.valueOf(codeSequence[random.nextInt(36)]);
// 产生随机的颜色分量来构造颜色值,这样输出的每位数字的颜色值都将不同。
red = random.nextInt(255);
green = random.nextInt(255);
blue = random.nextInt(255);
// 用随机产生的颜色将验证码绘制到图像中。
//gd.setColor(new Color(red,green,blue));
gd.setColor(new Color(255,0,0));
gd.drawString(strRand, (i + 1) * codeX, codeY);
// 将产生的四个随机数组合在一起。
randomCode.append(strRand);
}
// 将四位数字的验证码保存到Session中。
HttpSession session = request.getSession();
session.setAttribute("validateCode", randomCode.toString());
// 禁止图像缓存。
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
// 将图像输出到Servlet输出流中。
ServletOutputStream sos = response.getOutputStream();
ImageIO.write(buffImg, "jpeg", sos);
sos.close();
}
}
Map<String,Object> map = new HashMap<>();
map.put("total", selectPage.getTotal());
map.put("rows", list);
return map;
}
/**
* 获取所有个人的订单
*/
@RequestMapping("/selfList")
public Map listSelfExpress(Integer rows, Integer page, ExpressSelectWrapper esw, @RequestParam(defaultValue = "createDate") String order) {
// Get请求中文编码
try {
esw.setName(globalFunction.iso8859ToUtf8(esw.getName()));
esw.setAddress(globalFunction.iso8859ToUtf8(esw.getAddress()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 得到筛选条件
EntityWrapper<Express> expressWrapper = globalFunction.getExpressWrapper(esw);
// 设置查找当前用户的订单
expressWrapper.eq("staff", globalFunction.getUserId());
Page<Express> selectPage = expressService.selectPage(new Page<>(page, rows, order, false), expressWrapper);
List<ExpressDto> list = globalFunction.express2dto(selectPage.getRecords());
Map<String,Object> map = new HashMap<>();
map.put("total", selectPage.getTotal());
map.put("rows", list);
return map;
}
/**
* 获取单个订单详情
*/
@GetMapping("/{id}")
public Msg getById(@PathVariable String id) {
Express express = expressService.selectById(id);
ExpressDto expressDto = globalFunction.express2dto(express);
return Msg.ok(null,expressDto);
}
/**
/**
* 用户反馈Controller
*/
@RestController
@RequestMapping("/admin/feedback")
public class FeedbackController {
@Autowired
private FeedbackService feedbackService;
@Autowired
private SysUserService userService;
@Autowired
private GlobalFunction globalFunction;
/**
* 获取所有反馈类型
*/
@GetMapping("/type/list")
public Msg listFeedbackType() {
List<Map<String,Object>> result = new ArrayList<>();
for(FeedbackTypeEnum enums :FeedbackTypeEnum.values()) {
Map<String,Object> map = new HashMap<>();
map.put("id",enums.getIndex());
map.put("name",enums.getName());
result.add(map);
}
return Msg.ok(null,result);
}
/**
* 获取所有反馈
*/
@GetMapping("/list")
public Map listFeedback(Integer rows, Integer page, FeedbackSelectWrapper fsw, @RequestParam(defaultValue = "createDate") String order) {
// Get请求中文编码
try {
fsw.setName(globalFunction.iso8859ToUtf8(fsw.getName()));
fsw.setStaffName(globalFunction.iso8859ToUtf8(fsw.getStaffName()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
* 支付Controller
*/
@Controller
@RequestMapping("/payment")
public class PaymentController {
@Value("${session.latest_express}")
private String SESSION_LATEST_EXPRESS;
@Value("${session.latest_payment}")
private String SESSION_LATEST_PAYMENT;
@Autowired
private ExpressService expressService;
@Autowired
private ExpressPaymentService expressPaymentService;
@Autowired
private AliPaySetting aliPaySetting;
@Autowired
private AlipayClient alipayClient;
/**
* 从客户Cookie中取出最新的一条订单信息
*/
@GetMapping("/express")
@ResponseBody
public Msg getExpress(HttpSession session) {
Express express = (Express)session.getAttribute(SESSION_LATEST_EXPRESS);
if(express != null) {
return Msg.ok(null,express);
} else {
return Msg.error("订单好像丢失了,请重新下单...");
}
}
/**
* 线下支付方式
* @param money 支付金额
*/
@PostMapping("/offline")
@ResponseBody
public Msg paymentOffline(Double money, HttpSession session) {
Express express = (Express)session.getAttribute(SESSION_LATEST_EXPRESS);
if(express == null || money == null) {
return Msg.error("参数错误");
}
}
}
/**
* 管理员订单Controller
*/
@RestController
@RequestMapping("/admin/express")
public class ExpressController {
@Autowired
private ExpressService expressService;
@Autowired
private GlobalFunction globalFunction;
@Autowired
private ExpressPaymentService expressPaymentService;
/**
* 获取订单的状态列表
*/
@GetMapping("/status")
public Msg listExpressStatus() {
List<Map<String,Object>> result = new ArrayList<>();
for(ExpressStatusEnum enums :ExpressStatusEnum.values()) {
Map<String,Object> map = new HashMap<>();
map.put("id",enums.getIndex());
* 更新用户信息
*/
@PostMapping("")
public Msg update(SysUser user) {
userService.updateById(user);
return Msg.ok();
}
/**
* 新增用户信息
*/
@PostMapping("/insert")
public Msg insert(SysUser user) {
UUID uuid = UUID.randomUUID();
user.setId(uuid.toString());
user.setRoleId(1);
user.setStatus(0);
user.setPassword(PasswordUtils.entryptPassword("123456"));
//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
user.setCreateDate(new Date());// new Date()为获取当前系统时间
user.setUpdateDate(new Date());
userService.insert(user);
return Msg.ok();
}
/**
* 获取用户信息
*/
@GetMapping("/{id}")
public Msg getById(@PathVariable String id) {
SysUser user = userService.selectById(id);
return Msg.ok(null,user);
}
/**
* 修改员工为在职
*/
@PostMapping("/active")
public Msg changeActive(String[] ids) {
changeUserStatus(ids, SysUserStatusEnum.ACTIVE.getIndex());
return Msg.ok();
}
/**
* 修改员工为冻结
return Msg.ok(null,staffs);
}
/**
* 获取所有职员
*/
@GetMapping("/list")
public Map listStaff(Integer rows, Integer page, SysUserSelectWrapper usw) {
// Get请求中文编码
try {
usw.setName(globalFunction.iso8859ToUtf8(usw.getName()));
usw.setAddress(globalFunction.iso8859ToUtf8(usw.getAddress()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 得到筛选条件
EntityWrapper<SysUser> userWrapper = globalFunction.getSysUserWrapper(usw);
// 不显示admin角色
userWrapper.ne("role_id", RoleEnum.ADMIN.getIndex());
Page<SysUser> selectPage = userService.selectPage(new Page<>(page, rows), userWrapper);
List<SysUserDto> list = globalFunction.sysUser2dto(selectPage.getRecords());
Map<String,Object> map = new HashMap<>();
map.put("total", selectPage.getTotal());
map.put("rows", list);
return map;
}
/**
* 更新用户信息
*/
@PostMapping("")
public Msg update(SysUser user) {
userService.updateById(user);
return Msg.ok();
}
/**
* 新增用户信息
*/
@PostMapping("/insert")
public Msg insert(SysUser user) {
map.put("name",enums.getName());
result.add(map);
}
return Msg.ok(null,result);
}
/**
* 获取所有反馈
*/
@GetMapping("/list")
public Map listFeedback(Integer rows, Integer page, FeedbackSelectWrapper fsw, @RequestParam(defaultValue = "createDate") String order) {
// Get请求中文编码
try {
fsw.setName(globalFunction.iso8859ToUtf8(fsw.getName()));
fsw.setStaffName(globalFunction.iso8859ToUtf8(fsw.getStaffName()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 得到筛选条件
EntityWrapper<Feedback> feedbackWrapper = globalFunction.getFeedbackWrapper(fsw);
Page<Feedback> selectPage = feedbackService.selectPage(new Page<>(page, rows,order,false), feedbackWrapper);
List<FeedbackDto> list = globalFunction.feedback2dto(selectPage.getRecords());
Map<String,Object> map = new HashMap<>();
map.put("total", selectPage.getTotal());
map.put("rows", list);
return map;
}
/**
* 删除反馈
*/
@PostMapping("/delete")
public Msg deleteById(String[] ids) {
for(String id : ids) {
feedbackService.deleteById(id);
}
/**
* 获取单个订单详情
*/
@GetMapping("/{id}")
public Msg getById(@PathVariable String id) {
Express express = expressService.selectById(id);
ExpressDto expressDto = globalFunction.express2dto(express);
return Msg.ok(null,expressDto);
}
/**
* 分配订单
* @param ids 订单数组
* @param staffId 派送员id
*/
@PostMapping("/assign")
public Msg assignExpress(String[] ids,String staffId) {
for(String id : ids) {
Express express = expressService.selectById(id);
// 只有订单状态为WAIT_DIST时才要分配订单
if(ExpressStatusEnum.WAIT_DIST.getName().equals(ExpressStatusEnum.getName(express.getStatus()))) {
express.setStaff(staffId);
express.setStatus(ExpressStatusEnum.TRANSPORT.getIndex());
expressService.updateById(express);
}
}
return Msg.ok();
}
/**
* 确认订单
*/
@PostMapping("/confirm")
public Msg confirmExpress(ExpressPayment payment) {
String id = payment.getExpressId();
Express express = expressService.selectById(id);
express.setStatus(ExpressStatusEnum.COMPLTE.getIndex());
expressService.updateById(express);
Express express = (Express)session.getAttribute(SESSION_LATEST_EXPRESS);
if(express == null || money == null) {
response.getWriter().write("参数错误,请重新下单");
}
// 金额保留两位
money = (double) (Math.round(money * 100)) / 100;
// 生成订单
String expressId = expressService.createExpress(express);
// 生成订单支付
expressPaymentService.createAliPayment(expressId, money, aliPaySetting.getSellerId());
// 1、设置请求参数
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
// 页面跳转同步通知页面路径
alipayRequest.setReturnUrl(aliPaySetting.getReturnUrl());
// 服务器异步通知页面路径
alipayRequest.setNotifyUrl(aliPaySetting.getNotifyUrl());
// 2、SDK已经封装掉了公共参数,这里只需要传入业务参数,请求参数查阅开头Wiki
Map<String,String> map = new HashMap<>(16);
map.put("out_trade_no", expressId);
map.put("total_amount", String.valueOf(money));
map.put("subject", "快递代拿");
map.put("body", "快递代拿在线支付");
// 销售产品码
map.put("product_code","FAST_INSTANT_TRADE_PAY");
alipayRequest.setBizContent(JsonUtils.objectToJson(map));
response.setContentType("text/html;charset=utf-8");
try{
// 3、生成支付表单
AlipayTradePagePayResponse alipayResponse = alipayClient.pageExecute(alipayRequest);
if(alipayResponse.isSuccess()) {
String result = alipayResponse.getBody();
response.getWriter().write(result);
} else {
response.getWriter().write("error");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@RequestMapping("/selfList")
public Map listSelfExpress(Integer rows, Integer page, ExpressSelectWrapper esw, @RequestParam(defaultValue = "createDate") String order) {
// Get请求中文编码
try {
esw.setName(globalFunction.iso8859ToUtf8(esw.getName()));
esw.setAddress(globalFunction.iso8859ToUtf8(esw.getAddress()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 得到筛选条件
EntityWrapper<Express> expressWrapper = globalFunction.getExpressWrapper(esw);
// 设置查找当前用户的订单
expressWrapper.eq("staff", globalFunction.getUserId());
Page<Express> selectPage = expressService.selectPage(new Page<>(page, rows, order, false), expressWrapper);
List<ExpressDto> list = globalFunction.express2dto(selectPage.getRecords());
Map<String,Object> map = new HashMap<>();
map.put("total", selectPage.getTotal());
map.put("rows", list);
return map;
}
/**
* 获取单个订单详情
*/
@GetMapping("/{id}")
public Msg getById(@PathVariable String id) {
Express express = expressService.selectById(id);
ExpressDto expressDto = globalFunction.express2dto(express);
return Msg.ok(null,expressDto);
}
/**
* 接单
*/
@PostMapping("")
public Msg acceptExpress(String[] ids) {
for(String id : ids) {
Express express = expressService.selectById(id);