ArchivesDustBinController.java 10 KB

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