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.StorageCellLog;
import digital.laboratory.platform.entrustment.service.StorageCellLogService;
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_log" )
@Api( tags = "308-暂存柜记录管理")
public class StorageCellLogController {

    private final  StorageCellLogService storageCellLogService;

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

	/**
     * 分页查询
     * @param page 分页对象
     * @param storageCellLog 暂存柜记录
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cell_log_get')" )
    public R getStorageCellLogPage(Page page, StorageCellLog storageCellLog) {
        return R.ok(storageCellLogService.page(page, Wrappers.query(storageCellLog)));
    }


    /**
     * 新增暂存柜记录
     * @param storageCellLog 暂存柜记录
     * @return R
     */
    @ApiOperation(value = "新增暂存柜记录", notes = "新增暂存柜记录")
    @SysLog("新增暂存柜记录" )
    @PostMapping
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cell_log_add')" )
    public R postAddObject(@RequestBody StorageCellLog storageCellLog) {
        storageCellLog.setId(IdWorker.get32UUID().toUpperCase());
        return R.ok(storageCellLogService.save(storageCellLog));
    }

    /**
     * 修改暂存柜记录
     * @param storageCellLog 暂存柜记录
     * @return R
     */
    @ApiOperation(value = "修改暂存柜记录", notes = "修改暂存柜记录")
    @SysLog("修改暂存柜记录" )
    @PutMapping
//    @PreAuthorize("@pms.hasPermission('entrustment_storage_cell_log_edit')" )
    public R putUpdateById(@RequestBody StorageCellLog storageCellLog) {
        return R.ok(storageCellLogService.updateById(storageCellLog));
    }

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

}
