package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.OperatingReportNew;
import com.ym.mec.biz.dal.page.OperatingReportNewQueryInfo;
import com.ym.mec.biz.service.OperatingReportNewService;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Objects;

@Api(tags = "经营报表服务")
@RequestMapping("operatingReportNew")
@RestController
public class OperatingReportNewController extends BaseController {

    @Autowired
    private OperatingReportNewService operatingReportNewService;
    @Autowired
    private OrganizationService organizationService;

    @GetMapping(value = "/execTask")
    public void operatingReportMonth(Date month){
        if(Objects.isNull(month)){
            month = DateUtil.addMonths(new Date(),-1);
        }
        operatingReportNewService.operatingReportMonth(month);
    }

    @ApiOperation("报表列表")
    @GetMapping(value = "/queryPage")
    @PreAuthorize("@pcs.hasPermissions('operatingReportNew/queryPage')")
    public HttpResponseResult<PageInfo<OperatingReportNew>> queryPage(OperatingReportNewQueryInfo queryInfo) {
        queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
        return succeed(operatingReportNewService.queryPage(queryInfo));
    }
}
