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.SampleBoxInLog;
import digital.laboratory.platform.entrustment.service.SampleBoxInLogService;
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_box_in_log" )
@Api(value = "sample_box_in_log", tags = "样品包入库出库日志管理")
public class SampleBoxInLogController {

    private final  SampleBoxInLogService sampleBoxInLogService;

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

	/**
     * 分页查询
     * @param page 分页对象
     * @param sampleBoxInLog 样品包入库出库日志
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('entrustment_sample_box_in_log_get')" )
    public R getSampleBoxInLogPage(Page page, SampleBoxInLog sampleBoxInLog) {
        return R.ok(sampleBoxInLogService.page(page, Wrappers.query(sampleBoxInLog)));
    }


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

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

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

}
