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.order.service.dto.DmOrderRecordQueryCriteria;
import me.zhengjie.modules.dm.serveEvaluate.service.dto.DmServeEvaluateQueryCriteria;
import me.zhengjie.modules.dm.service.service.dto.DmServicePjQueryCriteria;
import me.zhengjie.modules.dm.statement.service.DmEvaluateService;
import me.zhengjie.modules.dm.statement.service.dto.DmEvaluateDto;
import me.zhengjie.modules.dm.statement.service.dto.DmEvaluateQueryCriteria;
import me.zhengjie.modules.dm.statement.service.dto.DmStatementDto;
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.web.bind.annotation.GetMapping;
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.sql.Timestamp;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@Api(tags = "statement管理")
@RequestMapping("/api/dmEvaluate")
public class DmEvaluateController {
    private final DmEvaluateService dmEvaluateService;


    @Log("查询整体评价")
    @ApiOperation("查询整体评价")
    @GetMapping(value = "/selectEvaluate")
//    @PreAuthorize("@el.check('dmEvaluate:list')")
    public ResponseEntity<Object> selectEvaluate(String stateDate, String endDate, String type, Pageable pageable) throws ParseException {
        return new ResponseEntity<>(dmEvaluateService.selectServicePj(stateDate,endDate,type,pageable), HttpStatus.OK);
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('dmEvaluate:list')")
    public void download(HttpServletResponse response, String stateDate, String endDate, String type, Pageable pageable) throws IOException {
//        dmEvaluateService.download(dmEvaluateService.queryAll(criteria), response);
        Map<String,Object> map = dmEvaluateService.selectServicePj(stateDate,endDate,type,pageable);
        List<DmEvaluateDto> all = (List<DmEvaluateDto>)map.get("content");
        dmEvaluateService.download(all, response);
    }

//    @GetMapping
//    @Log("查询dmEvaluate")
//    @ApiOperation("查询dmEvaluate")
//    @PreAuthorize("@el.check('dmEvaluate:list')")
//    public ResponseEntity<Object> query(DmEvaluateQueryCriteria criteria, Pageable pageable){
//        return new ResponseEntity<>(dmEvaluateService.queryAll(criteria,pageable),HttpStatus.OK);
//    }
}
