| | |
| | | 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.device.dto.DeviceStateDto; |
| | | import com.ruoyi.device.mapper.DeviceStateMapper; |
| | | import com.ruoyi.device.pojo.DeviceState; |
| | | import com.ruoyi.device.service.DeviceStateService; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import com.ruoyi.inspect.util.UserUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import jakarta.annotation.Resource; |
| | |
| | | |
| | | @Resource |
| | | private LaboratoryMapper laboratoryMapper; |
| | | |
| | | @Resource |
| | | private UserMapper userMapper; |
| | | |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | | |
| | | @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); |
| | | }}); |
| | | |