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.SampleStoreChangeDutyLog;
import digital.laboratory.platform.entrustment.service.SampleStoreChangeDutyLogService;
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_change_duty_log" )
@Api(value = "sample_store_change_duty_log", tags = "样品库管理员换班日志管理")
public class SampleStoreChangeDutyLogController {

    private final  SampleStoreChangeDutyLogService sampleStoreChangeDutyLogService;

	/**
	 * 通过id查询样品库管理员换班日志
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
	@PreAuthorize("@pms.hasPermission('entrustment_sample_store_change_duty_log_get')" )
	public R getById(@PathVariable("id" ) String id) {
		return R.ok(sampleStoreChangeDutyLogService.getById(id));
	}

	/**
     * 分页查询
     * @param page 分页对象
     * @param sampleStoreChangeDutyLog 样品库管理员换班日志
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_change_duty_log_get')" )
    public R getSampleStoreChangeDutyLogPage(Page page, SampleStoreChangeDutyLog sampleStoreChangeDutyLog) {
        return R.ok(sampleStoreChangeDutyLogService.page(page, Wrappers.query(sampleStoreChangeDutyLog)));
    }


    /**
     * 新增样品库管理员换班日志
     * @param sampleStoreChangeDutyLog 样品库管理员换班日志
     * @return R
     */
    @ApiOperation(value = "新增样品库管理员换班日志", notes = "新增样品库管理员换班日志")
    @SysLog("新增样品库管理员换班日志" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_change_duty_log_add')" )
    public R postAddObject(@RequestBody SampleStoreChangeDutyLog sampleStoreChangeDutyLog) {
        sampleStoreChangeDutyLog.setId(IdWorker.get32UUID().toUpperCase());
        return R.ok(sampleStoreChangeDutyLogService.save(sampleStoreChangeDutyLog));
    }

    /**
     * 修改样品库管理员换班日志
     * @param sampleStoreChangeDutyLog 样品库管理员换班日志
     * @return R
     */
    @ApiOperation(value = "修改样品库管理员换班日志", notes = "修改样品库管理员换班日志")
    @SysLog("修改样品库管理员换班日志" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_change_duty_log_edit')" )
    public R putUpdateById(@RequestBody SampleStoreChangeDutyLog sampleStoreChangeDutyLog) {
        return R.ok(sampleStoreChangeDutyLogService.updateById(sampleStoreChangeDutyLog));
    }

    /**
     * 通过id删除样品库管理员换班日志
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除样品库管理员换班日志", notes = "通过id删除样品库管理员换班日志")
    @SysLog("通过id删除样品库管理员换班日志" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('entrustment_sample_store_change_duty_log_del')" )
    public R deleteById(@PathVariable String id) {
        return R.ok(sampleStoreChangeDutyLogService.removeById(id));
    }

}
