当前位置:   article > 正文

Java项目:进销存管理系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)_java+vue+mysql前后端分离:文件下载接口

java+vue+mysql前后端分离:文件下载接口

源码获取:博客首页 "资源" 里下载!

一、项目简述

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

二、项目运行

环境配置: 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. * @author scott
  4. */
  5. @Data
  6. @ApiModel(value="接口返回对象", description="接口返回对象")
  7. public class Result<T> implements Serializable {
  8. private static final long serialVersionUID = 1L;
  9. /**
  10. * 成功标志
  11. */
  12. @ApiModelProperty(value = "成功标志")
  13. private boolean success = true;
  14. /**
  15. * 返回处理消息
  16. */
  17. @ApiModelProperty(value = "返回处理消息")
  18. private String message = "操作成功!";
  19. /**
  20. * 返回代码
  21. */
  22. @ApiModelProperty(value = "返回代码")
  23. private Integer code = 0;
  24. /**
  25. * 返回数据对象 data
  26. */
  27. @ApiModelProperty(value = "返回数据对象")
  28. private T result;
  29. /**
  30. * 时间戳
  31. */
  32. @ApiModelProperty(value = "时间戳")
  33. private long timestamp = System.currentTimeMillis();
  34. public Result() {
  35. }
  36. public Result<T> success(String message) {
  37. this.message = message;
  38. this.code = CommonConstant.SC_OK_200;
  39. this.success = true;
  40. return this;
  41. }
  42. public static Result<Object> ok() {
  43. Result<Object> r = new Result<Object>();
  44. r.setSuccess(true);
  45. r.setCode(CommonConstant.SC_OK_200);
  46. r.setMessage("成功");
  47. return r;
  48. }
  49. public static Result<Object> ok(String msg) {
  50. Result<Object> r = new Result<Object>();
  51. r.setSuccess(true);
  52. r.setCode(CommonConstant.SC_OK_200);
  53. r.setMessage(msg);
  54. return r;
  55. }
  56. public static Result<Object> ok(Object data) {
  57. Result<Object> r = new Result<Object>();
  58. r.setSuccess(true);
  59. r.setCode(CommonConstant.SC_OK_200);
  60. r.setResult(data);
  61. return r;
  62. }
  63. public static Result<Object> error(String msg) {
  64. return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
  65. }
  66. public static Result<Object> error(int code, String msg) {
  67. Result<Object> r = new Result<Object>();
  68. r.setCode(code);
  69. r.setMessage(msg);
  70. r.setSuccess(false);
  71. return r;
  72. }
  73. public Result<T> error500(String message) {
  74. this.message = message;
  75. this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
  76. this.success = false;
  77. return this;
  78. }
  79. /**
  80. * 无权限访问返回结果
  81. */
  82. public static Result<Object> noauth(String msg) {
  83. return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg);
  84. }
  85. }

用户信息控制器:

  1. /**
  2. * <p>
  3. * 用户表 前端控制器
  4. * </p>
  5. *
  6. */
  7. @Slf4j
  8. @RestController
  9. @RequestMapping("/sys/common")
  10. public class CommonController {
  11. @Autowired
  12. private ISysBaseAPI sysBaseAPI;
  13. @Value(value = "${jeecg.path.upload}")
  14. private String uploadpath;
  15. /**
  16. * 本地:local minio:minio 阿里:alioss
  17. */
  18. @Value(value="${jeecg.uploadType}")
  19. private String uploadType;
  20. /**
  21. * @Author 政辉
  22. * @return
  23. */
  24. @GetMapping("/403")
  25. public Result<?> noauth() {
  26. return Result.error("没有权限,请联系管理员授权");
  27. }
  28. /**
  29. * 文件上传统一方法
  30. * @param request
  31. * @param response
  32. * @return
  33. */
  34. @PostMapping(value = "/upload")
  35. public Result<?> upload(HttpServletRequest request, HttpServletResponse response) {
  36. Result<?> result = new Result<>();
  37. String savePath = "";
  38. String bizPath = request.getParameter("biz");
  39. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  40. MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
  41. if(oConvertUtils.isEmpty(bizPath)){
  42. if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
  43. //未指定目录,则用阿里云默认目录 upload
  44. bizPath = "upload";
  45. //result.setMessage("使用阿里云文件上传时,必须添加目录!");
  46. //result.setSuccess(false);
  47. //return result;
  48. }else{
  49. bizPath = "";
  50. }
  51. }
  52. if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
  53. //针对jeditor编辑器如何使 lcaol模式,采用 base64格式存储
  54. String jeditor = request.getParameter("jeditor");
  55. if(oConvertUtils.isNotEmpty(jeditor)){
  56. result.setMessage(CommonConstant.UPLOAD_TYPE_LOCAL);
  57. result.setSuccess(true);
  58. return result;
  59. }else{
  60. savePath = this.uploadLocal(file,bizPath);
  61. }
  62. }else{
  63. savePath = sysBaseAPI.upload(file,bizPath,uploadType);
  64. }
  65. if(oConvertUtils.isNotEmpty(savePath)){
  66. result.setMessage(savePath);
  67. result.setSuccess(true);
  68. }else {
  69. result.setMessage("上传失败!");
  70. result.setSuccess(false);
  71. }
  72. return result;
  73. }
  74. /**
  75. * 本地文件上传
  76. * @param mf 文件
  77. * @param bizPath 自定义路径
  78. * @return
  79. */
  80. private String uploadLocal(MultipartFile mf,String bizPath){
  81. try {
  82. String ctxPath = uploadpath;
  83. String fileName = null;
  84. File file = new File(ctxPath + File.separator + bizPath + File.separator );
  85. if (!file.exists()) {
  86. file.mkdirs();// 创建文件根目录
  87. }
  88. String orgName = mf.getOriginalFilename();// 获取文件名
  89. orgName = CommonUtils.getFileName(orgName);
  90. if(orgName.indexOf(".")!=-1){
  91. fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
  92. }else{
  93. fileName = orgName+ "_" + System.currentTimeMillis();
  94. }
  95. String savePath = file.getPath() + File.separator + fileName;
  96. File savefile = new File(savePath);
  97. FileCopyUtils.copy(mf.getBytes(), savefile);
  98. String dbpath = null;
  99. if(oConvertUtils.isNotEmpty(bizPath)){
  100. dbpath = bizPath + File.separator + fileName;
  101. }else{
  102. dbpath = fileName;
  103. }
  104. if (dbpath.contains("\\")) {
  105. dbpath = dbpath.replace("\\", "/");
  106. }
  107. return dbpath;
  108. } catch (IOException e) {
  109. log.error(e.getMessage(), e);
  110. }
  111. return "";
  112. }
  113. // @PostMapping(value = "/upload2")
  114. // public Result<?> upload2(HttpServletRequest request, HttpServletResponse response) {
  115. // Result<?> result = new Result<>();
  116. // try {
  117. // String ctxPath = uploadpath;
  118. // String fileName = null;
  119. // String bizPath = "files";
  120. // String tempBizPath = request.getParameter("biz");
  121. // if(oConvertUtils.isNotEmpty(tempBizPath)){
  122. // bizPath = tempBizPath;
  123. // }
  124. // String nowday = new SimpleDateFormat("yyyyMMdd").format(new Date());
  125. // File file = new File(ctxPath + File.separator + bizPath + File.separator + nowday);
  126. // if (!file.exists()) {
  127. // file.mkdirs();// 创建文件根目录
  128. // }
  129. // MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  130. // MultipartFile mf = multipartRequest.getFile("file");// 获取上传文件对象
  131. // String orgName = mf.getOriginalFilename();// 获取文件名
  132. // fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
  133. // String savePath = file.getPath() + File.separator + fileName;
  134. // File savefile = new File(savePath);
  135. // FileCopyUtils.copy(mf.getBytes(), savefile);
  136. // String dbpath = bizPath + File.separator + nowday + File.separator + fileName;
  137. // if (dbpath.contains("\\")) {
  138. // dbpath = dbpath.replace("\\", "/");
  139. // }
  140. // result.setMessage(dbpath);
  141. // result.setSuccess(true);
  142. // } catch (IOException e) {
  143. // result.setSuccess(false);
  144. // result.setMessage(e.getMessage());
  145. // log.error(e.getMessage(), e);
  146. // }
  147. // return result;
  148. // }
  149. /**
  150. * 预览图片&下载文件
  151. * 请求地址:http://localhost:8080/common/static/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
  152. *
  153. * @param request
  154. * @param response
  155. */
  156. @GetMapping(value = "/static/**")
  157. public void view(HttpServletRequest request, HttpServletResponse response) {
  158. // ISO-8859-1 ==> UTF-8 进行编码转换
  159. String imgPath = extractPathFromPattern(request);
  160. if(oConvertUtils.isEmpty(imgPath) || imgPath=="null"){
  161. return;
  162. }
  163. // 其余处理略
  164. InputStream inputStream = null;
  165. OutputStream outputStream = null;
  166. try {
  167. imgPath = imgPath.replace("..", "");
  168. if (imgPath.endsWith(",")) {
  169. imgPath = imgPath.substring(0, imgPath.length() - 1);
  170. }
  171. String filePath = uploadpath + File.separator + imgPath;
  172. File file = new File(filePath);
  173. if(!file.exists()){
  174. response.setStatus(404);
  175. throw new RuntimeException("文件不存在..");
  176. }
  177. response.setContentType("application/force-download");// 设置强制下载不打开
  178. response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
  179. inputStream = new BufferedInputStream(new FileInputStream(filePath));
  180. outputStream = response.getOutputStream();
  181. byte[] buf = new byte[1024];
  182. int len;
  183. while ((len = inputStream.read(buf)) > 0) {
  184. outputStream.write(buf, 0, len);
  185. }
  186. response.flushBuffer();
  187. } catch (IOException e) {
  188. log.error("预览文件失败" + e.getMessage());
  189. response.setStatus(404);
  190. e.printStackTrace();
  191. } finally {
  192. if (inputStream != null) {
  193. try {
  194. inputStream.close();
  195. } catch (IOException e) {
  196. log.error(e.getMessage(), e);
  197. }
  198. }
  199. if (outputStream != null) {
  200. try {
  201. outputStream.close();
  202. } catch (IOException e) {
  203. log.error(e.getMessage(), e);
  204. }
  205. }
  206. }
  207. }
  208. // /**
  209. // * 下载文件
  210. // * 请求地址:http://localhost:8080/common/download/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
  211. // *
  212. // * @param request
  213. // * @param response
  214. // * @throws Exception
  215. // */
  216. // @GetMapping(value = "/download/**")
  217. // public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
  218. // // ISO-8859-1 ==> UTF-8 进行编码转换
  219. // String filePath = extractPathFromPattern(request);
  220. // // 其余处理略
  221. // InputStream inputStream = null;
  222. // OutputStream outputStream = null;
  223. // try {
  224. // filePath = filePath.replace("..", "");
  225. // if (filePath.endsWith(",")) {
  226. // filePath = filePath.substring(0, filePath.length() - 1);
  227. // }
  228. // String localPath = uploadpath;
  229. // String downloadFilePath = localPath + File.separator + filePath;
  230. // File file = new File(downloadFilePath);
  231. // if (file.exists()) {
  232. // response.setContentType("application/force-download");// 设置强制下载不打开            
  233. // response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
  234. // inputStream = new BufferedInputStream(new FileInputStream(file));
  235. // outputStream = response.getOutputStream();
  236. // byte[] buf = new byte[1024];
  237. // int len;
  238. // while ((len = inputStream.read(buf)) > 0) {
  239. // outputStream.write(buf, 0, len);
  240. // }
  241. // response.flushBuffer();
  242. // }
  243. //
  244. // } catch (Exception e) {
  245. // log.info("文件下载失败" + e.getMessage());
  246. // // e.printStackTrace();
  247. // } finally {
  248. // if (inputStream != null) {
  249. // try {
  250. // inputStream.close();
  251. // } catch (IOException e) {
  252. // e.printStackTrace();
  253. // }
  254. // }
  255. // if (outputStream != null) {
  256. // try {
  257. // outputStream.close();
  258. // } catch (IOException e) {
  259. // e.printStackTrace();
  260. // }
  261. // }
  262. // }
  263. //
  264. // }
  265. /**
  266. * @功能:pdf预览Iframe
  267. * @param modelAndView
  268. * @return
  269. */
  270. @RequestMapping("/pdf/pdfPreviewIframe")
  271. public ModelAndView pdfPreviewIframe(ModelAndView modelAndView) {
  272. modelAndView.setViewName("pdfPreviewIframe");
  273. return modelAndView;
  274. }
  275. /**
  276. * 把指定URL后的字符串全部截断当成参数
  277. * 这么做是为了防止URL中包含中文或者特殊字符(/等)时,匹配不了的问题
  278. * @param request
  279. * @return
  280. */
  281. private static String extractPathFromPattern(final HttpServletRequest request) {
  282. String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
  283. String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
  284. return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
  285. }
  286. /**
  287. * 中转HTTP请求,解决跨域问题
  288. *
  289. * @param url 必填:请求地址
  290. * @return
  291. */
  292. @RequestMapping("/transitRESTful")
  293. public Result transitRESTful(@RequestParam("url") String url, HttpServletRequest request) {
  294. try {
  295. ServletServerHttpRequest httpRequest = new ServletServerHttpRequest(request);
  296. // 中转请求method、body
  297. HttpMethod method = httpRequest.getMethod();
  298. JSONObject params;
  299. try {
  300. params = JSON.parseObject(JSON.toJSONString(httpRequest.getBody()));
  301. } catch (Exception e) {
  302. params = new JSONObject();
  303. }
  304. // 中转请求问号参数
  305. JSONObject variables = JSON.parseObject(JSON.toJSONString(request.getParameterMap()));
  306. variables.remove("url");
  307. // 在 headers 里传递Token
  308. String token = TokenUtils.getTokenByRequest(request);
  309. HttpHeaders headers = new HttpHeaders();
  310. headers.set("X-Access-Token", token);
  311. // 发送请求
  312. String httpURL = URLDecoder.decode(url, "UTF-8");
  313. ResponseEntity<String> response = RestUtil.request(httpURL, method, headers , variables, params, String.class);
  314. // 封装返回结果
  315. Result<Object> result = new Result<>();
  316. int statusCode = response.getStatusCodeValue();
  317. result.setCode(statusCode);
  318. result.setSuccess(statusCode == 200);
  319. String responseBody = response.getBody();
  320. try {
  321. // 尝试将返回结果转为JSON
  322. Object json = JSON.parse(responseBody);
  323. result.setResult(json);
  324. } catch (Exception e) {
  325. // 转成JSON失败,直接返回原始数据
  326. result.setResult(responseBody);
  327. }
  328. return result;
  329. } catch (Exception e) {
  330. log.debug("中转HTTP请求失败", e);
  331. return Result.error(e.getMessage());
  332. }
  333. }
  334. }

 

付款单控制层:

  1. /**
  2. * @Description: 付款单
  3. */
  4. @Api(tags="付款单")
  5. @RestController
  6. @RequestMapping("/finance/finPayment")
  7. @Slf4j
  8. public class FinPaymentController {
  9. @Autowired
  10. private IFinPaymentService finPaymentService;
  11. @Autowired
  12. private IFinPaymentEntryService finPaymentEntryService;
  13. /**
  14. * 分页列表查询
  15. *
  16. * @param finPayment
  17. * @param pageNo
  18. * @param pageSize
  19. * @param req
  20. * @return
  21. */
  22. @AutoLog(value = "付款单-分页列表查询")
  23. @ApiOperation(value="付款单-分页列表查询", notes="付款单-分页列表查询")
  24. @GetMapping(value = {"/list", "/list/{paymentType}"}) //paymentType会传至finPayment.paymentType
  25. public Result<?> queryPageList(FinPayment finPayment,
  26. @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
  27. @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
  28. HttpServletRequest req) {
  29. QueryWrapper<FinPayment> queryWrapper = QueryGenerator.initQueryWrapper(finPayment, req.getParameterMap());
  30. Page<FinPayment> page = new Page<FinPayment>(pageNo, pageSize);
  31. IPage<FinPayment> pageList = finPaymentService.page(page, queryWrapper);
  32. return Result.ok(pageList);
  33. }
  34. @GetMapping(value = "/checkableList")
  35. public Result<?> queryCheckablePageList(FinPayment finPayment,
  36. @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
  37. @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
  38. HttpServletRequest req) {
  39. QueryWrapper<FinPayment> queryWrapper = QueryGenerator.initQueryWrapper(finPayment, req.getParameterMap());
  40. List<String> list = new ArrayList<String>();
  41. list.add("23");
  42. list.add("31");
  43. list.add("32");
  44. queryWrapper.in("bill_proc_Status", list);
  45. queryWrapper.eq("is_approved", 1);
  46. queryWrapper.eq("is_closed", 0);
  47. queryWrapper.eq("is_voided", 0);
  48. queryWrapper.apply("amt - deducted_amt - checked_amt > 0");
  49. Page<FinPayment> page = new Page<FinPayment>(pageNo, pageSize);
  50. IPage<FinPayment> pageList = finPaymentService.page(page, queryWrapper);
  51. return Result.ok(pageList);
  52. }
  53. /**
  54. * 添加
  55. *
  56. * @param finPaymentPage
  57. * @return
  58. */
  59. @AutoLog(value = "付款单-添加")
  60. @ApiOperation(value="付款单-添加", notes="付款单-添加")
  61. @PostMapping(value = "/add")
  62. public Result<?> add(@RequestBody FinPaymentPage finPaymentPage) {
  63. FinPayment finPayment = new FinPayment();
  64. BeanUtils.copyProperties(finPaymentPage, finPayment);
  65. finPaymentService.saveMain(finPayment, finPaymentPage.getFinPaymentEntryList());
  66. return Result.ok("添加成功!");
  67. }
  68. /**
  69. * 编辑
  70. *
  71. * @param finPaymentPage
  72. * @return
  73. */
  74. @AutoLog(value = "付款单-编辑")
  75. @ApiOperation(value="付款单-编辑", notes="付款单-编辑")
  76. @PutMapping(value = "/edit")
  77. public Result<?> edit(@RequestBody FinPaymentPage finPaymentPage) {
  78. FinPayment finPayment = new FinPayment();
  79. BeanUtils.copyProperties(finPaymentPage, finPayment);
  80. FinPayment finPaymentEntity = finPaymentService.getById(finPayment.getId());
  81. if(finPaymentEntity==null) {
  82. return Result.error("未找到对应数据");
  83. }
  84. finPaymentService.updateMain(finPayment, finPaymentPage.getFinPaymentEntryList());
  85. return Result.ok("编辑成功!");
  86. }
  87. /**
  88. * 通过id删除
  89. *
  90. * @param id
  91. * @return
  92. */
  93. @AutoLog(value = "付款单-通过id删除")
  94. @ApiOperation(value="付款单-通过id删除", notes="付款单-通过id删除")
  95. @DeleteMapping(value = "/delete")
  96. public Result<?> delete(@RequestParam(name="id",required=true) String id) {
  97. finPaymentService.delMain(id);
  98. return Result.ok("删除成功!");
  99. }
  100. /**
  101. * 批量删除
  102. *
  103. * @param ids
  104. * @return
  105. */
  106. @AutoLog(value = "付款单-批量删除")
  107. @ApiOperation(value="付款单-批量删除", notes="付款单-批量删除")
  108. @DeleteMapping(value = "/deleteBatch")
  109. public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
  110. this.finPaymentService.delBatchMain(Arrays.asList(ids.split(",")));
  111. return Result.ok("批量删除成功!");
  112. }
  113. /**
  114. * 通过id查询
  115. *
  116. * @param id
  117. * @return
  118. */
  119. @AutoLog(value = "付款单-通过id查询")
  120. @ApiOperation(value="付款单-通过id查询", notes="付款单-通过id查询")
  121. @GetMapping(value = "/queryById")
  122. public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
  123. FinPayment finPayment = finPaymentService.getById(id);
  124. if(finPayment==null) {
  125. return Result.error("未找到对应数据");
  126. }
  127. return Result.ok(finPayment);
  128. }
  129. /**
  130. * 通过id查询
  131. *
  132. * @param id
  133. * @return
  134. */
  135. @AutoLog(value = "付款明细集合-通过id查询")
  136. @ApiOperation(value="付款明细集合-通过id查询", notes="付款明细-通过id查询")
  137. @GetMapping(value = "/queryFinPaymentEntryByMainId")
  138. public Result<?> queryFinPaymentEntryListByMainId(@RequestParam(name="id",required=true) String id) {
  139. List<FinPaymentEntry> finPaymentEntryList = finPaymentEntryService.selectByMainId(id);
  140. return Result.ok(finPaymentEntryList);
  141. }
  142. /**
  143. * 导出excel
  144. *
  145. * @param request
  146. * @param finPayment
  147. */
  148. @RequestMapping(value = {"/exportXls", "/exportXls/{paymentType}"})
  149. public ModelAndView exportXls(HttpServletRequest request, FinPayment finPayment) {
  150. // Step.1 组装查询条件查询数据
  151. QueryWrapper<FinPayment> queryWrapper = QueryGenerator.initQueryWrapper(finPayment, request.getParameterMap());
  152. LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
  153. //Step.2 获取导出数据
  154. List<FinPayment> queryList = finPaymentService.list(queryWrapper);
  155. // 过滤选中数据
  156. String selections = request.getParameter("selections");
  157. List<FinPayment> finPaymentList = new ArrayList<FinPayment>();
  158. if(oConvertUtils.isEmpty(selections)) {
  159. finPaymentList = queryList;
  160. }else {
  161. List<String> selectionList = Arrays.asList(selections.split(","));
  162. finPaymentList = queryList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
  163. }
  164. // Step.3 组装pageList
  165. List<FinPaymentPage> pageList = new ArrayList<FinPaymentPage>();
  166. for (FinPayment main : finPaymentList) {
  167. FinPaymentPage vo = new FinPaymentPage();
  168. BeanUtils.copyProperties(main, vo);
  169. List<FinPaymentEntry> finPaymentEntryList = finPaymentEntryService.selectByMainId(main.getId());
  170. vo.setFinPaymentEntryList(finPaymentEntryList);
  171. pageList.add(vo);
  172. }
  173. // Step.4 AutoPoi 导出Excel
  174. ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
  175. mv.addObject(NormalExcelConstants.FILE_NAME, "付款单列表");
  176. mv.addObject(NormalExcelConstants.CLASS, FinPaymentPage.class);
  177. mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("付款单数据", "导出人:"+sysUser.getRealname(), "付款单"));
  178. mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
  179. return mv;
  180. }
  181. /**
  182. * 通过excel导入数据
  183. *
  184. * @param request
  185. * @param response
  186. * @return
  187. */
  188. @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  189. public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
  190. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  191. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  192. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  193. MultipartFile file = entity.getValue();// 获取上传文件对象
  194. ImportParams params = new ImportParams();
  195. params.setTitleRows(2);
  196. params.setHeadRows(1);
  197. params.setNeedSave(true);
  198. try {
  199. List<FinPaymentPage> list = ExcelImportUtil.importExcel(file.getInputStream(), FinPaymentPage.class, params);
  200. for (FinPaymentPage page : list) {
  201. FinPayment po = new FinPayment();
  202. BeanUtils.copyProperties(page, po);
  203. finPaymentService.saveMain(po, page.getFinPaymentEntryList());
  204. }
  205. return Result.ok("文件导入成功!数据行数:" + list.size());
  206. } catch (Exception e) {
  207. log.error(e.getMessage(),e);
  208. return Result.error("文件导入失败:"+e.getMessage());
  209. } finally {
  210. try {
  211. file.getInputStream().close();
  212. } catch (IOException e) {
  213. e.printStackTrace();
  214. }
  215. }
  216. }
  217. return Result.ok("文件导入失败!");
  218. }
  219. @AutoLog(value = "付款单-通过id审核")
  220. @ApiOperation(value="付款单-通过id审核", notes="付款单-通过id审核")
  221. @PutMapping(value = "/approve")
  222. public Result<?> approve(@RequestBody JSONObject json) {
  223. finPaymentService.approve(json.getString("id"));
  224. return Result.ok("审核通过!");
  225. }
  226. }

源码获取:博客首页 "资源" 里下载!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/317008
推荐阅读
相关标签
  

闽ICP备14008679号