BaseController.java 22 KB

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