BaseController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. package com.jtgh.yjpt.controller;
  2. import java.io.IOException;
  3. import java.math.BigDecimal;
  4. import java.net.URLEncoder;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.Calendar;
  8. import java.util.Collections;
  9. import java.util.List;
  10. import java.util.Locale;
  11. import java.util.Map;
  12. import java.util.ResourceBundle;
  13. import javax.persistence.criteria.CriteriaBuilder;
  14. import javax.persistence.criteria.CriteriaBuilder.In;
  15. import javax.persistence.criteria.Predicate;
  16. import javax.persistence.criteria.Root;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import net.sf.jasperreports.engine.JRDataSource;
  20. import org.apache.commons.lang.StringUtils;
  21. import org.apache.log4j.Logger;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.data.domain.Page;
  24. import org.springframework.data.domain.Sort;
  25. import org.springframework.data.domain.Sort.Direction;
  26. import org.springframework.jdbc.core.JdbcTemplate;
  27. import org.springframework.jdbc.support.rowset.SqlRowSet;
  28. import com.jtgh.yjpt.common.BusinessContext;
  29. import com.jtgh.yjpt.common.Constants;
  30. import com.jtgh.yjpt.common.GlobalData;
  31. import com.jtgh.yjpt.common.PredicateModel;
  32. import com.jtgh.yjpt.common.PredicateModel.JoinType;
  33. import com.jtgh.yjpt.common.PredicateModel.Operator;
  34. import com.jtgh.yjpt.common.ReportExportHelper;
  35. import com.jtgh.yjpt.common.SysException;
  36. import com.jtgh.yjpt.common.Utils;
  37. import com.jtgh.yjpt.entity.BaseEntity;
  38. import com.jtgh.yjpt.entity.auth.UserEntity;
  39. /**
  40. * 控制器层共通基类<br>
  41. * <p>
  42. * 所有控制器层(@controller)继承此共通基类,实现控制器层共通处理。
  43. * <p>
  44. * 关于Flex调用:
  45. * <li>需要被Flex远程调用的控制器使用@RemotingDestination注解
  46. * <li>需要被Flex远程调用的方法使用@RemotingInclude(可以不写,默认)注解
  47. * <li>不需要被Flex远程调用的方法使用@RemotingExclude注解
  48. *
  49. * @author 袁晓冬
  50. *
  51. */
  52. @SuppressWarnings("unchecked")
  53. public abstract class BaseController {
  54. /** 日志记录 */
  55. protected Logger logger = Logger.getLogger(getClass());
  56. @Autowired
  57. protected JdbcTemplate jdbcTemplate;
  58. /**
  59. * jasper打印文件
  60. */
  61. public void download(Map<String, Object> parameters, String fileName,
  62. String reportPath, String type, JRDataSource dataSource,
  63. HttpServletResponse response, HttpServletRequest request) {
  64. try {
  65. response.setCharacterEncoding("utf-8");
  66. if (ReportExportHelper.REPORT_EXPORT_TYPE_HTML.equals(type)) {
  67. response.setContentType("text/html");
  68. } else {
  69. response.setContentType("multipart/form-data");
  70. response.setHeader("Content-Disposition",
  71. "attachment;fileName=" + fileName);
  72. }
  73. if ("FF".equals(getBrowser(request))) {
  74. // 针对火狐浏览器处理方式不一样了
  75. //fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
  76. } else {
  77. fileName = URLEncoder.encode(fileName, "UTF-8");
  78. }
  79. ReportExportHelper.exportFromIreport(reportPath, response,
  80. parameters, dataSource, fileName, type);
  81. } catch (IOException e) {
  82. e.printStackTrace();
  83. }
  84. }
  85. /**
  86. * 服务器端判断客户端浏览器类型
  87. *
  88. * @param request
  89. * @return
  90. */
  91. private String getBrowser(HttpServletRequest request) {
  92. String UserAgent = request.getHeader("USER-AGENT").toLowerCase();
  93. if (UserAgent != null) {
  94. if (UserAgent.indexOf("msie") >= 0)
  95. return "IE";
  96. if (UserAgent.indexOf("firefox") >= 0)
  97. return "FF";
  98. if (UserAgent.indexOf("safari") >= 0)
  99. return "SF";
  100. }
  101. return null;
  102. }
  103. /**
  104. * 资源文件
  105. */
  106. public ResourceBundle resource = ResourceBundle.getBundle(Locale
  107. .getDefault().toString() + "/select", Locale.getDefault(), this
  108. .getClass().getClassLoader());
  109. /**
  110. * 时间格式化
  111. */
  112. public SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  113. /**
  114. * 时间格式化2
  115. */
  116. public SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  117. /**
  118. * 时间格式化3
  119. */
  120. public SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  121. /**
  122. * 时间格式化4
  123. */
  124. public SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy/MM/dd");
  125. /**
  126. * 时间格式化5
  127. */
  128. public SimpleDateFormat sdf5 = new SimpleDateFormat("HH:mm:ss");
  129. /**
  130. * 日历
  131. */
  132. public Calendar now = Calendar.getInstance();
  133. public Calendar yxq = Calendar.getInstance();
  134. /**
  135. * 默认排序
  136. */
  137. public Sort sort = new Sort(Direction.DESC, "id");
  138. // //********************日志记录********************
  139. // private HashMap<String, String> needLogMethods = new HashMap<String,
  140. // String>();
  141. //
  142. // /** 登录 */
  143. // public static final String LOG_METHOD_TYPE_LOGIN = "0";
  144. // /** 新增 */
  145. // public static final String LOG_METHOD_TYPE_ADD = "1";
  146. // /** 删除 */
  147. // public static final String LOG_METHOD_TYPE_DELETE = "2";
  148. // /** 编辑 */
  149. // public static final String LOG_METHOD_TYPE_EDIT = "3";
  150. // /** 查看 */
  151. // public static final String LOG_METHOD_TYPE_QUERY = "4";
  152. // /** 上传 */
  153. // public static final String LOG_METHOD_TYPE_UPLOAD = "5";
  154. // /** 下载 */
  155. // public static final String LOG_METHOD_TYPE_DOWNLOAD = "6";
  156. // /** 打印 */
  157. // public static final String LOG_METHOD_TYPE_PRINT = "7";
  158. // /** 权力阳光办件查看 */
  159. // public static final String LOG_METHOD_TYPE_QLYG_VIEW = "9";
  160. //
  161. // /**
  162. // * 根据方法设置是否记录日志<br>
  163. // * 返回false时不记录日志,登录方法及无需登录即可访问的方法必须不记录日志,因为无法取得登录用户信息<br>
  164. // * 默认false,不记录日志
  165. // *
  166. // * @param method
  167. // * @return
  168. // */
  169. // public boolean needLog(String method) {
  170. // if (needLogMethods != null && needLogMethods.get(method) != null) {
  171. // return true;
  172. // }
  173. // return false;
  174. // }
  175. //
  176. // public String getMethodType(String method) {
  177. // if (needLogMethods != null && needLogMethods.get(method) != null) {
  178. // return needLogMethods.get(method);
  179. // }
  180. // return null;
  181. // }
  182. //
  183. // /**
  184. // * 添加需要记录日志的方法名
  185. // *
  186. // * @param method
  187. // */
  188. // protected void addNeedLogMethods(String method, String type) {
  189. // if (needLogMethods == null)
  190. // needLogMethods = new HashMap<String, String>();
  191. // if (needLogMethods.get(method) == null)
  192. // needLogMethods.put(method, type);
  193. // }
  194. //
  195. // /**
  196. // * 删除不需要记录日志的方法名
  197. // *
  198. // * @param method
  199. // */
  200. // protected void removeNeedLogMethods(String method) {
  201. // if (needLogMethods != null && needLogMethods.get(method) != null)
  202. // needLogMethods.remove(method);
  203. // }
  204. //
  205. // /**
  206. // * 菜单对应ID
  207. // */
  208. // protected String menuCode = "";
  209. // /**
  210. // * 经营人菜单对应ID
  211. // */
  212. // protected String menuCode_jyr = "";
  213. //
  214. // public String getMenuCode() {
  215. // if (Utils.getSession().getAttribute(GlobalData.USER_SESSION_KEY) != null)
  216. // {
  217. // UserEntity user = (UserEntity) Utils.getSession().getAttribute(
  218. // GlobalData.USER_SESSION_KEY);
  219. // if (Constants.NO.equals(user.getSfjyr())) {
  220. // return menuCode;
  221. // } else if (!StringUtils.isEmpty(menuCode_jyr)) {
  222. // return menuCode_jyr;
  223. // }
  224. // }
  225. // return menuCode;
  226. // }
  227. /**
  228. * 创建BusinessContext
  229. *
  230. * @return
  231. */
  232. protected BusinessContext createBusinessContext() {
  233. BusinessContext bc = new BusinessContext();
  234. bc.setAttribute("success", true);
  235. return bc;
  236. }
  237. /**
  238. * 返回提示信息给前台<br>
  239. * <p>
  240. * 提示信息:message
  241. * <p>
  242. * 信息参数:args
  243. * <p>
  244. * 是否成功:success
  245. *
  246. * @param messageId
  247. * 国际化ID
  248. * @param susscess
  249. * 是否成功
  250. * @param args
  251. * 信息参数ID
  252. * @return
  253. */
  254. protected BusinessContext createBusinessContext(String messageId,
  255. boolean susscess, String... args) {
  256. BusinessContext bc = new BusinessContext();
  257. bc.setAttribute("message", messageId);
  258. bc.setAttribute("success", susscess);
  259. bc.setAttribute("args", args);
  260. return bc;
  261. }
  262. /**
  263. * 返回提示信息给前台<br>
  264. * <p>
  265. * 提示信息:message
  266. * <p>
  267. * 包名:bundle
  268. * <p>
  269. * 信息参数:args
  270. * <p>
  271. * 是否成功:success
  272. *
  273. * @param messageId
  274. * @param bundle
  275. * @param susscess
  276. * @param args
  277. * @return
  278. */
  279. protected BusinessContext createBusinessContext(String messageId,
  280. String bundle, boolean susscess, String... args) {
  281. BusinessContext bc = new BusinessContext();
  282. bc.setAttribute("message", messageId);
  283. bc.setAttribute("bundle", bundle);
  284. bc.setAttribute("success", susscess);
  285. bc.setAttribute("args", args);
  286. return bc;
  287. }
  288. /**
  289. * 根据Entity创建BusinessContext<br>
  290. * <p>
  291. * entity对象:record
  292. * <p>
  293. * 是否成功:success
  294. *
  295. * @param entity
  296. * @return
  297. */
  298. protected <T extends BaseEntity<?>> BusinessContext createBusinessContext(
  299. T entity) {
  300. BusinessContext bc = new BusinessContext();
  301. bc.setAttribute("record", entity);
  302. bc.setAttribute("success", true);
  303. return bc;
  304. }
  305. /**
  306. * 根据分页对象创建BusinessContext<br>
  307. * 用于分页查询<br>
  308. * <p>
  309. * 对象列表:records
  310. * <p>
  311. * 总条数:totalCount
  312. * <p>
  313. * 是否成功:success
  314. *
  315. * @param page
  316. * @return
  317. */
  318. protected BusinessContext createBusinessContext(Page<?> page) {
  319. BusinessContext bc = new BusinessContext();
  320. bc.setAttribute("records", page.getContent());
  321. bc.setAttribute("totalCount", page.getTotalElements());
  322. bc.setAttribute("success", true);
  323. return bc;
  324. }
  325. protected BusinessContext createEmptyListBusinessContext() {
  326. BusinessContext bc = new BusinessContext();
  327. bc.setAttribute("records", Collections.EMPTY_LIST);
  328. bc.setAttribute("totalCount", 0);
  329. bc.setAttribute("success", true);
  330. return bc;
  331. }
  332. protected BusinessContext creaBusinessContext(List<?> list) {
  333. BusinessContext bc = new BusinessContext();
  334. bc.setAttribute("records", list);
  335. bc.setAttribute("success", true);
  336. return bc;
  337. }
  338. /**
  339. * 判断PredicateModel的value是否为空,只添加非空数据
  340. *
  341. * @param filterList
  342. * @param model
  343. */
  344. protected void addNotEmptyModel(List<PredicateModel> filterList,
  345. PredicateModel model) {
  346. Object value = model.getValue();
  347. if (null == value || "".equals(value)) {
  348. return;
  349. }
  350. if (null == filterList) {
  351. throw new SysException(
  352. "List<PredicateModel> filterList can't be null!");
  353. }
  354. filterList.add(model);
  355. }
  356. /**
  357. * 判断PredicateModel的value是否为空,只添加非空数据
  358. *
  359. * @param filterList
  360. * @param model
  361. */
  362. protected void addNotEmptyModel(List<PredicateModel> filterList,
  363. String fieldName, Object value, Operator operator) {
  364. if (null == value || "".equals(value) || "null".equals(value)) {
  365. return;
  366. }
  367. if (null == filterList) {
  368. throw new SysException(
  369. "List<PredicateModel> filterList can't be null!");
  370. }
  371. filterList.add(new PredicateModel(fieldName, value, operator));
  372. }
  373. /**
  374. * List参数判断
  375. *
  376. * @param filterList
  377. * @param fieldName
  378. * @param values
  379. * @param index
  380. * @param operator
  381. */
  382. protected void addNotEmptyModel(List<PredicateModel> filterList,
  383. String fieldName, List<?> values, int index, Operator operator) {
  384. if (values.size() >= index + 1) {
  385. addNotEmptyModel(filterList, fieldName, values.get(index), operator);
  386. }
  387. }
  388. /**
  389. * 生成唯一编号,供权力阳光使用
  390. *
  391. * 部门编码(10位)+0000000001(流水号10位)
  392. *
  393. * @param seqName
  394. * @return
  395. */
  396. public String generateQlygNo(String deptCode, Long entityId) {
  397. StringBuffer no = new StringBuffer();
  398. // if (null != seqName) {
  399. no.append(GlobalData.DEPT_CODE);
  400. // String sql = "SELECT " + seqName + ".nextval FROM dual";
  401. // try {
  402. // SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
  403. // if (rs.next()) {
  404. String seq = entityId.toString();
  405. if (null != seq && seq.length() > 0) {
  406. if (seq.length() < 10) {
  407. for (int i = seq.length(); i < 10; i++) {
  408. no.append("0");
  409. }
  410. no.append(seq);
  411. } else {
  412. no.append(seq.substring(seq.length() - 10, seq.length()));
  413. }
  414. }
  415. // }
  416. // } catch (Exception e) {
  417. // e.printStackTrace();
  418. // }
  419. // }
  420. return no.toString();
  421. }
  422. public Long generateEntityId(String seqName) {
  423. if (seqName != null) {
  424. String sql = "SELECT " + seqName + ".nextval FROM dual";
  425. try {
  426. SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
  427. if (rs.next()) {
  428. String seq = rs.getString(1);
  429. if (null != seq && seq.length() > 0) {
  430. return Long.parseLong(seq);
  431. }
  432. }
  433. } catch (Exception e) {
  434. e.printStackTrace();
  435. }
  436. }
  437. return 0l;
  438. }
  439. public String getCurrentRoleCode(Long functionId) {
  440. UserEntity user = Utils.getCurrentUser();
  441. String sql = "SELECT DISTINCT ROLE.code code FROM T_YJPT_ROLE ROLE "
  442. + "JOIN T_YJPT_ROLE_USER RU ON ROLE.ID = RU.ROLEID "
  443. + "WHERE RU.USERID=? AND("
  444. + "EXISTS(SELECT 1 FROM T_YJPT_ROLE_MENU RM "
  445. + "WHERE RM.ROLE = ROLE.ID AND RM.MENU=?) OR "
  446. + "EXISTS(SELECT 1 FROM T_YJPT_ROLE_BUTTON RB "
  447. + "WHERE RB.ROLE = ROLE.ID AND RB.BUTTON=?)) order by role.code asc";
  448. String role = null;
  449. try {
  450. SqlRowSet rs = jdbcTemplate.queryForRowSet(sql, user.getId(),
  451. functionId, functionId);
  452. if (rs.next()) {
  453. role = rs.getString("code");
  454. }
  455. } catch (Exception e) {
  456. e.printStackTrace();
  457. }
  458. return role;
  459. }
  460. // /**
  461. // * 普通经营人,设置当前用户过滤条件
  462. // *
  463. // * @param filterList
  464. // */
  465. // protected void addRecordCodeFilter(List<PredicateModel> filterList) {
  466. // List<PredicateModel> orList = new ArrayList<PredicateModel>();
  467. // // 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
  468. // if (Utils.getCurrentUser().getJyrjcxx() != null
  469. // && Utils.getSession().getAttribute(GlobalData.USER_SESSION_JYR) != null
  470. // && ((List<?>) Utils.getSession().getAttribute(
  471. // GlobalData.USER_SESSION_JYR)).size() > 0) {
  472. // orList.add(new PredicateModel("addUser.jyrjcxx.id", Utils
  473. // .getSession().getAttribute(GlobalData.USER_SESSION_JYR),
  474. // Operator.IN));
  475. // }
  476. // if (Utils.getCurrentUser().getJsdw() != null) {
  477. // orList.add(new PredicateModel("addUser.jsdw.id", Utils
  478. // .getCurrentUser().getJsdw().getId(), Operator.EQ));
  479. // }
  480. // if (Utils.getCurrentUser().getAqpjjg() != null) {
  481. // orList.add(new PredicateModel("addUser.aqpjjg.id", Utils
  482. // .getCurrentUser().getAqpjjg().getId(), Operator.EQ));
  483. // }
  484. // if (orList != null && orList.size() > 0)
  485. // filterList.add(new PredicateModel(JoinType.OR, orList));
  486. // }
  487. /**
  488. * 根据角色设置过滤条件
  489. *
  490. * @param functionId
  491. * @param filterList
  492. */
  493. protected void addRecordCodeFilter(Long functionId,
  494. List<PredicateModel> filterList) {
  495. addRecordCodeFilter(functionId, filterList, null);
  496. }
  497. /**
  498. * 根据角色设置过滤条件
  499. *
  500. * @param functionId
  501. * @param filterList
  502. * @param user
  503. * 根据某个字段过滤经营人、建设单位、评价机构的数据,默认根据addUser
  504. */
  505. protected void addRecordCodeFilter(Long functionId,
  506. List<PredicateModel> filterList, String user) {
  507. addRecordCodeFilter(functionId, filterList, user, null);
  508. }
  509. /**
  510. * 根据角色设置过滤条件
  511. *
  512. * @param functionId
  513. * @param filterList
  514. * @param user
  515. * 根据某个字段过滤经营人、建设单位、评价机构的数据,默认根据addUser
  516. */
  517. protected void addRecordCodeFilter(Long functionId,
  518. List<PredicateModel> filterList, String user, String jyr) {
  519. if (user == null)
  520. user = "addUser.";
  521. if (Utils.getCurrentUser() != null
  522. && !GlobalData.adminID.equals(Utils.getCurrentUser().getId())) {
  523. List<PredicateModel> orList = new ArrayList<PredicateModel>();
  524. String role = getCurrentRoleCode(functionId);
  525. // 行政人员可以查找所有比自己低级的数据,以及经营人、建设单位、评价机构的数据
  526. if (Constants.NO.equals(Utils.getCurrentUser().getSfjyr())) {
  527. // 行政人员按照所在地过滤
  528. if (Utils.getCurrentUser().getSzd() != null)
  529. filterList.add(new PredicateModel("szd.id", Utils
  530. .getCurrentUser().getSzd().getByzd2(),
  531. Operator.LIKE_R));
  532. role = Utils.getParentRole(role);
  533. orList.add(new PredicateModel("recordCode", role,
  534. Operator.LIKE_R));
  535. orList.add(new PredicateModel("recordCode",
  536. Constants.RECORD_CODE_JYR, Operator.LIKE_R));
  537. orList.add(new PredicateModel("recordCode",
  538. Constants.RECORD_CODE_PJJG, Operator.LIKE_R));
  539. orList.add(new PredicateModel("recordCode",
  540. Constants.RECORD_CODE_JSDW, Operator.LIKE_R));
  541. orList.add(new PredicateModel("tbdyid", null, Operator.NNL));
  542. } else {
  543. // 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
  544. if (Utils.getCurrentUser().getJyrjcxx() != null
  545. && Utils.getSession().getAttribute(
  546. GlobalData.USER_SESSION_JYR) != null) {
  547. if (!StringUtils.isEmpty(jyr)) {
  548. orList.add(new PredicateModel(jyr + ".id", Utils
  549. .getSession().getAttribute(
  550. GlobalData.USER_SESSION_JYR),
  551. Operator.IN));
  552. } else {
  553. orList.add(new PredicateModel(user + "jyrjcxx.id",
  554. Utils.getSession().getAttribute(
  555. GlobalData.USER_SESSION_JYR),
  556. Operator.IN));
  557. }
  558. }
  559. if (Utils.getCurrentUser().getJsdw() != null) {
  560. orList.add(new PredicateModel(user + "jsdw.id", Utils
  561. .getCurrentUser().getJsdw().getId(), Operator.EQ));
  562. }
  563. if (Utils.getCurrentUser().getAqpjjg() != null) {
  564. orList.add(new PredicateModel(user + "aqpjjg.id", Utils
  565. .getCurrentUser().getAqpjjg().getId(), Operator.EQ));
  566. }
  567. }
  568. if (orList != null && orList.size() > 0) {
  569. filterList.add(new PredicateModel(JoinType.OR, orList));
  570. }
  571. }
  572. }
  573. /**
  574. * 根据角色设置过滤条件(流程中使用)
  575. *
  576. * @param functionId
  577. * @param filterList
  578. */
  579. protected void addRecordCodeFilter(Long functionId, CriteriaBuilder cb,
  580. Root<?> root, List<Predicate> filterList) {
  581. addRecordCodeFilter(functionId, cb, root, filterList, null, null);
  582. }
  583. /**
  584. * 根据角色设置过滤条件(流程中使用)
  585. *
  586. * @param functionId
  587. * @param filterList
  588. */
  589. protected void addRecordCodeFilter(Long functionId, CriteriaBuilder cb,
  590. Root<?> root, List<Predicate> filterList, String user, String jyr) {
  591. if (user == null)
  592. user = "addUser";
  593. if (Utils.getCurrentUser() != null && !GlobalData.adminID.equals(Utils.getCurrentUser().getId())) {// 不是超级用户
  594. List<Predicate> orList = new ArrayList<Predicate>();
  595. String role = getCurrentRoleCode(functionId);
  596. // 行政人员可以查找所有比自己低级的数据,以及经营人、建设单位、评价机构的数据
  597. if (Constants.NO.equals(Utils.getCurrentUser().getSfjyr())) {// 不是经营人
  598. // 行政人员按照所在地过滤
  599. if (Utils.getCurrentUser().getSzd() != null)
  600. filterList.add(cb.like(
  601. root.get("szd").get("id").as(String.class),
  602. Utils.getCurrentUser().getSzd().getByzd2() + "%"));
  603. if (role != null)
  604. role = Utils.getParentRole(role);
  605. orList.add(cb.like(root.get("recordCode").as(String.class),
  606. role + "%"));
  607. orList.add(cb.like(root.get("recordCode").as(String.class),
  608. Constants.RECORD_CODE_JYR + "%"));
  609. orList.add(cb.like(root.get("recordCode").as(String.class),
  610. Constants.RECORD_CODE_PJJG + "%"));
  611. orList.add(cb.like(root.get("recordCode").as(String.class),
  612. Constants.RECORD_CODE_JSDW + "%"));
  613. orList.add(cb.isNotNull(root.get("tbdyid").as(String.class)));
  614. } else {
  615. // 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
  616. if (Utils.getCurrentUser().getJyrjcxx() != null) {
  617. In<Long> in = null;
  618. if (StringUtils.isEmpty(jyr)) {
  619. in = cb.in(root.get(user).get("jyrjcxx").get("id")
  620. .as(Long.class));
  621. } else {
  622. in = cb.in(root.get(jyr).get("id").as(Long.class));
  623. }
  624. if (Utils.getSession().getAttribute(
  625. GlobalData.USER_SESSION_JYR) != null) {
  626. List<BigDecimal> jyrIdList = (List<BigDecimal>) Utils
  627. .getSession().getAttribute(
  628. GlobalData.USER_SESSION_JYR);
  629. if (jyrIdList != null)
  630. for (BigDecimal jyrId : jyrIdList) {
  631. in.value(jyrId.longValue());
  632. }
  633. }
  634. orList.add(in);
  635. }
  636. if (Utils.getCurrentUser().getJsdw() != null) {
  637. orList.add(cb.equal(root.get(user).get("jsdw"), Utils
  638. .getCurrentUser().getJsdw()));
  639. }
  640. if (Utils.getCurrentUser().getAqpjjg() != null) {
  641. orList.add(cb.equal(root.get(user).get("aqpjjg"), Utils
  642. .getCurrentUser().getAqpjjg()));
  643. }
  644. }
  645. if (orList != null && orList.size() > 0) {
  646. Predicate[] p = new Predicate[orList.size()];
  647. filterList.add(cb.or(orList.toArray(p)));
  648. }
  649. }
  650. }
  651. protected void addEmptyModel(List<PredicateModel> filterList,
  652. String fieldName, Operator nl) {
  653. filterList.add(new PredicateModel(fieldName, null, Operator.NL));
  654. }
  655. }