| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.constant.AssetStatusEnum; |
| | | import org.jeecg.modules.eam.constant.EquipmentLeanOutStatusEnum; |
| | | import org.jeecg.modules.eam.constant.*; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentLeanOut; |
| | | import org.jeecg.modules.eam.mapper.EamEquipmentLeanOutMapper; |
| | | import org.jeecg.modules.eam.request.EamEquipmentLeanOutQuery; |
| | | import org.jeecg.modules.eam.request.EamEquipmentLeanOutRequest; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentLeanOutService; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("equipment_lean_out", variables); |
| | | if (result != null) { |
| | | entity.setLeanStartTime(new Date()); |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_APPROVAL.name()); |
| | | //ä¿åå·¥å |
| | | equipmentLeanOutMapper.updateById(entity); |
| | | return result.isSuccess(); |
| | | } |
| | | return true; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public EamEquipmentLeanOut approval(EamEquipmentLeanOut eamEquipmentLeanOut) { |
| | | try { |
| | | // æ£æ¥è¯·æ±åæ° |
| | | if (!isValidRequest(eamEquipmentLeanOut)) { |
| | | throw new JeecgBootException("鿳忰"); |
| | | } |
| | | if (EquipmentLeanOutStatusEnum.WAIT_APPROVAL.name().equals(eamEquipmentLeanOut.getLeanStatus())) { |
| | | eamEquipmentLeanOut.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_RETURN.name()); |
| | | // å¾
å½è¿ |
| | | } else if (EquipmentLeanOutStatusEnum.WAIT_RETURN.name().equals(eamEquipmentLeanOut.getLeanStatus())) { |
| | | // å¾
确认 |
| | | eamEquipmentLeanOut.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_CONFIRM.name()); |
| | | } else if (EquipmentLeanOutStatusEnum.WAIT_CONFIRM.name().equals(eamEquipmentLeanOut.getLeanStatus())) { |
| | | // 已宿 |
| | | eamEquipmentLeanOut.setLeanStatus(EquipmentLeanOutStatusEnum.COMPLETE.name()); |
| | | } |
| | | // è·åå½åç»å½ç¨æ· |
| | | LoginUser sysUser = getCurrentUser(); |
| | | if (sysUser == null || StrUtil.isBlank(sysUser.getId())) { |
| | | throw new JeecgBootException("è´¦å·ä¸åå¨"); |
| | | } |
| | | // 审æ¹äºº |
| | | eamEquipmentLeanOut.setApprovalUser(sysUser.getUsername()); |
| | | //æ£æ¥è®¾å¤ |
| | | EamEquipment equipment = eamEquipmentService.getById(eamEquipmentLeanOut.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设å¤ä¸åå¨ï¼"); |
| | | } |
| | | eamEquipmentLeanOut.setLeanPerson(sysUser.getUsername()); |
| | | this.updateById(eamEquipmentLeanOut); |
| | | // è·åæµç¨ä¸å¡è®°å½ |
| | | return eamEquipmentLeanOut; |
| | | } catch (Exception e) { |
| | | throw new JeecgBootException("æä½å¤±è´¥ï¼" + e.getMessage()); |
| | | public EamEquipmentLeanOut approval(EamEquipmentLeanOutRequest request) { |
| | | EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(request.getId()); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("审æ¹çæ°æ®å·²å é¤ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | // è·åå½åç»å½ç¨æ· |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null || StrUtil.isBlank(user.getId())) { |
| | | throw new JeecgBootException("æªè·åå°ç»å½ç¨æ·ï¼è¯·éæ°ç»å½ååè¯ï¼"); |
| | | } |
| | | request.setApprovalUser(user.getUsername()); |
| | | // è·åæµç¨ä¸å¡è®°å½ |
| | | FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId()); |
| | | if (flowMyBusiness == null) { |
| | | throw new JeecgBootException("æµç¨å®ä¾ä¸åå¨ï¼è¯·å·æ°åéè¯ï¼"); |
| | | } |
| | | |
| | | boolean userAuthorized = isUserAuthorized(flowMyBusiness, user); |
| | | if (!userAuthorized) { |
| | | throw new JeecgBootException("ç¨æ·æ ææä½æ¤ä»»å¡ï¼è¯·å·æ°åéè¯ï¼"); |
| | | } |
| | | // 认é¢ä»»å¡ |
| | | if (!claimTask(flowMyBusiness.getTaskId(), user)) { |
| | | throw new JeecgBootException("ä»»å¡ä¸åå¨ã已宿æå·²è¢«ä»äººè®¤é¢ï¼"); |
| | | } |
| | | |
| | | EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设å¤ä¸åå¨ï¼è¯·æ£æ¥ï¼"); |
| | | } |
| | | |
| | | EquipmentLeanOutStatusEnum status = EquipmentLeanOutStatusEnum.getInstance(entity.getLeanStatus()); |
| | | if (status == null) { |
| | | return null; |
| | | } |
| | | //æµç¨åé |
| | | Map<String, Object> values = new HashMap<>(); |
| | | switch (status) { |
| | | // å®¡æ¹ |
| | | case WAIT_APPROVAL: |
| | | //æ§è¡å®æ |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getApprovalComment()); |
| | | values.put("comment", request.getApprovalComment()); |
| | | values.put("approvalDealType", request.getApprovalDealType()); |
| | | request.setComment(request.getApprovalComment()); |
| | | entity.setApprovalUser(user.getUsername());// å®¡æ ¸äºº |
| | | entity.setApprovalComment(request.getApprovalComment());// å®¡æ ¸æè§ |
| | | entity.setApprovalTime(new Date());// å®¡æ ¸æ¶é´ |
| | | entity.setApprovalDealType(request.getApprovalDealType()); // 审æ¹ç±»å |
| | | // éªè¯éè¿è¿æ¯é©³å |
| | | if (request.getApprovalDealType().equals("1")) { |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_RETURN.name()); |
| | | List<String> userApprovalList = new ArrayList<>(Collections.singletonList(entity.getLeanPerson())); |
| | | values.put("NextAssignee", userApprovalList); |
| | | } else { |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.COMPLETE.name()); |
| | | } |
| | | break; |
| | | // å½è¿ |
| | | case WAIT_RETURN: |
| | | if (StringUtils.isBlank(equipment.getEquipmentManager())) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
设å¤ç®¡çåï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | List<String> userApprovalList = new ArrayList<>(Collections.singletonList(entity.getLeanPerson())); |
| | | userApprovalList.add(equipment.getEquipmentManager()); |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getReturnComment()); |
| | | values.put("comment", request.getReturnComment()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | request.setComment(request.getReturnComment()); |
| | | entity.setLeanEndTime(new Date()); //å½è¿æ¶é´ |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_CONFIRM.name()); |
| | | entity.setApprovalUser(user.getUsername());// å®¡æ ¸äºº |
| | | entity.setLeanEndTime(new Date());// å½è¿æ¶é´ |
| | | entity.setReturnComment(request.getReturnComment());// å½è¿å¤æ³¨ |
| | | break; |
| | | // å½è¿ç¡®è®¤ |
| | | case WAIT_CONFIRM: |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getConfirmComment()); |
| | | values.put("comment", request.getConfirmComment()); |
| | | request.setComment(request.getConfirmComment()); |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.COMPLETE.name()); |
| | | entity.setConfirmUser(user.getUsername()); |
| | | entity.setConfirmComment(request.getConfirmComment()); |
| | | entity.setConfirmTime(new Date()); |
| | | // ä¿®æ¹è®¾å¤ç¶æ |
| | | equipment.setAssetStatus(AssetStatusEnum.NORMAL.name()); |
| | | eamEquipmentService.updateById(equipment); |
| | | break; |
| | | } |
| | | request.setValues(values); |
| | | |
| | | // 宿æµç¨ä»»å¡ |
| | | Result result = flowTaskService.complete(request); |
| | | if (!result.isSuccess()) { |
| | | throw new JeecgBootException("审æ¹å¤±è´¥ï¼è¯·å·æ°æ¥çï¼"); |
| | | } |
| | | //ä¿åå·¥å |
| | | equipmentLeanOutMapper.updateById(entity); |
| | | return entity; |
| | | } |
| | | |
| | | |
| | |
| | | business.getActStatus(); |
| | | } |
| | | |
| | | |
| | | private boolean isValidRequest(EamEquipmentLeanOut request) { |
| | | return StrUtil.isNotBlank(request.getCode()) && StrUtil.isNotBlank(request.getEquipmentId()); |
| | | private boolean claimTask(String taskId, LoginUser user) { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return false; |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return false; |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | return true; |
| | | } |
| | | |
| | | private LoginUser getCurrentUser() { |
| | | try { |
| | | return (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | /** |
| | | * å¤æç¨æ·æ¯å¦æ¥ææ¤æé |
| | | * |
| | | * @param flowMyBusiness |
| | | * @param user |
| | | * @return |
| | | */ |
| | | private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) { |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | return todoUsers != null && todoUsers.contains(user.getUsername()); |
| | | } |
| | | |
| | | @Override |