TTest0818Controller.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. package cn.com.lzt.test.controller;
  2. import cn.com.lzt.test.entity.TTest0818Entity;
  3. import cn.com.lzt.test.service.TTest0818ServiceI;
  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. import com.jeecg.qianbao.util.FormProcUtil;
  64. /**
  65. * @Title: Controller
  66. * @Description: 执行节点监听测试
  67. * @author onlineGenerator
  68. * @date 2017-08-21 17:00:44
  69. * @version V1.0
  70. *
  71. */
  72. @Controller
  73. @RequestMapping("/tTest0818Controller")
  74. public class TTest0818Controller extends BaseController {
  75. /**
  76. * Logger for this class
  77. */
  78. private static final Logger logger = Logger.getLogger(TTest0818Controller.class);
  79. @Autowired
  80. private TTest0818ServiceI tTest0818Service;
  81. @Autowired
  82. private SystemService systemService;
  83. @Autowired
  84. private Validator validator;
  85. /**
  86. * 执行节点监听测试列表 页面跳转
  87. *
  88. * @return
  89. */
  90. @RequestMapping(params = "list")
  91. public ModelAndView list(HttpServletRequest request) {
  92. return new ModelAndView("cn/com/lzt/test/tTest0818List");
  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(TTest0818Entity tTest0818,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  104. CriteriaQuery cq = new CriteriaQuery(TTest0818Entity.class, dataGrid);
  105. //查询条件组装器
  106. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tTest0818, request.getParameterMap());
  107. try{
  108. //自定义追加查询条件
  109. }catch (Exception e) {
  110. throw new BusinessException(e.getMessage());
  111. }
  112. cq.add();
  113. this.tTest0818Service.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(TTest0818Entity tTest0818, HttpServletRequest request) {
  124. String message = null;
  125. AjaxJson j = new AjaxJson();
  126. tTest0818 = systemService.getEntity(TTest0818Entity.class, tTest0818.getId());
  127. message = "执行节点监听测试删除成功";
  128. try{
  129. tTest0818Service.delete(tTest0818);
  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. TTest0818Entity tTest0818 = systemService.getEntity(TTest0818Entity.class,
  153. id
  154. );
  155. tTest0818Service.delete(tTest0818);
  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(TTest0818Entity tTest0818, HttpServletRequest request) {
  175. String message = null;
  176. AjaxJson j = new AjaxJson();
  177. message = "执行节点监听测试添加成功";
  178. try{
  179. tTest0818Service.save(tTest0818);
  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(TTest0818Entity tTest0818, HttpServletRequest request) {
  198. String message = null;
  199. AjaxJson j = new AjaxJson();
  200. message = "执行节点监听测试更新成功";
  201. TTest0818Entity t = tTest0818Service.get(TTest0818Entity.class, tTest0818.getId());
  202. try {
  203. MyBeanUtils.copyBeanNotNull2Bean(tTest0818, t);
  204. tTest0818Service.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(TTest0818Entity tTest0818, HttpServletRequest req) {
  221. if (StringUtil.isNotEmpty(tTest0818.getId())) {
  222. tTest0818 = tTest0818Service.getEntity(TTest0818Entity.class, tTest0818.getId());
  223. req.setAttribute("tTest0818Page", tTest0818);
  224. }
  225. return new ModelAndView("cn/com/lzt/test/tTest0818-add");
  226. }
  227. /**
  228. * 执行节点监听测试编辑页面跳转
  229. *
  230. * @return
  231. */
  232. @RequestMapping(params = "goUpdate")
  233. public ModelAndView goUpdate(TTest0818Entity tTest0818, HttpServletRequest req) {
  234. if (StringUtil.isNotEmpty(tTest0818.getId())) {
  235. tTest0818 = tTest0818Service.getEntity(TTest0818Entity.class, tTest0818.getId());
  236. req.setAttribute("tTest0818Page", tTest0818);
  237. }
  238. if(org.apache.commons.lang.StringUtil.isNotEmpty(req.getParameter("taskId"))){
  239. FormProcUtil.initWorkflowParam(req);
  240. }
  241. req.setAttribute("taskId",(String)req.getParameter("taskId"));
  242. return new ModelAndView("cn/com/lzt/test/tTest0818-update");
  243. }
  244. /**
  245. * 导入功能跳转
  246. *
  247. * @return
  248. */
  249. @RequestMapping(params = "upload")
  250. public ModelAndView upload(HttpServletRequest req) {
  251. req.setAttribute("controller_name","tTest0818Controller");
  252. return new ModelAndView("common/upload/pub_excel_upload");
  253. }
  254. /**
  255. * 导出excel
  256. *
  257. * @param request
  258. * @param response
  259. */
  260. @RequestMapping(params = "exportXls")
  261. public String exportXls(TTest0818Entity tTest0818,HttpServletRequest request,HttpServletResponse response
  262. , DataGrid dataGrid,ModelMap modelMap) {
  263. CriteriaQuery cq = new CriteriaQuery(TTest0818Entity.class, dataGrid);
  264. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tTest0818, request.getParameterMap());
  265. List<TTest0818Entity> tTest0818s = this.tTest0818Service.getListByCriteriaQuery(cq,false);
  266. modelMap.put(NormalExcelConstants.FILE_NAME,"执行节点监听测试");
  267. modelMap.put(NormalExcelConstants.CLASS,TTest0818Entity.class);
  268. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("执行节点监听测试列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  269. "导出信息"));
  270. modelMap.put(NormalExcelConstants.DATA_LIST,tTest0818s);
  271. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  272. }
  273. /**
  274. * 导出excel 使模板
  275. *
  276. * @param request
  277. * @param response
  278. */
  279. @RequestMapping(params = "exportXlsByT")
  280. public String exportXlsByT(TTest0818Entity tTest0818,HttpServletRequest request,HttpServletResponse response
  281. , DataGrid dataGrid,ModelMap modelMap) {
  282. modelMap.put(NormalExcelConstants.FILE_NAME,"执行节点监听测试");
  283. modelMap.put(NormalExcelConstants.CLASS,TTest0818Entity.class);
  284. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("执行节点监听测试列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  285. "导出信息"));
  286. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  287. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  288. }
  289. @SuppressWarnings("unchecked")
  290. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  291. @ResponseBody
  292. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  293. AjaxJson j = new AjaxJson();
  294. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  295. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  296. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  297. MultipartFile file = entity.getValue();// 获取上传文件对象
  298. ImportParams params = new ImportParams();
  299. params.setTitleRows(2);
  300. params.setHeadRows(1);
  301. params.setNeedSave(true);
  302. try {
  303. List<TTest0818Entity> listTTest0818Entitys = ExcelImportUtil.importExcel(file.getInputStream(),TTest0818Entity.class,params);
  304. for (TTest0818Entity tTest0818 : listTTest0818Entitys) {
  305. tTest0818Service.save(tTest0818);
  306. }
  307. j.setMsg("文件导入成功!");
  308. } catch (Exception e) {
  309. j.setMsg("文件导入失败!");
  310. logger.error(ExceptionUtil.getExceptionMessage(e));
  311. }finally{
  312. try {
  313. file.getInputStream().close();
  314. } catch (IOException e) {
  315. e.printStackTrace();
  316. }
  317. }
  318. }
  319. return j;
  320. }
  321. @RequestMapping(method = RequestMethod.GET)
  322. @ResponseBody
  323. public List<TTest0818Entity> list() {
  324. List<TTest0818Entity> listTTest0818s=tTest0818Service.getList(TTest0818Entity.class);
  325. return listTTest0818s;
  326. }
  327. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  328. @ResponseBody
  329. public ResponseEntity<?> get(@PathVariable("id") String id) {
  330. TTest0818Entity task = tTest0818Service.get(TTest0818Entity.class, id);
  331. if (task == null) {
  332. return new ResponseEntity(HttpStatus.NOT_FOUND);
  333. }
  334. return new ResponseEntity(task, HttpStatus.OK);
  335. }
  336. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  337. @ResponseBody
  338. public ResponseEntity<?> create(@RequestBody TTest0818Entity tTest0818, UriComponentsBuilder uriBuilder) {
  339. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  340. Set<ConstraintViolation<TTest0818Entity>> failures = validator.validate(tTest0818);
  341. if (!failures.isEmpty()) {
  342. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  343. }
  344. //保存
  345. try{
  346. tTest0818Service.save(tTest0818);
  347. } catch (Exception e) {
  348. e.printStackTrace();
  349. return new ResponseEntity(HttpStatus.NO_CONTENT);
  350. }
  351. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  352. String id = tTest0818.getId();
  353. URI uri = uriBuilder.path("/rest/tTest0818Controller/" + id).build().toUri();
  354. HttpHeaders headers = new HttpHeaders();
  355. headers.setLocation(uri);
  356. return new ResponseEntity(headers, HttpStatus.CREATED);
  357. }
  358. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  359. public ResponseEntity<?> update(@RequestBody TTest0818Entity tTest0818) {
  360. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  361. Set<ConstraintViolation<TTest0818Entity>> failures = validator.validate(tTest0818);
  362. if (!failures.isEmpty()) {
  363. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  364. }
  365. //保存
  366. try{
  367. tTest0818Service.saveOrUpdate(tTest0818);
  368. } catch (Exception e) {
  369. e.printStackTrace();
  370. return new ResponseEntity(HttpStatus.NO_CONTENT);
  371. }
  372. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  373. return new ResponseEntity(HttpStatus.NO_CONTENT);
  374. }
  375. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  376. @ResponseStatus(HttpStatus.NO_CONTENT)
  377. public void delete(@PathVariable("id") String id) {
  378. tTest0818Service.deleteEntityById(TTest0818Entity.class, id);
  379. }
  380. }