FinanceController.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package lingtao.net.controller;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.apache.commons.lang.StringUtils;
  6. import org.apache.shiro.SecurityUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import org.springframework.web.multipart.MultipartFile;
  13. import com.github.pagehelper.PageHelper;
  14. import com.github.pagehelper.PageInfo;
  15. import lingtao.net.bean.Finance;
  16. import lingtao.net.bean.Msg;
  17. import lingtao.net.bean.SysUser;
  18. import lingtao.net.service.FinanceService;
  19. @Controller
  20. public class FinanceController {
  21. @Autowired
  22. private FinanceService financeService;
  23. // 用户跳转页面
  24. @RequestMapping("/finance/index")
  25. public void index(HttpServletRequest request, HttpServletResponse response) throws Exception {
  26. // return "/finance/finance";
  27. response.sendRedirect(request.getContextPath() + "/views/system/finance/finance.jsp");
  28. }
  29. /**
  30. * 根据条件查询数据
  31. *
  32. */
  33. @ResponseBody
  34. @RequestMapping("/getFinance")
  35. public PageInfo<Finance> getFinance(@RequestParam(value = "page", defaultValue = "1") Integer page,
  36. @RequestParam(value = "limit", defaultValue = "10") Integer limit, Finance finance) {
  37. PageHelper.startPage(page, limit);
  38. List<Finance> financeList = financeService.getFinance(finance);
  39. PageInfo<Finance> pageInfo = new PageInfo<Finance>(financeList);
  40. return pageInfo;
  41. }
  42. /**
  43. * 获取自己上传过的文件名(用于导出文件)
  44. *
  45. * @return
  46. */
  47. @ResponseBody
  48. @RequestMapping("/getAllFilename")
  49. public List<String> getAllFilename() {
  50. SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
  51. List<String> FilenameList = financeService.getAllFilename(user.getRealname());
  52. return FilenameList;
  53. }
  54. /**
  55. * 根据文件名删除自己导入过的文件
  56. *
  57. * @return
  58. */
  59. @ResponseBody
  60. @RequestMapping("/deleteDataByFilename")
  61. public Msg deleteDataByFilename(@RequestParam(value = "filename") String filename) {
  62. SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
  63. return financeService.deleteDataByFilename(filename, user.getRealname());
  64. }
  65. /**
  66. *
  67. * 文件上传
  68. */
  69. @ResponseBody
  70. @RequestMapping(value = "/ajaxUpload_1")
  71. public Msg uploadExcel(@RequestParam("file") MultipartFile file) throws Exception {
  72. synchronized (this) {
  73. return financeService.ajaxUploadExcel(file);
  74. }
  75. }
  76. /**
  77. * 导出
  78. *
  79. * @param response
  80. * @param request
  81. * @param finance
  82. * @throws Exception
  83. */
  84. @RequestMapping("/excel")
  85. public void excel(HttpServletResponse response, Finance finance) throws Exception {
  86. if (StringUtils.isEmpty(finance.getFilename())) {
  87. return;
  88. }
  89. financeService.excel(response, finance);
  90. }
  91. }