OnlineMall简易版网上商城系统(后端)

此项目用redis做中间缓存,大多数数据都保存在redis中.利用restful风格的方式,便于快速找到请求路径和对应的方法.对个别实体,创建DTO,查询前端所需要的数据,封装DTO,返回数据.

主要技术(spring+springmvc+mybatis-plus+redis)

项目结构:

Service层主要代码:

UserServiceImp

主要功能:完成用户的注册和登录,对用户的增删改查.

package com.hzy.onlinemall.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzy.onlinemall.bean.Users;
import com.hzy.onlinemall.dto.Result;
import com.hzy.onlinemall.dto.UserDTO;
import com.hzy.onlinemall.mapper.UsersMapper;
import com.hzy.onlinemall.service.UsersService;
import com.hzy.onlinemall.util.MyPage;
import com.hzy.onlinemall.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;;
import java.util.stream.Collectors;

import static com.hzy.onlinemall.util.RedisConstants.*;
import static com.hzy.onlinemall.util.SystemConstants.USERS_PHONE;
import static com.hzy.onlinemall.util.SystemConstants.USERS_PK;

/**
 * @Description TODO  先操作数据库再操作redis
 * @Author ziyong_hu
 * @Date 2023/9/18 10:11
 */

@Service
@Transactional
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private  RedisUtil redisUtil;
    //用户注册
    public Result register(Users users){
        stringRedisTemplate.opsForHash().put(USERS_KEY,users.getUPhone(),users.toString());
        return Result.ok(save(users)) ;
     }
    //用户登录
    public Result login(String username,String password){
         //用户数输入名字和密码进行登录,如果登录成功,把该用户的数据存入redis中.
        Users users = query().eq("u_name", username).eq("u_pwd", password).one();
        if (users==null)
            return Result.fail("登录失败,请重新输入...");
        stringRedisTemplate.opsForValue().set("user:"+users.getUId().toString(),JSONUtil.toJsonStr(users));
        return Result.ok(true) ;
    }
    //用户查看个人信息
    public Result selectOne(Integer id){
         if (id==null)
             return Result.ok(false);
         //通过id先查询redis中有没有该数据,没有则查询数据库.
        String userStr = stringRedisTemplate.opsForValue().get(USER_KEY+ id.toString());
        if (userStr!=null)
            //redis中有该条数据,直接返回
            return Result.ok(JSONUtil.toBean(userStr, Users.class));
            Users user = query().eq(USERS_PK, id).one();
            return Result.ok(user);
    }
    //用户修改个人信息
    public  Result updateInfo(Users users){
         Boolean isSuccess= updateById(users);
         Users user = query().eq(USERS_PK, users.getUId()).one();
         stringRedisTemplate.opsForValue().set(USER_KEY+user.getUId(),JSONUtil.toJsonStr(user));
         return Result.ok(isSuccess) ;
     }
    //管理员查看所有用户
    public Result selectAll(Integer pageStart){
         //先查询redis,再查询数据库
        MyPage page = redisUtil.getPage(pageStart, USERS_KEY, USERS_SORT_KEY,Users.class);
        if (page!=null){
            return  Result.ok(page);
        }
        List<Users> list = query().list();
        for (Users user:list) {
            String userStr = JSONUtil.toJsonStr(user);
            stringRedisTemplate.opsForHash().put(USERS_KEY,user.getUId().toString(),userStr);
            stringRedisTemplate.opsForZSet().add(USERS_SORT_KEY,user.getUId().toString(),user.getUId());
        }
        return selectAll(pageStart);
    }
    //删除个人信息
    public  Result delete(String uPhone){
        Long delete = stringRedisTemplate.opsForHash().delete(USERS_KEY, uPhone);
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.eq(USERS_PHONE,uPhone);
        boolean removeById = remove(wrapper);
        return Result.ok(delete==1 && removeById);
    }
    //通过id拆查询userDTO(姓名,电话,地址)
    public UserDTO selectUserDTOByID(Integer id){
        Result result = selectOne(id);
        Users user =(Users) result.getData();
        return UserDTO.builder().userName(user.getUName()).userPhone(user.getUPhone()).userAddress(user.getUAddress()).build();
    }
}

 OrderServiceImpl

主要功能:当用户点击支付按钮时对订单,以及商品表的改动。用户可以直接点击购买,也可以先加入购物车,再购买此商品

package com.hzy.onlinemall.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzy.onlinemall.bean.Orders;
import com.hzy.onlinemall.dto.CarDTO;
import com.hzy.onlinemall.dto.GoodsDTO;
import com.hzy.onlinemall.dto.Result;
import com.hzy.onlinemall.mapper.OrdersMapper;
import com.hzy.onlinemall.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.hzy.onlinemall.util.RedisConstants.*;
import static com.hzy.onlinemall.util.SystemConstants.ORDERS_TABLE_KEY;

/**
 * @Description TODO
 * @Author ziyong_hu
 * @Date 2023/9/18 10:09
 */
@Service
@Transactional
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private OrderDetailServiceImpl orderDetailService;
    @Autowired
    private GoodsServiceImpl goodsService;
    @Autowired
    private  CarsServiceImpl carsService;
    //这里用户点击购买,但是还没有付款,我们不存入数据库中,存入redis中,设置过期时间
    //{
    //     "uid":5,
    //     "gid":6,
    //     "ototal":10,
    //      "ostatus":0
    //}
    public Result insertOne(Orders orders){
        orders.setOId(RandomUtil.randomNumbers(10)); //将id作为key
        /*
        * 先查询goods表,取出商品的单价,单价*购买数量=该批订单的总金额;
        * */
        GoodsDTO goodsDTO = goodsService.selectGoodsDTOByID(orders.getGId());
        orders.setOPrice(orders.getOTotal()*goodsDTO.getGoodsPrice());
        stringRedisTemplate.opsForValue().set(ORDER_KEY+ORDER_NO_PAY_KEY+orders.getOId(),JSONUtil.toJsonStr(orders), REDIS_ORDER_TTL, TimeUnit.MINUTES);
        return Result.ok(true);
    }

    //用户点击支付按钮.将数据写入数据库中和redis中(Key发送改变),商品销售量++;
    public Result buyGoods(String oid) {
        String s = stringRedisTemplate.opsForValue().get(ORDER_KEY+ORDER_NO_PAY_KEY+oid);
        //如果s==null,说明支付时间过期,需重新支付
        if (s==null){
         return Result.fail("支付失败请重新支付");
        }
        Orders order = JSONUtil.toBean(s, Orders.class);
        //这里要设置订单的状态(已支付),并且更新下单时间.
        order.setOTime(new Date());
        order.setOStatus(1);
        if (!save(order)){
          return Result.fail("支付失败请重新支付");
        }
        stringRedisTemplate.opsForHash().put(ORDERS_KEY,order.getOId(), JSONUtil.toJsonStr(order));
        //删除未支付的订单
        stringRedisTemplate.delete(ORDER_KEY+ORDER_NO_PAY_KEY+order.getOId());
        System.out.println(ORDER_KEY+ORDER_NO_PAY_KEY+order.getOId());
        //新增订单详情
        orderDetailService.insert(order);
        //删除购物车的商品
        carsService.deleteCar(order.getUId());
        //修改库存和销售量
//        insertOne(order);
        goodsService.updateQuantityById(order);
        return Result.ok("支付成功...");
    }

    //通过传入的购物车id,购买商品
    public Result buyGoodsByCarId(CarDTO carDTO) {
        System.out.println("buyGoodsByCarId:---------------------------------"+carDTO.toString());
        //这里要设置订单的状态(已支付),并且更新下单时间.
        Orders order = Orders.builder()
                .oId(RandomUtil.randomNumbers(10))
                .gId(carDTO.getGID())
                .uId(carDTO.getUID())
                .oPrice(carDTO.getGoodsPrice()*carDTO.getBuyNum())
                .oTotal(carDTO.getBuyNum())
                .oStatus(1)
                .oTime(new Date())
                .build();
        if (!save(order)){
            return Result.fail("支付失败请重新支付");
        }
        stringRedisTemplate.opsForHash().put(ORDERS_KEY,order.getOId(), JSONUtil.toJsonStr(order));
        //删除未支付的订单
        stringRedisTemplate.delete(ORDER_KEY+ORDER_NO_PAY_KEY+order.getOId());
        System.out.println(ORDER_KEY+ORDER_NO_PAY_KEY+order.getOId());
        //新增订单详情
        System.out.println("加入订单表中的gid"+order.getGId());
        orderDetailService.insert(order);
//        //删除购物车的商品
//        carsService.deleteCar(order.getUId());
        //修改库存和销售量
         goodsService.updateQuantityById(order);
        return Result.ok("支付成功...");
    }

    //用户查看个人订单(传用户的ID)
    public Result selectOne(Integer id){
       Set<String> members = stringRedisTemplate.opsForSet().members(ORDER_KEY+ORDER_PAY_KEY+id.toString());
       if (members.size()==0){
           QueryWrapper<Orders> wrapper = new QueryWrapper<>();
           wrapper.eq(ORDERS_TABLE_KEY, id);
           List<Orders> ordersList = ordersMapper.selectList(wrapper);
           if (ordersList.size()!=0){
               for (int i = 0; i <ordersList.size() ; i++) {
                   Orders orders = ordersList.get(i);
                   System.out.println(orders.toString());
                   stringRedisTemplate.opsForSet().add(ORDER_KEY+ORDER_PAY_KEY+orders.getUId().toString(),JSONUtil.toJsonStr(orders));
               }
               return Result.ok(ordersList) ;
           }
       }
       return Result.ok(members.stream().map(z -> JSONUtil.toBean(JSONUtil.toJsonStr(z), Orders.class)).collect(Collectors.toList()));
   }

    //管理员查看所有订单
    public Result selectAll(){
        List<Object> values = stringRedisTemplate.opsForHash().values(ORDERS_KEY);
        if (values.size()==0){
            List<Orders> orders = query().list();
                for (int i = 0; i < orders.size(); i++) {
                    Orders order = orders.get(i);
                    stringRedisTemplate.opsForHash().put(ORDERS_KEY,order.getOId(),JSONUtil.toJsonStr(order));
                }
                return Result.ok(orders);
        }
        return  Result.ok(values.stream().map(z -> JSONUtil.toBean(JSONUtil.toJsonStr(z), Orders.class)).collect(Collectors.toList()));
    }

    //通过订单ID查询订单
    public  Orders selectByOID(String OID){
        Object o = stringRedisTemplate.opsForHash().get(ORDERS_KEY, OID);
        if (o!=null){
            return JSONUtil.toBean(o.toString(),Orders.class);
        }
        return null;
    }
}

GoodsServiceImpl

主要功能:对用户的增删改查,以及模糊查询和分页

package com.hzy.onlinemall.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzy.onlinemall.bean.Goods;
import com.hzy.onlinemall.bean.Orders;
import com.hzy.onlinemall.dto.GoodsDTO;
import com.hzy.onlinemall.dto.Result;
import com.hzy.onlinemall.mapper.GoodsMapper;
import com.hzy.onlinemall.service.GoodsService;
import com.hzy.onlinemall.util.MyPage;
import com.hzy.onlinemall.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.hzy.onlinemall.util.RedisConstants.*;
import static com.hzy.onlinemall.util.SystemConstants.GOODS_NAME;

/**
 * @Description TODO
 * @Author ziyong_hu
 * @Date 2023/9/18 10:05
 */
@Service
@Transactional
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
  @Resource
  private StringRedisTemplate stringRedisTemplate;
  @Autowired
  private TypeServiceImpl typeService;
  @Autowired
  private GoodsMapper goodsMapper;
  @Autowired
  private RedisUtil redisUtil;

    //同过商品id查询商品
    public  Result selectOne(Integer id){
       Object o = stringRedisTemplate.opsForHash().get(GOODS_KEY, id.toString());
       return Result.ok( JSONUtil.toBean(o.toString(), Goods.class));
   }

    //通过id查询GoodsDTO(商品名称,商品价格)
    public GoodsDTO selectGoodsDTOByID(Integer id){
        Goods goods =(Goods) selectOne(id).getData();
        GoodsDTO goodsDTO = GoodsDTO.builder().goodsName(goods.getGName()).goodsPrice(goods.getGPrice()).build();
        return goodsDTO ;
    }

    //查看所有商品(分页查询)-->这里用redis ZSet实现分页查询.
    public Result listGoodsPage(Integer pageStart){
        MyPage page = redisUtil.getPage(pageStart,GOODS_KEY,GOODS_LIMIT_KEY,Goods.class);
        if (page!=null){
                return Result.ok(page);
        }
       //redis中有数据
//        PageHelper.startPage(pageStart,PAGE_SIZE);
        List<Goods> goodsList = query().list();
//        PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);
        for (Goods goods :goodsList ) {
            String goodsStr = JSONUtil.toJsonStr(goods);
            stringRedisTemplate.opsForZSet().add(GOODS_LIMIT_KEY, goods.getGId().toString(), goods.getGId());
            stringRedisTemplate.opsForHash().put(GOODS_KEY,goods.getGId().toString(),goodsStr);
        }
       return   listGoodsPage(pageStart);
//        return Result.ok(pageInfo) ;
    }

    //新增商品
    public  Result insertGoods(Goods goods){
       save(goods);
       stringRedisTemplate.opsForHash().put(GOODS_KEY,goods.getGId().toString(),JSONUtil.toJsonStr(goods));
       return  Result.ok(true);
    }

    //删除商品
    public Result deleteGoods(Integer id){
       removeById(id);
       stringRedisTemplate.opsForHash().delete(GOODS_KEY,id.toString());
       return Result.ok(true);
    }

    //按照商品类别分类(用户选择商品类别查找商品)
    public Result groupByGoodsType(String gName){
        Set<String> members = stringRedisTemplate.opsForSet().members(TYPE_KEY + gName);
        return Result.ok( members.stream().map(z->JSONUtil.toBean(JSONUtil.toJsonStr(z),Goods.class)).collect(Collectors.toList()));
   }

    //修改商品(当用户已经下单时,减少库存量,增加销售量)
    public Result updateQuantityById(Orders orders){
        Goods goods =(Goods) selectOne(orders.getGId()).getData();//
        goods.setGQuantity(goods.getGQuantity()-orders.getOTotal());
        goods.setGSaleQty(goods.getGSaleQty()+orders.getOTotal());
        updateById(goods);
        stringRedisTemplate.opsForHash().put(GOODS_KEY,goods.getGId().toString(),JSONUtil.toJsonStr(goods));
        return  Result.ok(true);
    }

    //修改商品
    public  Result updateGoodsById(Goods goods){
        boolean b = updateById(goods);
        if (!b)return Result.ok(false);
        stringRedisTemplate.opsForHash().put(GOODS_KEY,goods.getGId().toString(),JSONUtil.toJsonStr(goods));
        return Result.ok(true);
    }

    //模糊查询商品
    public Result listGoodsByLike(String goodsName){
        Set<String> members = stringRedisTemplate.opsForSet().members(GOODS_KEY+GOODS_LIKE_KEY+goodsName);
        if (members!= null) {
          return Result.ok( members.stream().map(z->JSONUtil.toBean(JSONUtil.toJsonStr(z),Goods.class)).collect(Collectors.toList()));
        }
        LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<Goods> wrapper = queryWrapper.like(Goods::getGName, goodsName);
        List<Goods> goodsList = goodsMapper.selectList(wrapper);
        for (Goods goods : goodsList){
            String goodsStr = JSONUtil.toJsonStr(goods);
            stringRedisTemplate.opsForSet().add(GOODS_KEY+GOODS_LIKE_KEY+goodsName,goodsStr);
            stringRedisTemplate.expire(GOODS_KEY+GOODS_LIKE_KEY+goodsName,REDIS_GOODS_TTL, TimeUnit.MINUTES);
        }
        return Result.ok(goodsList);
    }

    //根据名字查单个商品
    public  Result selectByName(String goodsName){
        String s = stringRedisTemplate.opsForValue().get(GOODS_KEY + goodsName);
        if (s==null){
            Goods goods = query().eq(GOODS_NAME, goodsName).one();
            String goodsStr = JSONUtil.toJsonStr(goods);
            stringRedisTemplate.opsForValue().set(GOODS_KEY + goodsName,goodsStr,REDIS_GOODS_TTL,TimeUnit.MINUTES);
            return Result.ok(goods) ;
        }
        return Result.ok(JSONUtil.toBean(s,Goods.class));
    }
}

CarServiceImpl

主要功能:对购物车的增删改查.

package com.hzy.onlinemall.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzy.onlinemall.bean.Cars;
import com.hzy.onlinemall.bean.Goods;
import com.hzy.onlinemall.dto.CarDTO;
import com.hzy.onlinemall.dto.Result;
import com.hzy.onlinemall.mapper.CarsMapper;
import com.hzy.onlinemall.service.CarsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static com.hzy.onlinemall.util.RedisConstants.REDIS_CAR_DETAIL;
import static com.hzy.onlinemall.util.SystemConstants.USERS_PK;

/**
 * @Description 用户对购物车的增删改查
 * @Author ziyong_hu
 * @Date 2023/9/18 10:04
 */

@Service
@Transactional
public class CarsServiceImpl extends ServiceImpl<CarsMapper, Cars> implements CarsService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private CarsMapper carsMapper;
    @Autowired
    private GoodsServiceImpl goodsService;
    @Autowired
    private OrdersServiceImpl ordersService;

    //参数值是用户id
    public List<Cars> getSimpleCar(Integer id){
        QueryWrapper<Cars> wrapper = new QueryWrapper<>();
        wrapper.eq(USERS_PK,id);
        return  carsMapper.selectList(wrapper);
    }

    public  Cars getSimpleCarByCid(Integer cid){
        return query().eq("c_id", cid).one();
    }
    //用户id
    public Result getDetailsCar(Integer uid){
        Set<String> members = stringRedisTemplate.opsForSet().members(REDIS_CAR_DETAIL + uid);
        if (members.size()!=0){
            List<CarDTO> list = members.stream().map(z -> JSONUtil.toBean(JSONUtil.toJsonStr(z), CarDTO.class)).collect(Collectors.toList());
            System.out.println(list);
            return Result.ok(list);
        }
        //用户的购物车
        List<Cars> carsList = getSimpleCar(uid);
        ArrayList<CarDTO> carDTOList = new ArrayList<>();
        for (Cars cars:carsList){
            Goods goods =(Goods) goodsService.selectOne(cars.getGId()).getData();
            CarDTO carDTO = CarDTO.builder()
                    .gID(cars.getGId())
                    .uID(cars.getUId())
                    .buyNum(cars.getCNum())
                    .goodsName(goods.getGName())
                    .goodsInfo(goods.getGInfo())
                    .goodsPrice(goods.getGPrice())
                    .GoodsImage(goods.getGImage())
                    .total(goods.getGPrice()*cars.getCNum())
                    .cID(cars.getCId())
                    .build();
            carDTOList.add(carDTO);
            String carStr = JSONUtil.toJsonStr(carDTO);
            stringRedisTemplate.opsForSet().add(REDIS_CAR_DETAIL+uid,carStr);
        }
        return  Result.ok(carDTOList) ;
    }


    //通过cid查询DetailsCar内部使用
    public Result getDetailsCarByCid(Integer cid){
        Cars car = getSimpleCarByCid(cid);
            Goods goods =(Goods) goodsService.selectOne(car.getGId()).getData();
            CarDTO carDTO = CarDTO.builder()
                    .gID(car.getGId())
                    .uID(car.getUId())
                    .buyNum(car.getCNum())
                    .goodsName(goods.getGName())
                    .goodsInfo(goods.getGInfo())
                    .goodsPrice(goods.getGPrice())
                    .GoodsImage(goods.getGImage())
                    .total(goods.getGPrice()*car.getCNum())
                    .cID(car.getCId())
                    .build();
        return  Result.ok(carDTO) ;
    }
    //当用户将商品加入购物车,然后点击购买,此时可以看作删除该购物车,调用orders类的方法
    //参数购车id.这里需要前端传入一个cid过来.
    public  Result deleteCar(Integer cid){
//        Cars simpleCar = getSimpleCarByCid(cid);
        CarDTO carDTO = (CarDTO) getDetailsCarByCid(cid).getData();
        ordersService.buyGoodsByCarId(carDTO);
        removeById(cid);
        return Result.ok(true);
    }

    public Result addCar(Cars cars){
        return Result.ok(save(cars)) ;
    }

}

Controller层主要代码

AdminController

package com.hzy.onlinemall.controller;

import com.hzy.onlinemall.bean.Goods;
import com.hzy.onlinemall.bean.Type;
import com.hzy.onlinemall.dto.AdminDTO;
import com.hzy.onlinemall.dto.Result;
import com.hzy.onlinemall.service.impl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Description TODO
 * @Author ziyong_hu
 * @Date 2023/9/18 10:43
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminServiceImpl adminService;
    @Autowired
    private UsersServiceImpl usersService;
    @Autowired
    private TypeServiceImpl typeService;
    @Autowired
    private OrdersServiceImpl ordersService;
    @Autowired
    private OrderDetailServiceImpl orderDetailService;
    @Autowired
    private GoodsServiceImpl goodsService;
    @Autowired
    private  HistoryServiceImpl historyService;

    @PostMapping("/login")
    public Result login(@RequestBody AdminDTO adminDTO){
      return  Result.ok(adminService.Login(adminDTO.getAName(),adminDTO.getAPwd()));
    }

    @GetMapping("/user/list")
    public  Result listUserNOParams(Integer pageStart){
        return Result.ok(usersService.selectAll(pageStart));
    }

    @GetMapping("/user/list/{pageStart}")
    public  Result listUserParams(@PathVariable Integer pageStart){
        return Result.ok(usersService.selectAll(pageStart));
    }

    @PutMapping("/type/update")
    public  Result update(@RequestBody Type type){
        return Result.ok(typeService.update(type));
     }

    @GetMapping("/type/list")
    public  Result listType(){
        return Result.ok(typeService.selectAll());
    }

    @DeleteMapping("/type/delete/{name}")
    public Result delete(@PathVariable String name){
        return Result.ok(typeService.delete(name));
     }

     @GetMapping("/order/list")
    public Result selectAll(){
        return Result.ok(ordersService.selectAll());
     }

     @GetMapping("/orderDetail/list")
    public  Result  orderDetailList(){
        return Result.ok(orderDetailService.orderDetailList());
     }

     @GetMapping("/orderDetailDTO/list")
    public  Result orderDetailDTOList(){
        return  Result.ok(orderDetailService.orderDetailDTOList());
     }

     @GetMapping("/goods/list/{pageStart}")
    public Result goodsList(@PathVariable Integer pageStart){
        return Result.ok(goodsService.listGoodsPage(pageStart));
     }

     @PostMapping("/goods/insert")
    public  Result insert(@RequestBody Goods goods){
        return  goodsService.insertGoods(goods);
     }

     @DeleteMapping("/goods/delete/{id}")
    public  Result delete(@PathVariable Integer id){
        return  Result.ok(goodsService.deleteGoods(id));
     }

     @GetMapping("/goods/selectOne/{id}")
    public Result selectOne(@PathVariable Integer id){
        return Result.ok(goodsService.selectOne(id));
     }

     @GetMapping("/goods/groupByGoods")
    public Result groupByGoods(){
       return Result.ok(typeService.groupByGoods());
     }

     @GetMapping("/history/remove/{id}/{reason}")
    public  Result removedGoods(@PathVariable Integer id,@PathVariable String reason){
        return  Result.ok(historyService.removedGoods(id,reason));
     }

     @GetMapping("/history/list")
    public Result selectAllHistory(){
        return Result.ok(historyService.selectAllHistory());
     }

     @GetMapping("/history/ReShelve/{id}")
    public  Result ReShelve(@PathVariable Integer id){
        return Result.ok(historyService.ReShelve(id));
    }

}

UserController

package com.hzy.onlinemall.controller;

import com.hzy.onlinemall.bean.Cars;
import com.hzy.onlinemall.bean.Users;
import com.hzy.onlinemall.dto.Result;
import com.hzy.onlinemall.dto.UsersVo;
import com.hzy.onlinemall.service.impl.CarsServiceImpl;
import com.hzy.onlinemall.service.impl.GoodsServiceImpl;
import com.hzy.onlinemall.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author ziyong_hu
 * @Date 2023/9/18 15:16
 */
@RestController
@RequestMapping("/user")
public class UsersController {
    @Autowired
    private UsersServiceImpl usersService;
    @Autowired
    private GoodsServiceImpl goodsService;
    @Autowired
    private CarsServiceImpl carsService;

    //用户注册
    @PostMapping ("/register")
    public Result insert(@RequestBody Users users){
        return Result.ok(usersService.register(users));
    }

    //用户登录
    @PostMapping("/login")
    public  Result login(@RequestBody UsersVo UsersVo){
        return  Result.ok(usersService.login(UsersVo.getUName(),UsersVo.getUPwd()));
    }

    //查看个人信息
    @GetMapping("/self/{id}")
    public  Result self(@PathVariable Integer id){
        return Result.ok(usersService.selectOne(id));
    }

    //修改个人信息
    @PutMapping("/update")
    public  Result updateInfo(@RequestBody Users users){
        return Result.ok(usersService.updateInfo(users));
    }

    @DeleteMapping("/delete/{uPhone}")
    public  Result delete(@PathVariable String uPhone){
        return  Result.ok(usersService.delete(uPhone));
    }

    @GetMapping("/goods/list/{pageStart}")
    public Result goodsList(@PathVariable Integer pageStart){
        return Result.ok(goodsService.listGoodsPage(pageStart));
    }

    @GetMapping("/goods/list")
    public Result goodsListNoParams(Integer pageStart){
        return Result.ok(goodsService.listGoodsPage(pageStart));
    }

    @GetMapping("/goods/groupbygoods/{gName}")
    public  Result GroupByGoods(@PathVariable String gName){
            return  Result.ok(goodsService.groupByGoodsType(gName));
    }

    @GetMapping("/goods/listGoodsByLike/{gName}")
    public  Result listGoodsByLike(@PathVariable String gName){
       return Result.ok(goodsService.listGoodsByLike(gName)) ;
    }

    @GetMapping("/goods/selectByName/{gName}")
    public  Result selectByName(@PathVariable String gName){
        return  Result.ok(goodsService.selectByName(gName));
    }

    @GetMapping("/car/selectSimpleCar/{id}")
    public  Result getSimpleCar(@PathVariable Integer id){
        return  Result.ok(carsService.getSimpleCar(id));
    }

    @GetMapping("/car/selectDetailCar/{id}")
    public Result getDetailsCar(@PathVariable Integer id){
        return Result.ok(carsService.getDetailsCar(id));
    }

    @PostMapping("/car/add")
    public  Result addCar(@RequestBody Cars cars){
      return Result.ok(carsService.addCar(cars));
    }

    @GetMapping("/car/deleteCar/{cid}")
    public  Result deleteCar(@PathVariable Integer cid){
        return  Result.ok(carsService.deleteCar(cid));
    }


}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值