();
// if (needLogMethods.get(method) == null)
// needLogMethods.put(method, type);
// }
//
// /**
// * 删除不需要记录日志的方法名
// *
// * @param method
// */
// protected void removeNeedLogMethods(String method) {
// if (needLogMethods != null && needLogMethods.get(method) != null)
// needLogMethods.remove(method);
// }
//
// /**
// * 菜单对应ID
// */
// protected String menuCode = "";
// /**
// * 经营人菜单对应ID
// */
// protected String menuCode_jyr = "";
//
// public String getMenuCode() {
// if (Utils.getSession().getAttribute(GlobalData.USER_SESSION_KEY) != null)
// {
// UserEntity user = (UserEntity) Utils.getSession().getAttribute(
// GlobalData.USER_SESSION_KEY);
// if (Constants.NO.equals(user.getSfjyr())) {
// return menuCode;
// } else if (!StringUtils.isEmpty(menuCode_jyr)) {
// return menuCode_jyr;
// }
// }
// return menuCode;
// }
/**
* 创建BusinessContext
*
* @return
*/
protected BusinessContext createBusinessContext() {
BusinessContext bc = new BusinessContext();
bc.setAttribute("success", true);
return bc;
}
/**
* 返回提示信息给前台
*
* 提示信息:message
*
* 信息参数:args
*
* 是否成功:success
*
* @param messageId
* 国际化ID
* @param susscess
* 是否成功
* @param args
* 信息参数ID
* @return
*/
protected BusinessContext createBusinessContext(String messageId,
boolean susscess, String... args) {
BusinessContext bc = new BusinessContext();
bc.setAttribute("message", messageId);
bc.setAttribute("success", susscess);
bc.setAttribute("args", args);
return bc;
}
/**
* 返回提示信息给前台
*
* 提示信息:message
*
* 包名:bundle
*
* 信息参数:args
*
* 是否成功:success
*
* @param messageId
* @param bundle
* @param susscess
* @param args
* @return
*/
protected BusinessContext createBusinessContext(String messageId,
String bundle, boolean susscess, String... args) {
BusinessContext bc = new BusinessContext();
bc.setAttribute("message", messageId);
bc.setAttribute("bundle", bundle);
bc.setAttribute("success", susscess);
bc.setAttribute("args", args);
return bc;
}
/**
* 根据Entity创建BusinessContext
*
* entity对象:record
*
* 是否成功:success
*
* @param entity
* @return
*/
protected > BusinessContext createBusinessContext(
T entity) {
BusinessContext bc = new BusinessContext();
bc.setAttribute("record", entity);
bc.setAttribute("success", true);
return bc;
}
/**
* 根据分页对象创建BusinessContext
* 用于分页查询
*
* 对象列表:records
*
* 总条数:totalCount
*
* 是否成功:success
*
* @param page
* @return
*/
protected BusinessContext createBusinessContext(Page> page) {
BusinessContext bc = new BusinessContext();
bc.setAttribute("records", page.getContent());
bc.setAttribute("totalCount", page.getTotalElements());
bc.setAttribute("success", true);
return bc;
}
protected BusinessContext createEmptyListBusinessContext() {
BusinessContext bc = new BusinessContext();
bc.setAttribute("records", Collections.EMPTY_LIST);
bc.setAttribute("totalCount", 0);
bc.setAttribute("success", true);
return bc;
}
protected BusinessContext creaBusinessContext(List> list) {
BusinessContext bc = new BusinessContext();
bc.setAttribute("records", list);
bc.setAttribute("success", true);
return bc;
}
/**
* 判断PredicateModel的value是否为空,只添加非空数据
*
* @param filterList
* @param model
*/
protected void addNotEmptyModel(List filterList,
PredicateModel model) {
Object value = model.getValue();
if (null == value || "".equals(value)) {
return;
}
if (null == filterList) {
throw new SysException(
"List filterList can't be null!");
}
filterList.add(model);
}
/**
* 判断PredicateModel的value是否为空,只添加非空数据
*
* @param filterList
* @param model
*/
protected void addNotEmptyModel(List filterList,
String fieldName, Object value, Operator operator) {
if (null == value || "".equals(value) || "null".equals(value)) {
return;
}
if (null == filterList) {
throw new SysException(
"List filterList can't be null!");
}
filterList.add(new PredicateModel(fieldName, value, operator));
}
/**
* List参数判断
*
* @param filterList
* @param fieldName
* @param values
* @param index
* @param operator
*/
protected void addNotEmptyModel(List filterList,
String fieldName, List> values, int index, Operator operator) {
if (values.size() >= index + 1) {
addNotEmptyModel(filterList, fieldName, values.get(index), operator);
}
}
/**
* 生成唯一编号,供权力阳光使用
*
* 部门编码(10位)+0000000001(流水号10位)
*
* @param seqName
* @return
*/
public String generateQlygNo(String deptCode, Long entityId) {
StringBuffer no = new StringBuffer();
// if (null != seqName) {
no.append(GlobalData.DEPT_CODE);
// String sql = "SELECT " + seqName + ".nextval FROM dual";
// try {
// SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
// if (rs.next()) {
String seq = entityId.toString();
if (null != seq && seq.length() > 0) {
if (seq.length() < 10) {
for (int i = seq.length(); i < 10; i++) {
no.append("0");
}
no.append(seq);
} else {
no.append(seq.substring(seq.length() - 10, seq.length()));
}
}
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
return no.toString();
}
public Long generateEntityId(String seqName) {
if (seqName != null) {
String sql = "SELECT " + seqName + ".nextval FROM dual";
try {
SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
if (rs.next()) {
String seq = rs.getString(1);
if (null != seq && seq.length() > 0) {
return Long.parseLong(seq);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return 0l;
}
public String getCurrentRoleCode(Long functionId) {
UserEntity user = Utils.getCurrentUser();
String sql = "SELECT DISTINCT ROLE.code code FROM T_YJPT_ROLE ROLE "
+ "JOIN T_YJPT_ROLE_USER RU ON ROLE.ID = RU.ROLEID "
+ "WHERE RU.USERID=? AND("
+ "EXISTS(SELECT 1 FROM T_YJPT_ROLE_MENU RM "
+ "WHERE RM.ROLE = ROLE.ID AND RM.MENU=?) OR "
+ "EXISTS(SELECT 1 FROM T_YJPT_ROLE_BUTTON RB "
+ "WHERE RB.ROLE = ROLE.ID AND RB.BUTTON=?)) order by role.code asc";
String role = null;
try {
SqlRowSet rs = jdbcTemplate.queryForRowSet(sql, user.getId(),
functionId, functionId);
if (rs.next()) {
role = rs.getString("code");
}
} catch (Exception e) {
e.printStackTrace();
}
return role;
}
// /**
// * 普通经营人,设置当前用户过滤条件
// *
// * @param filterList
// */
// protected void addRecordCodeFilter(List filterList) {
// List orList = new ArrayList();
// // 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
// if (Utils.getCurrentUser().getJyrjcxx() != null
// && Utils.getSession().getAttribute(GlobalData.USER_SESSION_JYR) != null
// && ((List>) Utils.getSession().getAttribute(
// GlobalData.USER_SESSION_JYR)).size() > 0) {
// orList.add(new PredicateModel("addUser.jyrjcxx.id", Utils
// .getSession().getAttribute(GlobalData.USER_SESSION_JYR),
// Operator.IN));
// }
// if (Utils.getCurrentUser().getJsdw() != null) {
// orList.add(new PredicateModel("addUser.jsdw.id", Utils
// .getCurrentUser().getJsdw().getId(), Operator.EQ));
// }
// if (Utils.getCurrentUser().getAqpjjg() != null) {
// orList.add(new PredicateModel("addUser.aqpjjg.id", Utils
// .getCurrentUser().getAqpjjg().getId(), Operator.EQ));
// }
// if (orList != null && orList.size() > 0)
// filterList.add(new PredicateModel(JoinType.OR, orList));
// }
/**
* 根据角色设置过滤条件
*
* @param functionId
* @param filterList
*/
protected void addRecordCodeFilter(Long functionId,
List filterList) {
addRecordCodeFilter(functionId, filterList, null);
}
/**
* 根据角色设置过滤条件
*
* @param functionId
* @param filterList
* @param user
* 根据某个字段过滤经营人、建设单位、评价机构的数据,默认根据addUser
*/
protected void addRecordCodeFilter(Long functionId,
List filterList, String user) {
addRecordCodeFilter(functionId, filterList, user, null);
}
/**
* 根据角色设置过滤条件
*
* @param functionId
* @param filterList
* @param user
* 根据某个字段过滤经营人、建设单位、评价机构的数据,默认根据addUser
*/
protected void addRecordCodeFilter(Long functionId,
List filterList, String user, String jyr) {
if (user == null)
user = "addUser.";
if (Utils.getCurrentUser() != null
&& !GlobalData.adminID.equals(Utils.getCurrentUser().getId())) {
List orList = new ArrayList();
String role = getCurrentRoleCode(functionId);
// 行政人员可以查找所有比自己低级的数据,以及经营人、建设单位、评价机构的数据
if (Constants.NO.equals(Utils.getCurrentUser().getSfjyr())) {
// 行政人员按照所在地过滤
if (Utils.getCurrentUser().getSzd() != null)
filterList.add(new PredicateModel("szd.id", Utils
.getCurrentUser().getSzd().getByzd2(),
Operator.LIKE_R));
role = Utils.getParentRole(role);
orList.add(new PredicateModel("recordCode", role,
Operator.LIKE_R));
orList.add(new PredicateModel("recordCode",
Constants.RECORD_CODE_JYR, Operator.LIKE_R));
orList.add(new PredicateModel("recordCode",
Constants.RECORD_CODE_PJJG, Operator.LIKE_R));
orList.add(new PredicateModel("recordCode",
Constants.RECORD_CODE_JSDW, Operator.LIKE_R));
orList.add(new PredicateModel("tbdyid", null, Operator.NNL));
} else {
// 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
if (Utils.getCurrentUser().getJyrjcxx() != null
&& Utils.getSession().getAttribute(
GlobalData.USER_SESSION_JYR) != null) {
if (!StringUtils.isEmpty(jyr)) {
orList.add(new PredicateModel(jyr + ".id", Utils
.getSession().getAttribute(
GlobalData.USER_SESSION_JYR),
Operator.IN));
} else {
orList.add(new PredicateModel(user + "jyrjcxx.id",
Utils.getSession().getAttribute(
GlobalData.USER_SESSION_JYR),
Operator.IN));
}
}
if (Utils.getCurrentUser().getJsdw() != null) {
orList.add(new PredicateModel(user + "jsdw.id", Utils
.getCurrentUser().getJsdw().getId(), Operator.EQ));
}
if (Utils.getCurrentUser().getAqpjjg() != null) {
orList.add(new PredicateModel(user + "aqpjjg.id", Utils
.getCurrentUser().getAqpjjg().getId(), Operator.EQ));
}
}
if (orList != null && orList.size() > 0) {
filterList.add(new PredicateModel(JoinType.OR, orList));
}
}
}
/**
* 根据角色设置过滤条件(流程中使用)
*
* @param functionId
* @param filterList
*/
protected void addRecordCodeFilter(Long functionId, CriteriaBuilder cb,
Root> root, List filterList) {
addRecordCodeFilter(functionId, cb, root, filterList, null, null);
}
/**
* 根据角色设置过滤条件(流程中使用)
*
* @param functionId
* @param filterList
*/
protected void addRecordCodeFilter(Long functionId, CriteriaBuilder cb,
Root> root, List filterList, String user, String jyr) {
if (user == null)
user = "addUser";
if (Utils.getCurrentUser() != null && !GlobalData.adminID.equals(Utils.getCurrentUser().getId())) {// 不是超级用户
List orList = new ArrayList();
String role = getCurrentRoleCode(functionId);
// 行政人员可以查找所有比自己低级的数据,以及经营人、建设单位、评价机构的数据
if (Constants.NO.equals(Utils.getCurrentUser().getSfjyr())) {// 不是经营人
// 行政人员按照所在地过滤
if (Utils.getCurrentUser().getSzd() != null)
filterList.add(cb.like(
root.get("szd").get("id").as(String.class),
Utils.getCurrentUser().getSzd().getByzd2() + "%"));
if (role != null)
role = Utils.getParentRole(role);
orList.add(cb.like(root.get("recordCode").as(String.class),
role + "%"));
orList.add(cb.like(root.get("recordCode").as(String.class),
Constants.RECORD_CODE_JYR + "%"));
orList.add(cb.like(root.get("recordCode").as(String.class),
Constants.RECORD_CODE_PJJG + "%"));
orList.add(cb.like(root.get("recordCode").as(String.class),
Constants.RECORD_CODE_JSDW + "%"));
orList.add(cb.isNotNull(root.get("tbdyid").as(String.class)));
} else {
// 经营人可以看自己及自己下级经营人的数据,非行政人员的建设方和评价机构只能看自己所在企业的数据
if (Utils.getCurrentUser().getJyrjcxx() != null) {
In in = null;
if (StringUtils.isEmpty(jyr)) {
in = cb.in(root.get(user).get("jyrjcxx").get("id")
.as(Long.class));
} else {
in = cb.in(root.get(jyr).get("id").as(Long.class));
}
if (Utils.getSession().getAttribute(
GlobalData.USER_SESSION_JYR) != null) {
List jyrIdList = (List) Utils
.getSession().getAttribute(
GlobalData.USER_SESSION_JYR);
if (jyrIdList != null)
for (BigDecimal jyrId : jyrIdList) {
in.value(jyrId.longValue());
}
}
orList.add(in);
}
if (Utils.getCurrentUser().getJsdw() != null) {
orList.add(cb.equal(root.get(user).get("jsdw"), Utils
.getCurrentUser().getJsdw()));
}
if (Utils.getCurrentUser().getAqpjjg() != null) {
orList.add(cb.equal(root.get(user).get("aqpjjg"), Utils
.getCurrentUser().getAqpjjg()));
}
}
if (orList != null && orList.size() > 0) {
Predicate[] p = new Predicate[orList.size()];
filterList.add(cb.or(orList.toArray(p)));
}
}
}
protected void addEmptyModel(List filterList,
String fieldName, Operator nl) {
filterList.add(new PredicateModel(fieldName, null, Operator.NL));
}
}