chenhj
8 天以前 d55278560d29562b341aafa1652209a8aae0af33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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<MeasuringInstrumentLedgerRecordMapper, MeasuringInstrumentLedgerRecord> implements MeasuringInstrumentLedgerRecordService {
 
    private final MeasuringInstrumentLedgerRecordMapper measuringInstrumentLedgerRecordMapper;
    private final MeasuringInstrumentLedgerMapper measuringInstrumentLedgerMapper;
    private final CommonFileMapper commonFileMapper;
 
    @Override
    public IPage<MeasuringInstrumentLedgerRecord> listPage(Page page, MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord) {
        IPage<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecordIPage = measuringInstrumentLedgerRecordMapper.listPage(page, measuringInstrumentLedgerRecord);
        measuringInstrumentLedgerRecordIPage.getRecords().forEach(item -> {
            LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
            salesLedgerFileWrapper.eq(CommonFile::getCommonId, item.getId())
                    .eq(CommonFile::getType, FileNameType.MEASURINGRecord.getValue());
            List<CommonFile> commonFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
            item.setCommonFiles(commonFiles);
        });
        return measuringInstrumentLedgerRecordIPage;
    }
 
    @Override
    public void export(HttpServletResponse response) {
        List<MeasuringInstrumentLedgerRecord> list = measuringInstrumentLedgerRecordMapper.list( new MeasuringInstrumentLedgerRecord());
        ExcelUtil<MeasuringInstrumentLedgerRecord> util = new ExcelUtil<MeasuringInstrumentLedgerRecord>(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;
    }
}