package com.ruoyi.measuringinstrumentledger.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.common.enums.FileNameType; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerMapper; import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerRecordMapper; import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedger; import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedgerRecord; import com.ruoyi.measuringinstrumentledger.service.MeasuringInstrumentLedgerRecordService; import com.ruoyi.sales.mapper.CommonFileMapper; import com.ruoyi.sales.pojo.CommonFile; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; /** * @author :yys * @date : 2025/8/5 9:24 */ @Service @Slf4j @RequiredArgsConstructor public class MeasuringInstrumentLedgerRecordServiceImpl extends ServiceImpl implements MeasuringInstrumentLedgerRecordService { private final MeasuringInstrumentLedgerRecordMapper measuringInstrumentLedgerRecordMapper; private final MeasuringInstrumentLedgerMapper measuringInstrumentLedgerMapper; private final CommonFileMapper commonFileMapper; @Override public IPage listPage(Page page, MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord) { IPage measuringInstrumentLedgerRecordIPage = measuringInstrumentLedgerRecordMapper.listPage(page, measuringInstrumentLedgerRecord); measuringInstrumentLedgerRecordIPage.getRecords().forEach(item -> { LambdaQueryWrapper salesLedgerFileWrapper = new LambdaQueryWrapper<>(); salesLedgerFileWrapper.eq(CommonFile::getCommonId, item.getId()) .eq(CommonFile::getType, FileNameType.MEASURINGRecord.getValue()); List commonFiles = commonFileMapper.selectList(salesLedgerFileWrapper); item.setCommonFiles(commonFiles); }); return measuringInstrumentLedgerRecordIPage; } @Override public void export(HttpServletResponse response) { List list = measuringInstrumentLedgerRecordMapper.list( new MeasuringInstrumentLedgerRecord()); ExcelUtil util = new ExcelUtil(MeasuringInstrumentLedgerRecord.class); util.exportExcel(response, list , "计量器具台账记录数据"); } @Override public boolean updateMeasuringInstrumentLedgerRecord(MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord) { MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord1 = measuringInstrumentLedgerRecordMapper.selectById(measuringInstrumentLedgerRecord.getId()); if (measuringInstrumentLedgerRecord1 == null) { return false; } // 有效期变更,重新计算预计下次检定日期 if(!measuringInstrumentLedgerRecord1.getValid().equals(measuringInstrumentLedgerRecord.getValid())){ MeasuringInstrumentLedger measuringInstrumentLedger = measuringInstrumentLedgerMapper.selectById(measuringInstrumentLedgerRecord1.getMeasuringInstrumentLedgerId()); if(measuringInstrumentLedger != null){ measuringInstrumentLedger.setValid(measuringInstrumentLedgerRecord.getValid()); measuringInstrumentLedger.setNextDate(new Date(measuringInstrumentLedger.getMostDate().getTime() + measuringInstrumentLedgerRecord.getValid() * 24 * 60 * 60 * 1000L)); } measuringInstrumentLedgerMapper.updateById(measuringInstrumentLedger); } measuringInstrumentLedgerRecordMapper.updateById(measuringInstrumentLedgerRecord); return true; } }