package com.slodon.b2b2c.controller.statistics.admin;

import com.slodon.b2b2c.bo.*;
import com.slodon.b2b2c.core.controller.BaseController;
import com.slodon.b2b2c.core.response.JsonResult;
import com.slodon.b2b2c.core.response.SldResponse;
import com.slodon.b2b2c.model.statistics.*;
import com.slodon.b2b2c.model.system.SettingModel;
import com.slodon.b2b2c.statistics.pojo.*;
import com.slodon.b2b2c.statistics.pojo.base.*;
import com.slodon.b2b2c.system.pojo.Setting;
import com.slodon.b2b2c.util.StatsDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.List;

@Api(tags = "admin-定时任务补充管理")
@RestController
@RequestMapping("v3/statistics/admin/stats/job")
public class StatsJobController extends BaseController {

    @Resource
    private StatsDataUtil statsDataUtil;

    //region model
    //小时model
    @Resource
    private BrandHourModel brandHourModel;
    @Resource
    private CategoryHourModel categoryHourModel;
    @Resource
    private GoodsHourModel goodsHourModel;
    @Resource
    private MemberHourModel memberHourModel;
    @Resource
    private MemberStoreHourModel memberStoreHourModel;
    @Resource
    private PlatformHourModel platformHourModel;
    @Resource
    private ProvinceHourModel provinceHourModel;
    @Resource
    private StoreHourModel storeHourModel;
    @Resource
    private TerminalHourModel terminalHourModel;

    //日model
    @Resource
    private BrandDayModel brandDayModel;
    @Resource
    private CategoryDayModel categoryDayModel;
    @Resource
    private GoodsDayModel goodsDayModel;
    @Resource
    private MemberDayModel memberDayModel;
    @Resource
    private MemberStoreDayModel memberStoreDayModel;
    @Resource
    private PlatformDayModel platformDayModel;
    @Resource
    private ProvinceDayModel provinceDayModel;
    @Resource
    private StoreDayModel storeDayModel;
    @Resource
    private TerminalDayModel terminalDayModel;

    //周model
    @Resource
    private BrandWeekModel brandWeekModel;
    @Resource
    private CategoryWeekModel categoryWeekModel;
    @Resource
    private GoodsWeekModel goodsWeekModel;
    @Resource
    private MemberWeekModel memberWeekModel;
    @Resource
    private MemberStoreWeekModel memberStoreWeekModel;
    @Resource
    private PlatformWeekModel platformWeekModel;
    @Resource
    private ProvinceWeekModel provinceWeekModel;
    @Resource
    private StoreWeekModel storeWeekModel;
    @Resource
    private TerminalWeekModel terminalWeekModel;

    //月model
    @Resource
    private BrandMonthModel brandMonthModel;
    @Resource
    private CategoryMonthModel categoryMonthModel;
    @Resource
    private GoodsMonthModel goodsMonthModel;
    @Resource
    private MemberMonthModel memberMonthModel;
    @Resource
    private MemberStoreMonthModel memberStoreMonthModel;
    @Resource
    private PlatformMonthModel platformMonthModel;
    @Resource
    private ProvinceMonthModel provinceMonthModel;
    @Resource
    private StoreMonthModel storeMonthModel;
    @Resource
    private TerminalMonthModel terminalMonthModel;

    //年model
    @Resource
    private BrandYearModel brandYearModel;
    @Resource
    private CategoryYearModel categoryYearModel;
    @Resource
    private GoodsYearModel goodsYearModel;
    @Resource
    private MemberYearModel memberYearModel;
    @Resource
    private MemberStoreYearModel memberStoreYearModel;
    @Resource
    private PlatformYearModel platformYearModel;
    @Resource
    private ProvinceYearModel provinceYearModel;
    @Resource
    private StoreYearModel storeYearModel;
    @Resource
    private TerminalYearModel terminalYearModel;
    //endregion

    @ApiOperation("小时统计任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(name = "webSite", value = "站点")
    })
    @GetMapping("hourStats")
    public JsonResult hourStats(Date startTime, Date endTime, @RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {

        //1.查询阶段内的统计基础数据
        StatsBasicDataBO basicDataBO = statsDataUtil.searchStatsBasicData(startTime, endTime, webSite);

        //2.保存品牌统计表
        Collection<BrandOrderBO> brandOrderBOS = statsDataUtil.buildBrandStatsInfo(basicDataBO);
        brandOrderBOS.forEach(brandOrderBO -> {
            BrandBase brandBase = brandOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            BrandHour brandHour = new BrandHour();
            brandHour.copy(brandBase);
            brandHour.setWebSite(webSite);
            brandHourModel.saveBrandHour(brandHour);
        });

        //3.保存商品分类统计表
        Collection<CategoryOrderBO> categoryOrderBOS = statsDataUtil.buildCategoryStatsInfo(basicDataBO);
        categoryOrderBOS.forEach(categoryOrderBO -> {
            CategoryBase categoryBase = categoryOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            CategoryHour categoryHour = new CategoryHour();
            categoryHour.copy(categoryBase);
            categoryHour.setWebSite(webSite);
            categoryHourModel.saveCategoryHour(categoryHour);
        });

        //4.保存商品统计
        Collection<GoodsStatsBO> goodsStatsBOS = statsDataUtil.buildGoodsStatsInfo(basicDataBO);
        goodsStatsBOS.forEach(goodsStatsBO -> {
            GoodsBase goodsBase = goodsStatsBO.initStats(startTime, basicDataBO.getOrderMap());
            GoodsHour goodsHour = new GoodsHour();
            goodsHour.copy(goodsBase);
            goodsHour.setWebSite(webSite);
            goodsHourModel.saveGoodsHour(goodsHour);
        });

        //5.保存会员统计
        Collection<MemberStatsBO> memberStatsBOS = statsDataUtil.buildMemberStatsInfo(basicDataBO);
        memberStatsBOS.forEach(memberStatsBO -> {
            MemberBase memberBase = memberStatsBO.initStats(startTime);
            MemberHour memberHour = new MemberHour();
            memberHour.copy(memberBase);
            memberHour.setWebSite(webSite);
            memberHourModel.saveMemberHour(memberHour);
        });

        //6.保存店铺会员统计
        Collection<MemberStoreStatsBO> memberStoreStatsBOS = statsDataUtil.buildMemberStoreStatsInfo(basicDataBO);
        memberStoreStatsBOS.forEach(memberStoreStatsBO -> {
            MemberStoreBase memberStoreBase = memberStoreStatsBO.initStats(startTime);
            MemberStoreHour memberStoreHour = new MemberStoreHour();
            memberStoreHour.copy(memberStoreBase);
            memberStoreHour.setWebSite(webSite);
            memberStoreHourModel.saveMemberStoreHour(memberStoreHour);
        });

        //7.保存平台统计
        PlatformStatsBO platformStatsBO = new PlatformStatsBO();
        PlatformBase platformBase = platformStatsBO.initStats(startTime, basicDataBO);
        PlatformHour platformHour = new PlatformHour();
        platformHour.copy(platformBase);
        platformHour.setWebSite(webSite);
        platformHourModel.savePlatformHour(platformHour);

        //8.保存省份统计
        Collection<ProvinceStatsBO> provinceStatsBOS = statsDataUtil.buildProvinceStatsInfo(basicDataBO);
        provinceStatsBOS.forEach(provinceStatsBO -> {
            ProvinceBase provinceBase = provinceStatsBO.initStats(startTime);
            ProvinceHour provinceHour = new ProvinceHour();
            provinceHour.copy(provinceBase);
            provinceHourModel.saveProvinceHour(provinceHour);
        });

        //9.保存店铺统计
        Collection<StoreStatsBO> storeStatsBOS = statsDataUtil.buildStoreStatsInfo(basicDataBO);
        storeStatsBOS.forEach(storeStatsBO -> {
            StoreBase storeBase = storeStatsBO.initStats(startTime);
            StoreHour storeHour = new StoreHour();
            storeHour.copy(storeBase);
            storeHour.setWebSite(webSite);
            storeHourModel.saveStoreHour(storeHour);
        });

        //10.保存终端统计
        Collection<TerminalStatsBO> terminalStatsBOS = statsDataUtil.buildTerminalStatsInfo(basicDataBO);
        terminalStatsBOS.forEach(terminalStatsBO -> {
            TerminalBase terminalBase = terminalStatsBO.initStats(startTime);
            TerminalHour terminalHour = new TerminalHour();
            terminalHour.copy(terminalBase);
            terminalHourModel.saveTerminalHour(terminalHour);
        });


        return SldResponse.success();
    }

    @ApiOperation("日统计任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(name = "webSite", value = "站点")
    })
    @GetMapping("dayStats")
    public JsonResult dayStats(Date startTime, Date endTime,@RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
        //1.查询阶段内的统计基础数据
        StatsBasicDataBO basicDataBO = statsDataUtil.searchStatsBasicData(startTime, endTime,webSite);

        //2.保存品牌统计表
        Collection<BrandOrderBO> brandOrderBOS = statsDataUtil.buildBrandStatsInfo(basicDataBO);
        brandOrderBOS.forEach(brandOrderBO -> {
            BrandBase brandBase = brandOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            BrandDay brandDay = new BrandDay();
            brandDay.copy(brandBase);
            brandDay.setWebSite(webSite);
            brandDayModel.saveBrandDay(brandDay);
        });

        //3.保存商品分类统计表
        Collection<CategoryOrderBO> categoryOrderBOS = statsDataUtil.buildCategoryStatsInfo(basicDataBO);
        categoryOrderBOS.forEach(categoryOrderBO -> {
            CategoryBase categoryBase = categoryOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            CategoryDay categoryDay = new CategoryDay();
            categoryDay.copy(categoryBase);
            categoryDay.setWebSite(webSite);
            categoryDayModel.saveCategoryDay(categoryDay);
        });

        //4.保存商品统计
        Collection<GoodsStatsBO> goodsStatsBOS = statsDataUtil.buildGoodsStatsInfo(basicDataBO);
        goodsStatsBOS.forEach(goodsStatsBO -> {
            GoodsBase goodsBase = goodsStatsBO.initStats(startTime, basicDataBO.getOrderMap());
            GoodsDay goodsDay = new GoodsDay();
            goodsDay.copy(goodsBase);
            goodsDay.setWebSite(webSite);
            goodsDayModel.saveGoodsDay(goodsDay);
        });

        //5.保存会员统计
        Collection<MemberStatsBO> memberStatsBOS = statsDataUtil.buildMemberStatsInfo(basicDataBO);
        memberStatsBOS.forEach(memberStatsBO -> {
            MemberBase memberBase = memberStatsBO.initStats(startTime);
            MemberDay memberDay = new MemberDay();
            memberDay.copy(memberBase);
            memberDay.setWebSite(webSite);
            memberDayModel.saveMemberDay(memberDay);
        });

        //6.保存店铺会员统计
        Collection<MemberStoreStatsBO> memberStoreStatsBOS = statsDataUtil.buildMemberStoreStatsInfo(basicDataBO);
        memberStoreStatsBOS.forEach(memberStoreStatsBO -> {
            MemberStoreBase memberStoreBase = memberStoreStatsBO.initStats(startTime);
            MemberStoreDay memberStoreDay = new MemberStoreDay();
            memberStoreDay.copy(memberStoreBase);
            memberStoreDay.setWebSite(webSite);
            memberStoreDayModel.saveMemberStoreDay(memberStoreDay);
        });

        //7.保存平台统计
        PlatformStatsBO platformStatsBO = new PlatformStatsBO();
        PlatformBase platformBase = platformStatsBO.initStats(startTime, basicDataBO);
        PlatformDay platformDay = new PlatformDay();
        platformDay.copy(platformBase);
        platformDayModel.savePlatformDay(platformDay);

        //8.保存省份统计
        Collection<ProvinceStatsBO> provinceStatsBOS = statsDataUtil.buildProvinceStatsInfo(basicDataBO);
        provinceStatsBOS.forEach(provinceStatsBO -> {
            ProvinceBase provinceBase = provinceStatsBO.initStats(startTime);
            ProvinceDay provinceDay = new ProvinceDay();
            provinceDay.copy(provinceBase);
            provinceDayModel.saveProvinceDay(provinceDay);
        });

        //9.保存店铺统计
        Collection<StoreStatsBO> storeStatsBOS = statsDataUtil.buildStoreStatsInfo(basicDataBO);
        storeStatsBOS.forEach(storeStatsBO -> {
            StoreBase storeBase = storeStatsBO.initStats(startTime);
            StoreDay storeDay = new StoreDay();
            storeDay.copy(storeBase);
            storeDay.setWebSite(webSite);
            storeDayModel.saveStoreDay(storeDay);
        });

        //10.保存终端统计
        Collection<TerminalStatsBO> terminalStatsBOS = statsDataUtil.buildTerminalStatsInfo(basicDataBO);
        terminalStatsBOS.forEach(terminalStatsBO -> {
            TerminalBase terminalBase = terminalStatsBO.initStats(startTime);
            TerminalDay terminalDay = new TerminalDay();
            terminalDay.copy(terminalBase);
            terminalDayModel.saveTerminalDay(terminalDay);
        });
        return SldResponse.success();
    }

    @ApiOperation("周统计任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(name = "webSite", value = "站点")
    })
    @GetMapping("weekStats")
    public JsonResult weekStats(Date startTime, Date endTime,@RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
        //1.查询阶段内的统计基础数据
        StatsBasicDataBO basicDataBO = statsDataUtil.searchStatsBasicData(startTime, endTime,webSite);

        //2.保存品牌统计表
        Collection<BrandOrderBO> brandOrderBOS = statsDataUtil.buildBrandStatsInfo(basicDataBO);
        brandOrderBOS.forEach(brandOrderBO -> {
            BrandBase brandBase = brandOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            BrandWeek brandWeek = new BrandWeek();
            brandWeek.copy(brandBase);
            brandWeek.setWebSite(webSite);
            brandWeekModel.saveBrandWeek(brandWeek);
        });

        //3.保存商品分类统计表
        Collection<CategoryOrderBO> categoryOrderBOS = statsDataUtil.buildCategoryStatsInfo(basicDataBO);
        categoryOrderBOS.forEach(categoryOrderBO -> {
            CategoryBase categoryBase = categoryOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            CategoryWeek categoryWeek = new CategoryWeek();
            categoryWeek.copy(categoryBase);
            categoryWeek.setWebSite(webSite);
            categoryWeekModel.saveCategoryWeek(categoryWeek);
        });

        //4.保存商品统计
        Collection<GoodsStatsBO> goodsStatsBOS = statsDataUtil.buildGoodsStatsInfo(basicDataBO);
        goodsStatsBOS.forEach(goodsStatsBO -> {
            GoodsBase goodsBase = goodsStatsBO.initStats(startTime, basicDataBO.getOrderMap());
            GoodsWeek goodsWeek = new GoodsWeek();
            goodsWeek.copy(goodsBase);
            goodsWeek.setWebSite(webSite);
            goodsWeekModel.saveGoodsWeek(goodsWeek);
        });

        //5.保存会员统计
        Collection<MemberStatsBO> memberStatsBOS = statsDataUtil.buildMemberStatsInfo(basicDataBO);
        memberStatsBOS.forEach(memberStatsBO -> {
            MemberBase memberBase = memberStatsBO.initStats(startTime);
            MemberWeek memberWeek = new MemberWeek();
            memberWeek.copy(memberBase);
            memberWeek.setWebSite(webSite);
            memberWeekModel.saveMemberWeek(memberWeek);
        });

        //6.保存店铺会员统计
        Collection<MemberStoreStatsBO> memberStoreStatsBOS = statsDataUtil.buildMemberStoreStatsInfo(basicDataBO);
        memberStoreStatsBOS.forEach(memberStoreStatsBO -> {
            MemberStoreBase memberStoreBase = memberStoreStatsBO.initStats(startTime);
            MemberStoreWeek memberStoreWeek = new MemberStoreWeek();
            memberStoreWeek.copy(memberStoreBase);
            memberStoreWeek.setWebSite(webSite);
            memberStoreWeekModel.saveMemberStoreWeek(memberStoreWeek);
        });

        //7.保存平台统计
        PlatformStatsBO platformStatsBO = new PlatformStatsBO();
        PlatformBase platformBase = platformStatsBO.initStats(startTime, basicDataBO);
        PlatformWeek platformWeek = new PlatformWeek();
        platformWeek.copy(platformBase);
        platformWeekModel.savePlatformWeek(platformWeek);

        //8.保存省份统计
        Collection<ProvinceStatsBO> provinceStatsBOS = statsDataUtil.buildProvinceStatsInfo(basicDataBO);
        provinceStatsBOS.forEach(provinceStatsBO -> {
            ProvinceBase provinceBase = provinceStatsBO.initStats(startTime);
            ProvinceWeek provinceWeek = new ProvinceWeek();
            provinceWeek.copy(provinceBase);
            provinceWeekModel.saveProvinceWeek(provinceWeek);
        });

        //9.保存店铺统计
        Collection<StoreStatsBO> storeStatsBOS = statsDataUtil.buildStoreStatsInfo(basicDataBO);
        storeStatsBOS.forEach(storeStatsBO -> {
            StoreBase storeBase = storeStatsBO.initStats(startTime);
            StoreWeek storeWeek = new StoreWeek();
            storeWeek.copy(storeBase);
            storeWeek.setWebSite(webSite);
            storeWeekModel.saveStoreWeek(storeWeek);
        });

        //10.保存终端统计
        Collection<TerminalStatsBO> terminalStatsBOS = statsDataUtil.buildTerminalStatsInfo(basicDataBO);
        terminalStatsBOS.forEach(terminalStatsBO -> {
            TerminalBase terminalBase = terminalStatsBO.initStats(startTime);
            TerminalWeek terminalWeek = new TerminalWeek();
            terminalWeek.copy(terminalBase);
            terminalWeekModel.saveTerminalWeek(terminalWeek);
        });
        return SldResponse.success();
    }

    @ApiOperation("月统计任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(name = "webSite", value = "站点")
    })
    @GetMapping("monthStats")
    public JsonResult monthStats(Date startTime, Date endTime,@RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
        //1.查询阶段内的统计基础数据
        StatsBasicDataBO basicDataBO = statsDataUtil.searchStatsBasicData(startTime, endTime,webSite);

        //2.保存品牌统计表
        Collection<BrandOrderBO> brandOrderBOS = statsDataUtil.buildBrandStatsInfo(basicDataBO);
        brandOrderBOS.forEach(brandOrderBO -> {
            BrandBase brandBase = brandOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            BrandMonth brandMonth = new BrandMonth();
            brandMonth.copy(brandBase);
            brandMonth.setWebSite(webSite);
            brandMonthModel.saveBrandMonth(brandMonth);
        });

        //3.保存商品分类统计表
        Collection<CategoryOrderBO> categoryOrderBOS = statsDataUtil.buildCategoryStatsInfo(basicDataBO);
        categoryOrderBOS.forEach(categoryOrderBO -> {
            CategoryBase categoryBase = categoryOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            CategoryMonth categoryMonth = new CategoryMonth();
            categoryMonth.copy(categoryBase);
            categoryMonth.setWebSite(webSite);
            categoryMonthModel.saveCategoryMonth(categoryMonth);
        });

        //4.保存商品统计
        Collection<GoodsStatsBO> goodsStatsBOS = statsDataUtil.buildGoodsStatsInfo(basicDataBO);
        goodsStatsBOS.forEach(goodsStatsBO -> {
            GoodsBase goodsBase = goodsStatsBO.initStats(startTime, basicDataBO.getOrderMap());
            GoodsMonth goodsMonth = new GoodsMonth();
            goodsMonth.copy(goodsBase);
            goodsMonth.setWebSite(webSite);
            goodsMonthModel.saveGoodsMonth(goodsMonth);
        });

        //5.保存会员统计
        Collection<MemberStatsBO> memberStatsBOS = statsDataUtil.buildMemberStatsInfo(basicDataBO);
        memberStatsBOS.forEach(memberStatsBO -> {
            MemberBase memberBase = memberStatsBO.initStats(startTime);
            MemberMonth memberMonth = new MemberMonth();
            memberMonth.copy(memberBase);
            memberMonth.setWebSite(webSite);
            memberMonthModel.saveMemberMonth(memberMonth);
        });

        //6.保存店铺会员统计
        Collection<MemberStoreStatsBO> memberStoreStatsBOS = statsDataUtil.buildMemberStoreStatsInfo(basicDataBO);
        memberStoreStatsBOS.forEach(memberStoreStatsBO -> {
            MemberStoreBase memberStoreBase = memberStoreStatsBO.initStats(startTime);
            MemberStoreMonth memberStoreMonth = new MemberStoreMonth();
            memberStoreMonth.copy(memberStoreBase);
            memberStoreMonth.setWebSite(webSite);
            memberStoreMonthModel.saveMemberStoreMonth(memberStoreMonth);
        });

        //7.保存平台统计
        PlatformStatsBO platformStatsBO = new PlatformStatsBO();
        PlatformBase platformBase = platformStatsBO.initStats(startTime, basicDataBO);
        PlatformMonth platformMonth = new PlatformMonth();
        platformMonth.copy(platformBase);
        platformMonthModel.savePlatformMonth(platformMonth);

        //8.保存省份统计
        Collection<ProvinceStatsBO> provinceStatsBOS = statsDataUtil.buildProvinceStatsInfo(basicDataBO);
        provinceStatsBOS.forEach(provinceStatsBO -> {
            ProvinceBase provinceBase = provinceStatsBO.initStats(startTime);
            ProvinceMonth provinceMonth = new ProvinceMonth();
            provinceMonth.copy(provinceBase);
            provinceMonthModel.saveProvinceMonth(provinceMonth);
        });

        //9.保存店铺统计
        Collection<StoreStatsBO> storeStatsBOS = statsDataUtil.buildStoreStatsInfo(basicDataBO);
        storeStatsBOS.forEach(storeStatsBO -> {
            StoreBase storeBase = storeStatsBO.initStats(startTime);
            StoreMonth storeMonth = new StoreMonth();
            storeMonth.copy(storeBase);
            storeMonth.setWebSite(webSite);
            storeMonthModel.saveStoreMonth(storeMonth);
        });

        //10.保存终端统计
        Collection<TerminalStatsBO> terminalStatsBOS = statsDataUtil.buildTerminalStatsInfo(basicDataBO);
        terminalStatsBOS.forEach(terminalStatsBO -> {
            TerminalBase terminalBase = terminalStatsBO.initStats(startTime);
            TerminalMonth terminalMonth = new TerminalMonth();
            terminalMonth.copy(terminalBase);
            terminalMonthModel.saveTerminalMonth(terminalMonth);
        });
        return SldResponse.success();
    }

    @ApiOperation("年统计任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(name = "webSite", value = "站点")
    })
    @GetMapping("yearStats")
    public JsonResult yearStats(Date startTime, Date endTime,@RequestParam(value = "webSite", required = false, defaultValue = "1") String webSite) {
        //1.查询阶段内的统计基础数据
        StatsBasicDataBO basicDataBO = statsDataUtil.searchStatsBasicData(startTime, endTime,webSite);

        //2.保存品牌统计表
        Collection<BrandOrderBO> brandOrderBOS = statsDataUtil.buildBrandStatsInfo(basicDataBO);
        brandOrderBOS.forEach(brandOrderBO -> {
            BrandBase brandBase = brandOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            BrandYear brandYear = new BrandYear();
            brandYear.copy(brandBase);
            brandYear.setWebSite(webSite);
            brandYearModel.saveBrandYear(brandYear);
        });

        //3.保存商品分类统计表
        Collection<CategoryOrderBO> categoryOrderBOS = statsDataUtil.buildCategoryStatsInfo(basicDataBO);
        categoryOrderBOS.forEach(categoryOrderBO -> {
            CategoryBase categoryBase = categoryOrderBO.initStats(startTime, basicDataBO.getOrderMap());
            CategoryYear categoryYear = new CategoryYear();
            categoryYear.copy(categoryBase);
            categoryYear.setWebSite(webSite);
            categoryYearModel.saveCategoryYear(categoryYear);
        });

        //4.保存商品统计
        Collection<GoodsStatsBO> goodsStatsBOS = statsDataUtil.buildGoodsStatsInfo(basicDataBO);
        goodsStatsBOS.forEach(goodsStatsBO -> {
            GoodsBase goodsBase = goodsStatsBO.initStats(startTime, basicDataBO.getOrderMap());
            GoodsYear goodsYear = new GoodsYear();
            goodsYear.copy(goodsBase);
            goodsYear.setWebSite(webSite);
            goodsYearModel.saveGoodsYear(goodsYear);
        });

        //5.保存会员统计
        Collection<MemberStatsBO> memberStatsBOS = statsDataUtil.buildMemberStatsInfo(basicDataBO);
        memberStatsBOS.forEach(memberStatsBO -> {
            MemberBase memberBase = memberStatsBO.initStats(startTime);
            MemberYear memberYear = new MemberYear();
            memberYear.copy(memberBase);
            memberYear.setWebSite(webSite);
            memberYearModel.saveMemberYear(memberYear);
        });

        //6.保存店铺会员统计
        Collection<MemberStoreStatsBO> memberStoreStatsBOS = statsDataUtil.buildMemberStoreStatsInfo(basicDataBO);
        memberStoreStatsBOS.forEach(memberStoreStatsBO -> {
            MemberStoreBase memberStoreBase = memberStoreStatsBO.initStats(startTime);
            MemberStoreYear memberStoreYear = new MemberStoreYear();
            memberStoreYear.copy(memberStoreBase);
            memberStoreYear.setWebSite(webSite);
            memberStoreYearModel.saveMemberStoreYear(memberStoreYear);
        });

        //7.保存平台统计
        PlatformStatsBO platformStatsBO = new PlatformStatsBO();
        PlatformBase platformBase = platformStatsBO.initStats(startTime, basicDataBO);
        PlatformYear platformYear = new PlatformYear();
        platformYear.copy(platformBase);
        platformYearModel.savePlatformYear(platformYear);

        //8.保存省份统计
        Collection<ProvinceStatsBO> provinceStatsBOS = statsDataUtil.buildProvinceStatsInfo(basicDataBO);
        provinceStatsBOS.forEach(provinceStatsBO -> {
            ProvinceBase provinceBase = provinceStatsBO.initStats(startTime);
            ProvinceYear provinceYear = new ProvinceYear();
            provinceYear.copy(provinceBase);
            provinceYearModel.saveProvinceYear(provinceYear);
        });

        //9.保存店铺统计
        Collection<StoreStatsBO> storeStatsBOS = statsDataUtil.buildStoreStatsInfo(basicDataBO);
        storeStatsBOS.forEach(storeStatsBO -> {
            StoreBase storeBase = storeStatsBO.initStats(startTime);
            StoreYear storeYear = new StoreYear();
            storeYear.copy(storeBase);
            storeYear.setWebSite(webSite);
            storeYearModel.saveStoreYear(storeYear);
        });

        //10.保存终端统计
        Collection<TerminalStatsBO> terminalStatsBOS = statsDataUtil.buildTerminalStatsInfo(basicDataBO);
        terminalStatsBOS.forEach(terminalStatsBO -> {
            TerminalBase terminalBase = terminalStatsBO.initStats(startTime);
            TerminalYear terminalYear = new TerminalYear();
            terminalYear.copy(terminalBase);
            terminalYearModel.saveTerminalYear(terminalYear);
        });
        return SldResponse.success();
    }
}
