package com.xzx.gc.order.service;
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.NumberUtil;
|
import com.xzx.gc.entity.PlatformAccountInfo;
|
import com.xzx.gc.entity.PlatformAccountLog;
|
import com.xzx.gc.order.mapper.PlatformAccountLogMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Service
|
@Transactional
|
public class PlatformAccountLogService {
|
|
@Autowired
|
private PlatformAccountLogMapper platformAccountLogMapper;
|
|
@Autowired
|
private PlatformAccountInfoService platformAccountInfoService;
|
|
|
public void add(PlatformAccountLog platformAccountLog){
|
platformAccountLog.setCreateTime(DateUtil.now());
|
List<PlatformAccountInfo> platformAccountInfos = platformAccountInfoService.find();
|
if(CollUtil.isNotEmpty(platformAccountInfos)){
|
BigDecimal money=Convert.toBigDecimal(platformAccountInfos.stream().filter(x->x.getFieldKey().equals("money")).collect(Collectors.toList()).get(0).getFieldValue());
|
BigDecimal hbb=Convert.toBigDecimal(platformAccountInfos.stream().filter(x->x.getFieldKey().equals("hbb")).collect(Collectors.toList()).get(0).getFieldValue());
|
if(platformAccountLog.getHbb()!=null){
|
platformAccountLog.setOldHbb(hbb);
|
BigDecimal add = NumberUtil.add(hbb,platformAccountLog.getHbb());
|
platformAccountLog.setNewHbb(add);
|
}
|
|
if(platformAccountLog.getMoney()!=null){
|
platformAccountLog.setOldMoney(money);
|
BigDecimal add = NumberUtil.add(money,platformAccountLog.getMoney());
|
platformAccountLog.setNewMoney(add);
|
}
|
}
|
platformAccountLogMapper.insertSelective(platformAccountLog);
|
}
|
}
|