package lingtao.net.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lingtao.net.bean.Finance; import lingtao.net.bean.Msg; import lingtao.net.bean.SysUser; import lingtao.net.service.FinanceService; @Controller public class FinanceController { @Autowired private FinanceService financeService; // 用户跳转页面 @RequestMapping("/finance/index") public void index(HttpServletRequest request, HttpServletResponse response) throws Exception { // return "/finance/finance"; response.sendRedirect(request.getContextPath() + "/views/system/finance/finance.jsp"); } /** * 根据条件查询数据 * */ @ResponseBody @RequestMapping("/getFinance") public PageInfo getFinance(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "limit", defaultValue = "10") Integer limit, Finance finance) { PageHelper.startPage(page, limit); List financeList = financeService.getFinance(finance); PageInfo pageInfo = new PageInfo(financeList); return pageInfo; } /** * 获取自己上传过的文件名(用于导出文件) * * @return */ @ResponseBody @RequestMapping("/getAllFilename") public List getAllFilename() { SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal(); List FilenameList = financeService.getAllFilename(user.getRealname()); return FilenameList; } /** * 根据文件名删除自己导入过的文件 * * @return */ @ResponseBody @RequestMapping("/deleteDataByFilename") public Msg deleteDataByFilename(@RequestParam(value = "filename") String filename) { SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal(); return financeService.deleteDataByFilename(filename, user.getRealname()); } /** * * 文件上传 */ @ResponseBody @RequestMapping(value = "/ajaxUpload_1") public Msg uploadExcel(@RequestParam("file") MultipartFile file) throws Exception { synchronized (this) { return financeService.ajaxUploadExcel(file); } } /** * 导出 * * @param response * @param request * @param finance * @throws Exception */ @RequestMapping("/excel") public void excel(HttpServletResponse response, Finance finance) throws Exception { if (StringUtils.isEmpty(finance.getFilename())) { return; } financeService.excel(response, finance); } }