瀏覽代碼

提供给子系统获取数据的接口

wangqiang 1 年之前
父節點
當前提交
db7a6aa978

+ 7 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/security/config/WebSecurityConfig.java

@@ -75,6 +75,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                         "/cwProjectReport/signatureCallBack/**",
                         "/app/sys/getCode",
                         "/sys/casLogin",
+                        "/sys/user/queryDetailByLoginName",
+                        "/sys/user/list",
+                        "/sys/user/queryById",
+                        "/sys/user/getUserByLoginNameForChild",
+                        "/sys/user/getAllUserInfo",
+                        "/sys/user/savePwdChild",
+                        "/sys/user/treeUserDataAllOfficeForChild",
                         "/app/luckyDraw/**",
                         "/sys/saveNewPassword",
                         "/sys/getPhoneCode").permitAll() // 允许请求无需认证

+ 15 - 15
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/LoginController.java

@@ -122,18 +122,18 @@ public class LoginController {
             }
         }
         //根据登录名查询登录信息
-        List<UserDTO> loginUserList = userService.getUserIdByLoginOrMobile(username);
-        if(null != loginUserList){
-            if (loginUserList.size()>1){
-                throw new DisabledException ( "登录名存在重复,请使用手机号进行登录或联系管理员" );
-            }else{
-                if(loginUserList.size()==0){
-                    throw new DisabledException ( "未找到登陆人员信息" );
-                }else{
-                    username = loginUserList.get(0).getLoginName();
-                }
-            }
-        }
+//        List<UserDTO> loginUserList = userService.getUserIdByLoginOrMobile(username);
+//        if(null != loginUserList){
+//            if (loginUserList.size()>1){
+//                throw new DisabledException ( "登录名存在重复,请使用手机号进行登录或联系管理员" );
+//            }else{
+//                if(loginUserList.size()==0){
+//                    throw new DisabledException ( "未找到登陆人员信息" );
+//                }else{
+//                    username = loginUserList.get(0).getLoginName();
+//                }
+//            }
+//        }
 
         SecurityUtils.login (username, password, authenticationManager  ); //登录操作spring security
 
@@ -157,9 +157,9 @@ public class LoginController {
         userDTO.setToken(token);
         //将登录的用户信息存放到redis中(在线状态key中)
         RedisUtils.getInstance().set(CacheNames.USER_CACHE_LOGIN_ONLINE_LOGIN_NAME + loginUserName , userDTO);
-        if(!"123456".equals(password) && !DaoAuthenticationProvider.getValue().equals(password)){
-            userService.updateUserUpPassword(userDTO);
-        }
+//        if(!"123456".equals(password) && !DaoAuthenticationProvider.getValue().equals(password)){
+//            userService.updateUserUpPassword(userDTO);
+//        }
 
         return responseUtil.ok ( );
     }

+ 104 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/UserController.java

@@ -16,6 +16,7 @@ import com.google.gson.Gson;
 import com.jeeplus.aop.demo.annotation.DemoMode;
 import com.jeeplus.aop.logging.annotation.ApiLog;
 import com.jeeplus.common.beanvalidator.BeanValidators;
+import com.jeeplus.common.redis.RedisUtils;
 import com.jeeplus.common.utils.FileUtils;
 import com.jeeplus.common.utils.ResponseUtil;
 import com.jeeplus.config.properties.FileProperties;
@@ -92,6 +93,9 @@ public class UserController {
     @Autowired
     private RosterBaseCService rosterBaseCService;
 
+    @Autowired
+    private RedisUtils redisUtils;
+
     /**
      * 根据id查询用户
      *
@@ -557,6 +561,26 @@ public class UserController {
         return ResponseEntity.badRequest ( ).body ( "参数错误!" );
     }
 
+    @DemoMode
+    @ApiLog("子系统修改密码")
+    @RequestMapping("savePwdChild")
+    @ApiOperation(value = "修改密码")
+    public boolean savePwdChild(String mobile, String newPassword) {
+        //根据手机号判断修改哪个用户的密码
+        try {
+            List<UserDTO> dtos = userService.getUserIdByLoginOrMobile(mobile);
+            User user = new User ( dtos.get(0).getId ( ) );
+            user.setPassword ( SecurityUtils.encryptPassword ( newPassword ) );
+            user.setUpPassword("1"); // 密码修改状态改为”已修改“
+            userService.updateById ( user );
+            //清空redis中的对应的用户信息
+            redisUtils.delete  ("user:assess:cache:loginName::" + dtos.get(0).getLoginName());
+            return true;
+        } catch (Exception e){
+            return false;
+        }
+    }
+
 
     /**
      * 获取菜单
@@ -645,6 +669,33 @@ public class UserController {
      * @param showAll 是否显示不可用数据 1 显示 0 隐藏
      * @return
      */
+    @ApiLog("获取部门用户数据给子系统")
+    @GetMapping("treeUserDataAllOfficeForChild")
+    public ResponseEntity treeUserDataAllOfficeForChild(@RequestParam(required = false) String mobile,@RequestParam(required = false) String officeName,@RequestParam(required = false) String extId, @RequestParam(required = false) String type, @RequestParam(required = false, defaultValue = CommonConstants.NO) String showAll) {
+        List<OfficeDTO> list = officeService.getOfficeAllByOfficeName (officeName);
+        if(list.size()>0){
+            List<String> officeIds = Lists.newArrayList();
+            for (OfficeDTO info : list) {
+                info.setTypeFlag(true);
+                officeIds.add(info.getId());
+            }
+            //根据部门查询对应部门下的所有数据
+            List<OfficeDTO> officeDTOList = userService.getUserByOffice(officeIds,type);
+            list.addAll(officeDTOList);
+        }
+        List rootTree = officeService.getRootTreeForChild (list, extId, type, showAll, "1",mobile);
+        return ResponseEntity.ok (rootTree);
+    }
+
+    /**
+     * 获取机构JSON数据。
+     *
+     * @param officeName 部门名称
+     * @param extId 排除的ID
+     * @param type  类型(1:公司;2:部门)
+     * @param showAll 是否显示不可用数据 1 显示 0 隐藏
+     * @return
+     */
     @ApiLog("获取部门用户数据")
     @GetMapping("treeUserDataByOfficeName")
     public ResponseEntity treeUserDataByOfficeName(@RequestParam(required = false) String officeName,@RequestParam(required = false) String extId, @RequestParam(required = false) String type, @RequestParam(required = false, defaultValue = CommonConstants.NO) String showAll) {
@@ -777,6 +828,59 @@ public class UserController {
     }
 
     /**
+     * 根据ids查询用户基本信息(姓名、手机、角色、部门)
+     *
+     * @param loginName
+     * @return
+     */
+    @ApiLog("根据登录名查询用户基本信息")
+    @GetMapping("queryDetailByLoginName")
+    @ApiOperation(value = "根据登录名查询用户基本信息")
+    public UserDTO queryDetailByLoginName(@RequestParam("loginName") String loginName) {
+        UserDTO userDTO = userService.getUserByLoginName(loginName);
+        Boolean updatePassword = userService.isUpdatePassword(userDTO.getId());
+        userDTO.setUpPassword(updatePassword+"");
+        userDTO.setRoleList(userDTO.getRoleDTOList());
+        return userDTO;
+    }
+
+    /**
+     * 提供给子系统的用户详细信息的接口
+     * @param buffer
+     * @return
+     */
+    @ApiLog("根据子系统传来的所以信息查询详细信息")
+    @GetMapping("getAllUserInfo")
+    @ApiOperation(value = "根据子系统传来的所以信息查询详细信息")
+    public List<UserDTO> getAllUserInfo(StringBuffer buffer){
+        String s = buffer.toString();
+        String[] list = s.split(",");
+        List<UserDTO> arrayList = new ArrayList<>();
+        for (int i=0;i<list.length;i++){
+            UserDTO userDTO = userService.get(list[i]);
+            arrayList.add(userDTO);
+        }
+        return arrayList;
+    }
+
+    /**
+     * 根据登录名获取用户
+     *
+     * @param loginName
+     * @return
+     */
+    @ApiLog("根据登录名获取用户")
+    @GetMapping("getUserByLoginNameForChild")
+    @ApiOperation(value = "根据登录名获取用户")
+    public UserDTO getUserByLoginNameForChild(@RequestParam("loginName") String loginName) {
+        UserDTO userDTO = userService.getUserByLoginNameForChild(loginName);
+        Boolean updatePassword = userService.isUpdatePassword(userDTO.getId());
+        userDTO.setUpPassword(updatePassword+"");
+        userDTO.setRoleList(userDTO.getRoleDTOList());
+        return userDTO;
+    }
+
+    /**
      * 获取当前用户是否已经修改过密码
      * @return
      */

+ 1 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/xml/UserMapper.xml

@@ -47,6 +47,7 @@
 		a.is_admin AS "isAdmin",
     	a.password,
     	a.no,
+    	a.up_password as upPassword,
 		a.name,
 		a.email,
 		a.phone,

+ 94 - 1
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/OfficeService.java

@@ -16,7 +16,9 @@ import com.jeeplus.sys.constant.CommonConstants;
 import com.jeeplus.sys.constant.enums.OfficeTypeEnum;
 import com.jeeplus.sys.domain.Office;
 import com.jeeplus.sys.mapper.OfficeMapper;
+import com.jeeplus.sys.mapper.UserMapper;
 import com.jeeplus.sys.service.dto.OfficeDTO;
+import com.jeeplus.sys.service.dto.UserDTO;
 import com.jeeplus.sys.service.mapstruct.OfficeWrapper;
 import com.jeeplus.sys.utils.UserUtils;
 import org.apache.commons.lang.StringUtils;
@@ -45,6 +47,9 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
     @Autowired
     private OfficeMapper officeMapper;
 
+    @Autowired
+    private UserService userService;
+
     public List <OfficeDTO> getRootTree(List<OfficeDTO> list, String extId, String type, String showAll, String showMyOffice) {
         List<OfficeDTO> offices = Lists.newArrayList ();
         // 获取到所有parent_id为‘0’的部门数据
@@ -57,9 +62,11 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
             }
         }
         if (com.jeeplus.sys.utils.StringUtils.isNotBlank(showMyOffice)) {
+
+
             OfficeDTO officeDTO = UserUtils.getCurrentUserDTO().getOfficeDTO();
             // 排除管理员
-            if (!UserUtils.getCurrentUserDTO().isAdmin()){
+            if (!UserUtils.getCurrentUserDTO().getOfficeDTO().isAdmin()){
                 if (StringUtils.isNotBlank(officeDTO.getParentIds())) {
                     String[] split = officeDTO.getParentIds().split(",");
                     if (split.length > 2) {
@@ -84,6 +91,92 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
         return offices;
     }
 
+    public List <OfficeDTO> getRootTreeForChild(List<OfficeDTO> list, String extId, String type, String showAll, String showMyOffice,String mobile) {
+        List<OfficeDTO> offices = Lists.newArrayList ();
+        // 获取到所有parent_id为‘0’的部门数据
+        List<OfficeDTO> rootTrees = officeWrapper.toDTO (super.getChildren (new Office (OfficeDTO.getRootId ())));
+        for (OfficeDTO root : rootTrees) {
+            if (this.isUseAble ( extId, type,root, showAll )){
+                // 不是被排除节点的子节点
+                List<OfficeDTO> officeList = formatListToTree (root, list, extId, type, showAll);
+                offices.addAll (officeList);
+            }
+        }
+        if (com.jeeplus.sys.utils.StringUtils.isNotBlank(showMyOffice)) {
+            UserDTO dto = userService.getUserByLoginNameForChild(mobile);
+
+            OfficeDTO officeDTO = dto.getOfficeDTO();
+            // 排除管理员
+            if (!dto.getOfficeDTO().isAdmin()){
+                if (StringUtils.isNotBlank(officeDTO.getParentIds())) {
+                    String[] split = officeDTO.getParentIds().split(",");
+                    if (split.length > 2) {
+                        Office office = officeMapper.selectById(split[2]);
+                        if ("0".equals(office.getIsPublic())) {
+                            // isPublic为“0”,当前用户的公司为私有,查询的部门包含自己所属公司全部部门和其他的公有部门
+                            if(null != officeDTO && StringUtils.isNotBlank(officeDTO.getParentIds())){
+                                offices = this.getCompanyFromTreeForChild(offices,dto);
+                            }
+                        }
+                    } else {
+                        if ("0".equals(officeDTO.getIsPublic())) {
+                            // isPublic为“0”,当前用户的公司为私有,查询的部门包含自己所属公司全部部门和其他的公有部门
+                            if(null != officeDTO && StringUtils.isNotBlank(officeDTO.getParentIds())){
+                                offices = this.getCompanyFromTreeForChild(offices,dto);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return offices;
+    }
+
+    /**
+     * 在tree数据中找到当前登录人的“集团”以及“公司”
+     */
+    public List<OfficeDTO> getCompanyFromTreeForChild(List<OfficeDTO> rootTrees,UserDTO dto){
+        // 当前登录人的集团id
+        String corporationId = dto.getCompanyDTO().getId();
+        // 公司id
+        String parentIds = officeMapper.selectById(dto.getOfficeDTO().getId()).getParentIds();
+        String companyId = null;
+        String[] split = parentIds.split(",");
+        if(split.length>2){
+            companyId = split[2];
+        }else{
+            companyId = dto.getOfficeDTO().getId();
+        }
+        List<OfficeDTO> os = new ArrayList<>();
+        if (CollectionUtil.isNotEmpty(rootTrees)) {
+            String finalCompanyId = companyId;
+            rootTrees.stream().forEach(item->{
+                if ("1".equals(item.getIsPublic())) { // 找到公有的集团
+                    OfficeDTO officeDTO = item;
+                    if (CollectionUtil.isNotEmpty(item.getChildren())){
+                        officeDTO.setChildren(item.getChildren());
+                    }
+                    os.add(officeDTO);
+                }else{
+                    if(item.getId().equals(corporationId)){  // 找到登录人的集团
+                        OfficeDTO officeDTO = item;
+                        if (CollectionUtil.isNotEmpty(item.getChildren())&&!"".equals(finalCompanyId)){
+                            List<OfficeDTO> companys = new ArrayList<>();
+                            item.getChildren().stream().forEach(child->{
+                                if(child.getId().equals(finalCompanyId) || "1".equals(child.getIsPublic())){ // 登录人的公司 或者 公有公司
+                                    companys.add(child);
+                                }
+                            });
+                            officeDTO.setChildren(companys);
+                        }
+                        os.add(officeDTO);
+                    }
+                }
+            });
+        }
+        return os;
+    }
+
     /**
      * 在tree数据中找到当前登录人的“集团”以及“公司”
      */

+ 48 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/UserService.java

@@ -41,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
@@ -77,6 +79,9 @@ public class UserService  extends ServiceImpl<UserMapper, User> {
 	@Autowired
 	private RosterBaseCService rosterBaseCService;
 
+	// 通过 -?[0-9]+(\\\\.[0-9]+)? 进行匹配是否为数字
+	private static Pattern pattern = Pattern.compile("-?[0-9]+(\\\\.[0-9]+)?");
+
 	@Autowired
 	private SysUserFailedLogService sysUserFailedLogService;
 
@@ -123,6 +128,49 @@ public class UserService  extends ServiceImpl<UserMapper, User> {
 	 * @param loginName
 	 * @return
 	 */
+	public UserDTO getUserByLoginNameForChild(String loginName) {
+		//查人力资源系统的用户信息
+		QueryWrapper queryWrapper = new QueryWrapper ();
+		//判断是否是用手机号登录
+		Matcher m = pattern.matcher(loginName);
+		if (m.matches()){
+			queryWrapper.eq ("a.mobile", loginName);
+			queryWrapper.eq("a.del_flag","0");
+		} else {
+			queryWrapper.eq ("a.login_name", loginName);
+			queryWrapper.eq("a.del_flag","0");
+		}
+		UserDTO userDTO = baseMapper.get(queryWrapper);
+
+		if (null == userDTO){
+			return null;
+		}
+
+		final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
+		//获取登录ip
+		final String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
+
+		// 获取客户端操作系统
+		String os = userAgent.getOperatingSystem().getName();
+		// 获取客户端浏览器
+		String browser = userAgent.getBrowser().getName();
+		// 登录地址
+		String address = AddressUtils.getRealAddressByIP(ip);
+
+		userDTO.setLoginTime(new Date());
+
+		userDTO.setLoginIp(ip);
+		userDTO.setLoginLocation(address);
+		userDTO.setOs(os);
+		userDTO.setBrowser(browser);
+		return userDTO;
+	}
+
+	/**
+	 * 根据登录名获取用户
+	 * @param loginName
+	 * @return
+	 */
 	@Cacheable(cacheNames = CacheNames.USER_CACHE_LOGIN_NAME, key = "#loginName")
 	public UserDTO getUserByLoginName(String loginName) {
 		QueryWrapper queryWrapper = new QueryWrapper ();

+ 5 - 1
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/dto/UserDTO.java

@@ -47,7 +47,7 @@ public class  UserDTO extends BaseDTO {
     /**
      * 密码
      */
-    @JsonIgnore
+//    @JsonIgnore
     @Length(min = 1, max = 100)
     private String password;
 
@@ -150,6 +150,10 @@ public class  UserDTO extends BaseDTO {
      */
     private String sign;
 
+    /**
+     * 是否修改过密码,1为是
+     */
+    private String upPassword;
 
     /**
      * 备注