Commit b5587b014159591a97bd4195df5a9195034f5951

Authored by wangqian
1 parent 4fa0fd51

派单修改

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,8 +36,7 @@ import static com.zteits.urbanops.framework.common.exception.enums.GlobalErrorCo
36 import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; 36 import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception;
37 import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception0; 37 import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception0;
38 import static com.zteits.urbanops.framework.common.util.servlet.ServletUtils.getClientIP; 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 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; 40 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*;
42 41
43 /** 42 /**
@@ -195,46 +194,64 @@ public class AssignTasksInfoServiceImpl implements AssignTasksInfoService { @@ -195,46 +194,64 @@ public class AssignTasksInfoServiceImpl implements AssignTasksInfoService {
195 if (existingTask == null) { 194 if (existingTask == null) {
196 throw exception(ASSIGN_TASKS_INFO_NOT_EXISTS); 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 String formattedDeadline = Objects.nonNull(deadline) 199 String formattedDeadline = Objects.nonNull(deadline)
202 ? DEADLINE_FORMATTER.format(deadline) 200 ? DEADLINE_FORMATTER.format(deadline)
203 : ""; // 或 null 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 Map<String, Object> templateParams = new HashMap<String, Object>(); 231 Map<String, Object> templateParams = new HashMap<String, Object>();
222 templateParams.put("companyName", existingTask.getCompanyName()); 232 templateParams.put("companyName", existingTask.getCompanyName());
223 - templateParams.put("taskName", assignTasksDO.getTaskName()); 233 + templateParams.put("taskName", existingTask.getTaskName());
224 templateParams.put("deadline", formattedDeadline); 234 templateParams.put("deadline", formattedDeadline);
225 -  
226 // 5. 发送短信通知 235 // 5. 发送短信通知
227 log.info("派单发送短信 signMap: {}", JSONObject.toJSONString(templateParams)); 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 int newRushNum = (existingTask.getRushNum() == null) ? 1: existingTask.getRushNum() + 1; 256 int newRushNum = (existingTask.getRushNum() == null) ? 1: existingTask.getRushNum() + 1;
240 //催办次数+1 257 //催办次数+1
@@ -243,7 +260,7 @@ public class AssignTasksInfoServiceImpl implements AssignTasksInfoService { @@ -243,7 +260,7 @@ public class AssignTasksInfoServiceImpl implements AssignTasksInfoService {
243 assignTaskInfo.setRushNum(newRushNum); 260 assignTaskInfo.setRushNum(newRushNum);
244 assignTasksInfoMapper.updateById(assignTaskInfo); 261 assignTasksInfoMapper.updateById(assignTaskInfo);
245 } else { 262 } else {
246 - throw exception(ASSIGN_TASKS_INFO_004); 263 + throw exception0(BAD_REQUEST.getCode(),"发送短信失败");
247 } 264 }
248 return 1; 265 return 1;
249 } 266 }