| | |
| | | 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 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; |
| | | |
| | |
| | | vo.setStorageBlobVOs(fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum.DEVICE_MAINTENANCE, id)); |
| | | return vo; |
| | | } |
| | | |
| | | @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() + " 条保养记录"); |
| | | } |
| | | } |