Explorar o código

添加用户损益报表权限控制相关代码

JammeyJiang hai 8 meses
pai
achega
e9c5fb6720

+ 1 - 1
src/main/java/com/kcim/dao/model/UserReportRight.java

@@ -37,7 +37,7 @@ public class UserReportRight implements Serializable {
 	/**
 	 * 中台用户id
 	 */
-	private String userId;
+	private Long userId;
 	/**
 	 * 中台用户工号
 	 */

+ 1 - 1
src/main/java/com/kcim/dao/model/UserResponsibilityRight.java

@@ -37,7 +37,7 @@ public class UserResponsibilityRight implements Serializable {
 	/**
 	 * 中台用户id
 	 */
-	private String userId;
+	private Long userId;
 	/**
 	 * 中台用户工号
 	 */

+ 67 - 55
src/main/java/com/kcim/dao/repository/UserReportRightRepository.java

@@ -7,7 +7,9 @@ import com.kcim.dao.mapper.UserReportRightMapper;
 import com.kcim.dao.model.UserReportRight;
 import org.springframework.stereotype.Repository;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * @program: CostAccount
@@ -28,59 +30,69 @@ public class UserReportRightRepository extends ServiceImpl<UserReportRightMapper
         return this.list(queryWrapper);
     }
 
-//    public List<StandItem> getList(String name) {
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, UserContext.getHospId());
-//        if(!StringUtils.isEmpty(name)){
-//            queryWrapper.like(StandItem::getName, name);
-//        }
-//        return this.list(queryWrapper);
-//    }
-//
-//    public Page<StandItem> getPage(Integer current, Integer pageSize, String name, String kcClassCode) {
-//        Page<StandItem> page = new Page<>(current,pageSize);
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, UserContext.getHospId());
-//        if(!StringUtils.isEmpty(name)){
-////            queryWrapper.like(StandItem::getName,name);
-//            queryWrapper.and(q->q.like(StandItem::getName,name).or().like(StandItem::getNationalCode,name));
-//        }
-//        if(!StringUtils.isEmpty(kcClassCode)){
-//            queryWrapper.eq(StandItem::getKcClassCode,kcClassCode);
-//        }
-//        return this.page(page,queryWrapper);
-//    }
-//
-//    public StandItem getOneByCode(String code) {
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, UserContext.getHospId());
-//        queryWrapper.eq(StandItem::getCode,code);
-//        return this.getOne(queryWrapper);
-//    }
-//
-//    public void deleteStandItem(Integer id) {
-//        StandItem item = this.getById(id);
-//        if(Objects.nonNull(item)){
-//            item.setDeleteTime(new Date());
-//            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
-//            this.updateById(item);
-//            this.removeById(id);
-//        }
-//    }
-//
-//    public void removeList(List<StandItem> list) {
-//        for (StandItem item : list) {
-//            item.setDeleteTime(new Date());
-//            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
-//        }
-//        this.updateBatchById(list,100);
-//        List<Integer> collect = list.stream().map(StandItem::getId).collect(Collectors.toList());
-//        this.removeBatchByIds(collect,100);
-//    }
-//
-//    public List<StandItem> getList(SessionUserVO currentUser) {
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, currentUser.getHospId());
-//        return this.list(queryWrapper);
-//    }
+
+    /**
+     * 添加一个用户损益报表权限
+     * @param uerReportRight
+     */
+    public void addUserReportRight(UserReportRight uerReportRight) {
+        uerReportRight.setHospId(UserContext.getHospId());
+        uerReportRight.setCreateTime(new Date());
+        uerReportRight.setCreateUser(String.valueOf(UserContext.getCurrentUser().getId()));
+        this.save(uerReportRight);
+    }
+
+    /**
+     * 添加一个用户损益报表权限
+     * @param userId
+     * @param reportCode
+     */
+    public void addUserReportRight(Long userId,String  reportCode) {
+        UserReportRight uerReportRight = new UserReportRight();
+        uerReportRight.setHospId(UserContext.getHospId());
+        uerReportRight.setUserId(userId);
+        uerReportRight.setReportCode(reportCode);
+        uerReportRight.setCreateTime(new Date());
+        uerReportRight.setCreateUser(String.valueOf(UserContext.getCurrentUser().getId()));
+        this.save(uerReportRight);
+    }
+
+    /**
+     * 删除一个用户损益报表权限
+     * @param uerReportRight
+     */
+    public void deleteUserReportRight(UserReportRight uerReportRight) {
+        LambdaQueryWrapper<UserReportRight> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(UserReportRight::getHospId, UserContext.getHospId());
+        queryWrapper.eq(UserReportRight::getUserId, uerReportRight.getUserId());
+        queryWrapper.eq(UserReportRight::getReportCode, uerReportRight.getReportCode());
+        UserReportRight item = this.getOne(queryWrapper);
+        if(Objects.nonNull(item)){
+            item.setDeleteTime(new Date());
+            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
+            this.updateById(item);
+            this.removeById(item.getId());
+        }
+    }
+
+    /**
+     * 删除一个用户损益报表权限
+     * @param userId
+     * @param reportCode
+     */
+    public void deleteUserReportRight(Long userId,String  reportCode) {
+        LambdaQueryWrapper<UserReportRight> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(UserReportRight::getHospId, UserContext.getHospId());
+        queryWrapper.eq(UserReportRight::getUserId,userId);
+        queryWrapper.eq(UserReportRight::getReportCode, reportCode);
+        UserReportRight item = this.getOne(queryWrapper);
+        if(Objects.nonNull(item)){
+            item.setDeleteTime(new Date());
+            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
+            this.updateById(item);
+            this.removeById(item.getId());
+        }
+    }
+
+
 }

+ 93 - 56
src/main/java/com/kcim/dao/repository/UserResponsibilityRightRepository.java

@@ -6,8 +6,12 @@ import com.kcim.common.util.UserContext;
 import com.kcim.dao.mapper.UserResponsibilityRightMapper;
 import com.kcim.dao.model.UserResponsibilityRight;
 import org.springframework.stereotype.Repository;
+import org.springframework.util.CollectionUtils;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * @program: CostAccount
@@ -22,65 +26,98 @@ public class UserResponsibilityRightRepository extends ServiceImpl<UserResponsib
      * @return  列表
      */
     public List<UserResponsibilityRight> getList() {
+        return getListByUserId(UserContext.getCurrentUser().getId());
+    }
+
+    /**
+     * 获取指定用户有权限的列表
+     * @param userId
+     * @return
+     */
+    public List<UserResponsibilityRight> getListByUserId(Long userId) {
         LambdaQueryWrapper<UserResponsibilityRight> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(UserResponsibilityRight::getHospId, UserContext.getHospId());
-        queryWrapper.eq(UserResponsibilityRight::getUserId, UserContext.getCurrentUser().getId());
+        queryWrapper.eq(UserResponsibilityRight::getUserId, userId);
         return this.list(queryWrapper);
     }
 
-//    public List<StandItem> getList(String name) {
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, UserContext.getHospId());
-//        if(!StringUtils.isEmpty(name)){
-//            queryWrapper.like(StandItem::getName, name);
-//        }
-//        return this.list(queryWrapper);
-//    }
-//
-//    public Page<StandItem> getPage(Integer current, Integer pageSize, String name, String kcClassCode) {
-//        Page<StandItem> page = new Page<>(current,pageSize);
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, UserContext.getHospId());
-//        if(!StringUtils.isEmpty(name)){
-////            queryWrapper.like(StandItem::getName,name);
-//            queryWrapper.and(q->q.like(StandItem::getName,name).or().like(StandItem::getNationalCode,name));
-//        }
-//        if(!StringUtils.isEmpty(kcClassCode)){
-//            queryWrapper.eq(StandItem::getKcClassCode,kcClassCode);
-//        }
-//        return this.page(page,queryWrapper);
-//    }
-//
-//    public StandItem getOneByCode(String code) {
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, UserContext.getHospId());
-//        queryWrapper.eq(StandItem::getCode,code);
-//        return this.getOne(queryWrapper);
-//    }
-//
-//    public void deleteStandItem(Integer id) {
-//        StandItem item = this.getById(id);
-//        if(Objects.nonNull(item)){
-//            item.setDeleteTime(new Date());
-//            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
-//            this.updateById(item);
-//            this.removeById(id);
-//        }
-//    }
-//
-//    public void removeList(List<StandItem> list) {
-//        for (StandItem item : list) {
-//            item.setDeleteTime(new Date());
-//            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
-//        }
-//        this.updateBatchById(list,100);
-//        List<Integer> collect = list.stream().map(StandItem::getId).collect(Collectors.toList());
-//        this.removeBatchByIds(collect,100);
-//    }
-//
-//    public List<StandItem> getList(SessionUserVO currentUser) {
-//        LambdaQueryWrapper<StandItem> queryWrapper = new LambdaQueryWrapper<>();
-//        queryWrapper.eq(StandItem::getHospId, currentUser.getHospId());
-//        return this.list(queryWrapper);
-//    }
+    /**
+     * 批量删除指定用户责任中心权限
+     * @param list
+     */
+    public void removeUserResponsibilityRightList(List<UserResponsibilityRight> list){
+        if(!CollectionUtils.isEmpty(list)){
+            list.stream().forEach(userResponsibility-> {
+                userResponsibility.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
+                userResponsibility.setDeleteTime(new Date());
+            });
+            this.updateBatchById(list);
+            List<Integer> collect = list.stream().map(UserResponsibilityRight::getId).collect(Collectors.toList());
+            this.removeByIds(collect);
+        }
+    }
+
+    /**
+     * 添加一个用户责任中心权限
+     * @param userResponsibilityRight
+     */
+    public void addUserResponsibilityRight(UserResponsibilityRight userResponsibilityRight) {
+        userResponsibilityRight.setHospId(UserContext.getHospId());
+        userResponsibilityRight.setCreateTime(new Date());
+        userResponsibilityRight.setCreateUser(String.valueOf(UserContext.getCurrentUser().getId()));
+        this.save(userResponsibilityRight);
+    }
+
+    /**
+     * 添加一个用户责任中心权限
+     * @param userId
+     * @param responsibilityCode
+     */
+    public void addUserResponsibilityRight(Long userId,String  responsibilityCode) {
+        UserResponsibilityRight userResponsibilityRight = new UserResponsibilityRight();
+        userResponsibilityRight.setHospId(UserContext.getHospId());
+        userResponsibilityRight.setUserId(userId);
+        userResponsibilityRight.setResponsibilityCode(responsibilityCode);
+        userResponsibilityRight.setCreateTime(new Date());
+        userResponsibilityRight.setCreateUser(String.valueOf(UserContext.getCurrentUser().getId()));
+        this.save(userResponsibilityRight);
+    }
+
+    /**
+     * 删除一个用户责任中心权限
+     * @param userResponsibilityRight
+     */
+    public void deleteUserResponsibilityRight(UserResponsibilityRight userResponsibilityRight) {
+        LambdaQueryWrapper<UserResponsibilityRight> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(UserResponsibilityRight::getHospId, UserContext.getHospId());
+        queryWrapper.eq(UserResponsibilityRight::getUserId, userResponsibilityRight.getUserId());
+        queryWrapper.eq(UserResponsibilityRight::getResponsibilityCode, userResponsibilityRight.getResponsibilityCode());
+        UserResponsibilityRight item = this.getOne(queryWrapper);
+        if(Objects.nonNull(item)){
+            item.setDeleteTime(new Date());
+            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
+            this.updateById(item);
+            this.removeById(item.getId());
+        }
+    }
+
+    /**
+     * 删除指定用户的责任中心权限
+     * @param userId
+     * @param responsibilityCode
+     */
+    public void deleteUserResponsibilityRight(Long userId,String  responsibilityCode) {
+        LambdaQueryWrapper<UserResponsibilityRight> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(UserResponsibilityRight::getHospId, UserContext.getHospId());
+        queryWrapper.eq(UserResponsibilityRight::getUserId, userId);
+        queryWrapper.eq(UserResponsibilityRight::getResponsibilityCode, responsibilityCode);
+        UserResponsibilityRight item = this.getOne(queryWrapper);
+        if(Objects.nonNull(item)){
+            item.setDeleteTime(new Date());
+            item.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
+            this.updateById(item);
+            this.removeById(item.getId());
+        }
+    }
+
 }

+ 24 - 6
src/main/java/com/kcim/service/UserReportRightService.java

@@ -15,22 +15,40 @@ import java.util.List;
 public interface UserReportRightService extends IService<UserReportRight> {
 
     /**
-     * 获取用户的责任中心权限列
+     * 获取用户有权限的损益报
      * @return
      */
-    List<UserReportRight> getUserReportRight();
+    DictDataVo getUserReports();
 
     /**
-     * 获取用户有权限的损益报表列表
+     * 获取用户列表
+     * @param userName
      * @return
      */
-    List<UserReportRightVO> UserReportRightList();
+    Object getUserList(Integer current, Integer pageSize,String userName);
 
 
     /**
-     * 获取用户有权限的损益报表
+     * 获取用户有权限的损益报表列表
+     * @param reportName
+     * @param hideFlag
+     * @param userId
      * @return
      */
-    DictDataVo getUserReports();
+    List<UserReportRightVO> getUserReportRights(Long userId,String reportName, Integer hideFlag);
+
+    /**
+     * 修改指定用户的损益报表权限
+     * @param userId
+     * @param reportCode
+     * @param status
+     */
+    void editUserReportRight(Long userId, String reportCode, Integer status);
+
+    /**
+     * 编辑用户损益报表权限
+     * @param userReportRightVO
+     */
+    public void editUserReportRight(UserReportRightVO userReportRightVO);
 }
 

+ 22 - 1
src/main/java/com/kcim/service/UserResponsibilityRightService.java

@@ -22,10 +22,31 @@ public interface UserResponsibilityRightService  extends IService<UserResponsibi
 
     /**
      * 获取用户的责任中心权限列表
+     * @param responsibilityName
+     * @param hideFlag
      * @return
      */
-    UserResponsibilityRightVO UserResponsibilityRightList();
+    List<UserResponsibilityRightVO> getUserResponsibilityRights(Long userId,String responsibilityName, Integer hideFlag);
 
+    /**
+     * 编辑用户损益报表权限
+     * @param uerResponsibilityRightVO
+     */
+    void editUserResponsibilityRight(UserResponsibilityRightVO uerResponsibilityRightVO);
 
+    /**
+     * 修改指定用户的责任中心权限
+     * @param userId
+     * @param responsibilityCode
+     * @param status
+     */
+    void editUserResponsibilityRight(Long userId,String responsibilityCode,Integer status);
+
+    /**
+     * 给用户添加所有损益报表权限
+     * @param userId
+     * @param allRightFlag
+     */
+    void editAllUserResponsibilityRight(Long userId,Integer allRightFlag);
 }
 

+ 9 - 6
src/main/java/com/kcim/service/impl/CostDepartmentProfitServiceImpl.java

@@ -1602,12 +1602,15 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
             if(CollectionUtils.isEmpty(currentUserResponsibilityRights)){
                 throw new CostException("您没有分配责任中心权限,请联系管理员");
             }
-            //筛选出有权限的责任中心对象
-            responsibilityList = responsibilityList.stream().filter(responsibility ->
-                    currentUserResponsibilityRights.stream().anyMatch(userRight ->
-                            userRight.getResponsibilityCode().equals(responsibility.getResponsibilityCode()))).collect(Collectors.toList());
-            if(CollectionUtils.isEmpty(responsibilityList)){
-                throw new CostException("您没有对应的责任中心权限,请联系管理员");
+            //如果不是分配了全部责任中心权限则过滤没有权限的责任中心
+            if(!currentUserResponsibilityRights.stream().anyMatch(userResponsibilityRight->userResponsibilityRight.getUserId().equals(NumberConstant.ZERO))){
+                //筛选出有权限的责任中心对象
+                responsibilityList = responsibilityList.stream().filter(responsibility ->
+                        currentUserResponsibilityRights.stream().anyMatch(userRight ->
+                                userRight.getResponsibilityCode().equals(responsibility.getResponsibilityCode()))).collect(Collectors.toList());
+                if(CollectionUtils.isEmpty(responsibilityList)){
+                    throw new CostException("您没有对应的责任中心权限,请联系管理员");
+                }
             }
         }
         List<Responsibility> responsibilityAllList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()

+ 12 - 9
src/main/java/com/kcim/service/impl/HospProfitAndLossServiceImpl.java

@@ -202,6 +202,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
                         .eq(HospProfitAndLoss::getDateYear, year)
                         .eq(HospProfitAndLoss::getDateMonth, month)
                         .eq(HospProfitAndLoss::getHospId, hospId)
+                        .eq(HospProfitAndLoss::getReportType, reportType)
         );
         // 得到全院损益计算报表
         List<ReportForm> reportForms = reportFormService.getListByReportType(hospId, reportType);
@@ -385,6 +386,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         long l = System.currentTimeMillis();
         list.forEach(i -> {
             i.setCreateTime(l);
+            i.setReportType(reportType);
         });
         this.saveBatch(list);
     }
@@ -656,7 +658,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         Map<Long, Responsibility> responsibilityIdMap = responsibilityList.stream().collect(Collectors.toMap(Responsibility::getId, responsibility -> responsibility, (a, b) -> b));
 
         // 查询所有的全院损益数据  内存溢出问题
-        List<HospProfitAndLoss> hospProfitAndLosses = getAllDataByDate(year, month, hospId);
+        List<HospProfitAndLoss> hospProfitAndLosses = getAllDataByDate(year, month, hospId,NumberConstant.THREE);
         if (CollectionUtils.isEmpty(hospProfitAndLosses)) {
             throw new CostException(500, "未进行全院损益计算");
         }
@@ -1172,10 +1174,12 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         DateTime parse = DateUtil.parse(computeDate);
         int year = DateUtil.year(parse);
         int month = DateUtil.month(parse) + 1;
+        //查询全院损益报表配置
+        Integer integerReportType = Integer.valueOf(reportType);
 //        Integer year = ComputeDateUtils.getComputeYear(computeDate);
 //        Integer month = ComputeDateUtils.getComputeMonth(computeDate);
         // 查询所有的全院损益数据  内存溢出问题
-        List<HospProfitAndLoss> hospProfitAndLosses = getAllDataByDate(year, month, hospId);
+        List<HospProfitAndLoss> hospProfitAndLosses = getAllDataByDate(year, month, hospId,integerReportType);
         if (CollectionUtils.isEmpty(hospProfitAndLosses)) {
             throw new CostException(500, "未进行全院损益计算");
         }
@@ -1184,8 +1188,6 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         if (!CollectionUtils.isEmpty(hospAllList)) {
             hospProfitAndLosses.removeAll(hospAllList);
         }
-        //查询全院损益报表配置
-        Integer integerReportType = Integer.valueOf(reportType);
         List<ReportForm> reportFormList = reportFormService.list(new QueryWrapper<ReportForm>().lambda()
                 .eq(ReportForm::getHospId, hospId)
                 .eq(ReportForm::getReportType, integerReportType).eq(ReportForm::getHide, NumberConstant.ONE));
@@ -1220,11 +1222,11 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
             hospProfitVO.setParentId(0L);
             hospProfitVO.setReportName("全院其他收支");
             hospProfitVO.setSort(costProfitVos.size());
-            hospProfitVO.setReportType(3);
+            hospProfitVO.setReportType(integerReportType);
             hospProfitVO.setFraction(3);
             costProfitVos.add(hospProfitVO);
             for (int i = 0, hospAllListSize = hospAllList.size(); i < hospAllListSize; i++) {
-                costProfitVos.add(getHospProfitVO(hospAllList, i));
+                costProfitVos.add(getHospProfitVO(hospAllList, i,integerReportType));
             }
         }
 
@@ -1285,7 +1287,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
 
     }
 
-    private static @NotNull HospProfitVO getHospProfitVO(List<HospProfitAndLoss> hospAllList, int i) {
+    private static @NotNull HospProfitVO getHospProfitVO(List<HospProfitAndLoss> hospAllList, int i,int reportType) {
         HospProfitAndLoss hospProfitAndLoss = hospAllList.get(i);
         HospProfitVO hospProfitVO1 = new HospProfitVO();
         hospProfitVO1.setId(Long.valueOf(hospProfitAndLoss.getReportNum()));
@@ -1293,18 +1295,19 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         hospProfitVO1.setParentId(-1L);
         hospProfitVO1.setReportName(hospProfitAndLoss.getReportName());
         hospProfitVO1.setSort(i);
-        hospProfitVO1.setReportType(3);
+        hospProfitVO1.setReportType(reportType);
         hospProfitVO1.setAmount(hospProfitAndLoss.getAmount());
         hospProfitVO1.setFraction(3);
         return hospProfitVO1;
     }
 
-    private List<HospProfitAndLoss> getAllDataByDate(int year, int month, Long hospId) {
+    private List<HospProfitAndLoss> getAllDataByDate(int year, int month, Long hospId,int reportType) {
         return this.list(
                 new LambdaQueryWrapper<HospProfitAndLoss>()
                         .eq(HospProfitAndLoss::getHospId, hospId)
                         .eq(HospProfitAndLoss::getDateMonth, month)
                         .eq(HospProfitAndLoss::getDateYear, year)
+                        .eq(HospProfitAndLoss::getReportType, reportType)
         );
     }
 

+ 123 - 15
src/main/java/com/kcim/service/impl/UserReportRightServiceImpl.java

@@ -3,18 +3,25 @@ package com.kcim.service.impl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.kcim.common.constants.NumberConstant;
 import com.kcim.common.exception.CostException;
+import com.kcim.common.util.BeanUtil;
+import com.kcim.common.util.PageUtils;
 import com.kcim.dao.mapper.UserReportRightMapper;
 import com.kcim.dao.model.UserReportRight;
+import com.kcim.dao.model.UserResponsibilityRight;
 import com.kcim.dao.repository.UserReportRightRepository;
 import com.kcim.service.CenterService;
 import com.kcim.service.UserReportRightService;
+import com.kcim.service.UserResponsibilityRightService;
 import com.kcim.vo.DictDataVo;
+import com.kcim.vo.UserInfoVO;
 import com.kcim.vo.UserReportRightVO;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -23,8 +30,8 @@ import static com.kcim.common.constants.ParameterConstant.USER_REPORT_AUTHOR_ABL
 
 
 /**
- *
- * @author Administrator
+ * 用户报表权限
+ * @author
  */
 @Service("UserReportRightService")
 @Slf4j
@@ -33,17 +40,7 @@ public class UserReportRightServiceImpl extends ServiceImpl<UserReportRightMappe
 
     private final CenterService centerService;
     private UserReportRightRepository repository;
-
-    @Override
-    public List<UserReportRight> getUserReportRight() {
-
-        return null;
-    }
-
-    @Override
-    public List<UserReportRightVO> UserReportRightList() {
-        return null;
-    }
+    private UserResponsibilityRightService userResponsibilityRightService;
 
     /**
      * 获取用户有权限的损益报表
@@ -73,6 +70,119 @@ public class UserReportRightServiceImpl extends ServiceImpl<UserReportRightMappe
         return dictDataVo;
     }
 
+
+    /**
+     * 获取用户列表
+     * @param userName
+     * @return
+     */
+    @Override
+    public Object getUserList(Integer current, Integer pageSize, String userName) {
+        List<UserInfoVO> centerUserInfo = centerService.getCenterUserInfo(userName);
+        //判断是否有维护过责任中心权限
+        List<UserResponsibilityRight> userResponsibilityRight = userResponsibilityRightService.getUserResponsibilityRight();
+        if(!CollectionUtils.isEmpty(userResponsibilityRight)){
+            //获取所有用户ID并去重
+            List<Long> userList = userResponsibilityRight.stream().map(UserResponsibilityRight::getUserId).distinct().collect(Collectors.toList());
+            //找出所有配置过责任中心权限的用户
+            List<UserInfoVO> userInfoVOS = centerUserInfo.stream().filter(userInfo -> userList.contains(userInfo.getId())).collect(Collectors.toList());
+            if(!CollectionUtils.isEmpty(userInfoVOS)){
+                //设置是否配置标识
+                userInfoVOS.stream().forEach(userInfo ->userInfo.setUserStatus(NumberConstant.ONE));
+            }
+        }
+        //判断是否有维护过损益报表权限
+        List<UserReportRight> userReportRight = repository.getList();
+        if(!CollectionUtils.isEmpty(userReportRight)){
+            //获取所有用户ID并去重
+            List<Long> userList = userReportRight.stream().map(UserReportRight::getUserId).distinct().collect(Collectors.toList());
+            //找出所有配置过损益报表权限的用户
+            List<UserInfoVO> userInfoVOS = centerUserInfo.stream().filter(userInfo ->userList.contains(userInfo.getId())).collect(Collectors.toList());
+            if(!CollectionUtils.isEmpty(userInfoVOS)){
+                //设置是否配置标识
+                userInfoVOS.stream().forEach(userInfo ->userInfo.setUserStatus(NumberConstant.ONE));
+            }
+        }
+        PageUtils pageUserInfo = new PageUtils(new ArrayList<>(), NumberConstant.ZERO,pageSize,current);
+        if(CollectionUtils.isEmpty(centerUserInfo)){
+            return pageUserInfo;
+        }
+        pageUserInfo = new PageUtils(centerUserInfo, centerUserInfo.size(), pageSize, current);
+        return pageUserInfo;
+    }
+
+    /**
+     * 获取用户有权限的损益报表列表
+     * @param userId
+     * @param reportName
+     * @param hideFlag
+     * @return
+     */
+    @Override
+    public List<UserReportRightVO> getUserReportRights(Long userId,String reportName, Integer hideFlag) {
+        DictDataVo dictDataVo = centerService.getDict(PROFIT_REPORT_TYPE);
+        //没开启数据权限流程时返回所有
+        if(!ObjectUtils.isEmpty(dictDataVo)||CollectionUtils.isEmpty(dictDataVo.getDataVoList()))
+        {
+            throw new CostException("找不到有效的损益报表,请先维护损益报表字典");
+        }
+        //转成出参对象
+        List<UserReportRightVO> userReportRightVOList = dictDataVo.getDataVoList().stream().map(dataVo -> convertToReportRightVO(dataVo,userId)).collect(Collectors.toList());
+        //获取用户有权限的损益报表
+        List<UserReportRight> userReportRight = repository.getList();
+        if(!CollectionUtils.isEmpty(userReportRight)){
+            //只取reportCode
+            List<String> reportCodeList = userReportRight.stream().map(UserReportRight::getReportCode).distinct().collect(Collectors.toList());
+            //设置选择标志
+            userReportRightVOList.stream().forEach(userReport->
+                    userReport.setStatus(reportCodeList.contains(userReport.getReportCode())?NumberConstant.ONE:NumberConstant.ZERO));
+        }
+        return userReportRightVOList;
+    }
+
+
+    /**
+     * 编辑用户损益报表权限
+     * @param userReportRightVO
+     */
+    @Override
+    public void editUserReportRight(UserReportRightVO userReportRightVO) {
+        UserReportRight userReportRight = BeanUtil.convertObj(userReportRightVO, UserReportRight.class);
+        if(userReportRightVO.getStatus().equals(NumberConstant.ONE)){
+            repository.addUserReportRight(userReportRight);
+        }else{
+            repository.deleteUserReportRight(userReportRight);
+        }
+    }
+
+    /**
+     * 修改指定用户的损益报表权限
+     * @param userId
+     * @param reportCode
+     * @param status
+     */
+    @Override
+    public void editUserReportRight(Long userId, String reportCode, Integer status) {
+        if(status.equals(NumberConstant.ONE)){
+            repository.addUserReportRight(userId,reportCode);
+        }else{
+            repository.deleteUserReportRight(userId,reportCode);
+        }
+    }
+
+    /**
+     * 转成损益报表出参对象
+     * @param dictDataVo
+     * @return
+     */
+    public UserReportRightVO convertToReportRightVO(DictDataVo dictDataVo,Long userId){
+        UserReportRightVO userReportRightVO=new UserReportRightVO();
+        userReportRightVO.setReportCode(dictDataVo.getCode());
+        userReportRightVO.setReportName(dictDataVo.getName());
+        userReportRightVO.setUserId(userId);
+        return userReportRightVO;
+    }
+
     /**
      * 判断是否开启用户报表权限功能
      * @return
@@ -84,6 +194,4 @@ public class UserReportRightServiceImpl extends ServiceImpl<UserReportRightMappe
         }
         return parameterValue.equals(NumberConstant.ONE_S);
     }
-
-
 }

+ 92 - 2
src/main/java/com/kcim/service/impl/UserResponsibilityRightServiceImpl.java

@@ -1,16 +1,25 @@
 package com.kcim.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.kcim.common.constants.NumberConstant;
+import com.kcim.common.exception.CostException;
+import com.kcim.common.util.BeanUtil;
 import com.kcim.dao.mapper.UserResponsibilityRightMapper;
 import com.kcim.dao.model.UserResponsibilityRight;
 import com.kcim.dao.repository.UserResponsibilityRightRepository;
+import com.kcim.service.ResponsibilityService;
 import com.kcim.service.UserResponsibilityRightService;
+import com.kcim.vo.CostResponsibilityVO;
 import com.kcim.vo.UserResponsibilityRightVO;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 /**
@@ -24,6 +33,7 @@ public class UserResponsibilityRightServiceImpl extends ServiceImpl<UserResponsi
 
 
     UserResponsibilityRightRepository repository;
+    ResponsibilityService responsibilityService;
 
     /**
      * 获取当前用户有权限的责任中心信息
@@ -34,10 +44,90 @@ public class UserResponsibilityRightServiceImpl extends ServiceImpl<UserResponsi
         return  repository.getList();
     }
 
+    /**
+     * 获取用户的责任中心权限列表
+     * @param responsibilityName
+     * @param hideFlag
+     * @return
+     */
+    @Override
+    public List<UserResponsibilityRightVO> getUserResponsibilityRights(Long userId,String responsibilityName, Integer hideFlag) {
+        List<CostResponsibilityVO> responsibilityList = responsibilityService.getList( );
+        //没开启数据权限流程时返回所有
+        if(CollectionUtils.isEmpty(responsibilityList))
+        {
+            throw new CostException("找不到有效的责任中心,请先维护责任中心字典");
+        }
+        //转成出参对象
+        List<UserResponsibilityRightVO> userReportRightVOList = responsibilityList.stream().map(responsibility -> convertToResponsibilityRightVO(responsibility,userId)).collect(Collectors.toList());
+        //获取用户有权限的损益报表
+        List<UserResponsibilityRight> userResponsibilityRightList = repository.getList();
+        if(!CollectionUtils.isEmpty(userResponsibilityRightList)){
+            //只取责任中心代码
+            List<String> responsibilityCodeList = userResponsibilityRightList.stream().map(UserResponsibilityRight::getResponsibilityCode).distinct().collect(Collectors.toList());
+            //设置选择标志
+            userReportRightVOList.stream().forEach(responsibility->
+                    responsibility.setStatus(responsibilityCodeList.contains(responsibility.getResponsibilityCode())? NumberConstant.ONE:NumberConstant.ZERO));
+        }
+        return userReportRightVOList;
+    }
+
+    /**
+     * 转成用户责任中心权限对象
+     * @param responsibilityVO
+     * @return
+     */
+    public UserResponsibilityRightVO convertToResponsibilityRightVO(CostResponsibilityVO responsibilityVO, Long userId){
+        UserResponsibilityRightVO userResponsibilityRightVO = BeanUtil.convertObj(responsibilityVO, UserResponsibilityRightVO.class);
+        userResponsibilityRightVO.setUserId(userId);
+        return userResponsibilityRightVO;
+    }
+
 
+    /**
+     * 编辑用户损益报表权限
+     * @param uerResponsibilityRightVO
+     */
+    @Override
+    public void editUserResponsibilityRight(UserResponsibilityRightVO uerResponsibilityRightVO) {
+        UserResponsibilityRight userResponsibilityRight = BeanUtil.convertObj(uerResponsibilityRightVO, UserResponsibilityRight.class);
+        if(uerResponsibilityRightVO.getStatus().equals(NumberConstant.ONE)){
+            repository.addUserResponsibilityRight(userResponsibilityRight);
+        }else{
+            repository.deleteUserResponsibilityRight(userResponsibilityRight);
+        }
+    }
+
+    /**
+     * 修改指定用户的责任中心权限
+     * @param userId
+     * @param responsibilityCode
+     * @param status
+     */
+    @Override
+    public void editUserResponsibilityRight(Long userId, String responsibilityCode, Integer status) {
+        if(status.equals(NumberConstant.ONE)){
+            repository.addUserResponsibilityRight(userId,responsibilityCode);
+        }else{
+            repository.deleteUserResponsibilityRight(userId,responsibilityCode);
+        }
+    }
+
+    /**
+     * 给用户添加所有损益报表权限
+     * @param userId
+     */
     @Override
-    public UserResponsibilityRightVO UserResponsibilityRightList() {
-        return null;
+    @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
+    public void editAllUserResponsibilityRight(Long userId,Integer allRightFlag) {
+        //先移除已有的所有权限
+        List<UserResponsibilityRight> userResponsibilityRightList = repository.getListByUserId(userId);
+        repository.removeUserResponsibilityRightList(userResponsibilityRightList);
+        //新增一条特殊的全部权限则记录
+        if(allRightFlag.equals(NumberConstant.ONE)){
+            //组装核算单元为0的数据
+            repository.addUserResponsibilityRight(userId,String.valueOf(NumberConstant.ZERO));
+        }
     }
 
 

+ 6 - 1
src/main/java/com/kcim/vo/UserInfoVO.java

@@ -1,10 +1,10 @@
 package com.kcim.vo;
 
+import com.kcim.common.constants.NumberConstant;
 import io.swagger.annotations.ApiModel;
 import lombok.*;
 
 import java.util.Date;
-import java.util.List;
 
 /**
  * 我的主页 用户信息相关
@@ -124,6 +124,11 @@ public class UserInfoVO {
 
     private Integer employeeId;
 
+    /**
+     * 用户状态 0未设置 1已设置
+     */
+    private Integer userStatus= NumberConstant.ZERO;
+
     
 
 

+ 36 - 0
src/main/java/com/kcim/vo/UserReportRightVO.java

@@ -0,0 +1,36 @@
+package com.kcim.vo;
+
+import com.kcim.common.constants.NumberConstant;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.*;
+
+/**
+ * 用户损益表权限
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ApiModel
+public class UserReportRightVO {
+
+    @ApiModelProperty(name = "userId",value = "中台用户ID")
+    private Long userId;
+
+    @ApiModelProperty(name = "account",value = "用户工号")
+    private String account;
+
+    @ApiModelProperty(name = "reportName", value = "损益报表名称")
+    private String reportName;
+
+    @ApiModelProperty(name = "reportCode", value = "损益报表代码")
+    private String reportCode;
+
+    /**
+     * 选择标志 0未选择 1已选择
+     */
+    @ApiModelProperty(name = "status", value = "选择标志")
+    private Integer status= NumberConstant.ZERO;
+}

+ 82 - 0
src/main/java/com/kcim/vo/UserResponsibilityRightVO.java

@@ -0,0 +1,82 @@
+package com.kcim.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.kcim.common.constants.NumberConstant;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.*;
+
+/**
+ * 用户责任中心权限
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ApiModel
+public class UserResponsibilityRightVO {
+
+    @ApiModelProperty(name = "id",value = "用户责任中心权限的Id")
+    private Long id;
+
+    @ApiModelProperty(name = "userId",value = "中台用户ID")
+    private Long userId;
+
+    @ApiModelProperty(name = "account",value = "用户工号")
+    private String account;
+
+    @ApiModelProperty(name = "responsibilityName", value = "责任中心名称")
+    private String responsibilityName;
+
+    @ApiModelProperty(name = "responsibilityCode", value = "责任中心代码")
+    private String responsibilityCode;
+
+    @ApiModelProperty(name = "responsibilityLevel", value = "责任级别(第一级为1,以此类推)")
+    private Integer responsibilityLevel;
+
+    @ApiModelProperty(name = "isGatherCenter", value = "是否汇总中心1.是,2.不是")
+    private Integer isGatherCenter;
+
+    @ApiModelProperty(name = "responsibilityType", value = "责任类型 1. 收费中心,2.成本(费用)中心")
+    private Integer responsibilityType;
+
+    @ApiModelProperty(name = "shareId", value = "分摊层级Id")
+    /**
+     * 分摊级别的Id
+     */
+    private Long shareId;
+
+    @ApiModelProperty(name = "shareLevel", value = "分摊级别 如果是顶层默认为0")
+    private Integer shareLevel;
+
+    @ApiModelProperty(name = "shareName", value = "分摊级别名称")
+    private String shareName;
+
+    @ApiModelProperty(name = "deptStatus", value = "责任中心状态,0.门诊,1.住院")
+    private Integer isDefault;
+
+    /**
+     * 标准分摊层级
+     */
+    private String standardShareLevel;
+
+    /**
+     * 标准分摊层级名称
+     */
+    @TableField(exist = false)
+    private String standardShareLevelName;
+
+    /**
+     * 责任中心类型
+     */
+    private String type;
+    @TableField(exist = false)
+    private String typeName;
+
+    /**
+     * 选择标志 0未选择 1已选择
+     */
+    @ApiModelProperty(name = "status", value = "选择标志")
+    private Integer status= NumberConstant.ZERO;
+}

+ 60 - 4
src/main/java/com/kcim/web/UserReportRightController.java

@@ -2,22 +2,25 @@ package com.kcim.web;
 
 import com.kcim.common.util.Result;
 import com.kcim.service.UserReportRightService;
+import com.kcim.service.UserResponsibilityRightService;
+import com.kcim.vo.UserReportRightVO;
+import com.kcim.vo.UserResponsibilityRightVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * 用户报表权限相关操作
  */
 @RestController
-@RequestMapping("/UserReportRight")
+@RequestMapping("/userReportRight")
 @Api(tags = "用户报表权限相关操作")
 public class UserReportRightController {
     @Autowired
     private UserReportRightService userReportRightService;
+    @Autowired
+    private UserResponsibilityRightService userResponsibilityRightService;
 
 
     @GetMapping("/getUserReports")
@@ -25,4 +28,57 @@ public class UserReportRightController {
     public Result getUserReports(){
         return Result.ok(userReportRightService.getUserReports());
     }
+
+    @ApiOperation("获取用户列表")
+    @GetMapping("/getUserList")
+    public Result getUserList(@RequestParam(value = "current", defaultValue = "1") Integer current,
+                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
+                              @RequestParam(value = "name", required = false) String userName) {
+        return Result.ok(userReportRightService.getUserList(current,pageSize,userName));
+    }
+
+    @ApiOperation("获取用户损益报表权限列表")
+    @GetMapping("/getUserReportRights")
+    public Result getUserReportRights(@RequestParam(value = "userId") Long userId,
+                                      @RequestParam(value = "reportName", required = false) String reportName,
+                                      @RequestParam(value = "hideFlag", defaultValue = "0") Integer hideFlag) {
+        return Result.ok(userReportRightService.getUserReportRights(userId,reportName,hideFlag));
+    }
+
+    @ApiOperation("修改用户损益报表权限")
+    @PostMapping("/editUserReportRight")
+    public Result editUserReportRight(@RequestBody UserReportRightVO userReportRightVO) {
+        userReportRightService.editUserReportRight(userReportRightVO);
+        return Result.ok();
+    }
+
+    /**
+     * 获取用户责任中心权限列表
+     * @param responsibilityName 责任呢中心代码/名称
+     * @param hideFlag
+     * @return
+     */
+    @ApiOperation("获取用户责任中心权限列表")
+    @GetMapping("/getUserResponsibilityRights")
+    public Result getUserResponsibilityRights(@RequestParam(value = "userId") Long userId,
+                                              @RequestParam(value = "responsibilityName", required = false) String responsibilityName,
+                                              @RequestParam(value = "hideFlag", defaultValue = "0") Integer hideFlag) {
+        return Result.ok(userResponsibilityRightService.getUserResponsibilityRights(userId,responsibilityName,hideFlag));
+    }
+
+    @ApiOperation("修改用户损益报表权限")
+    @PostMapping("/editUserResponsibilityRight")
+    public Result editUserResponsibilityRight(@RequestBody UserResponsibilityRightVO uerResponsibilityRightVO) {
+        userResponsibilityRightService.editUserResponsibilityRight(uerResponsibilityRightVO);
+        return Result.ok();
+    }
+
+    @ApiOperation("修改用户的所有损益报表权限")
+    @PostMapping("/editAllUserResponsibilityRight")
+    public Result editAllUserResponsibilityRight(@RequestParam(value = "userId") Long userId,
+                                                @RequestParam(value = "allRightFlag", defaultValue = "0") Integer allRightFlag) {
+        userResponsibilityRightService.editAllUserResponsibilityRight(userId,allRightFlag);
+        return Result.ok();
+    }
+
 }