package com.ruoyi.business.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.basic.entity.CoalInfo;
|
import com.ruoyi.basic.mapper.CoalInfoMapper;
|
import com.ruoyi.business.entity.CarbonCubes;
|
import com.ruoyi.business.entity.PurchaseRegistration;
|
import com.ruoyi.business.mapper.CarbonCubesMapper;
|
import com.ruoyi.business.service.CarbonCubesService;
|
import com.ruoyi.common.core.domain.R;
|
import lombok.RequiredArgsConstructor;
|
import org.checkerframework.checker.units.qual.A;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDate;
|
|
@Service
|
@RequiredArgsConstructor
|
public class CarbonCubesServiceImpl extends ServiceImpl<CarbonCubesMapper, CarbonCubes> implements CarbonCubesService {
|
@Autowired
|
private final CoalInfoMapper coalInfoMapper;
|
|
|
|
@Override
|
public R addCarbonCubes(CarbonCubes carbonCubes) {
|
CoalInfo oldCoalInfo = coalInfoMapper.selectOne(new QueryWrapper<CoalInfo>().lambda().eq(CoalInfo::getCoal, carbonCubes.getCoal()));
|
CoalInfo coalInfo = new CoalInfo();
|
if (ObjectUtils.isEmpty(oldCoalInfo)) {
|
//新增煤种信息
|
coalInfo.setCoal(carbonCubes.getCoal());
|
coalInfo.setMaintainerId(1L);
|
coalInfo.setMaintenanceDate(LocalDate.now());
|
coalInfoMapper.insert(coalInfo);
|
}else {
|
coalInfo = oldCoalInfo;
|
}
|
carbonCubes.setCreateTime(LocalDate.now());
|
carbonCubes.setCoalId(coalInfo.getId());
|
CarbonCubes one = this.getOne(new QueryWrapper<CarbonCubes>().lambda()
|
.eq(CarbonCubes::getBillNumber, carbonCubes.getBillNumber()));
|
if (ObjectUtils.isEmpty(one)) {
|
// 新增
|
this.save(carbonCubes);
|
}else {
|
// 修改
|
this.update(carbonCubes, new QueryWrapper<CarbonCubes>().lambda()
|
.eq(CarbonCubes::getBillNumber, carbonCubes.getBillNumber()));
|
}
|
return R.ok();
|
}
|
}
|