BaseController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. * 日历
  119. */
  120. public Calendar now = Calendar.getInstance();
  121. public Calendar yxq = Calendar.getInstance();
  122. /**
  123. * 默认排序
  124. */
  125. public Sort sort = new Sort(Direction.DESC, "id");
  126. // //********************日志记录********************
  127. // private HashMap<String, String> needLogMethods = new HashMap<String,
  128. // String>();
  129. //
  130. // /** 登录 */
  131. // public static final String LOG_METHOD_TYPE_LOGIN = "0";
  132. // /** 新增 */
  133. // public static final String LOG_METHOD_TYPE_ADD = "1";
  134. // /** 删除 */
  135. // public static final String LOG_METHOD_TYPE_DELETE = "2";
  136. // /** 编辑 */
  137. // public static final String LOG_METHOD_TYPE_EDIT = "3";
  138. // /** 查看 */
  139. // public static final String LOG_METHOD_TYPE_QUERY = "4";
  140. // /** 上传 */
  141. // public static final String LOG_METHOD_TYPE_UPLOAD = "5";
  142. // /** 下载 */
  143. // public static final String LOG_METHOD_TYPE_DOWNLOAD = "6";
  144. // /** 打印 */
  145. // public static final String LOG_METHOD_TYPE_PRINT = "7";
  146. // /** 权力阳光办件查看 */
  147. // public static final String LOG_METHOD_TYPE_QLYG_VIEW = "9";
  148. //
  149. // /**
  150. // * 根据方法设置是否记录日志<br>
  151. // * 返回false时不记录日志,登录方法及无需登录即可访问的方法必须不记录日志,因为无法取得登录用户信息<br>
  152. // * 默认false,不记录日志
  153. // *
  154. // * @param method
  155. // * @return
  156. // */
  157. // public boolean needLog(String method) {
  158. // if (needLogMethods != null && needLogMethods.get(method) != null) {
  159. // return true;
  160. // }
  161. // return false;
  162. // }
  163. //
  164. // public String getMethodType(String method) {
  165. // if (needLogMethods != null && needLogMethods.get(method) != null) {
  166. // return needLogMethods.get(method);
  167. // }
  168. // return null;
  169. // }
  170. //
  171. // /**
  172. // * 添加需要记录日志的方法名
  173. // *
  174. // * @param method
  175. // */
  176. // protected void addNeedLogMethods(String method, String type) {
  177. // if (needLogMethods == null)
  178. // needLogMethods = new HashMap<String, String>();
  179. // if (needLogMethods.get(method) == null)
  180. // needLogMethods.put(method, type);
  181. // }
  182. //
  183. // /**
  184. // * 删除不需要记录日志的方法名
  185. // *
  186. // * @param method
  187. // */
  188. // protected void removeNeedLogMethods(String method) {
  189. // if (needLogMethods != null && needLogMethods.get(method) != null)
  190. // needLogMethods.remove(method);
  191. // }
  192. //
  193. // /**
  194. // * 菜单对应ID
  195. // */
  196. // protected String menuCode = "";
  197. // /**
  198. // * 经营人菜单对应ID
  199. // */
  200. // protected String menuCode_jyr = "";
  201. //
  202. // public String getMenuCode() {
  203. // if (Utils.getSession().getAttribute(GlobalData.USER_SESSION_KEY) != null)
  204. // {
  205. // UserEntity user = (UserEntity) Utils.getSession().getAttribute(
  206. // GlobalData.USER_SESSION_KEY);
  207. // if (Constants.NO.equals(user.getSfjyr())) {
  208. // return menuCode;
  209. // } else if (!StringUtils.isEmpty(menuCode_jyr)) {
  210. // return menuCode_jyr;
  211. // }
  212. // }
  213. // return menuCode;
  214. // }
  215. /**
  216. * 创建BusinessContext
  217. *
  218. * @return
  219. */
  220. protected BusinessContext createBusinessContext() {
  221. BusinessContext bc = new BusinessContext();
  222. bc.setAttribute("success", true);
  223. return bc;
  224. }
  225. /**
  226. * 返回提示信息给前台<br>
  227. * <p>
  228. * 提示信息:message
  229. * <p>
  230. * 信息参数:args
  231. * <p>
  232. * 是否成功:success
  233. *
  234. * @param messageId
  235. * 国际化ID
  236. * @param susscess
  237. * 是否成功
  238. * @param args
  239. * 信息参数ID
  240. * @return
  241. */
  242. protected BusinessContext createBusinessContext(String messageId,
  243. boolean susscess, String... args) {
  244. BusinessContext bc = new BusinessContext();
  245. bc.setAttribute("message", messageId);
  246. bc.setAttribute("success", susscess);
  247. bc.setAttribute("args", args);
  248. return bc;
  249. }
  250. /**
  251. * 返回提示信息给前台<br>
  252. * <p>
  253. * 提示信息:message
  254. * <p>
  255. * 包名:bundle
  256. * <p>
  257. * 信息参数:args
  258. * <p>
  259. * 是否成功:success
  260. *
  261. * @param messageId
  262. * @param bundle
  263. * @param susscess
  264. * @param args
  265. * @return
  266. */
  267. protected BusinessContext createBusinessContext(String messageId,
  268. String bundle, boolean susscess, String... args) {
  269. BusinessContext bc = new BusinessContext();
  270. bc.setAttribute("message", messageId);
  271. bc.setAttribute("bundle", bundle);
  272. bc.setAttribute("success", susscess);
  273. bc.setAttribute("args", args);
  274. return bc;
  275. }
  276. /**
  277. * 根据Entity创建BusinessContext<br>
  278. * <p>
  279. * entity对象:record
  280. * <p>
  281. * 是否成功:success
  282. *
  283. * @param entity
  284. * @return
  285. */
  286. protected <T extends BaseEntity<?>> BusinessContext createBusinessContext(
  287. T entity) {
  288. BusinessContext bc = new BusinessContext();
  289. bc.setAttribute("record", entity);
  290. bc.setAttribute("success", true);
  291. return bc;
  292. }
  293. /**
  294. * 根据分页对象创建BusinessContext<br>
  295. * 用于分页查询<br>
  296. * <p>
  297. * 对象列表:records
  298. * <p>
  299. * 总条数:totalCount
  300. * <p>
  301. * 是否成功:success
  302. *
  303. * @param page
  304. * @return
  305. */
  306. protected BusinessContext createBusinessContext(Page<?> page) {
  307. BusinessContext bc = new BusinessContext();
  308. bc.setAttribute("records", page.getContent());
  309. bc.setAttribute("totalCount", page.getTotalElements());
  310. bc.setAttribute("success", true);
  311. return bc;
  312. }
  313. protected BusinessContext createEmptyListBusinessContext() {
  314. BusinessContext bc = new BusinessContext();
  315. bc.setAttribute("records", Collections.EMPTY_LIST);
  316. bc.setAttribute("totalCount", 0);
  317. bc.setAttribute("success", true);
  318. return bc;
  319. }
  320. protected BusinessContext creaBusinessContext(List<?> list) {
  321. BusinessContext bc = new BusinessContext();
  322. bc.setAttribute("records", list);
  323. bc.setAttribute("success", true);
  324. return bc;
  325. }
  326. /**
  327. * 判断PredicateModel的value是否为空,只添加非空数据
  328. *
  329. * @param filterList
  330. * @param model
  331. */
  332. protected void addNotEmptyModel(List<PredicateModel> filterList,
  333. PredicateModel model) {
  334. Object value = model.getValue();
  335. if (null == value || "".equals(value)) {
  336. return;
  337. }
  338. if (null == filterList) {
  339. throw new SysException(
  340. "List<PredicateModel> filterList can't be null!");
  341. }
  342. filterList.add(model);
  343. }
  344. /**
  345. * 判断PredicateModel的value是否为空,只添加非空数据
  346. *
  347. * @param filterList
  348. * @param model
  349. */
  350. protected void addNotEmptyModel(List<PredicateModel> filterList,
  351. String fieldName, Object value, Operator operator) {
  352. if (null == value || "".equals(value) || "null".equals(value)) {
  353. return;
  354. }
  355. if (null == filterList) {
  356. throw new SysException(
  357. "List<PredicateModel> filterList can't be null!");
  358. }
  359. filterList.add(new PredicateModel(fieldName, value, operator));
  360. }
  361. /**
  362. * List参数判断
  363. *
  364. * @param filterList
  365. * @param fieldName
  366. * @param values
  367. * @param index
  368. * @param operator
  369. */
  370. protected void addNotEmptyModel(List<PredicateModel> filterList,
  371. String fieldName, List<?> values, int index, Operator operator) {
  372. if (values.size() >= index + 1) {
  373. addNotEmptyModel(filterList, fieldName, values.get(index), operator);
  374. }
  375. }
  376. /**
  377. * 生成唯一编号,供权力阳光使用
  378. *
  379. * 部门编码(10位)+0000000001(流水号10位)
  380. *
  381. * @param seqName
  382. * @return
  383. */
  384. public String generateQlygNo(String deptCode, Long entityId) {
  385. StringBuffer no = new StringBuffer();
  386. // if (null != seqName) {
  387. no.append(GlobalData.DEPT_CODE);
  388. // String sql = "SELECT " + seqName + ".nextval FROM dual";
  389. // try {
  390. // SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
  391. // if (rs.next()) {
  392. String seq = entityId.toString();
  393. if (null != seq && seq.length() > 0) {
  394. if (seq.length() < 10) {
  395. for (int i = seq.length(); i < 10; i++) {
  396. no.append("0");
  397. }
  398. no.append(seq);
  399. } else {
  400. no.append(seq.substring(seq.length() - 10, seq.length()));
  401. }
  402. }
  403. // }
  404. // } catch (Exception e) {
  405. // e.printStackTrace();
  406. // }
  407. // }
  408. return no.toString();
  409. }
  410. public Long generateEntityId(String seqName) {
  411. if (seqName != null) {
  412. String sql = "SELECT " + seqName + ".nextval FROM dual";
  413. try {
  414. SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
  415. if (rs.next()) {
  416. String seq = rs.getString(1);
  417. if (null != seq && seq.length() > 0) {
  418. return Long.parseLong(seq);
  419. }
  420. }
  421. } catch (Exception e) {
  422. e.printStackTrace();
  423. }
  424. }
  425. return 0l;
  426. }
  427. public String getCurrentRoleCode(Long functionId) {
  428. UserEntity user = Utils.getCurrentUser();
  429. String sql = "SELECT DISTINCT ROLE.code code FROM T_YJPT_ROLE ROLE "
  430. + "JOIN T_YJPT_ROLE_USER RU ON ROLE.ID = RU.ROLEID "
  431. + "WHERE RU.USERID=? AND("
  432. + "EXISTS(SELECT 1 FROM T_YJPT_ROLE_MENU RM "
  433. + "WHERE RM.ROLE = ROLE.ID AND RM.MENU=?) OR "
  434. + "EXISTS(SELECT 1 FROM T_YJPT_ROLE_BUTTON RB "
  435. + "WHERE RB.ROLE = ROLE.ID AND RB.BUTTON=?)) order by role.code asc";
  436. String role = null;
  437. try {
  438. SqlRowSet rs = jdbcTemplate.queryForRowSet(sql, user.getId(),
  439. functionId, functionId);
  440. if (rs.next()) {
  441. role = rs.getString("code");
  442. }
  443. } catch (Exception e) {
  444. e.printStackTrace();
  445. }
  446. return role;
  447. }
  448. // /**
  449. // * 普通经营人,设置当前用户过滤条件
  450. // *
  451. // * @param filterList
  452. // */
  453. // protected void addRecordCodeFilter(List<PredicateModel> filterList) {
  454. // List<PredicateModel> orList = new ArrayList<PredicateModel>();
  455. // // 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
  456. // if (Utils.getCurrentUser().getJyrjcxx() != null
  457. // && Utils.getSession().getAttribute(GlobalData.USER_SESSION_JYR) != null
  458. // && ((List<?>) Utils.getSession().getAttribute(
  459. // GlobalData.USER_SESSION_JYR)).size() > 0) {
  460. // orList.add(new PredicateModel("addUser.jyrjcxx.id", Utils
  461. // .getSession().getAttribute(GlobalData.USER_SESSION_JYR),
  462. // Operator.IN));
  463. // }
  464. // if (Utils.getCurrentUser().getJsdw() != null) {
  465. // orList.add(new PredicateModel("addUser.jsdw.id", Utils
  466. // .getCurrentUser().getJsdw().getId(), Operator.EQ));
  467. // }
  468. // if (Utils.getCurrentUser().getAqpjjg() != null) {
  469. // orList.add(new PredicateModel("addUser.aqpjjg.id", Utils
  470. // .getCurrentUser().getAqpjjg().getId(), Operator.EQ));
  471. // }
  472. // if (orList != null && orList.size() > 0)
  473. // filterList.add(new PredicateModel(JoinType.OR, orList));
  474. // }
  475. /**
  476. * 根据角色设置过滤条件
  477. *
  478. * @param functionId
  479. * @param filterList
  480. */
  481. protected void addRecordCodeFilter(Long functionId,
  482. List<PredicateModel> filterList) {
  483. addRecordCodeFilter(functionId, filterList, null);
  484. }
  485. /**
  486. * 根据角色设置过滤条件
  487. *
  488. * @param functionId
  489. * @param filterList
  490. * @param user
  491. * 根据某个字段过滤经营人、建设单位、评价机构的数据,默认根据addUser
  492. */
  493. protected void addRecordCodeFilter(Long functionId,
  494. List<PredicateModel> filterList, String user) {
  495. addRecordCodeFilter(functionId, filterList, user, 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, String jyr) {
  507. if (user == null)
  508. user = "addUser.";
  509. if (Utils.getCurrentUser() != null
  510. && !GlobalData.adminID.equals(Utils.getCurrentUser().getId())) {
  511. List<PredicateModel> orList = new ArrayList<PredicateModel>();
  512. String role = getCurrentRoleCode(functionId);
  513. // 行政人员可以查找所有比自己低级的数据,以及经营人、建设单位、评价机构的数据
  514. if (Constants.NO.equals(Utils.getCurrentUser().getSfjyr())) {
  515. // 行政人员按照所在地过滤
  516. if (Utils.getCurrentUser().getSzd() != null)
  517. filterList.add(new PredicateModel("szd.id", Utils
  518. .getCurrentUser().getSzd().getByzd2(),
  519. Operator.LIKE_R));
  520. // 根据站所过滤
  521. if(Utils.getCurrentUser().getZs() != null && StringUtils.isNotEmpty(jyr) ){
  522. if(jyr.equals("id")){
  523. filterList.add(new PredicateModel("zs.id", Utils.getCurrentUser().getZs().getId(),
  524. Operator.EQ));
  525. } else {
  526. filterList.add(new PredicateModel(jyr +".zs.id", Utils.getCurrentUser().getZs().getId(),
  527. Operator.EQ));
  528. }
  529. }
  530. role = Utils.getParentRole(role);
  531. orList.add(new PredicateModel("recordCode", null,
  532. Operator.NL));
  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
  594. && !GlobalData.adminID.equals(Utils.getCurrentUser().getId())) {// 不是超级用户
  595. List<Predicate> orList = new ArrayList<Predicate>();
  596. String role = getCurrentRoleCode(functionId);
  597. // 行政人员可以查找所有比自己低级的数据,以及经营人、建设单位、评价机构的数据
  598. if (Constants.NO.equals(Utils.getCurrentUser().getSfjyr())) {// 不是经营人
  599. // 行政人员按照所在地过滤
  600. if (Utils.getCurrentUser().getSzd() != null)
  601. filterList.add(cb.like(
  602. root.get("szd").get("id").as(String.class), Utils
  603. .getCurrentUser().getSzd().getByzd2()
  604. + "%"));
  605. // 根据站所过滤
  606. if(Utils.getCurrentUser().getZs() != null && StringUtils.isNotEmpty(jyr) ){
  607. if(jyr.equals("id")){
  608. filterList.add(cb.equal(root.get("zs").get("id").as(Long.class),
  609. Utils.getCurrentUser().getZs().getId()));
  610. } else {
  611. filterList.add(cb.equal(root.get(jyr).get("zs").get("id").as(Long.class),
  612. Utils.getCurrentUser().getZs().getId()));
  613. }
  614. }
  615. if (role != null)
  616. role = Utils.getParentRole(role);
  617. orList.add(cb.like(root.get("recordCode").as(String.class),
  618. role + "%"));
  619. orList.add(cb.like(root.get("recordCode").as(String.class),
  620. Constants.RECORD_CODE_JYR + "%"));
  621. orList.add(cb.like(root.get("recordCode").as(String.class),
  622. Constants.RECORD_CODE_PJJG + "%"));
  623. orList.add(cb.like(root.get("recordCode").as(String.class),
  624. Constants.RECORD_CODE_JSDW + "%"));
  625. orList.add(cb.isNotNull(root.get("tbdyid").as(String.class)));
  626. } else {
  627. // 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
  628. if (Utils.getCurrentUser().getJyrjcxx() != null) {
  629. In<Long> in = null;
  630. if (StringUtils.isEmpty(jyr)) {
  631. in = cb.in(root.get(user).get("jyrjcxx").get("id")
  632. .as(Long.class));
  633. } else {
  634. in = cb.in(root.get(jyr).get("id").as(Long.class));
  635. }
  636. if (Utils.getSession().getAttribute(
  637. GlobalData.USER_SESSION_JYR) != null) {
  638. List<BigDecimal> jyrIdList = (List<BigDecimal>) Utils
  639. .getSession().getAttribute(
  640. GlobalData.USER_SESSION_JYR);
  641. if (jyrIdList != null)
  642. for (BigDecimal jyrId : jyrIdList) {
  643. in.value(jyrId.longValue());
  644. }
  645. }
  646. orList.add(in);
  647. }
  648. if (Utils.getCurrentUser().getJsdw() != null) {
  649. orList.add(cb.equal(root.get(user).get("jsdw"), Utils
  650. .getCurrentUser().getJsdw()));
  651. }
  652. if (Utils.getCurrentUser().getAqpjjg() != null) {
  653. orList.add(cb.equal(root.get(user).get("aqpjjg"), Utils
  654. .getCurrentUser().getAqpjjg()));
  655. }
  656. }
  657. if (orList != null && orList.size() > 0) {
  658. Predicate[] p = new Predicate[orList.size()];
  659. filterList.add(cb.or(orList.toArray(p)));
  660. }
  661. }
  662. }
  663. protected void addEmptyModel(List<PredicateModel> filterList,
  664. String fieldName, Operator nl) {
  665. filterList.add(new PredicateModel(fieldName, null, Operator.NL));
  666. }
  667. }