Commit b5587b014159591a97bd4195df5a9195034f5951
1 parent
4fa0fd51
派单修改
Showing
1 changed file
with
45 additions
and
28 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/assigntasksinfo/AssignTasksInfoServiceImpl.java
| ... | ... | @@ -36,8 +36,7 @@ import static com.zteits.urbanops.framework.common.exception.enums.GlobalErrorCo |
| 36 | 36 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 37 | 37 | import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception0; |
| 38 | 38 | import static com.zteits.urbanops.framework.common.util.servlet.ServletUtils.getClientIP; |
| 39 | -import static com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 40 | -import static com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils.getLoginUserNickname; | |
| 39 | +import static com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils.*; | |
| 41 | 40 | import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; |
| 42 | 41 | |
| 43 | 42 | /** |
| ... | ... | @@ -195,46 +194,64 @@ public class AssignTasksInfoServiceImpl implements AssignTasksInfoService { |
| 195 | 194 | if (existingTask == null) { |
| 196 | 195 | throw exception(ASSIGN_TASKS_INFO_NOT_EXISTS); |
| 197 | 196 | } |
| 198 | - AssignTasksDO assignTasksDO = assignTasksMapper.selectById(existingTask.getTaskId()); | |
| 199 | - LocalDateTime deadline = assignTasksDO.getDeadline(); | |
| 200 | - | |
| 197 | + Long companyId = existingTask.getCompanyId(); | |
| 198 | + LocalDateTime deadline = existingTask.getDeadline(); | |
| 201 | 199 | String formattedDeadline = Objects.nonNull(deadline) |
| 202 | 200 | ? DEADLINE_FORMATTER.format(deadline) |
| 203 | 201 | : ""; // 或 null |
| 204 | - //填报人信息 | |
| 205 | - AdminUserRespDTO user = adminUserApi.getUser(getLoginUserId()); | |
| 206 | 202 | //用户角色 |
| 207 | - List<Long> roles = roleApi.getRoleIdsByUserId(user.getId()); | |
| 208 | - RoleDO roleDO = roleApi.getRoleIdByRoleCode(AssignTasksConstants.ASSIGN_ROLE_KEY); | |
| 209 | - if (roleDO == null) { | |
| 203 | + List<Long> userIds = roleApi.getUserIdsByRoleCode(AssignTasksConstants.ASSIGN_ROLE_KEY); | |
| 204 | + if (CollectionUtils.isEmpty(userIds)) { | |
| 210 | 205 | //未配置 |
| 211 | - throw exception0(BAD_REQUEST.getCode(),"系统未配置填报人角色"); | |
| 206 | + throw exception0(BAD_REQUEST.getCode(),"未配置子公司管理员角色"); | |
| 212 | 207 | } |
| 213 | - if(!roles.contains(roleDO.getId())) { | |
| 208 | + //填报人信息 | |
| 209 | + List<AdminUserRespDTO> users = adminUserApi.getUserList(userIds); | |
| 210 | + if(CollectionUtils.isEmpty(users)) { | |
| 214 | 211 | //没有权限 |
| 215 | - throw exception0(BAD_REQUEST.getCode(),"该用户未授权"); | |
| 212 | + throw exception0(BAD_REQUEST.getCode(),"未配置分公司管理员"); | |
| 216 | 213 | } |
| 217 | - String phonenumber = user.getMobile(); | |
| 218 | - if (StringUtils.isEmpty(phonenumber)) { | |
| 219 | - throw exception0(BAD_REQUEST.getCode(),"该用户未配置手机号码"); | |
| 214 | + | |
| 215 | + // 收集所有匹配companyId的用户,无匹配则返回空集合(而非null) | |
| 216 | + List<AdminUserRespDTO> matchUserList = users.stream() | |
| 217 | + .filter(user -> { | |
| 218 | + // 防御性判空:过滤掉null用户或deptId为空的用户 | |
| 219 | + if (user == null || user.getDeptId() == null) { | |
| 220 | + return false; | |
| 221 | + } | |
| 222 | + // 安全比较companyId和deptId(兼容null) | |
| 223 | + return Objects.equals(companyId, user.getDeptId()); | |
| 224 | + }) | |
| 225 | + .collect(Collectors.toList()); | |
| 226 | + if (CollectionUtils.isEmpty(matchUserList)) { | |
| 227 | + exception0(BAD_REQUEST.getCode(), "未找到归属该公司的管理员"); | |
| 220 | 228 | } |
| 229 | + | |
| 230 | + | |
| 221 | 231 | Map<String, Object> templateParams = new HashMap<String, Object>(); |
| 222 | 232 | templateParams.put("companyName", existingTask.getCompanyName()); |
| 223 | - templateParams.put("taskName", assignTasksDO.getTaskName()); | |
| 233 | + templateParams.put("taskName", existingTask.getTaskName()); | |
| 224 | 234 | templateParams.put("deadline", formattedDeadline); |
| 225 | - | |
| 226 | 235 | // 5. 发送短信通知 |
| 227 | 236 | log.info("派单发送短信 signMap: {}", JSONObject.toJSONString(templateParams)); |
| 228 | - SmsCodeSendReqDTO reqDTO = new SmsCodeSendReqDTO(); | |
| 229 | - reqDTO.setScene(AssignTasksConstants.ASSIGN_TASK_SCENE); | |
| 230 | - reqDTO.setMobile(phonenumber);//手机号 | |
| 231 | - reqDTO.setTemplateParams(templateParams);//短信参数 | |
| 232 | - reqDTO.setCreateIp(getClientIP()); | |
| 233 | - Long sendLogId = smsCodeApi.openSendSmsCode(reqDTO); | |
| 234 | - log.info("派单发送短信 sendLogId: {}", sendLogId); | |
| 237 | + Boolean sendFlag = false; | |
| 238 | + for (AdminUserRespDTO adminUserRespDTO : matchUserList) { | |
| 239 | + String phonenumber = adminUserRespDTO.getMobile(); | |
| 240 | + if (StringUtils.isEmpty(phonenumber)) { | |
| 241 | + continue; | |
| 242 | + } | |
| 243 | + SmsCodeSendReqDTO reqDTO = new SmsCodeSendReqDTO(); | |
| 244 | + reqDTO.setScene(AssignTasksConstants.ASSIGN_TASK_SCENE); | |
| 245 | + reqDTO.setMobile(phonenumber);//手机号 | |
| 246 | + reqDTO.setTemplateParams(templateParams);//短信参数 | |
| 247 | + reqDTO.setCreateIp(getClientIP()); | |
| 248 | + smsCodeApi.openSendSmsCode(reqDTO); | |
| 249 | + log.info("提交单位任务成功,已通知填报人:手机号:{},任务ID={}", phonenumber, existingTask.getId()); | |
| 250 | + sendFlag = true; | |
| 251 | + } | |
| 235 | 252 | |
| 236 | - if (sendLogId != null) { | |
| 237 | - log.info("提交单位任务成功,已通知填报人:手机号={},任务ID={}", phonenumber, existingTask.getId()); | |
| 253 | + if (sendFlag) { | |
| 254 | + log.info("提交单位任务成功,已通知填报人:任务ID={}", existingTask.getId()); | |
| 238 | 255 | |
| 239 | 256 | int newRushNum = (existingTask.getRushNum() == null) ? 1: existingTask.getRushNum() + 1; |
| 240 | 257 | //催办次数+1 |
| ... | ... | @@ -243,7 +260,7 @@ public class AssignTasksInfoServiceImpl implements AssignTasksInfoService { |
| 243 | 260 | assignTaskInfo.setRushNum(newRushNum); |
| 244 | 261 | assignTasksInfoMapper.updateById(assignTaskInfo); |
| 245 | 262 | } else { |
| 246 | - throw exception(ASSIGN_TASKS_INFO_004); | |
| 263 | + throw exception0(BAD_REQUEST.getCode(),"发送短信失败"); | |
| 247 | 264 | } |
| 248 | 265 | return 1; |
| 249 | 266 | } | ... | ... |