阅读 59 SEO

Java 实战范例之进销存管理系统的实现

读万卷书不如行万里路,只学书上的理论是远远不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用java+vue+Springboot+ssm+mysql+maven+redis实现一个前后端分离的进销存管理系统,大家可以在过程中查缺补漏,提升水平

一、项目简述

本系统功能包括: 库存管理,入库管理,出库管理,往来管理,基础资料, 系统管理,消息中心,系统监控等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX ( Webstorm也 行)+ Eclispe ( IntelliJ IDEA ,Eclispe,MyEclispe , Sts都支持)。

项目技术: Springboot + Maven + Mybatis-plus+ Vue + Redis + Shiro + Druid + logback 组成,B/S模萤;,其他:fastjson, poi, Swagger-ui, quartz, lombok (简化代码)等


采购发票登记代码:

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
221
222
223
224
/**
 * @Description: 采购发票登记
 * @Author: jeecg-boot
 * @Version: V1.0
 */
@Api(tags="采购发票登记")
@RestController
@RequestMapping("/finance/finPurInvoice")
@Slf4j
public class FinPurInvoiceController {
    @Autowired
    private IFinPurInvoiceService finPurInvoiceService;
    @Autowired
    private IFinPurInvoiceEntryService finPurInvoiceEntryService;
     
    /**
     * 分页列表查询
     *
     * @param finPurInvoice
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "采购发票登记-分页列表查询")
    @ApiOperation(value="采购发票登记-分页列表查询", notes="采购发票登记-分页列表查询")
    @GetMapping(value = {"/list", "/list/{isRubric}"})
    public Result<?> queryPageList(FinPurInvoice finPurInvoice,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<FinPurInvoice> queryWrapper = QueryGenerator.initQueryWrapper(finPurInvoice, req.getParameterMap());
        Page<FinPurInvoice> page = new Page<FinPurInvoice>(pageNo, pageSize);
        IPage<FinPurInvoice> pageList = finPurInvoiceService.page(page, queryWrapper);
        return Result.ok(pageList);
    }
     
    /**
     *   添加
     *
     * @param finPurInvoicePage
     * @return
     */
    @AutoLog(value = "采购发票登记-添加")
    @ApiOperation(value="采购发票登记-添加", notes="采购发票登记-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody FinPurInvoicePage finPurInvoicePage) {
        FinPurInvoice finPurInvoice = new FinPurInvoice();
        BeanUtils.copyProperties(finPurInvoicePage, finPurInvoice);
        finPurInvoiceService.saveMain(finPurInvoice, finPurInvoicePage.getFinPurInvoiceEntryList());
        return Result.ok("添加成功!");
    }
     
    /**
     *  编辑
     *
     * @param finPurInvoicePage
     * @return
     */
    @AutoLog(value = "采购发票登记-编辑")
    @ApiOperation(value="采购发票登记-编辑", notes="采购发票登记-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody FinPurInvoicePage finPurInvoicePage) {
        FinPurInvoice finPurInvoice = new FinPurInvoice();
        BeanUtils.copyProperties(finPurInvoicePage, finPurInvoice);
        FinPurInvoice finPurInvoiceEntity = finPurInvoiceService.getById(finPurInvoice.getId());
        if(finPurInvoiceEntity==null) {
            return Result.error("未找到对应数据");
        }
        finPurInvoiceService.updateMain(finPurInvoice, finPurInvoicePage.getFinPurInvoiceEntryList());
        return Result.ok("编辑成功!");
    }
     
    /**
     *   通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "采购发票登记-通过id删除")
    @ApiOperation(value="采购发票登记-通过id删除", notes="采购发票登记-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name="id",required=true) String id) {
        finPurInvoiceService.delMain(id);
        return Result.ok("删除成功!");
    }
     
    /**
     *  批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "采购发票登记-批量删除")
    @ApiOperation(value="采购发票登记-批量删除", notes="采购发票登记-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.finPurInvoiceService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功!");
    }
     
    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "采购发票登记-通过id查询")
    @ApiOperation(value="采购发票登记-通过id查询", notes="采购发票登记-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
        FinPurInvoice finPurInvoice = finPurInvoiceService.getById(id);
        if(finPurInvoice==null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(finPurInvoice);
  
    }
     
    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "明细通过主表ID查询")
    @ApiOperation(value="明细主表ID查询", notes="明细-通主表ID查询")
    @GetMapping(value = "/queryFinPurInvoiceEntryByMainId")
    public Result<?> queryFinPurInvoiceEntryListByMainId(@RequestParam(name="id",required=true) String id) {
        List<FinPurInvoiceEntry> finPurInvoiceEntryList = finPurInvoiceEntryService.selectByMainId(id);
        return Result.ok(finPurInvoiceEntryList);
    }
  
    /**
    * 导出excel
    *
    * @param request
    * @param finPurInvoice
    */
    @RequestMapping(value = {"/exportXls", "/exportXls/{isRubric}"})
    public ModelAndView exportXls(HttpServletRequest request, FinPurInvoice finPurInvoice) {
      // Step.1 组装查询条件查询数据
      QueryWrapper<FinPurInvoice> queryWrapper = QueryGenerator.initQueryWrapper(finPurInvoice, request.getParameterMap());
      LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
  
      //Step.2 获取导出数据
      List<FinPurInvoice> queryList = finPurInvoiceService.list(queryWrapper);
      // 过滤选中数据
      String selections = request.getParameter("selections");
      List<FinPurInvoice> finPurInvoiceList = new ArrayList<FinPurInvoice>();
      if(oConvertUtils.isEmpty(selections)) {
          finPurInvoiceList = queryList;
      }else {
          List<String> selectionList = Arrays.asList(selections.split(","));
          finPurInvoiceList = queryList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
      }
  
      // Step.3 组装pageList
      List<FinPurInvoicePage> pageList = new ArrayList<FinPurInvoicePage>();
      for (FinPurInvoice main : finPurInvoiceList) {
          FinPurInvoicePage vo = new FinPurInvoicePage();
          BeanUtils.copyProperties(main, vo);
          List<FinPurInvoiceEntry> finPurInvoiceEntryList = finPurInvoiceEntryService.selectByMainId(main.getId());
          vo.setFinPurInvoiceEntryList(finPurInvoiceEntryList);
          pageList.add(vo);
      }
  
      // Step.4 AutoPoi 导出Excel
      ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
      mv.addObject(NormalExcelConstants.FILE_NAME, "采购发票登记列表");
      mv.addObject(NormalExcelConstants.CLASS, FinPurInvoicePage.class);
      mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("采购发票登记数据", "导出人:"+sysUser.getRealname(), "采购发票登记"));
      mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
      return mv;
    }
  
    /**
    * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
      Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
      for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
          MultipartFile file = entity.getValue();// 获取上传文件对象
          ImportParams params = new ImportParams();
          params.setTitleRows(2);
          params.setHeadRows(1);
          params.setNeedSave(true);
          try {
              List<FinPurInvoicePage> list = ExcelImportUtil.importExcel(file.getInputStream(), FinPurInvoicePage.class, params);
              for (FinPurInvoicePage page : list) {
                  FinPurInvoice po = new FinPurInvoice();
                  BeanUtils.copyProperties(page, po);
                  finPurInvoiceService.saveMain(po, page.getFinPurInvoiceEntryList());
              }
              return Result.ok("文件导入成功!数据行数:" + list.size());
          } catch (Exception e) {
              log.error(e.getMessage(),e);
              return Result.error("文件导入失败:"+e.getMessage());
          } finally {
              try {
                  file.getInputStream().close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
      return Result.ok("文件导入失败!");
    }
  
     @AutoLog(value = "采购发票登记-通过id审核")
     @ApiOperation(value=