基于javaweb+mysql的springboot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)

基于javaweb+mysql的springboot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

基于javaweb的SpringBoot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)

管理员:

admin 123456

用户:

13511111111 123456

13511111112 123456

13511111113 123456

                }
            }
            for (int i = 0; i < (hot1.size() % 4 == 0 ? hot1.size() / 4 : hot1.size() / 4 + 1); i++) {
                int end = (i + 1) * 4;
                if (end > hot1.size() - 1) {
                    end = hot1.size() - 1;
                }
                hots.add(hot1.subList(i * 4, end));
            }
            model.addAttribute("hots", hots);
        }
        return "mobile/index";
    }

}

/**
 * 登录拦截器
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Autowired
    private UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        if(!httpServletRequest.getRequestURI().endsWith("htm")){
            return true;
        }
        Cookie[] cookies =  httpServletRequest.getCookies();
        if(cookies==null || cookies.length==0){
            throw new NeedLoginException("需要登录");
        }
        String uid = "";
        for (Cookie cookie : cookies) {
            if(cookie.getName().equals("login_key_auth")){
        for (int i = 0; i <ids.length ; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            if(shopEntity.getStock()==null || shopEntity.getStock()<shoppingGatEntity.getNum()){
                return Result.error(shopEntity.getName()+"库存不足");
            }
        }

        orderEntity.setAddress(customerAddressEntity.getAddress());
        orderEntity.setName(customerAddressEntity.getName());
        orderEntity.setPhone(customerAddressEntity.getPhone());
        orderService.insert(orderEntity);
        for (int i = 0; i <ids.length ; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            OrderShopEntity orderShopEntity = new OrderShopEntity();
            orderShopEntity.setId(IdWorkerUtil.getId());
            orderShopEntity.setPrice(new BigDecimal(prices[i]));
            orderShopEntity.setNum(nums[i]);
            orderShopEntity.setOrderId(orderEntity.getId());
            orderShopEntity.setName(shopEntity.getName());
            orderShopEntity.setCover(shopEntity.getCover());
            orderShopEntity.setShopId(shopEntity.getId());
            orderShopEntity.setCustomerId(userEntity.getId());
            orderShopService.insert(orderShopEntity);
            shopEntity.setStock(shopEntity.getStock()-nums[i]);
            shopService.updateById(shopEntity);
            shoppingGatService.deleteById(ids[i]);
            if(!StringUtils.isEmpty(shoppingGatEntity.getCid())){
                RoyaltyEntity royaltyEntity = new RoyaltyEntity();
                royaltyEntity.setId(IdWorkerUtil.getId());
                royaltyEntity.setCustomer(shoppingGatEntity.getCid());
                royaltyEntity.setMark("订单下单抽取提成");
                royaltyEntity.setTime(new Date());
                royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
                royaltyService.insert(royaltyEntity);
            }
        }
        return Result.success("订单结算成功");
    }

}


/**
 * 普通用户管理
 */
@Controller
@RequestMapping("childType")
public class ChildTypeController {

    @Autowired
    private ChildTypeService childTypeService  ;

    /**
     * 根据1级分类查询2级分类
     * @param type
     * @return
     */
    @PostMapping("childList.htm")
    @ResponseBody
    public Result childList(Integer type){
        EntityWrapper entityWrapper = new EntityWrapper();
        List<ChildTypeEntity> list =  childTypeService.selectList(entityWrapper);
        return Result.success(list);
    }

    /**
     * 根据1级分类查询2级分类
     * @param type
     * @return
     */
    @PostMapping("childList.do")
    @ResponseBody
    public Result childListdo(Integer type){
        EntityWrapper entityWrapper = new EntityWrapper();
        List<ChildTypeEntity> list =  childTypeService.selectList(entityWrapper);
        return Result.success(list);
    }

    public String list(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq(CustomerAddressTable.CUSTOMER_ID,customerEntity.getId());
        List<CustomerAddressEntity> list = service.selectList(wrapper);
        model.addAttribute("list",list);
        return "mobile/address_list";
    }

    /**
     * 保存界面
     * @param model
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("save.do")
    public String save(Model model,String id)throws Exception{
        CustomerAddressEntity entity = new CustomerAddressEntity();
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);
        return "mobile/address_save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.do")
    @ResponseBody
    public Result save(Model model, CustomerAddressEntity entity)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        entity.setCustomerId(customerEntity.getId());
        if(StringUtils.isEmpty(entity.getId())){
            entity.setId(IdWorkerUtil.getId());
            service.insert(entity);
        }else{
            service.updateById(entity);
        }
        return Result.success("保存成功");
    }

    /**
     * 删除
     * @param id
     * @return

}

@Controller
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private MenuService menuService;

    @Autowired
    private RoleMenuService roleMenuService;

    /**
     * 角色界面
     * @param model
     * @return
     * @throws Exception
     */
    @GetMapping("list.htm")
    public String list(Model model)throws Exception{
     * @param model
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("save.htm")
    public String save(Model model,String id)throws Exception{
        CustomerEntity entity = new CustomerEntity();
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);
        return "customer/save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.htm")
    @ResponseBody
    public Result save(Model model, CustomerEntity entity)throws Exception{
        if(StringUtils.isEmpty(entity.getId())){
            entity.setId(IdWorkerUtil.getId());
            service.insert(entity);
        }else{
            if(entity.getAuthStatus()==2){
                entity.setType(2);
            }
            service.updateById(entity);
        }
        return Result.success("保存成功");
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("del.htm")
    @ResponseBody
    public Result del(String id)throws Exception{
        service.deleteById(id);
        return Result.success("保存成功");
    }

        for (String s : set) {
            RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
            roleMenuEntity.setId(IdWorkerUtil.getId());
            roleMenuEntity.setMenuId(s);
            roleMenuEntity.setRoleId(roleId);
            roleMenuService.insert(roleMenuEntity);
        }
        for (String s : list) {
            RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
            roleMenuEntity.setId(IdWorkerUtil.getId());
            roleMenuEntity.setMenuId(s);
            roleMenuEntity.setRoleId(roleId);
            roleMenuService.insert(roleMenuEntity);
        }
        return Result.success("权限保存成功");
    }

}

@Controller
@RequestMapping("mobileCustomer")
public class MobileCustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 我的界面
     * @param model
     * @return
     * @throws Exception
     */
     */
    @GetMapping("list.htm")
    public String list(Model model)throws Exception{
        List<RoleEntity> list = roleService.selectList(new EntityWrapper<>());
        model.addAttribute("list",list);
        return "role/list";
    }

    /**
     * 保存
     * @param id
     * @param name
     * @return
     * @throws Exception
     */
    @PostMapping("save.htm")
    @ResponseBody
    @ImLog(type = "角色",mark = "保存角色 {id} {name} {status}")
    public Result save(String id,String name,Boolean status)throws Exception{
        RoleEntity roleEntity = new RoleEntity();
        roleEntity.setName(name);
        roleEntity.setStatus(status);
        if(StringUtils.isEmpty(id)){
            roleEntity.setId(IdWorker.get32UUID());
            roleEntity.setTime(new Date());
            roleService.insert(roleEntity);
        }else{
            roleEntity.setId(id);
            roleService.updateById(roleEntity);
        }
        return Result.success("保存成功");
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("del.htm")
    @ResponseBody
    @ImLog(type = "角色",mark = "删除角色 {id}")
    public Result del(String id)throws Exception{
        roleService.deleteById(id);
        return Result.success("保存成功");
    }

    /**
     * 权限界面
     * @return
     * @throws Exception

@Controller
@RequestMapping("shoppingGat")
public class ShoppingGatController {

    @Autowired
    private ShoppingGatService shoppingGatService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private CustomerAddressService customerAddressService;

    @Autowired
    private RoyaltyService royaltyService;

    /**
     * 购物车界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    public String list(Model model)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
        List<ShoppingGatEntity> gats = shoppingGatService.selectList(entityWrapper);
        if(gats!=null ){
            for (ShoppingGatEntity gat : gats) {
                ShopEntity shopEntity = shopService.selectById(gat.getShopId());
                gat.setShopEntity(shopEntity);
            }
        }
        model.addAttribute("gats",gats);
       List<CustomerAddressEntity> customerAddressEntities =   customerAddressService.selectList(entityWrapper);
        model.addAttribute("customerAddressEntities",customerAddressEntities);
        return "mobile/gat";
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception

@Controller
@RequestMapping("customerAddress")
public class CustomerAddressController {

    @Autowired
    private CustomerAddressService service;

    /**
     * 列表界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    public String list(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq(CustomerAddressTable.CUSTOMER_ID,customerEntity.getId());
        List<CustomerAddressEntity> list = service.selectList(wrapper);
        model.addAttribute("list",list);
        return "mobile/address_list";
    }

    /**
     * 保存界面
     * @param model
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("save.do")
        orderEntity.setStatus(1);
        orderEntity.setTime(new Date());

        CustomerAddressEntity customerAddressEntity = customerAddressService.selectById(addressId);
        if(customerAddressEntity==null){
            return  Result.error("请选择收货地址");
        }
        //验证库存是否足够
        for (int i = 0; i <ids.length ; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            if(shopEntity.getStock()==null || shopEntity.getStock()<shoppingGatEntity.getNum()){
                return Result.error(shopEntity.getName()+"库存不足");
            }
        }

        orderEntity.setAddress(customerAddressEntity.getAddress());
        orderEntity.setName(customerAddressEntity.getName());
        orderEntity.setPhone(customerAddressEntity.getPhone());
        orderService.insert(orderEntity);
        for (int i = 0; i <ids.length ; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            OrderShopEntity orderShopEntity = new OrderShopEntity();
            orderShopEntity.setId(IdWorkerUtil.getId());
            orderShopEntity.setPrice(new BigDecimal(prices[i]));
            orderShopEntity.setNum(nums[i]);
            orderShopEntity.setOrderId(orderEntity.getId());
            orderShopEntity.setName(shopEntity.getName());
            orderShopEntity.setCover(shopEntity.getCover());
            orderShopEntity.setShopId(shopEntity.getId());
            orderShopEntity.setCustomerId(userEntity.getId());
            orderShopService.insert(orderShopEntity);
            shopEntity.setStock(shopEntity.getStock()-nums[i]);
            shopService.updateById(shopEntity);
            shoppingGatService.deleteById(ids[i]);
            if(!StringUtils.isEmpty(shoppingGatEntity.getCid())){
                RoyaltyEntity royaltyEntity = new RoyaltyEntity();
                royaltyEntity.setId(IdWorkerUtil.getId());
                royaltyEntity.setCustomer(shoppingGatEntity.getCid());
                royaltyEntity.setMark("订单下单抽取提成");
                royaltyEntity.setTime(new Date());
                royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
                royaltyService.insert(royaltyEntity);
            }
        }
        return Result.success("订单结算成功");
    }

     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.htm")
    @ResponseBody
    public Result save(Model model, ShopTypeEntity entity)throws Exception{
        if(StringUtils.isEmpty(entity.getId())){
            entity.setId(IdWorkerUtil.getId());
            service.insert(entity);
        }else{
            service.updateById(entity);
        }
        return Result.success("保存成功");
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("del.htm")
    @ResponseBody
    public Result del(String id)throws Exception{
        service.deleteById(id);
        return Result.success("保存成功");
    }

}

        return Result.success("成功");
    }

    /**
     * 添加到购物车
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping("add.do")
    @ResponseBody
    public Result add(String shopId,Integer num,String customerId)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId())
                .eq(ShoppingGatTable.SHOP_ID,shopId);
        ShoppingGatEntity gatEntity = shoppingGatService.selectOne(entityWrapper);
        if(gatEntity!=null){
            gatEntity.setNum(gatEntity.getNum()+num);
            shoppingGatService.updateById(gatEntity);
        }else{
            gatEntity = new ShoppingGatEntity();
            gatEntity.setId(IdWorker.get32UUID());
            gatEntity.setNum(num);
            gatEntity.setShopId(shopId);
            gatEntity.setCustomerId(userEntity.getId());
            gatEntity.setCid(customerId);
            shoppingGatService.insert(gatEntity);
        }
        return Result.success("成功");
    }

}

     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("del.htm")
    @ResponseBody
    public Result del(String id)throws Exception{
        service.deleteById(id);
        return Result.success("保存成功");
    }

}

@Controller
@RequestMapping("mobile")
public class MobileIndexController {

    @Autowired
    private ShopTypeService shopTypeService;

    @Autowired
    private ShopService shopService;

    @PostMapping("list.do")
    public Result list()throws Exception{
        //首先查询帮助信息
        EntityWrapper entityWrapper = new EntityWrapper();
        //消息列表
        entityWrapper
                .eq("user_id", Contants.getCustomer().getId())
                .orderBy("time",true);
        List<ChatRoomEntity> list = chatRoomService.selectList(entityWrapper);
        for (ChatRoomEntity chatRoomEntity : list) {
            chatRoomEntity.setBr(chatRoomEntity.getSendUser().equals(Contants.getCustomer().getId()));
        }
        return Result.success(list);
    }

    /**
     * 发送消息
     * @param chatRoomEntity
     * @return
     */
    @RequestMapping("addContent.do")
    public Result addContent(ChatRoomEntity chatRoomEntity){
        //首先查询帮助信息
        chatRoomEntity.setId(IdWorker.get32UUID());
        chatRoomEntity.setRead(false);
        chatRoomEntity.setSendUser(Contants.getCustomer().getId());
        chatRoomEntity.setUserId(Contants.getCustomer().getId());
        chatRoomEntity.setAssistUserId("-99");
        chatRoomEntity.setTime(new Date());
        chatRoomService.insert(chatRoomEntity);
        return Result.success("发送成功");
    }
}


/**
 */
@Controller
@RequestMapping("file")
public class ImgController {
    public static final String FILE_PATH = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\upload\\";

    static {
        File file = new File(FILE_PATH);
        file.mkdirs();
    }

    /**
     * 文件上传返回code为200
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    @ResponseBody
    public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
        //用来检测程序运行时间
        String fileName =  IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        try {
            File file1 = new File(FILE_PATH+"\\"+fileName);
            file1.createNewFile();
            //获取输出流
            OutputStream os=new FileOutputStream(file1.getPath());
            //获取输入流 CommonsMultipartFile 中可以直接得到文件的流
            InputStream is=file.getInputStream();
            os.close();
            is.close();
            InputStream inputStream = new FileInputStream(file1.getPath());
            byte[] b = new byte[inputStream.available()];
            inputStream.read(b);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return Result.error("上传文件失败");
        }
        return Result.success("/file/pic?pictureName="+fileName,"文件上传成功");
    }

    /**
     * 获取本地图片
     * @param pictureName //文件名
     * @return
     */
    @RequestMapping("/pic")
    public void ShowImg(String pictureName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        //这里是存放图片的文件夹地址
        FileInputStream fileIs=null;
        OutputStream outStream = null;
        try {
            fileIs = new FileInputStream(FILE_PATH+"/"+pictureName);
            //得到文件大小
            int i=fileIs.available();
            //准备一个字节数组存放二进制图片
            byte data[]=new byte[i];
            //读字节数组的数据
            fileIs.read(data);
            //设置返回的文件类型
            response.setContentType("application/octet-stream;charset=UTF-8");
            //得到向客户端输出二进制数据的对象
            outStream=response.getOutputStream();
            //输出数据
            outStream.write(data);
            outStream.flush();
        } catch (Exception e) {
            return;
        }finally {
            if(outStream!=null){
                //关闭输出流
                outStream.close();
                //关闭输入流
                fileIs.close();
            }
        }
    }
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值