package org.jeecg.modules.system.app.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.system.app.entity.ShopMoney;
import org.jeecg.modules.system.app.mapper.ShopMoneyMapper;
import org.jeecg.modules.system.app.mapper.StatisticsMapper;
import org.jeecg.modules.system.app.service.IStatisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class StatisticsServiceImpl implements IStatisticsService {

    @Resource
    private StatisticsMapper statisticsMapper;
    @Resource
    private ShopMoneyMapper shopMoneyMapper;

    @Override
    public List<Map<String, Object>> findByShopSum(int type) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return statisticsMapper.findByShopSum(type,loginUser.getOrgCode());
    }

    @Override
    public List<Map<String, Object>> findByDeptSum(int type) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return statisticsMapper.findByDeptSum(type,loginUser.getOrgCode());
    }

    @Override
    public Map<String, Object> findIndexStatistics() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return statisticsMapper.findIndexStatistics(loginUser.getOrgCode());
    }

    @Override
    public List<Map<String, Object>> findMonthSaleTrend() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return statisticsMapper.findMonthSaleTrend(loginUser.getOrgCode());
    }

    @Override
    public List<Map<String, Object>> findShopAccountOverview(Page<Map<String, Object>> page, String name) {
        return statisticsMapper.findShopAccountOverview(page, name);
    }

    @Override
    public List<Map<String, Object>> findShopAccountOverviewDept() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return statisticsMapper.findShopAccountOverviewDept(loginUser.getOrgCode());
    }

    @Override
    public Page<ShopMoney> selectFundChanges(Page<ShopMoney> page, int incomeType, int moneyType, int changeInfo) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return shopMoneyMapper.selectFundChanges(page, loginUser.getOrgCode(), incomeType, moneyType, changeInfo);
    }
}
