家居建材商城|基于Springboot+Vue实现家居建材商城(三)

简介: 家居建材商城|基于Springboot+Vue实现家居建材商城

家居建材商城|基于Springboot+Vue实现家居建材商城(二)https://developer.aliyun.com/article/1423365


package com.qiu.controller;
import com.qiu.entity.Product;
import com.qiu.entity.Purchase;
import com.qiu.entity.StoreEntity;
import com.qiu.service.ProductService;
import com.qiu.service.PurchaseService;
import com.qiu.service.StoreService;
import com.qiu.util.general.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 *  商铺管理和商品入库
 */
@CrossOrigin
@RestController
public class StoreController {
    @Autowired
    private StoreService storeService;
    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private ProductService productService;
    /**
     * 查询商铺信息
     */
    @RequestMapping(value = "/store/findByStore")
    public CommonResult findByNumber(StoreEntity store) {
        StoreEntity storeEntity = storeService.selectByStore(store);
        if (storeEntity != null) {
            return CommonResult.success("商铺查询成功", storeEntity);
        }
        return CommonResult.error("商铺查询失败");
    }
    /**
     * 查询全部商铺
     */
    @RequestMapping(value = "/store/findAll")
    public CommonResult findAll() {
        List<StoreEntity> stores = storeService.selectAll();
        if (stores != null) {
            return CommonResult.success("商铺查询成功", stores);
        }
        return CommonResult.error("商铺查询失败");
    }
    /**
     * 商铺入驻申请
     * @param store 商铺信息
     */
    @RequestMapping(value = "/store/addStore")
    public CommonResult addStore(StoreEntity store) {
        if (store != null) {
            if (storeService.insertData(store)) {
                return CommonResult.success("店铺入驻申请已发送", store);
            }
            return CommonResult.error("申请发送失败");
        }
        return CommonResult.error("商铺注册数据不存在");
    }
    /**
     * 通过商铺编号更新商铺信息
     *
     * @param store 商铺信息
     */
    @RequestMapping(value = "/store/updateStore")
    public CommonResult updateStoreEntity(StoreEntity store) {
        if (store != null) {
            if (storeService.updateByStore(store)) {
                return CommonResult.success("更新成功", store);
            }
            return CommonResult.error("更新失败");
        }
        return CommonResult.error("商铺数据不存在");
    }
    /**
     * 更新商铺状态
     * @param store 商铺信息
     * @return
     */
    @RequestMapping(value = "/store/updateStoreStatus")
    public CommonResult updateStoreStatus(StoreEntity store) {
        if (store != null) {
            if (storeService.updateStoreStatus(store)) {
                return CommonResult.success("更新成功");
            }
            return CommonResult.error("更新失败");
        }
        return CommonResult.error("商铺数据不存在");
    }
    /**
     * 删除供应商
     * @param storeNumber 供应商编号
     */
    @RequestMapping(value = "/store/deleteStore")
    public CommonResult deleteStoreById(Integer storeNumber) {
        if (storeNumber != null) {
            if (storeService.deleteById(storeNumber)) {
                return CommonResult.success("删除成功", storeNumber);
            }
            return CommonResult.error("删除失败");
        }
        return CommonResult.error("商铺数据不存在");
    }
    //-------------------------------------------商品入库操作------------------------------------------------
    /**
     * 查询入库信息
     * @param purchaseId 入库编号
     */
    @RequestMapping(value = "/purchase/findPurchaseById")
    public CommonResult findPurchaseById(Integer purchaseId) {
        Purchase purchase = purchaseService.selectById(purchaseId);
        if (purchase != null) {
            return CommonResult.success("入库信息查询成功", purchase);
        }
        return CommonResult.error("入库信息查询失败");
    }
    /**
     * 查询全部入库信息
     */
    @RequestMapping(value = "/purchase/findPurchaseAll")
    public CommonResult findPurchaseAll(String accountNumber) {
        List<Purchase> purchases = purchaseService.selectAll(accountNumber);
        if (purchases != null) {
            return CommonResult.success("入库信息查询成功", purchases);
        }
        return CommonResult.error("入库信息查询失败");
    }
    /**
     * 添加入库记录
     * @param purchase 入库信息
     */
    @RequestMapping(value = "/purchase/addPurchase")
    public CommonResult addPurchase(Purchase purchase) {
        if (purchase != null) {
            //1.添加商品库存
            Integer productId = productService.selectIdByKey(purchase.getProductNo());
            Product product = productService.selectById(productId);
            Integer lowestStock = product.getLowestStock();
            Integer productStock = product.getProductStock();
            Integer purchaseNumber =Integer.parseInt(purchase.getPurchaseNumber());
            product.setProductStock(productStock + purchaseNumber);
            product.setIsStockOut(product.getProductStock() < lowestStock);
            if (productService.updateById(product)) {//库存信息更新成功
                purchaseService.insertData(purchase);//插入一条入库记录
                return CommonResult.success("商品入库成功", purchase);
            }
            return CommonResult.error("商品库存更新失败");
        }
        return CommonResult.error("系统繁忙,请稍后再试!");
    }
    /**
     * 删除入库记录
     *
     * @param purchaseId 入库id
     */
    @RequestMapping(value = "/purchase/deletePurchase")
    public CommonResult deletePurchase(Integer purchaseId) {
        if (purchaseId != null) {
            if (purchaseService.deleteById(purchaseId)) {
                return CommonResult.success("删除成功", purchaseId);
            }
            return CommonResult.error("删除失败");
        }
        return CommonResult.error("入库信息数据不存在,请刷新重试");
    }
}
package com.qiu.controller;
import com.qiu.constant.UserStatusEnum;
import com.qiu.entity.User;
import com.qiu.entity.UserRole;
import com.qiu.entity.Vip;
import com.qiu.service.UserRoleService;
import com.qiu.service.UserService;
import com.qiu.service.VipService;
import com.qiu.util.general.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
 *  用户相关业务
 */
@CrossOrigin
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private VipService vipService;
    /**
     * 根据id查询用户
     *
     * @param id 用户编号
     */
    @RequestMapping(value = "/user/findById")
    public CommonResult findById(Integer id) {
        User user = userService.selectById(id);
        if (user != null) {
            return CommonResult.success("查询成功", user);
        } else {
            return CommonResult.error("查询失败");
        }
    }
    /**
     * 根据账号查询用户
     *
     * @param key 账号
     */
    @RequestMapping(value = "/user/findByKey")
    public CommonResult findByKey(String key) {
        User user = userService.selectByKey(key);
        if (user != null) {
            return CommonResult.success("查询成功", user);
        }
        return CommonResult.error("查询失败");
    }
    /**
     * 查询所有顾客
     */
    @RequestMapping(value = "/user/findAll/customer")
    public CommonResult findAllCustomer() {
        List<User> users = userService.queryAllByStatus(UserStatusEnum.CUSTOMER);
        if (users != null) {
            return CommonResult.success("查询成功", users);
        }
        return CommonResult.error("查询失败");
    }
    /**
     * 查询所有管理员
     */
    @RequestMapping(value = "/user/findAll/admin")
    public CommonResult findAllAdmin() {
        List<User> users = userService.queryAllByStatus(UserStatusEnum.ADMIN);
        if (users != null) {
            return CommonResult.success("查询成功", users);
        }
        return CommonResult.error("查询失败");
    }
//    /**
//     * 查询商家的商铺编号
//     */
//    @RequestMapping(value = "/user/storeNumber")
//    public CommonResult findStoreNumber(String accountNumber) {
//        String storeNumber= userService.selectStoreNumber(accountNumber);
//        if (storeNumber != null) {
//            return CommonResult.success("商铺编号查询成功", storeNumber);
//        }
//        return CommonResult.error("商铺编号查询失败");
//    }
    /**
     * 判断某个用户是否还存在
     *
     * @param key 账号
     */
    @RequestMapping(value = "/user/existKey")
    public CommonResult existKey(String key) {
        boolean exist = userService.existsWithPrimaryKey(key);
        return CommonResult.success("查询成功", exist);
    }
    /**
     * 查询用户状态
     *
     * @param accountNumber 用户账号
     */
    @RequestMapping(value = "/user/userState")
    public CommonResult userState(String accountNumber) {
        boolean state = userService.selectUserState(accountNumber);
        return CommonResult.success("查询成功", state);
    }
    /**
     * 查询用户记录的总个数
     */
    @RequestMapping(value = "/user/count")
    public CommonResult findCount() {
        int count = userService.selectCount();
        return CommonResult.success("查询成功", count);
    }
    /**
     * 通过用户账号查询用户ID
     *
     * @param key 用户账号
     */
    @RequestMapping(value = "/user/findIdByKey")
    public CommonResult findIdByKey(String key) {
        Integer id = userService.selectIdByKey(key);
        if (id != null) {
            return CommonResult.success("查询成功", id);
        }
        return CommonResult.error("未查询到");
    }
    /**
     * 删除用户
     *
     * @param userId 用户编号
     */
    @RequestMapping(value = "/user/delete")
    public CommonResult delete(Integer userId) {
        if (userService.deleteById(userId)) {
            return CommonResult.success("删除成功", userId);
        }
        return CommonResult.error("删除失败");
    }
    /**
     * 角色授权
     *
     * @param userId 用户编号
     * @param roleId 角色编号列表
     */
    @RequestMapping(value = "/user/author")
    public CommonResult author(Integer userId, @RequestParam List<Integer> roleId) {
        if (userId != null && roleId != null && !roleId.isEmpty()) {
            if (userRoleService.deleteById(userId)) {
                UserRole userRole = new UserRole();
                userRole.setUserId(userId);
                for (Integer id : roleId) {
                    userRole.setRoleId(id);
                    userRoleService.insertData(userRole);
                }
            }
            User user = new User();
            user.setUserId(userId);
            user.setStatus(UserStatusEnum.ADMIN);
            userService.updateById(user);
            return CommonResult.success("授权成功");
        } else {
            return CommonResult.error("角色授权数据不完整!");
        }
    }
    /**
     * 查询所有VIP用户
     */
    @RequestMapping(value = "/vip/findAllVip")
    public CommonResult findAllVip() {
        List<Vip> vips = vipService.selectAll();
        if (vips != null) {
            return CommonResult.success("查询成功", vips);
        }
        return CommonResult.error("查询失败");
    }
    /**
     * 查询VIP用户信息根据id
     *
     * @param vipId 会员编号
     */
    @RequestMapping(value = "/vip/findVipById")
    public CommonResult findVipById(Integer vipId) {
        Vip vip = vipService.selectById(vipId);
        if (vip != null) {
            return CommonResult.success("查询成功", vip);
        }
        return CommonResult.error("查询失败");
    }
    /**
     * 查询VIP用户信息根据id
     *
     * @param accountNumber 用户账号
     */
    @RequestMapping(value = "/vip/findVipByKey")
    public CommonResult findVipByKey(String accountNumber) {
        Vip vip = vipService.selectByKey(accountNumber);
        if (vip != null) {
            return CommonResult.success("查询成功", vip);
        }
        return CommonResult.error("查询失败");
    }
    /**
     * 判断用户信息是否存在
     *
     * @param accountNumber 用户账号
     */
    @RequestMapping(value = "/vip/existsVip")
    public CommonResult existsVip(String accountNumber) {
        boolean exist = vipService.existsVip(accountNumber);
        return CommonResult.success("查询成功", exist);
    }
    /**
     * 增加会员信息
     *
     * @param vip 会员信息
     */
    @RequestMapping(value = "/vip/addVip")
    public 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);
        }
        return CommonResult.error("会员信息添加失败");
    }
    /**
     * 更新会员信息
     *
     * @param vip 会员信息
     */
    @RequestMapping(value = "/vip/updateVip")
    public CommonResult updateVip(Vip vip) {
        if (vipService.updateById(vip)) {
            return CommonResult.success("会员信息更新成功", vip);
        }
        return CommonResult.error("会员信息更新失败");
    }
    /**
     * 清除信息
     *
     * @param vipId 会员编号
     */
    @RequestMapping(value = "/vip/deleteVip")
    public CommonResult deleteVip(Integer vipId) {
        if (vipService.deleteById(vipId)) {
            return CommonResult.success("删除成功", vipId);
        }
        return CommonResult.error("删除失败");
    }
}

五,项目总结

表结构及ER图

本系统用到了18张表存储数据,分别是banner(商品广告轮播图表)、

Logistics(物流表)、order(订单表)、product(商品表)、product_brand(商品品牌表)、product_review(商品评价表)、product_specs(商品规格表)、product_type(商品类型推荐表)、purchase(商品入库记录表)、return_goods(商品退货表)、return_reason(退货原因表)、role(角色表)、shopping_cart(购物车表)、specs(商品规格表)、store(商铺信息表)、sys_commodity_type(商品类型表)、user(用户表)、user_role(用户角色表)。

相关文章
|
1天前
|
JSON JavaScript Java
从前端Vue到后端Spring Boot:接收JSON数据的正确姿势
从前端Vue到后端Spring Boot:接收JSON数据的正确姿势
25 0
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的4S店客户管理系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的4S店客户管理系统的详细设计和实现
47 4
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的在线课堂微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的在线课堂微信小程序的详细设计和实现
35 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
59 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的商品展示的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的商品展示的详细设计和实现
33 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
54 3
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
32 2
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的助农扶贫微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的助农扶贫微信小程序的详细设计和实现
35 2
|
1天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
43 2
|
JavaScript 算法 Java
springboot vue二手交易市场毕设源码(毕设)
springboot vue二手交易市场毕设源码
312 0
springboot vue二手交易市场毕设源码(毕设)