| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.deepoove.poi.data.Pictures; |
| | | 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.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.util.UserUtils; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | 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; |
| | | |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | | @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) { |
| | |
| | | Laboratory laboratory = laboratoryMapper.selectOne(Wrappers.<Laboratory>lambdaQuery() |
| | | .eq(Laboratory::getLaboratoryNumber, largeCategory) |
| | | .select(Laboratory::getLaboratoryName)); |
| | | laboratoryName = laboratory.getLaboratoryName(); |
| | | laboratoryName = laboratory != null ? laboratory.getLaboratoryName() : ""; |
| | | } else { |
| | | laboratoryName = ""; |
| | | } |
| | | |
| | | //todo: 设备状态查询签名地址 暂时人名查询 |
| | | //获取申请人的签名地址 |
| | | String applicantUrl = null; |
| | | if (deviceStateDto.getSubmitOperatingPersonnel() != null) { |
| | | applicantUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery() |
| | | .eq(User::getName, deviceStateDto.getSubmitOperatingPersonnel())) |
| | | .getSignatureUrl(); |
| | | if (StringUtils.isBlank(applicantUrl)) { |
| | | throw new ErrorException("找不到申请人的签名"); |
| | | } |
| | | } |
| | | |
| | | //获取部门负责人的签名地址 |
| | | String headOfDepartmentUrl = null; |
| | | if (deviceStateDto.getDepartmentNextPesponsible() != null) { |
| | | headOfDepartmentUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery() |
| | | .eq(User::getName, deviceStateDto.getDepartmentNextPesponsible())) |
| | | .getSignatureUrl(); |
| | | if (StringUtils.isBlank(headOfDepartmentUrl)) { |
| | | throw new ErrorException("找不到部门负责人的签名"); |
| | | } |
| | | } |
| | | |
| | | //获取计量室复测人的签名地址 |
| | | String measurementRoomUrl = null; |
| | | if (deviceStateDto.getMeasuringRoomNextPesponsible() != null) { |
| | | measurementRoomUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery() |
| | | .eq(User::getName, deviceStateDto.getMeasuringRoomNextPesponsible())) |
| | | .getSignatureUrl(); |
| | | if (StringUtils.isBlank(measurementRoomUrl)) { |
| | | throw new ErrorException("找不到计量室复测人的签名"); |
| | | } |
| | | } |
| | | |
| | | //获取批准人的签名地址 |
| | | String approvedUrl = null; |
| | | if (deviceStateDto.getApprovalNextPesponsible() != null) { |
| | | approvedUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery() |
| | | .eq(User::getName, deviceStateDto.getApprovalNextPesponsible())) |
| | | .getSignatureUrl(); |
| | | if (StringUtils.isBlank(approvedUrl)) { |
| | | throw new ErrorException("找不到批准人的签名"); |
| | | } |
| | | } |
| | | |
| | | // 获取路径 |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/word/device-status.docx"); |
| | | Configure configure = Configure.builder() |
| | | .build(); |
| | | String finalApplicantUrl = applicantUrl; // 申请人的签名地址 |
| | | String finalHeadOfDepartmentUrl = headOfDepartmentUrl; // 部门负责人的签名地址 |
| | | String finalMeasurementRoomUrl = measurementRoomUrl; // 计量室复测人的签名地址 |
| | | String finalApprovedUrl = approvedUrl; // 批准人的签名地址 |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("deviceStateDto", deviceStateDto); |
| | | put("submitOperatingPersonnelUrl", StringUtils.isNotBlank(finalApplicantUrl) ? Pictures.ofLocal(imgUrl + "/" + finalApplicantUrl).create() : null); |
| | | put("departmentNextPesponsibleUrl", StringUtils.isNotBlank(finalHeadOfDepartmentUrl) ? Pictures.ofLocal(imgUrl + "/" + finalHeadOfDepartmentUrl).create() : null); |
| | | put("measuringRoomNextPesponsibleUrl", StringUtils.isNotBlank(finalMeasurementRoomUrl) ? Pictures.ofLocal(imgUrl + "/" + finalMeasurementRoomUrl).create() : null); |
| | | put("approvalNextPesponsibleUrl", StringUtils.isNotBlank(finalApprovedUrl) ? Pictures.ofLocal(imgUrl + "/" + finalApprovedUrl).create() : null); |
| | | // 签名兜底: 人员未配置签名或签名文件缺失时返回透明图片, 保证导出不因空图片报错 |
| | | put("submitOperatingPersonnelUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getSubmitOperatingPersonnel())); |
| | | put("departmentNextPesponsibleUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getDepartmentNextPesponsible())); |
| | | put("measuringRoomNextPesponsibleUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getMeasuringRoomNextPesponsible())); |
| | | put("approvalNextPesponsibleUrl", UserUtils.getFinalUserSignatureOrTransparent(deviceStateDto.getApprovalNextPesponsible())); |
| | | put("laboratory", laboratoryName); |
| | | }}); |
| | | |
| | | 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(); |