ArchivesToiletsController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. package cn.com.lzt.car.archives.controller;
  2. import com.daju.common.util.DataPage;
  3. import com.daju.mix.dao.entity.TBArchivesToilets;
  4. import com.daju.mix.dao.service.impl.TBArchivesToiletsServiceImpl;
  5. import org.apache.log4j.Logger;
  6. import org.jeecgframework.core.common.controller.BaseController;
  7. import org.jeecgframework.core.common.exception.BusinessException;
  8. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  9. import org.jeecgframework.core.common.model.json.AjaxJson;
  10. import org.jeecgframework.core.common.model.json.DataGrid;
  11. import org.jeecgframework.core.constant.Globals;
  12. import org.jeecgframework.core.util.ExceptionUtil;
  13. import org.jeecgframework.core.util.ResourceUtil;
  14. import org.jeecgframework.core.util.StringUtil;
  15. import org.jeecgframework.poi.excel.ExcelImportUtil;
  16. import org.jeecgframework.poi.excel.entity.ExportParams;
  17. import org.jeecgframework.poi.excel.entity.ImportParams;
  18. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  19. import org.jeecgframework.tag.core.easyui.TagUtil;
  20. import org.jeecgframework.web.system.service.SystemService;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Controller;
  23. import org.springframework.ui.ModelMap;
  24. import org.springframework.web.bind.annotation.RequestMapping;
  25. import org.springframework.web.bind.annotation.RequestMethod;
  26. import org.springframework.web.bind.annotation.ResponseBody;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import org.springframework.web.multipart.MultipartHttpServletRequest;
  29. import org.springframework.web.servlet.ModelAndView;
  30. import javax.annotation.Resource;
  31. import javax.servlet.http.HttpServletRequest;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.io.IOException;
  34. import java.util.ArrayList;
  35. import java.util.HashMap;
  36. import java.util.List;
  37. import java.util.Map;
  38. /**
  39. * @author onlineGenerator
  40. * @version V1.0
  41. * @Title: Controller
  42. * @Description: 公厕档案管理
  43. * @date 2019-10-12 14:09:46
  44. */
  45. @Controller
  46. @RequestMapping("/archivesToiletsController")
  47. public class ArchivesToiletsController extends BaseController {
  48. /**
  49. * Logger for this class
  50. */
  51. private static final Logger logger = Logger.getLogger(ArchivesToiletsController.class);
  52. private String bestXmlPath= "cn/com/lzt/car/archives/";
  53. @Resource
  54. private TBArchivesToiletsServiceImpl tbArchivesToiletsService;
  55. @Autowired
  56. private SystemService systemService;
  57. /**
  58. * 公厕档案管理列表 页面跳转
  59. *
  60. * @return
  61. */
  62. @RequestMapping(params = "list")
  63. public ModelAndView list(HttpServletRequest request) {
  64. return new ModelAndView(bestXmlPath+"archivesToiletsList");
  65. }
  66. /**
  67. * 公厕档案新增页面跳转
  68. *
  69. * @return
  70. */
  71. @RequestMapping(params = "goAddOrUpdate")
  72. public ModelAndView goAdd(TBArchivesToilets archivesToilets, HttpServletRequest req) {
  73. if (StringUtil.isNotEmpty(archivesToilets.getId())) {
  74. archivesToilets = tbArchivesToiletsService.getById(archivesToilets.getId());
  75. req.setAttribute("archivesToilets", archivesToilets);
  76. return new ModelAndView(bestXmlPath+"archivesToilets-update");
  77. }
  78. return new ModelAndView(bestXmlPath+"archivesToilets-add");
  79. }
  80. /**
  81. * easyui AJAX请求数据
  82. *
  83. * @param request
  84. * @param response
  85. * @param dataGrid
  86. * @param archivesToilets
  87. */
  88. @RequestMapping(params = "datagrid")
  89. public void datagrid(TBArchivesToilets archivesToilets, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  90. DataPage<TBArchivesToilets> page = tbArchivesToiletsService.queryPageList(archivesToilets,dataGrid);
  91. TagUtil.datagrid(response, dataGrid, page);
  92. }
  93. /**
  94. * 添加公厕档案管理
  95. *
  96. * @param archivesToilets
  97. * @return
  98. */
  99. @RequestMapping(params = "doAdd")
  100. @ResponseBody
  101. public AjaxJson doAdd(TBArchivesToilets archivesToilets, HttpServletRequest request) {
  102. String message = null;
  103. AjaxJson j = new AjaxJson();
  104. message = "公厕档案添加成功";
  105. try{
  106. HashMap<String, Object> hashMap = tbArchivesToiletsService.insert(archivesToilets);
  107. j.setAttributes(hashMap);
  108. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  109. }catch(Exception e){
  110. e.printStackTrace();
  111. message = "公厕档案添加失败";
  112. throw new BusinessException(message+e.getMessage());
  113. }
  114. j.setMsg(message);
  115. return j;
  116. }
  117. /**
  118. * 更新公厕档案
  119. *
  120. * @param archivesToilets
  121. * @return
  122. */
  123. @RequestMapping(params = "doUpdate")
  124. @ResponseBody
  125. public AjaxJson doUpdate(TBArchivesToilets archivesToilets, HttpServletRequest request) {
  126. String message = null;
  127. AjaxJson j = new AjaxJson();
  128. message = "公厕档案更新成功";
  129. try {
  130. HashMap<String, Object> map = tbArchivesToiletsService.updataById(archivesToilets);
  131. j.setAttributes(map);
  132. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  133. } catch (Exception e) {
  134. e.printStackTrace();
  135. message = "公厕档案更新失败";
  136. throw new BusinessException(e.getMessage());
  137. }
  138. j.setMsg(message);
  139. return j;
  140. }
  141. /**
  142. * 删除公厕档案
  143. *
  144. * @return
  145. */
  146. @RequestMapping(params = "doDel")
  147. @ResponseBody
  148. public AjaxJson doDel(String id, HttpServletRequest request) {
  149. String message = null;
  150. AjaxJson j = new AjaxJson();
  151. message = "公厕档案删除成功";
  152. try{
  153. HashMap<String, Object> map = tbArchivesToiletsService.delectById(id);
  154. j.setAttributes(map);
  155. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  156. }catch(Exception e){
  157. e.printStackTrace();
  158. message = "公厕档案删除失败";
  159. throw new BusinessException(e.getMessage());
  160. }
  161. j.setMsg(message);
  162. return j;
  163. }
  164. /**
  165. * 批量删除公厕档案
  166. *
  167. * @return
  168. */
  169. @RequestMapping(params = "doBatchDel")
  170. @ResponseBody
  171. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  172. String message = null;
  173. AjaxJson j = new AjaxJson();
  174. message = "公厕档案删除成功";
  175. try{
  176. for(String id:ids.split(",")){
  177. tbArchivesToiletsService.delectById(id);
  178. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  179. }
  180. }catch(Exception e){
  181. e.printStackTrace();
  182. message = "公厕档案删除失败";
  183. throw new BusinessException(e.getMessage());
  184. }
  185. j.setMsg(message);
  186. return j;
  187. }
  188. /**
  189. * 导入功能跳转
  190. *
  191. * @return
  192. */
  193. @RequestMapping(params = "upload")
  194. public ModelAndView upload(HttpServletRequest req) {
  195. req.setAttribute("controller_name","archivesToiletsController");
  196. return new ModelAndView("common/upload/pub_excel_upload");
  197. }
  198. /**
  199. * 导出excel
  200. *
  201. * @param request
  202. * @param response
  203. */
  204. @RequestMapping(params = "exportXls")
  205. public String exportXls(TBArchivesToilets archivesToilets, HttpServletRequest request, HttpServletResponse response
  206. , DataGrid dataGrid, ModelMap modelMap) {
  207. CriteriaQuery cq = new CriteriaQuery(TBArchivesToilets.class, dataGrid);
  208. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, archivesToilets, request.getParameterMap());
  209. List<TBArchivesToilets> archivesToiletsList = this.tbArchivesToiletsService.list();
  210. modelMap.put(NormalExcelConstants.FILE_NAME,"公厕档案");
  211. modelMap.put(NormalExcelConstants.CLASS,TBArchivesToilets.class);
  212. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("公厕档案列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
  213. "导出信息"));
  214. modelMap.put(NormalExcelConstants.DATA_LIST,archivesToiletsList);
  215. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  216. }
  217. /**
  218. * 导出excel 使模板
  219. *
  220. * @param request
  221. * @param response
  222. */
  223. @RequestMapping(params = "exportXlsByT")
  224. public String exportXlsByT(TBArchivesToilets archivesToilets,HttpServletRequest request,HttpServletResponse response
  225. , DataGrid dataGrid,ModelMap modelMap) {
  226. modelMap.put(NormalExcelConstants.FILE_NAME,"公厕档案");
  227. modelMap.put(NormalExcelConstants.CLASS,TBArchivesToilets.class);
  228. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("公厕档案列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  229. "导出信息"));
  230. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  231. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  232. }
  233. @SuppressWarnings("unchecked")
  234. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  235. @ResponseBody
  236. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  237. AjaxJson j = new AjaxJson();
  238. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  239. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  240. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  241. MultipartFile file = entity.getValue();// 获取上传文件对象
  242. ImportParams params = new ImportParams();
  243. params.setTitleRows(2);
  244. params.setHeadRows(1);
  245. params.setNeedSave(true);
  246. try {
  247. List<TBArchivesToilets> tbArchivesToiletsList = ExcelImportUtil.importExcel(file.getInputStream(),TBArchivesToilets.class,params);
  248. for (TBArchivesToilets archivesToilets : tbArchivesToiletsList) {
  249. tbArchivesToiletsService.insert(archivesToilets);
  250. }
  251. j.setMsg("文件导入成功!");
  252. } catch (Exception e) {
  253. j.setMsg("文件导入失败!");
  254. logger.error(ExceptionUtil.getExceptionMessage(e));
  255. }finally{
  256. try {
  257. file.getInputStream().close();
  258. } catch (IOException e) {
  259. e.printStackTrace();
  260. }
  261. }
  262. }
  263. return j;
  264. }
  265. }