package com.chushang.inspection.terminal.controller;
import cn.hutool.core.bean.BeanUtil;
import com.chushang.common.core.validator.Create;
import com.chushang.common.core.validator.Update;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.inspection.terminal.dto.ConsumablesTotalDTO;
import com.chushang.inspection.terminal.po.ConsumablesTotal;
import com.chushang.inspection.terminal.query.ConsumablesDetailsQuery;
import com.chushang.inspection.terminal.query.ConsumablesTotalQuery;
import com.chushang.inspection.terminal.service.ConsumablesTotalService;
import com.chushang.security.annotation.RequiresPermissions;
import lombok.extern.java.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
* (consumables_total)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/consumables/total")
public class ConsumablesTotalController {
/**
* 服务对象
*/
    @Resource
    ConsumablesTotalService consumablesTotalService;

    /**
     * 查询耗材总数
     *
     * @param query 条件
     */
    @GetMapping("/page")
    @RequiresPermissions("consumables:total:page")
    public AjaxResult findPage(@Validated ConsumablesTotalQuery query) {
        return AjaxResult.success(consumablesTotalService.findPage(query));
    }


    /**
     * 查询耗材详情
     */
    @GetMapping("/info/{totalId}")
    @RequiresPermissions("consumables:total:info")
    public AjaxResult info(@PathVariable Long totalId) {
        return AjaxResult.success(consumablesTotalService.getById(totalId));
    }


    /**
     * 入库
     */
    @SysLog(value = "耗材入库", businessType = BusinessType.INSERT)
    @PostMapping("/storage")
    @RequiresPermissions("consumables:total:storage")
    public AjaxResult storage(@RequestBody @Validated(Create.class) ConsumablesTotalDTO total) {
        consumablesTotalService.storage(total);
        return AjaxResult.success();
    }

    /**
     * 出库
     */
    @SysLog(value = "耗材出库", businessType = BusinessType.UPDATE)
    @PostMapping("/out")
    @RequiresPermissions("consumables:total:out")
    public AjaxResult outOfWarehouse(@RequestBody @Validated(Update.class) ConsumablesTotalDTO total) {
        consumablesTotalService.outOfWarehouse(total);
        return AjaxResult.success();
    }

    /**
     * 修改
     */
    @SysLog(value = "耗材", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @RequiresPermissions("consumables:total:update")
    public AjaxResult update(@RequestBody @Validated(Update.class) ConsumablesTotalDTO total) {
        consumablesTotalService.updateById(BeanUtil.copyProperties(total, ConsumablesTotal.class));
        return AjaxResult.success();
    }


}
