Java项目 校园超市管理系统(java+SSM+Mysql

前端模板框架为Bootstrap,系统分为前台和后台。后台主要为管理员角色,功能有:

商品类型管理、商品管理、订单管理、会员管理、管理员管理等。前台用户功能有:登录、注册、查看商品、加入购物车、付款、查看订单、个人中心等。该系统总共9张表

运行环境:windows/linux、jdk1.8、mysql5.x、maven3.5\3.6、tomcat7.0

image-20211118212501232

image-20211118212521609

image-20211118212535704

image-20211118212547097

image-20211118212602292

image-20211118212616224

前端商品控制器:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
typescript复制代码/**
* <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);

  }
}

前端销售控制器:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
kotlin复制代码/**
* <p>
* 前端控制器
* </p>
*/
@RestController
@RequestMapping("/sale")
public class SaleController {
   @Autowired
   private SaleService saleService;

   @Autowired
   private GoodsService goodsService;
   
   @Autowired
   private CustomerService customerService;

   /**
    * 销售查询
    *
    * @param
    * @return
    */
   @SysLog("销售查询操作")
   @RequestMapping("/saleList")
   public DataGridViewResult saleList(SaleVO saleVO) {

       //创建分页信息   参数1 当前页 参数2 每页显示条数
       IPage<Sale> page = new Page<>(saleVO.getPage(), saleVO.getLimit());
       QueryWrapper<Sale> queryWrapper = new QueryWrapper<>();
       queryWrapper.like(!StringUtils.isEmpty(saleVO.getNumbering()),"numbering", saleVO.getNumbering());
       queryWrapper.eq(saleVO.getGid() != null && saleVO.getGid() != 0, "gid", saleVO.getGid());
       queryWrapper.ge(saleVO.getStartTime() != null, "buytime", saleVO.getStartTime());
       queryWrapper.le(saleVO.getEndTime() != null, "buytime", saleVO.getEndTime());

       queryWrapper.orderByDesc("buytime");

       IPage<Sale> saleIPage = saleService.page(page, queryWrapper);

       List<Sale> records = saleIPage.getRecords();

       for (Sale sale : records) {
           sale.setAllmoney(sale.getMoney()*sale.getBuyquantity());
           Customer customer = customerService.getById(sale.getCustid());

           if (null != customer) {
               sale.setCustomervip(customer.getCustvip());
               sale.setCustomername(customer.getCustname());
          }
           Goods goods = goodsService.getById(sale.getGid());
           if (null != goods) {

               sale.setGoodsname(goods.getGname());
               sale.setGnumbering(goods.getGnumbering());
          }
      }

       return new DataGridViewResult(saleIPage.getTotal(), records);

  }


   /**
    * 添加销售单信息
    *
    * @param sale
    * @return
    */
   @SysLog("销售添加操作")
   @PostMapping("/addsale")
   public Result addsale(Sale sale, HttpSession session) {
       if (sale.getGid()==0){
           return Result.error(false, null, "添加失败!未选商品");
      }
       Goods goods = goodsService.getById(sale.getGid());
       Integer gquantity = goods.getGquantity();
       if(gquantity<sale.getBuyquantity()){
           return Result.error(false, null, "添加失败!库存不足,库存为:"+gquantity);
      }
       User user = (User) session.getAttribute("username");
       String num = RandomStringUtils.randomAlphanumeric(7);
       sale.setNumbering(num);
       sale.setPerson(user.getUsername());
       sale.setBuytime(new Date());
       sale.setRealnumber(sale.getBuyquantity());
       boolean bool = saleService.save(sale);
       if (bool) {
           return Result.success(true, "200", "添加成功!");
      }
       return Result.error(false, null, "添加失败!库存不足");
  }


   /**
    * 修改销售单信息
    *
    * @param sale
    * @return
    */
   @SysLog("销售修改操作")
   @PostMapping("/updatesale")
   public Result updatesale(Sale sale, HttpSession session) {

       User user = (User) session.getAttribute("username");
       sale.setPerson(user.getUsername());
       sale.setBuytime(new Date());
       boolean bool = saleService.updateById(sale);
       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 = saleService.removeById(id);
       if (bool) {
           return Result.success(true, "200", "删除成功!");
      }
       return Result.error(false, null, "删除失败!");
  }



}

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%