Blame view

fw-morax-service/src/main/java/cn/fw/morax/service/biz/kpi/IndicatorBizService.java 7.5 KB
57fffce6   姜超   [jiangchao] 绩效组查询接口
1
  package cn.fw.morax.service.biz.kpi;
6eb4edeb   姜超   [jiangchao] 分页查询修改
2
  
6eb4edeb   姜超   [jiangchao] 分页查询修改
3
  import cn.fw.common.exception.BusinessException;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
4
  import cn.fw.common.page.AppPage;
a5953781   姜超   feature(*): 保存、修改...
5
  import cn.fw.common.web.annotation.DisLock;
139792ba   姜超   feature(*): 岗位绩效指...
6
  import cn.fw.ehr.sdk.api.enums.RoleManagerEnum;
2436d2f9   姜超   feature(*): 根据岗位查...
7
  import cn.fw.ehr.sdk.api.result.PostRoleVo;
6eb4edeb   姜超   [jiangchao] 分页查询修改
8
9
  import cn.fw.morax.common.utils.PublicUtil;
  import cn.fw.morax.domain.db.kpi.Indicators;
bbb00e01   姜超   feature(*): 启用禁用指标
10
  import cn.fw.morax.domain.db.kpi.KpiGroup;
57fffce6   姜超   [jiangchao] 绩效组查询接口
11
  import cn.fw.morax.domain.dto.IndicatorsDTO;
139792ba   姜超   feature(*): 岗位绩效指...
12
  import cn.fw.morax.domain.dto.query.IndicatorPostQueryDTO;
4b07306b   姜超   feature(*): 星级特殊调整申请
13
  import cn.fw.morax.domain.dto.query.IndicatorQueryDTO;
6eb4edeb   姜超   [jiangchao] 分页查询修改
14
  import cn.fw.morax.domain.enums.ApplicableRoleEnum;
83fc9174   姜超   feature(*): 薪酬项查询...
15
  import cn.fw.morax.domain.vo.kpi.IndicatorsVO;
2436d2f9   姜超   feature(*): 根据岗位查...
16
17
  import cn.fw.morax.rpc.ehr.EhrRpcService;
  import cn.fw.morax.rpc.ehr.dto.PostInfoDTO;
6eb4edeb   姜超   [jiangchao] 分页查询修改
18
  import cn.fw.morax.service.data.kpi.IndicatorsService;
8420e237   jiangchao   [jiangchao] 枚举类修改
19
  import com.alibaba.fastjson.JSON;
6eb4edeb   姜超   [jiangchao] 分页查询修改
20
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
a5953781   姜超   feature(*): 保存、修改...
21
  import lombok.Getter;
6eb4edeb   姜超   [jiangchao] 分页查询修改
22
23
  import lombok.RequiredArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
a5953781   姜超   feature(*): 保存、修改...
24
  import org.springframework.beans.factory.annotation.Value;
6eb4edeb   姜超   [jiangchao] 分页查询修改
25
26
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
27
  
2436d2f9   姜超   feature(*): 根据岗位查...
28
  import java.util.*;
67765106   姜超   feature(*): 指标分页查询修改
29
  import java.util.function.Function;
bbb00e01   姜超   feature(*): 启用禁用指标
30
31
  import java.util.stream.Collectors;
  
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
32
  import static cn.fw.common.businessvalidator.Validator.BV;
6eb4edeb   姜超   [jiangchao] 分页查询修改
33
34
35
36
37
38
  
  @RequiredArgsConstructor
  @Service
  @Slf4j
  public class IndicatorBizService {
  
bbb00e01   姜超   feature(*): 启用禁用指标
39
      private final KpiGroupIndicatorBizService kpiGroupIndicatorBizService;
6eb4edeb   姜超   [jiangchao] 分页查询修改
40
      private final IndicatorsService indicatorsService;
2436d2f9   姜超   feature(*): 根据岗位查...
41
      private final EhrRpcService ehrRpcService;
6eb4edeb   姜超   [jiangchao] 分页查询修改
42
  
a5953781   姜超   feature(*): 保存、修改...
43
44
45
46
47
48
49
      @Value("${spring.cache.custom.global-prefix}:indicator:save:")
      @Getter
      private String savePrefix;
      @Value("${spring.cache.custom.global-prefix}:indicator:enable:")
      @Getter
      private String enablePrefix;
  
6eb4edeb   姜超   [jiangchao] 分页查询修改
50
51
      /**
       * 分页查询
f6a37f71   张志伟   :rocket:
52
       *
6eb4edeb   姜超   [jiangchao] 分页查询修改
53
54
55
       * @param dto
       * @return
       */
83fc9174   姜超   feature(*): 薪酬项查询...
56
      public AppPage<IndicatorsVO> indicatorsPage(IndicatorQueryDTO dto) {
e9c4a48b   姜超   feature(*): 实时查询绩...
57
          if (PublicUtil.isNotEmpty(dto.getRoleCode())) {
67765106   姜超   feature(*): 指标分页查询修改
58
              List<ApplicableRoleEnum> roleTypes = new ArrayList<ApplicableRoleEnum>(){{
e9c4a48b   姜超   feature(*): 实时查询绩...
59
60
61
                  add(ApplicableRoleEnum.ALL);
                  add(ApplicableRoleEnum.MANAGEMENT_ROLE);
              }};
67765106   姜超   feature(*): 指标分页查询修改
62
              dto.setAllRoleTypes(roleTypes);
e9c4a48b   姜超   feature(*): 实时查询绩...
63
          }
67765106   姜超   feature(*): 指标分页查询修改
64
65
66
67
          Long total = indicatorsService.indicatorsPageTotal(dto);
          return PublicUtil.<IndicatorsVO, IndicatorQueryDTO>queryPage(dto, total, new Function<IndicatorQueryDTO, List<IndicatorsVO>>() {
              @Override
              public List<IndicatorsVO> apply(IndicatorQueryDTO basePageQuery) {
b2d77916   jiangchao   fix(*): 修改数据库字段类型
68
                  return indicatorsService.indicatorsPage(dto);
67765106   姜超   feature(*): 指标分页查询修改
69
              }
6eb4edeb   姜超   [jiangchao] 分页查询修改
70
          });
67765106   姜超   feature(*): 指标分页查询修改
71
  
6eb4edeb   姜超   [jiangchao] 分页查询修改
72
73
74
      }
  
      /**
1a516cf8   姜超   feature(*): 指标详情接口
75
       * 指标详情
cc9fae5a   姜超   feature(*): 保存校验修改
76
       *
1a516cf8   姜超   feature(*): 指标详情接口
77
78
79
       * @param id
       * @return
       */
83fc9174   姜超   feature(*): 薪酬项查询...
80
      public IndicatorsVO indicatorDetail(Long id) {
1a516cf8   姜超   feature(*): 指标详情接口
81
          Indicators indicators = indicatorsService.getById(id);
2d3b63e0   姜超   feature(*): 保存指标修改
82
          BV.notNull(indicators, "指标不存在,请重试");
83fc9174   姜超   feature(*): 薪酬项查询...
83
          return PublicUtil.copy(indicators, IndicatorsVO.class);
1a516cf8   姜超   feature(*): 指标详情接口
84
85
86
      }
  
      /**
6eb4edeb   姜超   [jiangchao] 分页查询修改
87
       * 保存指标
f6a37f71   张志伟   :rocket:
88
       *
6eb4edeb   姜超   [jiangchao] 分页查询修改
89
90
91
92
       * @param dto
       * @return
       */
      @Transactional(rollbackFor = Exception.class)
a5953781   姜超   feature(*): 保存、修改...
93
      @DisLock(prefix = "#this.getSavePrefix()", key = "#dto.getIndicatorName()", message = "保存中,请勿重复操作")
57fffce6   姜超   [jiangchao] 绩效组查询接口
94
      public void saveIndicator(IndicatorsDTO dto) {
6eb4edeb   姜超   [jiangchao] 分页查询修改
95
          this.checkIndicatorRole(dto);
f6a37f71   张志伟   :rocket:
96
          this.checkIndicatorName(dto.getIndicatorName());
6eb4edeb   姜超   [jiangchao] 分页查询修改
97
98
          String indicatorCode = PublicUtil.getUUID();
          this.checkIndicatorCode(indicatorCode);
1a516cf8   姜超   feature(*): 指标详情接口
99
100
          Indicators indicators = dto.convertToPo();
          indicators.setIndicatorCode(indicatorCode);
cc9fae5a   姜超   feature(*): 保存校验修改
101
          indicatorsService.save(indicators);
bbb00e01   姜超   feature(*): 启用禁用指标
102
103
      }
  
1a516cf8   姜超   feature(*): 指标详情接口
104
  
bbb00e01   姜超   feature(*): 启用禁用指标
105
106
      /**
       * 指标库禁用启用
b8b6eb02   姜超   feature(*): 接口注释修改
107
       * 
bbb00e01   姜超   feature(*): 启用禁用指标
108
109
110
111
       * @param indicatorId
       * @param enable
       */
      @Transactional(rollbackFor = Exception.class)
a5953781   姜超   feature(*): 保存、修改...
112
      @DisLock(prefix = "#this.getEnablePrefix()", key = "#indicatorId", message = "修改中,请勿重复操作")
bbb00e01   姜超   feature(*): 启用禁用指标
113
114
115
116
117
118
      public void enableIndicator(Long indicatorId, Boolean enable) {
          Indicators indicators = indicatorsService.getById(indicatorId);
          BV.notNull(indicators, "指标不存在,请重试");
          BV.isFalse(enable.equals(indicators.getEnable()), "指标已经是" + ((enable) ? "启用": "禁用") + "状态,请重试");
          //禁用情况:正在使用的指标不能禁用,并提示哪些地方在用
          if (! enable) {
f7bec0dc   姜超   feature(*): 禁用启用薪酬指标
119
              List<KpiGroup> kpiGroups = kpiGroupIndicatorBizService.getKpiGroupByIndicatorId(indicatorId);
bbb00e01   姜超   feature(*): 启用禁用指标
120
121
122
123
124
              Set<String> postNames = kpiGroups.stream().map(KpiGroup::getPostName).collect(Collectors.toSet());
              if (PublicUtil.isNotEmpty(postNames)) {
                  throw new BusinessException(String.join(",", postNames) + "岗位正在使用此绩效指标,不能禁用");
              }
          }
98f0b2aa   姜超   feature(*): 添加yn判断
125
          indicatorsService.update(Wrappers.<Indicators>lambdaUpdate()
bbb00e01   姜超   feature(*): 启用禁用指标
126
127
128
                  .set(Indicators::getEnable, enable)
                  .eq(Indicators::getId, indicatorId)
          );
6eb4edeb   姜超   [jiangchao] 分页查询修改
129
130
131
132
      }
  
      /**
       * 检查指标角色配置
f6a37f71   张志伟   :rocket:
133
       *
6eb4edeb   姜超   [jiangchao] 分页查询修改
134
135
       * @param dto
       */
57fffce6   姜超   [jiangchao] 绩效组查询接口
136
      private void checkIndicatorRole(IndicatorsDTO dto) {
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
137
          Boolean portionNotSelectRole = ApplicableRoleEnum.PORTION.equals(dto.getRoleType()) &&
779bd5ed   姜超   feature(*): 移除系统中...
138
                  PublicUtil.isEmpty(dto.getRoleNames());
b2b91763   姜超   feature(*): 校验指标修改
139
          BV.isFalse(portionNotSelectRole, "自定义角色,请选择至少一个角色");
6eb4edeb   姜超   [jiangchao] 分页查询修改
140
141
142
143
      }
  
      /**
       * 检查指标名称
f6a37f71   张志伟   :rocket:
144
       *
6eb4edeb   姜超   [jiangchao] 分页查询修改
145
       * @param indicatorName
6eb4edeb   姜超   [jiangchao] 分页查询修改
146
       */
f6a37f71   张志伟   :rocket:
147
      private void checkIndicatorName(String indicatorName) {
6eb4edeb   姜超   [jiangchao] 分页查询修改
148
149
          long taskCount = indicatorsService.count(Wrappers.<Indicators>lambdaQuery()
                  .eq(Indicators::getIndicatorName, indicatorName)
39ca0e9a   姜超   feature(Indicator...
150
                  .eq(Indicators::getYn, Boolean.TRUE)
6eb4edeb   姜超   [jiangchao] 分页查询修改
151
          );
4b07306b   姜超   feature(*): 星级特殊调整申请
152
          BV.isFalse(taskCount > 0, "指标名称已存在,请重新输入");
6eb4edeb   姜超   [jiangchao] 分页查询修改
153
154
155
156
      }
  
      /**
       * 检查指标编码
f6a37f71   张志伟   :rocket:
157
       *
6eb4edeb   姜超   [jiangchao] 分页查询修改
158
159
160
161
162
163
164
165
166
167
168
       * @param indicatorCode
       */
      private void checkIndicatorCode(String indicatorCode) {
          long taskCount = indicatorsService.count(Wrappers.<Indicators>lambdaQuery()
                  .eq(Indicators::getIndicatorCode, indicatorCode)
          );
          if (taskCount > 0) {
              log.error("指标编码生成重复:{}", indicatorCode);
              throw new BusinessException("指标编码已存在,请重试");
          }
      }
84ca72cf   姜超   feature(*): 根据岗位查询指标
169
170
171
  
      /**
       * 获取岗位下的绩效组指标
b8b6eb02   姜超   feature(*): 接口注释修改
172
       *
84ca72cf   姜超   feature(*): 根据岗位查询指标
173
174
175
       * @param postId
       * @return
       */
83fc9174   姜超   feature(*): 薪酬项查询...
176
      public List<IndicatorsVO> getPostIndicators(Long postId, String shopIds) {
2436d2f9   姜超   feature(*): 根据岗位查...
177
178
          List<Long> postIds = new ArrayList<Long>(){{
              add(postId);
84ca72cf   姜超   feature(*): 根据岗位查询指标
179
          }};
2436d2f9   姜超   feature(*): 根据岗位查...
180
          List<PostInfoDTO> postInfoDTOS = ehrRpcService.getPostInfoList(postIds);
2436d2f9   姜超   feature(*): 根据岗位查...
181
182
          List<String> roleCodes = postInfoDTOS.stream()
                  .map(PostInfoDTO::getRoleList)
139792ba   姜超   feature(*): 岗位绩效指...
183
                  .filter(Objects::nonNull)
2436d2f9   姜超   feature(*): 根据岗位查...
184
185
186
                  .flatMap(Collection::stream)
                  .map(PostRoleVo::getRoleCode)
                  .distinct().collect(Collectors.toList());
139792ba   姜超   feature(*): 岗位绩效指...
187
188
          Boolean queryManagerRole = hasManagerRole(roleCodes);
          IndicatorPostQueryDTO dto = new IndicatorPostQueryDTO(roleCodes, queryManagerRole);
1355883a   姜超   feature(*): 人员调岗修...
189
  //        IndicatorPostQueryDTO dto = new IndicatorPostQueryDTO(new ArrayList<String>(){{add("FWGW");add("XSGW");}}, Boolean.TRUE);
139792ba   姜超   feature(*): 岗位绩效指...
190
191
192
193
194
          return indicatorsService.getPostIndicators(dto);
      }
  
      /**
       * 是否拥有管理角色
b8b6eb02   姜超   feature(*): 接口注释修改
195
       *
139792ba   姜超   feature(*): 岗位绩效指...
196
197
198
       * @return
       */
      private Boolean hasManagerRole(List<String> roleCodes) {
2436d2f9   姜超   feature(*): 根据岗位查...
199
          if (PublicUtil.isEmpty(roleCodes)) {
139792ba   姜超   feature(*): 岗位绩效指...
200
              return Boolean.FALSE;
2436d2f9   姜超   feature(*): 根据岗位查...
201
          }
139792ba   姜超   feature(*): 岗位绩效指...
202
203
204
          HashSet<String> roleCodeSet = new HashSet<>(roleCodes);
          return Arrays.stream(RoleManagerEnum.values())
                  .anyMatch(roleManagerEnum -> roleCodeSet.contains(roleManagerEnum.getCode()));
84ca72cf   姜超   feature(*): 根据岗位查询指标
205
      }
139792ba   姜超   feature(*): 岗位绩效指...
206
  
6eb4edeb   姜超   [jiangchao] 分页查询修改
207
  }