| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- package cn.com.lzt.car.archives.controller;
- import com.daju.common.util.DataPage;
- import com.daju.mix.dao.entity.TBArchivesToilets;
- import com.daju.mix.dao.service.impl.TBArchivesToiletsServiceImpl;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.common.controller.BaseController;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
- import org.jeecgframework.core.common.model.json.AjaxJson;
- import org.jeecgframework.core.common.model.json.DataGrid;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.ExceptionUtil;
- import org.jeecgframework.core.util.ResourceUtil;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.poi.excel.ExcelImportUtil;
- import org.jeecgframework.poi.excel.entity.ExportParams;
- import org.jeecgframework.poi.excel.entity.ImportParams;
- import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
- import org.jeecgframework.tag.core.easyui.TagUtil;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.MultipartHttpServletRequest;
- import org.springframework.web.servlet.ModelAndView;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @author onlineGenerator
- * @version V1.0
- * @Title: Controller
- * @Description: 公厕档案管理
- * @date 2019-10-12 14:09:46
- */
- @Controller
- @RequestMapping("/archivesToiletsController")
- public class ArchivesToiletsController extends BaseController {
- /**
- * Logger for this class
- */
- private static final Logger logger = Logger.getLogger(ArchivesToiletsController.class);
- private String bestXmlPath= "cn/com/lzt/car/archives/";
- @Resource
- private TBArchivesToiletsServiceImpl tbArchivesToiletsService;
- @Autowired
- private SystemService systemService;
- /**
- * 公厕档案管理列表 页面跳转
- *
- * @return
- */
- @RequestMapping(params = "list")
- public ModelAndView list(HttpServletRequest request) {
- return new ModelAndView(bestXmlPath+"archivesToiletsList");
- }
- /**
- * 公厕档案新增页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goAddOrUpdate")
- public ModelAndView goAdd(TBArchivesToilets archivesToilets, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(archivesToilets.getId())) {
- archivesToilets = tbArchivesToiletsService.getById(archivesToilets.getId());
- req.setAttribute("archivesToilets", archivesToilets);
- return new ModelAndView(bestXmlPath+"archivesToilets-update");
- }
- return new ModelAndView(bestXmlPath+"archivesToilets-add");
- }
- /**
- * easyui AJAX请求数据
- *
- * @param request
- * @param response
- * @param dataGrid
- * @param archivesToilets
- */
- @RequestMapping(params = "datagrid")
- public void datagrid(TBArchivesToilets archivesToilets, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- DataPage<TBArchivesToilets> page = tbArchivesToiletsService.queryPageList(archivesToilets,dataGrid);
- TagUtil.datagrid(response, dataGrid, page);
- }
- /**
- * 添加公厕档案管理
- *
- * @param archivesToilets
- * @return
- */
- @RequestMapping(params = "doAdd")
- @ResponseBody
- public AjaxJson doAdd(TBArchivesToilets archivesToilets, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "公厕档案添加成功";
- try{
- HashMap<String, Object> hashMap = tbArchivesToiletsService.insert(archivesToilets);
- j.setAttributes(hashMap);
- systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "公厕档案添加失败";
- throw new BusinessException(message+e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 更新公厕档案
- *
- * @param archivesToilets
- * @return
- */
- @RequestMapping(params = "doUpdate")
- @ResponseBody
- public AjaxJson doUpdate(TBArchivesToilets archivesToilets, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "公厕档案更新成功";
- try {
- HashMap<String, Object> map = tbArchivesToiletsService.updataById(archivesToilets);
- j.setAttributes(map);
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- } catch (Exception e) {
- e.printStackTrace();
- message = "公厕档案更新失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 删除公厕档案
- *
- * @return
- */
- @RequestMapping(params = "doDel")
- @ResponseBody
- public AjaxJson doDel(String id, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "公厕档案删除成功";
- try{
- HashMap<String, Object> map = tbArchivesToiletsService.delectById(id);
- j.setAttributes(map);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "公厕档案删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 批量删除公厕档案
- *
- * @return
- */
- @RequestMapping(params = "doBatchDel")
- @ResponseBody
- public AjaxJson doBatchDel(String ids,HttpServletRequest request){
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "公厕档案删除成功";
- try{
- for(String id:ids.split(",")){
- tbArchivesToiletsService.delectById(id);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }
- }catch(Exception e){
- e.printStackTrace();
- message = "公厕档案删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 导入功能跳转
- *
- * @return
- */
- @RequestMapping(params = "upload")
- public ModelAndView upload(HttpServletRequest req) {
- req.setAttribute("controller_name","archivesToiletsController");
- return new ModelAndView("common/upload/pub_excel_upload");
- }
- /**
- * 导出excel
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "exportXls")
- public String exportXls(TBArchivesToilets archivesToilets, HttpServletRequest request, HttpServletResponse response
- , DataGrid dataGrid, ModelMap modelMap) {
- CriteriaQuery cq = new CriteriaQuery(TBArchivesToilets.class, dataGrid);
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, archivesToilets, request.getParameterMap());
- List<TBArchivesToilets> archivesToiletsList = this.tbArchivesToiletsService.list();
- modelMap.put(NormalExcelConstants.FILE_NAME,"公厕档案");
- modelMap.put(NormalExcelConstants.CLASS,TBArchivesToilets.class);
- modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("公厕档案列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
- "导出信息"));
- modelMap.put(NormalExcelConstants.DATA_LIST,archivesToiletsList);
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
- /**
- * 导出excel 使模板
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "exportXlsByT")
- public String exportXlsByT(TBArchivesToilets archivesToilets,HttpServletRequest request,HttpServletResponse response
- , DataGrid dataGrid,ModelMap modelMap) {
- modelMap.put(NormalExcelConstants.FILE_NAME,"公厕档案");
- modelMap.put(NormalExcelConstants.CLASS,TBArchivesToilets.class);
- modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("公厕档案列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
- "导出信息"));
- modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
- @SuppressWarnings("unchecked")
- @RequestMapping(params = "importExcel", method = RequestMethod.POST)
- @ResponseBody
- public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
- AjaxJson j = new AjaxJson();
- 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<TBArchivesToilets> tbArchivesToiletsList = ExcelImportUtil.importExcel(file.getInputStream(),TBArchivesToilets.class,params);
- for (TBArchivesToilets archivesToilets : tbArchivesToiletsList) {
- tbArchivesToiletsService.insert(archivesToilets);
- }
- j.setMsg("文件导入成功!");
- } catch (Exception e) {
- j.setMsg("文件导入失败!");
- logger.error(ExceptionUtil.getExceptionMessage(e));
- }finally{
- try {
- file.getInputStream().close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return j;
- }
- }
|