| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.utils.FileUtil; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.device.dto.DeviceMaintenanceDto; |
| | |
| | | import com.ruoyi.device.mapper.DeviceMaintenanceMapper; |
| | | import com.ruoyi.device.pojo.DeviceMaintenance; |
| | | import com.ruoyi.device.service.IDeviceMaintenanceService; |
| | | import com.ruoyi.device.vo.DeviceMaintenanceVo; |
| | | import com.ruoyi.device.vo.DeviceRepairVo; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SpareParts; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | private final DeviceMaintenanceMapper deviceMaintenanceMapper; |
| | | private final SparePartsMapper sparePartsMapper; |
| | | private final SparePartsRequisitionRecordService sparePartsRequisitionRecordService; |
| | | private final FileUtil fileUtil; |
| | | |
| | | @Override |
| | | public IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult saveDeviceRepair(DeviceMaintenance deviceMaintenance) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult saveDeviceRepair(DeviceMaintenanceDto deviceMaintenance) { |
| | | boolean save = this.save(deviceMaintenance); |
| | | if (save){ |
| | | // 处理图片上传 |
| | | fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs()); |
| | | return AjaxResult.success(); |
| | | } |
| | | return AjaxResult.error(); |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenance deviceMaintenance) { |
| | | public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenanceDto deviceMaintenance) { |
| | | DeviceMaintenance oldDeviceMaintenance = this.getById(deviceMaintenance.getId()); |
| | | // 处理备件使用情况 |
| | | if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(deviceMaintenance.getSparePartsUseList())) { |
| | |
| | | } |
| | | |
| | | if (this.updateById(deviceMaintenance)) { |
| | | // 处理图片上传 |
| | | fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs()); |
| | | return AjaxResult.success(); |
| | | } |
| | | return AjaxResult.error(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DeviceMaintenanceDto detailById(Long id) { |
| | | public DeviceMaintenanceVo detailById(Long id) { |
| | | DeviceMaintenanceVo vo = deviceMaintenanceMapper.detailById(id); |
| | | vo.setStorageBlobVOs(fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum.DEVICE_MAINTENANCE, id)); |
| | | return vo; |
| | | } |
| | | |
| | | return deviceMaintenanceMapper.detailById(id); |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult complete(Long id) { |
| | | DeviceMaintenance record = this.getById(id); |
| | | if (record == null) { |
| | | return AjaxResult.error("保养记录不存在"); |
| | | } |
| | | if (record.getStatus() != null && record.getStatus() == 1) { |
| | | return AjaxResult.error("该保养记录已完成"); |
| | | } |
| | | record.setStatus(1); |
| | | record.setMaintenanceActuallyName(SecurityUtils.getLoginUser().getNickName()); |
| | | record.setMaintenanceActuallyTime(LocalDateTime.now()); |
| | | this.updateById(record); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult batchComplete(String dateStr) { |
| | | if (StringUtils.isBlank(dateStr)) { |
| | | return AjaxResult.error("日期参数不能为空"); |
| | | } |
| | | LocalDate date = LocalDate.parse(dateStr); |
| | | LocalDateTime startOfDay = date.atStartOfDay(); |
| | | LocalDateTime endOfDay = date.atTime(LocalTime.MAX); |
| | | List<DeviceMaintenance> records = this.lambdaQuery() |
| | | .eq(DeviceMaintenance::getStatus, 0) |
| | | .ge(DeviceMaintenance::getCreateTime, startOfDay) |
| | | .le(DeviceMaintenance::getCreateTime, endOfDay) |
| | | .list(); |
| | | if (records.isEmpty()) { |
| | | return AjaxResult.error("该日期下没有待完成的保养记录"); |
| | | } |
| | | String nickName = SecurityUtils.getLoginUser().getNickName(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | for (DeviceMaintenance record : records) { |
| | | record.setStatus(1); |
| | | record.setMaintenanceActuallyName(nickName); |
| | | record.setMaintenanceActuallyTime(now); |
| | | } |
| | | this.updateBatchById(records); |
| | | return AjaxResult.success("已完成 " + records.size() + " 条保养记录"); |
| | | } |
| | | } |