首頁 > 軟體

Java實戰之超市收銀管理系統的實現

2022-03-25 16:01:10

一、專案簡述

本系統主要實現的功能有:收銀、報表、使用者管理、商品管理、銷售管理、進貨退貨管理、倉庫管 理等等功能。

二、專案執行

環境設定: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支援)

專案技術: Spring+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等

三、效果圖

四、核心程式碼

品類資訊控制層

/**
 * <p>
 *  前端控制器
 * </p>
 *
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
 
    @Autowired
    private CategoryService categoryService;
 
 
    /**
     * 類別模糊查詢
     * @param
     * @return
     */
    @SysLog("類別查詢操作")
    @RequestMapping("/categoryList")
    public DataGridViewResult categoryList(CategoryVO categoryVO) {
 
        //建立分頁資訊    引數1 當前頁  引數2 每頁顯示條數
        IPage<Category> page = new Page<>(categoryVO.getPage(), categoryVO.getLimit());
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(categoryVO.getCatename()),"catename", categoryVO.getCatename());
        IPage<Category> categoryIPage = categoryService.page(page, queryWrapper);
        /**
         * logsIPage.getTotal() 總條數
         * logsIPage.getRecords() 分頁記錄列表
         */
        return new DataGridViewResult(categoryIPage.getTotal(),categoryIPage.getRecords());
 
    }
 
    /**
     * 類別批次刪除
     * @param ids
     * @return
     */
    @SysLog("類別刪除操作")
    @RequestMapping("/deleteList")
    public Result deleteList(String ids) {
        //將字串拆分成陣列
        String[] idsStr = ids.split(",");
        List<String> list = Arrays.asList(idsStr);
        boolean bool = categoryService.removeByIds(list);
        if(bool){
            return Result.success(true,"200","刪除成功!");
        }
        return Result.error(false,null,"刪除失敗!");
    }
 
    /**
     * 新增類別資訊
     * @param category
     * @return
     */
    @SysLog("類別新增操作")
    @PostMapping("/addcategory")
    public Result addCategory(Category category){
        boolean bool = categoryService.save(category);
        if(bool){
            return Result.success(true,"200","新增成功!");
        }
        return Result.error(false,null,"新增失敗!");
    }
 
    /**
     * 修改類別資訊
     * @param category
     * @return
     */
    @SysLog("類別修改操作")
    @PostMapping("/updatecategory")
    public Result updateCategory(Category category){
 
        boolean bool = categoryService.updateById(category);
        if(bool){
            return Result.success(true,"200","修改成功!");
        }
        return Result.error(false,null,"修改失敗!");
    }
 
    /**
     * 刪除單條資料
     * @param id
     * @return
     */
    @SysLog("類別刪除操作")
    @RequestMapping("/deleteOne")
    public Result deleteOne(int id) {
 
        boolean bool = categoryService.removeById(id);
        if(bool){
            return Result.success(true,"200","刪除成功!");
        }
        return Result.error(false,null,"刪除失敗!");
    }
}

使用者資訊控制層

/**
 * <p>
 *  前端控制器
 * </p>
 *
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
 
    @Autowired
    private CustomerService customerService;
 
 
    /**
     * 客戶模糊查詢
     * @param
     * @return
     */
    @SysLog("客戶查詢操作")
    @RequestMapping("/customerList")
    public DataGridViewResult customerList(CustomerVO customerVO) {
 
        //建立分頁資訊    引數1 當前頁  引數2 每頁顯示條數
        IPage<Customer> page = new Page<>(customerVO.getPage(), customerVO.getLimit());
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(customerVO.getCustvip()),"custvip", customerVO.getCustvip());
        IPage<Customer> customerIPage = customerService.page(page, queryWrapper);
        /**
         * logsIPage.getTotal() 總條數
         * logsIPage.getRecords() 分頁記錄列表
         */
        return new DataGridViewResult(customerIPage.getTotal(),customerIPage.getRecords());
 
    }
 
    /**
     * 客戶批次刪除
     * @param ids
     * @return
     */
    @SysLog("客戶刪除操作")
    @RequestMapping("/deleteList")
    public Result deleteList(String ids) {
        //將字串拆分成陣列
        String[] idsStr = ids.split(",");
        List<String> list = Arrays.asList(idsStr);
        boolean bool = customerService.removeByIds(list);
        if(bool){
            return Result.success(true,"200","刪除成功!");
        }
        return Result.error(false,null,"刪除失敗!");
    }
 
    /**
     * 新增客戶資訊
     * @param customer
     * @return
     */
    @SysLog("客戶新增操作")
    @PostMapping("/addcustomer")
    public Result addCustomer(Customer customer){
        String id = RandomStringUtils.randomAlphanumeric(10);
 
        customer.setCustvip(id);
        boolean bool = customerService.save(customer);
        if(bool){
            return Result.success(true,"200","新增成功!");
        }
        return Result.error(false,null,"新增失敗!");
    }
 
    /**
     * 修改客戶資訊
     * @param customer
     * @return
     */
    @SysLog("客戶修改操作")
    @PostMapping("/updatecustomer")
    public Result updateCustomer(Customer customer){
 
        boolean bool = customerService.updateById(customer);
        if(bool){
            return Result.success(true,"200","修改成功!");
        }
        return Result.error(false,null,"修改失敗!");
    }
 
    /**
     * 刪除單條資料
     * @param id
     * @return
     */
    @SysLog("客戶刪除操作")
    @RequestMapping("/deleteOne")
    public Result deleteOne(int id) {
 
        boolean bool = customerService.removeById(id);
        if(bool){
            return Result.success(true,"200","刪除成功!");
        }
        return Result.error(false,null,"刪除失敗!");
    }
 
 
 
    /**
     *
     * 載入下拉框
     * @return
     */
    @RequestMapping("/loadAllCustomer")
    public DataGridViewResult loadAllCustomer(){
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        List<Customer> list = customerService.list(queryWrapper);
        return new DataGridViewResult(list);
 
    }
 
}

商品資訊控制層

/**
 * <p>
 * 前端控制器
 * </p>
 *
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
 
 
    @Autowired
    private GoodsService goodsService;
 
    @Autowired
    private ProviderService providerService;
 
    @Autowired
    private CategoryService categoryService;
 
    /**
     * 商品模糊查詢
     *
     * @param
     * @return
     */
    @SysLog("商品查詢操作")
    @RequestMapping("/goodsList")
    public DataGridViewResult goodsList(GoodsVO goodsVO) {
        //建立分頁資訊    引數1 當前頁  引數2 每頁顯示條數
        IPage<Goods> page = new Page<>(goodsVO.getPage(), goodsVO.getLimit());
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(goodsVO.getProviderid() != null && goodsVO.getProviderid() != 0, "providerid", goodsVO.getProviderid());
        queryWrapper.like(!StringUtils.isEmpty(goodsVO.getGname()), "gname", goodsVO.getGname());
        IPage<Goods> goodsIPage = goodsService.page(page, queryWrapper);
        List<Goods> records = goodsIPage.getRecords();
        for (Goods goods : records) {
            Provider provider = providerService.getById(goods.getProviderid());
            if (null != provider) {
                goods.setProvidername(provider.getProvidername());
            }
        }
        return new DataGridViewResult(goodsIPage.getTotal(), records);
    }
 
 
    /**
     * 新增商品資訊
     *
     * @param goods
     * @return
     */
    @SysLog("商品新增操作")
    @PostMapping("/addgoods")
    public Result addGoods(Goods goods) {
        String id = RandomStringUtils.randomAlphanumeric(8);
        if (goods.getGoodsimg()!=null&&goods.getGoodsimg().endsWith("_temp")){
            String newName = AppFileUtils.renameFile(goods.getGoodsimg());
            goods.setGoodsimg(newName);
        }
        goods.setGnumbering(id);
        boolean bool = goodsService.save(goods);
        if (bool) {
            return Result.success(true, "200", "新增成功!");
        }
        return Result.error(false, null, "新增失敗!");
    }
 
    /**
     * 修改商品資訊
     *
     * @param goods
     * @return
     */
    @SysLog("商品修改操作")
    @PostMapping("/updategoods")
    public Result updateGoods(Goods goods) {
        //商品圖片不是預設圖片
        if (!(goods.getGoodsimg()!=null&&goods.getGoodsimg().equals(Constast.DEFAULT_IMG))){
            if (goods.getGoodsimg().endsWith("_temp")){
                String newName = AppFileUtils.renameFile(goods.getGoodsimg());
                goods.setGoodsimg(newName);
                //刪除原先的圖片
                String oldPath = goodsService.getById(goods.getGid()).getGoodsimg();
                AppFileUtils.removeFileByPath(oldPath);
            }
        }
        boolean bool = goodsService.updateById(goods);
        if (bool) {
            return Result.success(true, "200", "修改成功!");
        }
        return Result.error(false, null, "修改失敗!");
    }
 
 
    /**
     * 刪除單條資料
     *
     * @param id
     * @return
     */
    @SysLog("商品刪除操作")
    @RequestMapping("/deleteOne")
    public Result deleteOne(int id) {
 
        boolean bool = goodsService.removeById(id);
        if (bool) {
            return Result.success(true, "200", "刪除成功!");
        }
        return Result.error(false, null, "刪除失敗!");
    }
 
    /**
     * 根據id查詢當前商品擁有的類別
     *
     * @param id
     * @return
     */
    @RequestMapping("/initGoodsByCategoryId")
    public DataGridViewResult initGoodsByCategoryId(int id) {
        List<Map<String, Object>> mapList = null;
        try {
            //查詢所有類別列表
            mapList = categoryService.listMaps();
            //根據商品id查詢商品擁有的類別
            Set<Integer> cateIdList = categoryService.findGoodsByCategoryId(id);
            for (Map<String, Object> map : mapList) {
                //定義標記 預設不選中
                boolean flag = false;
                int cateId = (int) map.get("cateid");
                for (Integer cid : cateIdList) {
                    if (cid == cateId) {
                        flag = true;
                        break;
                    }
                }
                map.put("LAY_CHECKED", flag);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new DataGridViewResult(Long.valueOf(mapList.size()), mapList);
 
    }
 
    /**
     * 根據商品id載入商品資訊
     * @param goodsid
     * @return
     */
    @GetMapping("/loadGoodsById")
    public DataGridViewResult loadGoodsById(int goodsid) {
 
 
        QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
        goodsQueryWrapper.eq(goodsid != 0, "gid", goodsid);
        Goods goods = goodsService.getById(goodsid);
 
        return new DataGridViewResult(goods);
 
    }
 
    /**
     * 為商品分配類別
     *
     * @param categoryids
     * @param goodsid
     * @return
     */
    @SysLog("類別新增操作")
    @RequestMapping("/saveGoodsCategory")
    public Result saveGoodsCategory(String categoryids, int goodsid) {
 
        try {
            if (goodsService.saveGoodsCategory(goodsid, categoryids)) {
                return Result.success(true, null, "分配成功");
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error(false, null, "分配失敗");
 
    }
 
    /**
     * 載入下拉框
     *
     * @return
     */
    @RequestMapping("/loadAllGoods")
    public DataGridViewResult loadAllGoods() {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        List<Goods> list = goodsService.list(queryWrapper);
        return new DataGridViewResult(list);
 
    }
 
 
    /**
     * 根據供應商查商品下拉框
     *
     * @param providerid
     * @return
     */
    @RequestMapping("/loadGoodsByProvidreId")
    public DataGridViewResult loadGoodsByProvidreId(Integer providerid) {
        QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
        goodsQueryWrapper.eq(providerid != null, "providerid", providerid);
        List<Goods> list = goodsService.list(goodsQueryWrapper);
        for (Goods goods : list) {
            Provider provider = providerService.getById(goods.getProviderid());
            if (null != provider) {
                goods.setProvidername(provider.getProvidername());
            }
 
        }
        return new DataGridViewResult(list);
 
    }
}

以上就是Java實戰之超市收銀管理系統的實現的詳細內容,更多關於Java收銀系統的資料請關注it145.com其它相關文章!


IT145.com E-mail:sddin#qq.com