package me.zhengjie.modules.dm.statement.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.dm.statement.service.DmHaveDinnerService;
import me.zhengjie.modules.dm.statement.service.dto.DmHaveDinnerDto;
import me.zhengjie.modules.dm.statement.service.dto.DmHaveDinnerQueryCriteria;
import me.zhengjie.modules.dm.statement.service.dto.DmStatementDto;
import me.zhengjie.modules.dm.statement.service.dto.DmStatementQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Transactional
@RestController
@RequiredArgsConstructor
@Api(tags = "haveDinner管理")
@RequestMapping("/api/dmHaveDinner")
public class DmHaveDinnerController {
    private final DmHaveDinnerService dmHaveDinnerService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('dmHaveDinner:list')")
    public void download(HttpServletResponse response, String stateDate, String endDate, String type, Pageable pageable) throws IOException {
        Map<String,Object> map = dmHaveDinnerService.selectZgHaveDinner(stateDate,endDate,type,pageable);
        List<DmHaveDinnerDto> all = (List<DmHaveDinnerDto>)map.get("content");
        if (type.equals("week")){
            dmHaveDinnerService.downWeekload(all, response);
        }else {
            dmHaveDinnerService.download(all, response);
        }
    }


    @GetMapping(value = "/dmZgHaveDinner")
    @Log("用餐报表")
    @ApiOperation("用餐报表")
//    @PreAuthorize("@el.check('dmHaveDinner:list')")
    public ResponseEntity<Object> selectZgHaveDinner(String stateDate, String endDate, String type, Pageable pageable){
        Map<String,Object> map = new HashMap<>();
        map.put("one",dmHaveDinnerService.selectZgHaveDinner(stateDate,endDate,type,pageable));
        return new ResponseEntity<>(map, HttpStatus.OK);
    }

    @GetMapping(value = "/dmZdHaveDinner")
    @Log("用餐报表")
    @ApiOperation("用餐报表")
    public ResponseEntity<Object> selectZdHaveDinner(String stateDate, String endDate, String type, Pageable pageable){
        Map<String,Object> map = new HashMap<>();
        map.put("two",dmHaveDinnerService.selectZdHaveDinner(stateDate,endDate,type,pageable));
        return new ResponseEntity<>(map, HttpStatus.OK);
    }

}
