|
@@ -171,36 +171,51 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public RepairApplicationForm saveModelByDTO(RepairApplicationFormDTO model) {
|
|
|
+ Integer type = model.getType();
|
|
|
+ if (type == null) {
|
|
|
+ type = 1;
|
|
|
+ model.setType(type);
|
|
|
+ }
|
|
|
Weekend<RepairApplicationForm> weekend = new Weekend<>(RepairApplicationForm.class);
|
|
|
- weekend.weekendCriteria().andIsNotNull(RepairApplicationForm::getId);
|
|
|
+ weekend.weekendCriteria().andIsNotNull(RepairApplicationForm::getId).andEqualTo(RepairApplicationForm::getType, model.getType());
|
|
|
int count = mapper.selectCountByExample(weekend);
|
|
|
UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
model.setUserId(userInfo.getUserId());
|
|
|
//model.setCheckUserId(userInfo.getUserId());
|
|
|
// 查询对应的维修人,保存维修单
|
|
|
- SbInfoVO sb = sbInfoService.getById(model.getSbId());
|
|
|
-
|
|
|
- // 保存报修单
|
|
|
- model.setModelId(sb.getModelId());
|
|
|
- model.setNo(IdGeneratorUtils.getRepairApplicaitonFormNo(++count));
|
|
|
- model.setStatus(RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue());
|
|
|
+ String sbId = model.getSbId();
|
|
|
+ if (StringUtils.isNotEmpty(sbId)) {
|
|
|
+ SbInfoVO sb = sbInfoService.getById(sbId);
|
|
|
+ // 保存报修单
|
|
|
+ model.setModelId(sb.getModelId());
|
|
|
+ if (sb.getStatus().intValue() == SbInfoStatusEnum.IN_MAINTAIN.getValue()) {
|
|
|
+ throw new BusinessException("设备已经在维修中,请等待维修完成, sbId" + model.getSbId());
|
|
|
+ }
|
|
|
+ // 如果选择了设备停机,则要修改设备状态
|
|
|
+ if (model.getNeedStop().intValue() == RepairApplicationFormStopEnum.STOP.getValue()) {
|
|
|
+ SbInfo info = new SbInfo();
|
|
|
+ info.setId(sb.getId());
|
|
|
+ info.setStatus(SbInfoStatusEnum.IN_MAINTAIN.getValue());
|
|
|
+ sbInfoService.modModelByPrimaryKey(info);
|
|
|
+ }
|
|
|
+ if (sb.getUseGroup() == null) {
|
|
|
+ throw new BusinessException("找不到设备对应的使用工作组,无法指派维修单,请先设置设备的归属组,sbId" + model.getSbId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ model.setNo(type == 1 ? IdGeneratorUtils.getRepairApplicaitonFormNo(++count) : model.getNo());
|
|
|
+ String repairUserId = model.getRepairUserId();
|
|
|
+ model.setStatus(StringUtils.isNotEmpty(repairUserId) ? RepairApplicationFormStatusEnum.ALLOCATED.getValue() : RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue());
|
|
|
model.setApplyTime(LocalDateTime.now());
|
|
|
model.setCreatedTime(model.getApplyTime());
|
|
|
model.setUpdateTime(model.getApplyTime());
|
|
|
- if (sb.getStatus().intValue() == SbInfoStatusEnum.IN_MAINTAIN.getValue()) {
|
|
|
- throw new BusinessException("设备已经在维修中,请等待维修完成, sbId" + model.getSbId());
|
|
|
- }
|
|
|
|
|
|
- // 如果选择了设备停机,则要修改设备状态
|
|
|
- if (model.getNeedStop().intValue() == RepairApplicationFormStopEnum.STOP.getValue()) {
|
|
|
- SbInfo info = new SbInfo();
|
|
|
- info.setId(sb.getId());
|
|
|
- info.setStatus(SbInfoStatusEnum.IN_MAINTAIN.getValue());
|
|
|
- sbInfoService.modModelByPrimaryKey(info);
|
|
|
- }
|
|
|
- if (sb.getUseGroup() == null) {
|
|
|
- throw new BusinessException("找不到设备对应的使用工作组,无法指派维修单,请先设置设备的归属组,sbId" + model.getSbId());
|
|
|
+ // 关联维修单
|
|
|
+ String mainRepairId = model.getMainRepairId();
|
|
|
+ if (StringUtils.isNotEmpty(mainRepairId)) {
|
|
|
+ //TODO
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
// List<SysUserVO> userList = sysUserService.selectDeptManager(sb.getUseGroup(), SysDeptManagerType.REPAIR.getValue());
|
|
|
// if (userList == null || userList.size() == 0) {
|
|
|
// throw new BusinessException("找不到设备对应的维修员,无法指派维修单,请先设置设备的归属组,sbId" + model.getSbId());
|
|
@@ -211,22 +226,33 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
|
|
|
model.setId(IdGeneratorUtils.getObjectId());
|
|
|
this.saveFile(model);
|
|
|
RepairApplicationForm form = super.saveModelHaveCreateInfo(model);
|
|
|
-
|
|
|
- List<SysUser> users = sysUserService.getRepairUser(new SysUserDTO());
|
|
|
- List<SysUser> filterUsers = users.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
|
|
|
- if (CollectionUtil.isEmpty(filterUsers)) {
|
|
|
- filterUsers = users.stream().filter(item -> item.getIdentityType().equals(SysUserIdentityType.WXZG.getValue())).collect(Collectors.toList());
|
|
|
- }
|
|
|
List<String> userIds = new ArrayList<>();
|
|
|
List<String> mails = new ArrayList<>();
|
|
|
- filterUsers.forEach(item -> {
|
|
|
- userIds.add(item.getUserId());
|
|
|
- mails.add(item.getEmail());
|
|
|
- });
|
|
|
- // 通过给当天值班维修人员
|
|
|
- SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
|
|
|
- model.getId(), MessageTemplateUtil.getRepairApplicationForReceive(model.getNo()),
|
|
|
- model.getId(), userIds, mails));
|
|
|
+ if (StringUtils.isEmpty(repairUserId)) {
|
|
|
+ List<SysUser> users = sysUserService.getRepairUser(new SysUserDTO());
|
|
|
+ List<SysUser> filterUsers = users.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isEmpty(filterUsers)) {
|
|
|
+ filterUsers = users.stream().filter(item -> item.getIdentityType().equals(SysUserIdentityType.WXZG.getValue())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ filterUsers.forEach(item -> {
|
|
|
+ userIds.add(item.getUserId());
|
|
|
+ mails.add(item.getEmail());
|
|
|
+ });
|
|
|
+ // 通过给当天值班维修人员
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
|
|
|
+ model.getId(), MessageTemplateUtil.getRepairApplicationForReceive(model.getNo()),
|
|
|
+ model.getId(), userIds, mails));
|
|
|
+ } else {
|
|
|
+ SysUserVO user = sysUserService.selectUserVO(repairUserId);
|
|
|
+ userIds.add(repairUserId);
|
|
|
+ mails.add(user.getEmail());
|
|
|
+ // 通过给当天值班维修人员
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
|
|
|
+ model.getId(), MessageTemplateUtil.getRepairDispatch(model.getNo()),
|
|
|
+ model.getId(), userIds, mails));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return form;
|
|
|
}
|
|
|
|