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.HairJobIdentificationMaterial;
import digital.laboratory.platform.entrustment.service.HairJobIdentificationMaterialService;
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_identification_material" )
@Api(value = "hair_job_identification_material", tags = "毛发任务的检材信息管理")
public class HairJobIdentificationMaterialControllerx {

    private final  HairJobIdentificationMaterialService hairJobIdentificationMaterialService;

	/**
	 * 通过id查询毛发任务的检材信息
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
	@PreAuthorize("@pms.hasPermission('entrustment_hair_job_identification_material_get')" )
	public R<HairJobIdentificationMaterial> getById(@PathVariable("id" ) String id) {
		return R.ok(hairJobIdentificationMaterialService.getById(id));
	}

	/**
     * 分页查询
     * @param page 分页对象
     * @param hairJobIdentificationMaterial 毛发任务的检材信息
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('entrustment_hair_job_identification_material_get')" )
    public R<IPage<HairJobIdentificationMaterial>> getHairJobIdentificationMaterialPage(Page page, HairJobIdentificationMaterial hairJobIdentificationMaterial) {
        return R.ok(hairJobIdentificationMaterialService.page(page, Wrappers.query(hairJobIdentificationMaterial)));
    }


    /**
     * 新增毛发任务的检材信息
     * @param hairJobIdentificationMaterial 毛发任务的检材信息
     * @return R
     */
    @ApiOperation(value = "新增毛发任务的检材信息", notes = "新增毛发任务的检材信息")
    @SysLog("新增毛发任务的检材信息" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('entrustment_hair_job_identification_material_add')" )
    public R postAddObject(@RequestBody HairJobIdentificationMaterial hairJobIdentificationMaterial) {
        return R.ok(hairJobIdentificationMaterialService.save(hairJobIdentificationMaterial));
    }

    /**
     * 修改毛发任务的检材信息
     * @param hairJobIdentificationMaterial 毛发任务的检材信息
     * @return R
     */
    @ApiOperation(value = "修改毛发任务的检材信息", notes = "修改毛发任务的检材信息")
    @SysLog("修改毛发任务的检材信息" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('entrustment_hair_job_identification_material_edit')" )
    public R putUpdateById(@RequestBody HairJobIdentificationMaterial hairJobIdentificationMaterial) {
        return R.ok(hairJobIdentificationMaterialService.updateById(hairJobIdentificationMaterial));
    }

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

}
