PostController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. package cn.com.lzt.post.controller;
  2. import cn.com.lzt.post.entity.PostEntity;
  3. import cn.com.lzt.post.service.PostServiceI;
  4. import org.apache.log4j.Logger;
  5. import org.jeecgframework.core.beanvalidator.BeanValidators;
  6. import org.jeecgframework.core.common.controller.BaseController;
  7. import org.jeecgframework.core.common.dao.jdbc.JdbcDao;
  8. import org.jeecgframework.core.common.exception.BusinessException;
  9. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  10. import org.jeecgframework.core.common.model.json.AjaxJson;
  11. import org.jeecgframework.core.common.model.json.DataGrid;
  12. import org.jeecgframework.core.constant.Globals;
  13. import org.jeecgframework.core.util.*;
  14. import org.jeecgframework.poi.excel.ExcelImportUtil;
  15. import org.jeecgframework.poi.excel.entity.ExportParams;
  16. import org.jeecgframework.poi.excel.entity.ImportParams;
  17. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  18. import org.jeecgframework.tag.core.easyui.TagUtil;
  19. import org.jeecgframework.web.system.service.SystemService;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.http.HttpHeaders;
  22. import org.springframework.http.HttpStatus;
  23. import org.springframework.http.MediaType;
  24. import org.springframework.http.ResponseEntity;
  25. import org.springframework.stereotype.Controller;
  26. import org.springframework.ui.ModelMap;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import org.springframework.web.multipart.MultipartHttpServletRequest;
  30. import org.springframework.web.servlet.ModelAndView;
  31. import org.springframework.web.util.UriComponentsBuilder;
  32. import javax.servlet.http.HttpServletRequest;
  33. import javax.servlet.http.HttpServletResponse;
  34. import javax.validation.ConstraintViolation;
  35. import javax.validation.Validator;
  36. import java.io.IOException;
  37. import java.net.URI;
  38. import java.util.*;
  39. /**
  40. * @Title: Controller
  41. * @Description: 岗位
  42. * @author onlineGenerator
  43. * @date 2017-10-10 17:08:26
  44. * @version V1.0
  45. *
  46. */
  47. @Controller
  48. @RequestMapping("/postController")
  49. public class PostController extends BaseController {
  50. /**
  51. * Logger for this class
  52. */
  53. private static final Logger logger = Logger.getLogger(PostController.class);
  54. @Autowired
  55. private PostServiceI postService;
  56. @Autowired
  57. private SystemService systemService;
  58. @Autowired
  59. private Validator validator;
  60. /**
  61. * 岗位列表 页面跳转
  62. *
  63. * @return
  64. */
  65. @RequestMapping(params = "list")
  66. public ModelAndView list(HttpServletRequest request) {
  67. return new ModelAndView("cn/com/lzt/post/postList");
  68. }
  69. /**
  70. * 岗位列表 页面跳转
  71. *
  72. * @return
  73. */
  74. @RequestMapping(params = "postAllowanceList")
  75. public ModelAndView postAllowanceList(HttpServletRequest request) {
  76. return new ModelAndView("cn/com/lzt/post/postAllowanceList");
  77. }
  78. /**
  79. * easyui AJAX请求数据
  80. *
  81. * @param request
  82. * @param response
  83. * @param dataGrid
  84. * @param user
  85. */
  86. @RequestMapping(params = "datagrid_allow")
  87. public void datagrid_allow(PostEntity post,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  88. CriteriaQuery cq = new CriteriaQuery(PostEntity.class, dataGrid);
  89. if(post.getPostName() != null && !"".equals(post.getPostName().trim())){
  90. post.setPostName("*"+post.getPostName()+"*");
  91. }
  92. if(StringUtil.isEmpty(post.getId())){
  93. cq.isNull("parentPostid");
  94. }else{
  95. cq.eq("parentPostid", post.getId());
  96. post.setId(null);
  97. }
  98. //查询条件组装器
  99. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, post, request.getParameterMap());
  100. try{
  101. //自定义追加查询条件
  102. String[] status = new String[]{Globals.Enabled_Status.toString(), Globals.Disabled_Status.toString()};
  103. cq.in("status", status);
  104. cq.eq("deleteFlag", Globals.Delete_Normal.toString());
  105. Map map = new HashMap();
  106. map.put("createDate", "desc");
  107. cq.setOrder(map);
  108. }catch (Exception e) {
  109. throw new BusinessException(e.getMessage());
  110. }
  111. cq.add();
  112. this.postService.getDataGridReturn(cq, true);
  113. TagUtil.treegrid(response, dataGrid);
  114. }
  115. /**
  116. * easyui AJAX请求数据
  117. *
  118. * @param request
  119. * @param response
  120. * @param dataGrid
  121. * @param user
  122. */
  123. @RequestMapping(params = "datagrid")
  124. public void datagrid(PostEntity post,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  125. CriteriaQuery cq = new CriteriaQuery(PostEntity.class, dataGrid);
  126. if(post.getPostName() != null && !"".equals(post.getPostName().trim())){
  127. post.setPostName("*"+post.getPostName()+"*");
  128. }
  129. if(StringUtil.isEmpty(post.getId())){
  130. cq.isNull("parentPostid");
  131. }else{
  132. cq.eq("parentPostid", post.getId());
  133. post.setId(null);
  134. }
  135. //查询条件组装器
  136. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, post, request.getParameterMap());
  137. try{
  138. //自定义追加查询条件
  139. String[] status = new String[]{Globals.Enabled_Status.toString(), Globals.Disabled_Status.toString()};
  140. cq.in("status", status);
  141. cq.eq("deleteFlag", Globals.Delete_Normal.toString());
  142. Map map = new HashMap();
  143. map.put("createDate", "desc");
  144. cq.setOrder(map);
  145. }catch (Exception e) {
  146. throw new BusinessException(e.getMessage());
  147. }
  148. cq.add();
  149. this.postService.getDataGridReturn(cq, true);
  150. TagUtil.treegrid(response, dataGrid);
  151. }
  152. /**
  153. * 删除岗位
  154. *
  155. * @return
  156. */
  157. @RequestMapping(params = "doDel")
  158. @ResponseBody
  159. public AjaxJson doDel(PostEntity post, HttpServletRequest request) {
  160. String message = null;
  161. AjaxJson j = new AjaxJson();
  162. post = systemService.getEntity(PostEntity.class, post.getId());
  163. message = "岗位删除成功";
  164. try{
  165. postService.delete(post);
  166. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  167. }catch(Exception e){
  168. e.printStackTrace();
  169. message = "岗位删除失败";
  170. throw new BusinessException(e.getMessage());
  171. }
  172. j.setMsg(message);
  173. return j;
  174. }
  175. /**
  176. * 逻辑删除岗位
  177. *
  178. * @return
  179. */
  180. @RequestMapping(params = "logicDel")
  181. @ResponseBody
  182. public AjaxJson logicDel(String id, HttpServletRequest request) {
  183. String message = null;
  184. AjaxJson j = new AjaxJson();
  185. PostEntity post = systemService.getEntity(PostEntity.class, id);
  186. message = "岗位 删除成功";
  187. try{
  188. List<PostEntity> childList = getAllChildrenList(post.getId(), null, null);
  189. childList.add(post);// 加入父节点
  190. for(int i=0; i<childList.size(); i++){
  191. childList.get(i).setDeleteFlag(Globals.Delete_Forbidden.toString());// 设置为1已删除
  192. }
  193. postService.batchUpdate(childList);
  194. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  195. }catch(Exception e){
  196. e.printStackTrace();
  197. message = "岗位 删除失败";
  198. throw new BusinessException(e.getMessage());
  199. }
  200. j.setMsg(message);
  201. return j;
  202. }
  203. /**
  204. * 批量删除岗位
  205. *
  206. * @return
  207. */
  208. @RequestMapping(params = "doBatchDel")
  209. @ResponseBody
  210. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  211. String message = null;
  212. AjaxJson j = new AjaxJson();
  213. message = "岗位删除成功";
  214. try{
  215. for(String id:ids.split(",")){
  216. PostEntity post = systemService.getEntity(PostEntity.class,
  217. id
  218. );
  219. postService.delete(post);
  220. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  221. }
  222. }catch(Exception e){
  223. e.printStackTrace();
  224. message = "岗位删除失败";
  225. throw new BusinessException(e.getMessage());
  226. }
  227. j.setMsg(message);
  228. return j;
  229. }
  230. /**
  231. * 添加岗位
  232. *
  233. * @param ids
  234. * @return
  235. */
  236. @RequestMapping(params = "doAdd")
  237. @ResponseBody
  238. public AjaxJson doAdd(PostEntity post, HttpServletRequest request) {
  239. String message = null;
  240. AjaxJson j = new AjaxJson();
  241. message = "岗位添加成功";
  242. try{
  243. if(StringUtil.isEmpty(post.getParentPostid())){
  244. post.setParentPostid(null);
  245. String localMaxCode = getMaxLocalCode(null);
  246. post.setPostCode(YouBianCodeUtil.getNextYouBianCode(localMaxCode));
  247. }else{
  248. PostEntity entity = postService.findUniqueByProperty(PostEntity.class, "id", post.getParentPostid());
  249. String localMaxCode = getMaxLocalCode(entity.getPostCode());
  250. post.setPostCode(YouBianCodeUtil.getSubYouBianCode(entity.getPostCode(), localMaxCode));
  251. }
  252. post.setStatus(Globals.Enabled_Status.toString());
  253. post.setDeleteFlag(Globals.Delete_Normal.toString());
  254. postService.save(post);
  255. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  256. }catch(Exception e){
  257. e.printStackTrace();
  258. message = "岗位添加失败";
  259. throw new BusinessException(e.getMessage());
  260. }
  261. j.setMsg(message);
  262. return j;
  263. }
  264. /**
  265. * 岗位名称重复校验
  266. *
  267. * @param ids
  268. * @return
  269. */
  270. @RequestMapping(params = "checkPostName")
  271. @ResponseBody
  272. public Map<String,Object> checkPostName(PostEntity post, HttpServletRequest request) {
  273. Boolean flag = postService.findPostByPostName(post);
  274. Map<String,Object> res = new HashMap<String, Object>();
  275. res.put("flag",flag);
  276. return res;
  277. }
  278. /**
  279. * 更新岗位
  280. *
  281. * @param ids
  282. * @return
  283. */
  284. @RequestMapping(params = "doUpdate")
  285. @ResponseBody
  286. public AjaxJson doUpdate(PostEntity post, HttpServletRequest request) {
  287. String message = null;
  288. AjaxJson j = new AjaxJson();
  289. message = "岗位更新成功";
  290. PostEntity t = postService.get(PostEntity.class, post.getId());
  291. try {
  292. MyBeanUtils.copyBeanNotNull2Bean(post, t);
  293. if(StringUtil.isEmpty(t.getParentPostid())){
  294. t.setParentPostid(null);
  295. }
  296. postService.saveOrUpdate(t);
  297. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  298. } catch (Exception e) {
  299. e.printStackTrace();
  300. message = "岗位更新失败";
  301. throw new BusinessException(e.getMessage());
  302. }
  303. j.setMsg(message);
  304. return j;
  305. }
  306. /**
  307. * 岗位新增页面跳转
  308. *
  309. * @return
  310. */
  311. @RequestMapping(params = "goAdd")
  312. public ModelAndView goAdd(PostEntity post, HttpServletRequest req) {
  313. if (StringUtil.isNotEmpty(post.getId())) {
  314. post = postService.getEntity(PostEntity.class, post.getId());
  315. req.setAttribute("postPage", post);
  316. }
  317. return new ModelAndView("cn/com/lzt/post/post-add");
  318. }
  319. /**
  320. * 岗位编辑页面跳转
  321. *
  322. * @return
  323. */
  324. @RequestMapping(params = "goUpdate")
  325. public ModelAndView goUpdate(PostEntity post, HttpServletRequest req) {
  326. if (StringUtil.isNotEmpty(post.getId())) {
  327. post = postService.getEntity(PostEntity.class, post.getId());
  328. if(post!=null && post.getParentPostid()!=null){
  329. PostEntity parentPost = postService.getEntity(PostEntity.class, post.getParentPostid());
  330. post.setParentPost(parentPost);
  331. }
  332. req.setAttribute("postPage", post);
  333. }
  334. return new ModelAndView("cn/com/lzt/post/post-update");
  335. }
  336. /**
  337. * 岗位编辑页面跳转
  338. *
  339. * @return
  340. */
  341. @RequestMapping(params = "goUpdate_postAllowance")
  342. public ModelAndView goUpdate_postAllowance(PostEntity post, HttpServletRequest req) {
  343. if (StringUtil.isNotEmpty(post.getId())) {
  344. post = postService.getEntity(PostEntity.class, post.getId());
  345. if(post!=null && post.getParentPostid()!=null){
  346. PostEntity parentPost = postService.getEntity(PostEntity.class, post.getParentPostid());
  347. post.setParentPost(parentPost);
  348. }
  349. req.setAttribute("postPage", post);
  350. }
  351. return new ModelAndView("cn/com/lzt/post/post-update-postAllowance");
  352. }
  353. /**
  354. * 导入功能跳转
  355. *
  356. * @return
  357. */
  358. @RequestMapping(params = "upload")
  359. public ModelAndView upload(HttpServletRequest req) {
  360. req.setAttribute("controller_name","postController");
  361. return new ModelAndView("common/upload/pub_excel_upload");
  362. }
  363. /**
  364. * 导出excel
  365. *
  366. * @param request
  367. * @param response
  368. */
  369. @RequestMapping(params = "exportXls")
  370. public String exportXls(PostEntity post,HttpServletRequest request,HttpServletResponse response
  371. , DataGrid dataGrid,ModelMap modelMap) {
  372. CriteriaQuery cq = new CriteriaQuery(PostEntity.class, dataGrid);
  373. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, post, request.getParameterMap());
  374. List<PostEntity> posts = this.postService.getListByCriteriaQuery(cq,false);
  375. modelMap.put(NormalExcelConstants.FILE_NAME,"岗位");
  376. modelMap.put(NormalExcelConstants.CLASS,PostEntity.class);
  377. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("岗位列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  378. "导出信息"));
  379. modelMap.put(NormalExcelConstants.DATA_LIST,posts);
  380. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  381. }
  382. /**
  383. * 导出excel 使模板
  384. *
  385. * @param request
  386. * @param response
  387. */
  388. @RequestMapping(params = "exportXlsByT")
  389. public String exportXlsByT(PostEntity post,HttpServletRequest request,HttpServletResponse response
  390. , DataGrid dataGrid,ModelMap modelMap) {
  391. modelMap.put(NormalExcelConstants.FILE_NAME,"岗位");
  392. modelMap.put(NormalExcelConstants.CLASS,PostEntity.class);
  393. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("岗位列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  394. "导出信息"));
  395. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  396. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  397. }
  398. @SuppressWarnings("unchecked")
  399. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  400. @ResponseBody
  401. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  402. AjaxJson j = new AjaxJson();
  403. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  404. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  405. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  406. MultipartFile file = entity.getValue();// 获取上传文件对象
  407. ImportParams params = new ImportParams();
  408. params.setTitleRows(2);
  409. params.setHeadRows(1);
  410. params.setNeedSave(true);
  411. try {
  412. List<PostEntity> listPostEntitys = ExcelImportUtil.importExcel(file.getInputStream(),PostEntity.class,params);
  413. for (PostEntity post : listPostEntitys) {
  414. postService.save(post);
  415. }
  416. j.setMsg("文件导入成功!");
  417. } catch (Exception e) {
  418. j.setMsg("文件导入失败!");
  419. logger.error(ExceptionUtil.getExceptionMessage(e));
  420. }finally{
  421. try {
  422. file.getInputStream().close();
  423. } catch (IOException e) {
  424. e.printStackTrace();
  425. }
  426. }
  427. }
  428. return j;
  429. }
  430. @RequestMapping(method = RequestMethod.GET)
  431. @ResponseBody
  432. public List<PostEntity> list() {
  433. List<PostEntity> listPosts=postService.getList(PostEntity.class);
  434. return listPosts;
  435. }
  436. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  437. @ResponseBody
  438. public ResponseEntity<?> get(@PathVariable("id") String id) {
  439. PostEntity task = postService.get(PostEntity.class, id);
  440. if (task == null) {
  441. return new ResponseEntity(HttpStatus.NOT_FOUND);
  442. }
  443. return new ResponseEntity(task, HttpStatus.OK);
  444. }
  445. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  446. @ResponseBody
  447. public ResponseEntity<?> create(@RequestBody PostEntity post, UriComponentsBuilder uriBuilder) {
  448. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  449. Set<ConstraintViolation<PostEntity>> failures = validator.validate(post);
  450. if (!failures.isEmpty()) {
  451. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  452. }
  453. //保存
  454. try{
  455. postService.save(post);
  456. } catch (Exception e) {
  457. e.printStackTrace();
  458. return new ResponseEntity(HttpStatus.NO_CONTENT);
  459. }
  460. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  461. String id = post.getId();
  462. URI uri = uriBuilder.path("/rest/postController/" + id).build().toUri();
  463. HttpHeaders headers = new HttpHeaders();
  464. headers.setLocation(uri);
  465. return new ResponseEntity(headers, HttpStatus.CREATED);
  466. }
  467. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  468. public ResponseEntity<?> update(@RequestBody PostEntity post) {
  469. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  470. Set<ConstraintViolation<PostEntity>> failures = validator.validate(post);
  471. if (!failures.isEmpty()) {
  472. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  473. }
  474. //保存
  475. try{
  476. postService.saveOrUpdate(post);
  477. } catch (Exception e) {
  478. e.printStackTrace();
  479. return new ResponseEntity(HttpStatus.NO_CONTENT);
  480. }
  481. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  482. return new ResponseEntity(HttpStatus.NO_CONTENT);
  483. }
  484. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  485. @ResponseStatus(HttpStatus.NO_CONTENT)
  486. public void delete(@PathVariable("id") String id) {
  487. postService.deleteEntityById(PostEntity.class, id);
  488. }
  489. //--------------------------------------------------------------------------------------
  490. /**
  491. * 生成code
  492. * @param parentCode
  493. * @return
  494. */
  495. private synchronized String getMaxLocalCode(String parentCode){
  496. if(oConvertUtils.isEmpty(parentCode)){
  497. parentCode = "";
  498. }
  499. int localCodeLength = parentCode.length() + YouBianCodeUtil.zhanweiLength;
  500. StringBuilder sb = new StringBuilder();
  501. sb.append("SELECT post_code FROM t_bus_post");
  502. if(ResourceUtil.getJdbcUrl().indexOf(JdbcDao.DATABSE_TYPE_SQLSERVER)!=-1){
  503. sb.append(" where LEN(post_code) = ").append(localCodeLength);
  504. }else{
  505. sb.append(" where LENGTH(post_code) = ").append(localCodeLength);
  506. }
  507. if(oConvertUtils.isNotEmpty(parentCode)){
  508. sb.append(" and post_code like '").append(parentCode).append("%'");
  509. }
  510. sb.append(" ORDER BY post_code DESC");
  511. List<Map<String, Object>> objMapList = postService.findForJdbc(sb.toString(), 1, 1);
  512. String returnCode = null;
  513. if(objMapList!=null && objMapList.size()>0){
  514. returnCode = (String)objMapList.get(0).get("post_code");
  515. }
  516. return returnCode;
  517. }
  518. /**
  519. * 启用
  520. *
  521. * @author zhijia.wang
  522. */
  523. @RequestMapping(params = "enable")
  524. @ResponseBody
  525. public AjaxJson enable(String id, HttpServletRequest req) {
  526. AjaxJson j = new AjaxJson();
  527. String message = null;
  528. PostEntity post = postService.getEntity(PostEntity.class, id);
  529. try{
  530. List<PostEntity> childList = getAllParentList(post.getParentPostid(), null, null);
  531. childList.add(post);// 加入父节点
  532. for(int i=0; i<childList.size(); i++){
  533. childList.get(i).setStatus(Globals.Enabled_Status.toString());// 设置为0启用状态
  534. }
  535. postService.batchUpdate(childList);// 执行批量更新
  536. message = "岗位:" + "" + "启用成功!";
  537. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  538. }catch(Exception e){
  539. message = "操作失败!";
  540. }
  541. j.setMsg(message);
  542. return j;
  543. }
  544. /**
  545. * 停用
  546. *
  547. * @author zhijia.wang
  548. */
  549. @RequestMapping(params = "disable")
  550. @ResponseBody
  551. public AjaxJson disable(String id, HttpServletRequest req) {
  552. AjaxJson j = new AjaxJson();
  553. String message = null;
  554. PostEntity post = postService.getEntity(PostEntity.class, id);
  555. try{
  556. List<PostEntity> childList = getAllChildrenList(id, null, null);
  557. childList.add(post);// 加入父节点
  558. for(int i=0; i<childList.size(); i++){
  559. childList.get(i).setStatus(Globals.Disabled_Status.toString());// 设置为1停用状态
  560. }
  561. postService.batchUpdate(childList);
  562. message = "岗位:" + "" + "停用成功!";
  563. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  564. }catch(Exception e){
  565. message = "操作失败!";
  566. }
  567. j.setMsg(message);
  568. return j;
  569. }
  570. /**
  571. * 获取某个父节点下面的所有子节点
  572. *
  573. * @param pid 父ID
  574. * @param entryList 当前节点的所有子节点列表(for循环用)
  575. * @param childList 所有子节点列表
  576. * @return
  577. */
  578. private List<PostEntity> getAllChildrenList(String pid, List<PostEntity> entryList, List<PostEntity> childList) {
  579. if(childList == null){
  580. childList = new ArrayList<PostEntity>();
  581. }
  582. final String hql = "from PostEntity where parentPostid=? ";
  583. entryList = postService.findHql(hql, pid);
  584. for (PostEntity entry : entryList) {
  585. // 遍历出父id等于参数的id,add进子节点集合
  586. if (entry.getParentPostid().equals(pid)) {
  587. // 递归遍历下一级
  588. getAllChildrenList(entry.getId(), entryList, childList);
  589. childList.add(entry);
  590. }
  591. }
  592. return childList;
  593. }
  594. /**
  595. * 获取某个子节点上面的所有父节点
  596. *
  597. * @param childId 父ID
  598. * @param entryList 当前节点的所有父节点列表(for循环用)
  599. * @param childList 所有父节点列表
  600. * @return
  601. */
  602. private List<PostEntity> getAllParentList(String pid, List<PostEntity> entryList, List<PostEntity> parentList) {
  603. if(parentList == null){
  604. parentList = new ArrayList<PostEntity>();
  605. }
  606. final String hql = "from PostEntity where id=? ";
  607. entryList = postService.findHql(hql, pid);
  608. for (PostEntity entry : entryList) {
  609. // 遍历出父id等于参数的id,add进父节点集合
  610. if (entry.getId().equals(pid)) {
  611. // 递归遍历下一级
  612. getAllParentList(entry.getParentPostid(), entryList, parentList);
  613. parentList.add(entry);
  614. }
  615. }
  616. return parentList;
  617. }
  618. }