package com.cool.bang.modules.business.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.business.domain.Corp;
import com.cool.bang.modules.business.domain.DataCollection;
import com.cool.bang.modules.business.domain.DataCount;
import com.cool.bang.modules.business.service.ICorpService;
import com.cool.bang.modules.business.service.IDataCollectionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据集合
 *
 * @author PeiZhi Guo
 * @version 1.0.0
 * 2024-10-31 17:05
 */
@RestController
@RequestMapping(ControllerConstant.BUSINESS + "data/v1")
public class DataDistrictController extends BaseController {

    @Autowired
    private IDataCollectionService dataCollectionService;

    @Autowired
    private ICorpService corpService;


    @GetMapping
    @PreAuthorize("hasPermission('','business:tj:main')")
    public ResultTable main(PageDomain pageDomain, DataCount param) {
        PageInfo<DataCount> clfDataCollectionPage = dataCollectionService.queryByDataCountList(pageDomain, param);
        return pageTable(clfDataCollectionPage.getList(), clfDataCollectionPage.getTotal());
    }

    @GetMapping("view")
    public Result getview(Integer district,String yearMonth) {
        return success(dataCollectionService.queryByDataView(yearMonth,district));
    }

    @GetMapping("end")
    public Result get(Integer district,String yearMonth) {
        return success(dataCollectionService.addIsEnd(yearMonth,district));
    }

    @GetMapping("count")
    public Result getCount() {
        List<DataCount> queryByDataCount = dataCollectionService.queryByDataCount();
        DataCollection dataCollection = new DataCollection();
        dataCollection.setDataCountList(queryByDataCount);
        dataCollection.setSaleNumber(corpService.list(new Corp()).size());
        dataCollection.setOtherSaleNumber(dataCollectionService.list(new DataCollection()).size());
        return success(dataCollection);
    }

}
