/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.youchain.basicdata.rest;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.youchain.annotation.Log;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.domain.Studen;
import com.youchain.basicdata.service.StudenService;
import com.youchain.basicdata.service.dto.StudenQueryCriteria;
import com.youchain.businessdata.inputJson.OrderInfo;
import com.youchain.config.FileProperties;
import com.youchain.exception.handler.ApiError;
import com.youchain.exception.handler.ApiResult;
import com.youchain.modules.system.domain.Dept;
import com.youchain.utils.BaseStatus;
import com.youchain.utils.FileUtil;
import com.youchain.utils.UserUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK;

/**
* @website https://eladmin.vip
* @author LY
* @date 2024-04-16
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "studen管理")
@Slf4j
@RequestMapping("/api/studen")
public class StudenController {

    private final StudenService studenService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('studen:list')")
    public void exportStuden(HttpServletResponse response, StudenQueryCriteria criteria) throws IOException {
        studenService.download(studenService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询studen")
    @ApiOperation("查询studen")
    @PreAuthorize("@el.check('studen:list')")
    public ResponseEntity<Object> queryStuden(StudenQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(studenService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增studen")
    @ApiOperation("新增studen")
    @PreAuthorize("@el.check('studen:add')")
    public ResponseEntity<Object> createStuden(@Validated @RequestBody Studen resources){
        return new ResponseEntity<>(studenService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改studen")
    @ApiOperation("修改studen")
    @PreAuthorize("@el.check('studen:edit')")
    public ResponseEntity<Object> updateStuden(@Validated @RequestBody Studen resources){
        studenService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除studen")
    @ApiOperation("删除studen")
    @PreAuthorize("@el.check('studen:del')")
    public ResponseEntity<Object> deleteStuden(@RequestBody Integer[] ids) {
        studenService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
