Search in sources :

Example 76 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class LoginController method thirdLogin.

@ApiOperation("第三方平台登录接口-thirdLogin")
@RequestMapping(value = "/thirdLogin", method = RequestMethod.POST)
public Result<JSONObject> thirdLogin(@RequestBody SysThirdLoginModel sysThirdLoginModel) {
    Result<JSONObject> result = new Result<JSONObject>();
    SysUser sysUser = new SysUser();
    List<String> localRoleIds = new ArrayList<>();
    List<String> localDepIds = new ArrayList<>();
    String roles = "";
    String departments = "";
    // if(sysThirdLoginModel.getThirdType().equals("OneMap")){
    // //一张图接口:无需对接
    // sysUser.setUsername("oneMap");
    // sysUser.setThirdId("");
    // sysUser.setThirdType("oneMap");
    // sysUser.setPassword(CommonConstant.DEFAULT_INIT_PASSWORD);
    // }
    // else if(sysThirdLoginModel.getThirdType().equals("oneSystem")){
    // }
    // 1. 从第三方平台获取用户信息
    // "http://19.15.73.125:9000/user/user-system/secUser/getSecUserByName";
    String oneSystemUrl = baseConfig.getOneSystemUrl();
    JSONObject variables = new JSONObject();
    variables.put("username", sysThirdLoginModel.getUserName());
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("Authorization", sysThirdLoginModel.getThirdToken());
    ResponseEntity<JSONObject> responseEntity = RestUtil.request(oneSystemUrl, HttpMethod.GET, httpHeaders, variables, null, JSONObject.class);
    if (responseEntity.getStatusCode() != HttpStatus.OK) {
        result.error500("调用第三方平台用户鉴权请求失败");
        return result;
    }
    JSONObject responseObject = responseEntity.getBody();
    Integer status = responseObject.getInteger("status");
    if (status != 0) {
        result.error500("调用第三方平台用户鉴权发生错误,返回码:" + status.toString());
        return result;
    }
    JSONObject userInfoObject = responseObject.getJSONObject("result").getJSONObject("userInfo");
    String thirdUserId = userInfoObject.getString("id");
    String userName = userInfoObject.getString("name");
    String realName = userInfoObject.getString("alias");
    sysUser.setUsername(userName);
    sysUser.setRealname(realName);
    sysUser.setThirdId(thirdUserId);
    sysUser.setPassword(CommonConstant.DEFAULT_INIT_PASSWORD);
    // 不写入这个字段,不从role读取permission
    // sysUser.setThirdType("oneSystem");
    // 2、获取并转换角色
    List<String> roleIds = userInfoObject.getJSONArray("roleIdList").toJavaList(String.class);
    if (roleIds != null && !roleIds.isEmpty()) {
        // 特定的内部角色,可以检索全部文档
        sysUser.setThirdType(KMConstant.PublicUser);
        if (kmSysConfigService.getSysConfigValue("InnerRoleId") != null && !kmSysConfigService.getSysConfigValue("InnerRoleId").isEmpty()) {
            String innerRole = kmSysConfigService.getSysConfigValue("InnerRoleId");
            if (roleIds.contains(innerRole)) {
                // thirdType用于保存部门范围标识
                sysUser.setThirdType(KMConstant.InnerUser);
            }
        }
        for (String roleId : roleIds) {
            LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysRole::getRoleCode, roleId);
            // 角色转换:roleCode字段存储第三方系统的roleid
            SysRole sysRole = sysRoleService.getOne(queryWrapper);
            if (sysRole != null)
                localRoleIds.add(sysRole.getId());
        }
        roles = StringUtils.concatListToString(localRoleIds);
    }
    // 3、获取并转换部门
    List<String> depIds = userInfoObject.getJSONArray("orgIdList").toJavaList(String.class);
    if (depIds != null & !depIds.isEmpty()) {
        for (String depId : depIds) {
            LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysDepart::getMemo, depId);
            // 部门转换:memo字段存储第三方系统的departmentId
            SysDepart sysDepart = sysDepartService.getOne(queryWrapper);
            if (sysDepart != null) {
                localDepIds.add(sysDepart.getId());
            }
            departments = StringUtils.concatListToString(localDepIds);
        }
    }
    // 4、检查系统是否存在用户,如果没有,则新建,如果有,则修改刷新角色部门信息
    LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(SysUser::getUsername, sysUser.getUsername());
    SysUser dbSysUser = sysUserService.getOne(queryWrapper);
    if (dbSysUser == null) {
        // 设置创建时间
        sysUser.setCreateTime(new Date());
        String salt = oConvertUtils.randomGen(8);
        sysUser.setSalt(salt);
        String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), sysUser.getPassword(), salt);
        sysUser.setPassword(passwordEncode);
        sysUser.setStatus(1);
        sysUser.setDelFlag(CommonConstant.DEL_FLAG_0);
        // 转换角色和部门后 sysUserService.saveUser();
        sysUserService.saveUser(sysUser, roles, departments);
    // if(!sysUserService.save(sysUser)){
    // result.error500("创建用户失败");
    // return result;
    // }
    } else {
        // 转换角色和部门后 sysUserService.editUser(); 可以清空缓存
        // 重置内部标识
        dbSysUser.setThirdType(sysUser.getThirdType());
        dbSysUser.setRealname(sysUser.getRealname());
        sysUserService.editUser(dbSysUser, roles, departments);
    }
    // 5、设置用户登录信息
    sysUser = sysUserService.getUserByName(sysUser.getUsername());
    userInfo(sysUser, result);
    return result;
// 生成token
// String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
// // 设置token缓存有效时间
// if(!redisUtil.hasKey(CommonConstant.PREFIX_USER_TOKEN + token))
// redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
// redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
// 
// //		redisUtil.set(CommonConstant.PREFIX_THIRD_USER_TOKEN + sysUser.getUsername(),sysThirdLoginModel.getThirdToken());
// //		redisUtil.expire(CommonConstant.PREFIX_THIRD_USER_TOKEN + sysUser.getUsername(),JwtUtil.EXPIRE_TIME*2 / 1000);
// 
// //		redisUtil.set(CommonConstant.PREFIX_THIRD_USER_ROLEIDS+ sysUser.getUsername(),localRoleIds);
// //		redisUtil.expire(CommonConstant.PREFIX_THIRD_USER_ROLEIDS + sysUser.getUsername(),JwtUtil.EXPIRE_TIME*2 / 1000);
// 
// JSONObject obj = new JSONObject();
// obj.put("token", token);
// obj.put("userInfo", sysUser);
// obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
// result.setResult(obj);
// result.success("登录成功");
// 
// return result;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) SysUser(org.jeecg.modules.system.entity.SysUser) EncryptedString(org.jeecg.common.util.encryption.EncryptedString) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) JSONObject(com.alibaba.fastjson.JSONObject) SysRole(org.jeecg.modules.system.entity.SysRole) SysDepart(org.jeecg.modules.system.entity.SysDepart) ApiOperation(io.swagger.annotations.ApiOperation)

Example 77 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysAnnouncementController method exportXls.

/**
 * 导出excel
 *
 * @param request
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysAnnouncement sysAnnouncement, HttpServletRequest request) {
    // Step.1 组装查询条件
    LambdaQueryWrapper<SysAnnouncement> queryWrapper = new LambdaQueryWrapper<SysAnnouncement>(sysAnnouncement);
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    queryWrapper.eq(SysAnnouncement::getDelFlag, CommonConstant.DEL_FLAG_0);
    List<SysAnnouncement> pageList = sysAnnouncementService.list(queryWrapper);
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "系统通告列表");
    mv.addObject(NormalExcelConstants.CLASS, SysAnnouncement.class);
    LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("系统通告列表数据", "导出人:" + user.getRealname(), "导出信息"));
    mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    return mv;
}
Also used : ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) SysAnnouncement(org.jeecg.modules.system.entity.SysAnnouncement) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView) LoginUser(org.jeecg.common.system.vo.LoginUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 78 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysAnnouncementController method listByUser.

/**
 * @功能:补充用户数据,并返回系统消息
 * @return
 */
@RequestMapping(value = "/listByUser", method = RequestMethod.GET)
public Result<Map<String, Object>> listByUser() {
    Result<Map<String, Object>> result = new Result<Map<String, Object>>();
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    String userId = sysUser.getId();
    // 1.将系统消息补充到用户通告阅读标记表中
    LambdaQueryWrapper<SysAnnouncement> querySaWrapper = new LambdaQueryWrapper<SysAnnouncement>();
    // 全部人员
    querySaWrapper.eq(SysAnnouncement::getMsgType, CommonConstant.MSG_TYPE_ALL);
    // 未删除
    querySaWrapper.eq(SysAnnouncement::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
    // 已发布
    querySaWrapper.eq(SysAnnouncement::getSendStatus, CommonConstant.HAS_SEND);
    // 新注册用户不看结束通知
    querySaWrapper.ge(SysAnnouncement::getEndTime, sysUser.getCreateTime());
    // update-begin--Author:liusq  Date:20210108 for:[JT-424] 【开源issue】bug处理--------------------
    querySaWrapper.notInSql(SysAnnouncement::getId, "select annt_id from sys_announcement_send where user_id='" + userId + "'");
    // update-begin--Author:liusq  Date:20210108  for: [JT-424] 【开源issue】bug处理--------------------
    List<SysAnnouncement> announcements = sysAnnouncementService.list(querySaWrapper);
    if (announcements.size() > 0) {
        for (int i = 0; i < announcements.size(); i++) {
            // update-begin--Author:wangshuai  Date:20200803  for: 通知公告消息重复LOWCOD-759--------------------
            // 因为websocket没有判断是否存在这个用户,要是判断会出现问题,故在此判断逻辑
            LambdaQueryWrapper<SysAnnouncementSend> query = new LambdaQueryWrapper<>();
            query.eq(SysAnnouncementSend::getAnntId, announcements.get(i).getId());
            query.eq(SysAnnouncementSend::getUserId, userId);
            SysAnnouncementSend one = sysAnnouncementSendService.getOne(query);
            if (null == one) {
                SysAnnouncementSend announcementSend = new SysAnnouncementSend();
                announcementSend.setAnntId(announcements.get(i).getId());
                announcementSend.setUserId(userId);
                announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
                sysAnnouncementSendService.save(announcementSend);
            }
        // update-end--Author:wangshuai  Date:20200803  for: 通知公告消息重复LOWCOD-759------------
        }
    }
    // 2.查询用户未读的系统消息
    Page<SysAnnouncement> anntMsgList = new Page<SysAnnouncement>(0, 5);
    // 通知公告消息
    anntMsgList = sysAnnouncementService.querySysCementPageByUserId(anntMsgList, userId, "1");
    Page<SysAnnouncement> sysMsgList = new Page<SysAnnouncement>(0, 5);
    // 系统消息
    sysMsgList = sysAnnouncementService.querySysCementPageByUserId(sysMsgList, userId, "2");
    Map<String, Object> sysMsgMap = new HashMap<String, Object>();
    sysMsgMap.put("sysMsgList", sysMsgList.getRecords());
    sysMsgMap.put("sysMsgTotal", sysMsgList.getTotal());
    sysMsgMap.put("anntMsgList", anntMsgList.getRecords());
    sysMsgMap.put("anntMsgTotal", anntMsgList.getTotal());
    result.setSuccess(true);
    result.setResult(sysMsgMap);
    return result;
}
Also used : SysAnnouncementSend(org.jeecg.modules.system.entity.SysAnnouncementSend) SysAnnouncement(org.jeecg.modules.system.entity.SysAnnouncement) HashMap(java.util.HashMap) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) LoginUser(org.jeecg.common.system.vo.LoginUser) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 79 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysDepartPermissionController method queryTreeListForDeptRole.

/**
 * 用户角色授权功能,查询菜单权限树
 * @param request
 * @return
 */
@RequestMapping(value = "/queryTreeListForDeptRole", method = RequestMethod.GET)
public Result<Map<String, Object>> queryTreeListForDeptRole(@RequestParam(name = "departId", required = true) String departId, HttpServletRequest request) {
    Result<Map<String, Object>> result = new Result<>();
    // 全部权限ids
    List<String> ids = new ArrayList<>();
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        query.inSql(SysPermission::getId, "select permission_id  from sys_depart_permission where depart_id='" + departId + "'");
        List<SysPermission> list = sysPermissionService.list(query);
        for (SysPermission sysPer : list) {
            ids.add(sysPer.getId());
        }
        List<TreeModel> treeList = new ArrayList<>();
        getTreeModelList(treeList, list, null);
        Map<String, Object> resMap = new HashMap<String, Object>();
        // 全部树节点数据
        resMap.put("treeList", treeList);
        // 全部树ids
        resMap.put("ids", ids);
        result.setResult(resMap);
        result.setSuccess(true);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return result;
}
Also used : Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) TreeModel(org.jeecg.modules.system.model.TreeModel) SysPermission(org.jeecg.modules.system.entity.SysPermission) JSONObject(com.alibaba.fastjson.JSONObject)

Example 80 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class SysDictController method treeList.

/**
 * @功能:获取树形字典数据
 * @param sysDict
 * @param pageNo
 * @param pageSize
 * @param req
 * @return
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/treeList", method = RequestMethod.GET)
public Result<List<SysDictTree>> treeList(SysDict sysDict, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
    Result<List<SysDictTree>> result = new Result<>();
    LambdaQueryWrapper<SysDict> query = new LambdaQueryWrapper<>();
    // 构造查询条件
    String dictName = sysDict.getDictName();
    if (oConvertUtils.isNotEmpty(dictName)) {
        query.like(true, SysDict::getDictName, dictName);
    }
    query.orderByDesc(true, SysDict::getCreateTime);
    List<SysDict> list = sysDictService.list(query);
    List<SysDictTree> treeList = new ArrayList<>();
    for (SysDict node : list) {
        treeList.add(new SysDictTree(node));
    }
    result.setSuccess(true);
    result.setResult(treeList);
    return result;
}
Also used : SysDictTree(org.jeecg.modules.system.model.SysDictTree) SysDict(org.jeecg.modules.system.entity.SysDict) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)381 Transactional (org.springframework.transaction.annotation.Transactional)60 JSONObject (com.alibaba.fastjson.JSONObject)52 Result (org.jeecg.common.api.vo.Result)50 ArrayList (java.util.ArrayList)42 List (java.util.List)30 Map (java.util.Map)29 Collectors (java.util.stream.Collectors)26 Service (org.springframework.stereotype.Service)24 LoginUser (org.jeecg.common.system.vo.LoginUser)22 SysPermission (org.jeecg.modules.system.entity.SysPermission)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)21 IPage (com.baomidou.mybatisplus.core.metadata.IPage)20 HashMap (java.util.HashMap)20 SysUser (org.jeecg.modules.system.entity.SysUser)20 ApiOperation (io.swagger.annotations.ApiOperation)19 ServiceException (cn.lili.common.exception.ServiceException)18 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)18 Autowired (org.springframework.beans.factory.annotation.Autowired)18