package com.fs.his.service.impl;

import com.fs.common.constant.FsConstants;
import com.fs.common.core.redis.RedisCache;
import com.fs.common.utils.DateUtils;
import com.fs.his.domain.FsRedPacket;
import com.fs.his.service.IFsRedPacketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 红包Service业务层处理
 *
 * @author fs
 * @date 2023-10-23
 */
@Service
public class FsRedPacketServiceImpl implements IFsRedPacketService
{

    @Autowired
    private RedisCache redisCache;
    /**
     * @Description: 获取红包余额相关信息
     * @Param:
     * @Return:
     * @Author xgb
     * @Date 2025/11/4 11:52
     */
    @Override
    public FsRedPacket getInfo(Long companyId) {
       String yesterdayBalance =redisCache.getCacheObject(FsConstants.COMPANY_MONEY_DATE_KEY+companyId+":"+ DateUtils.getDate());
       String balance = redisCache.getCacheObject(FsConstants.COMPANY_MONEY_KEY+companyId);
       FsRedPacket fsRedPacket = new FsRedPacket();
       if(balance!=null){
           fsRedPacket.setRedBalance(new BigDecimal( balance));
           if(yesterdayBalance!=null){
               fsRedPacket.setRedTodayComsumption(fsRedPacket.getRedBalance().subtract(new BigDecimal(yesterdayBalance)));
           }
       }
       return fsRedPacket;
    }
}
