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.core.toolkit.CollectionUtils;
|
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.dto.MeasuringInstrumentLedgerDto;
|
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.MeasuringInstrumentLedgerService;
|
import com.ruoyi.project.system.domain.SysUser;
|
import com.ruoyi.project.system.mapper.SysUserMapper;
|
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.io.IOException;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author :yys
|
* @date : 2025/8/5 9:23
|
*/
|
@Service
|
@Slf4j
|
@RequiredArgsConstructor
|
public class MeasuringInstrumentLedgerServiceImpl extends ServiceImpl<MeasuringInstrumentLedgerMapper, MeasuringInstrumentLedger> implements MeasuringInstrumentLedgerService {
|
|
private final MeasuringInstrumentLedgerMapper measuringInstrumentLedgerMapper;
|
private final MeasuringInstrumentLedgerRecordMapper measuringInstrumentLedgerRecordMapper;
|
private final SysUserMapper sysUserMapper;
|
|
@Override
|
public IPage<MeasuringInstrumentLedger> listPage(Page page, MeasuringInstrumentLedger measuringInstrumentLedger) {
|
IPage<MeasuringInstrumentLedger> measuringInstrumentLedgerIPage = measuringInstrumentLedgerMapper.listPage(page, measuringInstrumentLedger);
|
List<Integer> types = new ArrayList<>();
|
types.add(FileNameType.MEASURING.getValue());
|
types.add(FileNameType.MEASURINGRecord.getValue());
|
measuringInstrumentLedgerIPage.getRecords().forEach(item -> {
|
LambdaQueryWrapper<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
measuringInstrumentLedgerRecordLambdaQueryWrapper.eq(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId, item.getId());
|
List<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecords = measuringInstrumentLedgerRecordMapper.selectList(measuringInstrumentLedgerRecordLambdaQueryWrapper);
|
List<Long> collect = new ArrayList<>();
|
if(!CollectionUtils.isEmpty(measuringInstrumentLedgerRecords)){
|
collect = measuringInstrumentLedgerRecords.stream().map(MeasuringInstrumentLedgerRecord::getId).collect(Collectors.toList());
|
}
|
collect.add(item.getId());
|
});
|
return measuringInstrumentLedgerIPage;
|
}
|
|
@Override
|
public boolean verifying(MeasuringInstrumentLedgerDto req) throws IOException {
|
MeasuringInstrumentLedger measuringInstrumentLedger = measuringInstrumentLedgerMapper.selectById(req.getId());
|
if(measuringInstrumentLedger == null) {
|
return false;
|
}
|
SysUser sysUser = sysUserMapper.selectUserById(measuringInstrumentLedger.getUserId());
|
measuringInstrumentLedger.setValid(req.getValid());
|
measuringInstrumentLedger.setMostDate(req.getRecordDate());
|
measuringInstrumentLedger.setNextDate(new Date(req.getRecordDate().getTime() + 1000L * 60 * 60 * 24 * req.getValid()));
|
MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord = new MeasuringInstrumentLedgerRecord();
|
if(measuringInstrumentLedgerMapper.updateById(measuringInstrumentLedger) > 0) {
|
measuringInstrumentLedgerRecord.setMeasuringInstrumentLedgerId(req.getId());
|
measuringInstrumentLedgerRecord.setRecordDate(req.getRecordDate());
|
measuringInstrumentLedgerRecord.setEntryDate(req.getEntryDate());
|
measuringInstrumentLedgerRecord.setValid(req.getValid());
|
measuringInstrumentLedgerRecord.setUserId(req.getUserId());
|
measuringInstrumentLedgerRecord.setUserName(sysUser.getUserName());
|
measuringInstrumentLedgerRecordMapper.insert(measuringInstrumentLedgerRecord);
|
// 台账绑定一次
|
// if(!CollectionUtils.isEmpty(req.getTempFileIds())){
|
// migrateTempFilesToFormal(measuringInstrumentLedger.getId(), req.getTempFileIds(), FileNameType.MEASURING.getValue());
|
// }
|
return true;
|
}
|
return false;
|
}
|
|
@Override
|
public void export(HttpServletResponse response) {
|
List<MeasuringInstrumentLedger> list = measuringInstrumentLedgerMapper.listPage(new MeasuringInstrumentLedger());
|
ExcelUtil<MeasuringInstrumentLedger> util = new ExcelUtil<MeasuringInstrumentLedger>(MeasuringInstrumentLedger.class);
|
util.exportExcel(response, list , "客户档案数据");
|
}
|
|
@Override
|
public boolean add(MeasuringInstrumentLedger measuringInstrumentLedger) throws IOException {
|
SysUser sysUser = sysUserMapper.selectUserById(measuringInstrumentLedger.getUserId());
|
if (sysUser == null) {
|
return false;
|
}
|
measuringInstrumentLedger.setUserName(sysUser.getUserName());
|
measuringInstrumentLedgerMapper.insert(measuringInstrumentLedger);
|
return true;
|
}
|
|
}
|