| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package jnpf.permission.service.impl;
- import cn.hutool.core.collection.CollectionUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.google.common.collect.Lists;
- import jnpf.base.service.SuperServiceImpl;
- import jnpf.constant.CodeConst;
- import jnpf.permission.entity.GroupEntity;
- import jnpf.permission.mapper.GroupMapper;
- import jnpf.permission.model.usergroup.GroupPagination;
- import jnpf.permission.service.CodeNumService;
- import jnpf.permission.service.GroupService;
- import jnpf.util.DateUtil;
- import jnpf.util.RandomUtil;
- import jnpf.util.StringUtil;
- import jnpf.util.UserProvider;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.Collections;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.stream.Collectors;
- /**
- * 分组管理业务类实现类
- *
- * @author :JNPF开发平台组
- * @version: V3.1.0
- * @copyright 引迈信息技术有限公司
- * @date :2022/3/10 18:00
- */
- @Service
- public class GroupServiceImpl extends SuperServiceImpl<GroupMapper, GroupEntity> implements GroupService {
- @Autowired
- private CodeNumService codeNumService;
- @Override
- public List<GroupEntity> getList(GroupPagination pagination) {
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- // 定义变量判断是否需要使用修改时间倒序
- boolean flag = false;
- // 判断关键字
- String keyword = pagination.getKeyword();
- if (StringUtil.isNotEmpty(keyword)) {
- flag = true;
- queryWrapper.lambda().and(
- t -> t.like(GroupEntity::getFullName, keyword)
- .or().like(GroupEntity::getEnCode, keyword)
- .or().like(GroupEntity::getDescription, keyword)
- );
- }
- if (pagination.getEnabledMark() != null) {
- queryWrapper.lambda().eq(GroupEntity::getEnabledMark, pagination.getEnabledMark());
- }
- // 获取列表
- queryWrapper.lambda().orderByAsc(GroupEntity::getSortCode).orderByAsc(GroupEntity::getCreatorTime);
- if (flag) {
- queryWrapper.lambda().orderByDesc(GroupEntity::getLastModifyTime);
- }
- //不分页
- if (Objects.equals(pagination.getDataType(), 1)) {
- return list(queryWrapper);
- }
- //有分页
- Page<GroupEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
- IPage<GroupEntity> iPage = this.page(page, queryWrapper);
- return pagination.setData(iPage.getRecords(), iPage.getTotal());
- }
- @Override
- public List<GroupEntity> list() {
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(GroupEntity::getEnabledMark, 1);
- queryWrapper.lambda().orderByAsc(GroupEntity::getSortCode).orderByAsc(GroupEntity::getCreatorTime);
- return this.list(queryWrapper);
- }
- @Override
- public Map<String, Object> getGroupMap() {
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().select(GroupEntity::getId, GroupEntity::getFullName);
- return this.list(queryWrapper).stream().collect(Collectors.toMap(GroupEntity::getId, GroupEntity::getFullName));
- }
- @Override
- public Map<String, Object> getGroupEncodeMap() {
- return getGroupEncodeMap(false);
- }
- @Override
- public Map<String, Object> getGroupEncodeMap(boolean enabledMark) {
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- if (enabledMark) {
- queryWrapper.lambda().eq(GroupEntity::getEnabledMark, 1);
- }
- queryWrapper.lambda().select(GroupEntity::getId, GroupEntity::getFullName, GroupEntity::getEnCode);
- return this.list(queryWrapper).stream().collect(Collectors.toMap(group -> group.getFullName() + "/" + group.getEnCode(), GroupEntity::getId));
- }
- @Override
- public GroupEntity getInfo(String id) {
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(GroupEntity::getId, id);
- return this.getOne(queryWrapper);
- }
- @Override
- public GroupEntity getInfo(String fullName, String enCode) {
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(GroupEntity::getFullName, fullName);
- queryWrapper.lambda().eq(GroupEntity::getEnCode, enCode);
- return this.getOne(queryWrapper);
- }
- @Override
- public void crete(GroupEntity entity) {
- entity.setId(RandomUtil.uuId());
- if (StringUtil.isEmpty(entity.getEnCode())) {
- entity.setEnCode(codeNumService.getCodeFunction(() -> codeNumService.getCodeOnce(CodeConst.YHZ), code -> this.isExistByEnCode(code, null)));
- }
- entity.setCreatorUserId(UserProvider.getUser().getUserId());
- entity.setCreatorTime(DateUtil.getNowDate());
- entity.setEnabledMark(1);
- this.save(entity);
- }
- @Override
- public Boolean update(String id, GroupEntity entity) {
- entity.setId(id);
- if (StringUtil.isEmpty(entity.getEnCode())) {
- entity.setEnCode(codeNumService.getCodeFunction(() -> codeNumService.getCodeOnce(CodeConst.YHZ), code -> this.isExistByEnCode(code, id)));
- }
- entity.setLastModifyUserId(UserProvider.getUser().getUserId());
- entity.setLastModifyTime(DateUtil.getNowDate());
- entity.setEnabledMark(1);
- return this.updateById(entity);
- }
- @Override
- public void delete(GroupEntity entity) {
- this.removeById(entity.getId());
- }
- @Override
- public Boolean isExistByFullName(String fullName, String id) {
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(GroupEntity::getFullName, fullName);
- if (!StringUtil.isEmpty(id)) {
- queryWrapper.lambda().ne(GroupEntity::getId, id);
- }
- return this.count(queryWrapper) > 0;
- }
- @Override
- public Boolean isExistByEnCode(String enCode, String id) {
- if (StringUtil.isEmpty(enCode)) return false;
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(GroupEntity::getEnCode, enCode);
- if (!StringUtil.isEmpty(id)) {
- queryWrapper.lambda().ne(GroupEntity::getId, id);
- }
- return this.count(queryWrapper) > 0;
- }
- @Override
- public List<GroupEntity> getListByIds(List<String> idList) {
- return getListByIds(idList, true);
- }
- @Override
- public List<GroupEntity> getListByIds(List<String> idList, Boolean filterEnabledMark) {
- if (CollectionUtil.isEmpty(idList)) return Collections.EMPTY_LIST;
- QueryWrapper<GroupEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().in(GroupEntity::getId, idList);
- if (idList.size() > 1000) {
- List<List<String>> lists = Lists.partition(idList, 1000);
- queryWrapper.lambda().and(t -> {
- for (List<String> list : lists) {
- t.in(GroupEntity::getId, list).or();
- }
- });
- } else {
- queryWrapper.lambda().in(GroupEntity::getId, idList);
- }
- if (filterEnabledMark) {
- queryWrapper.lambda().eq(GroupEntity::getEnabledMark, 1);
- }
- return this.list(queryWrapper);
- }
- }
|