UserChangesLogController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. package cn.com.lzt.userchangeslog.controller;
  2. import java.io.IOException;
  3. import java.net.URI;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.Set;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import javax.validation.ConstraintViolation;
  13. import javax.validation.Validator;
  14. import org.apache.commons.lang.xwork.StringUtils;
  15. import org.apache.log4j.Logger;
  16. import org.jeecgframework.core.beanvalidator.BeanValidators;
  17. import org.jeecgframework.core.common.controller.BaseController;
  18. import org.jeecgframework.core.common.exception.BusinessException;
  19. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  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.ExceptionUtil;
  24. import org.jeecgframework.core.util.MyBeanUtils;
  25. import org.jeecgframework.core.util.ResourceUtil;
  26. import org.jeecgframework.core.util.StringUtil;
  27. import org.jeecgframework.poi.excel.ExcelImportUtil;
  28. import org.jeecgframework.poi.excel.entity.ExportParams;
  29. import org.jeecgframework.poi.excel.entity.ImportParams;
  30. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  31. import org.jeecgframework.tag.core.easyui.TagUtil;
  32. import org.jeecgframework.web.system.pojo.base.TSDepart;
  33. import org.jeecgframework.web.system.service.SystemService;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.http.HttpHeaders;
  36. import org.springframework.http.HttpStatus;
  37. import org.springframework.http.MediaType;
  38. import org.springframework.http.ResponseEntity;
  39. import org.springframework.stereotype.Controller;
  40. import org.springframework.ui.ModelMap;
  41. import org.springframework.util.CollectionUtils;
  42. import org.springframework.web.bind.annotation.PathVariable;
  43. import org.springframework.web.bind.annotation.RequestBody;
  44. import org.springframework.web.bind.annotation.RequestMapping;
  45. import org.springframework.web.bind.annotation.RequestMethod;
  46. import org.springframework.web.bind.annotation.ResponseBody;
  47. import org.springframework.web.bind.annotation.ResponseStatus;
  48. import org.springframework.web.multipart.MultipartFile;
  49. import org.springframework.web.multipart.MultipartHttpServletRequest;
  50. import org.springframework.web.servlet.ModelAndView;
  51. import org.springframework.web.util.UriComponentsBuilder;
  52. import cn.com.lzt.leave.service.ModifyServiceI;
  53. import cn.com.lzt.userchangeslog.dao.UserChangeLogMinidaoDao;
  54. import cn.com.lzt.userchangeslog.dto.UserChangesLogDto;
  55. import cn.com.lzt.userchangeslog.entity.UserChangesLogEntity;
  56. import cn.com.lzt.userchangeslog.service.UserChangesLogServiceI;
  57. /**
  58. * @Title: Controller
  59. * @Description: 员工人事变动记录
  60. * @author onlineGenerator
  61. * @date 2017-11-10 11:55:30
  62. * @version V1.0
  63. *
  64. */
  65. @Controller
  66. @RequestMapping("/userChangesLogController")
  67. public class UserChangesLogController extends BaseController {
  68. /**
  69. * Logger for this class
  70. */
  71. private static final Logger logger = Logger.getLogger(UserChangesLogController.class);
  72. @Autowired
  73. private UserChangesLogServiceI userChangesLogService;
  74. @Autowired
  75. private SystemService systemService;
  76. @Autowired
  77. private ModifyServiceI modifyService;
  78. @Autowired
  79. private Validator validator;
  80. @Autowired
  81. private UserChangeLogMinidaoDao userChangeLogMinidaoDao;
  82. /**
  83. * 员工人事变动记录列表 页面跳转
  84. *
  85. * @return
  86. */
  87. @RequestMapping(params = "list")
  88. public ModelAndView list(HttpServletRequest request) {
  89. return new ModelAndView("cn/com/lzt/userchangeslog/userChangesLogList");
  90. }
  91. /**
  92. * easyui AJAX请求数据
  93. *
  94. * @param request
  95. * @param response
  96. * @param dataGrid
  97. * @param user
  98. */
  99. @RequestMapping(params = "datagrid")
  100. public void datagrid(UserChangesLogEntity userChangesLog,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  101. CriteriaQuery cq = new CriteriaQuery(UserChangesLogEntity.class, dataGrid);
  102. // 组装模糊查询条件
  103. if(!StringUtil.isEmpty(userChangesLog.getUserName())){
  104. userChangesLog.setUserName("*" + userChangesLog.getUserName() + "*");
  105. }
  106. String changeTime_begin = request.getParameter("changeTime_begin");
  107. String changeTime_end = request.getParameter("changeTime_end");
  108. String orgIds = request.getParameter("orgIds");
  109. List<String> orgIdList = extractIdListByComma(orgIds);
  110. if (!CollectionUtils.isEmpty(orgIdList)) {
  111. cq.in("belongUnitid", orgIdList.toArray());
  112. }
  113. Map map = new HashMap();
  114. map.put("changeTime", "desc");
  115. cq.setOrder(map);
  116. //查询条件组装器
  117. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, userChangesLog, request.getParameterMap());
  118. try{
  119. //自定义追加查询条件
  120. if(StringUtils.isNotBlank(changeTime_begin) && StringUtils.isNotBlank(changeTime_end)){
  121. cq.ge("changeTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(changeTime_begin + " 00:00:00"));
  122. cq.le("changeTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(changeTime_end + " 23:59:59"));
  123. }
  124. }catch (Exception e) {
  125. throw new BusinessException(e.getMessage());
  126. }
  127. cq.add();
  128. this.userChangesLogService.getDataGridReturn(cq, true);
  129. List<UserChangesLogEntity> objList = dataGrid.getResults();
  130. for(UserChangesLogEntity obj : objList){
  131. obj.setBelongUnitName(modifyService.getByorgId(obj.getBelongUnitid()));
  132. obj.setInUnitName(modifyService.getByorgId(obj.getInUnitid()));
  133. }
  134. TagUtil.datagrid(response, dataGrid);
  135. }
  136. /**
  137. * 设置缴金状态
  138. *
  139. * @return
  140. */
  141. @RequestMapping(params = "setUpPayRemindStatus")
  142. @ResponseBody
  143. public AjaxJson setUpPayRemindStatus(String id, HttpServletRequest request) {
  144. String message = null;
  145. AjaxJson j = new AjaxJson();
  146. UserChangesLogEntity userChangesLog = systemService.getEntity(UserChangesLogEntity.class, id);
  147. // 设置状态为2已缴金
  148. userChangesLog.setPayRemindStatus(Globals.PAY_REMIND_STATUS_2);
  149. message = "缴金状态更新成功";
  150. try{
  151. userChangesLogService.updateEntitie(userChangesLog);
  152. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  153. }catch(Exception e){
  154. e.printStackTrace();
  155. message = "缴金状态更新失败";
  156. throw new BusinessException(e.getMessage());
  157. }
  158. j.setMsg(message);
  159. return j;
  160. }
  161. /**
  162. * 设置停缴状态
  163. *
  164. * @return
  165. */
  166. @RequestMapping(params = "setUpStopPayRemindStatus")
  167. @ResponseBody
  168. public AjaxJson setUpStopPayRemindStatus(String id, HttpServletRequest request) {
  169. String message = null;
  170. AjaxJson j = new AjaxJson();
  171. UserChangesLogEntity userChangesLog = systemService.getEntity(UserChangesLogEntity.class, id);
  172. // 设置状态为3已停缴
  173. userChangesLog.setPayRemindStatus(Globals.PAY_REMIND_STATUS_3);
  174. message = "停缴状态更新成功";
  175. try{
  176. userChangesLogService.updateEntitie(userChangesLog);
  177. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  178. }catch(Exception e){
  179. e.printStackTrace();
  180. message = "停缴状态更新失败";
  181. throw new BusinessException(e.getMessage());
  182. }
  183. j.setMsg(message);
  184. return j;
  185. }
  186. /**
  187. * 删除员工人事变动记录
  188. *
  189. * @return
  190. */
  191. @RequestMapping(params = "doDel")
  192. @ResponseBody
  193. public AjaxJson doDel(UserChangesLogEntity userChangesLog, HttpServletRequest request) {
  194. String message = null;
  195. AjaxJson j = new AjaxJson();
  196. userChangesLog = systemService.getEntity(UserChangesLogEntity.class, userChangesLog.getId());
  197. message = "员工人事变动记录删除成功";
  198. try{
  199. userChangesLogService.delete(userChangesLog);
  200. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  201. }catch(Exception e){
  202. e.printStackTrace();
  203. message = "员工人事变动记录删除失败";
  204. throw new BusinessException(e.getMessage());
  205. }
  206. j.setMsg(message);
  207. return j;
  208. }
  209. /**
  210. * 批量删除员工人事变动记录
  211. *
  212. * @return
  213. */
  214. @RequestMapping(params = "doBatchDel")
  215. @ResponseBody
  216. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  217. String message = null;
  218. AjaxJson j = new AjaxJson();
  219. message = "员工人事变动记录删除成功";
  220. try{
  221. for(String id:ids.split(",")){
  222. UserChangesLogEntity userChangesLog = systemService.getEntity(UserChangesLogEntity.class,
  223. id
  224. );
  225. userChangesLogService.delete(userChangesLog);
  226. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  227. }
  228. }catch(Exception e){
  229. e.printStackTrace();
  230. message = "员工人事变动记录删除失败";
  231. throw new BusinessException(e.getMessage());
  232. }
  233. j.setMsg(message);
  234. return j;
  235. }
  236. /**
  237. * 添加员工人事变动记录
  238. *
  239. * @param ids
  240. * @return
  241. */
  242. @RequestMapping(params = "doAdd")
  243. @ResponseBody
  244. public AjaxJson doAdd(UserChangesLogEntity userChangesLog, HttpServletRequest request) {
  245. String message = null;
  246. AjaxJson j = new AjaxJson();
  247. message = "员工人事变动记录添加成功";
  248. try{
  249. userChangesLogService.save(userChangesLog);
  250. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  251. }catch(Exception e){
  252. e.printStackTrace();
  253. message = "员工人事变动记录添加失败";
  254. throw new BusinessException(e.getMessage());
  255. }
  256. j.setMsg(message);
  257. return j;
  258. }
  259. /**
  260. * 更新员工人事变动记录
  261. *
  262. * @param ids
  263. * @return
  264. */
  265. @RequestMapping(params = "doUpdate")
  266. @ResponseBody
  267. public AjaxJson doUpdate(UserChangesLogEntity userChangesLog, HttpServletRequest request) {
  268. String message = null;
  269. AjaxJson j = new AjaxJson();
  270. message = "员工人事变动记录更新成功";
  271. UserChangesLogEntity t = userChangesLogService.get(UserChangesLogEntity.class, userChangesLog.getId());
  272. try {
  273. MyBeanUtils.copyBeanNotNull2Bean(userChangesLog, t);
  274. userChangesLogService.saveOrUpdate(t);
  275. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  276. } catch (Exception e) {
  277. e.printStackTrace();
  278. message = "员工人事变动记录更新失败";
  279. throw new BusinessException(e.getMessage());
  280. }
  281. j.setMsg(message);
  282. return j;
  283. }
  284. /**
  285. * 员工人事变动记录新增页面跳转
  286. *
  287. * @return
  288. */
  289. @RequestMapping(params = "goAdd")
  290. public ModelAndView goAdd(UserChangesLogEntity userChangesLog, HttpServletRequest req) {
  291. if (StringUtil.isNotEmpty(userChangesLog.getId())) {
  292. userChangesLog = userChangesLogService.getEntity(UserChangesLogEntity.class, userChangesLog.getId());
  293. req.setAttribute("userChangesLogPage", userChangesLog);
  294. }
  295. return new ModelAndView("cn/com/lzt/userchangeslog/userChangesLog-add");
  296. }
  297. /**
  298. * 员工人事变动记录编辑页面跳转
  299. *
  300. * @return
  301. */
  302. @RequestMapping(params = "goUpdate")
  303. public ModelAndView goUpdate(UserChangesLogEntity userChangesLog, HttpServletRequest req) {
  304. if (StringUtil.isNotEmpty(userChangesLog.getId())) {
  305. userChangesLog = userChangesLogService.getEntity(UserChangesLogEntity.class, userChangesLog.getId());
  306. req.setAttribute("userChangesLogPage", userChangesLog);
  307. }
  308. return new ModelAndView("cn/com/lzt/userchangeslog/userChangesLog-update");
  309. }
  310. /**
  311. * 导入功能跳转
  312. *
  313. * @return
  314. */
  315. @RequestMapping(params = "upload")
  316. public ModelAndView upload(HttpServletRequest req) {
  317. req.setAttribute("controller_name","userChangesLogController");
  318. return new ModelAndView("common/upload/pub_excel_upload");
  319. }
  320. /**
  321. * 导出excel
  322. *
  323. * @param request
  324. * @param response
  325. */
  326. @RequestMapping(params = "exportXls")
  327. public String exportXls(UserChangesLogEntity userChangesLog,HttpServletRequest request,HttpServletResponse response
  328. , DataGrid dataGrid,ModelMap modelMap) {
  329. //CriteriaQuery cq = new CriteriaQuery(UserChangesLogEntity.class, dataGrid);
  330. //org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, userChangesLog, request.getParameterMap());
  331. String changeTime_begin = request.getParameter("changeTime_begin");
  332. String changeTime_end = request.getParameter("changeTime_end");
  333. Map<String,Object> params = new HashMap<String, Object>();
  334. params.put("beginTime", StringUtil.isNotEmpty(changeTime_begin) ? changeTime_begin : null);
  335. params.put("endTime", StringUtil.isNotEmpty(changeTime_end) ? changeTime_end : null);
  336. params.put("userCode", StringUtil.isNotEmpty(userChangesLog.getUserCode()) ? userChangesLog.getUserCode() : null);
  337. params.put("changeType", StringUtil.isNotEmpty(userChangesLog.getChangeType()) ? userChangesLog.getChangeType() : null);
  338. params.put("payRemindStatus", StringUtil.isNotEmpty(userChangesLog.getPayRemindStatus()) ? userChangesLog.getPayRemindStatus() : null);
  339. List<UserChangesLogDto> userChangesLogs = userChangeLogMinidaoDao.getListByCriteriaQuery(params);
  340. modelMap.put(NormalExcelConstants.FILE_NAME,"员工人事变动记录");
  341. modelMap.put(NormalExcelConstants.CLASS,UserChangesLogDto.class);
  342. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("员工人事变动记录列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  343. "导出信息"));
  344. modelMap.put(NormalExcelConstants.DATA_LIST,userChangesLogs);
  345. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  346. }
  347. /**
  348. * 导出excel 使模板
  349. *
  350. * @param request
  351. * @param response
  352. */
  353. @RequestMapping(params = "exportXlsByT")
  354. public String exportXlsByT(UserChangesLogEntity userChangesLog,HttpServletRequest request,HttpServletResponse response
  355. , DataGrid dataGrid,ModelMap modelMap) {
  356. modelMap.put(NormalExcelConstants.FILE_NAME,"员工人事变动记录");
  357. modelMap.put(NormalExcelConstants.CLASS,UserChangesLogEntity.class);
  358. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("员工人事变动记录列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  359. "导出信息"));
  360. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  361. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  362. }
  363. @SuppressWarnings("unchecked")
  364. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  365. @ResponseBody
  366. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  367. AjaxJson j = new AjaxJson();
  368. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  369. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  370. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  371. MultipartFile file = entity.getValue();// 获取上传文件对象
  372. ImportParams params = new ImportParams();
  373. params.setTitleRows(2);
  374. params.setHeadRows(1);
  375. params.setNeedSave(true);
  376. try {
  377. List<UserChangesLogEntity> listUserChangesLogEntitys = ExcelImportUtil.importExcel(file.getInputStream(),UserChangesLogEntity.class,params);
  378. for (UserChangesLogEntity userChangesLog : listUserChangesLogEntitys) {
  379. userChangesLogService.save(userChangesLog);
  380. }
  381. j.setMsg("文件导入成功!");
  382. } catch (Exception e) {
  383. j.setMsg("文件导入失败!");
  384. logger.error(ExceptionUtil.getExceptionMessage(e));
  385. }finally{
  386. try {
  387. file.getInputStream().close();
  388. } catch (IOException e) {
  389. e.printStackTrace();
  390. }
  391. }
  392. }
  393. return j;
  394. }
  395. @RequestMapping(method = RequestMethod.GET)
  396. @ResponseBody
  397. public List<UserChangesLogEntity> list() {
  398. List<UserChangesLogEntity> listUserChangesLogs=userChangesLogService.getList(UserChangesLogEntity.class);
  399. return listUserChangesLogs;
  400. }
  401. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  402. @ResponseBody
  403. public ResponseEntity<?> get(@PathVariable("id") String id) {
  404. UserChangesLogEntity task = userChangesLogService.get(UserChangesLogEntity.class, id);
  405. if (task == null) {
  406. return new ResponseEntity(HttpStatus.NOT_FOUND);
  407. }
  408. return new ResponseEntity(task, HttpStatus.OK);
  409. }
  410. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  411. @ResponseBody
  412. public ResponseEntity<?> create(@RequestBody UserChangesLogEntity userChangesLog, UriComponentsBuilder uriBuilder) {
  413. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  414. Set<ConstraintViolation<UserChangesLogEntity>> failures = validator.validate(userChangesLog);
  415. if (!failures.isEmpty()) {
  416. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  417. }
  418. //保存
  419. try{
  420. userChangesLogService.save(userChangesLog);
  421. } catch (Exception e) {
  422. e.printStackTrace();
  423. return new ResponseEntity(HttpStatus.NO_CONTENT);
  424. }
  425. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  426. String id = userChangesLog.getId();
  427. URI uri = uriBuilder.path("/rest/userChangesLogController/" + id).build().toUri();
  428. HttpHeaders headers = new HttpHeaders();
  429. headers.setLocation(uri);
  430. return new ResponseEntity(headers, HttpStatus.CREATED);
  431. }
  432. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  433. public ResponseEntity<?> update(@RequestBody UserChangesLogEntity userChangesLog) {
  434. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  435. Set<ConstraintViolation<UserChangesLogEntity>> failures = validator.validate(userChangesLog);
  436. if (!failures.isEmpty()) {
  437. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  438. }
  439. //保存
  440. try{
  441. userChangesLogService.saveOrUpdate(userChangesLog);
  442. } catch (Exception e) {
  443. e.printStackTrace();
  444. return new ResponseEntity(HttpStatus.NO_CONTENT);
  445. }
  446. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  447. return new ResponseEntity(HttpStatus.NO_CONTENT);
  448. }
  449. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  450. @ResponseStatus(HttpStatus.NO_CONTENT)
  451. public void delete(@PathVariable("id") String id) {
  452. userChangesLogService.deleteEntityById(UserChangesLogEntity.class, id);
  453. }
  454. //---------------------------------------------------------------------------------------
  455. /**
  456. * 用户选择机构列表跳转页面
  457. *
  458. * @return
  459. */
  460. @RequestMapping(params = "departSelect")
  461. public String departSelect(HttpServletRequest req) {
  462. req.setAttribute("orgIds", req.getParameter("orgIds"));
  463. return "cn/com/lzt/userchangeslog/departSelect";
  464. }
  465. @RequestMapping(params = "getDepartInfo")
  466. @ResponseBody
  467. public AjaxJson getDepartInfo(HttpServletRequest request, HttpServletResponse response){
  468. AjaxJson j = new AjaxJson();
  469. String orgIds = request.getParameter("orgIds");
  470. String[] ids = new String[]{};
  471. if(StringUtils.isNotBlank(orgIds)){
  472. orgIds = orgIds.substring(0, orgIds.length()-1);
  473. ids = orgIds.split("\\,");
  474. }
  475. String parentid = request.getParameter("parentid");
  476. List<TSDepart> tSDeparts = new ArrayList<TSDepart>();
  477. StringBuffer hql = new StringBuffer(" from TSDepart t where 1=1 ");
  478. if(StringUtils.isNotBlank(parentid)){
  479. TSDepart dePart = this.systemService.getEntity(TSDepart.class, parentid);
  480. hql.append(" and TSPDepart = ?");
  481. tSDeparts = this.systemService.findHql(hql.toString(), dePart);
  482. } else {
  483. hql.append(" and t.orgType = ?");
  484. tSDeparts = this.systemService.findHql(hql.toString(), "1");
  485. }
  486. List<Map<String,Object>> dateList = new ArrayList<Map<String,Object>>();
  487. if(tSDeparts.size()>0){
  488. Map<String,Object> map = null;
  489. String sql = null;
  490. Object[] params = null;
  491. for(TSDepart depart:tSDeparts){
  492. map = new HashMap<String,Object>();
  493. map.put("id", depart.getId());
  494. map.put("name", depart.getDepartname());
  495. if(ids.length>0){
  496. for(String id:ids){
  497. if(id.equals(depart.getId())){
  498. map.put("checked", true);
  499. }
  500. }
  501. }
  502. if(StringUtils.isNotBlank(parentid)){
  503. map.put("pId", parentid);
  504. } else{
  505. map.put("pId", "1");
  506. }
  507. //根据id判断是否有子节点
  508. sql = "select count(1) from t_s_depart t where t.parentdepartid = ?";
  509. params = new Object[]{depart.getId()};
  510. long count = this.systemService.getCountForJdbcParam(sql, params);
  511. if(count>0){
  512. map.put("isParent",true);
  513. }
  514. dateList.add(map);
  515. }
  516. }
  517. net.sf.json.JSONArray jsonArray = net.sf.json.JSONArray.fromObject(dateList);
  518. j.setMsg(jsonArray.toString());
  519. return j;
  520. }
  521. }