package com.kxs.user.biz.service.impl;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kxs.common.security.util.SecurityUtils;
import com.kxs.user.api.model.old.TradeDaySummary;
import com.kxs.user.api.vo.kxsapp.userLevel.AmountDetailVO;
import com.kxs.user.biz.mapper.old.TradeDaySummaryMapper;
import com.kxs.user.biz.service.TradeDaySummaryService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 交易统计查询
 *
 * @author 没秃顶的码农
 * @date 2024-02-27
 */
@Service
public class TradeDaySummaryServiceImpl extends ServiceImpl<TradeDaySummaryMapper, TradeDaySummary> implements TradeDaySummaryService {


    @Override
    public AmountDetailVO amountDetail() {

        Long userId = SecurityUtils.getUser().getId();
        AmountDetailVO amountDetailVO = new AmountDetailVO();
        String thisMonth = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.SIMPLE_MONTH_PATTERN);

        BigDecimal pos = baseMapper.currentMonthsPosTotal(userId, thisMonth);
        pos = pos == null ? BigDecimal.ZERO : pos;
        BigDecimal pos2 = baseMapper.currentMonthsPosTotal2(userId, thisMonth);
        pos2 = pos2 == null ? BigDecimal.ZERO : pos2;
        amountDetailVO.setPos(pos.add(pos2));

        Integer gd = baseMapper.currentMonthsGdTotal(userId, thisMonth);
        gd = gd == null ? 0 : gd;
        amountDetailVO.setGd(gd);

        BigDecimal zlb = baseMapper.currentMonthsZlbTotal(userId, thisMonth);
        zlb = zlb == null ? BigDecimal.ZERO : zlb;
        amountDetailVO.setZlb(zlb);

        return amountDetailVO;
    }
}
