package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.DmpProductAttribute;
import com.usky.iot.service.DmpProductAttributeService;
import com.usky.iot.service.vo.DmpProductAttributeRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品属性表
 *
 * @author ya
 * @since 2022-10-08
 */
@RestController
@RequestMapping("/dmpProductAttribute")
public class DmpProductAttributeController {


    @Autowired
    private DmpProductAttributeService dmpProductAttributeService;

    /**
     * 新增
     * @param dmpProductAttribute
     * @return
     */
    @PostMapping
    public ApiResult<Void> add(@RequestBody DmpProductAttribute dmpProductAttribute){
        dmpProductAttributeService.add(dmpProductAttribute);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param dmpProductAttribute
     * @return
     */
    @PutMapping
    public ApiResult<Void> edit(@RequestBody DmpProductAttribute dmpProductAttribute){
        dmpProductAttributeService.update(dmpProductAttribute);
        return ApiResult.success();
    }


    /**
     * 分页
     * @param dmpProductAttributeRequest
     * @return
     */
    @PostMapping("/page")
    public ApiResult<CommonPage<DmpProductAttribute>> page(@RequestBody DmpProductAttributeRequest dmpProductAttributeRequest)
    {
        return ApiResult.success(dmpProductAttributeService.page(dmpProductAttributeRequest));
    }



    /**
     * 删除记录
     */
    @DeleteMapping("/{id}")
    public ApiResult<Void> remove(@PathVariable("id") Integer id)
    {
        dmpProductAttributeService.remove(id);
        return ApiResult.success();
    }

    /**
     * 批量设置属性绑定状态
     * @param ids
     * @return
     */
    @PostMapping("updateBatchBind")
    public ApiResult<Void> updateBatchBind(@RequestParam("ids[]") List<Integer> ids){
        dmpProductAttributeService.updateBatchBind(ids);
        return ApiResult.success();
    }
}

