diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java index 393c6dd9..13d3550f 100644 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java @@ -20,4 +20,6 @@ public interface ISysMenuData extends ICommonData { */ List findByUserId(Long userId); + List selectMenuList(SysMenu menu, Long userId, boolean isSuperAdmin); + } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java new file mode 100644 index 00000000..da9517e1 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java @@ -0,0 +1,22 @@ +package cc.iotkit.data.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.persistence.EntityManager; + +/** + * @Author: 石恒 + * @Date: 2023/5/28 16:58 + * @Description: + */ +@Configuration +public class JpaConfig { + + @Bean + public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) { + return new JPAQueryFactory(entityManager); + } + +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java index b2595d78..dc2f7298 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java @@ -27,6 +27,8 @@ import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.Order; import org.springframework.stereotype.Service; +import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig; + @Primary @Service @RequiredArgsConstructor diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java new file mode 100644 index 00000000..71e81c19 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java @@ -0,0 +1,144 @@ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.SysMenuRepository; +import cc.iotkit.data.model.TbSysConfig; +import cc.iotkit.data.model.TbSysMenu; +import cc.iotkit.data.system.ISysMenuData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysConfig; +import cc.iotkit.model.system.SysMenu; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +import javax.persistence.EntityManager; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import static cc.iotkit.data.model.QTbSysMenu.tbSysMenu; + + +/** + * @Author: 石恒 + * @Date: 2023/5/28 15:43 + * @Description: + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysMenuDataImpl implements ISysMenuData { + + private final SysMenuRepository sysMenuRepository; + + @Override + public SysMenu findById(Long id) { + TbSysMenu tbSysMenu = sysMenuRepository.findById(id).orElseThrow(() -> + new BizException(ErrCode.DATA_NOT_EXIST)); + return MapstructUtils.convert(tbSysMenu, SysMenu.class); + } + + @Override + public List findByIds(Collection ids) { + List list = sysMenuRepository.findAllById(ids); + return MapstructUtils.convert(list, SysMenu.class); + } + + @Override + public SysMenu save(SysMenu data) { + sysMenuRepository.save(MapstructUtils.convert(data, TbSysMenu.class)); + return data; + } + + @Override + public void batchSave(List data) { + List tbSysMenus = data.stream().map(e -> MapstructUtils.convert(e, TbSysMenu.class)).collect(Collectors.toList()); + sysMenuRepository.saveAll(tbSysMenus); + } + + @Override + public void deleteById(Long id) { + sysMenuRepository.deleteById(id); + } + + @Override + public void deleteByIds(Collection ids) { + sysMenuRepository.deleteAllByIdInBatch(ids); + } + + @Override + public long count() { + return 0; + } + + @Override + public List findAll() { + return null; + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return null; + } + + @Override + public List findAllByCondition(SysMenu data) { + return null; + } + + @Override + public SysMenu findOneByCondition(SysMenu data) { + return null; + } + + @Override + public List findByUserId(Long userId) { + return null; + } + + @Override + public List selectMenuList(SysMenu menu, Long userId, boolean isSuperAdmin) { + + PredicateBuilder predicateBuilder = PredicateBuilder.instance(tbSysMenu.menuId.isNotNull()); + + + // 管理员显示所有菜单信息 + if (isSuperAdmin) { + predicateBuilder + .and(StringUtils.isNotBlank(menu.getMenuName()), () -> tbSysMenu.menuName.like(menu.getMenuName())) + .and(StringUtils.isNotBlank(menu.getVisible()), () -> tbSysMenu.visible.eq(menu.getVisible())) + .and(StringUtils.isNotBlank(menu.getStatus()), () -> tbSysMenu.status.eq(menu.getStatus())); + + menuList = baseMapper.selectVoList(new LambdaQueryWrapper() + .like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName()) + .eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible()) + .eq(StringUtils.isNotBlank(menu.getStatus()), SysMenu::getStatus, menu.getStatus()) + .orderByAsc(SysMenu::getParentId) + .orderByAsc(SysMenu::getOrderNum)); + } else { + predicateBuilder.and(tbSysMenu.menuId.eq(userId)); + BooleanBuilder builder = new BooleanBuilder(); + QueryWrapper wrapper = Wrappers.query(); + wrapper.eq("sur.user_id", userId) + .like(StringUtils.isNotBlank(menu.getMenuName()), "m.menu_name", menu.getMenuName()) + .eq(StringUtils.isNotBlank(menu.getVisible()), "m.visible", menu.getVisible()) + .eq(StringUtils.isNotBlank(menu.getStatus()), "m.status", menu.getStatus()) + .orderByAsc("m.parent_id") + .orderByAsc("m.order_num"); + menuList = baseMapper.selectMenuListByUserId(wrapper); + } + Predicate predicate = predicateBuilder.build(); + sysMenuRepository.findAll(predicate); + + return menuList; + } +} diff --git a/iot-common/pom.xml b/iot-common/pom.xml index 8d6b09a4..eb3ca8bf 100644 --- a/iot-common/pom.xml +++ b/iot-common/pom.xml @@ -8,6 +8,7 @@ cc.iotkit ${revision} + ${revision} pom iot-common