/*
*  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.businessdata.rest;

import com.youchain.annotation.Log;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.domain.Stock;
import com.youchain.businessdata.domain.CountDetail;
import com.youchain.businessdata.domain.CountRecord;
import com.youchain.businessdata.domain.Inventory;
import com.youchain.businessdata.domain.ItemKey;
import com.youchain.businessdata.service.CountRecordService;
import com.youchain.businessdata.service.dto.CountDetailQueryCriteria;
import com.youchain.businessdata.service.dto.CountRecordQueryCriteria;
import com.youchain.modules.system.domain.Dept;
import com.youchain.utils.BizStatus;
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.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.List;
import javax.persistence.Query;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://eladmin.vip
* @author houjianlan
* @date 2023-10-20
**/
@RestController
@RequiredArgsConstructor
@Slf4j
@Api(tags = "count_record管理")
@RequestMapping("/api/countRecord")
public class CountRecordController {

    private final CountRecordService countRecordService;

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

    @GetMapping
    @ApiOperation("查询count_record")
    public ResponseEntity<Object> queryCountRecord(CountRecordQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(countRecordService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @GetMapping(value = "/queryPlanCountRecord")
    @ApiOperation("查询count_detail")
    public ResponseEntity<Object> queryPlanCountRecord(CountRecordQueryCriteria criteria){
        return new ResponseEntity<>(countRecordService.queryAll(criteria),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增count_record")
    @ApiOperation("新增count_record")
    @PreAuthorize("@el.check('countRecord:add')")
    public ResponseEntity<Object> createCountRecord(@Validated @RequestBody CountRecord resources){
        return new ResponseEntity<>(countRecordService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改count_record")
    @ApiOperation("修改count_record")
    @PreAuthorize("@el.check('countRecord:edit')")
    public ResponseEntity<Object> updateCountRecord(@Validated @RequestBody CountRecord resources){
        countRecordService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除count_record")
    @ApiOperation("删除count_record")
    @PreAuthorize("@el.check('countRecord:del')")
    public ResponseEntity<Object> deleteCountRecord(@RequestBody Long[] ids) {
        countRecordService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

}
