//package com.gree.mall.manager.logic.report;
//
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//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.enums.OfflineSaleRecordSaleTypeEnum;
//import com.gree.mall.manager.helper.ResponseHelper;
//import com.gree.mall.manager.logic.common.CommonLogic;
//import com.gree.mall.manager.plus.entity.AdminUserZone;
//import com.gree.mall.manager.plus.entity.AdminWebsit;
//import com.gree.mall.manager.plus.entity.OfflineSaleRecord;
//import com.gree.mall.manager.plus.entity.OrderInfo;
//import com.gree.mall.manager.plus.service.AdminUserZoneService;
//import com.gree.mall.manager.plus.service.AdminWebsitService;
//import com.gree.mall.manager.plus.service.OfflineSaleRecordService;
//import com.gree.mall.manager.plus.service.WebsitZoneService;
//import com.gree.mall.manager.utils.CommonUtils;
//import com.gree.mall.manager.utils.DateUtils;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestParam;
//
//import javax.servlet.http.HttpServletRequest;
//import java.math.BigDecimal;
//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 OfflineDataLogic {
//
//    @Autowired
//    private AdminWebsitService adminWebsitService;
//    @Autowired
//    private OfflineSaleRecordService offlineSaleRecordService;
//    @Autowired
//    private CommonLogic commonLogic;
//
//    public IPage<OfflineSaleRecord> page(HttpServletRequest request,String name, String phone, String websitName, String websitNumber,
//                                         String category, Integer num, BigDecimal minAmount, BigDecimal maxAmount, Boolean status,
//                                         String startTime, String endTime, Integer pageNum, Integer pageSize
//    ) {
//        /*AdminWebsitBean adminWebsitBean = CommonUtils.getAdminUser(request);
//        List<String> zoneIds = new ArrayList<>();
//        if(adminWebsitBean.getType() == 0){
//            List<AdminUserZone> adminWebsitBeanList = adminUserZoneService.lambdaQuery().eq(AdminUserZone::getAdminUserId,adminWebsitBean.getAdminUserId()).list();
//            if(CollectionUtils.isNotEmpty(adminWebsitBeanList)){
//                zoneIds = adminWebsitBeanList.stream().map(AdminUserZone::getAdminZoneId).collect(Collectors.toList());
//            }
//        }
//*/
//        AdminUserCom adminUser = commonLogic.getAdminUser(request);
//        List<String> companyWechatIds = adminUser.getCompanyWechatIds();
//        List<AdminWebsit> list = adminWebsitService.lambdaQuery()
//                //.//in(CollectionUtils.isNotEmpty(adminUser.getAdminWebsitIds()), AdminWebsit::getWebsitId, adminUser.getAdminWebsitIds())
//                .in(AdminWebsit::getCorpId, adminUser.getCorpIds())
//                .list();
//        List<String> websitNumbers = list.stream().map(AdminWebsit::getWebsitNumber).collect(Collectors.toList());
//
//        IPage page = offlineSaleRecordService.lambdaQuery()
//                .eq(status != null, OfflineSaleRecord::getStatus, status)
//                .in(CollectionUtils.isNotEmpty(websitNumbers),OfflineSaleRecord::getWebsitNumber,websitNumbers)
//                .in(CollectionUtils.isNotEmpty(companyWechatIds), OfflineSaleRecord::getCompanyWechatId, companyWechatIds)
//                .eq(num != null, OfflineSaleRecord::getSaleNum, num)
//                .like(StringUtils.isNotBlank(name), OfflineSaleRecord::getSaleManName, name)
//                .like(StringUtils.isNotBlank(phone), OfflineSaleRecord::getSalePhone, phone)
//                .like(StringUtils.isNotBlank(websitName), OfflineSaleRecord::getWebsitName, websitName)
//                .like(StringUtils.isNotBlank(websitNumber), OfflineSaleRecord::getWebsitNumber, websitNumber)
//                .like(StringUtils.isNotBlank(category), OfflineSaleRecord::getGoodsCategory, category)
//                .ge(minAmount != null, OfflineSaleRecord::getSaleAmount, minAmount)
//                .le(maxAmount != null, OfflineSaleRecord::getSaleAmount, maxAmount)
//                .ge(StringUtils.isNotBlank(startTime), OfflineSaleRecord::getSaleTime, startTime)
//                .le(StringUtils.isNotBlank(endTime), OfflineSaleRecord::getSaleTime, endTime)
//                .orderByDesc(OfflineSaleRecord::getCreateTime)
//                .page(new Page<>(pageNum, pageSize));
//
//        return page;
//    }
//
//
//    public void delete( String id) {
//        offlineSaleRecordService.removeById(id);
//    }
//
//
//    public OfflineSaleRecord detail( String id) {
//        return offlineSaleRecordService.getById(id);
//    }
//
//    public String save(HttpServletRequest request,OfflineSaleRecord offlineSaleRecord) {
//        /*AdminWebsitBean adminWebsitBean = CommonUtils.getAdminUser(request);*/
//       /* offlineSaleRecord.setAdminUserId(adminWebsitBean.getAdminUserId());*/
////        offlineSaleRecord.setZoneId();
//
//        AdminUserCom adminUser = commonLogic.getAdminUser(request);
//
//        offlineSaleRecord.setAdminUserId(adminUser.getCompanyWechatId());
//        offlineSaleRecord.setCompanyName(adminUser.getCompanyName());
//        offlineSaleRecord.setCreateTime(new Date());
//        offlineSaleRecordService.save(offlineSaleRecord);
//        return offlineSaleRecord.getId();
//    }
//
//    public void update(OfflineSaleRecord offlineSaleRecord) {
//        offlineSaleRecordService.updateById(offlineSaleRecord);
//    }
//
//    public ExcelData exportData(List<OfflineSaleRecord> list){
//        String[] titles = new String[]{"网点编号","网点名称","区域","销售员名称","销售员手机号","销售金额","销售数量"
//                ,"销售日期","销售类型","商品类型","商品名称","状态","创建时间"};
//
//        List<List<Object>> rows = new ArrayList<>();
//        for(OfflineSaleRecord bean:list){
//            List<Object> row = new ArrayList<>();
//            row.add(bean.getWebsitNumber());
//            row.add(bean.getWebsitName());
//            row.add(bean.getZoneName());
//            row.add(bean.getSaleManName());
//            row.add(bean.getSalePhone());
//            row.add(bean.getSaleAmount());
//            row.add(bean.getSaleNum());
//            row.add(DateUtils.formatDate(bean.getSaleTime()));
//            row.add(OfflineSaleRecordSaleTypeEnum.valueOf(bean.getSaleType()).getName());
//            row.add(bean.getGoodsCategory());
//            row.add(bean.getGoodsName());
//            row.add(bean.getStatus()?"正常":"异常");
//            row.add(DateUtils.formatDate(bean.getCreateTime()));
//            rows.add(row);
//        }
//        ExcelData excelData = new ExcelData();
//        excelData.setTitles(Arrays.asList(titles));
//        excelData.setRows(rows);
//        return excelData;
//    }
//}
