package digital.laboratory.platform.entrustment.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.common.log.annotation.SysLog;
import digital.laboratory.platform.entrustment.entity.Entrustment;
import digital.laboratory.platform.entrustment.entity.StorageCabinet;
import digital.laboratory.platform.entrustment.service.StorageCabinetService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 暂存柜
 *
 * @author Zhang Xiaolong created at  2022-04-25
 * @describe 暂存柜 前端控制器
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/papp/entrustment/storage_cabinet" )
@Api( tags = "306-暂存柜管理")
public class StorageCabinetController {

    private final  StorageCabinetService storageCabinetService;

	/**
	 * 通过id查询暂存柜
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
//	@PreAuthorize("@pms.hasPermission('entrustment_storage_cabinet_get')" )
	public R<StorageCabinet> getById(@PathVariable("id" ) String id) {
		return R.ok(storageCabinetService.getById(id));
	}

	/**
     * 分页查询
     * @param page 分页对象
     * @param storageCabinet 暂存柜
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cabinet_get')" )
    public R<IPage<StorageCabinet>> getStorageCabinetPage(Page<StorageCabinet> page, StorageCabinet storageCabinet) {
        return R.ok(storageCabinetService.page(page, Wrappers.query(storageCabinet)));
    }



    /**
     * 新增暂存柜
     * @param storageCabinet 暂存柜
     * @return R
     */
    @ApiOperation(value = "新增暂存柜", notes = "新增暂存柜")
    @SysLog("新增暂存柜" )
    @PostMapping
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cabinet_add')" )
    public R postAddObject(@RequestBody StorageCabinet storageCabinet) {
        storageCabinet.setId(IdWorker.get32UUID().toUpperCase());
        return R.ok(storageCabinetService.save(storageCabinet));
    }

    /**
     * 修改暂存柜
     * @param storageCabinet 暂存柜
     * @return R
     */
    @ApiOperation(value = "修改暂存柜", notes = "修改暂存柜")
    @SysLog("修改暂存柜" )
    @PutMapping
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cabinet_edit')" )
    public R putUpdateById(@RequestBody StorageCabinet storageCabinet) {
        return R.ok(storageCabinetService.updateById(storageCabinet));
    }

    /**
     * 通过id删除暂存柜
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除暂存柜", notes = "通过id删除暂存柜")
    @SysLog("通过id删除暂存柜" )
    @DeleteMapping("/{id}" )
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cabinet_del')" )
    public R deleteById(@PathVariable String id) {
        return R.ok(storageCabinetService.removeById(id));
    }

}
