wangwei 7 tahun lalu
induk
melakukan
771acc347c

+ 51 - 21
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/UserController.java

@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiOperation;
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -12,12 +13,15 @@ import java.util.stream.Stream;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
@@ -29,13 +33,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.google.common.collect.Lists;
+
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
+import cn.com.qmth.examcloud.commons.web.helpers.page.PageInfo;
 import cn.com.qmth.examcloud.commons.web.security.annotation.Uac;
 import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
 import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
 import cn.com.qmth.examcloud.commons.web.security.enums.UacPolicy;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.FullUserInfo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
@@ -57,27 +65,49 @@ public class UserController extends ControllerSupport{
     @Autowired
     UserRepo userRepo;
 
+	@ApiOperation(value = "查询所有用户", notes = "")
+	@GetMapping("/all/{curPage}/{pageSize}")
+	public PageInfo<FullUserInfo> getAllUser(@PathVariable Integer curPage,
+			@PathVariable Integer pageSize, @RequestParam Long orgId,
+			@RequestParam String loginName, @RequestParam String name, @RequestParam String enable,
+			@RequestParam String roleCode, @RequestParam String type) {
 
-    @ApiOperation(value = "查询所有用户", notes = "分页带查询")
-    @GetMapping("/all/{curPage}/{pageSize}")
-    public ResponseEntity getAllUser(@ModelAttribute UserEntity userCriteria,
-                                     @PathVariable Integer curPage,
-                                     @PathVariable Integer pageSize,
-                                     HttpServletRequest request) {
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        if (accessUser != null) {
-            if (accessUser.getRootOrgId() == 0) {
-                return new ResponseEntity(userService.findOrgUser(userCriteria,
-                        new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
-            } else {
-                userCriteria.setRootOrgId(accessUser.getRootOrgId());
-            }
-        } else {
-            return new ResponseEntity(HttpStatus.NOT_FOUND);
-        }
-        return new ResponseEntity(userService.findAll(userCriteria,
-                new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
-    }
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+		if ((!isSuperAdmin()) && (!orgId.equals(accessUser.getRootOrgId()))) {
+			throw new StatusException("B-150001", "非法请求");
+		}
+
+		Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
+				"update_time");
+
+		loginName = "%" + loginName.trim() + "%";
+		name = "%" + name.trim() + "%";
+
+		Page<UserEntity> userList = userRepo.findAll(orgId, name, loginName, type, roleCode,
+				pageable);
+		Iterator<UserEntity> iterator = userList.iterator();
+
+		List<FullUserInfo> fullUserInfoList = Lists.newArrayList();
+		while (iterator.hasNext()) {
+			UserEntity next = iterator.next();
+			FullUserInfo bean = new FullUserInfo();
+			bean.setId(next.getId());
+			bean.setLoginName(next.getLoginName());
+			bean.setName(next.getName());
+			bean.setRootOrgId(next.getRootOrgId());
+			
+			List<UserRole> userRoles = next.getUserRoles();
+			for (UserRole cur : userRoles) {
+				
+			}
+			
+			fullUserInfoList.add(bean);
+		}
+
+		PageInfo<FullUserInfo> ret = new PageInfo<FullUserInfo>();
+		ret.setList(fullUserInfoList);
+		return ret;
+	}
 
     @ApiOperation(value = "按id查询用户", notes = "id查询")
     @GetMapping("/{id}")

+ 109 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/bean/FullUserInfo.java

@@ -0,0 +1,109 @@
+package cn.com.qmth.examcloud.core.basic.api.controller.bean;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+/**
+ * 全量用户信息
+ *
+ * @author WANGWEI
+ * @date 2018年6月25日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class FullUserInfo implements JsonSerializable {
+
+	private static final long serialVersionUID = -1326157272669439949L;
+
+	private Long id;
+
+	private Long rootOrgId;
+
+	private Long rootOrgName;
+
+	private Long orgId;
+
+	private String orgName;
+
+	private String name;
+
+	private String loginName;
+
+	/**
+	 * 角色合集
+	 */
+	private String roleNamesStr;
+
+	private Boolean enable;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Long getRootOrgName() {
+		return rootOrgName;
+	}
+
+	public void setRootOrgName(Long rootOrgName) {
+		this.rootOrgName = rootOrgName;
+	}
+
+	public Long getOrgId() {
+		return orgId;
+	}
+
+	public void setOrgId(Long orgId) {
+		this.orgId = orgId;
+	}
+
+	public String getOrgName() {
+		return orgName;
+	}
+
+	public void setOrgName(String orgName) {
+		this.orgName = orgName;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getLoginName() {
+		return loginName;
+	}
+
+	public void setLoginName(String loginName) {
+		this.loginName = loginName;
+	}
+
+	public String getRoleNamesStr() {
+		return roleNamesStr;
+	}
+
+	public void setRoleNamesStr(String roleNamesStr) {
+		this.roleNamesStr = roleNamesStr;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
+}

+ 28 - 19
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/UserRepo.java

@@ -17,34 +17,43 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
 /**
  * Created by songyue on 17/1/13.
  */
-public interface UserRepo extends JpaRepository<UserEntity,Long>,QueryByExampleExecutor<UserEntity>,JpaSpecificationExecutor<UserEntity>{
+public interface UserRepo
+		extends
+			JpaRepository<UserEntity, Long>,
+			QueryByExampleExecutor<UserEntity>,
+			JpaSpecificationExecutor<UserEntity> {
 
-    UserEntity findByRootOrgIdAndLoginName(long rootOrgId,String loginName);
+	UserEntity findByRootOrgIdAndLoginName(long rootOrgId, String loginName);
 
-    UserEntity findByLoginName(String loginName);
+	UserEntity findByLoginName(String loginName);
 
-    @Transactional
-    @Modifying
-    @Query("update UserEntity set password = :password where id = :id")
-    void updatePasswordById(@Param("id")long id,@Param("password")String password);
+	@Transactional
+	@Modifying
+	@Query("update UserEntity set password = :password where id = :id")
+	void updatePasswordById(@Param("id") long id, @Param("password") String password);
 
-    int countByLoginName(String loginName);
+	int countByLoginName(String loginName);
 
-    List<UserEntity> findByOrgIdAndType(long orgId,String userType);
+	List<UserEntity> findByOrgIdAndType(long orgId, String userType);
 
-    List<UserEntity> findByRootOrgIdAndType(long rootOrgId,String userType);
+	List<UserEntity> findByRootOrgIdAndType(long rootOrgId, String userType);
 
 	List<UserEntity> findByOrgId(Long orgId);
-	
-	@Query(nativeQuery = true,value = "SELECT DISTINCT * FROM ecs_core_user us, ecs_core_user_role ur WHERE us.id = ur.user_id And us.root_org_id = ? And ur.role_code = 'MARKER' And us.enable = 1")
+
+	@Query(nativeQuery = true, value = "SELECT DISTINCT * FROM ecs_core_user us, ecs_core_user_role ur WHERE us.id = ur.user_id And us.root_org_id = ? And ur.role_code = 'MARKER' And us.enable = 1")
 	List<UserEntity> findMarkerByRootOrgId(Long rootOrgId);
 
-    @Query(value = "SELECT distinct * FROM ecs_core_user us, ecs_core_user_role ur WHERE us.id = ur.user_id " +
-            "And us.root_org_id = ? And ur.role_code = 'MARKER' And us.enable = 1 ORDER BY ?#{#pageable}",
-    countQuery = "SELECT count(distinct us.id) FROM ecs_core_user us, ecs_core_user_role ur WHERE us.id = ur.user_id " +
-            "And us.root_org_id = ? And ur.role_code = 'MARKER' And us.enable = 1 ORDER BY ?#{#pageable}",nativeQuery = true)
-    Page<UserEntity> findMarkerByRootOrgId(Long rootOrgId, Pageable pageable);
+	@Query(nativeQuery = true, value = "SELECT DISTINCT * FROM ecs_core_user us, ecs_core_user_role ur WHERE us.type = 'PRINT' and us.id = ur.user_id and ur.role_code = 'PROJECT_MANAGER' And us.enable = 1")
+	List<UserEntity> findPrintPm();
+
+	@Query(value = "SELECT  * FROM ecs_core_user X, ecs_core_user_role Y WHERE X.id = Y.user_id "
+			+ "And X.root_org_id = :rootOrgId And X.name like :name And x.login_name like :loginName And type = :type "
+			+ "And Y.role_code = :roleCode ORDER BY ?#{#pageable} ", countQuery = ""
+					+ "SELECT count(*) FROM ecs_core_user X, ecs_core_user_role Y WHERE X.id = Y.user_id "
+					+ "And X.root_org_id = :rootOrgId And X.name like :name And x.login_name like :loginName And type = :type "
+					+ "And Y.role_code = :roleCode ", nativeQuery = true)
+	Page<UserEntity> findAll(@Param("rootOrgId") Long rootOrgId, @Param("name") String name,
+			@Param("loginName") String loginName, @Param("type") String type,
+			@Param("roleCode") String roleCode, Pageable pageable);
 
-    @Query(nativeQuery = true,value = "SELECT DISTINCT * FROM ecs_core_user us, ecs_core_user_role ur WHERE us.type = 'PRINT' and us.id = ur.user_id and ur.role_code = 'PROJECT_MANAGER' And us.enable = 1")
-    List<UserEntity> findPrintPm();
 }

+ 4 - 12
examcloud-core-basic-starter/src/main/java/cn/com/qmth/examcloud/core/basic/starter/config/PropertiesConfig.java

@@ -1,9 +1,9 @@
 package cn.com.qmth.examcloud.core.basic.starter.config;
 
-import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.event.ContextRefreshedEvent;
 
 import cn.com.qmth.examcloud.commons.base.util.PathUtil;
 import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
@@ -16,23 +16,15 @@ import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
 @Configuration
-public class PropertiesConfig implements BeanPostProcessor {
+public class PropertiesConfig implements ApplicationListener<ContextRefreshedEvent> {
 
 	@Value("${spring.profiles.active}")
 	private String springProfilesActive;
 
 	@Override
-	public Object postProcessBeforeInitialization(Object bean, String beanName)
-			throws BeansException {
-		return bean;
-	}
-
-	@Override
-	public Object postProcessAfterInitialization(Object bean, String beanName)
-			throws BeansException {
+	public void onApplicationEvent(ContextRefreshedEvent event) {
 		String resourceName = "application-" + springProfilesActive + ".properties";
 		PropertiesUtil.configureAndWatch(PathUtil.getResoucePath(resourceName));
-		return bean;
 	}
 
 }