基于javaweb+mysql的springboot网上电商项目(前后端分离+java+vue+springboot+ssm+mysql+maven+redis)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot网上电商项目(前后端分离+java+vue+springboot+ssm+mysql+maven+redis)
一、项目简述
本系统功能包括: 一款基于Springboot+Vue的电商项目,前后端分离项目,前台后台都有,前台商品展示购买,购物车分类,订 单查询等等,后台商品管理,订单管理,信息维护,用户管理等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持)。
项目技术: Springboot + Maven + Mybatis + Vue + Redis, B/S 模式+ Maven等等,附带支付宝沙箱环境以及支付环节代码。
String tradeNo =map.get("out_trade_no");
String tradeName = map.get("subject");
String payAmount = map.get("buyer_pay_amount");
log.info("[支付成功] {交易时间:{},订单号:{},订单名称:{},交易金额:{}}",payTime,tradeNo,tradeName,payAmount);
}
}
}
/**
* @email qiudb.top@aliyun.com
* @description 发送邮件、产生验证码图片、发送短信等工具类操作
*/
@RestController
@CrossOrigin
public class UtilController {
private final RedisTemplate<String, String> redisTemplate;
private final AliYunSmsService aliYunSmsService;
private final IMailService mailService;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public UtilController(RedisTemplate<String, String> redisTemplate, IMailService mailService, AliYunSmsService aliYunSmsService) {
if(returnGoodsService.insertData(returnGoods)){
return CommonResult.success("添加成功",returnGoods);
}else{
return CommonResult.error("添加失败");
}
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("商品退货数据不存在");
}
@RequestMapping(value = "/returnGoods/updateReturn")
private CommonResult updateReturn(ReturnGoods returnGoods) {
if(returnGoods!=null){
returnGoods.setDealTime(new Date());
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("商品退货数据不存在");
}
/*我的订单 查询退货订单信息*/
@RequestMapping(value = "/returnGoods/findReturnInfo")
private CommonResult findReturnInfo(String userNumber) {
if(userNumber!=null){
List<Map<String, Object>> data = returnGoodsService.selectAllOrder(userNumber);
return CommonResult.success("商品退货订单查询成功",data);
}
return CommonResult.error("商品退货数据不存在");
}
/*拒绝买家退货*/
@RequestMapping(value = "/returnGoods/refuseReturn")
private CommonResult refuseReturn(Integer returnId,String operatorNumber,String operatorName) {
if(returnId!=null){
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
returnGoods.setReturnState("已拒绝");
returnGoods.setDealTime(new Date());
returnGoods.setOperatorNumber(operatorNumber);
returnGoods.setOperatorName(operatorName);
String orderNo = returnGoods.getOrderNo();
Integer orderId = orderService.selectIdByKey(orderNo);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("已拒绝");
if(orderService.updateById(order)){
if(returnGoodsService.updateById(returnGoods)){
returnGoods.setOperatorNumber(operatorNumber);
returnGoods.setOperatorName(operatorName);
String orderNo = returnGoods.getOrderNo();
Integer orderId = orderService.selectIdByKey(orderNo);
Order order = new Order();
order.setOrderId(orderId);
order.setReturnState(true);
order.setOrderState("已退款");
Logistics logistics = logisticsService.selectOrderNo(orderNo);
if(logistics!=null){
logisticsService.deleteById(logistics.getLogisticId());
}
if(orderService.updateById(order)){
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("商品退款数据不存在");
}
/*拒绝买家退款申请*/
@RequestMapping(value = "/returnGoods/rejectRefund")
private CommonResult rejectRefund(Integer returnId,String operatorNumber,String operatorName) {
if(returnId!=null){
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
returnGoods.setReturnState("拒绝退款");
returnGoods.setDealTime(new Date());
returnGoods.setOperatorNumber(operatorNumber);
returnGoods.setOperatorName(operatorName);
String orderNo = returnGoods.getOrderNo();
Integer orderId = orderService.selectIdByKey(orderNo);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("待发货");
if(orderService.updateById(order)){
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
@RequestMapping(value = "/shoppingCart/findAll")
private CommonResult findAllShoppingCart(String accountNumber) {
List<Map<String, Object>> shoppingInfo = shoppingCartService.selectAll(accountNumber);
if(shoppingInfo!=null){
return CommonResult.success("购物车查询成功",shoppingInfo);
}else{
return CommonResult.error("购物车查询失败");
}
}
@RequestMapping(value = "/shoppingCart/findById")
private CommonResult findById(Integer cartId) {
ShoppingCart shoppingCart = shoppingCartService.selectById(cartId);
if(shoppingCart!=null){
return CommonResult.success("购物车查询成功",shoppingCart);
}else{
return CommonResult.error("购物车查询失败");
}
}
}
/**
* @email qiudb.top@aliyun.com
* @description 用户授权类
*/
}
@RequestMapping(value = "/returnReason/addReason")
private CommonResult addReason(ReturnReason returnReason) {
if(returnReason!=null){
if(returnReasonService.insertData(returnReason)){
return CommonResult.success("添加成功",returnReason);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
@RequestMapping(value = "/returnReason/updateReason")
private CommonResult updateReason(ReturnReason returnReason) {
if(returnReason!=null){
if(returnReasonService.updateById(returnReason)){
return CommonResult.success("更新成功",returnReason);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
@RequestMapping(value = "/returnReason/deleteReason")
private CommonResult updateReason(Integer reasonId) {
if(reasonId!=null){
if(returnReasonService.deleteById(reasonId)){
return CommonResult.success("删除成功",reasonId);
}else{
return CommonResult.error("删除失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
/*查询商品退货信息*/
@RequestMapping(value = "/returnGoods/findReturnById")
private CommonResult findReturnById(Integer returnId) {
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
if(returnGoods!=null){
return CommonResult.success("退货商品查询成功",returnGoods);
/*根据帐号查询用户*/
@RequestMapping(value = "/user/findByKey")
private CommonResult findByKey(String key) {
User user = userService.selectByKey(key);
if(user!=null){
return CommonResult.success("查询成功",user);
}else{
return CommonResult.error("查询失败");
}
}
/*查询所有用户*/
@RequestMapping(value = "/user/findAll")
private CommonResult findAll() {
List<User> users = userService.selectAll();
if(users!=null){
return CommonResult.success("查询成功",users);
}else{
return CommonResult.error("查询失败");
}
}
/*判断某个用户是否还存在*/
@RequestMapping(value = "/user/existKey")
private CommonResult existKey(String key) {
Boolean isExist = userService.existsWithPrimaryKey(key);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
/*查询用户状态*/
@RequestMapping(value = "/user/userState")
private CommonResult userState(String accountNumber) {
Boolean state = userService.selectUserState(accountNumber);
if(state!=null){
return CommonResult.success("查询成功",state);
}else{
return CommonResult.error("查询失败");
}
}
/*查询用户记录的总条数*/
@RequestMapping(value = "/user/count")
private CommonResult findCount() {
Integer count = userService.selectCount();
if(count!=null){
if(count!=0){
return CommonResult.success("查询成功",count);
@Slf4j
@Controller
public class AlipayController {
private final AlipayService alipayService;
private final OrderService orderService;
private final RedisTemplate<String,String> redisTemplate;
private final String hostAddress;
public AlipayController(AlipayService alipayService,OrderService orderService,RedisTemplate<String,String> redisTemplate) {
this.alipayService = alipayService;
this.orderService = orderService;
this.redisTemplate = redisTemplate;
this.hostAddress= PropertiesUtil.getServerHost() +":"+PropertiesUtil.getPort();
}
@RequestMapping("/")
private String index(){
return "index.html";
}
/*
https://qiustudy.utools.club/alipay/create?orderNo=10060&orderName=花卷商城-华为手机支付订单&payPrice=4000
*/
@ResponseBody
@PostMapping(value = "/create", produces = "text/html;charset=utf-8")
public void create(@RequestParam("orderNo") String orderNo,
@RequestParam("orderName") String orderName,
@RequestParam("payPrice") String payPrice
,HttpServletResponse response) {
//发起支付
// return alipayService.create(orderNo, orderName, payPrice);
//跳过支付宝支付过程
try{
//String tradeNo =map.get("out_trade_no");
String tradeNo =orderNo;
if(tradeNo.contains("Vip")){
Integer orderId = orderService.selectIdByKey(tradeNo);
Order order = new Order();
order.setOrderId(orderId);
newProduct.setProductStock(newStock);
newProduct.setIsStockOut(newStock<product.getLowestStock());
// 如果库存小于等于0,自动下架
newProduct.setIsSale(newStock>0);
if(productService.updateById(newProduct)){
if(orderService.insertData(order)){
redisTemplate.opsForValue().set(order.getOrderNo(),order.getOrderNo(),24, TimeUnit.HOURS);
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("商品库存不足");
}
}
}else{
return CommonResult.error("订单数据不完整");
}
}
@RequestMapping(value = "/order/cartOrder")
private CommonResult cartOrder(String orderNo,String ordersInfo) {
JSONArray jsonArray = JSON.parseArray(ordersInfo);
List<Order> orders = JSONObject.parseArray(jsonArray.toJSONString(), Order.class);
if(orders!=null){
ArrayList<String> orderInfo = new ArrayList<>();
ArrayList<String> productInfo = new ArrayList<>();
for (Order order : orders) {
Product product = productService.selectByKey(order.getProductNo());
Integer productStock = product.getProductStock();
Integer payAmount = order.getPayAmount();
boolean isOk =productStock >= payAmount;
if(isOk){
Product newProduct = new Product();
newProduct.setProductId(product.getProductId());
int newStock = productStock - payAmount;
newProduct.setProductStock(newStock);
newProduct.setIsStockOut(newStock<product.getLowestStock());
// 如果库存小于等于0,自动下架
newProduct.setIsSale(newStock>0);
if(productService.updateById(newProduct)){
if(orderService.insertData(order)){
orderInfo.add(order.getOrderNo());
productInfo.add(order.getProductNo());
}
//清除用户缓存
RealmSecurityManager securityManager = (RealmSecurityManager) SecurityUtils.getSecurityManager();
UserRealm userRealm = (UserRealm) securityManager.getRealms().iterator().next();
//清空redis中的缓存信息
userRealm.clearRedis(user,session);
userRealm.clearCache(SecurityUtils.getSubject().getPrincipals());
//退出登录
subject.logout();
return CommonResult.success("退出成功");
}catch(Exception e){
logger.error(e.getMessage());
}
}
return CommonResult.error("退出失败,未找到用户帐号");
}
//权限不够时,将转到此请求上来
@RequestMapping("/notRole")
private CommonResult notRole(){
return new CommonResult(403,"暂无权限!");
}
/*判断key是否存在 目前用于判断邮箱是否被注册过*/
@RequestMapping(value = "/allow/existUser")
private CommonResult existUser(String accountNumber) {
Boolean isExist = userService.existsWithPrimaryKey(accountNumber);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
/*判断手机号phone是否存在 目前被用于绑定手机号时,确认手机号已被绑定*/
@RequestMapping(value = "/allow/existPhone")
private CommonResult existPhone(String telephone) {
Boolean isExist = userService.existsWithPrimaryPhone(telephone);
if(isExist!=null){
return CommonResult.success("手机号查询成功",isExist);
}else{
return CommonResult.error("手机号查询失败");
}
}
public static void main(String[] args) {
System.out.println("23");
}
if(orderMap!=null){
resultMap.putAll(orderMap);
}
if(returnGoodsMap!=null){
resultMap.putAll(returnGoodsMap);
}
if(resultMap.size()!=0){
return CommonResult.success("查询成功",resultMap);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/view/orderChartDATE")
private CommonResult orderChartDATE(String startTime,String endTime) {
Map<String, Object> data = new HashMap<>();
List<Map<String, Object>> lineData = orderService.selectChartDATE(startTime,endTime);
List<Map<String, Object>> ringData = orderService.selectProductTypeChart(startTime, endTime);
Map<String, Object> countData = orderService.selectCountAndAmount(startTime,endTime);
if(lineData.size()!=0){
data.put("lineData",lineData);
}
if(ringData.size()!=0){
data.put("ringData",ringData);
}
if(countData.size()!=0){
data.put("countData",countData);
}
if(data.size()!=0){
return CommonResult.success("查询成功",data);
}else{
return CommonResult.error("查询失败");
}
}
}
/**
* @email qiudb.top@aliyun.com
* @description 描述
}
/*判断用户信息是否存在*/
@RequestMapping(value = "/vip/existsVip")
private CommonResult existsVip(String accountNumber) {
Boolean isExist = vipService.existsVip(accountNumber);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
//创建vip信息
@RequestMapping(value = "/vip/addVip")
private CommonResult addVip(Vip vip) {
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);//设置起时间
cal.add(Calendar.YEAR, 1);//增加一年
vip.setOverdueTime(cal.getTime());
if(vipService.insertData(vip)){
return CommonResult.success("vip信息插入成功",vip);
}else{
return CommonResult.error("vip信息插入失败");
}
}
//更新vip信息
@RequestMapping(value = "/vip/updateVip")
private CommonResult updateVip(Vip vip) {
if(vipService.updateById(vip)){
return CommonResult.success("vip信息更新成功",vip);
}else{
return CommonResult.error("vip信息更新失败");
}
}
//删除vip信息
@RequestMapping(value = "/vip/deleteVip")
private CommonResult deleteVip(Integer vipId) {
if(vipService.deleteById(vipId)){
return CommonResult.success("删除成功",vipId);
}else{
return CommonResult.error("删除失败");
}
return CommonResult.success("订单数量查询成功",count);
}else{
return CommonResult.error("订单数量查询失败");
}
}
@RequestMapping(value = "/order/add")
private CommonResult addOrder(Order order) {
if(order!=null){
if(order.getProductNo().contains("Vip")){
if(orderService.insertData(order)){
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
Product product = productService.selectByKey(order.getProductNo());
Integer productStock = product.getProductStock();
Integer payAmount = order.getPayAmount();
boolean isOk =productStock >= payAmount;
if(isOk){
Product newProduct = new Product();
newProduct.setProductId(product.getProductId());
int newStock = productStock - payAmount;
newProduct.setProductStock(newStock);
newProduct.setIsStockOut(newStock<product.getLowestStock());
// 如果库存小于等于0,自动下架
newProduct.setIsSale(newStock>0);
if(productService.updateById(newProduct)){
if(orderService.insertData(order)){
redisTemplate.opsForValue().set(order.getOrderNo(),order.getOrderNo(),24, TimeUnit.HOURS);
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("商品库存不足");
}
}
}else{
return CommonResult.error("订单数据不完整");
}
}
@RequestMapping(value = "/order/cartOrder")
private CommonResult cartOrder(String orderNo,String ordersInfo) {
JSONArray jsonArray = JSON.parseArray(ordersInfo);
List<Order> orders = JSONObject.parseArray(jsonArray.toJSONString(), Order.class);
return CommonResult.success("查询成功","id: "+id);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/role/add")
private CommonResult add(Role role) {
if(role!=null){
if(roleService.insertData(role)){
return CommonResult.success("添加成功",role);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("用户数据不存在");
}
@RequestMapping(value = "/role/update")
private CommonResult update(Role role) {
System.out.println(role);
if(roleService.updateById(role)){
return CommonResult.success("更新成功",role);
}else{
return CommonResult.error("更新失败");
}
}
@RequestMapping(value = "/role/delete")
private CommonResult delete(Integer roleId) {
if(roleService.deleteById(roleId)){
return CommonResult.success("删除成功",roleId);
}else{
return CommonResult.error("删除失败");
}
}
}
}
/**
* 登录操作
* @param username 用户登录的帐号
* @param password 用户登录的密码
* @param rememberMe shiro框架的 记住我 功能
*/
@RequestMapping(value = "/login",produces = {"application/json;charset=UTF-8"})
private CommonResult doLogin(String username,String password,boolean rememberMe) {
try {
if (username == null) {
throw new AuthenticationException();
}
if (password == null) {
throw new IncorrectCredentialsException();
}
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
if (subject.isAuthenticated())
return CommonResult.error("已登录");
subject.login(token);
Map<String, Object> info = new HashMap<>();
String authorization = (String) subject.getSession().getId();
User user;
if (username.contains("@")) {
//包含@符号,代表用户通过邮箱帐号登录
user = userService.selectByKey(username);
} else {
//不包含@符号,代表用户通过手机号登录
user = userService.selectByPhone(username);
}
info.put("user", user); //存放用户信息
//更新最后登录时间
user.setLoginTime(new Date());
userService.updateById(user);
//存放sessionId, 即 token
info.put("sessionId", authorization);
List<Role> roles = roleService.selectAll();
List<String> rs = new ArrayList<>(); // rs 存放的是role的名称
List<String> rsInfo = new ArrayList<>(); //rsInfo 存放role的描述
for (Role role : roles) {
rs.add(role.getRoleName());
rsInfo.add(role.getRoleName());
}
boolean[] booleans = subject.hasRoles(rs);
for (int i = booleans.length - 1; i >= 0; i--) {
if (!booleans[i]) {
/**
* @email qiudb.top@aliyun.com
* @description 数据分析,商品数量,订单数量等分析业务
*/
@CrossOrigin
@RestController
public class OverViewController {
final OrderService orderService;
final ProductService productService;
final ReturnGoodsService returnGoodsService;
public OverViewController(OrderService orderService,ProductService productService,ReturnGoodsService returnGoodsService) {
this.orderService = orderService;
this.productService = productService;
this.returnGoodsService = returnGoodsService;
}
@RequestMapping(value = "/view/dataInfo")
private CommonResult dataInfo() {
Map<String, Object> resultMap = new HashMap<>();
Map<String, Object> productMap = productService.productOverview();
Map<String, Object> orderMap = orderService.orderOverview();
Map<String, Object> returnGoodsMap = returnGoodsService.returnGoodsOverview();
if(productMap!=null){
resultMap.putAll(productMap);
}
if(orderMap!=null){
resultMap.putAll(orderMap);
}
if(returnGoodsMap!=null){
resultMap.putAll(returnGoodsMap);
}
if(resultMap.size()!=0){
return CommonResult.success("查询成功",resultMap);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/view/orderChartDATE")
private CommonResult orderChartDATE(String startTime,String endTime) {
Map<String, Object> data = new HashMap<>();
private CommonResult doLogin(String username,String password,boolean rememberMe) {
try {
if (username == null) {
throw new AuthenticationException();
}
if (password == null) {
throw new IncorrectCredentialsException();
}
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
if (subject.isAuthenticated())
return CommonResult.error("已登录");
subject.login(token);
Map<String, Object> info = new HashMap<>();
String authorization = (String) subject.getSession().getId();
User user;
if (username.contains("@")) {
//包含@符号,代表用户通过邮箱帐号登录
user = userService.selectByKey(username);
} else {
//不包含@符号,代表用户通过手机号登录
user = userService.selectByPhone(username);
}
info.put("user", user); //存放用户信息
//更新最后登录时间
user.setLoginTime(new Date());
userService.updateById(user);
//存放sessionId, 即 token
info.put("sessionId", authorization);
List<Role> roles = roleService.selectAll();
List<String> rs = new ArrayList<>(); // rs 存放的是role的名称
List<String> rsInfo = new ArrayList<>(); //rsInfo 存放role的描述
for (Role role : roles) {
rs.add(role.getRoleName());
rsInfo.add(role.getRoleName());
}
boolean[] booleans = subject.hasRoles(rs);
for (int i = booleans.length - 1; i >= 0; i--) {
if (!booleans[i]) {
rs.remove(i);
rsInfo.remove(i);
}
}
info.put("role", rs);
info.put("roleInfo", rsInfo);
return CommonResult.success("登录成功", info);
}catch (LockedAccountException e){
return CommonResult.error("您的帐号存在异常行为,已被封停(请联系工作人员)");
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/productSpecs/add")
private CommonResult add(ProductSpecs productSpecs) {
if(productSpecs!=null){
if(productSpecsService.insertData(productSpecs)){
return CommonResult.success("添加成功",productSpecs);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("数据不存在");
}
@RequestMapping(value = "/productSpecs/addBatch")
private CommonResult addBatch(Integer productId,Integer[] specsIds) {
System.out.println(productId);
System.out.println(Arrays.toString(specsIds));
if(specsIds!=null){
ProductSpecs productSpecs;
List<ProductSpecs> productSpecsList = new ArrayList<>();
for (Integer specsId : specsIds) {
productSpecs = new ProductSpecs();
productSpecs.setProductId(productId);
productSpecs.setSpecsId(specsId);
productSpecsList.add(productSpecs);
}
for (ProductSpecs specs : productSpecsList) {
System.out.println(specs);
}
if(productSpecsService.insertBatch(productSpecsList)){
return CommonResult.success("添加成功",productSpecsList);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("数据不存在");
}
@RequestMapping(value = "/productSpecs/update")
private CommonResult update(ProductSpecs productSpecs) {
if(productSpecsService.updateById(productSpecs)){
return CommonResult.success("更新成功",productSpecs);
}else{
return CommonResult.error("更新失败");
}
}
@RequestMapping(value = "/productSpecs/delete")