Search in sources :

Example 6 with Wrappers

use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project SurveyKing by javahuang.

the class RepoServiceImpl method batchAddRepoTemplate.

@Override
public void batchAddRepoTemplate(RepoTemplateRequest request) {
    List<Tag> tagList = new ArrayList<>();
    List<TemplateRequest> templatesAdd = new ArrayList<>();
    List<TemplateRequest> templatesUpdate = new ArrayList<>();
    List<RepoTemplate> repoTemplatesAdd = new ArrayList<>();
    request.getTemplates().forEach(template -> {
        RepoTemplate repoTemplate = new RepoTemplate();
        if (template.getId() == null) {
            template.setId(IdWorker.getIdStr());
            templatesAdd.add(template);
            if (request.getRepoId() != null) {
                repoTemplate.setRepoId(request.getRepoId());
                repoTemplate.setTemplateId(template.getId());
                repoTemplatesAdd.add(repoTemplate);
            }
        } else {
            templatesUpdate.add(template);
        }
        // template 里面的 tags 冗余了
        if (template.getTemplate().getTags() != null) {
            template.setTag(template.getTemplate().getTags().toArray(new String[0]));
        }
        List<String> tags = template.getTemplate().getTags();
        if (tags != null && tags.size() > 0) {
            tags.forEach(tagStr -> {
                Tag tag = new Tag();
                tag.setName(tagStr);
                tag.setEntityId(template.getId());
                tag.setCategory(TagCategoryEnum.template.name());
                tagList.add(tag);
            });
        }
        template.setQuestionType(template.getTemplate().getType());
    });
    if (templatesAdd.size() > 0) {
        // 添加模板的时候,需要添加题库与模板的关联关系
        templateService.batchAddTemplate(templatesAdd);
        repoTemplateService.saveBatch(repoTemplatesAdd);
    }
    if (templatesUpdate.size() > 0) {
        templateService.batchUpdateTemplate(templatesUpdate);
        // 更新模板时需要删除之前的标签
        tagService.remove(Wrappers.<Tag>lambdaUpdate().eq(Tag::getEntityId, templatesUpdate.stream().map(x -> x.getId()).collect(Collectors.toList())));
    }
    // 添加模板问题标签
    if (tagList.size() > 0) {
        tagService.saveBatch(tagList);
    }
}
Also used : IdWorker(com.baomidou.mybatisplus.core.toolkit.IdWorker) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) RepoViewMapper(cn.surveyking.server.domain.mapper.RepoViewMapper) BaseService(cn.surveyking.server.service.BaseService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Repo(cn.surveyking.server.domain.model.Repo) RepoTemplate(cn.surveyking.server.domain.model.RepoTemplate) Tag(cn.surveyking.server.domain.model.Tag) Collectors(java.util.stream.Collectors) TagCategoryEnum(cn.surveyking.server.core.constant.TagCategoryEnum) cn.surveyking.server.domain.dto(cn.surveyking.server.domain.dto) ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) PaginationResponse(cn.surveyking.server.core.common.PaginationResponse) List(java.util.List) StringUtils.isNotBlank(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank) RepoMapper(cn.surveyking.server.mapper.RepoMapper) Service(org.springframework.stereotype.Service) CollectionUtils(org.springframework.util.CollectionUtils) Template(cn.surveyking.server.domain.model.Template) RepoService(cn.surveyking.server.service.RepoService) Transactional(org.springframework.transaction.annotation.Transactional) ArrayList(java.util.ArrayList) RepoTemplate(cn.surveyking.server.domain.model.RepoTemplate) Tag(cn.surveyking.server.domain.model.Tag)

Example 7 with Wrappers

use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project SurveyKing by javahuang.

the class AbstractTaskHandler method getHistoricTree.

/**
 * 将任务流转记录转换成一棵节点树
 * @param processInstanceId 任务实例 ID
 * @return 最后一个操作节点
 */
protected TaskTreeNode getHistoricTree(String processInstanceId) {
    List<String> approvalTypes = new ArrayList<>();
    approvalTypes.add(FlowApprovalType.SAVE);
    approvalTypes.add(FlowApprovalType.AGREE);
    approvalTypes.add(FlowApprovalType.ROLLBACK);
    approvalTypes.add(FlowApprovalType.REVERT);
    List<FlowOperation> operations = flowOperationService.list(Wrappers.<FlowOperation>lambdaQuery().eq(FlowOperation::getInstanceId, processInstanceId).in(FlowOperation::getApprovalType, approvalTypes).orderByAsc(FlowOperation::getCreateAt));
    TaskTreeNode rootNode = null, lastNode = null;
    for (int i = 0; i < operations.size(); i++) {
        FlowOperation operation = operations.get(i);
        TaskTreeNode currNode = new TaskTreeNode();
        currNode.setId(operation.getId());
        currNode.setActivityId(operation.getActivityId());
        if (i == 0) {
            rootNode = currNode;
            lastNode = currNode;
            continue;
        }
        if (lastNode != null && lastNode.getActivityId() != null && lastNode.getActivityId().equals(currNode.getActivityId())) {
            continue;
        }
        if (FlowApprovalType.SAVE.equals(operation.getApprovalType())) {
            lastNode = rootNode;
            continue;
        } else if (FlowApprovalType.AGREE.equals(operation.getApprovalType())) {
            currNode.setParent(lastNode);
            if (lastNode.getChildren().stream().noneMatch(node -> node.getActivityId().equals(currNode.getActivityId()))) {
                lastNode.getChildren().add(currNode);
            }
        } else if (FlowApprovalType.ROLLBACK.equals(operation.getApprovalType())) {
            lastNode = lastNode.findParentByKey(operation.getNewActivityId());
            continue;
        } else if (FlowApprovalType.REVERT.equals(operation.getApprovalType())) {
        // 撤回节点的 taskDefKey 和已完成节点是一致的
        }
        lastNode = currNode;
    }
    return lastNode;
}
Also used : FlowEntryNode(cn.surveyking.server.flow.domain.model.FlowEntryNode) TaskService(org.flowable.engine.TaskService) FlowTaskType(cn.surveyking.server.flow.constant.FlowTaskType) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) UserService(cn.surveyking.server.service.UserService) AnswerQuery(cn.surveyking.server.domain.dto.AnswerQuery) cn.surveyking.server.flow.service(cn.surveyking.server.flow.service) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) FlowApprovalType(cn.surveyking.server.flow.constant.FlowApprovalType) BpmnModel(org.flowable.bpmn.model.BpmnModel) RuntimeService(org.flowable.engine.RuntimeService) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance) AnswerView(cn.surveyking.server.domain.dto.AnswerView) FlowConstant(cn.surveyking.server.flow.constant.FlowConstant) SecurityContextUtils(cn.surveyking.server.core.uitls.SecurityContextUtils) FieldPermissionType(cn.surveyking.server.flow.constant.FieldPermissionType) Task(org.flowable.task.api.Task) FlowOperation(cn.surveyking.server.flow.domain.model.FlowOperation) AnswerRequest(cn.surveyking.server.domain.dto.AnswerRequest) FlowOperationMapper(cn.surveyking.server.flow.mapper.FlowOperationMapper) FlowOperationUser(cn.surveyking.server.flow.domain.model.FlowOperationUser) List(java.util.List) HistoryService(org.flowable.engine.HistoryService) FlowEntry(cn.surveyking.server.flow.domain.model.FlowEntry) StartEvent(org.flowable.bpmn.model.StartEvent) Data(lombok.Data) ApprovalTaskRequest(cn.surveyking.server.flow.domain.dto.ApprovalTaskRequest) RepositoryService(org.flowable.engine.RepositoryService) UpdateFlowOperationUserRequest(cn.surveyking.server.flow.domain.dto.UpdateFlowOperationUserRequest) AnswerService(cn.surveyking.server.service.AnswerService) FlowOperation(cn.surveyking.server.flow.domain.model.FlowOperation) ArrayList(java.util.ArrayList)

Example 8 with Wrappers

use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project albedo by somowhere.

the class DeptRelationServiceImpl method saveDeptRelation.

/**
 * 维护部门关系
 *
 * @param deptDto 部门
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void saveDeptRelation(DeptDto deptDto) {
    // 增加部门关系表
    DeptRelationDo condition = new DeptRelationDo();
    condition.setDescendant(deptDto.getParentId());
    List<DeptRelationDo> relationList = deptRelationRepository.selectList(Wrappers.<DeptRelationDo>query().lambda().eq(DeptRelationDo::getDescendant, deptDto.getParentId())).stream().map(relation -> {
        relation.setDescendant(deptDto.getId());
        return relation;
    }).collect(Collectors.toList());
    if (CollUtil.isNotEmpty(relationList)) {
        this.saveBatch(relationList);
    }
    // 自己也要维护到关系表中
    DeptRelationDo own = new DeptRelationDo();
    own.setDescendant(deptDto.getId());
    own.setAncestor(deptDto.getId());
    deptRelationRepository.insert(own);
}
Also used : Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) DeptRelationRepository(com.albedo.java.modules.sys.repository.DeptRelationRepository) List(java.util.List) DeptRelationDo(com.albedo.java.modules.sys.domain.DeptRelationDo) CollUtil(com.albedo.java.common.core.util.CollUtil) Service(org.springframework.stereotype.Service) AllArgsConstructor(lombok.AllArgsConstructor) BaseServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.BaseServiceImpl) Collectors(java.util.stream.Collectors) DeptDto(com.albedo.java.modules.sys.domain.dto.DeptDto) DeptRelationService(com.albedo.java.modules.sys.service.DeptRelationService) Transactional(org.springframework.transaction.annotation.Transactional) DeptRelationDo(com.albedo.java.modules.sys.domain.DeptRelationDo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Wrappers

use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project tansci by typ1805.

the class SysOrgServiceImpl method list.

@Override
public List<SysOrg> list(SysOrg sysOrg) {
    LambdaQueryWrapper queryWrapper = null;
    if (Objects.equals(0, SecurityUserUtils.getUser().getType())) {
        queryWrapper = Wrappers.<SysOrg>lambdaQuery().eq(SysOrg::getDelFlag, 0).like(Objects.nonNull(sysOrg.getName()), SysOrg::getName, sysOrg.getName()).orderByDesc(SysOrg::getCreateTime);
    } else {
        queryWrapper = Wrappers.<SysOrg>lambdaQuery().eq(SysOrg::getDelFlag, 0).in(SysOrg::getId, SecurityUserUtils.getUser().getOrgIds()).like(Objects.nonNull(sysOrg.getName()), SysOrg::getName, sysOrg.getName()).orderByDesc(SysOrg::getCreateTime);
    }
    List<SysOrg> orgList = this.baseMapper.selectList(queryWrapper);
    List<SysOrg> newOrgList = orgList.stream().filter(item -> item.getParentId() == 0).map(item -> {
        item.setChildren(this.getChildrens(item, orgList));
        return item;
    }).sorted((item1, item2) -> {
        return (item1.getSort() == null ? 0 : item1.getSort()) - (item2.getSort() == null ? 0 : item2.getSort());
    }).collect(Collectors.toList());
    return newOrgList.size() > 0 ? newOrgList : orgList;
}
Also used : ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) SecurityUserUtils(com.tansci.utils.SecurityUserUtils) SysOrgRole(com.tansci.domain.system.SysOrgRole) SysOrgService(com.tansci.service.system.SysOrgService) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Collectors(java.util.stream.Collectors) SysOrgRoleService(com.tansci.service.system.SysOrgRoleService) ArrayList(java.util.ArrayList) SysOrgMapper(com.tansci.mapper.system.SysOrgMapper) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) SysOrg(com.tansci.domain.system.SysOrg) Transactional(org.springframework.transaction.annotation.Transactional) SysOrg(com.tansci.domain.system.SysOrg) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 10 with Wrappers

use of com.baomidou.mybatisplus.core.toolkit.Wrappers in project tansci by typ1805.

the class SysRoleServiceImpl method page.

@Override
public IPage<SysRole> page(Page page, SysRole role) {
    LambdaQueryWrapper queryWrapper = null;
    if (Objects.equals(0, SecurityUserUtils.getUser().getType())) {
        queryWrapper = Wrappers.<SysRole>lambdaQuery().like(Objects.nonNull(role.getName()), SysRole::getName, role.getName()).orderByDesc(SysRole::getCreateTime, SysRole::getUpdateTime);
    } else {
        List<SysUserOrg> orgs = sysUserOrgService.list(Wrappers.<SysUserOrg>lambdaQuery().in(SysUserOrg::getOrgId, SecurityUserUtils.getUser().getOrgIds()));
        List<String> userIds = new ArrayList<>();
        if (Objects.nonNull(orgs) && orgs.size() > 0) {
            userIds = orgs.stream().map(SysUserOrg::getUserId).distinct().collect(Collectors.toList());
        } else {
            userIds.add(SecurityUserUtils.getUser().getId());
        }
        queryWrapper = Wrappers.<SysRole>lambdaQuery().in(SysRole::getCreator, userIds).like(Objects.nonNull(role.getName()), SysRole::getName, role.getName()).orderByDesc(SysRole::getCreateTime, SysRole::getUpdateTime);
    }
    IPage<SysRole> roleIPage = this.baseMapper.selectPage(page, queryWrapper);
    List<SysDic> statusList = roleIPage.getSize() > 0 ? sysDicService.list(Wrappers.<SysDic>lambdaQuery().eq(SysDic::getGroupName, "role_status")) : new ArrayList<>();
    roleIPage.getRecords().forEach(item -> {
        Optional<SysDic> sOptional = statusList.stream().filter(s -> s.getDicValue() == item.getStatus()).findFirst();
        if (sOptional.isPresent()) {
            item.setStatusName(sOptional.get().getDicLabel());
        }
        item.setTypeName(Enums.getVlaueByGroup(item.getType(), "role_type"));
    });
    return roleIPage;
}
Also used : ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) SecurityUserUtils(com.tansci.utils.SecurityUserUtils) Enums(com.tansci.common.constant.Enums) com.tansci.service.system(com.tansci.service.system) java.util(java.util) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Collectors(java.util.stream.Collectors) Transient(java.beans.Transient) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) SysMenuRoleVo(com.tansci.domain.system.vo.SysMenuRoleVo) Slf4j(lombok.extern.slf4j.Slf4j) com.tansci.domain.system(com.tansci.domain.system) SysRoleMapper(com.tansci.mapper.system.SysRoleMapper) Service(org.springframework.stereotype.Service) SysRoleDto(com.tansci.domain.system.dto.SysRoleDto) IPage(com.baomidou.mybatisplus.core.metadata.IPage) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)16 Collectors (java.util.stream.Collectors)15 Service (org.springframework.stereotype.Service)14 List (java.util.List)13 Transactional (org.springframework.transaction.annotation.Transactional)11 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)8 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ArrayList (java.util.ArrayList)4 RequiredArgsConstructor (lombok.RequiredArgsConstructor)4 StrUtil (cn.hutool.core.util.StrUtil)3 Arrays (java.util.Arrays)3 Slf4j (lombok.extern.slf4j.Slf4j)3 SecurityContextUtils (cn.surveyking.server.core.uitls.SecurityContextUtils)2 BaseService (cn.surveyking.server.service.BaseService)2 UserService (cn.surveyking.server.service.UserService)2 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)2 RoleMenuService (com.albedo.java.modules.sys.service.RoleMenuService)2 SysCacheUtil (com.albedo.java.modules.sys.util.SysCacheUtil)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)2