17 小时以前 46944d762174e5b7e7a627c59928e2a3c9e03dd4
src/main/java/com/ruoyi/device/service/impl/DeviceMaintenanceServiceImpl.java
@@ -4,40 +4,46 @@
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.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.dto.DeviceMaintenanceDto;
import com.ruoyi.device.execl.DeviceMaintenanceExeclDto;
import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.device.pojo.DeviceMaintenance;
import com.ruoyi.device.service.IDeviceLedgerService;
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.project.system.service.ISysNoticeService;
import com.ruoyi.measuringinstrumentledger.pojo.SpareParts;
import com.ruoyi.measuringinstrumentledger.pojo.SparePartsRequisitionRecord;
import com.ruoyi.measuringinstrumentledger.service.SparePartsRequisitionRecordService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jakarta.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Service
@RequiredArgsConstructor
public class DeviceMaintenanceServiceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements IDeviceMaintenanceService {
    @Autowired
    private DeviceMaintenanceMapper deviceMaintenanceMapper;
    @Autowired
    private SparePartsMapper sparePartsMapper;
    @Autowired
    private SparePartsRequisitionRecordService sparePartsRequisitionRecordService;
    private final DeviceMaintenanceMapper deviceMaintenanceMapper;
    private final IDeviceLedgerService deviceLedgerService;
    private final SparePartsMapper sparePartsMapper;
    private final SparePartsRequisitionRecordService sparePartsRequisitionRecordService;
    private final FileUtil fileUtil;
    private final ISysNoticeService sysNoticeService;
    @Override
    public IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto) {
@@ -46,9 +52,18 @@
    }
    @Override
    public AjaxResult saveDeviceRepair(DeviceMaintenance deviceMaintenance) {
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult saveDeviceRepair(DeviceMaintenanceDto deviceMaintenance) {
        DeviceLedger byId = deviceLedgerService.getById(deviceMaintenance.getDeviceLedgerId());
        if (byId != null) {
            deviceMaintenance.setDeviceName(byId.getDeviceName());
            deviceMaintenance.setDeviceModel(byId.getDeviceModel());
            deviceMaintenance.setAreaId(byId.getAreaId());
        }
        boolean save = this.save(deviceMaintenance);
        if (save){
            // 处理图片上传
            fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs());
            return AjaxResult.success();
        }
        return AjaxResult.error();
@@ -56,8 +71,17 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenance deviceMaintenance) {
    public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenanceDto deviceMaintenance) {
        DeviceMaintenance oldDeviceMaintenance = this.getById(deviceMaintenance.getId());
        Long effectiveDeviceLedgerId = deviceMaintenance.getDeviceLedgerId() != null
                ? deviceMaintenance.getDeviceLedgerId()
                : oldDeviceMaintenance.getDeviceLedgerId();
        DeviceLedger byId = deviceLedgerService.getById(effectiveDeviceLedgerId);
        if (byId != null) {
            deviceMaintenance.setDeviceName(byId.getDeviceName());
            deviceMaintenance.setDeviceModel(byId.getDeviceModel());
            deviceMaintenance.setAreaId(byId.getAreaId());
        }
        // 处理备件使用情况
        if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(deviceMaintenance.getSparePartsUseList())) {
            List<Long> sparePartIds = new ArrayList<>();
@@ -71,6 +95,18 @@
                        spareParts.setQuantity(spareParts.getQuantity().subtract(new BigDecimal(sparePartUse.getQuantity())));
                        sparePartsMapper.updateById(spareParts);
                        sparePartIds.add(sparePartUse.getId());
                        // 库存预警通知
                        if (spareParts.getWarnNum() != null && spareParts.getNotifyPersonId() != null
                                && spareParts.getQuantity().compareTo(spareParts.getWarnNum()) < 0) {
                            sysNoticeService.simpleNoticeByUser(
                                    "备件库存预警",
                                    "备件【" + spareParts.getName() + "】当前库存(" + spareParts.getQuantity()
                                            + ")已低于预警数量(" + spareParts.getWarnNum() + "),请及时采购补充。",
                                    List.of(spareParts.getNotifyPersonId()),
                                    "/equipmentManagement/spareParts"
                                    );
                        }
                        // 创建备件领用记录
                        SparePartsRequisitionRecord record = new SparePartsRequisitionRecord();
@@ -92,6 +128,8 @@
        }
        if (this.updateById(deviceMaintenance)) {
            // 处理图片上传
            fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_MAINTENANCE, deviceMaintenance.getId(), deviceMaintenance.getStorageBlobDTOs());
            return AjaxResult.success();
        }
        return AjaxResult.error();
@@ -113,8 +151,9 @@
    }
    @Override
    public DeviceMaintenanceDto detailById(Long id) {
        return deviceMaintenanceMapper.detailById(id);
    public DeviceMaintenanceVo detailById(Long id) {
        DeviceMaintenanceVo vo = deviceMaintenanceMapper.detailById(id);
        vo.setStorageBlobVOs(fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum.DEVICE_MAINTENANCE, id));
        return vo;
    }
}