package com.bonus.canteen.core.report.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.report.domain.*;
import com.bonus.canteen.core.report.mapper.TradeReportMapper;
import com.bonus.canteen.core.report.service.TradeReportService;
import com.bonus.common.houqin.utils.SM4EncryptUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class TradeReportServiceImpl implements TradeReportService {
    @Resource
    TradeReportMapper tradeReportMapper;

    @Override
    public List<TradeFlowVO> selectTradeFlow(TradeFlowParam param) {
        String encryptedSearchValue = SM4EncryptUtils.sm4Encrypt(param.getSearchValue());
        List<TradeFlowVO> tradeFlowVOList = tradeReportMapper.selectTradeFlow(param, encryptedSearchValue);
        if(CollUtil.isNotEmpty(tradeFlowVOList)) {
            for(TradeFlowVO vo : tradeFlowVOList) {
                vo.setPhonenumber(SM4EncryptUtils.sm4Decrypt(vo.getPhonenumber()));
            }
        }
        return tradeFlowVOList;
    }

    @Override
    public List<OperatingRevenueVO> selectOperatingRevenue(OperatingRevenueParam param) {
        return tradeReportMapper.selectOperatingRevenue(param);
    }

    @Override
    public List<CanteenStallRevenueVO> selectCanteenStallRevenue(CanteenStallRevenueParam param) {
        return tradeReportMapper.selectCanteenStallRevenue(param);
    }

    @Override
    public List<DeviceRevenueVO> selectDeviceRevenue(DeviceRevenueParam param) {
        return tradeReportMapper.selectDeviceRevenue(param);
    }

    @Override
    public List<UserRevenueVO> selectUserRevenue(UserRevenueParam param) {
        return tradeReportMapper.selectUserRevenue(param, SM4EncryptUtils.sm4Encrypt(param.getSearchValue()));
    }

    @Override
    public List<GoodsRevenueVO> selectGoodsRevenue(GoodsRevenueParam param) {
        return tradeReportMapper.selectGoodsRevenue(param);
    }
}
