| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.DataBaseConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | 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.entity.EamEquipmentSealUp; |
| | | 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.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 设备借出归还 |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean equipmentReturn(String id) { |
| | | EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(id); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("要提交的数据不存在,请刷新重试!"); |
| | | } |
| | | if (!EquipmentLeanOutStatusEnum.WAIT_RETURN.name().equals(entity.getLeanStatus())) { |
| | | throw new JeecgBootException("当前数据状态不允许编辑!"); |
| | | } |
| | | //检查设备 |
| | | EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设备不存在!"); |
| | | } |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | throw new JeecgBootException("当前用户无法编辑封存记录!"); |
| | | } |
| | | //启动审批流程 |
| | | flowCommonService.initActBusiness("工单号:" + entity.getCode() + ";设备编号: " + equipment.getEquipmentCode() + ";进行设备归还", |
| | | entity.getId(), "IEamEquipmentLeanOutService", "equipment_return", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", entity.getId()); |
| | | variables.put("organization", "新增归还默认归还流程"); |
| | | variables.put("comment", "新增归还默认归还流程"); |
| | | variables.put("proofreading", true); |
| | | // 分配给设备管理员 |
| | | List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getOrgId(), BusinessCodeConst.PCR0004); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("设备未分配给设备管理员,无法进入下级审批!"); |
| | | } |
| | | List<String> usernames = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("equipment_return", variables); |
| | | if (result != null) { |
| | | entity.setLeanEndTime(new Date()); |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_CONFIRM.name()); |
| | | //保存工单 |
| | | equipmentLeanOutMapper.updateById(entity); |
| | | return result.isSuccess(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.LEAN_OUT, businessTable = "eam_equipment_lean_out") |
| | | public EamEquipmentLeanOut approval(EamEquipmentLeanOutRequest request) { |
| | | EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(request.getId()); |
| | | if (entity == null) { |
| | |
| | | } else { |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.COMPLETE.name()); |
| | | // 修改设备状态 |
| | | equipment.setAssetStatus(AssetStatusEnum.NORMAL.name()); |
| | | eamEquipmentService.updateById(equipment); |
| | | } |
| | | break; |
| | | // 归还 |
| | |
| | | values.put("organization", request.getReturnComment()); |
| | | values.put("comment", request.getReturnComment()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | values.put("approvalDealType", "1"); |
| | | request.setComment(request.getReturnComment()); |
| | | entity.setLeanEndTime(new Date()); //归还时间 |
| | | //设置entity |
| | |
| | | break; |
| | | // 归还确认 |
| | | case WAIT_CONFIRM: |
| | | values.put("approvalDealType", "1"); |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getConfirmComment()); |
| | | values.put("comment", request.getConfirmComment()); |
| | | request.setComment(request.getConfirmComment()); |
| | | //设置entity |
| | | entity.setApprovalUser(user.getUsername());// 审核人 |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.COMPLETE.name()); |
| | | entity.setConfirmUser(user.getUsername()); |
| | | entity.setConfirmComment(request.getConfirmComment()); |
| | | entity.setConfirmTime(new Date()); |
| | | // 修改设备状态 |
| | | // 修改设备状态0 |
| | | equipment.setAssetStatus(AssetStatusEnum.NORMAL.name()); |
| | | eamEquipmentService.updateById(equipment); |
| | | break; |