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.SampleStoreLog;
import digital.laboratory.platform.entrustment.service.SampleStoreLogService;
import digital.laboratory.platform.entrustment.vo.CaseEventVO;
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-07-06
 * @describe 样品库入库出库日志 前端控制器
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/papp/entrustment/sample_store_log" )
@Api(value = "sample_store_log", tags = "样品库入库出库日志管理")
public class SampleStoreLogController {

    private final  SampleStoreLogService sampleStoreLogService;

	/**
	 * 通过id查询样品库入库出库日志
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
	@PreAuthorize("@pms.hasPermission('entrustment_sample_store_log_get')" )
	public R getById(@PathVariable("id" ) String id) {
		return R.ok(sampleStoreLogService.getById(id));
	}

	/**
     * 分页查询
     * @param page 分页对象
     * @param sampleStoreLog 样品库入库出库日志
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_log_get')" )
    public R<IPage<SampleStoreLog>> getSampleStoreLogPage(Page page, SampleStoreLog sampleStoreLog) {
        return R.ok(sampleStoreLogService.page(page, Wrappers.query(sampleStoreLog)));
    }


    /**
     * 新增样品库入库出库日志
     * @param sampleStoreLog 样品库入库出库日志
     * @return R
     */
    @ApiOperation(value = "新增样品库入库出库日志", notes = "新增样品库入库出库日志")
    @SysLog("新增样品库入库出库日志" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_log_add')" )
    public R postAddObject(@RequestBody SampleStoreLog sampleStoreLog) {
        sampleStoreLog.setId(IdWorker.get32UUID().toUpperCase());
        return R.ok(sampleStoreLogService.save(sampleStoreLog));
    }

    /**
     * 修改样品库入库出库日志
     * @param sampleStoreLog 样品库入库出库日志
     * @return R
     */
    @ApiOperation(value = "修改样品库入库出库日志", notes = "修改样品库入库出库日志")
    @SysLog("修改样品库入库出库日志" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_log_edit')" )
    public R putUpdateById(@RequestBody SampleStoreLog sampleStoreLog) {
        return R.ok(sampleStoreLogService.updateById(sampleStoreLog));
    }

    /**
     * 通过id删除样品库入库出库日志
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除样品库入库出库日志", notes = "通过id删除样品库入库出库日志")
    @SysLog("通过id删除样品库入库出库日志" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_log_del')" )
    public R deleteById(@PathVariable String id) {
        return R.ok(sampleStoreLogService.removeById(id));
    }

}
