|
|
@@ -2,8 +2,10 @@ package com.jeesite.modules.mes.web;
|
|
|
|
|
|
import com.jeesite.common.config.Global;
|
|
|
import com.jeesite.common.collect.ListUtils;
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
import com.jeesite.common.lang.DateUtils;
|
|
|
import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.common.mybatis.mapper.query.QueryType;
|
|
|
import com.jeesite.common.service.ServiceException;
|
|
|
import com.jeesite.common.utils.excel.ExcelExport;
|
|
|
import com.jeesite.common.utils.excel.ExcelImport;
|
|
|
@@ -17,8 +19,11 @@ import com.jeesite.modules.sys.entity.*;
|
|
|
import com.jeesite.modules.sys.service.EmployeeService;
|
|
|
import com.jeesite.modules.sys.service.EmpUserService;
|
|
|
import com.jeesite.modules.sys.service.UserService;
|
|
|
+import com.jeesite.modules.sys.utils.UserUtils;
|
|
|
import com.jeesite.modules.sys.web.user.EmpUserController;
|
|
|
+import org.springframework.dao.EmptyResultDataAccessException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
@@ -51,6 +56,9 @@ public class EmpUserCustomController extends BaseController {
|
|
|
@Autowired
|
|
|
private EmployeeService employeeService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
@ModelAttribute
|
|
|
public EmpUser get(String userCode, boolean isNewRecord) {
|
|
|
return empUserService.get(userCode, isNewRecord);
|
|
|
@@ -181,23 +189,133 @@ public class EmpUserCustomController extends BaseController {
|
|
|
return empUserController.save(empUser, oldLoginCode, request);
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
+ @ResponseBody
|
|
|
+ public Page<EmpUser> listData(EmpUser empUser, Boolean isAll, String ctrlPermi, String ctrlPermiFilter,
|
|
|
+ HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ applyOfficeTreeFilter(empUser, Boolean.TRUE.equals(isAll));
|
|
|
+ empUser.setPage(new Page<>(request, response));
|
|
|
+ return empUserService.findPage(empUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void applyOfficeTreeFilter(EmpUser empUser, boolean isAll) {
|
|
|
+ if (isAll) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ User currentUser = UserUtils.getUser();
|
|
|
+ if (currentUser == null || currentUser.isSuperAdmin()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (empUser.getEmployee() != null && empUser.getEmployee().getCompany() != null) {
|
|
|
+ empUser.getEmployee().getCompany().setIsQueryChildren(true);
|
|
|
+ }
|
|
|
+ Office office = empUser.getEmployee() == null ? null : empUser.getEmployee().getOffice();
|
|
|
+ String officeCode = office == null ? null : office.getOfficeCode();
|
|
|
+ if (office != null) {
|
|
|
+ office.setIsQueryChildren(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(officeCode) && !isTopOffice(officeCode)) {
|
|
|
+ List<String> officeCodes = findPermittedOfficeCodes(currentUser.getUserCode(), officeCode);
|
|
|
+ if (officeCodes.isEmpty()) {
|
|
|
+ officeCodes.add("__NO_AUTH_OFFICE__");
|
|
|
+ }
|
|
|
+ empUser.getSqlMap().getWhere().and("o.office_code", QueryType.IN, officeCodes.toArray(new String[0]));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> officeCodes = findPermittedOfficeCodes(currentUser.getUserCode(), officeCode);
|
|
|
+ if (officeCodes.isEmpty()) {
|
|
|
+ officeCodes.add("__NO_AUTH_OFFICE__");
|
|
|
+ }
|
|
|
+ empUser.getSqlMap().getWhere().and("o.office_code", QueryType.IN, officeCodes.toArray(new String[0]));
|
|
|
+ if (office != null) {
|
|
|
+ office.setOfficeCode(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isTopOffice(String officeCode) {
|
|
|
+ try {
|
|
|
+ String parentCode = jdbcTemplate.queryForObject(
|
|
|
+ "select parent_code from js_sys_office where office_code = ?",
|
|
|
+ String.class, officeCode);
|
|
|
+ return StringUtils.isBlank(parentCode) || "0".equals(parentCode);
|
|
|
+ } catch (EmptyResultDataAccessException ex) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> findPermittedOfficeCodes(String userCode, String rootOfficeCode) {
|
|
|
+ if (StringUtils.isBlank(userCode)) {
|
|
|
+ return ListUtils.newArrayList();
|
|
|
+ }
|
|
|
+ boolean selectedTopOffice = StringUtils.isNotBlank(rootOfficeCode) && isTopOffice(rootOfficeCode);
|
|
|
+ if (StringUtils.isBlank(rootOfficeCode) || selectedTopOffice) {
|
|
|
+ List<String> officeCodes = queryPermittedOfficeCodes(userCode, rootOfficeCode, true);
|
|
|
+ if (!officeCodes.isEmpty()) {
|
|
|
+ return officeCodes;
|
|
|
+ }
|
|
|
+ } else if (!queryPermittedOfficeCodes(userCode, null, true).isEmpty()) {
|
|
|
+ return queryPermittedOfficeCodes(userCode, rootOfficeCode, true);
|
|
|
+ }
|
|
|
+ return queryPermittedOfficeCodes(userCode, rootOfficeCode, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> queryPermittedOfficeCodes(String userCode, String rootOfficeCode, boolean onlySpecificScopes) {
|
|
|
+ List<Object> params = ListUtils.newArrayList();
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ sql.append("select distinct o.office_code ");
|
|
|
+ sql.append("from js_sys_office o ");
|
|
|
+ sql.append("where 1 = 1 ");
|
|
|
+ if (StringUtils.isNotBlank(rootOfficeCode)) {
|
|
|
+ sql.append("and (o.office_code = ? or o.parent_codes like concat('%,', ?, ',%')) ");
|
|
|
+ params.add(rootOfficeCode);
|
|
|
+ params.add(rootOfficeCode);
|
|
|
+ }
|
|
|
+ sql.append("and exists (");
|
|
|
+ sql.append(" select 1 from (");
|
|
|
+ sql.append(" select rds.ctrl_data from js_sys_role_data_scope rds ");
|
|
|
+ sql.append(" join js_sys_user_role ur on ur.role_code = rds.role_code ");
|
|
|
+ sql.append(" where ur.user_code = ? and rds.ctrl_type = 'Office' and rds.ctrl_permi = '1' ");
|
|
|
+ sql.append(" union ");
|
|
|
+ sql.append(" select uds.ctrl_data from js_sys_user_data_scope uds ");
|
|
|
+ sql.append(" where uds.user_code = ? and uds.ctrl_type = 'Office' and uds.ctrl_permi = '1' ");
|
|
|
+ sql.append(" ) ds ");
|
|
|
+ sql.append(" join js_sys_office so on so.office_code = ds.ctrl_data ");
|
|
|
+ sql.append(" where (o.office_code = ds.ctrl_data or o.parent_codes like concat('%,', ds.ctrl_data, ',%')) ");
|
|
|
+ params.add(userCode);
|
|
|
+ params.add(userCode);
|
|
|
+ if (onlySpecificScopes) {
|
|
|
+ if (StringUtils.isBlank(rootOfficeCode)) {
|
|
|
+ sql.append(" and so.parent_code is not null and so.parent_code <> '0' ");
|
|
|
+ } else if (!isTopOffice(rootOfficeCode)) {
|
|
|
+ sql.append(" and so.parent_code is not null and so.parent_code <> '0' ");
|
|
|
+ } else {
|
|
|
+ sql.append(" and ds.ctrl_data <> ? and so.parent_codes like concat('%,', ?, ',%') ");
|
|
|
+ params.add(rootOfficeCode);
|
|
|
+ params.add(rootOfficeCode);
|
|
|
+ }
|
|
|
+ } else if (StringUtils.isNotBlank(rootOfficeCode)) {
|
|
|
+ sql.append(" and exists (");
|
|
|
+ sql.append(" select 1 from js_sys_office selected ");
|
|
|
+ sql.append(" where selected.office_code = ? ");
|
|
|
+ sql.append(" and (so.office_code = selected.office_code ");
|
|
|
+ sql.append(" or so.parent_codes like concat('%,', selected.office_code, ',%') ");
|
|
|
+ sql.append(" or selected.parent_codes like concat('%,', so.office_code, ',%'))");
|
|
|
+ sql.append(" ) ");
|
|
|
+ params.add(rootOfficeCode);
|
|
|
+ }
|
|
|
+ sql.append(")");
|
|
|
+ return jdbcTemplate.queryForList(sql.toString(), String.class, params.toArray());
|
|
|
+ }
|
|
|
+
|
|
|
private boolean shouldSaveAuth(HttpServletRequest request) {
|
|
|
return "auth".equals(request.getParameter("op")) || request.getParameterMap().containsKey("userRoleString");
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "exportData")
|
|
|
public void exportData(EmpUser empUser, String ctrlPermi, String ctrlPermiFilter, HttpServletResponse response) {
|
|
|
- if (empUser.getEmployee() != null) {
|
|
|
- if (empUser.getEmployee().getOffice() != null) {
|
|
|
- empUser.getEmployee().getOffice().setIsQueryChildren(true);
|
|
|
- }
|
|
|
- if (empUser.getEmployee().getCompany() != null) {
|
|
|
- empUser.getEmployee().getCompany().setIsQueryChildren(true);
|
|
|
- }
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(ctrlPermi) || !"0".equals(ctrlPermi) || Global.isStrictMode()) {
|
|
|
- empUserService.addDataScopeFilter(empUser, ctrlPermiFilter);
|
|
|
- }
|
|
|
+ applyOfficeTreeFilter(empUser, false);
|
|
|
List<ExcelEmpUserEmployee> list = ListUtils.newArrayList();
|
|
|
for (EmpUser user : empUserService.findList(empUser)) {
|
|
|
list.add(toExcel(user));
|