|
|
@@ -0,0 +1,181 @@
|
|
|
+package org.dromara.hotel.service.impl;
|
|
|
+
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.SpringUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.encrypt.interceptor.MybatisDecryptInterceptor;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.hotel.domain.bo.KfAreaPermissionsBo;
|
|
|
+import org.dromara.hotel.domain.vo.KfAreaPermissionsVo;
|
|
|
+import org.dromara.hotel.domain.KfAreaPermissions;
|
|
|
+import org.dromara.hotel.mapper.KfAreaPermissionsMapper;
|
|
|
+import org.dromara.hotel.service.IKfAreaPermissionsService;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 客房权限Service业务层处理
|
|
|
+ *
|
|
|
+ * @author LionLi
|
|
|
+ * @date 2024-11-12
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class KfAreaPermissionsServiceImpl implements IKfAreaPermissionsService {
|
|
|
+
|
|
|
+ private final KfAreaPermissionsMapper baseMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询客房权限
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 客房权限
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public KfAreaPermissionsVo queryById(Long id){
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询客房权限列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 客房权限分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<KfAreaPermissionsVo> queryPageList(KfAreaPermissionsBo bo, PageQuery pageQuery) {
|
|
|
+ Page<KfAreaPermissionsVo> result = baseMapper.selectByBo(pageQuery.build(), bo);
|
|
|
+ //返回数据解密
|
|
|
+ MybatisDecryptInterceptor dencrypt = SpringUtils.getBean(MybatisDecryptInterceptor.class);
|
|
|
+ result.getRecords().stream().forEach(item -> {
|
|
|
+ item.setPhone(dencrypt.decrypt(item.getPhone()));
|
|
|
+ });
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的客房权限列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 客房权限列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<KfAreaPermissionsVo> queryList(KfAreaPermissionsBo bo) {
|
|
|
+ LambdaQueryWrapper<KfAreaPermissions> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<KfAreaPermissions> buildQueryWrapper(KfAreaPermissionsBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<KfAreaPermissions> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getAreaId() != null, KfAreaPermissions::getAreaId, bo.getAreaId());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ private QueryWrapper<KfAreaPermissions> buildQueryWrapper(KfAreaPermissionsBo bo,String tableAlias) {
|
|
|
+ QueryWrapper<KfAreaPermissions> lqw = new QueryWrapper<>();
|
|
|
+ String columnPrefix = "";
|
|
|
+ if(StringUtils.isNotBlank(tableAlias)){
|
|
|
+ columnPrefix = tableAlias + ".";
|
|
|
+ }
|
|
|
+ lqw.eq(bo.getAreaId() != null, columnPrefix+"area_id", bo.getAreaId());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增客房权限
|
|
|
+ *
|
|
|
+ * @param bo 客房权限
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(KfAreaPermissionsBo bo) {
|
|
|
+ KfAreaPermissions add = MapstructUtils.convert(bo, KfAreaPermissions.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertBatch(Long[] areaIds, String[] userIds) {
|
|
|
+ List<KfAreaPermissions> permissionsList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 校验输入参数
|
|
|
+ if (areaIds == null || userIds == null || areaIds.length == 0 || userIds.length == 0) {
|
|
|
+ throw new IllegalArgumentException("areaIds and userIds must not be null or empty");
|
|
|
+ }
|
|
|
+ Map<Long, String> resMap = groupByAreaIds(areaIds).stream()
|
|
|
+ .collect(Collectors.toMap(map -> Long.parseLong(map.get("area_id").toString()), map -> map.get("user_id").toString()));
|
|
|
+ // 构建权限对象列表
|
|
|
+ for (Long areaId : areaIds) {
|
|
|
+ String dbUserIds = resMap.get(areaId);
|
|
|
+ for (String userId : userIds) {
|
|
|
+ if (dbUserIds == null || !dbUserIds.contains(userId)) {
|
|
|
+ KfAreaPermissions permissions = new KfAreaPermissions();
|
|
|
+ permissions.setAreaId(areaId);
|
|
|
+ permissions.setUserId(userId);
|
|
|
+ permissionsList.add(permissions);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean flag = baseMapper.insertBatch(permissionsList);
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改客房权限
|
|
|
+ *
|
|
|
+ * @param bo 客房权限
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(KfAreaPermissionsBo bo) {
|
|
|
+ KfAreaPermissions update = MapstructUtils.convert(bo, KfAreaPermissions.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(KfAreaPermissions entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除客房权限信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> groupByAreaIds(Long[] areaIds) {
|
|
|
+ QueryWrapper<KfAreaPermissions> qw = new QueryWrapper<>();
|
|
|
+ qw.select("area_id", "group_concat(user_id) as user_id");
|
|
|
+ qw.in("area_id", areaIds);
|
|
|
+ qw.groupBy("area_id");
|
|
|
+ return baseMapper.selectMaps(qw);
|
|
|
+ }
|
|
|
+}
|