| | |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.ruoyi.basic.mapper.LaboratoryMapper; |
| | | import com.ruoyi.basic.pojo.Laboratory; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.device.dto.DeviceStateDto; |
| | | import com.ruoyi.device.mapper.DeviceMapper; |
| | | import com.ruoyi.device.mapper.DeviceStateMapper; |
| | | import com.ruoyi.device.pojo.Device; |
| | | import com.ruoyi.device.pojo.DeviceState; |
| | | import com.ruoyi.device.service.DeviceStateService; |
| | | import com.ruoyi.inspect.util.UserUtils; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | |
| | | |
| | | @Resource |
| | | private LaboratoryMapper laboratoryMapper; |
| | | @Resource |
| | | private UserMapper userMapper; |
| | | @Resource |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveDeviceState(DeviceState deviceState) { |
| | | User user = userMapper.selectById(SecurityUtils.getUserId().intValue()); |
| | | if (deviceState.getStateId() != null) { |
| | | DeviceState existing = baseMapper.selectById(deviceState.getStateId()); |
| | | if (existing == null) { |
| | | throw new ServiceException("单据不存在"); |
| | | } |
| | | if ("关闭".equals(existing.getCurrentState())) { |
| | | throw new ServiceException("该流程已结束,不能再操作"); |
| | | } |
| | | if (StringUtils.isNotBlank(existing.getCurrentResponsible()) |
| | | && !existing.getCurrentResponsible().equals(user.getName())) { |
| | | throw new ServiceException("您不是当前环节责任人,无权操作"); |
| | | } |
| | | } |
| | | boolean saved = saveOrUpdate(deviceState); |
| | | if (saved && "关闭".equals(deviceState.getCurrentState())) { |
| | | updateDeviceStatus(deviceState); |
| | | } |
| | | return saved; |
| | | } |
| | | |
| | | /** |
| | | * 流程最终批准后,把停用/启用结果同步到设备档案状态 |
| | | */ |
| | | private void updateDeviceStatus(DeviceState deviceState) { |
| | | if (deviceState.getDeviceId() == null) { |
| | | return; |
| | | } |
| | | Device device = deviceMapper.selectById(deviceState.getDeviceId()); |
| | | if (device == null) { |
| | | return; |
| | | } |
| | | Integer status = null; |
| | | if ("0scrap".equals(deviceState.getDeviceStatus())) { |
| | | status = 3; |
| | | } else if ("1startUsing".equals(deviceState.getDeviceStatus())) { |
| | | status = 0; |
| | | } else if ("2stopUsing".equals(deviceState.getDeviceStatus())) { |
| | | status = 2; |
| | | } |
| | | if (status != null) { |
| | | device.setDeviceStatus(status); |
| | | deviceMapper.updateById(device); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public IPage<DeviceStateDto> getDeviceStatePage(Integer deviceId, Page page, String processNumber) { |
| | |
| | | try { |
| | | response.setContentType("application/msword"); |
| | | String fileName = URLEncoder.encode( |
| | | "设备维护保养记录", "UTF-8"); |
| | | "设备停用启用记录", "UTF-8"); |
| | | response.setHeader("Content-disposition", |
| | | "attachment;filename=" + fileName + ".docx"); |
| | | OutputStream os = response.getOutputStream(); |