package digital.laboratory.platform.entrustment.controller;

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.StorageCell;
import digital.laboratory.platform.entrustment.service.StorageCellService;
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_cell" )
@Api( tags = "307-暂存柜,每行一个单元格管理")
public class StorageCellController {

    private final  StorageCellService storageCellService;

	/**
	 * 通过id查询暂存柜,每行一个单元格
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
//	@PreAuthorize("@pms.hasPermission('entrustment_storage_cell_get')" )
	public R getById(@PathVariable("id" ) String id) {
		return R.ok(storageCellService.getById(id));
	}

	/**
     * 分页查询
     * @param page 分页对象
     * @param storageCell 暂存柜,每行一个单元格
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cell_get')" )
    public R getStorageCellPage(Page page, StorageCell storageCell) {
        return R.ok(storageCellService.page(page, Wrappers.query(storageCell)));
    }


    /**
     * 新增暂存柜,每行一个单元格
     * @param storageCell 暂存柜,每行一个单元格
     * @return R
     */
    @ApiOperation(value = "新增暂存柜,每行一个单元格", notes = "新增暂存柜,每行一个单元格")
    @SysLog("新增暂存柜,每行一个单元格" )
    @PostMapping
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cell_add')" )
    public R postAddObject(@RequestBody StorageCell storageCell) {
        storageCell.setId(IdWorker.get32UUID().toUpperCase());
        return R.ok(storageCellService.save(storageCell));
    }

    /**
     * 修改暂存柜,每行一个单元格
     * @param storageCell 暂存柜,每行一个单元格
     * @return R
     */
    @ApiOperation(value = "修改暂存柜,每行一个单元格", notes = "修改暂存柜,每行一个单元格")
    @SysLog("修改暂存柜,每行一个单元格" )
    @PutMapping
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cell_edit')" )
    public R putUpdateById(@RequestBody StorageCell storageCell) {
        return R.ok(storageCellService.updateById(storageCell));
    }

    /**
     * 通过id删除暂存柜,每行一个单元格
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除暂存柜,每行一个单元格", notes = "通过id删除暂存柜,每行一个单元格")
    @SysLog("通过id删除暂存柜,每行一个单元格" )
    @DeleteMapping("/{id}" )
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cell_del')" )
    public R deleteById(@PathVariable String id) {
        return R.ok(storageCellService.removeById(id));
    }

}
