//package com.gree.mall.manager.logic.report;
//
//import org.apache.commons.collections4.CollectionUtils;
//import com.gree.mall.manager.bean.ExcelData;
//import com.gree.mall.manager.bean.admin.AdminUserCom;
//import com.gree.mall.manager.bean.admin.AdminWebsitBean;
//import com.gree.mall.manager.commonmapper.CustomSalesReportMapper;
//import com.gree.mall.manager.logic.common.CommonLogic;
//import com.gree.mall.manager.plus.entity.AdminWebsit;
//import com.gree.mall.manager.plus.entity.SaleReport;
//import com.gree.mall.manager.plus.entity.WebsitZone;
//import com.gree.mall.manager.plus.service.AdminWebsitService;
//import com.gree.mall.manager.utils.CommonUtils;
//import com.gree.mall.manager.utils.excel.ExcelUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Date;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Service
//@Slf4j
//public class SalesReportLogic {
//
//    @Autowired
//    private CustomSalesReportMapper customSalesReportMapper;
//    @Autowired
//    AdminWebsitService adminWebsitService;
//    @Autowired
//    CommonLogic commonLogic;
//
//
//    public List<SaleReport> realTimeStatistics(HttpServletRequest request,String startTime,String endTime) {
//
//        AdminUserCom adminUser = commonLogic.getAdminUser(request);
//
//        List<String> adminWebsitIds = adminUser.getAdminWebsitIds();
//
//
//        if (adminUser.getType() != 0 || CollectionUtils.isEmpty(adminWebsitIds)) {
//            //超管
//            List<SaleReport> saleReports = customSalesReportMapper.queryData(null,startTime, endTime,adminUser.getCorpIds());
//            return saleReports;
//        } else {
//            //拥有的网点权限
//            List<AdminWebsit> list = adminWebsitService.lambdaQuery().in(AdminWebsit::getWebsitId, adminWebsitIds).list();
//            List<String> websitNumbers = list.stream().map(AdminWebsit::getWebsitNumber).collect(Collectors.toList());
//            //网点帐号
//            List<SaleReport> saleReports = customSalesReportMapper.queryData(websitNumbers,startTime, endTime,adminUser.getCorpIds());
//            return saleReports;
//        }
//    }
//
//
//    public void exportData(HttpServletRequest request,HttpServletResponse response,String startTime,String endTime) throws Exception {
//
//        List<SaleReport> list = this.realTimeStatistics(request,startTime,endTime);
//
//        String[] titles = {"区域", "网点编号", "网点名称", "当天销售金额", "当天商城开单人数", "格匠商城（线上）金额", "占比", "线下零售/批发（线下）金额", "占比",
//                "工程（线下）金额", "占比"};
//        ExcelData excelData = new ExcelData();
//        List<List<Object>> rows = new ArrayList<>();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//        for (SaleReport saleReport : list) {
//            List<Object> row = new ArrayList<>();
//            row.add(saleReport.getZoneName());
//            row.add(saleReport.getWebsitNumber());
//            row.add(saleReport.getWebsitName());
//            row.add(saleReport.getSaleTotalAmount());
//            row.add(saleReport.getBillNum());
//            row.add(saleReport.getSaleOnlineAmount());
//            row.add(saleReport.getSaleOnlinePercent());
//            row.add(saleReport.getSaleOfflineSaleAmount());
//            row.add(saleReport.getSaleOfflineSalePercent());
//            row.add(saleReport.getSaleOfflineProAmount());
//            row.add(saleReport.getSaleOfflineProPercent());
//            rows.add(row);
//        }
//
//        String fileName = String.format("报表导出%s.xlsx", simpleDateFormat.format(new Date()));
//        excelData.setTitles(Arrays.asList(titles));
//        excelData.setName("报表");
//        excelData.setRows(rows);
//        ExcelUtils.exportExcel(request, response, fileName, excelData, -1, null);
//    }
//
//
//
//}
