TBusUserEventController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. package cn.com.lzt.userevent.controller;
  2. import cn.com.lzt.userevent.entity.TBusUserEventEntity;
  3. import cn.com.lzt.userevent.service.TBusUserEventServiceI;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.text.SimpleDateFormat;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import org.apache.log4j.Logger;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.ModelMap;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import org.springframework.web.servlet.ModelAndView;
  16. import org.jeecgframework.core.common.controller.BaseController;
  17. import org.jeecgframework.core.common.exception.BusinessException;
  18. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  19. import org.jeecgframework.core.common.model.common.TreeChildCount;
  20. import org.jeecgframework.core.common.model.json.AjaxJson;
  21. import org.jeecgframework.core.common.model.json.DataGrid;
  22. import org.jeecgframework.core.constant.Globals;
  23. import org.jeecgframework.core.util.StringUtil;
  24. import org.jeecgframework.tag.core.easyui.TagUtil;
  25. import org.jeecgframework.web.system.pojo.base.TSDepart;
  26. import org.jeecgframework.web.system.service.SystemService;
  27. import org.jeecgframework.core.util.MyBeanUtils;
  28. import java.io.OutputStream;
  29. import org.jeecgframework.core.util.BrowserUtils;
  30. import org.jeecgframework.poi.excel.ExcelExportUtil;
  31. import org.jeecgframework.poi.excel.ExcelImportUtil;
  32. import org.jeecgframework.poi.excel.entity.ExportParams;
  33. import org.jeecgframework.poi.excel.entity.ImportParams;
  34. import org.jeecgframework.poi.excel.entity.TemplateExportParams;
  35. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  36. import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
  37. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  38. import org.jeecgframework.core.util.ResourceUtil;
  39. import java.io.IOException;
  40. import org.springframework.web.bind.annotation.RequestMethod;
  41. import org.springframework.web.multipart.MultipartFile;
  42. import org.springframework.web.multipart.MultipartHttpServletRequest;
  43. import java.util.Map;
  44. import java.util.HashMap;
  45. import org.jeecgframework.core.util.ExceptionUtil;
  46. import org.springframework.http.ResponseEntity;
  47. import org.springframework.stereotype.Controller;
  48. import org.springframework.web.bind.annotation.PathVariable;
  49. import org.springframework.web.bind.annotation.RequestBody;
  50. import org.springframework.web.bind.annotation.RequestMapping;
  51. import org.springframework.web.bind.annotation.RequestMethod;
  52. import org.springframework.web.bind.annotation.ResponseBody;
  53. import org.springframework.web.bind.annotation.ResponseStatus;
  54. import org.springframework.http.HttpHeaders;
  55. import org.springframework.http.HttpStatus;
  56. import org.jeecgframework.core.beanvalidator.BeanValidators;
  57. import java.util.Set;
  58. import javax.validation.ConstraintViolation;
  59. import javax.validation.Validator;
  60. import java.net.URI;
  61. import org.springframework.http.MediaType;
  62. import org.springframework.web.util.UriComponentsBuilder;
  63. /**
  64. * @Title: Controller
  65. * @Description: 关键事件表
  66. * @author onlineGenerator
  67. * @date 2019-07-30 10:06:00
  68. * @version V1.0
  69. *
  70. */
  71. @Controller
  72. @RequestMapping("/tBusUserEventController")
  73. public class TBusUserEventController extends BaseController {
  74. /**
  75. * Logger for this class
  76. */
  77. private static final Logger logger = Logger.getLogger(TBusUserEventController.class);
  78. @Autowired
  79. private TBusUserEventServiceI tBusUserEventService;
  80. @Autowired
  81. private SystemService systemService;
  82. @Autowired
  83. private Validator validator;
  84. /**
  85. * 关键事件表列表 页面跳转
  86. *
  87. * @return
  88. */
  89. @RequestMapping(params = "list")
  90. public ModelAndView list(String userId,HttpServletRequest request) {
  91. request.setAttribute("userId", userId);
  92. return new ModelAndView("cn/com/lzt/userevent/tBusUserEventList");
  93. }
  94. /**
  95. * easyui AJAX请求数据
  96. *
  97. * @param request
  98. * @param response
  99. * @param dataGrid
  100. * @param user
  101. */
  102. @RequestMapping(params = "datagrid")
  103. public void datagrid(TBusUserEventEntity tBusUserEvent,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  104. CriteriaQuery cq = new CriteriaQuery(TBusUserEventEntity.class, dataGrid);
  105. //查询条件组装器
  106. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBusUserEvent, request.getParameterMap());
  107. try{
  108. //自定义追加查询条件
  109. }catch (Exception e) {
  110. throw new BusinessException(e.getMessage());
  111. }
  112. cq.add();
  113. this.tBusUserEventService.getDataGridReturn(cq, true);
  114. TagUtil.datagrid(response, dataGrid);
  115. }
  116. /**
  117. * 删除关键事件表
  118. *
  119. * @return
  120. */
  121. @RequestMapping(params = "doDel")
  122. @ResponseBody
  123. public AjaxJson doDel(TBusUserEventEntity tBusUserEvent, HttpServletRequest request) {
  124. String message = null;
  125. AjaxJson j = new AjaxJson();
  126. tBusUserEvent = systemService.getEntity(TBusUserEventEntity.class, tBusUserEvent.getId());
  127. message = "关键事件表删除成功";
  128. try{
  129. tBusUserEventService.delete(tBusUserEvent);
  130. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  131. }catch(Exception e){
  132. e.printStackTrace();
  133. message = "关键事件表删除失败";
  134. throw new BusinessException(e.getMessage());
  135. }
  136. j.setMsg(message);
  137. return j;
  138. }
  139. /**
  140. * 批量删除关键事件表
  141. *
  142. * @return
  143. */
  144. @RequestMapping(params = "doBatchDel")
  145. @ResponseBody
  146. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  147. String message = null;
  148. AjaxJson j = new AjaxJson();
  149. message = "关键事件表删除成功";
  150. try{
  151. for(String id:ids.split(",")){
  152. TBusUserEventEntity tBusUserEvent = systemService.getEntity(TBusUserEventEntity.class,
  153. id
  154. );
  155. tBusUserEventService.delete(tBusUserEvent);
  156. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  157. }
  158. }catch(Exception e){
  159. e.printStackTrace();
  160. message = "关键事件表删除失败";
  161. throw new BusinessException(e.getMessage());
  162. }
  163. j.setMsg(message);
  164. return j;
  165. }
  166. /**
  167. * 添加关键事件表
  168. *
  169. * @param ids
  170. * @return
  171. */
  172. @RequestMapping(params = "doAdd")
  173. @ResponseBody
  174. public AjaxJson doAdd(TBusUserEventEntity tBusUserEvent, HttpServletRequest request) {
  175. String message = null;
  176. AjaxJson j = new AjaxJson();
  177. message = "关键事件表添加成功";
  178. try{
  179. tBusUserEventService.save(tBusUserEvent);
  180. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  181. }catch(Exception e){
  182. e.printStackTrace();
  183. message = "关键事件表添加失败";
  184. throw new BusinessException(e.getMessage());
  185. }
  186. j.setMsg(message);
  187. return j;
  188. }
  189. /**
  190. * 更新关键事件表
  191. *
  192. * @param ids
  193. * @return
  194. */
  195. @RequestMapping(params = "doUpdate")
  196. @ResponseBody
  197. public AjaxJson doUpdate(TBusUserEventEntity tBusUserEvent, HttpServletRequest request) {
  198. String message = null;
  199. AjaxJson j = new AjaxJson();
  200. message = "关键事件表更新成功";
  201. TBusUserEventEntity t = tBusUserEventService.get(TBusUserEventEntity.class, tBusUserEvent.getId());
  202. try {
  203. MyBeanUtils.copyBeanNotNull2Bean(tBusUserEvent, t);
  204. tBusUserEventService.saveOrUpdate(t);
  205. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  206. } catch (Exception e) {
  207. e.printStackTrace();
  208. message = "关键事件表更新失败";
  209. throw new BusinessException(e.getMessage());
  210. }
  211. j.setMsg(message);
  212. return j;
  213. }
  214. /**
  215. * 关键事件表新增页面跳转
  216. *
  217. * @return
  218. */
  219. @RequestMapping(params = "goAdd")
  220. public ModelAndView goAdd(TBusUserEventEntity tBusUserEvent, String userId, HttpServletRequest req) {
  221. req.setAttribute("userId", userId);
  222. if (StringUtil.isNotEmpty(tBusUserEvent.getId())) {
  223. tBusUserEvent = tBusUserEventService.getEntity(TBusUserEventEntity.class, tBusUserEvent.getId());
  224. req.setAttribute("tBusUserEventPage", tBusUserEvent);
  225. }
  226. return new ModelAndView("cn/com/lzt/userevent/tBusUserEvent-add");
  227. }
  228. /**
  229. * 关键事件表编辑页面跳转
  230. *
  231. * @return
  232. */
  233. @RequestMapping(params = "goUpdate")
  234. public ModelAndView goUpdate(TBusUserEventEntity tBusUserEvent, HttpServletRequest req) {
  235. if (StringUtil.isNotEmpty(tBusUserEvent.getId())) {
  236. tBusUserEvent = tBusUserEventService.getEntity(TBusUserEventEntity.class, tBusUserEvent.getId());
  237. req.setAttribute("tBusUserEventPage", tBusUserEvent);
  238. }
  239. return new ModelAndView("cn/com/lzt/userevent/tBusUserEvent-update");
  240. }
  241. /**
  242. * 导入功能跳转
  243. *
  244. * @return
  245. */
  246. @RequestMapping(params = "upload")
  247. public ModelAndView upload(HttpServletRequest req) {
  248. req.setAttribute("controller_name","tBusUserEventController");
  249. return new ModelAndView("common/upload/pub_excel_upload");
  250. }
  251. /**
  252. * 导出excel
  253. *
  254. * @param request
  255. * @param response
  256. */
  257. @RequestMapping(params = "exportXls")
  258. public String exportXls(TBusUserEventEntity tBusUserEvent,HttpServletRequest request,HttpServletResponse response
  259. , DataGrid dataGrid,ModelMap modelMap) {
  260. CriteriaQuery cq = new CriteriaQuery(TBusUserEventEntity.class, dataGrid);
  261. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBusUserEvent, request.getParameterMap());
  262. List<TBusUserEventEntity> tBusUserEvents = this.tBusUserEventService.getListByCriteriaQuery(cq,false);
  263. modelMap.put(NormalExcelConstants.FILE_NAME,"关键事件表");
  264. modelMap.put(NormalExcelConstants.CLASS,TBusUserEventEntity.class);
  265. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("关键事件表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  266. "导出信息"));
  267. modelMap.put(NormalExcelConstants.DATA_LIST,tBusUserEvents);
  268. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  269. }
  270. /**
  271. * 导出excel 使模板
  272. *
  273. * @param request
  274. * @param response
  275. */
  276. @RequestMapping(params = "exportXlsByT")
  277. public String exportXlsByT(TBusUserEventEntity tBusUserEvent,HttpServletRequest request,HttpServletResponse response
  278. , DataGrid dataGrid,ModelMap modelMap) {
  279. modelMap.put(NormalExcelConstants.FILE_NAME,"关键事件表");
  280. modelMap.put(NormalExcelConstants.CLASS,TBusUserEventEntity.class);
  281. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("关键事件表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  282. "导出信息"));
  283. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  284. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  285. }
  286. @SuppressWarnings("unchecked")
  287. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  288. @ResponseBody
  289. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  290. AjaxJson j = new AjaxJson();
  291. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  292. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  293. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  294. MultipartFile file = entity.getValue();// 获取上传文件对象
  295. ImportParams params = new ImportParams();
  296. params.setTitleRows(2);
  297. params.setHeadRows(1);
  298. params.setNeedSave(true);
  299. try {
  300. List<TBusUserEventEntity> listTBusUserEventEntitys = ExcelImportUtil.importExcel(file.getInputStream(),TBusUserEventEntity.class,params);
  301. for (TBusUserEventEntity tBusUserEvent : listTBusUserEventEntitys) {
  302. tBusUserEventService.save(tBusUserEvent);
  303. }
  304. j.setMsg("文件导入成功!");
  305. } catch (Exception e) {
  306. j.setMsg("文件导入失败!");
  307. logger.error(ExceptionUtil.getExceptionMessage(e));
  308. }finally{
  309. try {
  310. file.getInputStream().close();
  311. } catch (IOException e) {
  312. e.printStackTrace();
  313. }
  314. }
  315. }
  316. return j;
  317. }
  318. @RequestMapping(method = RequestMethod.GET)
  319. @ResponseBody
  320. public List<TBusUserEventEntity> list() {
  321. List<TBusUserEventEntity> listTBusUserEvents=tBusUserEventService.getList(TBusUserEventEntity.class);
  322. return listTBusUserEvents;
  323. }
  324. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  325. @ResponseBody
  326. public ResponseEntity<?> get(@PathVariable("id") String id) {
  327. TBusUserEventEntity task = tBusUserEventService.get(TBusUserEventEntity.class, id);
  328. if (task == null) {
  329. return new ResponseEntity(HttpStatus.NOT_FOUND);
  330. }
  331. return new ResponseEntity(task, HttpStatus.OK);
  332. }
  333. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  334. @ResponseBody
  335. public ResponseEntity<?> create(@RequestBody TBusUserEventEntity tBusUserEvent, UriComponentsBuilder uriBuilder) {
  336. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  337. Set<ConstraintViolation<TBusUserEventEntity>> failures = validator.validate(tBusUserEvent);
  338. if (!failures.isEmpty()) {
  339. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  340. }
  341. //保存
  342. try{
  343. tBusUserEventService.save(tBusUserEvent);
  344. } catch (Exception e) {
  345. e.printStackTrace();
  346. return new ResponseEntity(HttpStatus.NO_CONTENT);
  347. }
  348. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  349. String id = tBusUserEvent.getId();
  350. URI uri = uriBuilder.path("/rest/tBusUserEventController/" + id).build().toUri();
  351. HttpHeaders headers = new HttpHeaders();
  352. headers.setLocation(uri);
  353. return new ResponseEntity(headers, HttpStatus.CREATED);
  354. }
  355. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  356. public ResponseEntity<?> update(@RequestBody TBusUserEventEntity tBusUserEvent) {
  357. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  358. Set<ConstraintViolation<TBusUserEventEntity>> failures = validator.validate(tBusUserEvent);
  359. if (!failures.isEmpty()) {
  360. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  361. }
  362. //保存
  363. try{
  364. tBusUserEventService.saveOrUpdate(tBusUserEvent);
  365. } catch (Exception e) {
  366. e.printStackTrace();
  367. return new ResponseEntity(HttpStatus.NO_CONTENT);
  368. }
  369. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  370. return new ResponseEntity(HttpStatus.NO_CONTENT);
  371. }
  372. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  373. @ResponseStatus(HttpStatus.NO_CONTENT)
  374. public void delete(@PathVariable("id") String id) {
  375. tBusUserEventService.deleteEntityById(TBusUserEventEntity.class, id);
  376. }
  377. }