Yansen 2 年之前
父節點
當前提交
3c761ee083
共有 26 個檔案被更改,包括 649 行新增90 行删除
  1. 二進制
      db/ybai.db
  2. 8
    0
      pom.xml
  3. 27
    0
      src/main/java/com/yunzhi/inte/common/ExcelUtils.java
  4. 47
    5
      src/main/java/com/yunzhi/inte/controller/DishesController.java
  5. 18
    19
      src/main/java/com/yunzhi/inte/controller/FoodIngredientsController.java
  6. 33
    4
      src/main/java/com/yunzhi/inte/controller/GuaranteeTaskController.java
  7. 14
    1
      src/main/java/com/yunzhi/inte/controller/PackageController.java
  8. 46
    6
      src/main/java/com/yunzhi/inte/controller/StoreController.java
  9. 136
    41
      src/main/java/com/yunzhi/inte/controller/StoreLogController.java
  10. 27
    6
      src/main/java/com/yunzhi/inte/controller/StoreTypeController.java
  11. 10
    1
      src/main/java/com/yunzhi/inte/entity/Dishes.java
  12. 26
    1
      src/main/java/com/yunzhi/inte/entity/Store.java
  13. 28
    1
      src/main/java/com/yunzhi/inte/entity/StoreLog.java
  14. 1
    1
      src/main/java/com/yunzhi/inte/entity/StoreType.java
  15. 13
    0
      src/main/java/com/yunzhi/inte/mapper/FoodIngredientsMapper.java
  16. 6
    0
      src/main/java/com/yunzhi/inte/mapper/StoreLogMapper.java
  17. 6
    0
      src/main/java/com/yunzhi/inte/mapper/StoreMapper.java
  18. 9
    0
      src/main/java/com/yunzhi/inte/service/FoodIngredientsService.java
  19. 6
    1
      src/main/java/com/yunzhi/inte/service/StoreLogService.java
  20. 6
    1
      src/main/java/com/yunzhi/inte/service/StoreService.java
  21. 44
    0
      src/main/java/com/yunzhi/inte/service/impl/FoodIngredientsServiceImpl.java
  22. 26
    1
      src/main/java/com/yunzhi/inte/service/impl/StoreLogServiceImpl.java
  23. 26
    1
      src/main/java/com/yunzhi/inte/service/impl/StoreServiceImpl.java
  24. 28
    0
      src/main/resources/mapper/FoodIngredientsMapper.xml
  25. 30
    0
      src/main/resources/mapper/StoreLogMapper.xml
  26. 28
    0
      src/main/resources/mapper/StoreMapper.xml

二進制
db/ybai.db 查看文件


+ 8
- 0
pom.xml 查看文件

@@ -75,6 +75,14 @@
75 75
 			<scope>test</scope>
76 76
 		</dependency>
77 77
 
78
+		<!--excel start-->
79
+		<dependency>
80
+			<groupId>com.alibaba</groupId>
81
+			<artifactId>easyexcel</artifactId>
82
+			<version>2.0.4</version>
83
+		</dependency>
84
+		<!--excel end-->
85
+
78 86
 		<!--swagger start-->
79 87
 		<dependency>
80 88
 			<groupId>io.springfox</groupId>

+ 27
- 0
src/main/java/com/yunzhi/inte/common/ExcelUtils.java 查看文件

@@ -0,0 +1,27 @@
1
+package com.yunzhi.inte.common;
2
+
3
+import com.alibaba.excel.EasyExcel;
4
+
5
+import javax.servlet.http.HttpServletResponse;
6
+import java.io.IOException;
7
+import java.util.List;
8
+
9
+public class ExcelUtils {
10
+
11
+    /**
12
+     * 发送 excel 到客户端
13
+     * 暂时只支持单 sheet 页
14
+     * @param response
15
+     * @param data
16
+     * @param fileName
17
+     * @throws IOException
18
+     */
19
+    public static void flush(HttpServletResponse response, Class dataClass, List data, String fileName) throws IOException {
20
+        response.setContentType("application/vnd.ms-excel");
21
+        response.setCharacterEncoding("utf-8");
22
+        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
23
+        response.setHeader("Content-Disposition", "attachment;filename="+StringUtils.urlEncode(fileName)+".xlsx");
24
+
25
+        EasyExcel.write(response.getOutputStream(), dataClass).sheet("sheet1").doWrite(data);
26
+    }
27
+}

+ 47
- 5
src/main/java/com/yunzhi/inte/controller/DishesController.java 查看文件

@@ -8,6 +8,10 @@ import com.yunzhi.inte.common.ResponseBean;
8 8
 import java.util.List;
9 9
 
10 10
 import com.yunzhi.inte.common.StringUtils;
11
+import com.yunzhi.inte.entity.FoodIngredients;
12
+import com.yunzhi.inte.entity.Package;
13
+import com.yunzhi.inte.entity.StoreType;
14
+import com.yunzhi.inte.service.FoodIngredientsService;
11 15
 import io.swagger.annotations.Api;
12 16
 import io.swagger.annotations.ApiOperation;
13 17
 import io.swagger.annotations.ApiParam;
@@ -29,6 +33,9 @@ public class DishesController extends BaseController {
29 33
     @Autowired
30 34
     private DishesService dishesService;
31 35
 
36
+    @Autowired
37
+    private FoodIngredientsService foodIngredientsService;
38
+
32 39
     /**
33 40
      * 通过ID查询单条数据
34 41
      *
@@ -38,7 +45,13 @@ public class DishesController extends BaseController {
38 45
     @ApiOperation("通过ID查询单条数据")
39 46
     @GetMapping("/dishes/{id}")
40 47
     public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
41
-        return ResponseBean.success(dishesService.getById(id));
48
+        Dishes dishes = dishesService.getById(id);
49
+
50
+        // 获取详情列表
51
+        List<Integer> list = foodIngredientsService.getItemListByDish(id);
52
+        dishes.setIngredientsIdList(list);
53
+
54
+        return ResponseBean.success(dishes);
42 55
     }
43 56
 
44 57
     /**
@@ -72,9 +85,32 @@ public class DishesController extends BaseController {
72 85
      */
73 86
     @ApiOperation("新增数据")
74 87
     @PostMapping("/dishes")
75
-    public ResponseBean add(Dishes dishes) throws Exception {
76
-        dishes.setStatus(1);
77
-        dishesService.save(dishes);
88
+    public ResponseBean add(@ApiParam("对象实体") @RequestBody Dishes dishes) throws Exception {
89
+        Dishes origin = dishesService.getExistBy("name", dishes.getName(), false, true);
90
+
91
+        List<Integer> ingredientsList = dishes.getIngredientsIdList();
92
+        Integer foodNum = null == ingredientsList ? 0 : ingredientsList.size();
93
+        dishes.setFoodNum(foodNum);
94
+
95
+        Integer dishId = dishes.getId();
96
+        if (dishId == null) {
97
+            if (null != origin) {
98
+                return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
99
+            }
100
+
101
+            dishes.setStatus(1);
102
+            dishesService.save(dishes);
103
+            dishId = dishes.getId();
104
+        } else {
105
+            if (null != origin && !dishId.equals(origin.getId())) {
106
+                return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
107
+            }
108
+
109
+            dishesService.updateById(dishes);
110
+        }
111
+
112
+        foodIngredientsService.addOrUpdate(dishId, ingredientsList);
113
+
78 114
         return ResponseBean.success(dishes);
79 115
     }
80 116
 
@@ -86,7 +122,13 @@ public class DishesController extends BaseController {
86 122
      */
87 123
     @ApiOperation("更新数据")
88 124
     @PutMapping("/dishes/{id}")
89
-    public ResponseBean edit(Dishes dishes) throws Exception {
125
+    public ResponseBean edit(@ApiParam("对象ID") @PathVariable Integer id,
126
+                             @ApiParam("对象实体") @RequestBody Dishes dishes) throws Exception {
127
+        Dishes origin = dishesService.getExistBy("name", dishes.getName(), false, true);
128
+        if (null != origin && !id.equals(origin.getId())) {
129
+            return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
130
+        }
131
+
90 132
         dishes.setStatus(1);
91 133
         dishesService.updateById(dishes);
92 134
         return ResponseBean.success(dishes);

+ 18
- 19
src/main/java/com/yunzhi/inte/controller/FoodIngredientsController.java 查看文件

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.inte.common.BaseController;
7 7
 import com.yunzhi.inte.common.ResponseBean;
8 8
 import java.util.List;
9
+
10
+import com.yunzhi.inte.entity.Store;
9 11
 import io.swagger.annotations.Api;
10 12
 import io.swagger.annotations.ApiOperation;
11 13
 import io.swagger.annotations.ApiParam;
@@ -49,12 +51,11 @@ public class FoodIngredientsController extends BaseController {
49 51
     @ApiOperation("分页查询")
50 52
     @GetMapping("/foodIngredients")
51 53
     public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
54
+                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
55
+                             @ApiParam("食材ID") @RequestParam(value ="dishId") Integer dishId) throws Exception {
53 56
 
54
-        IPage<FoodIngredients> pg = new Page<>(pageNum, pageSize);
55
-        // QueryWrapper<FoodIngredients> queryWrapper = new QueryWrapper<>();
56
-        // queryWrapper.orderByDesc("create_date");
57
-        IPage<FoodIngredients> result = foodIngredientsService.page(pg);
57
+        IPage<Store> pg = new Page<>(pageNum, pageSize);
58
+        IPage<Store> result = foodIngredientsService.getByDish(pg, dishId);
58 59
 
59 60
         return ResponseBean.success(result);
60 61
     }
@@ -67,23 +68,21 @@ public class FoodIngredientsController extends BaseController {
67 68
      */
68 69
     @ApiOperation("新增数据")
69 70
     @PostMapping("/foodIngredients")
70
-    public ResponseBean add(FoodIngredients foodIngredients) throws Exception {
71
+    public ResponseBean add(@ApiParam("实例对象") @RequestBody FoodIngredients foodIngredients) throws Exception {
72
+
73
+        QueryWrapper<FoodIngredients> queryWrapper = new QueryWrapper<>();
74
+        queryWrapper.eq("dish_id", foodIngredients.getDishId());
75
+        queryWrapper.eq("item_id", foodIngredients.getItemId());
76
+        int count = foodIngredientsService.count(queryWrapper);
77
+
78
+        if (count > 0) {
79
+            return ResponseBean.error("当前菜肴已存在", ResponseBean.ERROR_ILLEGAL_PARAMS);
80
+        }
81
+
71 82
         foodIngredientsService.save(foodIngredients);
72 83
         return ResponseBean.success(foodIngredients);
73 84
     }
74 85
 
75
-    /**
76
-     * 更新数据
77
-     *
78
-     * @param foodIngredients 实例对象
79
-     * @return 实例对象
80
-     */
81
-    @ApiOperation("更新数据")
82
-    @PutMapping("/foodIngredients/{id}")
83
-    public ResponseBean edit(FoodIngredients foodIngredients) throws Exception {
84
-        foodIngredientsService.updateById(foodIngredients);
85
-        return ResponseBean.success(foodIngredients);
86
-    }
87 86
 
88 87
     /**
89 88
      * 通过主键删除数据
@@ -94,7 +93,7 @@ public class FoodIngredientsController extends BaseController {
94 93
     @ApiOperation("通过主键删除数据")
95 94
     @DeleteMapping("/foodIngredients/{id}")
96 95
     public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
97
-        foodIngredientsService.removeLogicById(id);
96
+        foodIngredientsService.removeById(id);
98 97
         return ResponseBean.success("success");
99 98
     }
100 99
 }

+ 33
- 4
src/main/java/com/yunzhi/inte/controller/GuaranteeTaskController.java 查看文件

@@ -6,8 +6,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.inte.common.BaseController;
7 7
 import com.yunzhi.inte.common.ResponseBean;
8 8
 
9
+import java.text.ParseException;
10
+import java.text.SimpleDateFormat;
9 11
 import java.util.Date;
10 12
 import java.util.List;
13
+
14
+import com.yunzhi.inte.common.StringUtils;
11 15
 import io.swagger.annotations.Api;
12 16
 import io.swagger.annotations.ApiOperation;
13 17
 import io.swagger.annotations.ApiParam;
@@ -41,6 +45,12 @@ public class GuaranteeTaskController extends BaseController {
41 45
         return ResponseBean.success(guaranteeTaskService.getById(id));
42 46
     }
43 47
 
48
+    private Date toDate(String str) throws ParseException {
49
+        String format = "yyyy-MM-dd HH:mm:ss";
50
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
51
+        return sdf.parse(str);
52
+    }
53
+
44 54
     /**
45 55
      * 分页查询
46 56
      *
@@ -51,12 +61,31 @@ public class GuaranteeTaskController extends BaseController {
51 61
     @ApiOperation("分页查询")
52 62
     @GetMapping("/guaranteeTask")
53 63
     public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
54
-                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
64
+                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
65
+                             @ApiParam("保障序号") @RequestParam(value ="guaranteeNo", required = false) String guaranteeNo,
66
+                             @ApiParam("受领人") @RequestParam(value ="receiver", required = false) String receiver,
67
+                             @ApiParam(value = "开始时间", example = "2022-09-01") @RequestParam(value ="startDate", required = false) String startDate,
68
+                             @ApiParam(value = "结束时间", example = "2022-09-30") @RequestParam(value ="endDate", required = false) String endDate) throws Exception {
55 69
 
56 70
         IPage<GuaranteeTask> pg = new Page<>(pageNum, pageSize);
57
-        // QueryWrapper<GuaranteeTask> queryWrapper = new QueryWrapper<>();
58
-        // queryWrapper.orderByDesc("create_date");
59
-        IPage<GuaranteeTask> result = guaranteeTaskService.page(pg);
71
+        QueryWrapper<GuaranteeTask> queryWrapper = new QueryWrapper<>();
72
+        queryWrapper.like(!StringUtils.isEmpty(guaranteeNo), "guarantee_no", guaranteeNo);
73
+        queryWrapper.like(!StringUtils.isEmpty(receiver), "receiver", receiver);
74
+
75
+        if (!StringUtils.isEmpty(startDate)) {
76
+            Date start = toDate(startDate + " 00:00:00");
77
+            Date end = toDate(endDate + " 23:59:59");
78
+            queryWrapper.le("start_date", end.getTime());
79
+            queryWrapper.ge("end_date", start.getTime());
80
+        }
81
+//        if (!StringUtils.isEmpty(endDate)) {
82
+//            Date end = toDate(endDate + " 23:59:59");
83
+//            queryWrapper.le("end_date", end.getTime());
84
+//        }
85
+
86
+        queryWrapper.eq("status", 1);
87
+        queryWrapper.orderByDesc("id");
88
+        IPage<GuaranteeTask> result = guaranteeTaskService.page(pg, queryWrapper);
60 89
 
61 90
         return ResponseBean.success(result);
62 91
     }

+ 14
- 1
src/main/java/com/yunzhi/inte/controller/PackageController.java 查看文件

@@ -8,6 +8,8 @@ import com.yunzhi.inte.common.ResponseBean;
8 8
 import java.util.List;
9 9
 
10 10
 import com.yunzhi.inte.common.StringUtils;
11
+import com.yunzhi.inte.entity.Dishes;
12
+import com.yunzhi.inte.entity.Store;
11 13
 import io.swagger.annotations.Api;
12 14
 import io.swagger.annotations.ApiOperation;
13 15
 import io.swagger.annotations.ApiParam;
@@ -73,6 +75,11 @@ public class PackageController extends BaseController {
73 75
     @ApiOperation("新增数据")
74 76
     @PostMapping("/package")
75 77
     public ResponseBean add(@ApiParam("对象实体") @RequestBody Package pkg) throws Exception {
78
+        Package origin = packageService.getExistBy("name", pkg.getName(), false, true);
79
+        if (null != origin) {
80
+            return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
81
+        }
82
+
76 83
         packageService.save(pkg);
77 84
         return ResponseBean.success(pkg);
78 85
     }
@@ -85,7 +92,13 @@ public class PackageController extends BaseController {
85 92
      */
86 93
     @ApiOperation("更新数据")
87 94
     @PutMapping("/package/{id}")
88
-    public ResponseBean edit(@ApiParam("对象实体") @RequestBody Package pkg) throws Exception {
95
+    public ResponseBean edit(@ApiParam("对象ID") @PathVariable Integer id,
96
+                             @ApiParam("对象实体") @RequestBody Package pkg) throws Exception {
97
+        Package origin = packageService.getExistBy("name", pkg.getName(), false, true);
98
+        if (null != origin && !id.equals(origin.getId())) {
99
+            return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
100
+        }
101
+
89 102
         packageService.updateById(pkg);
90 103
         return ResponseBean.success(pkg);
91 104
     }

+ 46
- 6
src/main/java/com/yunzhi/inte/controller/StoreController.java 查看文件

@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.inte.common.BaseController;
7
+import com.yunzhi.inte.common.ExcelUtils;
7 8
 import com.yunzhi.inte.common.ResponseBean;
8 9
 import java.util.List;
10
+
11
+import com.yunzhi.inte.common.StringUtils;
9 12
 import io.swagger.annotations.Api;
10 13
 import io.swagger.annotations.ApiOperation;
11 14
 import io.swagger.annotations.ApiParam;
@@ -14,6 +17,8 @@ import org.springframework.web.bind.annotation.*;
14 17
 import com.yunzhi.inte.entity.Store;
15 18
 import com.yunzhi.inte.service.StoreService;
16 19
 
20
+import javax.servlet.http.HttpServletResponse;
21
+
17 22
 /**
18 23
  * 库存表;(store)表控制层
19 24
  * @author : http://njyunzhi.com
@@ -49,16 +54,38 @@ public class StoreController extends BaseController {
49 54
     @ApiOperation("分页查询")
50 55
     @GetMapping("/store")
51 56
     public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
57
+                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
58
+                             @ApiParam("名称") @RequestParam(value ="name", required = false) String name,
59
+                             @ApiParam("分类ID") @RequestParam(value ="typeId", required = false) String typeId,
60
+                             @ApiParam("是否食材") @RequestParam(value ="isDish", required = false) Integer isDish) throws Exception {
53 61
 
54 62
         IPage<Store> pg = new Page<>(pageNum, pageSize);
55
-        // QueryWrapper<Store> queryWrapper = new QueryWrapper<>();
56
-        // queryWrapper.orderByDesc("create_date");
57
-        IPage<Store> result = storeService.page(pg);
63
+        IPage<Store> result = storeService.getPageBy(pg, name, typeId, isDish);
58 64
 
59 65
         return ResponseBean.success(result);
60 66
     }
61 67
 
68
+
69
+    /**
70
+     * 导出
71
+     *
72
+     * @param name 名称
73
+     * @param typeId 分类ID
74
+     * @return 导出
75
+     */
76
+    @ApiOperation("导出")
77
+    @GetMapping("/store/export")
78
+    public ResponseBean export(@ApiParam("名称") @RequestParam(value ="name", required = false) String name,
79
+                               @ApiParam("分类ID") @RequestParam(value ="typeId", required = false) String typeId,
80
+                               HttpServletResponse response) throws Exception {
81
+
82
+        List<Store> result = storeService.getListBy(name, typeId);
83
+
84
+        ExcelUtils.flush(response, Store.class, result, "库存列表");
85
+
86
+        return null;
87
+    }
88
+
62 89
     /**
63 90
      * 新增数据
64 91
      *
@@ -67,7 +94,13 @@ public class StoreController extends BaseController {
67 94
      */
68 95
     @ApiOperation("新增数据")
69 96
     @PostMapping("/store")
70
-    public ResponseBean add(Store store) throws Exception {
97
+    public ResponseBean add(@ApiParam("对象实体") @RequestBody Store store) throws Exception {
98
+        Store origin = storeService.getExistBy("name", store.getName(), false, true);
99
+        if (null != origin) {
100
+            return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
101
+        }
102
+
103
+        store.setStatus(1);
71 104
         storeService.save(store);
72 105
         return ResponseBean.success(store);
73 106
     }
@@ -80,7 +113,14 @@ public class StoreController extends BaseController {
80 113
      */
81 114
     @ApiOperation("更新数据")
82 115
     @PutMapping("/store/{id}")
83
-    public ResponseBean edit(Store store) throws Exception {
116
+    public ResponseBean edit(@ApiParam("对象ID") @PathVariable Integer id,
117
+                             @ApiParam("对象实体") @RequestBody Store store) throws Exception {
118
+        Store origin = storeService.getExistBy("name", store.getName(), false, true);
119
+        if (null != origin && !id.equals(origin.getId())) {
120
+            return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
121
+        }
122
+
123
+        store.setId(id);
84 124
         storeService.updateById(store);
85 125
         return ResponseBean.success(store);
86 126
     }

+ 136
- 41
src/main/java/com/yunzhi/inte/controller/StoreLogController.java 查看文件

@@ -4,8 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.inte.common.BaseController;
7
+import com.yunzhi.inte.common.ExcelUtils;
7 8
 import com.yunzhi.inte.common.ResponseBean;
9
+
10
+import java.util.Date;
8 11
 import java.util.List;
12
+
13
+import com.yunzhi.inte.entity.Store;
14
+import com.yunzhi.inte.service.StoreService;
9 15
 import io.swagger.annotations.Api;
10 16
 import io.swagger.annotations.ApiOperation;
11 17
 import io.swagger.annotations.ApiParam;
@@ -14,6 +20,8 @@ import org.springframework.web.bind.annotation.*;
14 20
 import com.yunzhi.inte.entity.StoreLog;
15 21
 import com.yunzhi.inte.service.StoreLogService;
16 22
 
23
+import javax.servlet.http.HttpServletResponse;
24
+
17 25
 /**
18 26
  * 库存日志;(store_log)表控制层
19 27
  * @author : http://njyunzhi.com
@@ -27,17 +35,20 @@ public class StoreLogController extends BaseController {
27 35
     @Autowired
28 36
     private StoreLogService storeLogService;
29 37
 
30
-    /**
31
-     * 通过ID查询单条数据
32
-     *
33
-     * @param id 主键
34
-     * @return 实例对象
35
-     */
36
-    @ApiOperation("通过ID查询单条数据")
37
-    @GetMapping("/storeLog/{id}")
38
-    public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
39
-        return ResponseBean.success(storeLogService.getById(id));
40
-    }
38
+    @Autowired
39
+    private StoreService storeService;
40
+
41
+//    /**
42
+//     * 通过ID查询单条数据
43
+//     *
44
+//     * @param id 主键
45
+//     * @return 实例对象
46
+//     */
47
+//    @ApiOperation("通过ID查询单条数据")
48
+//    @GetMapping("/storeLog/{id}")
49
+//    public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
50
+//        return ResponseBean.success(storeLogService.getById(id));
51
+//    }
41 52
 
42 53
     /**
43 54
      * 分页查询
@@ -49,52 +60,136 @@ public class StoreLogController extends BaseController {
49 60
     @ApiOperation("分页查询")
50 61
     @GetMapping("/storeLog")
51 62
     public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
63
+                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
64
+                             @ApiParam("库存ID") @RequestParam(value ="storeId", required = false) Integer storeId,
65
+                             @ApiParam("名称") @RequestParam(value ="name", required = false) String name,
66
+                             @ApiParam("分类ID") @RequestParam(value ="typeId", required = false) Integer typeId) throws Exception {
53 67
 
54 68
         IPage<StoreLog> pg = new Page<>(pageNum, pageSize);
55
-        // QueryWrapper<StoreLog> queryWrapper = new QueryWrapper<>();
56
-        // queryWrapper.orderByDesc("create_date");
57
-        IPage<StoreLog> result = storeLogService.page(pg);
69
+        IPage<StoreLog> result = storeLogService.getPageBy(pg, storeId, name, typeId);
58 70
 
59 71
         return ResponseBean.success(result);
60 72
     }
61 73
 
74
+
62 75
     /**
63
-     * 新增数据
76
+     * 导出
64 77
      *
65
-     * @param storeLog 实例对象
66
-     * @return 实例对象
78
+     * @param storeId 库存ID
79
+     * @return 查询结果
67 80
      */
68
-    @ApiOperation("新增数据")
69
-    @PostMapping("/storeLog")
70
-    public ResponseBean add(StoreLog storeLog) throws Exception {
71
-        storeLogService.save(storeLog);
72
-        return ResponseBean.success(storeLog);
81
+    @ApiOperation("导出")
82
+    @GetMapping("/storeLog/export")
83
+    public ResponseBean export(@ApiParam("库存ID") @RequestParam(value ="storeId", required = false) Integer storeId,
84
+                               @ApiParam("名称") @RequestParam(value ="name", required = false) String name,
85
+                               @ApiParam("分类ID") @RequestParam(value ="typeId", required = false) Integer typeId,
86
+                               HttpServletResponse response) throws Exception {
87
+
88
+        List<StoreLog> result = storeLogService.getListBy(storeId, name, typeId);
89
+        if (null != result && result.size() > 0) {
90
+            for(StoreLog log : result) {
91
+                String optType = "";
92
+                switch (log.getOptType()) {
93
+                    case "in":
94
+                        optType = "入库";
95
+                        break;
96
+                    case "out":
97
+                        optType = "出库";
98
+                        break;
99
+                    case "fix":
100
+                    default:
101
+                        optType = "盘点";
102
+                        break;
103
+                }
104
+
105
+                log.setOptType(optType);
106
+            }
107
+        }
108
+
109
+        ExcelUtils.flush(response, StoreLog.class, result, "出入库日志");
110
+        return null;
73 111
     }
74 112
 
75 113
     /**
76
-     * 更新数据
114
+     * 新数据
77 115
      *
78 116
      * @param storeLog 实例对象
79 117
      * @return 实例对象
80 118
      */
81
-    @ApiOperation("更新数据")
82
-    @PutMapping("/storeLog/{id}")
83
-    public ResponseBean edit(StoreLog storeLog) throws Exception {
84
-        storeLogService.updateById(storeLog);
85
-        return ResponseBean.success(storeLog);
86
-    }
119
+    @ApiOperation("新增数据")
120
+    @PostMapping("/storeLog")
121
+    public ResponseBean add(@ApiParam("对象实体") @RequestBody StoreLog storeLog) throws Exception {
87 122
 
88
-    /**
89
-     * 通过主键删除数据
90
-     *
91
-     * @param id 主键
92
-     * @return 是否成功
93
-     */
94
-    @ApiOperation("通过主键删除数据")
95
-    @DeleteMapping("/storeLog/{id}")
96
-    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
97
-        storeLogService.removeLogicById(id);
98
-        return ResponseBean.success("success");
123
+        if (storeLog.getStoreId() == null) {
124
+            return ResponseBean.error("未找到对应库存", ResponseBean.ERROR_ILLEGAL_PARAMS);
125
+        }
126
+
127
+        if (null == storeLog.getAmount()) {
128
+            return ResponseBean.error("请设置出入数量", ResponseBean.ERROR_ILLEGAL_PARAMS);
129
+        }
130
+
131
+        // 因为只有一个人用, 不用考虑并发问题
132
+        Store store = storeService.getById(storeLog.getStoreId());
133
+        Integer preAmount = null == store.getAmount() ? 0 : store.getAmount();
134
+        Integer amount = storeLog.getAmount();
135
+        Integer leftAmount = preAmount;
136
+
137
+        // 如果是盘点
138
+        if ("fix".equals(storeLog.getOptType())) {
139
+            if (amount < 0) {
140
+                return ResponseBean.error("盘点库存不能为负", ResponseBean.ERROR_ILLEGAL_PARAMS);
141
+            }
142
+
143
+            leftAmount = amount;
144
+        } else {
145
+            if ("out".equals(storeLog.getOptType())) {
146
+                // 如果是出库
147
+                if (amount > 0) {
148
+                    amount = 0 - amount;
149
+                }
150
+            }
151
+
152
+            leftAmount = amount + preAmount;
153
+
154
+            if (leftAmount < 0) {
155
+                return ResponseBean.error("库存不足", ResponseBean.ERROR_ILLEGAL_PARAMS);
156
+            }
157
+        }
158
+
159
+        storeLog.setPreAmount(preAmount);
160
+        storeLog.setAftAmount(leftAmount);
161
+        storeLog.setCreateDate(new Date());
162
+        storeLogService.save(storeLog);
163
+
164
+        store.setAmount(leftAmount);
165
+        storeService.updateById(store);
166
+
167
+        return ResponseBean.success(storeLog);
99 168
     }
169
+//
170
+//    /**
171
+//     * 更新数据
172
+//     *
173
+//     * @param storeLog 实例对象
174
+//     * @return 实例对象
175
+//     */
176
+//    @ApiOperation("更新数据")
177
+//    @PutMapping("/storeLog/{id}")
178
+//    public ResponseBean edit(@ApiParam("对象实体") @RequestBody StoreLog storeLog) throws Exception {
179
+//        storeLogService.updateById(storeLog);
180
+//        return ResponseBean.success(storeLog);
181
+//    }
182
+//
183
+//    /**
184
+//     * 通过主键删除数据
185
+//     *
186
+//     * @param id 主键
187
+//     * @return 是否成功
188
+//     */
189
+//    @ApiOperation("通过主键删除数据")
190
+//    @DeleteMapping("/storeLog/{id}")
191
+//    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
192
+//        storeLogService.removeLogicById(id);
193
+//        return ResponseBean.success("success");
194
+//    }
100 195
 }

+ 27
- 6
src/main/java/com/yunzhi/inte/controller/StoreTypeController.java 查看文件

@@ -6,6 +6,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.inte.common.BaseController;
7 7
 import com.yunzhi.inte.common.ResponseBean;
8 8
 import java.util.List;
9
+
10
+import com.yunzhi.inte.common.StringUtils;
11
+import com.yunzhi.inte.entity.Package;
12
+import com.yunzhi.inte.entity.Store;
9 13
 import io.swagger.annotations.Api;
10 14
 import io.swagger.annotations.ApiOperation;
11 15
 import io.swagger.annotations.ApiParam;
@@ -49,12 +53,15 @@ public class StoreTypeController extends BaseController {
49 53
     @ApiOperation("分页查询")
50 54
     @GetMapping("/storeType")
51 55
     public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
56
+                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
57
+                             @ApiParam("名称") @RequestParam(value ="name", required = false) String name) throws Exception {
53 58
 
54 59
         IPage<StoreType> pg = new Page<>(pageNum, pageSize);
55
-        // QueryWrapper<StoreType> queryWrapper = new QueryWrapper<>();
56
-        // queryWrapper.orderByDesc("create_date");
57
-        IPage<StoreType> result = storeTypeService.page(pg);
60
+        QueryWrapper<StoreType> queryWrapper = new QueryWrapper<>();
61
+        queryWrapper.like(!StringUtils.isEmpty(name), "name", name);
62
+        queryWrapper.eq("status", 1);
63
+        queryWrapper.orderByDesc("create_date");
64
+        IPage<StoreType> result = storeTypeService.page(pg, queryWrapper);
58 65
 
59 66
         return ResponseBean.success(result);
60 67
     }
@@ -67,7 +74,13 @@ public class StoreTypeController extends BaseController {
67 74
      */
68 75
     @ApiOperation("新增数据")
69 76
     @PostMapping("/storeType")
70
-    public ResponseBean add(StoreType storeType) throws Exception {
77
+    public ResponseBean add(@ApiParam("对象实体") @RequestBody StoreType storeType) throws Exception {
78
+        StoreType origin = storeTypeService.getExistBy("name", storeType.getName(), false, true);
79
+        if (null != origin) {
80
+            return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
81
+        }
82
+
83
+        storeType.setStatus(1);
71 84
         storeTypeService.save(storeType);
72 85
         return ResponseBean.success(storeType);
73 86
     }
@@ -75,12 +88,20 @@ public class StoreTypeController extends BaseController {
75 88
     /**
76 89
      * 更新数据
77 90
      *
91
+     * @param id 对象ID
78 92
      * @param storeType 实例对象
79 93
      * @return 实例对象
80 94
      */
81 95
     @ApiOperation("更新数据")
82 96
     @PutMapping("/storeType/{id}")
83
-    public ResponseBean edit(StoreType storeType) throws Exception {
97
+    public ResponseBean edit(@ApiParam("对象ID") @PathVariable Integer id,
98
+                             @ApiParam("对象实体") @RequestBody StoreType storeType) throws Exception {
99
+        StoreType origin = storeTypeService.getExistBy("name", storeType.getName(), false, true);
100
+        if (null != origin && !id.equals(origin.getId())) {
101
+            return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
102
+        }
103
+
104
+        storeType.setId(id);
84 105
         storeTypeService.updateById(storeType);
85 106
         return ResponseBean.success(storeType);
86 107
     }

+ 10
- 1
src/main/java/com/yunzhi/inte/entity/Dishes.java 查看文件

@@ -1,5 +1,6 @@
1 1
 package com.yunzhi.inte.entity;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.TableField;
3 4
 import io.swagger.annotations.ApiModel;
4 5
 import io.swagger.annotations.ApiModelProperty;
5 6
 import com.baomidou.mybatisplus.annotation.IdType;
@@ -7,6 +8,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
7 8
 import com.baomidou.mybatisplus.annotation.TableId;
8 9
 import java.io.Serializable;
9 10
 import java.util.Date;
11
+import java.util.List;
12
+
10 13
 import lombok.Data;
11 14
 import lombok.EqualsAndHashCode;
12 15
 import lombok.experimental.Accessors;
@@ -24,7 +27,7 @@ import lombok.experimental.Accessors;
24 27
 public class Dishes implements Serializable,Cloneable{
25 28
     /** 菜肴ID */
26 29
     @ApiModelProperty(name = "菜肴ID",notes = "")
27
-    @TableId(value = "id", type = IdType.INPUT)
30
+    @TableId(value = "id", type = IdType.AUTO)
28 31
     private Integer id ;
29 32
     /** 菜肴名称 */
30 33
     @ApiModelProperty(name = "菜肴名称",notes = "")
@@ -32,6 +35,9 @@ public class Dishes implements Serializable,Cloneable{
32 35
     /** 菜肴单位 */
33 36
     @ApiModelProperty(name = "菜肴单位",notes = "")
34 37
     private String unit ;
38
+    /** 食材数量 */
39
+    @ApiModelProperty(name = "食材数量",notes = "")
40
+    private Integer foodNum;
35 41
     /** 状态 */
36 42
     @ApiModelProperty(name = "状态",notes = "")
37 43
     private Integer status ;
@@ -39,4 +45,7 @@ public class Dishes implements Serializable,Cloneable{
39 45
     @ApiModelProperty(name = "创建时间",notes = "")
40 46
     private Date createDate ;
41 47
 
48
+    @TableField(exist = false)
49
+    @ApiModelProperty(name = "菜肴列表", notes = "")
50
+    private List<Integer> ingredientsIdList;
42 51
 }

+ 26
- 1
src/main/java/com/yunzhi/inte/entity/Store.java 查看文件

@@ -1,5 +1,8 @@
1 1
 package com.yunzhi.inte.entity;
2 2
 
3
+import com.alibaba.excel.annotation.ExcelIgnore;
4
+import com.alibaba.excel.annotation.ExcelProperty;
5
+import com.baomidou.mybatisplus.annotation.TableField;
3 6
 import io.swagger.annotations.ApiModel;
4 7
 import io.swagger.annotations.ApiModelProperty;
5 8
 import com.baomidou.mybatisplus.annotation.IdType;
@@ -23,22 +26,44 @@ import lombok.experimental.Accessors;
23 26
 @TableName("store")
24 27
 public class Store implements Serializable,Cloneable{
25 28
     /** ID */
29
+    @ExcelIgnore
26 30
     @ApiModelProperty(name = "ID",notes = "")
27
-    @TableId(value = "id", type = IdType.INPUT)
31
+    @TableId(value = "id", type = IdType.AUTO)
28 32
     private Integer id ;
29 33
     /** 物品名称 */
34
+    @ExcelProperty(value = "名称", index = 0)
30 35
     @ApiModelProperty(name = "物品名称",notes = "")
31 36
     private String name ;
32 37
     /** 所属分类 */
38
+    @ExcelIgnore
33 39
     @ApiModelProperty(name = "所属分类",notes = "")
34 40
     private Integer typeId ;
41
+
42
+    @ExcelProperty(value = "分类", index = 2)
43
+    @TableField(exist = false)
44
+    private String typeName;
45
+
35 46
     /** 库存量 */
47
+    @ExcelProperty(value = "库存量", index = 3)
36 48
     @ApiModelProperty(name = "库存量",notes = "")
37 49
     private Integer amount ;
50
+    /** 单位 */
51
+    @ExcelProperty(value = "单位", index = 1)
52
+    @ApiModelProperty(name = "单位",notes = "")
53
+    private String unit ;
54
+
55
+
56
+    /** 是否食材 */
57
+    @ExcelIgnore
58
+    @ApiModelProperty(name = "是否食材",notes = "")
59
+    private Integer isDish;
60
+
38 61
     /** 状态 */
62
+    @ExcelIgnore
39 63
     @ApiModelProperty(name = "状态",notes = "")
40 64
     private Integer status ;
41 65
     /** 创建时间 */
66
+    @ExcelIgnore
42 67
     @ApiModelProperty(name = "创建时间",notes = "")
43 68
     private Date createDate ;
44 69
 

+ 28
- 1
src/main/java/com/yunzhi/inte/entity/StoreLog.java 查看文件

@@ -1,5 +1,8 @@
1 1
 package com.yunzhi.inte.entity;
2 2
 
3
+import com.alibaba.excel.annotation.ExcelIgnore;
4
+import com.alibaba.excel.annotation.ExcelProperty;
5
+import com.baomidou.mybatisplus.annotation.TableField;
3 6
 import io.swagger.annotations.ApiModel;
4 7
 import io.swagger.annotations.ApiModelProperty;
5 8
 import com.baomidou.mybatisplus.annotation.IdType;
@@ -23,23 +26,47 @@ import lombok.experimental.Accessors;
23 26
 @TableName("store_log")
24 27
 public class StoreLog implements Serializable,Cloneable{
25 28
     /** 日志ID */
29
+    @ExcelIgnore
26 30
     @ApiModelProperty(name = "日志ID",notes = "")
27
-    @TableId(value = "id", type = IdType.INPUT)
31
+    @TableId(value = "id", type = IdType.AUTO)
28 32
     private Integer id ;
29 33
     /** 操作类型;in入库out出库fix盘点 */
34
+    @ExcelProperty(value = "操作", index = 2)
30 35
     @ApiModelProperty(name = "操作类型",notes = "in入库out出库fix盘点")
31 36
     private String optType ;
32 37
     /** 物品ID */
38
+    @ExcelIgnore
33 39
     @ApiModelProperty(name = "物品ID",notes = "")
34 40
     private String storeId ;
35 41
     /** 数量 */
42
+    @ExcelProperty(value = "数量", index = 3)
36 43
     @ApiModelProperty(name = "数量",notes = "")
37 44
     private Integer amount ;
38 45
     /** 操作前数量 */
46
+    @ExcelIgnore
39 47
     @ApiModelProperty(name = "操作前数量",notes = "")
40 48
     private Integer preAmount ;
49
+    /** 操作后数量 */
50
+    @ExcelProperty(value = "操作后库存", index = 4)
51
+    @ApiModelProperty(name = "操作后数量",notes = "")
52
+    private Integer aftAmount ;
41 53
     /** 操作时间 */
54
+    @ExcelProperty(value = "操作时间", index = 5)
42 55
     @ApiModelProperty(name = "操作时间",notes = "")
43 56
     private Date createDate ;
44 57
 
58
+    @ExcelProperty(value = "名称", index = 0)
59
+    @TableField(exist = false)
60
+    @ApiModelProperty(name = "物品名称",notes = "")
61
+    private String storeName ;
62
+
63
+    @ExcelIgnore
64
+    @TableField(exist = false)
65
+    @ApiModelProperty(name = "物品分类ID",notes = "")
66
+    private Integer typeId ;
67
+
68
+    @ExcelProperty(value = "分类", index = 1)
69
+    @TableField(exist = false)
70
+    @ApiModelProperty(name = "物品分类名称",notes = "")
71
+    private String typeName ;
45 72
 }

+ 1
- 1
src/main/java/com/yunzhi/inte/entity/StoreType.java 查看文件

@@ -24,7 +24,7 @@ import lombok.experimental.Accessors;
24 24
 public class StoreType implements Serializable,Cloneable{
25 25
     /** 分类ID */
26 26
     @ApiModelProperty(name = "分类ID",notes = "")
27
-    @TableId(value = "id", type = IdType.INPUT)
27
+    @TableId(value = "id", type = IdType.AUTO)
28 28
     private Integer id ;
29 29
     /** 名称 */
30 30
     @ApiModelProperty(name = "名称",notes = "")

+ 13
- 0
src/main/java/com/yunzhi/inte/mapper/FoodIngredientsMapper.java 查看文件

@@ -1,10 +1,14 @@
1 1
 package com.yunzhi.inte.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.yunzhi.inte.entity.Store;
4 6
 import org.apache.ibatis.annotations.Mapper;
5 7
 import org.apache.ibatis.annotations.Param;
6 8
 import com.yunzhi.inte.entity.FoodIngredients;
7 9
 
10
+import java.util.List;
11
+
8 12
 /**
9 13
  * 菜肴食材;(food_ingredients)表数据库访问层
10 14
  * @author : http://njyunzhi.com
@@ -13,4 +17,13 @@ import com.yunzhi.inte.entity.FoodIngredients;
13 17
 @Mapper
14 18
 public interface FoodIngredientsMapper  extends BaseMapper<FoodIngredients>{
15 19
 
20
+    IPage<Store> getByDish(IPage<Store> pg, @Param("dishId") Integer dishId);
21
+
22
+    List<FoodIngredients> getListByDish(@Param("dishId") Integer dishId);
23
+
24
+    int deleteNotExist(@Param("idList") List<Integer> idList);
25
+
26
+    FoodIngredients getByDishAndItem(@Param("dishId") Integer dishId,@Param("itemId") Integer itemId);
27
+
28
+    List<Integer> getItemListByDish(@Param("dishId") Integer dishId);
16 29
 }

+ 6
- 0
src/main/java/com/yunzhi/inte/mapper/StoreLogMapper.java 查看文件

@@ -1,10 +1,13 @@
1 1
 package com.yunzhi.inte.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
4 5
 import org.apache.ibatis.annotations.Mapper;
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 import com.yunzhi.inte.entity.StoreLog;
7 8
 
9
+import java.util.List;
10
+
8 11
 /**
9 12
  * 库存日志;(store_log)表数据库访问层
10 13
  * @author : http://njyunzhi.com
@@ -13,4 +16,7 @@ import com.yunzhi.inte.entity.StoreLog;
13 16
 @Mapper
14 17
 public interface StoreLogMapper  extends BaseMapper<StoreLog>{
15 18
 
19
+    IPage<StoreLog> getPageBy(IPage<StoreLog> pg, @Param("storeId") Integer storeId, @Param("storeName") String storeName, @Param("typeId") Integer typeId);
20
+
21
+    List<StoreLog> getListBy(@Param("storeId") Integer storeId, @Param("storeName") String storeName, @Param("typeId") Integer typeId);
16 22
 }

+ 6
- 0
src/main/java/com/yunzhi/inte/mapper/StoreMapper.java 查看文件

@@ -1,10 +1,13 @@
1 1
 package com.yunzhi.inte.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
4 5
 import org.apache.ibatis.annotations.Mapper;
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 import com.yunzhi.inte.entity.Store;
7 8
 
9
+import java.util.List;
10
+
8 11
 /**
9 12
  * 库存表;(store)表数据库访问层
10 13
  * @author : http://njyunzhi.com
@@ -13,4 +16,7 @@ import com.yunzhi.inte.entity.Store;
13 16
 @Mapper
14 17
 public interface StoreMapper  extends BaseMapper<Store>{
15 18
 
19
+    IPage<Store> getPageBy(IPage<Store> pg, @Param("name") String name, @Param("typeId") String typeId, @Param("isDish")  Integer isDish);
20
+
21
+    List<Store> getListBy(@Param("name") String name, @Param("typeId") String typeId);
16 22
 }

+ 9
- 0
src/main/java/com/yunzhi/inte/service/FoodIngredientsService.java 查看文件

@@ -1,7 +1,11 @@
1 1
 package com.yunzhi.inte.service;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.baomidou.mybatisplus.extension.service.IService;
4 5
 import com.yunzhi.inte.entity.FoodIngredients;
6
+import com.yunzhi.inte.entity.Store;
7
+
8
+import java.util.List;
5 9
 
6 10
 /**
7 11
  * 菜肴食材;(food_ingredients)表服务接口
@@ -10,4 +14,9 @@ import com.yunzhi.inte.entity.FoodIngredients;
10 14
  */
11 15
 public interface FoodIngredientsService extends IBaseService<FoodIngredients> {
12 16
 
17
+    IPage<Store> getByDish(IPage<Store> pg, Integer dishId);
18
+
19
+    void addOrUpdate(Integer dishId, List<Integer> ingredientsList);
20
+
21
+    List<Integer> getItemListByDish(Integer dishId);
13 22
 }

+ 6
- 1
src/main/java/com/yunzhi/inte/service/StoreLogService.java 查看文件

@@ -1,8 +1,10 @@
1 1
 package com.yunzhi.inte.service;
2 2
 
3
-import com.baomidou.mybatisplus.extension.service.IService;
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.inte.entity.StoreLog;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * 库存日志;(store_log)表服务接口
8 10
  * @author : http://njyunzhi.com
@@ -10,4 +12,7 @@ import com.yunzhi.inte.entity.StoreLog;
10 12
  */
11 13
 public interface StoreLogService extends IBaseService<StoreLog> {
12 14
 
15
+    IPage<StoreLog> getPageBy(IPage<StoreLog> pg, Integer storeId, String name, Integer typeId);
16
+
17
+    List<StoreLog> getListBy(Integer storeId, String name, Integer typeId);
13 18
 }

+ 6
- 1
src/main/java/com/yunzhi/inte/service/StoreService.java 查看文件

@@ -1,8 +1,10 @@
1 1
 package com.yunzhi.inte.service;
2 2
 
3
-import com.baomidou.mybatisplus.extension.service.IService;
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.inte.entity.Store;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * 库存表;(store)表服务接口
8 10
  * @author : http://njyunzhi.com
@@ -10,4 +12,7 @@ import com.yunzhi.inte.entity.Store;
10 12
  */
11 13
 public interface StoreService extends IBaseService<Store> {
12 14
 
15
+    IPage<Store> getPageBy(IPage<Store> pg, String name, String typeId, Integer isDish);
16
+
17
+    List<Store> getListBy(String name, String typeId);
13 18
 }

+ 44
- 0
src/main/java/com/yunzhi/inte/service/impl/FoodIngredientsServiceImpl.java 查看文件

@@ -1,10 +1,16 @@
1 1
 package com.yunzhi.inte.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.yunzhi.inte.entity.Store;
3 5
 import org.springframework.beans.factory.annotation.Autowired;
4 6
 import org.springframework.stereotype.Service;
5 7
 import com.yunzhi.inte.entity.FoodIngredients;
6 8
 import com.yunzhi.inte.mapper.FoodIngredientsMapper;
7 9
 import com.yunzhi.inte.service.FoodIngredientsService;
10
+
11
+import java.util.ArrayList;
12
+import java.util.List;
13
+
8 14
 /**
9 15
  * 菜肴食材;(food_ingredients)表服务实现类
10 16
  * @author : http://www.chiner.pro
@@ -13,4 +19,42 @@ import com.yunzhi.inte.service.FoodIngredientsService;
13 19
 @Service
14 20
 public class FoodIngredientsServiceImpl extends BaseServiceImpl<FoodIngredientsMapper, FoodIngredients> implements FoodIngredientsService {
15 21
 
22
+    @Override
23
+    public IPage<Store> getByDish(IPage<Store> pg, Integer dishId) {
24
+        return baseMapper.getByDish(pg, dishId);
25
+    }
26
+
27
+    @Override
28
+    public void addOrUpdate(Integer dishId, List<Integer> ingredientsList) {
29
+        // 查询已有 list
30
+        List<Integer> idList = new ArrayList<>();
31
+        if (null != ingredientsList && ingredientsList.size() > 0) {
32
+            //
33
+            for (Integer itemId: ingredientsList) {
34
+                FoodIngredients item = baseMapper.getByDishAndItem(dishId, itemId);
35
+
36
+                if (item != null) {
37
+                    // 有就更新
38
+                    updateById(item);
39
+                } else {
40
+                    // 没有就插入
41
+                    item = new FoodIngredients();
42
+                    item.setItemId(itemId);
43
+                    item.setDishId(dishId);
44
+                    save(item);
45
+                }
46
+                Integer id = item.getId();
47
+                idList.add(id);
48
+            }
49
+        } else {
50
+            idList.add(-1);
51
+        }
52
+        // 删除剩余的
53
+        baseMapper.deleteNotExist(idList);
54
+    }
55
+
56
+    @Override
57
+    public List<Integer> getItemListByDish(Integer dishId) {
58
+        return baseMapper.getItemListByDish(dishId);
59
+    }
16 60
 }

+ 26
- 1
src/main/java/com/yunzhi/inte/service/impl/StoreLogServiceImpl.java 查看文件

@@ -1,10 +1,14 @@
1 1
 package com.yunzhi.inte.service.impl;
2 2
 
3
-import org.springframework.beans.factory.annotation.Autowired;
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.yunzhi.inte.common.StringUtils;
4 5
 import org.springframework.stereotype.Service;
5 6
 import com.yunzhi.inte.entity.StoreLog;
6 7
 import com.yunzhi.inte.mapper.StoreLogMapper;
7 8
 import com.yunzhi.inte.service.StoreLogService;
9
+
10
+import java.util.List;
11
+
8 12
 /**
9 13
  * 库存日志;(store_log)表服务实现类
10 14
  * @author : http://www.chiner.pro
@@ -13,4 +17,25 @@ import com.yunzhi.inte.service.StoreLogService;
13 17
 @Service
14 18
 public class StoreLogServiceImpl extends BaseServiceImpl<StoreLogMapper, StoreLog> implements StoreLogService {
15 19
 
20
+    @Override
21
+    public IPage<StoreLog> getPageBy(IPage<StoreLog> pg, Integer storeId, String name, Integer typeId) {
22
+        if (StringUtils.isEmpty(name)) {
23
+            name = null;
24
+        } else {
25
+            name = "%" + name + "%";
26
+        }
27
+
28
+        return baseMapper.getPageBy(pg, storeId, name, typeId);
29
+    }
30
+
31
+    @Override
32
+    public List<StoreLog> getListBy(Integer storeId, String name, Integer typeId) {
33
+        if (StringUtils.isEmpty(name)) {
34
+            name = null;
35
+        } else {
36
+            name = "%" + name + "%";
37
+        }
38
+
39
+        return baseMapper.getListBy(storeId, name, typeId);
40
+    }
16 41
 }

+ 26
- 1
src/main/java/com/yunzhi/inte/service/impl/StoreServiceImpl.java 查看文件

@@ -1,10 +1,14 @@
1 1
 package com.yunzhi.inte.service.impl;
2 2
 
3
-import org.springframework.beans.factory.annotation.Autowired;
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.yunzhi.inte.common.StringUtils;
4 5
 import org.springframework.stereotype.Service;
5 6
 import com.yunzhi.inte.entity.Store;
6 7
 import com.yunzhi.inte.mapper.StoreMapper;
7 8
 import com.yunzhi.inte.service.StoreService;
9
+
10
+import java.util.List;
11
+
8 12
 /**
9 13
  * 库存表;(store)表服务实现类
10 14
  * @author : http://www.chiner.pro
@@ -13,4 +17,25 @@ import com.yunzhi.inte.service.StoreService;
13 17
 @Service
14 18
 public class StoreServiceImpl extends BaseServiceImpl<StoreMapper, Store> implements StoreService {
15 19
 
20
+    @Override
21
+    public IPage<Store> getPageBy(IPage<Store> pg, String name, String typeId, Integer isDish) {
22
+        if (StringUtils.isEmpty(name)) {
23
+            name = null;
24
+        } else {
25
+            name = "%" + name + "%";
26
+        }
27
+
28
+        return baseMapper.getPageBy(pg, name, typeId, isDish);
29
+    }
30
+
31
+    @Override
32
+    public List<Store> getListBy(String name, String typeId) {
33
+        if (StringUtils.isEmpty(name)) {
34
+            name = null;
35
+        } else {
36
+            name = "%" + name + "%";
37
+        }
38
+
39
+        return baseMapper.getListBy(name, typeId);
40
+    }
16 41
 }

+ 28
- 0
src/main/resources/mapper/FoodIngredientsMapper.xml 查看文件

@@ -3,4 +3,32 @@
3 3
 
4 4
 <mapper namespace="com.yunzhi.inte.mapper.FoodIngredientsMapper">
5 5
 
6
+    <sql id="getFoodIngredientsList">
7
+        SELECT
8
+            t.*
9
+        FROM
10
+            store t
11
+                INNER JOIN food_ingredients s ON s.item_id = t.id
12
+        WHERE
13
+            s.dish_id = #{dishId}
14
+    </sql>
15
+    <delete id="deleteNotExist">
16
+        delete from food_ingredients where id not in
17
+        <foreach item="id" collection="idList" separator="," open="(" close=")" index="">
18
+            #{id}
19
+        </foreach>
20
+    </delete>
21
+
22
+    <select id="getByDish" resultType="com.yunzhi.inte.entity.Store">
23
+        <include refid="getFoodIngredientsList"></include>
24
+    </select>
25
+    <select id="getListByDish" resultType="com.yunzhi.inte.entity.FoodIngredients">
26
+        <include refid="getFoodIngredientsList"></include>
27
+    </select>
28
+    <select id="getByDishAndItem" resultType="com.yunzhi.inte.entity.FoodIngredients">
29
+        select * from food_ingredients where dish_id = #{dishId} and item_id = #{itemId}
30
+    </select>
31
+    <select id="getItemListByDish" resultType="java.lang.Integer">
32
+        select item_id from food_ingredients where dish_id = #{dishId}
33
+    </select>
6 34
 </mapper>

+ 30
- 0
src/main/resources/mapper/StoreLogMapper.xml 查看文件

@@ -2,5 +2,35 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 
4 4
 <mapper namespace="com.yunzhi.inte.mapper.StoreLogMapper">
5
+    <sql id="getStoreLogList">
6
+        SELECT
7
+            t.*,
8
+            s.name AS store_name,
9
+            s.type_id,
10
+            m.name AS type_name
11
+        FROM
12
+            store_log t
13
+                INNER JOIN store s ON t.store_id = s.id
14
+                LEFT JOIN store_type m ON s.type_id = m.id
15
+        WHERE
16
+            s.status = 1
17
+          <if test="storeId != null">
18
+              AND s.id = #{storeId}
19
+          </if>
20
+        <if test="storeName != null and storeName != ''">
21
+            AND s.name like #{storeName}
22
+        </if>
23
+        <if test="typeId != null">
24
+            AND s.type_id = #{typeId}
25
+        </if>
26
+        ORDER BY
27
+            t.id DESC
28
+    </sql>
5 29
 
30
+    <select id="getPageBy" resultType="com.yunzhi.inte.entity.StoreLog">
31
+        <include refid="getStoreLogList"></include>
32
+    </select>
33
+    <select id="getListBy" resultType="com.yunzhi.inte.entity.StoreLog">
34
+        <include refid="getStoreLogList"></include>
35
+    </select>
6 36
 </mapper>

+ 28
- 0
src/main/resources/mapper/StoreMapper.xml 查看文件

@@ -3,4 +3,32 @@
3 3
 
4 4
 <mapper namespace="com.yunzhi.inte.mapper.StoreMapper">
5 5
 
6
+    <sql id="getStoreList">
7
+        SELECT
8
+            t.*,
9
+            s.name AS type_name
10
+        FROM
11
+            store t
12
+                LEFT JOIN store_type s ON t.type_id = s.id
13
+        WHERE
14
+            t.status = 1
15
+          <if test="name != null and name != ''">
16
+              AND t.name LIKE #{name}
17
+          </if>
18
+          <if test="typeId != null">
19
+              AND t.type_id = #{typeId}
20
+          </if>
21
+        <if test="isDish != null">
22
+            AND s.is_food = #{isDish}
23
+        </if>
24
+        ORDER BY
25
+            t.id DESC
26
+    </sql>
27
+
28
+    <select id="getPageBy" resultType="com.yunzhi.inte.entity.Store">
29
+        <include refid="getStoreList"></include>
30
+    </select>
31
+    <select id="getListBy" resultType="com.yunzhi.inte.entity.Store">
32
+        <include refid="getStoreList"></include>
33
+    </select>
6 34
 </mapper>