package digital.laboratory.platform.entrustment.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
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.HairJob;
import digital.laboratory.platform.entrustment.entity.SampleStoreLog;
import digital.laboratory.platform.entrustment.service.HairJobService;
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-26
 * @describe 毛发检测任务 前端控制器
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/papp/entrustment/hair_job" )
@Api(value = "hair_job", tags = "毛发检测任务管理")
public class HairJobController {

    private final  HairJobService hairJobService;

	/**
	 * 通过id查询毛发检测任务
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
	@PreAuthorize("@pms.hasPermission('entrustment_hair_job_get')" )
	public R getById(@PathVariable("id" ) String id) {
		return R.ok(hairJobService.getById(id));
	}

	/**
     * 分页查询
     * @param page 分页对象
     * @param hairJob 毛发检测任务
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('entrustment_hair_job_get')" )
    public R<IPage<HairJob>> getHairJobPage(Page page, HairJob hairJob) {
        return R.ok(hairJobService.page(page, Wrappers.query(hairJob)));
    }


    /**
     * 新增毛发检测任务
     * @param hairJob 毛发检测任务
     * @return R
     */
    @ApiOperation(value = "新增毛发检测任务", notes = "新增毛发检测任务")
    @SysLog("新增毛发检测任务" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('entrustment_hair_job_add')" )
    public R postAddObject(@RequestBody HairJob hairJob) {
        return R.ok(hairJobService.save(hairJob));
    }

    /**
     * 修改毛发检测任务
     * @param hairJob 毛发检测任务
     * @return R
     */
    @ApiOperation(value = "修改毛发检测任务", notes = "修改毛发检测任务")
    @SysLog("修改毛发检测任务" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('entrustment_hair_job_edit')" )
    public R putUpdateById(@RequestBody HairJob hairJob) {
        return R.ok(hairJobService.updateById(hairJob));
    }

    /**
     * 通过id删除毛发检测任务
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除毛发检测任务", notes = "通过id删除毛发检测任务")
    @SysLog("通过id删除毛发检测任务" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('entrustment_hair_job_del')" )
    public R deleteById(@PathVariable String id) {
        return R.ok(hairJobService.removeById(id));
    }

}
