基于javaweb+mysql的springboot前后端分离网上商城项目设计和实现(java+ssm+springboot+vue+redis)

基于javaweb+mysql的springboot前后端分离网上商城项目设计和实现(java+ssm+springboot+vue+redis)

运行环境

Java≥8、MySQL≥5.7、Node.js≥10

开发工具

后端:eclipse/idea/myeclipse/sts等均可配置运行

前端:WebStorm/VSCode/HBuilderX等均可

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SpringBoot前后端分离网上商城项目设计和实现(java+ssm+springboot+vue+redis)

主要实现技术:Java、springmvc、springboot、mybatis、mysql、tomcat、shiro权限框架、vue、jquery、node.js 、redis数据库、邮箱相关等技术。

主要功能实现:

用户登录、注册、商城浏览、购买、订单、购物车、退货、用户、个人中心、修改密码、角色等管理

前端主页面:商品关键字搜索和分类搜索功能以及首页轮播图配置展示

首页个人中心主要功能:密码修改、订单、购物车、商品详情模块、可以购买、加入购物车

购买时需要填写用户手机号和收获地址等信息、注册时默认生成支付宝模拟账号密码:

后台管理员主要对商品数据进行管理、分类管理、订单管理以及用户管理扥。

商品列表数据管理、后台添加商品信息、商品基础数据的维护管理、商品订单详情管理:根据关键字查询以及查看每一个订单的详情信息

首页轮播图配置展示、用户角色和权限管理控制:

前后端源码结构:

数据库图:

        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllSale")
    private CommonResult findAllSale() {
        List<Product> products = productService.selectAllSale();
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllLikeName")
    private CommonResult findAllLikeName(String keyWord) {
        List<Product> products = productService.selectAllLikeName(keyWord);
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllLikeType")
    private CommonResult findAllLikeType(String keyWord) {
        List<Product> products = productService.selectAllLikeType(keyWord);
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllLikeBrand")
    private CommonResult findAllLikeBrand(String keyWord) {
        List<Product> products = productService.selectAllLikeBrand(keyWord);
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllByType")
    private CommonResult findAllByType() {
        List<Map<String, Object>> maps = productService.selectAllByType();
        if(maps!=null){
            return CommonResult.success("商品分类信息查询成功",maps);
        }else{
            return CommonResult.error("商品分类信息查询失败");
        }
    }

    }
    @RequestMapping(value = "/product/findCount")
    private CommonResult findCount() {
        Integer count = productService.selectCount();
        if(count!=null){
            return CommonResult.success("商品数量查询成功",count);
        }else{
            return CommonResult.error("商品数量查询失败");
        }
    }
    @RequestMapping(value = "/product/existsKey")
    private CommonResult existsKey(String productNo) {
        Boolean isExist = productService.existsWithPrimaryKey(productNo);
        if(isExist!=null){
            return CommonResult.success("商品是否存在查询成功",isExist);
        }else{
            return CommonResult.error("商品是否存在查询失败");
        }
    }
    @RequestMapping(value = "/product/existsType")
    private CommonResult existsType(String productType) {
        Boolean isExist = productService.existsProductType(productType);
        if(isExist!=null){
            return CommonResult.success("查询成功",isExist);
        }else{
            return CommonResult.error("查询失败");
        }
    }
    @RequestMapping(value = "/product/existsBrand")
    private CommonResult existsBrand(String productBrand) {
        Boolean isExist = productService.existsProductBrand(productBrand);
        if(isExist!=null){
            return CommonResult.success("查询成功",isExist);
        }else{
            return CommonResult.error("查询失败");
        }
    }
    @RequestMapping(value = "/product/findAll")
    private CommonResult findAll() {
        List<Product> products = productService.selectAll();
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllSale")
    private CommonResult findAllSale() {
        List<Product> products = productService.selectAllSale();
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
 * @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) {
        this.mailService = mailService;
        this.aliYunSmsService = aliYunSmsService;
        this.redisTemplate = redisTemplate;
    }

    /**
     * 发送一个简单的文本邮件
     *
     * @param sendTo 收件人
     */
    @RequestMapping(value = "/util/send")
    public String sendmail(String sendTo) {
        mailService.sendSimpleMail(sendTo, "主题:你好普通邮件", "内容:第一封邮件");
        return "发送成功!";
    }

    /**
     * 发送一个邮箱随机验证码
     *
     * @param sendTo 收件人
     */
    @RequestMapping(value = "/allow/sendHtmlCode")
    public CommonResult sendHtmlCode(String sendTo) {
//        long startTime = System.currentTimeMillis(); //获取开始时间
        try {
            String code = MyUtils.getCode(6);
//            long oneTime = System.currentTimeMillis(); //获取第一阶段时间
            Map<String, Object> data = new HashMap<>();
            data.put("code", code);
            data.put("year", Calendar.getInstance().get(Calendar.YEAR));
            redisTemplate.opsForValue().set(sendTo, code, 10, TimeUnit.MINUTES);
            System.out.println("验证码是:" + code);
//          long twoTime = System.currentTimeMillis(); //获取第二阶段时间
            mailService.sendTemplateMail(sendTo, "操作验证码", "mail", data);
//          long threeTime = System.currentTimeMillis(); //获取第三阶段时间
//          MyUtils.speedTest(startTime,oneTime,twoTime,threeTime);
            return CommonResult.success("验证码已发送,网络有延迟请稍等~");
        } catch (Exception e) {
            return CommonResult.success("商品分类查询成功",productTypes);
        }else{
            return CommonResult.error("商品分类查询失败");
        }
    }

    @RequestMapping(value = "/productType/findAllName")
    private CommonResult findAllTypeName() {
        List<String> names = productTypeService.selectAllName();
        if(names!=null){
            return CommonResult.success("商品分类名称查询成功",names);
        }else{
            return CommonResult.error("商品分类名称查询失败");
        }
    }

    /*商品品牌*/
    @RequestMapping(value = "/productBrand/add")
    private CommonResult addBrand(ProductBrand productBrand) {
        if(productBrandService.insertData(productBrand)){
            return CommonResult.success("商品品牌添加成功",productBrand);
        }else{
            return CommonResult.error("商品品牌添加失败");
        }
    }

    @RequestMapping(value = "/productBrand/update")
    private CommonResult updateBrand(ProductBrand productBrand) {
        if(productBrandService.updateById(productBrand)){
            return CommonResult.success("商品品牌修改成功",productBrand);
        }else{
            return CommonResult.error("商品品牌修改失败");
        }
    }

    @RequestMapping(value = "/productBrand/deleteById")
    private CommonResult deleteBrandById(Integer brandId) {
        if(productBrandService.deleteById(brandId)){
            return CommonResult.success("商品品牌删除成功","brandId: "+brandId);
        }else{
            return CommonResult.error("商品品牌删除失败");
        }
    }

    @RequestMapping(value = "/productBrand/deleteByName")
    private CommonResult deleteBrandByName(String brandName) {
        if(productBrandService.deleteByName(brandName)){
    @RequestMapping(value = "/user/findById")
    private CommonResult findById(Integer id) {
        User user = userService.selectById(id);
        if(user!=null){
            return CommonResult.success("查询成功",user);
        }else{
            return CommonResult.error("查询失败");
        }
    }

    /*根据帐号查询用户*/
    @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);
    }

    @RequestMapping(value = "/order/receipt")
    private CommonResult updateOrder(Integer orderId) {
        Order order = new Order();
        order.setOrderId(orderId);
        order.setOrderState("已收货");
        if(orderService.updateById(order)){
            return CommonResult.success("商品收货成功",order);
        }else{
            return CommonResult.error("商品收货失败");
        }
    }

    @RequestMapping(value = "/orderDetail/orderInfo")
    private CommonResult orderInfo(String orderNo) {
        ArrayList<Object> resultList = new ArrayList<>();
        Order order = orderService.selectByKey(orderNo);
        Logistics logistics = logisticsService.selectOrderNo(orderNo);
        if(order!=null){
            resultList.add(order);
        }
        if(logistics!=null){
            resultList.add(logistics);
        }

        if(resultList.size()!=0){
            return CommonResult.success("订单详情查询成功",resultList);
        }else{
            return CommonResult.error("订单详情查询失败");
        }
    }
}
package com.qiu.controller;
@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) {
        this.mailService = mailService;
        this.aliYunSmsService = aliYunSmsService;
        this.redisTemplate = redisTemplate;
    }

    /**
     * 发送一个简单的文本邮件
     *
     * @param sendTo 收件人
     */
    @RequestMapping(value = "/util/send")
    public String sendmail(String sendTo) {
        mailService.sendSimpleMail(sendTo, "主题:你好普通邮件", "内容:第一封邮件");
        return "发送成功!";
    }

    /**
     * 发送一个邮箱随机验证码
     *
     * @param sendTo 收件人
     */
    @RequestMapping(value = "/allow/sendHtmlCode")
    public CommonResult sendHtmlCode(String sendTo) {
//        long startTime = System.currentTimeMillis(); //获取开始时间
        try {
            String code = MyUtils.getCode(6);
//            long oneTime = System.currentTimeMillis(); //获取第一阶段时间
            Map<String, Object> data = new HashMap<>();
            data.put("code", code);
            data.put("year", Calendar.getInstance().get(Calendar.YEAR));
            redisTemplate.opsForValue().set(sendTo, code, 10, TimeUnit.MINUTES);
            System.out.println("验证码是:" + code);
//          long twoTime = System.currentTimeMillis(); //获取第二阶段时间
            mailService.sendTemplateMail(sendTo, "操作验证码", "mail", data);
//          long threeTime = System.currentTimeMillis(); //获取第三阶段时间
//          MyUtils.speedTest(startTime,oneTime,twoTime,threeTime);
            return CommonResult.success("验证码已发送,网络有延迟请稍等~");
        } catch (Exception e) {
            return CommonResult.error("发送验证码时发生异常,请稍后重试!");
        }
    }

                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");
	 SimpleHash md5 = new SimpleHash("MD5", "admin", ByteSource.Util.bytes("1325554003@qq.com"), 2);
     System.out.println(md5.toHex());
}
    /*重置密码、找回密码*/
    }

    @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);
        }else{
            return CommonResult.error("退货商品查询失败");
        }
    }
    /*查询全部退货商品*/
    @RequestMapping(value = "/returnGoods/findAllReturn")
    /*查询全部供应商名称*/
    @RequestMapping(value = "/supplier/findAllName")
    private CommonResult findAllName() {
        List<String> names = supplierService.selectAllName();
        if(names!=null){
            return CommonResult.success("供货商名称查询成功",names);
        }else{
            return CommonResult.error("供货商名称查询失败");
        }
    }
    /*查询供应商是否存在*/
    @RequestMapping(value = "/supplier/existSupplier")
    private CommonResult existSupplier(Integer supplierId,String supplierName) {
        Boolean isExist = supplierService.existsWithSupplierName(supplierId,supplierName);
        if(isExist!=null){
            return CommonResult.success("查询成功",isExist);
        }else{
            return CommonResult.error("查询失败");
        }
    }
    /*添加供应商*/
    @RequestMapping(value = "/supplier/addSupplier")
    private CommonResult addSupplier(Supplier supplier) {
        if(supplier!=null){
            if(supplierService.insertData(supplier)){
                return CommonResult.success("添加成功",supplier);
            }else{
                return CommonResult.error("添加失败");
            }
        }
        return CommonResult.error("供应商数据不存在");
    }
    /*修改供应商*/
    @RequestMapping(value = "/supplier/updateSupplier")
    private CommonResult updateSupplier(Supplier supplier) {
        if(supplier!=null){
            if(supplierService.updateById(supplier)){
                return CommonResult.success("更新成功",supplier);
            }else{
                return CommonResult.error("更新失败");
            }
        }
        return CommonResult.error("供应商数据不存在");
    }
    @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);
            }else{
                return CommonResult.error("查询失败");
            }
            return CommonResult.error("商品品牌删除失败");
        }
    }

    @RequestMapping(value = "/productBrand/deleteByName")
    private CommonResult deleteBrandByName(String brandName) {
        if(productBrandService.deleteByName(brandName)){
            return CommonResult.success("商品品牌删除成功","brandName: "+brandName);
        }else{
            return CommonResult.error("商品品牌删除失败");
        }
    }

    @RequestMapping(value = "/productBrand/findAll")
    private CommonResult findAllBrand() {
        List<ProductBrand> productBrands = productBrandService.selectAll();
        if(productBrands!=null){
            return CommonResult.success("商品品牌查询成功",productBrands);
        }else{
            return CommonResult.error("商品品牌查询失败");
        }
    }

    @RequestMapping(value = "/productBrand/existsBrandName")
    private CommonResult existsBrandName(Integer brandId,String brandName) {
        Boolean isExist = productBrandService.existsWithBrandName(brandId,brandName);
        if(isExist!=null){
            return CommonResult.success("查询成功",isExist);
        }else{
            return CommonResult.error("查询失败");
        }
    }

    @RequestMapping(value = "/productBrand/findAllName")
    private CommonResult findAllBrandName() {
        List<String> names = productBrandService.selectAllName();
        if(names!=null){
            return CommonResult.success("商品品牌名称查询成功",names);
        }else{
            return CommonResult.error("商品品牌名称查询失败");
        }
    }
}
package com.qiu.controller;
 * @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<>();
        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){
            }
        }
        return CommonResult.error("用户数据不存在");
    }

    /*用于注册新用户*/
    @RequestMapping(value = "/allow/add")
    private CommonResult add(User user) {
        if(user.getPassword()!=null && user.getUserName()!=null){
//            SimpleHash md5 = new SimpleHash("MD5", user.getPassword(), ByteSource.Util.bytes(user.getAccountNumber()), 2);
//            user.setPassword(md5.toHex());
            user.setUserState(true);
            user.setCreatTime(Timestamp.valueOf(LocalDateTime.now()));
            if(userService.insertData(user)){
                logger.info("成功添加了一个新用户");
                return CommonResult.success("注册成功",user);
            }else{
                return CommonResult.error("注册失败");
            }
        }
        return CommonResult.error("用户数据不存在");
    }

    //更新用户信息
    @RequestMapping(value = "/allow/update")
    private CommonResult update(User user) {
        System.out.println(user);
        if(userService.updateById(user)){
            return CommonResult.success("信息保存成功",user);
        }else{
            return CommonResult.error("信息保存失败");
        }
    }

}
package com.qiu.controller;
            //更新最后登录时间
            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("您的帐号存在异常行为,已被封停(请联系工作人员)");
        } catch (IncorrectCredentialsException e) {
            return CommonResult.error("密码错误,请重新输入");
        } catch (AuthenticationException e) {
            return CommonResult.error("该用户不存在");
        }
    }

    /**
     * 退出登录操作
     * @param key       用户登录的帐号
     * @param session  前端存储的session(token)
     */
    @RequestMapping(value = "/logout")
    private CommonResult logout(String key,String session) {
        if(key!=null){
            try{
                User user = userService.selectByKey(key);
                Subject subject = SecurityUtils.getSubject();
                //清除用户缓存
                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());
            }
    }
}
package com.qiu.controller;

@CrossOrigin
@RequestMapping("/alipay")
@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,
        this.productService = productService;
    }

    /*商品类别*/
    @RequestMapping(value = "/product/findById")
    private CommonResult findById(Integer productId) {
        Product product = productService.selectById(productId);
        if(product!=null){
            return CommonResult.success("商品查询成功",product);
        }else{
            return CommonResult.error("商品查询失败");
        }
    }
    @RequestMapping(value = "/product/findByKey")
    private CommonResult findByKey(String productNo) {
        Product product = productService.selectByKey(productNo);
        if(product!=null){
            return CommonResult.success("商品查询成功",product);
        }else{
            return CommonResult.error("商品查询失败");
        }
    }
    @RequestMapping(value = "/product/findIdByKey")
    private CommonResult findIdByKey(String productNo) {
        Integer productId = productService.selectIdByKey(productNo);
        if(productId!=null){
            return CommonResult.success("商品id查询成功",productId);
        }else{
            return CommonResult.error("商品id查询失败");
        }
    }
    @RequestMapping(value = "/product/findCount")
    private CommonResult findCount() {
        Integer count = productService.selectCount();
        if(count!=null){
            return CommonResult.success("商品数量查询成功",count);
        }else{
            return CommonResult.error("商品数量查询失败");
        }
    }
    @RequestMapping(value = "/product/existsKey")
    private CommonResult existsKey(String productNo) {
        Boolean isExist = productService.existsWithPrimaryKey(productNo);
        if(isExist!=null){
            return CommonResult.success("商品是否存在查询成功",isExist);
        }else{
    private CommonResult existPurchase(String purchaseNo) {
        Boolean isExist = purchaseService.existsWithPrimaryKey(purchaseNo);
        if(isExist!=null){
            return CommonResult.success("查询成功",isExist);
        }else{
            return CommonResult.error("查询失败");
        }
    }
    /*添加采购信息*/
    @RequestMapping(value = "/purchase/addPurchase")
    private CommonResult addPurchase(Purchase purchase) {
        if(purchase!=null){
            if(purchaseService.insertData(purchase)){
                return CommonResult.success("添加成功",purchase);
            }else{
                return CommonResult.error("添加失败");
            }
        }
        return CommonResult.error("采购信息数据不存在");
    }
    /*修改采购信息*/
    @RequestMapping(value = "/purchase/updatePurchase")
    private CommonResult updatePurchase(Purchase purchase) {
        if(purchase!=null){
            if(purchaseService.updateById(purchase)){
                return CommonResult.success("更新成功",purchase);
            }else{
                return CommonResult.error("更新失败");
            }
        }
        return CommonResult.error("采购信息数据不存在");
    }
    /*删除采购信息*/
    @RequestMapping(value = "/purchase/deletePurchase")
    private CommonResult deletePurchase(Integer purchaseId) {
        if(purchaseId!=null){
            if(purchaseService.deleteById(purchaseId)){
                return CommonResult.success("删除成功",purchaseId);
            }else{
                return CommonResult.error("删除失败");
                }
                response.sendRedirect("http://"+hostAddress+"/?#/myOrder");
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
    }

    @ResponseBody
    @PostMapping(value = "/payNotify")
    public void payNotify(@RequestParam Map<String, String> map) {
        String tradeStatus = map.get("trade_status");
        if(tradeStatus.equals("TRADE_SUCCESS")){
            String payTime = map.get("gmt_payment");
            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);
        }
    }
}
package com.qiu.controller;

/**
 * @email qiudb.top@aliyun.com
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllByType")
    private CommonResult findAllByType() {
        List<Map<String, Object>> maps = productService.selectAllByType();
        if(maps!=null){
            return CommonResult.success("商品分类信息查询成功",maps);
        }else{
            return CommonResult.error("商品分类信息查询失败");
        }
    }

    @RequestMapping(value = "/product/add")
    private CommonResult add(Product product) {
        System.out.println(product);
        if(productService.insertData(product)){
            return CommonResult.success("添加商品成功",product);
        }else{
            return CommonResult.error("添加商品失败");
        }
    }

    @RequestMapping(value = "/product/update")
    private CommonResult update(Product product) {
        if(product.getIsNew()!=null && product.getIsNew()){
            product.setSaleTime(new Date());
        }
        if(productService.updateById(product)){
            return CommonResult.success("修改商品成功",product);
        }else{
            return CommonResult.error("修改商品失败");
        }
    }

    @RequestMapping(value = "/product/delete")
    private CommonResult delete(Integer productId) {
        if(productService.deleteById(productId)){
            return CommonResult.success("商品删除成功","productId:" + productId);
        }else{
            return CommonResult.error("商品删除失败");
        }
    }

    /*商品类别*/
    @RequestMapping(value = "/productType/add")
    private CommonResult addType(ProductType productType) {
        }
    }
    @RequestMapping(value = "/product/findAllSale")
    private CommonResult findAllSale() {
        List<Product> products = productService.selectAllSale();
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllLikeName")
    private CommonResult findAllLikeName(String keyWord) {
        List<Product> products = productService.selectAllLikeName(keyWord);
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllLikeType")
    private CommonResult findAllLikeType(String keyWord) {
        List<Product> products = productService.selectAllLikeType(keyWord);
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllLikeBrand")
    private CommonResult findAllLikeBrand(String keyWord) {
        List<Product> products = productService.selectAllLikeBrand(keyWord);
        if(products!=null){
            return CommonResult.success("全部商品信息查询成功",products);
        }else{
            return CommonResult.error("全部商品信息查询失败");
        }
    }
    @RequestMapping(value = "/product/findAllByType")
    private CommonResult findAllByType() {
        List<Map<String, Object>> maps = productService.selectAllByType();
        if(maps!=null){
            return CommonResult.success("商品分类信息查询成功",maps);
        }else{
            return CommonResult.error("商品分类信息查询失败");
        }
        }
    }

    @RequestMapping(value = "/shoppingCart/update")
    private CommonResult updateShoppingCart(ShoppingCart shoppingCart) {
        if(shoppingCartService.updateById(shoppingCart)){
            return CommonResult.success("购物车修改成功",shoppingCart);
        }else{
            return CommonResult.error("购物车修改失败");
        }
    }

    @RequestMapping(value = "/shoppingCart/deleteById")
    private CommonResult deleteShoppingCart(Integer cartId) {
        if(shoppingCartService.deleteById(cartId)){
            return CommonResult.success("购物车删除成功","cartId: "+cartId);
        }else{
            return CommonResult.error("购物车删除失败");
        }
    }
    @RequestMapping(value = "/shoppingCart/deleteByUser")
    private CommonResult deleteByUser(String accountNumber) {
        if(shoppingCartService.deleteByUser(accountNumber)){
            return CommonResult.success("购物车删除成功","accountNumber: "+accountNumber);
        }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("购物车查询失败");
        }
    }

}
package com.qiu.controller;

    @RequestMapping(value = "/role/findAllUsable")
    private CommonResult findAllUsable() {
        List<Role> roles = roleService.selectAllUsable();
        if(roles!=null){
            return CommonResult.success("查询成功",roles);
        }else{
            return CommonResult.error("查询失败");
        }
    }

    @RequestMapping(value = "/role/count")
    private CommonResult findCount() {
        Integer count = roleService.selectCount();
        if(count!=null){
            return CommonResult.success("查询成功",count);
        }else{
            return CommonResult.error("查询失败");
        }
    }

    @RequestMapping(value = "/role/findIdByKey")
    private CommonResult findIdByKey(String key) {
        Integer id = roleService.selectIdByKey(key);
        if(id!=null){
            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) {
            }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");
	 SimpleHash md5 = new SimpleHash("MD5", "admin", ByteSource.Util.bytes("1325554003@qq.com"), 2);
     System.out.println(md5.toHex());
}
    /*重置密码、找回密码*/
    @RequestMapping(value = "/allow/resetpwd")
    private CommonResult resetPwd(String accountNumber,String password) {
        if(accountNumber!=null && password!=null){
//            SimpleHash md5 = new SimpleHash("MD5", password, ByteSource.Util.bytes(accountNumber), 2);
//            password=md5.toHex();
            Integer id = userService.selectIdByKey(accountNumber);
            User user = new User();
            user.setUserId(id);
 * @email qiudb.top@aliyun.com
 * @description 商品评价 业务类
 */
@RestController
@CrossOrigin
public class ProductReviewController {
    final ProductReviewService ProductReviewService;
    final OrderService orderService;
    public ProductReviewController(ProductReviewService ProductReviewService,OrderService orderService){
        this.ProductReviewService = ProductReviewService;
        this.orderService = orderService;
    }

    /*商品类别*/
    @RequestMapping(value = "/productReview/add")
    private CommonResult addProductReview(ProductReview productReview) {
        if(ProductReviewService.insertData(productReview)){
            Integer orderId = orderService.selectIdByKey(productReview.getOrderNo());
            Order order = new Order();
            order.setOrderId(orderId);
            order.setOrderState("已评价");
            orderService.updateById(order);
            return CommonResult.success("商品评论添加成功",productReview);
        }else{
            return CommonResult.error("商品评论添加失败");
        }
    }

    @RequestMapping(value = "/productReview/update")
    private CommonResult updateProductReview(ProductReview productReview) {
        if(ProductReviewService.updateById(productReview)){
            return CommonResult.success("商品评论修改成功",productReview);
        }else{
            return CommonResult.error("商品评论修改失败");
        }
    }

    @RequestMapping(value = "/productReview/deleteById")
    private CommonResult deleteProductReview(Integer reviewId) {
        if(ProductReviewService.deleteById(reviewId)){
            return CommonResult.success("商品评论删除成功","reviewId: "+reviewId);
        }else{
            return CommonResult.error("商品评论删除失败");
        }
    }

    @RequestMapping(value = "/productReview/findAll")
    private CommonResult findAllProductReview(String productNo) {

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值